| | 1 | # -*- coding: utf-8 -*- |
|---|
| | 2 | """ dMdiLayoutPanel.py |
|---|
| | 3 | |
|---|
| | 4 | A special panel used together with dMainForm in MDI mode (windows only). |
|---|
| | 5 | |
|---|
| | 6 | Panels can be positioned inside the MDI client area at a given place and can |
|---|
| | 7 | be user resized. |
|---|
| | 8 | |
|---|
| | 9 | Example: |
|---|
| | 10 | lp = dMdiLayoutPanel(self, Size=(150,50), |
|---|
| | 11 | Resizable=True, Alignment="Left", |
|---|
| | 12 | Orientation="Vertical") |
|---|
| | 13 | """ |
|---|
| | 14 | |
|---|
| | 15 | import wx |
|---|
| | 16 | import dabo |
|---|
| | 17 | import dabo.ui |
|---|
| | 18 | dabo.ui.loadUI("wx") |
|---|
| | 19 | import dabo.dEvents as dEvents |
|---|
| | 20 | from dabo.dLocalize import _ |
|---|
| | 21 | import dControlMixin as dcm |
|---|
| | 22 | |
|---|
| | 23 | class 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 | |