Ticket #1137: dMdiLayoutPanel.diff

File dMdiLayoutPanel.diff, 6.3 kB (added by pedro.gato, 5 months ago)
  • ui/uiwx/dMdiLayoutPanel.py

    old new  
     1# -*- coding: utf-8 -*- 
     2""" dMdiLayoutPanel.py 
     3 
     4A special panel used together with dMainForm in MDI mode (windows only). 
     5 
     6Panels can be positioned inside the MDI client area at a given place and can 
     7be user resized. 
     8 
     9Example: 
     10    lp = dMdiLayoutPanel(self, Size=(150,50),  
     11        Resizable=True, Alignment="Left",  
     12        Orientation="Vertical") 
     13""" 
     14 
     15import wx 
     16import dabo 
     17import dabo.ui 
     18dabo.ui.loadUI("wx") 
     19import dabo.dEvents as dEvents 
     20from dabo.dLocalize import _ 
     21import dControlMixin as dcm 
     22 
     23class dMdiLayoutPanel(dcm.dControlMixin, wx.SashLayoutWindow): 
     24    def __init__(self, parent=None, properties=None, attProperties=None, *args, **kwargs): 
     25        self._baseClass = dMdiLayoutPanel 
     26        preClass = wx.SashLayoutWindow 
     27         
     28        self.__do_resizable_after = False 
     29        self.__resizable = False 
     30     
     31        dcm.dControlMixin.__init__(self, preClass, parent, properties, attProperties, *args, **kwargs) 
     32 
     33        #main panel creation 
     34        self.__pnl = dabo.ui.dPanel(self) 
     35        self.__pnl.Sizer = dabo.ui.dSizer("v") 
     36 
     37        self.super() 
     38 
     39    def initEvents(self): 
     40        self.Bind(wx.EVT_SASH_DRAGGED, self.__OnWxSashDragged) 
     41        self.bindEvent(dabo.dEvents.ChildBorn, self._childBorn) 
     42 
     43    def _afterSetProperties(self): 
     44        if self.__do_resizable_after: 
     45            self.Resizable = self.__resizable 
     46 
     47        self.super() 
     48 
     49    def __OnWxSashDragged(self, evt): 
     50        if evt.GetDragStatus() == wx.SASH_STATUS_OUT_OF_RANGE: 
     51            return 
     52 
     53        if self.Alignment == "Top" or self.Alignment == "Bottom": 
     54            self.SetDefaultSize((1, evt.GetDragRect().height)) 
     55        else: 
     56            self.SetDefaultSize((evt.GetDragRect().width, 1)) 
     57 
     58        #re-layout the parent frame 
     59        wx.LayoutAlgorithm().LayoutMDIFrame(self.Parent) 
     60 
     61    # We need to re-parent all childs except the main panel 
     62    def _childBorn(self, evt): 
     63        if not isinstance(evt.Child, dabo.ui.dPanel): 
     64            evt.Child.Parent = self.__pnl 
     65 
     66    # Proxy method re-parenting the added objects to the main panel 
     67    def addObject(self, classRef, Name=None, *args, **kwargs): 
     68        return self.__pnl.addObject(classRef, Name, *args, **kwargs) 
     69 
     70 
     71    # Properties getters/setters 
     72    def _getSize(self): 
     73        return self.GetDefaultSize() 
     74 
     75    def _setSize(self, size): 
     76        self.SetDefaultSize(size) 
     77 
     78    def _getOrientation(self): 
     79        if self.GetOrientation() == wx.LAYOUT_VERTICAL: 
     80            return "Vertical" 
     81        return "Horizontal" 
     82 
     83    def _setOrientation(self, orientation): 
     84        if self._constructed(): 
     85            if orientation[0].lower() == "h": 
     86                self.SetOrientation(wx.LAYOUT_HORIZONTAL) 
     87            else: 
     88                self.SetOrientation(wx.LAYOUT_VERTICAL) 
     89        else: 
     90            self._properties["Orientation"] = orientation 
     91 
     92    def _getAlignment(self): 
     93        al = self.GetAlignment() 
     94 
     95        if al == wx.LAYOUT_TOP: 
     96            return "Top" 
     97        elif al == wx.LAYOUT_LEFT: 
     98            return "Left" 
     99        elif al == wx.LAYOUT_RIGHT: 
     100            return "Right" 
     101        elif al == wx.LAYOUT_BOTTOM: 
     102            return "Bottom" 
     103        else: 
     104            return "" 
     105 
     106    def _setAlignment(self, alignment): 
     107        if self._constructed(): 
     108            al = alignment[0].lower() 
     109 
     110            if al == "t": 
     111                self.SetAlignment(wx.LAYOUT_TOP) 
     112            elif al == "l": 
     113                self.SetAlignment(wx.LAYOUT_LEFT) 
     114            elif al == "r": 
     115                self.SetAlignment(wx.LAYOUT_RIGHT) 
     116            elif al == "b": 
     117                self.SetAlignment(wx.LAYOUT_BOTTOM) 
     118 
     119        else: 
     120            self._properties["Alignment"] = alignment 
     121 
     122    def _getSizer(self): 
     123        return self.__pnl.Sizer 
     124 
     125    def _setSizer(self, sizer): 
     126        self.__pnl.Sizer = sizer 
     127 
     128    def _getResizable(self): 
     129        if self.Alignment == "Top": 
     130            return self.GetSashVisible(wx.SASH_BOTTOM) 
     131        elif self.Alignment == "Bottom": 
     132            return self.GetSashVisible(wx.SASH_TOP) 
     133        elif self.Alignment == "Left": 
     134            return self.GetSashVisible(wx.SASH_RIGHT) 
     135        elif self.Alignment == "Right": 
     136            return self.GetSashVisible(wx.SASH_LEFT) 
     137        else: 
     138            return False 
     139 
     140 
     141    def _setResizable(self, resizable): 
     142        if self._constructed(): 
     143            if self.Alignment == "Top": 
     144                self.SetSashVisible(wx.SASH_BOTTOM, resizable) 
     145            elif self.Alignment == "Bottom": 
     146                self.SetSashVisible(wx.SASH_TOP, resizable) 
     147            elif self.Alignment == "Left": 
     148                self.SetSashVisible(wx.SASH_RIGHT, resizable) 
     149            elif self.Alignment == "Right": 
     150                self.SetSashVisible(wx.SASH_LEFT, resizable) 
     151            else: 
     152                # Resizable depends on Alignment, as we cannot order the  
     153                # properties we will init Resizable later in _afterSetProperties 
     154                self.__resizable = resizable 
     155                self.__do_resizable_after = True 
     156        else: 
     157            self._properties["Resizable"] = resizable 
     158 
     159    # Properties 
     160     
     161    Size = property(_getSize, _setSize, (100,100), _("The size of the MDI panel, it will grow on the oposite coordinate of its Orientation")) 
     162     
     163    Orientation = property(_getOrientation, _setOrientation, "Horizontal", _("The orientation of the MDI panel, valid values are Horizontal or Vertical")) 
     164 
     165    Alignment = property(_getAlignment, _setAlignment, "Top", _("The alignment of the MDI panel, valid values are Top, Left, Right or Bottom")) 
     166 
     167    Sizer = property(_getSizer, _setSizer, None, _("The sizer used in this MDI panel")) 
     168 
     169    Resizable = property(_getResizable, _setResizable, False, _("Is this MDI panel resizable?")) 
     170     
  • ui/uiwx/__init__.py

    old new  
    146146from dLed import dLed 
    147147import dUICursors as dUICursors 
    148148import dShell 
     149from dMdiLayoutPanel import dMdiLayoutPanel 
    149150 
    150151try: 
    151152    from dLinePlot import dLinePlot 
  • ui/uiwx/dFormMain.py

    old new  
    5757 
    5858        dFormMainBase.__init__(self, preClass, parent, properties, *args, **kwargs) 
    5959 
     60    def initEvents(self): 
     61        self.Bind(wx.EVT_SIZE, self.__onWxSize) 
     62 
     63    def __onWxSize(self, evt): 
     64        try: 
     65            if self._mdi and isinstance(self, dabo.ui.dFormMain): 
     66                wx.LayoutAlgorithm().LayoutMDIFrame(self) 
     67        except: 
     68            pass 
     69 
    6070    def Show(self, show=True, *args, **kwargs): 
    6171        self._gtk_show_fix(show) 
    6272        dFormMain.__bases__[-1].Show(self, show, *args, **kwargs)