oakward event

lo,

I am having problem with tree event in my tiny implementation of Mediator pattern.
In my window, i have 2 events :
* one on a wxButton which work fine
* one on a wxTreeCtrl which causing me trouble : NOTHING happens (no output, warning nor error)
the aim of my app, is having to widget which produce the same event : outputting in the text area (and testing the pattern :slight_smile: )

tinyMediator.py (2.18 KB)

路路路

-----------
class MyApp(wx.App):

聽聽聽聽def OnInit(self):
聽聽聽聽聽聽聽聽mainWindow = wx.Frame(None, -1, "TinyMediator")
聽聽聽聽聽聽聽聽tinySizer = wx.BoxSizer(wx.VERTICAL)

聽聽聽聽聽聽聽聽tinyMediator = Mediator()
聽聽聽聽聽聽聽聽zoneText = TextArea(mainWindow)
聽聽聽聽聽聽聽聽copyBut = CopyButton(mainWindow, tinyMediator)
聽聽聽聽聽聽聽聽tinyTree = TinyTree(mainWindow, tinyMediator)

聽聽聽聽聽聽聽聽tinyMediator.registerTextView(zoneText)

聽聽聽聽聽聽聽聽tinySizer.Add(zoneText, 1, wx.EXPAND)
聽聽聽聽聽聽聽聽tinySizer.Add(copyBut, 1, wx.EXPAND)
聽聽聽聽聽聽聽聽tinySizer.Add(tinyTree, 1, wx.EXPAND)

聽聽聽聽聽聽聽聽wx.EVT_TREE_SEL_CHANGED(mainWindow, tinyTree.GetId(), tinyTree.execute)
聽聽聽聽聽聽聽聽wx.EVT_BUTTON(mainWindow, copyBut.GetId(), copyBut.execute)

聽聽聽聽聽聽聽聽mainWindow.SetSizerAndFit(tinySizer)

聽聽聽聽聽聽聽聽mainWindow.Show(wx.true)

聽聽聽聽聽聽聽聽# Show the Application as the top window
聽聽聽聽聽聽聽聽self.SetTopWindow(mainWindow)
聽聽聽聽聽聽聽聽return wx.true
-----------

If someone has any id??!!

Regards,

---kevin

keke wrote:

lo,

I am having problem with tree event in my tiny implementation of Mediator pattern.
In my window, i have 2 events :
* one on a wxButton which work fine
* one on a wxTreeCtrl which causing me trouble : NOTHING happens (no output, warning nor error)
the aim of my app, is having to widget which produce the same event : outputting in the text area (and testing the pattern :slight_smile: )

[...]

class TinyTree(wx.TreeCtrl):

    def __init__(self, parent, mediator):
        self.treeId = wx.NewId()

Here you make an ID...

        print self.treeId
        wx.TreeCtrl.__init__(self, parent, wx.NewId(), size=(200,100))

but here you use a new one, not self.treeId.

        self.mediator = mediator

        rootId = self.AddRoot("Root")
        self.AppendItem(rootId, "feuille1")
        self.AppendItem(rootId, "feuille2")

    def execute(self, event):
        print event
        self.mediator.copy()

    def GetId(self):
        return self.treeId

This returns the original one you created.

        wx.EVT_TREE_SEL_CHANGED(mainWindow, tinyTree.GetId(), tinyTree.execute)

And that is what you bind the event to. IOW, you are looking for events from a tree with tinyTree.treeId, but the tree was created with ID=tinyTree.treeId+1.

BTW, there is really no need to override GetId. (If you hadn't then your example would have worked eventhough you used wx.NewId in the call to __init__.)

路路路

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!