Howdy. I have another question on DSW related to event handling and in particular EVT_DYNAMIC_SASH_SPLIT.
I have a TreeCtrl inside a DSW and I seem to have to bind to EVT_DYNAMIC_SASH_SPLIT in the TreeCtrl code.
This seems a little weird to me. It seems like the correct place to bind should be in a derived class of DSW, e.g.
class MyDSW(wx.gizmos.DynamicSashWindow):
def __init__(self,*args, **kwargs):
super(MyDSW, self).__init__(*args, **kwargs)
self.Bind(wx.gizmos.EVT_DYNAMIC_SASH_SPLIT, self.OnSplit)
def OnSplit(self, evt):
print "caught the split event"
My rationale for saying this is simply that it seems to me that the DWS manages the splitting, not the
TreeCtrl. It just seems wrong to have the MyTreeCtrl creating another MyTreeCtrl instance.
That said, I tested the above code, and OnSplit never fires. This is surprising to me since EVT_DYNAMIC_SASH_SPLIT
is a command event and should propagate up the chain.
As usual there is something I don't understand, so if someone would be gracious enought to give me a clue, I'd appreciate it.
Danny
Here's the test code FWIW:
#%<-------------------------------------------------------------------------
import wx
import wx.gizmos
class MainFrame(wx.Frame):
def __init__(self, *args, **kwargs):
super(MainFrame,self).__init__(*args, **kwargs)
self.comboPanel = ComboPanel(self,wx.ID_ANY)
self.Show(True)
class MyDSW(wx.gizmos.DynamicSashWindow):
def __init__(self,*args, **kwargs):
super(MyDSW, self).__init__(*args, **kwargs)
self.Bind(wx.gizmos.EVT_DYNAMIC_SASH_SPLIT, self.OnSplit)
def OnSplit(self, evt):
print "caught the split event" #NEVER FIRES
class ComboPanel(wx.Panel):
def __init__(self, *args, **kwargs):
super(ComboPanel, self).__init__(*args, **kwargs)
self.splitter=wx.SplitterWindow(self, wx.ID_ANY)
self.splitter.SetMinimumPaneSize(100)
self.dsw = MyDSW(self.splitter,wx.ID_ANY)
self.tree = MyTree(self.dsw)
self.rightPanel=RightPanel(self.splitter, wx.ID_ANY)
self.splitter.SplitVertically(self.dsw, self.rightPanel, -200)
mainSizer = wx.BoxSizer(wx.VERTICAL)
mainSizer.Add(self.splitter, proportion=1, flag=wx.EXPAND|wx.ALL, border=20)
self.SetSizer(mainSizer)
class MyTree(wx.TreeCtrl):
def __init__(self, parent):
super(MyTree, self).__init__(parent, wx.ID_ANY, style=wx.TR_HAS_BUTTONS|wx.TR_EDIT_LABELS|wx.TR_LINES_AT_ROOT)
self.AddRoot("root")
font=self.GetFont()
font.SetPointSize(10)
self.SetFont(font)
#UNCOMMENT NEXT 3 LINES FOR A BINDING THAT DOES WORK
# self.Bind(wx.gizmos.EVT_DYNAMIC_SASH_SPLIT, self.OnSplit)
# def OnSplit(self, evt):
# print "caught the split event" #Will Fire
class RightPanel(wx.Panel):
def __init__(self, *args, **kwargs):
super(RightPanel, self).__init__(*args, **kwargs)
bottomlabel = wx.StaticText(self, -1,"Properties Editor", (5,5))
class App(wx.App):
def OnInit(self):
self.title = 'Logic Model'
self.mainFrame = MainFrame(None, wx.ID_ANY,self.title ,size=(750, 750),pos=(0,0),
style=wx.DEFAULT_FRAME_STYLE|wx.NO_FULL_REPAINT_ON_RESIZE)
return True
app = App(0)
app.MainLoop()