| 172 | | class wxDockHost(wxDockHostBase): |
|---|
| 173 | | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 174 | | #~ Constants / Variables / Etc. |
|---|
| 175 | | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 176 | | |
|---|
| 177 | | prepend = False |
|---|
| 178 | | dockcount = 0 |
|---|
| 179 | | hideempty = False |
|---|
| 180 | | |
|---|
| 181 | | OnLayingout = ObjectEventProperty() #(dockhost) |
|---|
| 182 | | OnLayoutComplete = ObjectEventProperty() #(dockhost) |
|---|
| 183 | | |
|---|
| 184 | | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 185 | | #~ Public Methods |
|---|
| 186 | | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 187 | | |
|---|
| 188 | | def __init__(self, parent, layout, rootparent=None, rootlayout=None, prepend=False, hideempty=False): |
|---|
| 189 | | self.parent = parent |
|---|
| 190 | | self.rootparent = rootparent or parent |
|---|
| 191 | | self.layout = layout |
|---|
| 192 | | self.rootlayout = rootlayout or layout |
|---|
| 193 | | self.prepend = prepend |
|---|
| 194 | | self.SetHideEmpty(hideempty) |
|---|
| 195 | | |
|---|
| 196 | | def GetHideEmpty(self): |
|---|
| 197 | | return self.hideempty |
|---|
| 198 | | |
|---|
| 199 | | def SetHideEmpty(self, hideempty): |
|---|
| 200 | | if isinstance(hideempty, int): |
|---|
| 201 | | self.hideempty = hideempty and self.parent or False |
|---|
| 202 | | else: |
|---|
| 203 | | self.hideempty = hideempty |
|---|
| 204 | | |
|---|
| 205 | | def DockItem(self, container, dockitem=None, *args, **kw): |
|---|
| 206 | | if dockitem is None: |
|---|
| 207 | | container.DockTo(self) |
|---|
| 208 | | else: |
|---|
| 209 | | return self._DoDockItem(container, dockitem, *args, **kw) |
|---|
| 210 | | |
|---|
| 211 | | def _DoDockItem(self, container, dockitem, *args, **kw): |
|---|
| 212 | | self.dockcount += 1 |
|---|
| 213 | | try: DIReparent = dockitem.Reparent |
|---|
| 214 | | except AttributeError: pass |
|---|
| 215 | | else: DIReparent(self.parent) |
|---|
| 216 | | |
|---|
| 217 | | if self.prepend: |
|---|
| 218 | | self.layout.Prepend(dockitem, *args, **kw) |
|---|
| 219 | | else: self.layout.Add(dockitem, *args, **kw) |
|---|
| 220 | | self.DockContainers().append(container) |
|---|
| 221 | | self.OnDockItem(container, dockitem) |
|---|
| 222 | | self.Layout() |
|---|
| 223 | | |
|---|
| 224 | | def UndockItem(self, container, dockitem=None, *args, **kw): |
|---|
| 225 | | if dockitem is None: |
|---|
| 226 | | if container.IsDocked(self): |
|---|
| 227 | | container.Undock() |
|---|
| 228 | | else: |
|---|
| 229 | | return self._DoUndockItem(container, dockitem, *args, **kw) |
|---|
| 230 | | |
|---|
| 231 | | def _DoUndockItem(self, container, dockitem, *args, **kw): |
|---|
| 232 | | self.dockcount -= 1 |
|---|
| 233 | | ### The following code is not required, but included so |
|---|
| 234 | | ### we don't wonder about the asymetry ;) |
|---|
| 235 | | ##try: DIReparent = dockitem.Reparent |
|---|
| 236 | | ##except AttributeError: pass |
|---|
| 237 | | ##else: DIReparent(None) |
|---|
| 238 | | |
|---|
| 239 | | # Disable size hints so the frame can resize when needed |
|---|
| 240 | | # We will re-enable in self.Layout |
|---|
| 241 | | self.parent.SetSizeHints(0, 0) |
|---|
| 242 | | self.layout.Remove(dockitem) |
|---|
| 243 | | self.DockContainers().remove(container) |
|---|
| 244 | | self.OnUndockItem(container, dockitem) |
|---|
| 245 | | self.Layout() |
|---|
| 246 | | |
|---|
| 247 | | def Layout(self): |
|---|
| 248 | | self.OnLayingout() |
|---|
| 249 | | self.HideEmpty() |
|---|
| 250 | | self.rootlayout.Layout() |
|---|
| 251 | | if self.layout is not self.rootlayout: |
|---|
| 252 | | self.layout.Layout() |
|---|
| 253 | | self._SetLayoutContainerSizeHints() |
|---|
| 254 | | self.OnLayoutComplete() |
|---|
| 255 | | |
|---|
| | 172 | class wxDockHostBase(wxDockHostAbstract): |
|---|
| | 182 | |
|---|
| | 183 | def GetHideEmpty(self): |
|---|
| | 184 | return self.hideempty |
|---|
| | 185 | |
|---|
| | 186 | def SetHideEmpty(self, hideempty): |
|---|
| | 187 | if isinstance(hideempty, int): |
|---|
| | 188 | self.hideempty = hideempty and self.parent or False |
|---|
| | 189 | else: |
|---|
| | 190 | self.hideempty = hideempty |
|---|
| | 191 | |
|---|
| | 192 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| | 193 | |
|---|
| | 194 | class wxDockHost(wxDockHostBase): |
|---|
| | 195 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| | 196 | #~ Constants / Variables / Etc. |
|---|
| | 197 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| | 198 | |
|---|
| | 199 | prepend = False |
|---|
| | 200 | dockcount = 0 |
|---|
| | 201 | hideempty = False |
|---|
| | 202 | |
|---|
| | 203 | OnLayingout = ObjectEventProperty() #(dockhost) |
|---|
| | 204 | OnLayoutComplete = ObjectEventProperty() #(dockhost) |
|---|
| | 205 | |
|---|
| | 206 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| | 207 | #~ Public Methods |
|---|
| | 208 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| | 209 | |
|---|
| | 210 | def __init__(self, parent, layout, rootparent=None, rootlayout=None, prepend=False, hideempty=False): |
|---|
| | 211 | self.parent = parent |
|---|
| | 212 | self.rootparent = rootparent or parent |
|---|
| | 213 | self.layout = layout |
|---|
| | 214 | self.rootlayout = rootlayout or layout |
|---|
| | 215 | self.prepend = prepend |
|---|
| | 216 | self.SetHideEmpty(hideempty) |
|---|
| | 217 | |
|---|
| | 218 | def DockItem(self, container, dockitem=None, *args, **kw): |
|---|
| | 219 | if dockitem is None: |
|---|
| | 220 | container.DockTo(self) |
|---|
| | 221 | else: |
|---|
| | 222 | return self._DoDockItem(container, dockitem, *args, **kw) |
|---|
| | 223 | |
|---|
| | 224 | def _DoDockItem(self, container, dockitem, *args, **kw): |
|---|
| | 225 | self.dockcount += 1 |
|---|
| | 226 | try: DIReparent = dockitem.Reparent |
|---|
| | 227 | except AttributeError: pass |
|---|
| | 228 | else: DIReparent(self.parent) |
|---|
| | 229 | |
|---|
| | 230 | if self.prepend: |
|---|
| | 231 | self.layout.Prepend(dockitem, *args, **kw) |
|---|
| | 232 | else: self.layout.Add(dockitem, *args, **kw) |
|---|
| | 233 | self.DockContainers().append(container) |
|---|
| | 234 | self.OnDockItem(container, dockitem) |
|---|
| | 235 | self.Layout() |
|---|
| | 236 | |
|---|
| | 237 | def UndockItem(self, container, dockitem=None, *args, **kw): |
|---|
| | 238 | if dockitem is None: |
|---|
| | 239 | if container.IsDocked(self): |
|---|
| | 240 | container.Undock() |
|---|
| | 241 | else: |
|---|
| | 242 | return self._DoUndockItem(container, dockitem, *args, **kw) |
|---|
| | 243 | |
|---|
| | 244 | def _DoUndockItem(self, container, dockitem, *args, **kw): |
|---|
| | 245 | self.dockcount -= 1 |
|---|
| | 246 | ### The following code is not required, but included so |
|---|
| | 247 | ### we don't wonder about the asymetry ;) |
|---|
| | 248 | ##try: DIReparent = dockitem.Reparent |
|---|
| | 249 | ##except AttributeError: pass |
|---|
| | 250 | ##else: DIReparent(None) |
|---|
| | 251 | |
|---|
| | 252 | # Disable size hints so the frame can resize when needed |
|---|
| | 253 | # We will re-enable in self.Layout |
|---|
| | 254 | self.parent.SetSizeHints(0, 0) |
|---|
| | 255 | self.layout.Remove(dockitem) |
|---|
| | 256 | self.DockContainers().remove(container) |
|---|
| | 257 | self.OnUndockItem(container, dockitem) |
|---|
| | 258 | self.Layout() |
|---|
| | 259 | |
|---|
| | 260 | def Layout(self): |
|---|
| | 261 | self.OnLayingout() |
|---|
| | 262 | self.HideEmpty() |
|---|
| | 263 | self.rootlayout.Layout() |
|---|
| | 264 | if self.layout is not self.rootlayout: |
|---|
| | 265 | self.layout.Layout() |
|---|
| | 266 | self._SetLayoutContainerSizeHints() |
|---|
| | 267 | self.OnLayoutComplete() |
|---|