| 113 | | def OnDockItem(self, container, dockitem=None, *args, **kw): |
|---|
| 114 | | pass # print "OnDockItem", self.__class__.__name__, container.__class__.__name__ |
|---|
| | 114 | def OnDockItem(self, dockhost, container, dockitem, *args, **kw): |
|---|
| | 115 | pass # print "OnDockItem", dockhost.__class__.__name__, container.__class__.__name__ |
|---|
| 119 | | def OnUndockItem(self, container, dockitem=None, *args, **kw): |
|---|
| 120 | | pass # print "OnUndockItem", self.__class__.__name__, container.__class__.__name__ |
|---|
| | 120 | def OnUndockItem(self, dockhost, container, dockitem, *args, **kw): |
|---|
| | 121 | pass # print "OnUndockItem", dockhost.__class__.__name__, container.__class__.__name__ |
|---|
| | 125 | |
|---|
| | 126 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| | 127 | |
|---|
| | 128 | class wxSingleDockHostMixin(object): |
|---|
| | 129 | """Adapts a multiple DockHost to only accept a single dock container""" |
|---|
| | 130 | |
|---|
| | 131 | _current = None |
|---|
| | 132 | |
|---|
| | 133 | def DockItem(self, container, dockitem=None, *args, **kw): |
|---|
| | 134 | if container is None: |
|---|
| | 135 | container.DockTo(self) |
|---|
| | 136 | else: |
|---|
| | 137 | if self._current is not None: |
|---|
| | 138 | self._current.Undock() |
|---|
| | 139 | self.__super.DockItem(container, dockitem, *args, **kw) |
|---|
| | 140 | self._current = weakref.proxy(container) |
|---|
| | 141 | |
|---|
| | 142 | def UndockItem(self, container, dockitem=None, *args, **kw): |
|---|
| | 143 | if container is None: |
|---|
| | 144 | if container.IsDocked(self): |
|---|
| | 145 | container.Undock() |
|---|
| | 146 | else: |
|---|
| | 147 | self.__super.UndockItem(container, dockitem, *args, **kw) |
|---|
| | 148 | self._current = None |
|---|
| | 149 | |
|---|
| | 150 | wxSingleDockHostMixin._wxSingleDockHostMixin__super = super(wxSingleDockHostMixin) |
|---|
| | 151 | |
|---|
| | 152 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| | 153 | |
|---|
| | 154 | class wxSingleDockHostAspect(wxSingleDockHostMixin): |
|---|
| | 155 | def MixinAspect(mixinclass, instance, add=True): |
|---|
| | 156 | try: |
|---|
| | 157 | instance.__restoreclass |
|---|
| | 158 | if not add: |
|---|
| | 159 | # Make it back to a normal dock host |
|---|
| | 160 | instance.__class__ = instance.__restoreclass |
|---|
| | 161 | #else: pass # It already is a single dock host |
|---|
| | 162 | except AttributeError: |
|---|
| | 163 | if add: |
|---|
| | 164 | # Make it a single dock host |
|---|
| | 165 | oldclass = instance.__class__ |
|---|
| | 166 | instance.__class__ = type('%s+%s'%(mixinclass, instance.__class__), (mixinclass, instance.__class__), {'__restoreclass': oldclass}) |
|---|
| | 167 | #else: pass # It is not a dock host, and it should stay that way |
|---|
| | 168 | MixinAspect = classmethod(MixinAspect) |
|---|
| 152 | | self.dockcount += 1 |
|---|
| 153 | | try: DIReparent = dockitem.Reparent |
|---|
| 154 | | except AttributeError: pass |
|---|
| 155 | | else: DIReparent(self.parent) |
|---|
| 156 | | |
|---|
| 157 | | if self.prepend: |
|---|
| 158 | | self.layout.Prepend(dockitem, *args, **kw) |
|---|
| 159 | | else: self.layout.Add(dockitem, *args, **kw) |
|---|
| 160 | | self.OnDockItem(container, dockitem) |
|---|
| 161 | | self.Layout() |
|---|
| | 197 | return self._DoDockItem(container, dockitem, *args, **kw) |
|---|
| | 198 | |
|---|
| | 199 | def _DoDockItem(self, container, dockitem, *args, **kw): |
|---|
| | 200 | self.dockcount += 1 |
|---|
| | 201 | try: DIReparent = dockitem.Reparent |
|---|
| | 202 | except AttributeError: pass |
|---|
| | 203 | else: DIReparent(self.parent) |
|---|
| | 204 | |
|---|
| | 205 | if self.prepend: |
|---|
| | 206 | self.layout.Prepend(dockitem, *args, **kw) |
|---|
| | 207 | else: self.layout.Add(dockitem, *args, **kw) |
|---|
| | 208 | self.OnDockItem(self, container, dockitem) |
|---|
| | 209 | self.Layout() |
|---|
| 168 | | self.dockcount -= 1 |
|---|
| 169 | | ### The following code is not required, but included so |
|---|
| 170 | | ### we don't wonder about the asymetry ;) |
|---|
| 171 | | ##try: DIReparent = dockitem.Reparent |
|---|
| 172 | | ##except AttributeError: pass |
|---|
| 173 | | ##else: DIReparent(None) |
|---|
| 174 | | |
|---|
| 175 | | # Disable size hints so the frame can resize when needed |
|---|
| 176 | | # We will re-enable in self.Layout |
|---|
| 177 | | self.parent.SetSizeHints(0, 0) |
|---|
| 178 | | self.layout.Remove(dockitem) |
|---|
| 179 | | self.OnUndockItem(container, dockitem) |
|---|
| 180 | | self.Layout() |
|---|
| | 216 | return self._DoUndockItem(container, dockitem, *args, **kw) |
|---|
| | 217 | |
|---|
| | 218 | def _DoUndockItem(self, container, dockitem, *args, **kw): |
|---|
| | 219 | self.dockcount -= 1 |
|---|
| | 220 | ### The following code is not required, but included so |
|---|
| | 221 | ### we don't wonder about the asymetry ;) |
|---|
| | 222 | ##try: DIReparent = dockitem.Reparent |
|---|
| | 223 | ##except AttributeError: pass |
|---|
| | 224 | ##else: DIReparent(None) |
|---|
| | 225 | |
|---|
| | 226 | # Disable size hints so the frame can resize when needed |
|---|
| | 227 | # We will re-enable in self.Layout |
|---|
| | 228 | self.parent.SetSizeHints(0, 0) |
|---|
| | 229 | self.layout.Remove(dockitem) |
|---|
| | 230 | self.OnUndockItem(self, container, dockitem) |
|---|
| | 231 | self.Layout() |
|---|
| 259 | | self.dockcount += 1 |
|---|
| 260 | | |
|---|
| 261 | | page = self.AcquireNotebookDockPage() |
|---|
| 262 | | |
|---|
| 263 | | try: DIReparent = dockitem.Reparent |
|---|
| | 315 | return self._DoDockItem(container, dockitem, *args, **kw) |
|---|
| | 316 | |
|---|
| | 317 | def _DoDockItem(self, container, dockitem, *args, **kw): |
|---|
| | 318 | self.dockcount += 1 |
|---|
| | 319 | |
|---|
| | 320 | page = self.AcquireNotebookDockPage() |
|---|
| | 321 | |
|---|
| | 322 | try: DIReparent = dockitem.Reparent |
|---|
| | 323 | except AttributeError: pass |
|---|
| | 324 | else: DIReparent(page) |
|---|
| | 325 | |
|---|
| | 326 | page.DockItem(dockitem, *args, **kw) |
|---|
| | 327 | |
|---|
| | 328 | text = None |
|---|
| | 329 | if text is None: |
|---|
| | 330 | try: text = container.pagename |
|---|
| 265 | | else: DIReparent(page) |
|---|
| 266 | | |
|---|
| 267 | | page.DockItem(dockitem, *args, **kw) |
|---|
| 268 | | |
|---|
| 269 | | text = None |
|---|
| 270 | | if text is None: |
|---|
| 271 | | try: text = container.pagename |
|---|
| 272 | | except AttributeError: pass |
|---|
| 273 | | if text is None: |
|---|
| 274 | | try: text = dockitem.GetLabel() |
|---|
| 275 | | except AttributeError: pass |
|---|
| 276 | | if text is None: |
|---|
| 277 | | text = text or dockitem.__class__.__name__ |
|---|
| 278 | | |
|---|
| 279 | | if self.prepend: |
|---|
| 280 | | self.notebook.InsertPage(0, page, text, self.selectpage) |
|---|
| 281 | | else: |
|---|
| 282 | | self.notebook.AddPage(page, text, self.selectpage) |
|---|
| 283 | | page.Show(True) |
|---|
| 284 | | self.OnDockItem(container, dockitem) |
|---|
| 285 | | self.Layout() |
|---|
| | 332 | if text is None: |
|---|
| | 333 | try: text = dockitem.GetLabel() |
|---|
| | 334 | except AttributeError: pass |
|---|
| | 335 | if text is None: |
|---|
| | 336 | text = text or dockitem.__class__.__name__ |
|---|
| | 337 | |
|---|
| | 338 | if self.prepend: |
|---|
| | 339 | self.notebook.InsertPage(0, page, text, self.selectpage) |
|---|
| | 340 | else: |
|---|
| | 341 | self.notebook.AddPage(page, text, self.selectpage) |
|---|
| | 342 | page.Show(True) |
|---|
| | 343 | self.OnDockItem(self, container, dockitem) |
|---|
| | 344 | self.Layout() |
|---|
| 292 | | self.dockcount -= 1 |
|---|
| 293 | | ### The following code is not required, but included so |
|---|
| 294 | | ### we don't wonder about the asymetry ;) |
|---|
| 295 | | ##try: DIReparent = dockitem.Reparent |
|---|
| 296 | | ##except AttributeError: pass |
|---|
| 297 | | ##else: DIReparent(None) |
|---|
| 298 | | |
|---|
| 299 | | page = self.FindNotebookDockPage(dockitem) |
|---|
| 300 | | page.UndockItem(dockitem) |
|---|
| 301 | | |
|---|
| 302 | | for idx in range(self.notebook.GetPageCount()): |
|---|
| 303 | | if self.notebook.GetPage(idx) is page: |
|---|
| 304 | | self.notebook.RemovePage(idx) |
|---|
| 305 | | break |
|---|
| 306 | | |
|---|
| 307 | | self.ReleaseNotebookDockPage(page) |
|---|
| 308 | | self.OnUndockItem(container, dockitem) |
|---|
| 309 | | self.Layout() |
|---|
| | 351 | return self._DoUndockItem(container, dockitem, *args, **kw) |
|---|
| | 352 | |
|---|
| | 353 | def _DoUndockItem(self, container, dockitem, *args, **kw): |
|---|
| | 354 | self.dockcount -= 1 |
|---|
| | 355 | ### The following code is not required, but included so |
|---|
| | 356 | ### we don't wonder about the asymetry ;) |
|---|
| | 357 | ##try: DIReparent = dockitem.Reparent |
|---|
| | 358 | ##except AttributeError: pass |
|---|
| | 359 | ##else: DIReparent(None) |
|---|
| | 360 | |
|---|
| | 361 | page = self.FindNotebookDockPage(dockitem) |
|---|
| | 362 | if page is None: raise KeyError, "Dockitem not found" |
|---|
| | 363 | page.UndockItem(dockitem) |
|---|
| | 364 | |
|---|
| | 365 | for idx in range(self.notebook.GetPageCount()): |
|---|
| | 366 | if self.notebook.GetPage(idx) is page: |
|---|
| | 367 | self.notebook.RemovePage(idx) |
|---|
| | 368 | break |
|---|
| | 369 | |
|---|
| | 370 | self.ReleaseNotebookDockPage(page) |
|---|
| | 371 | self.OnUndockItem(self, container, dockitem) |
|---|
| | 372 | self.Layout() |
|---|