Wxpython, using more than 1 timer?
Hi all,
Using wx
When adding a second timer as i have the first, the second timer
adding stops the first timer (updating or stops?) . In this example im
updating a uptime and localtime label. It works fine for displaying the
last "self.startTimer2()" called. But prevents the previous
self.startTimer1() from running . Im doing something fundamentally
wrong i guess?
def __init__(self, parent):
self._init_ctrls(parent)
#Start timers
self.startTimer1()
self.startTimer2()
def startTimer1(self):
self.t1 = wx.Timer(self)
self.t1.Start(360) # 36 ms = 1/10 hour
self.Bind(wx.EVT_TIMER, self.OnUpTime)
def startTimer2(self):
self.t2 = wx.Timer(self)
self.t2.Start(1000) # run every second
self.Bind(wx.EVT_TIMER, self.OnTime)
def OnTime(self,evt):
self.lblTime.SetLabel(str(time.localtime()))
def OnUpTime(self, evt):
self.lblUptime.SetLabel('Running ' + (str(myTimerText[0])) + '
hours') # 1/10 hour count
myTimerText[0] = myTimerText[0] + .1
Any help appreciated, ta
--
http://mail.python.org/mailman/listinfo/python-list
Re: Wxpython, using more than 1 timer?
Thanks for that, cheers
Regards
nikie wrote:
> janama wrote:
>
> > Hi all,
> >
> > Using wx
> > When adding a second timer as i have the first, the second timer
> > adding stops the first timer (updating or stops?) . In this example im
> > updating a uptime and localtime label. It works fine for displaying the
> > last "self.startTimer2()" called. But prevents the previous
> > self.startTimer1() from running . Im doing something fundamentally
> > wrong i guess?
> >
> > def __init__(self, parent):
> > self._init_ctrls(parent)
> >
> > #Start timers
> > self.startTimer1()
> > self.startTimer2()
> >
> > def startTimer1(self):
> > self.t1 = wx.Timer(self)
> > self.t1.Start(360) # 36 ms = 1/10 hour
> > self.Bind(wx.EVT_TIMER, self.OnUpTime)
> >
> > def startTimer2(self):
> > self.t2 = wx.Timer(self)
> > self.t2.Start(1000) # run every second
> > self.Bind(wx.EVT_TIMER, self.OnTime)
> >
> > def OnTime(self,evt):
> > self.lblTime.SetLabel(str(time.localtime()))
> >
> > def OnUpTime(self, evt):
> > self.lblUptime.SetLabel('Running ' + (str(myTimerText[0])) + '
> > hours') # 1/10 hour count
> > myTimerText[0] = myTimerText[0] + .1
> >
> > Any help appreciated, ta
>
> The problem is not that the first timer ist stopped, the problem is
> that both timers happen to call the same method in the end.
>
> Think of the "Bind" method as an assignment: it assigns a handler
> function to an event source. If you call it twice for the same event
> source, the second call will overwrite the first event handler. That's
> what happens in your code.
>
> The easiest way to change this is by using different ids for the
> timers:
>
> def startTimer1(self):
> self.t1 = wx.Timer(self, id=1)
> self.t1.Start(2000)
> self.Bind(wx.EVT_TIMER, self.OnUpTime, id=1)
>
> def startTimer2(self):
> self.t2 = wx.Timer(self, id=2)
> self.t2.Start(1000)
> self.Bind(wx.EVT_TIMER, self.OnTime, id=2)
>
> This way, the timers launch two different events, which are bound to
> two different methods.
--
http://mail.python.org/mailman/listinfo/python-list
Newbie wxpython staticbitmap help please
Hi, how do i go about having my little gui (boa) app updating
(changing) the bitmap used in a StaticBitmap automatically. In the
example below when i click the button the app check checks to see if a
file exists and if so it swaps the StaticBitmap in the gui to another
bitmap.
Can somewhone add a wx.Timer example to this to make it check
if the file exists every minute or so , instead of clicking the button
to check and update this? Or is there a better way of auto updating my
little gui apps StaticBitmap if a file exists?
Thanks for any help with this
Regards
Frame1
# Frame 1
#Boa:Frame:Frame1
import wx
import os
def create(parent):
return Frame1(parent)
[wxID_FRAME1, wxID_FRAME1BUTTON1, wxID_FRAME1PANEL1,
wxID_FRAME1STATICBITMAP1,
] = [wx.NewId() for _init_ctrls in range(4)]
class Frame1(wx.Frame):
def _init_ctrls(self, prnt):
# generated method, don't edit
wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt,
pos=wx.Point(535, 346), size=wx.Size(175, 109),
style=wx.DEFAULT_FRAME_STYLE, title='Frame1')
self.SetClientSize(wx.Size(167, 75))
self.panel1 = wx.Panel(id=wxID_FRAME1PANEL1, name='panel1',
parent=self,
pos=wx.Point(0, 0), size=wx.Size(167, 75),
style=wx.TAB_TRAVERSAL)
self.staticBitmap1 =
wx.StaticBitmap(bitmap=wx.Bitmap('Z:/Dan/scripting/python/gui/up1.png',
wx.BITMAP_TYPE_PNG), id=wxID_FRAME1STATICBITMAP1,
name='staticBitmap1', parent=self.panel1,
pos=wx.Point(16, 24),
size=wx.Size(32, 32), style=0)
self.button1 = wx.Button(id=wxID_FRAME1BUTTON1,
label='button1',
name='button1', parent=self.panel1, pos=wx.Point(64, 24),
size=wx.Size(88, 32), style=0)
self.button1.Bind(wx.EVT_BUTTON, self.OnButton1Button,
id=wxID_FRAME1BUTTON1)
def __init__(self, parent):
self._init_ctrls(parent)
def OnButton1Button(self, event):
if os.path.isfile('Z:/Dan/scripting/python/gui/p1.txt'):
i = wx.Image('Z:/Dan/scripting/python/gui/up2.png',
wx.BITMAP_TYPE_PNG)
b1 = wx.BitmapFromImage(i)
self.staticBitmap1.SetBitmap(b1)
event.Skip()
App1
#!/usr/bin/env python
#Boa:App:BoaApp
import wx
import Frame1
modules ={'Frame1': [1, 'Main frame of Application', 'Frame1.py']}
class BoaApp(wx.App):
def OnInit(self):
wx.InitAllImageHandlers()
self.main = Frame1.create(None)
self.main.Show()
self.SetTopWindow(self.main)
return True
def main():
application = BoaApp(0)
application.MainLoop()
if __name__ == '__main__':
main()
--
http://mail.python.org/mailman/listinfo/python-list
Re: Newbie wxpython staticbitmap help please
jean-michel bain-cornu wrote:
> Why won't you write it yourself using the demo ?
> It's clear and well documented.
> Regards,
> jm
Hi, have been just trying for 5 hours with the timer demo in wx, i just
havnt clicked with how to tie it in together,
I know (think) i need the following features from the timer demo ,
where you can periodically call a function using the wx.timer
self.Bind(wx.EVT_TIMER, self.OnTest1Timer)
#---(bind to the frame ?)
self.Bind(wx.EVT_BUTTON, self.OnTest3Start, t3b1)
#---(this binds to a button, how do i bind to my application on load or
startup instead ?)
def OnTest1Timer(self, evt):
self.log.write("got EVT_TIMER event\n")
#---(dont think i need the logging?)
def OnTest3Start(self, evt):
self.t3 = NotifyTimer(self.log)
self.t3.Start(1000)
self.log.write("NotifyTimer timer started\n")
self.t3b2.Enable()
#---(the Start i guess i will work if i remap the button event to an on
load type? event?
def OnTest3Stop(self, evt):
self.t3.Stop()
self.log.write("NotifyTimer timer stoped\n")
del self.t3
self.t3b2.Disable()
#---(Guess i wont need to stop the timer, as i want it to trigger the
'refreshing' of the StaticBitmaps ?)
# When deriving from wx.Timer you must provide a Notify method
# that will be called when the timer expires.
class NotifyTimer(wx.Timer):
def __init__(self, log):
wx.Timer.__init__(self)
self.log = log
def Notify(self):
self.log.write("got NotifyTimer event\n")
#---(dont know if i need this if i dont want to use this log feature)?
Im sorry if this all seems really amatuerish, i have genuially tried
hard to get my head around it , but i get error after error in boa.
Somewhone couldnt append a timer and perhaps help to refresh the
StaticBitmaps described, with the code, in first post). I will be able
to see and learn greatly from this.
Maybe some advice on where to find lists of the methods used in
wxpython
For example it took me hours to find methods ? like
StaticBitmap.SetImage("imageName")
Is there any good lists of these methods, properties etc for wxpython
controls?
Any good wxpython ide/editors that can "intellisense" them? boa,
komodo, stani's arnt working with "intellisensing" wx for me, (maybe i
cant configure them though)
Thanks for any help with any of this
Regards
--
http://mail.python.org/mailman/listinfo/python-list
Re: Newbie wxpython staticbitmap help please
Thanks Jean this now makes sense, really appreciate your time and
effort mate.
def __init__(self, parent):
self._init_ctrls(parent)
self.t1 = wx.Timer(self)
self.t1.Start(2000) # 2 seconds
self.Bind(wx.EVT_TIMER, self.OnTest1Timer)
self.OnTest1Timer(self)
def OnTest1Timer(self, evt):
if os.path.isfile('images/page1.txt'):
print "ok file present"
i = wx.Image('images/pageGreen.png',wx.BITMAP_TYPE_PNG)
b1 = wx.BitmapFromImage(i)
self.staticBitmap1.SetBitmap(b1)
else:
print "ok file present"
i = wx.Image('images/pageGrey.png',wx.BITMAP_TYPE_PNG)
b1 = wx.BitmapFromImage(i)
self.staticBitmap1.SetBitmap(b1)
The above works a treat,
thanks again Jean
janama
--
http://mail.python.org/mailman/listinfo/python-list
Formatted string to object
Hi,
can such a thing be done somehow?
aaa = self.aaa
bbb = %s.%s % ('parent', 'bbb')
Can you use strings or %s strings like in the above or
aaa = 'string'
aaa.%s() % 'upper'
Somehow?
Thanks for taking a look at this
Regards
Janama
--
http://mail.python.org/mailman/listinfo/python-list
Re: Formatted string to object
Thankyou everyone for help last time:
The following works ok when setting a
wx.lib.buttons.GenBitmapTextButton's disabled bitmap in using wxpython
instead of this:
self.b1.SetBitmapDisabled(self.yellow)
i can use this:
aaa = 1
result1 = eval("self.b%s.SetBitmapDisabled(self.yellow)" % aaa)
result
YAY!
How would i to achieve this with getattr() ?
getattr(locals()['parent'], aaa)???
Why would this be better as recommended in previous post here
http://groups.google.com.au/group/comp.lang.python/browse_frm/thread/2529515bc85cd954/c2f080b21d668081?q=janama&rnum=1#c2f080b21d668081
Any help appreciated
ta
--
http://mail.python.org/mailman/listinfo/python-list
