WxPython : Button Events
<p>Is there a way, that I could bind two events to a button in a sequential way. What I mean is as following: </p>

<p>In this example buttons 1 &amp; 2 are bonded to their events respectively. </p>

<pre><code>self.button1 = wx.Button(panel, -1, 'BUTTON1')
self.button1.Bind(wx.EVT_BUTTON, self.OnButton1)

self.button2 = wx.Button(panel, -1, 'Button2')
self.button2.Bind(wx.EVT_BUTTON, self.OnButton2)


def OnButton1(self,event):
    a = 1
    b = 3
    print a+b # basically some commands
    # Here I want to execute OnButton2 EVENT - So I use the following LINE
    OnButton2(event)
    # But the above command should not be executed unless the OnButton2 event has processed in the past - (Meaning unless the Button2 event has happen in the past) So How would I solve that problem.
    # It should be like IF CONDITION (BUTTON 2 HAS BEEN PRESSED IN THE PAST) - EXECUTE: SOME BASIC COMMANDS LIKE PRINT "HELLO"

def OnButton2(self,event):
    c = 4
    d = 5
    print c*d
</code></pre>

<pre><code>    self.button1 = wx.Button(panel, -1, 'BUTTON1')
    self.button1.Bind(wx.EVT_BUTTON, self.OnButton1)

    self.button2 = wx.Button(panel, -1, 'Button2')
    self.button2.Bind(wx.EVT_BUTTON, self.OnButton2)

    def OnButton1(self,event):
        #why not call a function directly beforehand?
        self.DoSomething(args)
        a = 1
        b = 3
        print a+b # basically some commands

    def OnButton2(self,event):
        self.DoSomething(args) 

    def DoSomething(self,args):
        c = 4
        d = 5
        print c*d
</code></pre>

<p>why not just use a separate function to call from within OnButton1?</p>

<p>Not sure why one would wait for OnButton2 event if you have click button one? </p>

<p>in the above, you can pass some argument(s) to DoSomething and have it return some value and then you can continue</p>

<p>For example</p>

<pre><code>    def OnButton1(self,event):

        value = self.DoSomething(11)
        a = 1
        b = 3

        new_value = a + b + value


    def DoSomething(self, args):
        c = 4
        d = 5
        e = args
        value = c + d + e
        print value

        return value
</code></pre>

<p>Updated: have OnButton2 work with some instance value. therefore, when OnButton1 checks to see if it is no longer None, you know OnButton2 event has been raised</p>

<pre><code>    self.value = None

    def OnButton1(self,event):

        if not self.value:
            return #still None, OnButton2 event hasn't been raised

        #else, continue working with value    
        value = self.DoSomething(11)
        a = 1
        b = 3

        new_value = a + b + value

    def OnButton2(self,event):
        self.value = 5
</code></pre>

python button wxpython