NovaBryan/EVE_Dump
Log | Files | 📦 下载最新源码 (.zip) | Refs | README

split_view.py (9464B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\carbonui\primitives\split_view.py
      2 import signals
      3 from carbonui import uiconst
      4 from carbonui.primitives.childrenlist import PyChildrenList
      5 from carbonui.primitives.container import Container
      6 from carbonui.uianimations import animations
      7 
      8 class PanelMode(object):
      9     INLINE = 1
     10     COMPACT_INLINE = 2
     11     OVERLAY = 3
     12     COMPACT_OVERLAY = 4
     13 
     14     @classmethod
     15     def is_compact(cls, panel_mode):
     16         return panel_mode == cls.COMPACT_INLINE or panel_mode == cls.COMPACT_OVERLAY
     17 
     18     @classmethod
     19     def is_inline(cls, panel_mode):
     20         return panel_mode == cls.INLINE or panel_mode == cls.COMPACT_INLINE
     21 
     22     @classmethod
     23     def is_overlay(cls, panel_mode):
     24         return panel_mode == cls.OVERLAY or panel_mode == cls.COMPACT_OVERLAY
     25 
     26 
     27 class PanelPlacement(object):
     28     LEFT = 1
     29     RIGHT = 2
     30 
     31 
     32 EXPAND_DURATION = 0.2
     33 COLLAPSE_DURATION = 0.2
     34 
     35 class SplitView(Container):
     36     default_clipChildren = True
     37 
     38     def __init__(self, compact_panel_width = 48, expanded = False, expanded_panel_width = 300, panel_mode = PanelMode.INLINE, panel_placement = PanelPlacement.LEFT, static_panel_inner_width = True, **kwargs):
     39         self._compact_panel_width = compact_panel_width
     40         self._expanded = expanded
     41         self._expanded_panel_width = expanded_panel_width
     42         self._is_animating = False
     43         self._panel_mode = panel_mode
     44         self._panel_placement = panel_placement
     45         self._static_panel_inner_width = static_panel_inner_width
     46         self._on_expanded_changed = None
     47         self._on_panel_mode_changed = None
     48         self._on_panel_placement_changed = None
     49         super(SplitView, self).__init__(**kwargs)
     50         self._panel_wrap = Container(name='panel_wrap', parent=self, align=self._get_panel_wrap_align(), width=self._get_panel_width(), clipChildren=True)
     51         self._panel = Container(name='panel', parent=self._panel_wrap, align=self._get_panel_align(), width=self._get_panel_inner_width())
     52         self._content = Container(name='content', parent=self, align=uiconst.TOALL)
     53         self.children = LockedChildrenList(self.children, message="Don't add children directly to a SplitView. Use the `content` and `panel` properties instead.")
     54 
     55     @property
     56     def collapsed(self):
     57         return not self._expanded
     58 
     59     @collapsed.setter
     60     def collapsed(self, value):
     61         self._set_expanded(not value, animate=True)
     62 
     63     @property
     64     def on_collapsed_changed(self):
     65         return self.on_expanded_changed
     66 
     67     @property
     68     def compact_panel_width(self):
     69         return self._compact_panel_width
     70 
     71     @compact_panel_width.setter
     72     def compact_panel_width(self, value):
     73         if self._compact_panel_width != value:
     74             self._compact_panel_width = value
     75             self._update_compact_panel_width()
     76 
     77     @property
     78     def content(self):
     79         return self._content
     80 
     81     @property
     82     def expanded(self):
     83         return self._expanded
     84 
     85     @expanded.setter
     86     def expanded(self, value):
     87         self._set_expanded(value, animate=True)
     88 
     89     def is_expanded(self):
     90         return self.expanded
     91 
     92     @property
     93     def on_expanded_changed(self):
     94         if self._on_expanded_changed is None:
     95             self._on_expanded_changed = signals.Signal('{}.on_expanded_changed'.format(self.__class__.__name__))
     96         return self._on_expanded_changed
     97 
     98     @property
     99     def expanded_panel_width(self):
    100         return self._expanded_panel_width
    101 
    102     @expanded_panel_width.setter
    103     def expanded_panel_width(self, value):
    104         if self._expanded_panel_width != value:
    105             self._expanded_panel_width = value
    106             self._update_expanded_panel_width()
    107 
    108     @property
    109     def panel(self):
    110         return self._panel
    111 
    112     @property
    113     def panel_mode(self):
    114         return self._panel_mode
    115 
    116     @panel_mode.setter
    117     def panel_mode(self, value):
    118         if self._panel_mode != value:
    119             self._panel_mode = value
    120             self._update_panel_mode()
    121             self._emit_panel_mode_changed()
    122 
    123     @property
    124     def on_panel_mode_changed(self):
    125         if self._on_panel_mode_changed is None:
    126             self._on_panel_mode_changed = signals.Signal('{}.on_panel_mode_changed'.format(self.__class__.__name__))
    127         return self._on_panel_mode_changed
    128 
    129     @property
    130     def panel_placement(self):
    131         return self._panel_placement
    132 
    133     @panel_placement.setter
    134     def panel_placement(self, value):
    135         if self._panel_placement != value:
    136             self._panel_placement = value
    137             self._update_panel_placement()
    138             self._emit_panel_placement_changed()
    139 
    140     @property
    141     def on_panel_placement_changed(self):
    142         if self._on_panel_placement_changed is None:
    143             self._on_panel_placement_changed = signals.Signal('{}.on_panel_placement_changed'.format(self.__class__.__name__))
    144         return self._on_panel_placement_changed
    145 
    146     @property
    147     def static_panel_inner_width(self):
    148         return self._static_panel_inner_width
    149 
    150     @static_panel_inner_width.setter
    151     def static_panel_inner_width(self, value):
    152         if self._static_panel_inner_width != value:
    153             self._static_panel_inner_width = value
    154             self._update_static_panel_inner_width()
    155 
    156     @property
    157     def is_animating(self):
    158         return self._is_animating
    159 
    160     def collapse(self, animate = True):
    161         self._set_expanded(False, animate)
    162 
    163     def expand(self, animate = True):
    164         self._set_expanded(True, animate)
    165 
    166     def _emit_expanded_changed(self):
    167         if self._on_expanded_changed is not None:
    168             self._on_expanded_changed(self.expanded)
    169 
    170     def _emit_panel_mode_changed(self):
    171         if self._on_panel_mode_changed is not None:
    172             self._on_panel_mode_changed(self)
    173 
    174     def _emit_panel_placement_changed(self):
    175         if self._on_panel_placement_changed is not None:
    176             self._on_panel_placement_changed(self)
    177 
    178     def _get_panel_align(self):
    179         if self._static_panel_inner_width:
    180             return uiconst.TOLEFT
    181         else:
    182             return uiconst.TOALL
    183 
    184     def _get_panel_inner_width(self):
    185         if self._static_panel_inner_width:
    186             return self._expanded_panel_width
    187         else:
    188             return 0
    189 
    190     def _get_panel_wrap_align(self):
    191         if self._panel_placement == PanelPlacement.LEFT:
    192             if PanelMode.is_inline(self._panel_mode):
    193                 return uiconst.TOLEFT
    194             else:
    195                 return uiconst.TOLEFT_NOPUSH
    196         elif self._panel_placement == PanelPlacement.RIGHT:
    197             if PanelMode.is_inline(self._panel_mode):
    198                 return uiconst.TORIGHT
    199             else:
    200                 return uiconst.TORIGHT_NOPUSH
    201 
    202     def _get_panel_width(self):
    203         if self._expanded:
    204             return self._expanded_panel_width
    205         else:
    206             return self._get_panel_collapsed_width()
    207 
    208     def _get_panel_collapsed_width(self):
    209         if PanelMode.is_compact(self._panel_mode):
    210             return self._compact_panel_width
    211         else:
    212             return 0
    213 
    214     def _update_compact_panel_width(self):
    215         if not self._expanded and PanelMode.is_compact(self._panel_mode):
    216             animations.StopAnimation(self._panel_wrap, 'width')
    217             self._panel_wrap.width = self._get_panel_collapsed_width()
    218 
    219     def _update_expanded_panel_width(self):
    220         self._panel.width = self._get_panel_inner_width()
    221         if self._expanded:
    222             animations.StopAnimation(self._panel_wrap, 'width')
    223             self._panel_wrap.width = self._get_panel_width()
    224 
    225     def _update_panel_mode(self):
    226         self._panel_wrap.align = self._get_panel_wrap_align()
    227         animations.StopAnimation(self._panel_wrap, 'width')
    228         self._panel_wrap.width = self._get_panel_width()
    229 
    230     def _update_panel_placement(self):
    231         self._panel_wrap.align = self._get_panel_wrap_align()
    232 
    233     def _update_static_panel_inner_width(self):
    234         self._panel.align = self._get_panel_align()
    235         self._update_expanded_panel_width()
    236 
    237     def _set_expanded(self, value, animate):
    238         if self._expanded != value:
    239             self._expanded = value
    240             self._is_animating = animate
    241             if self._expanded:
    242                 self._expand(animate)
    243             else:
    244                 self._collapse(animate)
    245             self._emit_expanded_changed()
    246 
    247     def _expand(self, animate):
    248         if animate:
    249             animations.MorphScalar(self._panel_wrap, 'width', startVal=self._panel_wrap.width, endVal=self._expanded_panel_width, duration=EXPAND_DURATION, callback=self._on_animation_stopped)
    250         else:
    251             self._panel_wrap.width = self._expanded_panel_width
    252 
    253     def _collapse(self, animate):
    254         if animate:
    255             animations.MorphScalar(self._panel_wrap, 'width', startVal=self._panel_wrap.width, endVal=self._get_panel_collapsed_width(), duration=COLLAPSE_DURATION, callback=self._on_animation_stopped)
    256         else:
    257             self._panel_wrap.width = self._get_panel_collapsed_width()
    258 
    259     def _on_animation_stopped(self):
    260         self._is_animating = False
    261 
    262 
    263 class LockedChildrenList(PyChildrenList):
    264 
    265     def __init__(self, other, message):
    266         self._message = message
    267         super(LockedChildrenList, self).__init__(owner=other.GetOwner(), children=list(other))
    268 
    269     def append(self, obj):
    270         raise RuntimeError(self._message)
    271 
    272     def insert(self, idx, obj):
    273         raise RuntimeError(self._message)