Hi All,
I've just replaced my simple dialog with the AboutBox dialog only to notice
it freezes on Windows (2.8.9.1 (msw-unicode)). On Linux (Ubuntu Hardy
2.8.9.1 (msw-unicode)) it works just fine. It's weird since the first
manually run OnAbout func works but through the TaskBarIcon it doens't.
Anybody a clue?
Rg,
Arnaud
#!/usr/bin/python
import wx
import string
import sys, os
#import OSC
import random, time
ID_ICON_TIMER = wx.NewId()
RTD_EVENT_TYPE = wx.NewEventType()
RTD_EVENT = wx.PyEventBinder(RTD_EVENT_TYPE, 1)
class RtdEvent(wx.PyCommandEvent):
def __init__(self, evtType, id):
wx.PyCommandEvent.__init__(self, evtType, id)
self.count = None
def SetCount(self, val):
self.count = val
def GetCount(self):
return self.count
···
##
# The IconBar class
#
class IconBar:
l= 1
r = 1
##
# \brief the constructor default left: red, default right: green
#
def
__init__(self,l_off=[128,0,0],l_on=[255,0,0],r_off=[0,128,0],r_on=[0,255,0]):
self.s_line = "\xff\xff\xff"+"\0"*45
self.s_border = "\xff\xff\xff\0\0\0"
self.s_point = "\0"*3
self.sl_off = string.join(map(chr,l_off),'')*6
self.sl_on = string.join(map(chr,l_on),'')*6
self.sr_off = string.join(map(chr,r_off),'')*6
self.sr_on = string.join(map(chr,r_on),'')*6
##
# \brief gets a new icon with 0 <= l,r <= 5
#
def Get(self,l,r):
s=""+self.s_line
for i in range(5):
if i<(5-l):
sl = self.sl_off
else:
sl = self.sl_on
if i<(5-r):
sr = self.sr_off
else:
sr = self.sr_on
s+=self.s_border+sl+self.s_point+sr+self.s_point
s+=self.s_border+sl+self.s_point+sr+self.s_point
s+=self.s_line
image = wx.EmptyImage(16,16)
image.SetData(s)
bmp = image.ConvertToBitmap()
##
# Deze functie loopt vast onder Linux
#
#bmp.SetMask(wx.Mask(bmp, wx.WHITE)) #sets the transparency colour to
white
icon = wx.EmptyIcon()
icon.CopyFromBitmap(bmp)
return icon
class MyTaskBarIcon(wx.TaskBarIcon):
l= 0
r = 0
##
# \brief the constructor
#
def __init__(self, frame):
wx.TaskBarIcon.__init__(self)
self.frame = frame
self.IconBar = IconBar((127,127,0),(255,255,0),(0,127,127),(0,255,255))
self.SetIconBar(self.l,self.r)
self.Bind(wx.EVT_MENU, self.frame.OnAbout, id=self.frame.RTDMENU_ABOUT)
self.Bind(wx.EVT_MENU, self.frame.OnTaskBarClose,
id=self.frame.RTDMENU_CLOSE)
def CreatePopupMenu(self):
"""
This method is called by the base class when it needs to popup
the menu for the default EVT_RIGHT_DOWN event. Just create
the menu how you want it and return it from this function,
the base class takes care of the rest.
"""
menu = wx.Menu()
menu.Append(self.frame.RTDMENU_ABOUT, "About")
menu.AppendSeparator()
menu.Append(self.frame.RTDMENU_CLOSE, "Exit Retyping Dante")
return menu
##
# \brief blinks the icon and updates self.l and self.r
#
def BlinkIcon(self, event):
self.SetIconBar(self.l,self.r, event.GetCount())
self.l += 1
if self.l > 5:
self.l = 0
self.r += 1
if self.r > 5:
self.r = 0
##
# \brief sets the icon bar and a message
#
def SetIconBar(self,l,r, c=0):
icon = self.IconBar.Get(l,r)
self.SetIcon(icon, "Retyping Dante\nCharacters Typed:%d"% c )
##
# The task bar application
#
class TaskBarApp(wx.Frame):
RTDMENU_ABOUT = wx.NewId()
RTDMENU_CLOSE = wx.NewId()
##
# \brief the constructor
#
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, -1, title, size = (1, 1),
style=wx.FRAME_NO_TASKBAR|wx.NO_FULL_REPAINT_ON_RESIZE)
#create Taskbar and Icon
self.tbicon = MyTaskBarIcon(self)
self.Bind(RTD_EVENT, self.OnRtdEvent)
self.Show(True)
#create array for logged keys
#self.chararray = []
#create OSC message container
#self.message = OSC.OSCMessage()
#initiate OSC client
#self.c = OSC.OSCClient()
#create dictionaries for stats
self.rtd_dic = {'count': -1}
self.rtd_dic['count'] = 0
self.count = 0
print wx.version()
self.delay = wx.CallLater(10, self.StartClient )
print "This First OnAbout works"
self.OnAbout(None)
def StartClient(self):
print "StartClient called"
def OnAbout(self, event):
info = wx.AboutDialogInfo()
info.Name = "Retyping Dante Test Client"
info.Version = "0.0.178"
info.Copyright = "(C) 2008 Stichting z25.org"
info.Description = "Characters Typed: %i:"% (self.rtd_dic['count'])
#info.Description = wx.lib.wordwrap(
#"This is an example application that shows how to create "
#"different kinds of About Boxes using wxPython!",
#350, wx.ClientDC(self.panel))
info.WebSite = ("http://test.com", "Current Stats")
info.AddArtist("Jelle van der Ster")
info.AddArtist("Arnaud Loonstra")
info.AddArtist("Matthew Groen")
info.AddArtist("Femke van der Ster")
info.AddArtist("Elmer Zwolsman")
info.AddArtist("Cindy van Rooijen")
info.Developers = ["Arnaud Loonstra"]
#info.License = wordwrap("Completely and totally open source!", 500,
# wx.ClientDC(self.panel))
# Show the wx.AboutBox
print "Freeze... here"
wx.AboutBox(info)
def OnTaskBarClose(self, event):
self.tbicon.Destroy()
wx.CallAfter(self.Close)
def OnRtdEvent(self, event):
self.tbicon.BlinkIcon(event)
def onKeyLogged(self, gil):
print self.kl.isAlive() , gil
self.rtd_dic['count'] += 1
self.constructMessage(gil)
# Omslachtig om dit met een event te doen maar het werkt.
# Kan ook gewoon self.tbicon.BlinkIcon(None) aanroepen
evt = RtdEvent(RTD_EVENT.evtType[0], 0 )
evt.SetCount(self.rtd_dic['count'])
evt.SetEventObject(self)
self.GetEventHandler().ProcessEvent(evt)
def GetCount(self):
return self.rtd_dic['count']
def KeyLogAlive(self):
try:
if self.kl.isAlive():
return True
else:
return False
except:
return None
def constructMessage(self, char):
#global chararray
self.chararray.append(char)
if len(self.chararray) >7:
self.message.clear()
self.message.setAddress("/print")
self.message.append(self.randomize(self.chararray))
print self.message
try:
self.c.send(self.message)
except:
pass
self.chararray = []
def randomize(self, l):
length = len(l)
for i in range(length):
j = random.randrange(i, length)
l[i], l[j] = l[j], l[i]
return l
def save_count(i):
'''Appends number and date to rtd_out.txt'''
fmt = "%d-%m-%y;%H:%M:%S"
output = '%i;%s' % (i, time.strftime(fmt))
print output
out = open("rtd_out.txt", "a",-1)
print >>out, output
##
# The main application wx.App class
#
class MyApp(wx.App):
def OnInit(self):
self.frame = TaskBarApp(None, -1, ' ')
self.frame.Center(wx.BOTH)
self.frame.Show(False)
return True
def main(argv=None):
if argv is None:
argv = sys.argv
app = MyApp(0)
app.MainLoop()
if __name__ == '__main__':
main()
--
View this message in context: http://www.nabble.com/wx.AboutBox(info)-freeze-on-Windows-tp19975747p19975747.html
Sent from the wxPython-users mailing list archive at Nabble.com.