Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #12370 > unrolled thread

Button Label change on EVT_BUTTON in wxpython!!!

Started byVen <praveen.venkata@gmail.com>
First post2011-08-28 18:30 -0700
Last post2011-08-29 17:46 +0000
Articles 3 — 3 participants

Back to article view | Back to comp.lang.python


Contents

  Button Label change on EVT_BUTTON in wxpython!!! Ven <praveen.venkata@gmail.com> - 2011-08-28 18:30 -0700
    Re: Button Label change on EVT_BUTTON in wxpython!!! Philip Semanchuk <philip@semanchuk.com> - 2011-08-28 22:34 -0400
    Re: Button Label change on EVT_BUTTON in wxpython!!! Rob Williscroft <rtw@rtw.me.uk> - 2011-08-29 17:46 +0000

#12370 — Button Label change on EVT_BUTTON in wxpython!!!

FromVen <praveen.venkata@gmail.com>
Date2011-08-28 18:30 -0700
SubjectButton Label change on EVT_BUTTON in wxpython!!!
Message-ID<aa1212bb-35e5-4bf9-b8ad-7a3c083749c2@x2g2000yql.googlegroups.com>
Some system info before proceeding further:

Platform: Mac OS X 10.7.1
Python Version: ActiveState Python 2.7.1
wxPython Version: [url=http://downloads.sourceforge.net/wxpython/
wxPython2.9-osx-2.9.2.1-cocoa-py2.7.dmg]wxPython2.9-osx-cocoa-py2.7[/
url]

I want the button label to be changed while performing a task

So, here is what I did/want:

self.run_button=wx.Button(self.panel,ID_RUN_BUTTON,label='Install')
self.Bind(wx.EVT_BUTTON, self.OnRun,id=ID_RUN_BUTTON)

def OnRun(self,evt):
	self.run_button.SetLabel('Installing..')
	#call a function that does the installation task
	installation_task()
	#After task completion, set the button label back to "Install"
	self.run_button.SetLabel('Install')

When I try doing this, it doesn't set the label to "Installing" while
the task is being performed. Any suggestions how do I achieve this?

[toc] | [next] | [standalone]


#12375

FromPhilip Semanchuk <philip@semanchuk.com>
Date2011-08-28 22:34 -0400
Message-ID<mailman.529.1314585301.27778.python-list@python.org>
In reply to#12370
On Aug 28, 2011, at 9:30 PM, Ven wrote:

> Some system info before proceeding further:
> 
> Platform: Mac OS X 10.7.1
> Python Version: ActiveState Python 2.7.1
> wxPython Version: [url=http://downloads.sourceforge.net/wxpython/
> wxPython2.9-osx-2.9.2.1-cocoa-py2.7.dmg]wxPython2.9-osx-cocoa-py2.7[/
> url]
> 
> I want the button label to be changed while performing a task
> 
> So, here is what I did/want:
> 
> self.run_button=wx.Button(self.panel,ID_RUN_BUTTON,label='Install')
> self.Bind(wx.EVT_BUTTON, self.OnRun,id=ID_RUN_BUTTON)
> 
> def OnRun(self,evt):
> 	self.run_button.SetLabel('Installing..')
> 	#call a function that does the installation task
> 	installation_task()
> 	#After task completion, set the button label back to "Install"
> 	self.run_button.SetLabel('Install')
> 
> When I try doing this, it doesn't set the label to "Installing" while
> the task is being performed. Any suggestions how do I achieve this?


Suggestion #1: After you set the label to "Installing...", try adding self.run_button.Refresh() and/or self.run_button.Update().

Suggestion #2: Ask wxPython questions on the wxPython mailing list.

Good luck
Philip

[toc] | [prev] | [next] | [standalone]


#12410

FromRob Williscroft <rtw@rtw.me.uk>
Date2011-08-29 17:46 +0000
Message-ID<mailman.549.1314640033.27778.python-list@python.org>
In reply to#12370
Ven wrote in news:aa1212bb-35e5-4bf9-b8ad-7a3c083749c2
@x2g2000yql.googlegroups.com in gmane.comp.python.general:

> So, here is what I did/want:
> 
> self.run_button=wx.Button(self.panel,ID_RUN_BUTTON,label='Install')
> self.Bind(wx.EVT_BUTTON, self.OnRun,id=ID_RUN_BUTTON)
> 
> def OnRun(self,evt):
>      self.run_button.SetLabel('Installing..')
>      #call a function that does the installation task
>      installation_task()
>      #After task completion, set the button label back to "Install"
>      self.run_button.SetLabel('Install')
> 
> When I try doing this, it doesn't set the label to "Installing" while
> the task is being performed. Any suggestions how do I achieve this?
> 

http://wiki.wxpython.org/CallAfter

Using this your OnRun will become somthing like:

def OnRun( self, evt ):
  def after():
    installation_task()
    self.run_button.SetLabel('Install')
  self.run_button.SetLabel('Installing..')
  wx.Callafter( after )

However if installation_task takes a long time you will need to use
threads, something like (untested):

def OnRun( self, evt ):
  def after():
    self.run_button.SetLabel('Install')
  def task():
    installation_task()
    wx.Callafter( after )

  self.run_button.SetLabel('Installing..')

  import threading
  threading.Thread( target = task ).start()

Rob.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web