1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
'''
Task Coach - Your friendly task manager
Copyright (C) 2004-2014 Task Coach developers <developers@taskcoach.org>
Task Coach is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Task Coach is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
'''
import wx
import wx.lib.agw.aui as aui
from taskcoachlib import operating_system
class AuiManagedFrameWithDynamicCenterPane(wx.Frame):
def __init__(self, *args, **kwargs):
super(AuiManagedFrameWithDynamicCenterPane, self).__init__(*args,
**kwargs)
agwStyle = aui.AUI_MGR_DEFAULT | aui.AUI_MGR_ALLOW_ACTIVE_PANE
if not operating_system.isWindows():
# With this style on Windows, you can't dock back floating frames
agwStyle |= aui.AUI_MGR_USE_NATIVE_MINIFRAMES
self.manager = aui.AuiManager(self, agwStyle)
self.manager.SetAutoNotebookStyle(aui.AUI_NB_TOP | \
aui.AUI_NB_CLOSE_BUTTON | \
aui.AUI_NB_SUB_NOTEBOOK | \
aui.AUI_NB_SCROLL_BUTTONS)
self.bindEvents()
def bindEvents(self):
for eventType in aui.EVT_AUI_PANE_CLOSE, aui.EVT_AUI_PANE_FLOATING:
self.manager.Bind(eventType, self.onPaneClosingOrFloating)
def onPaneClosingOrFloating(self, event):
pane = event.GetPane()
dockedPanes = self.dockedPanes()
if self.isCenterPane(pane) and len(dockedPanes) == 1:
event.Veto()
else:
event.Skip()
if self.isCenterPane(pane):
if pane in dockedPanes:
dockedPanes.remove(pane)
dockedPanes[0].Center()
def addPane(self, window, caption, name, floating=False):
x, y = window.GetPositionTuple()
x, y = window.ClientToScreenXY(x, y)
paneInfo = aui.AuiPaneInfo()
paneInfo = paneInfo.CloseButton(True).Floatable(True).\
Name(name).Caption(caption).Right().\
FloatingSize((300, 200)).BestSize((200, 200)).\
FloatingPosition((x + 30, y + 30)).\
CaptionVisible().MaximizeButton().DestroyOnClose()
if floating:
paneInfo.Float()
if not self.dockedPanes():
paneInfo = paneInfo.Center()
self.manager.AddPane(window, paneInfo)
self.manager.Update()
def setPaneTitle(self, window, title):
self.manager.GetPane(window).Caption(title)
def dockedPanes(self):
return [pane for pane in self.manager.GetAllPanes() \
if not pane.IsToolbar() and not pane.IsFloating() \
and not pane.IsNotebookPage()]
def float(self, window):
self.manager.GetPane(window).Float()
@staticmethod
def isCenterPane(pane):
return pane.dock_direction_get() == aui.AUI_DOCK_CENTER
|