how to get the current selected item from button event

hello

I tested some example. but I'm not sure how to get the selected item
index in order to collapse or expand stc control.

        self.ctrlsReverstDic[self.text.GetId()] = self.editor.GetId()

        self.Bind(wx.EVT_BUTTON, lambda event: self.OnClose(event,
id=self.text.GetId()), id=self.text.GetId())

    def OnClose(self, event, id):

        editor = wx.FindWindowById(self.ctrlsReverstDic[id])
        if self.IsCollapsed == False:
            editor.SetMinSize((-1, 1))
            self.IsCollapsed = True
        else:
            editor.SetMinSize((-1, 20 *
(editor.Text.strip().count('\n') + 1)))
            self.IsCollapsed = False

        self.Layout()

Wonjun, Choi

this is my example.

collapsebutton.py (5.15 KB)

Here you are binding a new lambda function to EVT_BUTTON using the event handler of the panel every time OnAddPython gets executed. So on every button press of any button you have a queue of these lambda functions are waiting to be called, only they don't all get called - only the first one in the queue gets called because the event isn't skipped. Also, they shouldn't all get called - that would fold everything. So if you think about it, it's a really convoluted way of not doing what you really want.

A few days ago I helped someone on #wxpython to do something similar to this, I've attached the end result. It may help you to try a different approach.

Toni

animated_folding.py (2.41 KB)

···

On Thu, 03 Nov 2011 09:21:50 +0100, Wonjun, Choi <wonjunchoi001@gmail.com> wrote:

hello

I tested some example. but I'm not sure how to get the selected item
index in order to collapse or expand stc control.

        self.Bind(wx.EVT_BUTTON, lambda event: self.OnClose(event,
id=self.text.GetId()), id=self.text.GetId())

hello

I tested some example. but I'm not sure how to get the selected item
index in order to collapse or expand stc control.

         self.ctrlsReverstDic[self.text.GetId()] = self.editor.GetId()

IIRC you used self.text and self.editor for many different instances and were told that this doesn't work as self.text will point you ONLY to the last instance and you can't get to the others from there.

         self.Bind(wx.EVT_BUTTON, lambda event: self.OnClose(event,
id=self.text.GetId()), id=self.text.GetId())

     def OnClose(self, event, id):

I wouldn't call this event handler "OnClose" that name is pretty often used for the close event handler for e.g. a frame or dialog.

         editor = wx.FindWindowById(self.ctrlsReverstDic[id])
         if self.IsCollapsed == False:
             editor.SetMinSize((-1, 1))
             self.IsCollapsed = True
         else:
             editor.SetMinSize((-1, 20 *
(editor.Text.strip().count('\n') + 1)))
             self.IsCollapsed = False

         self.Layout()

Maybe it is time for a new sample application:-) .

Werner

···

On 11/03/2011 09:21 AM, Wonjun, Choi wrote:

in attached example. each detail button was included in CommandRunner class

I have to include FlexGridSizer, ScrolledPanel, the class for each language.
so it will be hard work I think.

and there is still same issue in the example unless I use different CommandRunner for each language.

collapsebutton.py (5.15 KB)

Is there any alternative way?

can I do like this?

    self.ctrlsReverstDic[self.text.GetId()] = self.editor.GetId()
    self.Bind(wx.EVT_BUTTON, lambda event: self.OnClose(event, id=self.GetItemIndex(self.text)), id=self.text.GetId())

def OnClose(self, event, id):

    editor = wx.FindWindowById(self.ctrlsReverstDic[id])
    if self.IsCollapsed == False:
        editor.SetMinSize((-1, 1))
        self.IsCollapsed = True
    else:
        editor.SetMinSize((-1, 20 * (editor.Text.strip().count('\n') + 1)))
        self.IsCollapsed = False
       
    self.Layout()

I think I found the solution thought there is some bug.
thanks