381
384
self.editCancelled = False
386
Returns a copy of the event.
388
Any event that is posted to the wxPython event system for later action (via
389
`wx.EvtHandler.AddPendingEvent` or `wx.PostEvent`) must implement this method.
390
All wxPython events fully implement this method, but any derived events
391
implemented by the user should also implement this method just in case they
392
(or some event derived from them) are ever posted.
394
All wxPython events implement a copy constructor, so the easiest way of
395
implementing the L{Clone} function is to implement a copy constructor for a new
396
event (call it `MyEvent`) and then define the L{Clone} function like this::
403
return CommandNotebookEvent(self)
406
387
def SetSelection(self, s):
408
389
Sets the selection member variable.
524
505
self.notify = wx.NotifyEvent(command_type.GetEventType(), command_type.GetId())
529
Returns a copy of the event.
531
Any event that is posted to the wxPython event system for later action (via
532
`wx.EvtHandler.AddPendingEvent` or `wx.PostEvent`) must implement this method.
533
All wxPython events fully implement this method, but any derived events
534
implemented by the user should also implement this method just in case they
535
(or some event derived from them) are ever posted.
537
All wxPython events implement a copy constructor, so the easiest way of
538
implementing the L{Clone} function is to implement a copy constructor for a new
539
event (call it `MyEvent`) and then define the L{Clone} function like this::
546
return AuiNotebookEvent(self)
549
508
def GetNotifyEvent(self):
550
509
""" Returns the actual `wx.NotifyEvent`. """
552
511
return self.notify
613
572
img = self._bmp.ConvertToImage()
614
573
img.Rescale(16, 16, wx.IMAGE_QUALITY_HIGH)
615
574
self._bmp = wx.BitmapFromImage(img)
617
576
sz = wx.BoxSizer(wx.VERTICAL)
619
578
self._listBox = wx.ListBox(self, wx.ID_ANY, wx.DefaultPosition, wx.Size(200, 150), [], wx.LB_SINGLE | wx.NO_BORDER)
621
580
mem_dc = wx.MemoryDC()
622
581
mem_dc.SelectObject(wx.EmptyBitmap(1,1))
623
582
font = wx.SystemSettings_GetFont(wx.SYS_DEFAULT_GUI_FONT)
630
589
# Out signpost bitmap is 24 pixels
631
590
if panelHeight < 24:
634
593
self._panel = wx.Panel(self, wx.ID_ANY, wx.DefaultPosition, wx.Size(200, panelHeight))
636
595
sz.Add(self._panel)
637
596
sz.Add(self._listBox, 1, wx.EXPAND)
639
598
self.SetSizer(sz)
641
600
# Connect events to the list box
642
601
self._listBox.Bind(wx.EVT_KEY_UP, self.OnKeyUp)
643
602
self._listBox.Bind(wx.EVT_NAVIGATION_KEY, self.OnNavigationKey)
644
603
self._listBox.Bind(wx.EVT_LISTBOX_DCLICK, self.OnItemSelected)
646
605
# Connect paint event to the panel
647
606
self._panel.Bind(wx.EVT_PAINT, self.OnPanelPaint)
648
607
self._panel.Bind(wx.EVT_ERASE_BACKGROUND, self.OnPanelEraseBg)
709
668
:param `book`: the actual L{AuiNotebook}.
670
# Index of currently selected page
712
671
selection = book.GetSelection()
672
# Total number of pages
713
673
count = book.GetPageCount()
715
self._listBox.Append(book.GetPageText(selection))
716
self._indexMap.append(selection)
718
for c in xrange(count):
674
# List of (index, AuiNotebookPage)
675
pages = list(enumerate(book.GetTabContainer().GetPages()))
676
if book.GetAGWWindowStyleFlag() & AUI_NB_ORDER_BY_ACCESS:
677
# Sort pages using last access time. Most recently used is the
680
key = lambda element: element[1].access_time,
684
# Manually add the current selection as first item
685
# Remaining ones are added in the next loop
687
self._listBox.Append(book.GetPageText(selection))
688
self._indexMap.append(selection)
724
self._listBox.Append(book.GetPageText(c))
725
self._indexMap.append(c)
690
for (index, page) in pages:
691
self._listBox.Append(book.GetPageText(index))
692
self._indexMap.append(index)
727
694
# Select the next entry after the current selection
728
695
self._listBox.SetSelection(0)
876
848
Flag name Description
877
849
==================================== ==================================
878
850
``AUI_NB_TOP`` With this style, tabs are drawn along the top of the notebook
879
``AUI_NB_LEFT`` With this style, tabs are drawn along the left of the notebook. Not implemented yet.
880
``AUI_NB_RIGHT`` With this style, tabs are drawn along the right of the notebook. Not implemented yet.
881
``AUI_NB_BOTTOM`` With this style, tabs are drawn along the bottom of the notebook.
851
``AUI_NB_LEFT`` With this style, tabs are drawn along the left of the notebook. Not implemented yet
852
``AUI_NB_RIGHT`` With this style, tabs are drawn along the right of the notebook. Not implemented yet
853
``AUI_NB_BOTTOM`` With this style, tabs are drawn along the bottom of the notebook
882
854
``AUI_NB_TAB_SPLIT`` Allows the tab control to be split by dragging a tab
883
855
``AUI_NB_TAB_MOVE`` Allows a tab to be moved horizontally by dragging
884
856
``AUI_NB_TAB_EXTERNAL_MOVE`` Allows a tab to be moved to another tab control
888
860
``AUI_NB_CLOSE_BUTTON`` With this style, a close button is available on the tab bar
889
861
``AUI_NB_CLOSE_ON_ACTIVE_TAB`` With this style, a close button is available on the active tab
890
862
``AUI_NB_CLOSE_ON_ALL_TABS`` With this style, a close button is available on all tabs
891
``AUI_NB_MIDDLE_CLICK_CLOSE`` Allows to close AuiNotebook tabs by mouse middle button click
892
``AUI_NB_SUB_NOTEBOOK`` This style is used by AuiManager to create automatic AuiNotebooks
863
``AUI_NB_MIDDLE_CLICK_CLOSE`` Allows to close L{AuiNotebook} tabs by mouse middle button click
864
``AUI_NB_SUB_NOTEBOOK`` This style is used by L{AuiManager} to create automatic AuiNotebooks
893
865
``AUI_NB_HIDE_ON_SINGLE_TAB`` Hides the tab window if only one tab is present
894
866
``AUI_NB_SMART_TABS`` Use Smart Tabbing, like ``Alt`` + ``Tab`` on Windows
895
867
``AUI_NB_USE_IMAGES_DROPDOWN`` Uses images on dropdown window list menu instead of check items
896
868
``AUI_NB_CLOSE_ON_TAB_LEFT`` Draws the tab close button on the left instead of on the right (a la Camino browser)
897
869
``AUI_NB_TAB_FLOAT`` Allows the floating of single tabs. Known limitation: when the notebook is more or less full screen, tabs cannot be dragged far enough outside of the notebook to become floating pages
898
870
``AUI_NB_DRAW_DND_TAB`` Draws an image representation of a tab while dragging (on by default)
871
``AUI_NB_ORDER_BY_ACCESS`` Tab navigation order by last access time for the tabs
872
``AUI_NB_NO_TAB_FOCUS`` Don't draw tab focus rectangle
899
873
==================================== ==================================
901
875
:todo: Implementation of flags ``AUI_NB_RIGHT`` and ``AUI_NB_LEFT``.
905
879
self._agwFlags = agwFlags
907
881
# check for new close button settings
1257
1232
:param `offset`: the tab offset.
1260
1235
self._tab_offset = offset
1238
def MinimizeTabOffset(self, dc, wnd, max_width):
1240
Minimize `self._tab_offset` to fit as many tabs as possible in the available space.
1242
:param `dc`: a `wx.DC` device context;
1243
:param `wnd`: an instance of `wx.Window`;
1244
:param `max_width`: the maximum available width for the tabs.
1249
for i, page in reversed(list(enumerate(self._pages))):
1251
tab_button = self._tab_close_buttons[i]
1252
(tab_width, tab_height), x_extent = self._art.GetTabSize(dc, wnd, page.caption, page.bitmap, page.active, tab_button.cur_state, page.control)
1253
total_width += tab_width
1255
if total_width > max_width:
1259
if tab_offset < self._tab_offset and tab_offset < len(self._pages):
1260
self._tab_offset = tab_offset
1265
self._tab_offset = 0
1263
1268
def Render(self, raw_dc, wnd):
1265
Render() renders the tab catalog to the specified `wx.DC`.
1266
It is a virtual function and can be overridden to
1267
provide custom drawing capabilities.
1270
Renders the tab catalog to the specified `wx.DC`.
1272
It is a virtual function and can be overridden to provide custom drawing
1269
1275
:param `raw_dc`: a `wx.DC` device context;
1270
1276
:param `wnd`: an instance of `wx.Window`.
1320
1326
total_width += size[0]
1322
if i >= self._tab_offset:
1328
if i >= self._tab_offset:
1323
1329
if i+1 < page_count:
1324
1330
visible_width += x_extent
1326
1332
visible_width += size[0]
1328
1334
if total_width > self._rect.GetWidth() or self._tab_offset != 0:
1330
1336
# show left/right buttons
1331
1337
for button in self._buttons:
1332
1338
if button.id == AUI_BUTTON_LEFT or \
1333
1339
button.id == AUI_BUTTON_RIGHT:
1335
1341
button.cur_state &= ~AUI_BUTTON_STATE_HIDDEN
1339
1345
# hide left/right buttons
1340
1346
for button in self._buttons:
1341
1347
if button.id == AUI_BUTTON_LEFT or \
1342
1348
button.id == AUI_BUTTON_RIGHT:
1344
1350
button.cur_state |= AUI_BUTTON_STATE_HIDDEN
1346
1352
# determine whether left button should be enabled
1427
1433
if self._pages[i].control.IsShown():
1428
1434
self._pages[i].control.Hide()
1436
self.MinimizeTabOffset(dc, wnd, self._rect.GetWidth() - right_buttons_width - offset - 2)
1430
1438
# draw the tabs
1432
1440
active_offset = 0
1434
1442
rect = wx.Rect(*self._rect)
1436
1444
rect.height = self._rect.height
1438
1446
for i in xrange(self._tab_offset, page_count):
1440
1448
page = self._pages[i]
1441
1449
tab_button = self._tab_close_buttons[i]
1443
1451
# determine if a close button is on this tab
1444
1452
if (self._agwFlags & AUI_NB_CLOSE_ON_ALL_TABS and page.hasCloseButton) or \
1445
1453
(self._agwFlags & AUI_NB_CLOSE_ON_ACTIVE_TAB and page.active and page.hasCloseButton):
1447
1455
if tab_button.cur_state == AUI_BUTTON_STATE_HIDDEN:
1449
1457
tab_button.id = AUI_BUTTON_CLOSE
1450
1458
tab_button.cur_state = AUI_BUTTON_STATE_NORMAL
1451
1459
tab_button.location = wx.CENTER
1455
1463
tab_button.cur_state = AUI_BUTTON_STATE_HIDDEN
1457
1465
rect.x = offset
1458
1466
rect.width = self._rect.width - right_buttons_width - offset - 2
1788
1798
Gets the size which best suits the window: for a control, it would be the
1789
1799
minimal size which doesn't truncate the control, for a panel - the same
1790
1800
size as it would have after a call to `Fit()`.
1792
1802
:note: Overridden from `wx.PyControl`.
1795
1805
return wx.Size(self._rect.width, self._rect.height)
1798
1808
def OnSize(self, event):
1800
1810
Handles the ``wx.EVT_SIZE`` event for L{AuiTabCtrl}.
1802
:param `event`: a `wx.SizeEvent` event to be processed.
1812
:param `event`: a `wx.SizeEvent` event to be processed.
1805
1815
s = event.GetSize()
1806
1816
self.SetTabRect(wx.Rect(0, 0, s.GetWidth(), s.GetHeight()))
1809
1819
def OnLeftDown(self, event):
1811
1821
Handles the ``wx.EVT_LEFT_DOWN`` event for L{AuiTabCtrl}.
1813
:param `event`: a `wx.MouseEvent` event to be processed.
1823
:param `event`: a `wx.MouseEvent` event to be processed.
1816
1826
self.CaptureMouse()
1817
1827
self._click_pt = wx.Point(-1, -1)
1818
1828
self._is_dragging = False
1828
1838
# even if the tab is already active, because they may
1829
1839
# have multiple tab controls
1830
1840
if new_selection != self.GetActivePage() or isinstance(self.GetParent(), AuiNotebook):
1832
1842
e = AuiNotebookEvent(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING, self.GetId())
1833
1843
e.SetSelection(new_selection)
1834
1844
e.SetOldSelection(self.GetActivePage())
1835
1845
e.SetEventObject(self)
1836
1846
self.GetEventHandler().ProcessEvent(e)
1838
1848
self._click_pt.x = event.GetX()
1839
1849
self._click_pt.y = event.GetY()
1840
1850
self._click_tab = wnd
1852
page_index = self.GetActivePage()
1853
if page_index != wx.NOT_FOUND:
1854
self.GetWindowFromIdx(page_index).SetFocus()
1842
1856
if self._hover_button:
1843
1857
self._pressed_button = self._hover_button
1844
1858
self._pressed_button.cur_state = AUI_BUTTON_STATE_PRESSED
1862
1876
self._drag_image.EndDrag()
1863
1877
del self._drag_image
1864
1878
self._drag_image = None
1866
1880
event = AuiNotebookEvent(wxEVT_COMMAND_AUINOTEBOOK_CANCEL_DRAG, self.GetId())
1867
1881
event.SetSelection(self.GetIdxFromWindow(self._click_tab))
1868
1882
event.SetOldSelection(event.GetSelection())
1869
1883
event.SetEventObject(self)
1870
self.GetEventHandler().ProcessEvent(event)
1884
self.GetEventHandler().ProcessEvent(event)
1873
1887
def OnLeftUp(self, event):
1875
1889
Handles the ``wx.EVT_LEFT_UP`` event for L{AuiTabCtrl}.
1877
:param `event`: a `wx.MouseEvent` event to be processed.
1891
:param `event`: a `wx.MouseEvent` event to be processed.
1880
1894
self._on_button = False
1882
1896
if self._is_dragging:
1884
self._is_dragging = False
1885
if self._drag_image:
1886
self._drag_image.EndDrag()
1887
del self._drag_image
1888
self._drag_image = None
1889
self.GetParent().Refresh()
1891
1898
if self.HasCapture():
1892
1899
self.ReleaseMouse()
1901
self._is_dragging = False
1902
if self._drag_image:
1903
self._drag_image.EndDrag()
1904
del self._drag_image
1905
self._drag_image = None
1906
self.GetParent().Refresh()
1894
1908
evt = AuiNotebookEvent(wxEVT_COMMAND_AUINOTEBOOK_END_DRAG, self.GetId())
1895
1909
evt.SetSelection(self.GetIdxFromWindow(self._click_tab))
1896
1910
evt.SetOldSelection(evt.GetSelection())
1916
self.GetParent()._mgr.HideHint()
1902
1918
if self.HasCapture():
1903
1919
self.ReleaseMouse()
1921
if self._hover_button:
1922
self._pressed_button = self._hover_button
1905
1924
if self._pressed_button:
1907
1926
# make sure we're still clicking the button
1908
1927
button = self.ButtonHitTest(event.GetX(), event.GetY())
1910
1929
if button is None:
1913
1932
if button != self._pressed_button:
1914
1933
self._pressed_button = None
1920
1939
if self._pressed_button.cur_state & AUI_BUTTON_STATE_DISABLED == 0:
1922
1941
evt = AuiNotebookEvent(wxEVT_COMMAND_AUINOTEBOOK_BUTTON, self.GetId())
1923
1942
evt.SetSelection(self.GetIdxFromWindow(self._click_tab))
1924
1943
evt.SetInt(self._pressed_button.id)
1925
1944
evt.SetEventObject(self)
1926
self.GetEventHandler().ProcessEvent(evt)
1945
eventHandler = self.GetEventHandler()
1947
if eventHandler is not None:
1948
eventHandler.ProcessEvent(evt)
1928
1950
self._pressed_button = None
1930
1952
self._click_pt = wx.Point(-1, -1)
1931
1953
self._is_dragging = False
1932
1954
self._click_tab = None
2141
2176
# Apply the drag images offset
2142
2177
pos -= self._drag_img_offset
2143
2178
self._drag_image.Move(pos)
2146
2181
def OnLeaveWindow(self, event):
2148
2183
Handles the ``wx.EVT_LEAVE_WINDOW`` event for L{AuiTabCtrl}.
2150
:param `event`: a `wx.MouseEvent` event to be processed.
2185
:param `event`: a `wx.MouseEvent` event to be processed.
2153
2188
if self._hover_button:
2154
2189
self._hover_button.cur_state = AUI_BUTTON_STATE_NORMAL
2155
2190
self._hover_button = None
2160
2195
def OnButton(self, event):
2162
2197
Handles the ``EVT_AUINOTEBOOK_BUTTON`` event for L{AuiTabCtrl}.
2164
:param `event`: a L{AuiNotebookEvent} event to be processed.
2199
:param `event`: a L{AuiNotebookEvent} event to be processed.
2167
2202
button = event.GetInt()
2169
2204
if button == AUI_BUTTON_LEFT or button == AUI_BUTTON_RIGHT:
2170
2205
if button == AUI_BUTTON_LEFT:
2171
2206
if self.GetTabOffset() > 0:
2173
2208
self.SetTabOffset(self.GetTabOffset()-1)
2177
2212
self.SetTabOffset(self.GetTabOffset()+1)
2181
2216
elif button == AUI_BUTTON_WINDOWLIST:
2182
2217
idx = self.GetArtProvider().ShowDropDown(self, self._pages, self.GetActivePage())
2186
2221
e = AuiNotebookEvent(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING, self.GetId())
2187
2222
e.SetSelection(idx)
2188
2223
e.SetOldSelection(self.GetActivePage())
2189
2224
e.SetEventObject(self)
2190
2225
self.GetEventHandler().ProcessEvent(e)
2196
2231
def OnSetFocus(self, event):
2198
2233
Handles the ``wx.EVT_SET_FOCUS`` event for L{AuiTabCtrl}.
2200
:param `event`: a `wx.FocusEvent` event to be processed.
2235
:param `event`: a `wx.FocusEvent` event to be processed.
2276
2316
def OnKeyDown2(self, event):
2278
2320
Handles the ``wx.EVT_KEY_DOWN`` event for L{AuiTabCtrl}.
2280
:param `event`: a `wx.KeyEvent` event to be processed.
2322
:param `event`: a `wx.KeyEvent` event to be processed.
2324
:warning: This method implementation is now deprecated. Refer to L{OnKeyDown}
2325
for the correct one.
2283
print event.GetKeyCode(), event.ControlDown()
2284
2328
if self.GetActivePage() == -1:
2288
2332
# We can't leave tab processing to the system on Windows, tabs and keys
2289
2333
# get eaten by the system and not processed properly if we specify both
2290
2334
# wxTAB_TRAVERSAL and wxWANTS_CHARS. And if we specify just wxTAB_TRAVERSAL,
2440
2484
``wx.SIZE_AUTO_HEIGHT`` A -1 indicates that a class-specific default should be used for the height.
2441
2485
``wx.SIZE_USE_EXISTING`` Existing dimensions should be used if -1 values are supplied.
2442
2486
``wx.SIZE_ALLOW_MINUS_ONE`` Allow dimensions of -1 and less to be interpreted as real dimensions, not default values.
2443
``wx.SIZE_FORCE`` Normally, if the position and the size of the window are already the same as the parameters of this function, nothing is done. but with this flag a window resize may be forced even in this case (supported in wx 2.6.2 and later and only implemented for MSW and ignored elsewhere currently)
2487
``wx.SIZE_FORCE`` Normally, if the position and the size of the window are already the same as the parameters of this function, nothing is done. but with this flag a window resize may be forced even in this case (supported in wx 2.6.2 and later and only implemented for MSW and ignored elsewhere currently)
2444
2488
=================================== ======================================
2446
2490
:note: Overridden from `wx.PyControl`.
2467
2511
:note: Overridden from `wx.PyControl`.
2470
2514
return self._rect.width, self._rect.height
2473
2517
def Show(self, show=True):
2475
2519
Shows/hides the window.
2477
:param `show`: ``True`` to show the window, ``False`` otherwise.
2521
:param `show`: ``True`` to show the window, ``False`` otherwise.
2479
2523
:note: Overridden from `wx.PyControl`, this method always returns ``False`` as
2480
2524
L{TabFrame} should never be phisically shown on screen.
2486
2530
def DoSizing(self):
2487
2531
""" Does the actual sizing of the tab control. """
2489
2533
if not self._tabs:
2492
2536
hideOnSingle = ((self._tabs.GetAGWFlags() & AUI_NB_HIDE_ON_SINGLE_TAB) and \
2493
2537
self._tabs.GetPageCount() <= 1)
2495
2539
if not hideOnSingle and not self._parent._hide_tabs:
2496
2540
tab_height = self._tab_ctrl_height
2498
2542
self._tab_rect = wx.Rect(self._rect.x, self._rect.y, self._rect.width, self._tab_ctrl_height)
2500
if self._tabs.GetAGWFlags() & AUI_NB_BOTTOM:
2544
if self._tabs.GetAGWFlags() & AUI_NB_BOTTOM:
2501
2545
self._tab_rect = wx.Rect(self._rect.x, self._rect.y + self._rect.height - tab_height,
2502
2546
self._rect.width, tab_height)
2503
2547
self._tabs.SetDimensions(self._rect.x, self._rect.y + self._rect.height - tab_height,
2504
2548
self._rect.width, tab_height)
2505
2549
self._tabs.SetTabRect(wx.Rect(0, 0, self._rect.width, tab_height))
2509
2553
self._tab_rect = wx.Rect(self._rect.x, self._rect.y, self._rect.width, tab_height)
2510
2554
self._tabs.SetDimensions(self._rect.x, self._rect.y, self._rect.width, tab_height)
2511
2555
self._tabs.SetTabRect(wx.Rect(0, 0, self._rect.width, tab_height))
2513
2557
# TODO: elif (GetAGWFlags() & AUI_NB_LEFT)
2514
2558
# TODO: elif (GetAGWFlags() & AUI_NB_RIGHT)
2516
2560
self._tabs.Refresh()
2517
2561
self._tabs.Update()
2522
2566
self._tabs.SetDimensions(self._rect.x, self._rect.y, self._rect.width, tab_height)
2523
2567
self._tabs.SetTabRect(wx.Rect(0, 0, self._rect.width, tab_height))
2525
2569
pages = self._tabs.GetPages()
2527
2571
for page in pages:
2529
2573
height = self._rect.height - tab_height
2532
2576
# avoid passing negative height to wx.Window.SetSize(), this
2533
2577
# results in assert failures/GTK+ warnings
2536
2580
if self._tabs.GetAGWFlags() & AUI_NB_BOTTOM:
2537
2581
page.window.SetDimensions(self._rect.x, self._rect.y, self._rect.width, height)
2540
2584
page.window.SetDimensions(self._rect.x, self._rect.y + tab_height,
2541
2585
self._rect.width, height)
2543
2587
# TODO: elif (GetAGWFlags() & AUI_NB_LEFT)
2544
2588
# TODO: elif (GetAGWFlags() & AUI_NB_RIGHT)
2546
2590
if repr(page.window.__class__).find("AuiMDIChildFrame") >= 0:
2547
page.window.ApplyMDIChildFrameRect()
2591
page.window.ApplyMDIChildFrameRect()
2550
2594
def Update(self):
2552
2596
Calling this method immediately repaints the invalidated area of the window
2553
2597
and all of its children recursively while this would usually only happen when
2554
the flow of control returns to the event loop.
2598
the flow of control returns to the event loop.
2556
2600
:note: Notice that this function doesn't invalidate any area of the window so
2557
2601
nothing happens if nothing has been invalidated (i.e. marked as requiring a redraw).
2558
Use `Refresh` first if you want to immediately redraw the window unconditionally.
2602
Use `Refresh` first if you want to immediately redraw the window unconditionally.
2560
2604
:note: Overridden from `wx.PyControl`.
2594
2638
chosen by either the windowing system or wxPython, depending on platform;
2595
2639
:param `style`: the underlying `wx.PyPanel` window style;
2596
2640
:param `agwStyle`: the AGW-specific window style. This can be a combination of the following bits:
2598
2642
==================================== ==================================
2599
2643
Flag name Description
2600
2644
==================================== ==================================
2601
2645
``AUI_NB_TOP`` With this style, tabs are drawn along the top of the notebook
2602
2646
``AUI_NB_LEFT`` With this style, tabs are drawn along the left of the notebook. Not implemented yet.
2603
2647
``AUI_NB_RIGHT`` With this style, tabs are drawn along the right of the notebook. Not implemented yet.
2604
``AUI_NB_BOTTOM`` With this style, tabs are drawn along the bottom of the notebook.
2648
``AUI_NB_BOTTOM`` With this style, tabs are drawn along the bottom of the notebook
2605
2649
``AUI_NB_TAB_SPLIT`` Allows the tab control to be split by dragging a tab
2606
2650
``AUI_NB_TAB_MOVE`` Allows a tab to be moved horizontally by dragging
2607
2651
``AUI_NB_TAB_EXTERNAL_MOVE`` Allows a tab to be moved to another tab control
2611
2655
``AUI_NB_CLOSE_BUTTON`` With this style, a close button is available on the tab bar
2612
2656
``AUI_NB_CLOSE_ON_ACTIVE_TAB`` With this style, a close button is available on the active tab
2613
2657
``AUI_NB_CLOSE_ON_ALL_TABS`` With this style, a close button is available on all tabs
2614
``AUI_NB_MIDDLE_CLICK_CLOSE`` Allows to close AuiNotebook tabs by mouse middle button click
2615
``AUI_NB_SUB_NOTEBOOK`` This style is used by AuiManager to create automatic AuiNotebooks
2658
``AUI_NB_MIDDLE_CLICK_CLOSE`` Allows to close L{AuiNotebook} tabs by mouse middle button click
2659
``AUI_NB_SUB_NOTEBOOK`` This style is used by L{AuiManager} to create automatic AuiNotebooks
2616
2660
``AUI_NB_HIDE_ON_SINGLE_TAB`` Hides the tab window if only one tab is present
2617
2661
``AUI_NB_SMART_TABS`` Use Smart Tabbing, like ``Alt`` + ``Tab`` on Windows
2618
2662
``AUI_NB_USE_IMAGES_DROPDOWN`` Uses images on dropdown window list menu instead of check items
2619
2663
``AUI_NB_CLOSE_ON_TAB_LEFT`` Draws the tab close button on the left instead of on the right (a la Camino browser)
2620
2664
``AUI_NB_TAB_FLOAT`` Allows the floating of single tabs. Known limitation: when the notebook is more or less full screen, tabs cannot be dragged far enough outside of the notebook to become floating pages
2621
2665
``AUI_NB_DRAW_DND_TAB`` Draws an image representation of a tab while dragging (on by default)
2666
``AUI_NB_ORDER_BY_ACCESS`` Tab navigation order by last access time for the tabs
2667
``AUI_NB_NO_TAB_FOCUS`` Don't draw tab focus rectangle
2622
2668
==================================== ==================================
2624
2670
Default value for `agwStyle` is:
2690
2742
self.Bind(EVT_AUINOTEBOOK_DRAG_MOTION, self.OnTabDragMotion,
2691
2743
id=AuiBaseTabCtrlId, id2=AuiBaseTabCtrlId+500)
2692
2744
self.Bind(EVT_AUINOTEBOOK_CANCEL_DRAG, self.OnTabCancelDrag,
2693
id=AuiBaseTabCtrlId, id2=AuiBaseTabCtrlId+500)
2745
id=AuiBaseTabCtrlId, id2=AuiBaseTabCtrlId+500)
2694
2746
self.Bind(EVT_AUINOTEBOOK_BUTTON, self.OnTabButton,
2695
2747
id=AuiBaseTabCtrlId, id2=AuiBaseTabCtrlId+500)
2696
2748
self.Bind(EVT_AUINOTEBOOK_TAB_MIDDLE_DOWN, self.OnTabMiddleDown,
3023
3076
def SetAGWWindowStyleFlag(self, agwStyle):
3025
3078
Sets the AGW-specific style of the window.
3027
:param `agwStyle`: the new window style.
3080
:param `agwStyle`: the new window style. This can be a combination of the following bits:
3082
==================================== ==================================
3083
Flag name Description
3084
==================================== ==================================
3085
``AUI_NB_TOP`` With this style, tabs are drawn along the top of the notebook
3086
``AUI_NB_LEFT`` With this style, tabs are drawn along the left of the notebook. Not implemented yet.
3087
``AUI_NB_RIGHT`` With this style, tabs are drawn along the right of the notebook. Not implemented yet.
3088
``AUI_NB_BOTTOM`` With this style, tabs are drawn along the bottom of the notebook
3089
``AUI_NB_TAB_SPLIT`` Allows the tab control to be split by dragging a tab
3090
``AUI_NB_TAB_MOVE`` Allows a tab to be moved horizontally by dragging
3091
``AUI_NB_TAB_EXTERNAL_MOVE`` Allows a tab to be moved to another tab control
3092
``AUI_NB_TAB_FIXED_WIDTH`` With this style, all tabs have the same width
3093
``AUI_NB_SCROLL_BUTTONS`` With this style, left and right scroll buttons are displayed
3094
``AUI_NB_WINDOWLIST_BUTTON`` With this style, a drop-down list of windows is available
3095
``AUI_NB_CLOSE_BUTTON`` With this style, a close button is available on the tab bar
3096
``AUI_NB_CLOSE_ON_ACTIVE_TAB`` With this style, a close button is available on the active tab
3097
``AUI_NB_CLOSE_ON_ALL_TABS`` With this style, a close button is available on all tabs
3098
``AUI_NB_MIDDLE_CLICK_CLOSE`` Allows to close L{AuiNotebook} tabs by mouse middle button click
3099
``AUI_NB_SUB_NOTEBOOK`` This style is used by L{AuiManager} to create automatic AuiNotebooks
3100
``AUI_NB_HIDE_ON_SINGLE_TAB`` Hides the tab window if only one tab is present
3101
``AUI_NB_SMART_TABS`` Use Smart Tabbing, like ``Alt`` + ``Tab`` on Windows
3102
``AUI_NB_USE_IMAGES_DROPDOWN`` Uses images on dropdown window list menu instead of check items
3103
``AUI_NB_CLOSE_ON_TAB_LEFT`` Draws the tab close button on the left instead of on the right (a la Camino browser)
3104
``AUI_NB_TAB_FLOAT`` Allows the floating of single tabs. Known limitation: when the notebook is more or less full screen, tabs cannot be dragged far enough outside of the notebook to become floating pages
3105
``AUI_NB_DRAW_DND_TAB`` Draws an image representation of a tab while dragging (on by default)
3106
``AUI_NB_ORDER_BY_ACCESS`` Tab navigation order by last access time for the tabs
3107
``AUI_NB_NO_TAB_FOCUS`` Don't draw tab focus rectangle
3108
==================================== ==================================
3029
3110
:note: Please note that some styles cannot be changed after the window
3030
3111
creation and that `Refresh` might need to be be called after changing the
3548
3636
:param `page_idx`: the page index;
3549
3637
:param `colour`: an instance of `wx.Colour`.
3552
3640
if page_idx >= self._tabs.GetPageCount():
3555
3643
# update our own tab catalog
3556
3644
page_info = self._tabs.GetPage(page_idx)
3645
should_refresh = page_info.text_colour != colour
3557
3646
page_info.text_colour = colour
3559
3648
# update what's on screen
3560
3649
ctrl, ctrl_idx = self.FindTab(page_info.window)
3564
3653
info = ctrl.GetPage(ctrl_idx)
3654
should_refresh = should_refresh or info.text_colour != colour
3565
3655
info.text_colour = page_info.text_colour
3731
3823
:param `new_page`: the index of the new selection;
3732
3824
:param `force`: whether to force the selection or not.
3735
3826
wnd = self._tabs.GetWindowFromIdx(new_page)
3828
#Update page access time
3829
self._tabs.GetPages()[new_page].access_time = datetime.datetime.now()
3736
3831
if not wnd or not self.GetEnabled(new_page):
3737
3832
return self._curpage
3739
3834
# don't change the page unless necessary
3740
3835
# however, clicking again on a tab should give it the focus.
3741
3836
if new_page == self._curpage and not force:
3743
ctrl, ctrl_idx = self.FindTab(wnd)
3838
ctrl, ctrl_idx = self.FindTab(wnd)
3744
3839
if wx.Window.FindFocus() != ctrl:
3745
3840
ctrl.SetFocus()
3747
3842
return self._curpage
3749
3844
evt = AuiNotebookEvent(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING, self.GetId())
3750
3845
evt.SetSelection(new_page)
3751
3846
evt.SetOldSelection(self._curpage)
3752
3847
evt.SetEventObject(self)
3754
3849
if not self.GetEventHandler().ProcessEvent(evt) or evt.IsAllowed():
3756
3851
old_curpage = self._curpage
3757
3852
self._curpage = new_page
4024
4119
page_info = src_tabs.GetPage(src_idx)
4025
4120
if page_info.control:
4026
4121
self.ReparentControl(page_info.control, dest_tabs)
4028
4123
# create a pane info structure with the information
4029
4124
# about where the pane should be added
4030
4125
pane_info = framemanager.AuiPaneInfo().Bottom().CaptionVisible(False)
4032
4127
if direction == wx.LEFT:
4034
4129
pane_info.Left()
4035
4130
mouse_pt = wx.Point(0, cli_size.y/2)
4037
4132
elif direction == wx.RIGHT:
4039
4134
pane_info.Right()
4040
4135
mouse_pt = wx.Point(cli_size.x, cli_size.y/2)
4042
4137
elif direction == wx.TOP:
4044
4139
pane_info.Top()
4045
4140
mouse_pt = wx.Point(cli_size.x/2, 0)
4047
4142
elif direction == wx.BOTTOM:
4049
4144
pane_info.Bottom()
4050
4145
mouse_pt = wx.Point(cli_size.x/2, cli_size.y)
4052
4147
self._mgr.AddPane(new_tabs, pane_info, mouse_pt)
4053
4148
self._mgr.Update()
4055
4150
# remove the page from the source tabs
4056
4151
page_info.active = False
4058
4153
src_tabs.RemovePage(page_info.window)
4060
4155
if src_tabs.GetPageCount() > 0:
4061
4156
src_tabs.SetActivePage(0)
4062
4157
src_tabs.DoShowHide()
4063
4158
src_tabs.Refresh()
4065
4160
# add the page to the destination tabs
4066
4161
dest_tabs.InsertPage(page_info.window, page_info, 0)
4068
4163
if src_tabs.GetPageCount() == 0:
4069
4164
self.RemoveEmptyTabFrames()
4071
4166
self.DoSizing()
4072
4167
dest_tabs.DoShowHide()
4073
4168
dest_tabs.Refresh()
4325
4420
src_tabs = event.GetEventObject()
4326
4421
dest_tabs = self.GetTabCtrlFromPoint(client_pt)
4328
4423
if dest_tabs == src_tabs:
4330
src_tabs.SetCursor(wx.StockCursor(wx.CURSOR_ARROW))
4332
4425
# always hide the hint for inner-tabctrl drag
4333
4426
self._mgr.HideHint()
4335
4428
# if tab moving is not allowed, leave
4336
4429
if not self._agwFlags & AUI_NB_TAB_MOVE:
4339
4432
pt = dest_tabs.ScreenToClient(screen_pt)
4341
4434
# this is an inner-tab drag/reposition
4342
4435
dest_location_tab = dest_tabs.TabHitTest(pt.x, pt.y)
4344
4437
if dest_location_tab:
4346
4439
src_idx = event.GetSelection()
4347
4440
dest_idx = dest_tabs.GetIdxFromWindow(dest_location_tab)
4374
4468
if self._agwFlags & AUI_NB_TAB_FLOAT:
4375
4469
if self.IsMouseWellOutsideWindow():
4376
4470
hintRect = wx.RectPS(screen_pt, (400, 300))
4377
# Use CallAfter so we overwrite the hint that might be
4378
# shown by our superclass:
4379
wx.CallAfter(self._mgr.ShowHint, hintRect)
4471
# Use CallAfter so we overwrite the hint that might be
4472
# shown by our superclass:
4473
wx.CallAfter(self._mgr.ShowHint, hintRect)
4382
4476
# make sure we are not over the hint window
4384
4478
while tab_ctrl:
4385
4479
if isinstance(tab_ctrl, AuiTabCtrl):
4388
4482
tab_ctrl = tab_ctrl.GetParent()
4391
4485
nb = tab_ctrl.GetParent()
4395
4489
hint_rect = tab_ctrl.GetClientRect()
4396
4490
hint_rect.x, hint_rect.y = tab_ctrl.ClientToScreenXY(hint_rect.x, hint_rect.y)
4397
4491
self._mgr.ShowHint(hint_rect)
4402
4496
if not dest_tabs:
4403
4497
# we are either over a hint window, or not over a tab
4404
4498
# window, and there is no where to drag to, so exit
4407
4501
if self._agwFlags & AUI_NB_TAB_FLOAT:
4408
4502
if self.IsMouseWellOutsideWindow():
4409
4503
hintRect = wx.RectPS(screen_pt, (400, 300))
4410
# Use CallAfter so we overwrite the hint that might be
4411
# shown by our superclass:
4504
# Use CallAfter so we overwrite the hint that might be
4505
# shown by our superclass:
4412
4506
wx.CallAfter(self._mgr.ShowHint, hintRect)
4415
4509
# if there are less than two panes, split can't happen, so leave
4416
4510
if self._tabs.GetPageCount() < 2:
4420
4514
if not self._agwFlags & AUI_NB_TAB_SPLIT:
4424
src_tabs.SetCursor(wx.StockCursor(wx.CURSOR_SIZING))
4428
4519
hint_rect = dest_tabs.GetRect()
4429
4520
hint_rect.x, hint_rect.y = self.ClientToScreenXY(hint_rect.x, hint_rect.y)
4430
4521
self._mgr.ShowHint(hint_rect)
4433
4524
rect = self._mgr.CalculateHintRect(self._dummy_wnd, client_pt, zero)
4434
4525
if rect.IsEmpty():
4435
4526
self._mgr.HideHint()
4438
4529
hit_wnd = wx.FindWindowAtPoint(screen_pt)
4439
4530
if hit_wnd and not isinstance(hit_wnd, AuiNotebook):
4440
4531
tab_frame = self.GetTabFrameFromWindow(hit_wnd)
4566
4655
e2.SetEventObject(self)
4567
4656
self.GetEventHandler().ProcessEvent(e2)
4658
# notify the target notebook that the tab has been dragged
4659
e3 = AuiNotebookEvent(wxEVT_COMMAND_AUINOTEBOOK_DRAG_DONE, nb.GetId())
4660
e3.SetSelection(insert_idx)
4661
e3.SetOldSelection(insert_idx)
4662
e3.SetEventObject(nb)
4663
nb.GetEventHandler().ProcessEvent(e3)
4571
4667
if self._agwFlags & AUI_NB_TAB_FLOAT:
4572
self._mgr.HideHint()
4573
if self.IsMouseWellOutsideWindow():
4668
self._mgr.HideHint()
4669
if self.IsMouseWellOutsideWindow():
4574
4670
# Use CallAfter so we our superclass can deal with the event first
4575
4671
wx.CallAfter(self.FloatPage, self.GetSelection())
4579
4675
# only perform a tab split if it's allowed
4580
4676
dest_tabs = None
4582
4678
if self._agwFlags & AUI_NB_TAB_SPLIT and self._tabs.GetPageCount() >= 2:
4584
4680
# If the pointer is in an existing tab frame, do a tab insert
4585
4681
hit_wnd = wx.FindWindowAtPoint(mouse_screen_pt)
4586
4682
tab_frame = self.GetTabFrameFromTabCtrl(hit_wnd)
4587
4683
insert_idx = -1
4591
4687
dest_tabs = tab_frame._tabs
4593
4689
if dest_tabs == src_tabs:
4596
4692
pt = dest_tabs.ScreenToClient(mouse_screen_pt)
4597
4693
target = dest_tabs.TabHitTest(pt.x, pt.y)
4600
4696
insert_idx = dest_tabs.GetIdxFromWindow(target)
4604
4700
zero = wx.Point(0, 0)
4605
4701
rect = self._mgr.CalculateHintRect(self._dummy_wnd, mouse_client_pt, zero)
4607
4703
if rect.IsEmpty():
4608
4704
# there is no suitable drop location here, exit out
4611
4707
# If there is no tabframe at all, create one
4612
4708
new_tabs = TabFrame(self)
4613
4709
new_tabs._rect = wx.RectPS(wx.Point(0, 0), self.CalculateNewSplitSize())
4700
4794
:param `page_index`: the index of the page to be floated.
4702
4796
:warning: When the notebook is more or less full screen, tabs cannot be dragged far
4703
enough outside of the notebook to become floating pages.
4797
enough outside of the notebook to become floating pages.
4706
4800
root_manager = framemanager.GetManager(self)
4707
page_title = self.GetPageText(page_index)
4801
page_title = self.GetPageText(page_index)
4708
4802
page_contents = self.GetPage(page_index)
4709
4803
page_bitmap = self.GetPageBitmap(page_index)
4710
4804
text_colour = self.GetPageTextColour(page_index)
4711
4805
info = self.GetPageInfo(page_index)
4713
4807
if root_manager and root_manager != self._mgr:
4714
4808
root_manager = framemanager.GetManager(self)
4741
4835
self.GetActiveTabCtrl().DoShowHide()
4742
4836
self.DoSizing()
4743
4837
root_manager.Update()
4746
4840
frame = wx.Frame(self, title=page_title,
4747
4841
style=wx.DEFAULT_FRAME_STYLE|wx.FRAME_TOOL_WINDOW|
4748
wx.FRAME_FLOAT_ON_PARENT | wx.FRAME_NO_TASKBAR)
4842
wx.FRAME_FLOAT_ON_PARENT | wx.FRAME_NO_TASKBAR)
4750
4844
if info.control:
4751
4845
info.control.Reparent(frame)
4752
4846
info.control.Hide()
4754
frame.bitmap = page_bitmap
4848
frame.bitmap = page_bitmap
4755
4849
frame.page_index = page_index
4756
4850
frame.text_colour = text_colour
4757
4851
frame.control = info.control
4758
page_contents.Reparent(frame)
4759
frame.Bind(wx.EVT_CLOSE, self.OnCloseFloatingPage)
4760
frame.Move(wx.GetMousePosition())
4852
page_contents.Reparent(frame)
4853
frame.Bind(wx.EVT_CLOSE, self.OnCloseFloatingPage)
4854
frame.Move(wx.GetMousePosition())
4762
4856
self.RemovePage(page_index)
4764
4858
self.RemoveEmptyTabFrames()
4766
4860
wx.CallAfter(self.RemoveEmptyTabFrames)
4769
4863
def OnCloseFloatingPage(self, event):
4771
4865
Handles the ``wx.EVT_CLOSE`` event for a floating page in L{AuiNotebook}.
4773
:param `event`: a `wx.CloseEvent` event to be processed.
4867
:param `event`: a `wx.CloseEvent` event to be processed.
4776
4870
root_manager = framemanager.GetManager(self)
4779
4873
if pane.name.startswith("__floating__"):
4780
4874
self.ReDockPage(pane)
4786
frame = event.GetEventObject()
4787
page_title = frame.GetTitle()
4788
page_contents = frame.GetChildren()[-1]
4880
frame = event.GetEventObject()
4881
page_title = frame.GetTitle()
4882
page_contents = list(frame.GetChildren())[-1]
4789
4883
page_contents.Reparent(self)
4790
self.InsertPage(frame.page_index, page_contents, page_title, select=True, bitmap=frame.bitmap, control=control)
4884
self.InsertPage(frame.page_index, page_contents, page_title, select=True, bitmap=frame.bitmap, control=frame.control)
4792
4886
if frame.control:
4793
4887
src_tabs, idx = self.FindTab(page_contents)
4805
4899
:param `pane`: an instance of L{framemanager.AuiPaneInfo}.
4808
root_manager = framemanager.GetManager(self)
4902
root_manager = framemanager.GetManager(self)
4810
4904
pane.window.__floating_size__ = wx.Size(*pane.floating_size)
4811
4905
page_index = pane.window.__page_index__
4812
4906
text_colour = pane.window.__text_colour__
4813
4907
control = pane.window.__control__
4815
4909
root_manager.DetachPane(pane.window)
4816
4910
self.InsertPage(page_index, pane.window, pane.caption, True, pane.icon, control=control)
4989
5083
self._popupWin = TabNavigatorWindow(self, self._naviIcon)
4990
5084
self._popupWin.SetReturnCode(wx.ID_OK)
4991
5085
self._popupWin.ShowModal()
5086
idx = self._popupWin.GetSelectedPage()
4992
5087
self._popupWin.Destroy()
4993
5088
self._popupWin = None
5089
# Need to do CallAfter so that the selection and its
5090
# associated events get processed outside the context of
5091
# this key event. Not doing so causes odd issues with the
5092
# window focus under certain use cases on Windows.
5093
wx.CallAfter(self.SetSelection, idx, True)
4995
5095
# a dialog is already opened
4996
5096
self._popupWin.OnNavigationKey(event)
5027
5127
isFromSelf = event.GetEventObject() == self
5029
5129
if isFromParent or isFromSelf:
5031
5131
# no, it doesn't come from child, case (b) or (c): forward to a
5032
5132
# page but only if direction is backwards (TAB) or from ourselves,
5033
5133
if self.GetSelection() != wx.NOT_FOUND and (not event.GetDirection() or isFromSelf):
5035
5135
# so that the page knows that the event comes from it's parent
5036
5136
# and is being propagated downwards
5037
5137
event.SetEventObject(self)
5039
5139
page = self.GetPage(self.GetSelection())
5040
if not page.GetEventHandler().ProcessEvent(event):
5140
if not page.GetEventHandler().ProcessEvent(event):
5041
5141
page.SetFocus()
5043
5143
#else: page manages focus inside it itself
5045
5145
else: # otherwise set the focus to the notebook itself
5047
5147
self.SetFocus()
5051
5151
# send this event back for the 'wraparound' focus.
5052
5152
winFocus = event.GetCurrentFocus()
5527
5631
ctrl, ctrl_idx = self.FindTab(page_info.window)
5531
5635
info = ctrl.GetPage(ctrl_idx)
5532
5636
info.renamable = page_info.renamable
5537
5641
def IsRenamable(self, page_idx):
5539
5643
Returns whether a tab can be renamed or not.
5541
5645
:param `page_idx`: the page index.
5543
:returns: ``True`` is a page can be renamed, ``False`` otherwise.
5647
:returns: ``True`` is a page can be renamed, ``False`` otherwise.
5546
5650
if page_idx >= self._tabs.GetPageCount():
5583
5690
return not self.GetEventHandler().ProcessEvent(evt) or evt.IsAllowed()
5586
5693
def ResetTextControl(self):
5587
5694
""" Called by L{TabTextCtrl} when it marks itself for deletion. """
5589
5696
if not self._textCtrl:
5592
5699
self._textCtrl.Destroy()
5593
5700
self._textCtrl = None
5595
5702
# tab height might have changed
5596
5703
self.UpdateTabCtrlHeight(force=True)
5599
5706
def EditTab(self, page_index):
5601
5708
Starts the editing of an item label, sending a `EVT_AUINOTEBOOK_BEGIN_LABEL_EDIT` event.
5603
:param `page_index`: the page index we want to edit.
5710
:param `page_index`: the page index we want to edit.
5606
5713
if page_index >= self._tabs.GetPageCount():