Hi, thanks everyone for the great help in the recent past.
I am really strugling to find a way to process an left click on a tab
in the code below. See OnTest and the binding just above.
Maybe the structure of the code looks really strange to you, but hey
this is from my much larger app I am writting, so I can not really
change the structure now.
TIA Samuel.
import wx, wx.grid, wx.html, wx.aui
import wx.lib.agw.aui as aui
from wx.lib.agw.aui import aui_switcherdialog as ASD
···
#----------------------------------------------------------------------
def createPanes(frame):
#temporarely moved out of class PyAUIframe, for learning purposes
only
zl, zt, zw, zh = wx.ClientDisplayRect()
useSize = (zw-zl,zh-zt)
frame.tabControl = frame.CreateNotebook()
frame._mgr.AddPane(frame.tabControl,
wx.aui.AuiPaneInfo().Name("notebook_content").
CenterPane().BestSize(useSize).MinSize(useSize).PaneBorder(False))
class PyAUIFrame(wx.Frame):
def __init__(self, parent, id=-1, title="",
pos=wx.DefaultPosition,
size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE |
wx.SUNKEN_BORDER | wx.CLIP_CHILDREN ):
wx.Frame.__init__(self, parent, id, title, pos,
wx.DisplaySize() , style)
self.Maximize()
# tell FrameManager to manage this frame
self._mgr = wx.aui.AuiManager()
self._mgr.SetManagedWindow(self)
#Hard code a frame minimum size
zl, zt, zw, zh = wx.ClientDisplayRect()
self.SetMinSize((zw-zl, zh-zt))
# set up default notebook style
self._notebook_style = aui.AUI_NB_TAB_EXTERNAL_MOVE |
wx.NO_BORDER | aui.AUI_NB_TOP | aui.AUI_NB_TAB_SPLIT |
aui.AUI_NB_TAB_MOVE | aui.AUI_NB_SCROLL_BUTTONS |
aui.AUI_NB_DRAW_DND_TAB
self._notebook_theme = 0
createPanes(self)
self._mgr.GetPane("notebook_content").Show()
self._mgr.Update()
self.x= 0 #used for floating panes
self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
self.Bind(wx.EVT_SIZE, self.OnSize)
self.Bind(wx.EVT_CLOSE, self.OnClose)
self.Bind(wx.EVT_MENU, self.OnExit, id=wx.ID_EXIT)
self.Bind(wx.EVT_LEFT_DOWN, self.OnTest)
self.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CHANGING, self.OnTest)
self.Bind(wx.aui.EVT_AUINOTEBOOK_BUTTON, self.OnTest)
for widget in self.tabControl.GetChildren():
if isinstance(widget, wx.aui.AuiTabCtrl):
widget.Bind(wx.EVT_LEFT_DOWN, self.OnTest)
def OnTest(self, event):
#here I would like to see which tab clicked on, so I do some
preprocessing
#of relevant data before the tab is show (obviously the tab in
not a simple
#textctrl but a complex one with lots of different widgets.
iAmAnIdiotWhoDoesNotUnderstandPythonVeryWell = True
pass
def Exit(self):
self.OnExit(wx.EVT_MENU)
def OnClose(self, event):
self._mgr.UnInit()
del self._mgr
self.Destroy()
def OnExit(self, event):
self.Close()
def DoUpdate(self):
self._mgr.Update()
def OnEraseBackground(self, event):
event.Skip()
def OnSize(self, event):
event.Skip()
def CreateNotebook(self):
client_size = self.GetClientSize()
ctrl = aui.AuiNotebook(self, -1, wx.Point(client_size.x,
client_size.y),
wx.Size(430, 200),
self._notebook_style)
arts = [aui.AuiDefaultTabArt, aui.AuiSimpleTabArt,
aui.VC71TabArt, aui.FF2TabArt,
aui.VC8TabArt, aui.ChromeTabArt]
art = arts[self._notebook_theme]()
ctrl.SetArtProvider(art)
page_bmp = wx.ArtProvider.GetBitmap(wx.ART_NORMAL_FILE,
wx.ART_OTHER, wx.Size(16, 16))
ctrl.AddPage(wx.TextCtrl(ctrl, -1, "Some text",
wx.DefaultPosition, wx.DefaultSize,
wx.TE_MULTILINE|wx.NO_BORDER),
"wxTextCtrl 1", False, page_bmp)
ctrl.AddPage(wx.TextCtrl(ctrl, -1, "Some more text",
wx.DefaultPosition, wx.DefaultSize,
wx.TE_MULTILINE|wx.NO_BORDER),
"wxTextCtrl 2")
ctrl.AddPage(wx.TextCtrl(ctrl, -1, "Some more text",
wx.DefaultPosition, wx.DefaultSize,
wx.TE_MULTILINE|wx.NO_BORDER),
"wxTextCtrl 3")
return ctrl
#----------------------------------------------------------------------------
class testApp(wx.App):
def __init__(self, name):
self.name = name
wx.App.__init__(self, redirect=False)
def OnInit(self):
zl, zt, zw, zh = wx.ClientDisplayRect()
useSize = (zw-zl,zh-zt)
frame = PyAUIFrame(None, wx.ID_ANY, "wx.aui wxPython Demo",
size=useSize)
frame.Maximize()
frame.Show()
return True
if __name__ == '__main__':
name = 'apprender'
app = testApp(name)
app.MainLoop()