source: SHX/trunk/sandbox/auitab.py @ 93

Revision 93, 2.5 KB checked in by marcus, 11 years ago (diff)
  • some more layout experiment
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Rev Id Date
Line 
1import wx, wx.aui
2
3
4class AuiNotebookWithFloatingPages(wx.aui.AuiNotebook):
5    def __init__(self, *args, **kwargs):
6        super(AuiNotebookWithFloatingPages, self).__init__(*args, **kwargs)
7        self.__auiManager = self.GetAuiManager()
8        self.Bind(wx.aui.EVT_AUINOTEBOOK_END_DRAG, self.onEndDrag)
9        self.Bind(wx.aui.EVT_AUINOTEBOOK_DRAG_MOTION, self.onDragMotion)
10
11    def onDragMotion(self, event):
12        self.__auiManager.HideHint()
13        if self.IsMouseWellOutsideWindow():
14            x, y = wx.GetMousePosition()
15            hintRect = wx.Rect(x, y, 400, 300)
16            # Use CallAfter so we overwrite the hint that might be
17            # shown by our superclass:
18            wx.CallAfter(self.__auiManager.ShowHint, hintRect)
19        event.Skip()
20
21    def onEndDrag(self, event):
22        self.__auiManager.HideHint()
23        if self.IsMouseWellOutsideWindow():
24            # Use CallAfter so we our superclass can deal with the event first
25            wx.CallAfter(self.FloatPage, self.Selection)
26        event.Skip()
27
28    def IsMouseWellOutsideWindow(self):
29        screenRect = self.GetScreenRect()
30        screenRect.Inflate(50, 50)
31        return not screenRect.Contains(wx.GetMousePosition())
32
33    def FloatPage(self, pageIndex):
34        pageTitle = self.GetPageText(pageIndex)
35        frame = wx.Frame(self, title=pageTitle, 
36            style=wx.DEFAULT_FRAME_STYLE|wx.FRAME_TOOL_WINDOW)
37        pageContents = self.GetPage(pageIndex)
38        pageContents.Reparent(frame)
39        self.RemovePage(pageIndex)
40        frame.Bind(wx.EVT_CLOSE, self.onCloseFloatingPage)
41        frame.Move(wx.GetMousePosition())
42        frame.Show()
43
44    def onCloseFloatingPage(self, event):
45        event.Skip()
46        frame = event.GetEventObject()
47        pageTitle = frame.GetTitle()
48        pageContents = frame.GetChildren()[0]
49        pageContents.Reparent(self)
50        self.AddPage(pageContents, pageTitle, select=True)
51
52
53if __name__ == '__main__':
54
55    def createPanel(parent, ContentClass, *args, **kwargs):
56        panel = wx.Panel(parent)
57        content = ContentClass(panel, *args, **kwargs)
58        sizer = wx.BoxSizer()
59        sizer.Add(content, flag=wx.EXPAND, proportion=1)
60        panel.SetSizerAndFit(sizer)
61        return panel
62
63    app = wx.App(redirect=False)
64    frame = wx.Frame(None)
65    notebook = AuiNotebookWithFloatingPages(frame)
66    for index in range(5):
67        page = createPanel(notebook, wx.TextCtrl, 
68            value='This is page %d'%index, style=wx.TE_MULTILINE)
69        notebook.AddPage(page, 'Page %d'%index)
70    frame.Show()
71    app.MainLoop()
Note: See TracBrowser for help on using the repository browser.