How to refresh a label of a button

Hi,
I have a button and after the button is pressed I need to change their label and
continue with the routines, after the routines end I need to change the label again.
The problem it that the label doesn’t change it goes to to the routines after the SetLabel.

My question is how can I refresh the button (I try mybutton.refresh() without result)

thank you for your help.

Jorge wrote:

Hi,
I have a button and after the button is pressed I need to change their label and
continue with the routines, after the routines end I need to change the label again.
The problem it that the label doesn't change it goes to to the routines after the SetLabel.

My question is how can I refresh the button (I try mybutton.refresh() without result)

thank you for your help.

Normally you just call SetLabel() on your button instance in the event handler:

<code>

myBtn.SetLabel("New Value")

</code>

Then call a function. However, it sounds like you're blocking wxPython's mainloop, so try calling a refresh on the panel or frame BEFORE calling your long running task.

If that doesn't work, send us a small runnable example: http://wiki.wxpython.org/MakingSampleApps

···

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org
Python Extension Building Network: http://www.pythonlibrary.org

Thank Mike,
but how can I do a panel / frame refresh?

I’m to “young” in wxpython.

···

On Fri, Jan 30, 2009 at 10:11 PM, Mike Driscoll mike@pythonlibrary.org wrote:

Jorge wrote:

Hi,

I have a button and after the button is pressed I need to change their label and

continue with the routines, after the routines end I need to change the label again.

The problem it that the label doesn’t change it goes to to the routines after the SetLabel.

My question is how can I refresh the button (I try mybutton.refresh() without result)

thank you for your help.

Normally you just call SetLabel() on your button instance in the event handler:

myBtn.SetLabel(“New Value”)

Then call a function. However, it sounds like you’re blocking wxPython’s mainloop, so try calling a refresh on the panel or frame BEFORE calling your long running task.

If that doesn’t work, send us a small runnable example: http://wiki.wxpython.org/MakingSampleApps


Mike Driscoll

Blog: http://blog.pythonlibrary.org

Python Extension Building Network: http://www.pythonlibrary.org


wxpython-users mailing list

wxpython-users@lists.wxwidgets.org

http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

Jorge wrote:

Thank Mike,
but how can I do a panel / frame refresh?

In my applications, I usually have something like this:

<code>

import wx

class MyForm(wx.Frame):

    def __init__(self):

        wx.Frame.__init__(self, None, title="My Frame")
        self.panel = wx.Panel(self, wx.ID_ANY)
        self.myBtn = wx.Button(self.panel, wx.ID_ANY, "Push Me")

        self.Bind(wx.EVT_BUTTON, self.onBtnPress, self.myBtn)

    def onBtnPress(self, event):
        self.myBtn.SetLabel("New Label")
        #self.Refresh() or self.panel.Refresh()
        for x in range(5):
            print "sleep"
            wx.Sleep(1)
        print "awake!"

if __name__ == "__main__": app = wx.PySimpleApp()
    frame = MyForm().Show()
    app.MainLoop()
       </code>

Depending on how you have you application set up, you can call Refresh with "self" or with "self.panel" or "self.frame" or even "self.btn.GetParent().Refresh()"

My fake long running process didn't seem to stop my button from changing even when I commented out the Refresh() calls though, so I'm not really sure what you're doing differently...

···

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org
Python Extension Building Network: http://www.pythonlibrary.org

I'm to "young" in wxpython.

On Fri, Jan 30, 2009 at 10:11 PM, Mike Driscoll > <mike@pythonlibrary.org <mailto:mike@pythonlibrary.org>> wrote:

    Jorge wrote:

        Hi,
        I have a button and after the button is pressed I need to
        change their label and
        continue with the routines, after the routines end I need to
        change the label again.
        The problem it that the label doesn't change it goes to to the
        routines after the SetLabel.

        My question is how can I refresh the button (I try
        mybutton.refresh() without result)

        thank you for your help.

    Normally you just call SetLabel() on your button instance in the
    event handler:

    <code>

    myBtn.SetLabel("New Value")

    </code>

    Then call a function. However, it sounds like you're blocking
    wxPython's mainloop, so try calling a refresh on the panel or
    frame BEFORE calling your long running task.

    If that doesn't work, send us a small runnable example:
    http://wiki.wxpython.org/MakingSampleApps

    -------------------
    Mike Driscoll

    Blog: http://blog.pythonlibrary.org
    Python Extension Building Network: http://www.pythonlibrary.org

    _______________________________________________
    wxpython-users mailing list
    wxpython-users@lists.wxwidgets.org
    <mailto:wxpython-users@lists.wxwidgets.org>
    http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

------------------------------------------------------------------------

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

your code doesn’t work also :frowning:

I try calling the refresh in the ways you told me, but with out any result.

···

On Fri, Jan 30, 2009 at 10:22 PM, Mike Driscoll mike@pythonlibrary.org wrote:

Jorge wrote:

Thank Mike,

but how can I do a panel / frame refresh?

In my applications, I usually have something like this:

import wx

class MyForm(wx.Frame):

def init(self):

   wx.Frame.__init__(self, None, title="My Frame")

   self.panel = wx.Panel(self, wx.ID_ANY)

   self.myBtn = wx.Button(self.panel, wx.ID_ANY, "Push Me")



   self.Bind(wx.EVT_BUTTON, self.onBtnPress, self.myBtn)

def onBtnPress(self, event):

   self.myBtn.SetLabel("New Label")

   #self.Refresh() or self.panel.Refresh()

   for x in range(5):

       print "sleep"

       wx.Sleep(1)

   print "awake!"

if name == “main”: app = wx.PySimpleApp()

frame = MyForm().Show()

app.MainLoop()

  </code>

Depending on how you have you application set up, you can call Refresh with “self” or with “self.panel” or “self.frame” or even “self.btn.GetParent().Refresh()”

My fake long running process didn’t seem to stop my button from changing even when I commented out the Refresh() calls though, so I’m not really sure what you’re doing differently…


Mike Driscoll

Blog: http://blog.pythonlibrary.org

Python Extension Building Network: http://www.pythonlibrary.org

I’m to “young” in wxpython.

On Fri, Jan 30, 2009 at 10:11 PM, Mike Driscoll <mike@pythonlibrary.org mailto:mike@pythonlibrary.org> wrote:

Jorge wrote:



    Hi,

    I have a button and after the button is pressed I need to

    change their label and

    continue with the routines, after the routines end I need to

    change the label again.

    The problem it that the label doesn't change it goes to to the

    routines after the SetLabel.



    My question is how can I refresh the button (I try

    mybutton.refresh() without result)



    thank you for your help.





Normally you just call SetLabel() on your button instance in the

event handler:



<code>



myBtn.SetLabel("New Value")



</code>



Then call a function. However, it sounds like you're blocking

wxPython's mainloop, so try calling a refresh on the panel or

frame BEFORE calling your long running task.



If that doesn't work, send us a small runnable example:

[http://wiki.wxpython.org/MakingSampleApps](http://wiki.wxpython.org/MakingSampleApps)



-------------------

Mike Driscoll



Blog:   [http://blog.pythonlibrary.org](http://blog.pythonlibrary.org)

Python Extension Building Network:     [http://www.pythonlibrary.org](http://www.pythonlibrary.org)



_______________________________________________

wxpython-users mailing list

wxpython-users@lists.wxwidgets.org

mailto:wxpython-users@lists.wxwidgets.org

[http://lists.wxwidgets.org/mailman/listinfo/wxpython-users](http://lists.wxwidgets.org/mailman/listinfo/wxpython-users)


wxpython-users mailing list

wxpython-users@lists.wxwidgets.org

http://lists.wxwidgets.org/mailman/listinfo/wxpython-users


wxpython-users mailing list

wxpython-users@lists.wxwidgets.org

http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

Jorge wrote:

your code doesn't work also :frowning:

I try calling the refresh in the ways you told me, but with out any result.

It worked for me on Windows XP SP3, wxPython 2.8.9.1 and Python 2.5.2. What are you using?

Mike

···

On Fri, Jan 30, 2009 at 10:22 PM, Mike Driscoll > <mike@pythonlibrary.org <mailto:mike@pythonlibrary.org>> wrote:

    Jorge wrote:

        Thank Mike,
        but how can I do a panel / frame refresh?

    In my applications, I usually have something like this:

    <code>

    import wx

    class MyForm(wx.Frame):

      def __init__(self):

          wx.Frame.__init__(self, None, title="My Frame")
          self.panel = wx.Panel(self, wx.ID_ANY)
          self.myBtn = wx.Button(self.panel, wx.ID_ANY, "Push Me")

          self.Bind(wx.EVT_BUTTON, self.onBtnPress, self.myBtn)

      def onBtnPress(self, event):
          self.myBtn.SetLabel("New Label")
          #self.Refresh() or self.panel.Refresh()
          for x in range(5):
              print "sleep"
              wx.Sleep(1)
          print "awake!"

    if __name__ == "__main__": app = wx.PySimpleApp()
      frame = MyForm().Show()
      app.MainLoop()
         </code>

    Depending on how you have you application set up, you can call
    Refresh with "self" or with "self.panel" or "self.frame" or even
    "self.btn.GetParent().Refresh()"

    My fake long running process didn't seem to stop my button from
    changing even when I commented out the Refresh() calls though, so
    I'm not really sure what you're doing differently...

    -------------------
    Mike Driscoll

    Blog: http://blog.pythonlibrary.org
    Python Extension Building Network: http://www.pythonlibrary.org

        I'm to "young" in wxpython.

        On Fri, Jan 30, 2009 at 10:11 PM, Mike Driscoll > <mike@pythonlibrary.org <mailto:mike@pythonlibrary.org> > <mailto:mike@pythonlibrary.org > <mailto:mike@pythonlibrary.org>>> wrote:

           Jorge wrote:

               Hi,
               I have a button and after the button is pressed I need to
               change their label and
               continue with the routines, after the routines end I
        need to
               change the label again.
               The problem it that the label doesn't change it goes to
        to the
               routines after the SetLabel.

               My question is how can I refresh the button (I try
               mybutton.refresh() without result)

               thank you for your help.

           Normally you just call SetLabel() on your button instance
        in the
           event handler:

           <code>

           myBtn.SetLabel("New Value")

           </code>

           Then call a function. However, it sounds like you're blocking
           wxPython's mainloop, so try calling a refresh on the panel or
           frame BEFORE calling your long running task.

           If that doesn't work, send us a small runnable example:
           http://wiki.wxpython.org/MakingSampleApps

           -------------------
           Mike Driscoll

           Blog: http://blog.pythonlibrary.org
           Python Extension Building Network: http://www.pythonlibrary.org

           _______________________________________________
           wxpython-users mailing list
           wxpython-users@lists.wxwidgets.org
        <mailto:wxpython-users@lists.wxwidgets.org>
           <mailto:wxpython-users@lists.wxwidgets.org
        <mailto:wxpython-users@lists.wxwidgets.org>>

           http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

        ------------------------------------------------------------------------

        _______________________________________________
        wxpython-users mailing list
        wxpython-users@lists.wxwidgets.org
        <mailto:wxpython-users@lists.wxwidgets.org>
        http://lists.wxwidgets.org/mailman/listinfo/wxpython-users
         
    _______________________________________________
    wxpython-users mailing list
    wxpython-users@lists.wxwidgets.org
    <mailto:wxpython-users@lists.wxwidgets.org>
    http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

------------------------------------------------------------------------

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

Hello,

Jorge wrote:

your code doesn't work also :frowning:

I try calling the refresh in the ways you told me, but with out any result.

If your routine is blocking the main loop then calling Refresh wont help because refresh causes a paint event to be sent which won't be processed until control returns to the main loop.

You can either try

myButton.Refresh()
myButton.Update() # <- Force the repaint
myRoutine()

Or if that fails try calling Yield to let the main loop have a chance to process pending events before going into your routine.

myButton.Refresh()
wx.SafeYield()
myRoutine()

Cody

···

On Jan 31, 2009, at 9:58 AM, Mike Driscoll wrote:

Jorge wrote:

your code doesn't work also :frowning:

I try calling the refresh in the ways you told me, but with out any result.

Hi Jorge, you should really just post your code or a small runnable
sample and people can help you figure out what the issue is.
http://wiki.wxpython.org/MakingSampleApps

···

On Sat, Jan 31, 2009 at 10:58 AM, Mike Driscoll <mike@pythonlibrary.org> wrote:

It worked for me on Windows XP SP3, wxPython 2.8.9.1 and Python 2.5.2. What are you using?

Mike

On Fri, Jan 30, 2009 at 10:22 PM, Mike Driscoll <mike@pythonlibrary.org <mailto:mike@pythonlibrary.org>> wrote:

   Jorge wrote:

       Thank Mike,
       but how can I do a panel / frame refresh?

   In my applications, I usually have something like this:

   <code>

   import wx

   class MyForm(wx.Frame):

     def __init__(self):

         wx.Frame.__init__(self, None, title="My Frame")
         self.panel = wx.Panel(self, wx.ID_ANY)
         self.myBtn = wx.Button(self.panel, wx.ID_ANY, "Push Me")

         self.Bind(wx.EVT_BUTTON, self.onBtnPress, self.myBtn)

     def onBtnPress(self, event):
         self.myBtn.SetLabel("New Label")
         #self.Refresh() or self.panel.Refresh()
         for x in range(5):
             print "sleep"
             wx.Sleep(1)
         print "awake!"

   if __name__ == "__main__": app = wx.PySimpleApp()
     frame = MyForm().Show()
     app.MainLoop()
        </code>

   Depending on how you have you application set up, you can call
   Refresh with "self" or with "self.panel" or "self.frame" or even
   "self.btn.GetParent().Refresh()"

   My fake long running process didn't seem to stop my button from
   changing even when I commented out the Refresh() calls though, so
   I'm not really sure what you're doing differently...

   -------------------
   Mike Driscoll

   Blog: http://blog.pythonlibrary.org
   Python Extension Building Network: http://www.pythonlibrary.org

       I'm to "young" in wxpython.

       On Fri, Jan 30, 2009 at 10:11 PM, Mike Driscoll >> <mike@pythonlibrary.org <mailto:mike@pythonlibrary.org> >> <mailto:mike@pythonlibrary.org >> <mailto:mike@pythonlibrary.org>>> wrote:

          Jorge wrote:

              Hi,
              I have a button and after the button is pressed I need to
              change their label and
              continue with the routines, after the routines end I
       need to
              change the label again.
              The problem it that the label doesn't change it goes to
       to the
              routines after the SetLabel.

              My question is how can I refresh the button (I try
              mybutton.refresh() without result)

              thank you for your help.

          Normally you just call SetLabel() on your button instance
       in the
          event handler:

          <code>

          myBtn.SetLabel("New Value")

          </code>

          Then call a function. However, it sounds like you're blocking
          wxPython's mainloop, so try calling a refresh on the panel or
          frame BEFORE calling your long running task.

          If that doesn't work, send us a small runnable example:
          http://wiki.wxpython.org/MakingSampleApps

          -------------------
          Mike Driscoll

          Blog: http://blog.pythonlibrary.org
          Python Extension Building Network: http://www.pythonlibrary.org

          _______________________________________________
          wxpython-users mailing list
          wxpython-users@lists.wxwidgets.org
       <mailto:wxpython-users@lists.wxwidgets.org>
          <mailto:wxpython-users@lists.wxwidgets.org
       <mailto:wxpython-users@lists.wxwidgets.org>>

          http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

       ------------------------------------------------------------------------

       _______________________________________________
       wxpython-users mailing list
       wxpython-users@lists.wxwidgets.org
       <mailto:wxpython-users@lists.wxwidgets.org>
       http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

   _______________________________________________
   wxpython-users mailing list
   wxpython-users@lists.wxwidgets.org
   <mailto:wxpython-users@lists.wxwidgets.org>
   http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

------------------------------------------------------------------------

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

Ubuntu 8.10 86_64, python 2.5 wxpython 2.8.8.0

···

On Sat, Jan 31, 2009 at 3:58 PM, Mike Driscoll mike@pythonlibrary.org wrote:

Jorge wrote:

your code doesn’t work also :frowning:

I try calling the refresh in the ways you told me, but with out any result.

It worked for me on Windows XP SP3, wxPython 2.8.9.1 and Python 2.5.2. What are you using?

Mike

On Fri, Jan 30, 2009 at 10:22 PM, Mike Driscoll <mike@pythonlibrary.org mailto:mike@pythonlibrary.org> wrote:

Jorge wrote:



    Thank Mike,

    but how can I do a panel / frame refresh?





In my applications, I usually have something like this:



<code>



import wx



class MyForm(wx.Frame):



  def __init__(self):



      wx.Frame.__init__(self, None, title="My Frame")

      self.panel = wx.Panel(self, wx.ID_ANY)

      self.myBtn = wx.Button(self.panel, wx.ID_ANY, "Push Me")



      self.Bind(wx.EVT_BUTTON, self.onBtnPress, self.myBtn)



  def onBtnPress(self, event):

      self.myBtn.SetLabel("New Label")

      #self.Refresh() or self.panel.Refresh()

      for x in range(5):

          print "sleep"

          wx.Sleep(1)

      print "awake!"



if __name__ == "__main__":     app = wx.PySimpleApp()

  frame = MyForm().Show()

  app.MainLoop()

     </code>



Depending on how you have you application set up, you can call

Refresh with "self" or with "self.panel" or "self.frame" or even

"self.btn.GetParent().Refresh()"



My fake long running process didn't seem to stop my button from

changing even when I commented out the Refresh() calls though, so

I'm not really sure what you're doing differently...





-------------------

Mike Driscoll



Blog:   [http://blog.pythonlibrary.org](http://blog.pythonlibrary.org)

Python Extension Building Network:     [http://www.pythonlibrary.org](http://www.pythonlibrary.org)









    I'm to "young" in wxpython.



    On Fri, Jan 30, 2009 at 10:11 PM, Mike Driscoll

    <mike@pythonlibrary.org <mailto:mike@pythonlibrary.org>

<mailto:mike@pythonlibrary.org

    <mailto:mike@pythonlibrary.org>>> wrote:



       Jorge wrote:



           Hi,

           I have a button and after the button is pressed I need to

           change their label and

           continue with the routines, after the routines end I

    need to

           change the label again.

           The problem it that the label doesn't change it goes to

    to the

           routines after the SetLabel.



           My question is how can I refresh the button (I try

           mybutton.refresh() without result)



           thank you for your help.





       Normally you just call SetLabel() on your button instance

    in the

       event handler:



       <code>



       myBtn.SetLabel("New Value")



       </code>



       Then call a function. However, it sounds like you're blocking

       wxPython's mainloop, so try calling a refresh on the panel or

       frame BEFORE calling your long running task.



       If that doesn't work, send us a small runnable example:

       [http://wiki.wxpython.org/MakingSampleApps](http://wiki.wxpython.org/MakingSampleApps)



       -------------------

       Mike Driscoll



       Blog:   [http://blog.pythonlibrary.org](http://blog.pythonlibrary.org)

       Python Extension Building Network:            [http://www.pythonlibrary.org](http://www.pythonlibrary.org)



       _______________________________________________

       wxpython-users mailing list

       wxpython-users@lists.wxwidgets.org

    <mailto:wxpython-users@lists.wxwidgets.org>

       <mailto:wxpython-users@lists.wxwidgets.org

    <mailto:wxpython-users@lists.wxwidgets.org>>



       [http://lists.wxwidgets.org/mailman/listinfo/wxpython-users](http://lists.wxwidgets.org/mailman/listinfo/wxpython-users)





    ------------------------------------------------------------------------







    _______________________________________________

    wxpython-users mailing list

    wxpython-users@lists.wxwidgets.org

    <mailto:wxpython-users@lists.wxwidgets.org>

    [http://lists.wxwidgets.org/mailman/listinfo/wxpython-users](http://lists.wxwidgets.org/mailman/listinfo/wxpython-users)

    



_______________________________________________

wxpython-users mailing list

wxpython-users@lists.wxwidgets.org

<mailto:wxpython-users@lists.wxwidgets.org>

[http://lists.wxwidgets.org/mailman/listinfo/wxpython-users](http://lists.wxwidgets.org/mailman/listinfo/wxpython-users)


wxpython-users mailing list

wxpython-users@lists.wxwidgets.org

http://lists.wxwidgets.org/mailman/listinfo/wxpython-users


wxpython-users mailing list

wxpython-users@lists.wxwidgets.org

http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

I will try Cody Precord solution and if it doesn’t work I will post the sample.

Thank you.

···

On Sat, Jan 31, 2009 at 6:36 PM, Jorge starglider101@gmail.com wrote:

Ubuntu 8.10 86_64, python 2.5 wxpython 2.8.8.0

On Sat, Jan 31, 2009 at 3:58 PM, Mike Driscoll mike@pythonlibrary.org wrote:

Jorge wrote:

your code doesn’t work also :frowning:

I try calling the refresh in the ways you told me, but with out any result.

It worked for me on Windows XP SP3, wxPython 2.8.9.1 and Python 2.5.2. What are you using?

Mike

On Fri, Jan 30, 2009 at 10:22 PM, Mike Driscoll <mike@pythonlibrary.org mailto:mike@pythonlibrary.org> wrote:

Jorge wrote:



    Thank Mike,

    but how can I do a panel / frame refresh?





In my applications, I usually have something like this:



<code>



import wx



class MyForm(wx.Frame):



  def __init__(self):



      wx.Frame.__init__(self, None, title="My Frame")

      self.panel = wx.Panel(self, wx.ID_ANY)

      self.myBtn = wx.Button(self.panel, wx.ID_ANY, "Push Me")



      self.Bind(wx.EVT_BUTTON, self.onBtnPress, self.myBtn)



  def onBtnPress(self, event):

      self.myBtn.SetLabel("New Label")

      #self.Refresh() or self.panel.Refresh()

      for x in range(5):

          print "sleep"

          wx.Sleep(1)

      print "awake!"



if __name__ == "__main__":     app = wx.PySimpleApp()

  frame = MyForm().Show()

  app.MainLoop()

     </code>



Depending on how you have you application set up, you can call

Refresh with "self" or with "self.panel" or "self.frame" or even

"self.btn.GetParent().Refresh()"



My fake long running process didn't seem to stop my button from

changing even when I commented out the Refresh() calls though, so

I'm not really sure what you're doing differently...





-------------------

Mike Driscoll



Blog:   [http://blog.pythonlibrary.org](http://blog.pythonlibrary.org)

Python Extension Building Network:     [http://www.pythonlibrary.org](http://www.pythonlibrary.org)









    I'm to "young" in wxpython.



    On Fri, Jan 30, 2009 at 10:11 PM, Mike Driscoll

    <mike@pythonlibrary.org <mailto:mike@pythonlibrary.org>

<mailto:mike@pythonlibrary.org

    <mailto:mike@pythonlibrary.org>>> wrote:



       Jorge wrote:



           Hi,

           I have a button and after the button is pressed I need to

           change their label and

           continue with the routines, after the routines end I

    need to

           change the label again.

           The problem it that the label doesn't change it goes to

    to the

           routines after the SetLabel.



           My question is how can I refresh the button (I try

           mybutton.refresh() without result)



           thank you for your help.





       Normally you just call SetLabel() on your button instance

    in the

       event handler:



       <code>



       myBtn.SetLabel("New Value")



       </code>



       Then call a function. However, it sounds like you're blocking

       wxPython's mainloop, so try calling a refresh on the panel or

       frame BEFORE calling your long running task.



       If that doesn't work, send us a small runnable example:

       [http://wiki.wxpython.org/MakingSampleApps](http://wiki.wxpython.org/MakingSampleApps)



       -------------------

       Mike Driscoll



       Blog:   [http://blog.pythonlibrary.org](http://blog.pythonlibrary.org)

       Python Extension Building Network:            [http://www.pythonlibrary.org](http://www.pythonlibrary.org)



       _______________________________________________

       wxpython-users mailing list

       wxpython-users@lists.wxwidgets.org

    <mailto:wxpython-users@lists.wxwidgets.org>

       <mailto:wxpython-users@lists.wxwidgets.org

    <mailto:wxpython-users@lists.wxwidgets.org>>



       [http://lists.wxwidgets.org/mailman/listinfo/wxpython-users](http://lists.wxwidgets.org/mailman/listinfo/wxpython-users)





    ------------------------------------------------------------------------







    _______________________________________________

    wxpython-users mailing list

    wxpython-users@lists.wxwidgets.org

    <mailto:wxpython-users@lists.wxwidgets.org>

    [http://lists.wxwidgets.org/mailman/listinfo/wxpython-users](http://lists.wxwidgets.org/mailman/listinfo/wxpython-users)

    



_______________________________________________

wxpython-users mailing list

wxpython-users@lists.wxwidgets.org

<mailto:wxpython-users@lists.wxwidgets.org>

[http://lists.wxwidgets.org/mailman/listinfo/wxpython-users](http://lists.wxwidgets.org/mailman/listinfo/wxpython-users)


wxpython-users mailing list

wxpython-users@lists.wxwidgets.org

http://lists.wxwidgets.org/mailman/listinfo/wxpython-users


wxpython-users mailing list

wxpython-users@lists.wxwidgets.org

http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

Hi Cody,
your 1st solution doesn’t work
but the second one disables the form but change the label of the button and when my routine ends it enable the

···

On Sat, Jan 31, 2009 at 4:07 PM, Cody Precord codyprecord@gmail.com wrote:

Hello,

On Jan 31, 2009, at 9:58 AM, Mike Driscoll wrote:

Jorge wrote:

your code doesn’t work also :frowning:

I try calling the refresh in the ways you told me, but with out any result.

If your routine is blocking the main loop then calling Refresh wont help because refresh causes a paint event to be sent which won’t be processed until control returns to the main loop.

You can either try

myButton.Refresh()

myButton.Update() # ← Force the repaint

myRoutine()

Or if that fails try calling Yield to let the main loop have a chance to process pending events before going into your routine.

myButton.Refresh()

wx.SafeYield()

myRoutine()

Cody


wxpython-users mailing list

wxpython-users@lists.wxwidgets.org

http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

Cody Precord wrote:

Or if that fails try calling Yield to let the main loop have a chance to process pending events before going into your routine.

Or don't block returning to the main loop and do your long running task in some other way.

http://wiki.wxpython.org/LongRunningTasks
http://wiki.wxpython.org/Non-Blocking_Gui

···

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

Hi to everybody,
here is a sample, without my code that lies in another module, but with Mike’s loop
to simulate the routine:
#!/usr/bin/python

-- coding: cp1252 --

import wx
import wx.html

class Janela(wx.Frame):
def init(self):
wx.Frame.init(self, None, -1, “Recovery 1.0”, size=(800, 600), pos=(400,250))

    panel = wx.Panel(self, -1)
    ini = 132
    tam = 800 - ini
    self.edtPathSource = wx.TextCtrl(panel,-1,"",size=(tam,32),pos=(ini,1),style=wx.TE_READONLY|wx.TE_LEFT)
    self.edtPathTarget = wx.TextCtrl(panel,-1,"",size=(tam,32),pos=(ini,64),style=wx.TE_READONLY|wx.TE_LEFT)
    self.btnPathSource = wx.Button(panel,-1,label="Source", pos=(ini,32), size=(tam,32))
    self.btnPathTarget = wx.Button(panel,-1,label="Target", pos=(ini,96), size=(tam,32))
    self.btnAnalisa = wx.Button(panel,-1,label="Waiting 4 input", pos=(ini,160), size=(tam,32))
    self.btnExit = wx.Button(panel,-1,label="Exit", pos=(ini,192), size=(tam,32))

                                                                                                                                                                                                                                                                                                                                                                                                                                                 
    self.lstDatas = wx.ListBox(panel,-1,(1,1),(ini,599),['Empty'],wx.LB_SINGLE)
   
    self.Bind(wx.EVT_BUTTON,self.OnClickPathSource, self.btnPathSource)
    self.Bind(wx.EVT_BUTTON,self.OnClickExit, self.btnExit)
    self.Bind(wx.EVT_BUTTON,self.OnClickAnalisa, self.btnAnalisa)
    self.Bind(wx.EVT_BUTTON,self.OnClickPathTarget, self.btnPathTarget)
   
   
def OnClickPathSource(self, event):
    print 'Dialog'

def OnClickPathTarget(self, event):
    print 'dialog'
def OnClickExit(self, event):
    exit() 
   
def OnClickAnalisa(self, event):
    self.btnAnalisa.SetLabel('Working')
    self.btnAnalisa.Refresh()
    self.lstDatas.Clear()
    for x in range(5):
      print "sleep"
      wx.Sleep(1)
    print "awake!"

if name == ‘main’:
app = wx.PySimpleApp()
frame = Janela()
frame.Show(True)
app.MainLoop()

Thank you.

···

On Sat, Jan 31, 2009 at 10:55 PM, Robin Dunn robin@alldunn.com wrote:

Cody Precord wrote:

Or if that fails try calling Yield to let the main loop have a chance to process pending events before going into your routine.

Or don’t block returning to the main loop and do your long running task in some other way.

http://wiki.wxpython.org/LongRunningTasks

http://wiki.wxpython.org/Non-Blocking_Gui

Robin Dunn

Software Craftsman

http://wxPython.org Java give you jitters? Relax with wxPython!


wxpython-users mailing list

wxpython-users@lists.wxwidgets.org

http://lists.wxwidgets.org/mailman/listinfo/wxpython-users