wx.AboutBox(info) freeze on Windows

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.

sphaero wrote:

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
  

<snip>

It looks like the line:

self.delay = wx.CallLater(10, self.StartClient )

is causing it to choke on Windows. I'm not sure why you want to show an about screen and start some client 10 seconds later. Anyway, my guess is that the About Dialog is modal and somehow the CallLater is interfering with it and vice-versa. If you comment out that line, it works just fine.

I'm using Windows XP, wxPython 2.8.9.1 (msw-unicode), Python 2.5.2.

Mike

Mike Driscoll-2 wrote:

sphaero wrote:

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
  

<snip>

It looks like the line:

self.delay = wx.CallLater(10, self.StartClient )

is causing it to choke on Windows. I'm not sure why you want to show an
about screen and start some client 10 seconds later. Anyway, my guess is
that the About Dialog is modal and somehow the CallLater is interfering
with it and vice-versa. If you comment out that line, it works just fine.

I'm using Windows XP, wxPython 2.8.9.1 (msw-unicode), Python 2.5.2.

Mike

That's weird, commenting that line doesn't fix the problem here. Are you
sure it worked fine? I had tried that before.
The line can be removed anyway since it can be replaced by wx.CallAfter. But
that's not the scope now.

I'm running 2.5.2 as well on Win2003

Arnaud

···

--
View this message in context: http://www.nabble.com/wx.AboutBox(info)-freeze-on-Windows-tp19975747p19989130.html
Sent from the wxPython-users mailing list archive at Nabble.com.

sphaero wrote:

Mike Driscoll-2 wrote:
  

sphaero wrote:
    

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
  

<snip>

It looks like the line:

self.delay = wx.CallLater(10, self.StartClient )

is causing it to choke on Windows. I'm not sure why you want to show an about screen and start some client 10 seconds later. Anyway, my guess is that the About Dialog is modal and somehow the CallLater is interfering with it and vice-versa. If you comment out that line, it works just fine.

I'm using Windows XP, wxPython 2.8.9.1 (msw-unicode), Python 2.5.2.

Mike

That's weird, commenting that line doesn't fix the problem here. Are you
sure it worked fine? I had tried that before.
The line can be removed anyway since it can be replaced by wx.CallAfter. But
that's not the scope now.

I'm running 2.5.2 as well on Win2003

Arnaud
  
Well, I tried it again and it worked, but then I noticed that I actually had wxPython 2.8.8.0 installed. So I put the latest on in a VM and tried it again, but it still works. Maybe it's a Windows 2003 thing? Can anyone else run it on Windows after commenting out that line?

Mike

Mike Driscoll wrote:

Well, I tried it again and it worked, but then I noticed that
I actually had wxPython 2.8.8.0 installed. So I put the
latest on in a VM and tried it again, but it still works.
Maybe it's a Windows 2003 thing? Can anyone else run it on
Windows after commenting out that line?

I am on Windows 2003, but still on wxPython 2.8.7.1, so it may not act the
same.

Anyway, I ran it, but I don't know what I am looking for. The about box
appears, and if I close it, it disappears, but the program does not
terminate. I have to kill the program with Ctrl+Break to get back to the
prompt. The same applies when I run it on Linux (using Ctrl+C to kill it).
It makes no difference if I comment out that line or not.

Does this help? Anything else you want me to try? It may only be tomorrow.

Frank Millman

Frank,

Mike Driscoll wrote:
  

Well, I tried it again and it worked, but then I noticed that I actually had wxPython 2.8.8.0 installed. So I put the latest on in a VM and tried it again, but it still works. Maybe it's a Windows 2003 thing? Can anyone else run it on Windows after commenting out that line?

I am on Windows 2003, but still on wxPython 2.8.7.1, so it may not act the
same.

Anyway, I ran it, but I don't know what I am looking for. The about box
appears, and if I close it, it disappears, but the program does not
terminate. I have to kill the program with Ctrl+Break to get back to the
prompt. The same applies when I run it on Linux (using Ctrl+C to kill it).
It makes no difference if I comment out that line or not.

Does this help? Anything else you want me to try? It may only be tomorrow.

Frank Millman
  
The AboutDialog isn't going to close its parent when it closes. It basically runs in its own MainLoop, so when you close the dialog, you only kill that loop. If you want your main application to die too, you need to tell it to. Just add a "self.Close()" after "wx.AboutBox(info)".

···

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

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

Mike Driscoll-2 wrote:

[snip]

That's weird, commenting that line doesn't fix the problem here. Are you
sure it worked fine? I had tried that before.
The line can be removed anyway since it can be replaced by wx.CallAfter.
But
that's not the scope now.

I'm running 2.5.2 as well on Win2003

Arnaud
  
Well, I tried it again and it worked, but then I noticed that I actually
had wxPython 2.8.8.0 installed. So I put the latest on in a VM and tried
it again, but it still works. Maybe it's a Windows 2003 thing? Can
anyone else run it on Windows after commenting out that line?

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

You're right, it works on XP. I just installed python on XP vm and can
confirm. It must be a 2003 thing.
Let's see if I can clean up the code and file a bug report.

Arnaud

···

--
View this message in context: http://www.nabble.com/wx.AboutBox(info)-freeze-on-Windows-tp19975747p19997493.html
Sent from the wxPython-users mailing list archive at Nabble.com.

Frank Millman wrote:

[snip]
I am on Windows 2003, but still on wxPython 2.8.7.1, so it may not act the
same.

Anyway, I ran it, but I don't know what I am looking for. The about box
appears, and if I close it, it disappears, but the program does not
terminate. I have to kill the program with Ctrl+Break to get back to the
prompt. The same applies when I run it on Linux (using Ctrl+C to kill it).
It makes no difference if I comment out that line or not.

Does this help? Anything else you want me to try? It may only be tomorrow.

Frank Millman

Thanks for the feedback. You should have been able to close the app through
it's popup menu in the tray. It has the option to exit and show the about
box.

I've cleaned up the code a bit. It's now only controlled through the popup
menu on the TaskBarIcon.
I've tested the following:
Ubuntu Hoary: OK
python version: 2.5.2
wxPython version: 2.8.7.1 (gtk2-unicode)

WinXP: OK
python version: 2.5.2
wxPython version: 2.8.9.1 (msw-unicode)

Win2003: Freeze on wx.AboutBox(info)
python version: 2.5.2
wxPython version: 2.8.9.1 (msw-unicode)

This is the cleaned up code:
#!/usr/bin/python

import wx

import string

import sys, os, platform

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

# It just returns an icon on Get()

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()

    ##

    # This results in a freeze on Ubuntu

    #

    #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):

  ##

  # \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(2, 3)

    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")

    return menu

  ##

  # \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.Show(True)

  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:"% 99

    #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)

##

# 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__':

  print "python version:", platform.python_version()

  print "wxPython version:", wx.version()

  main()

--
View this message in context: http://www.nabble.com/wx.AboutBox(info)-freeze-on-Windows-tp19975747p19998002.html
Sent from the wxPython-users mailing list archive at Nabble.com.

Sphaero wrote:

Thanks for the feedback. You should have been able to close
the app through it's popup menu in the tray. It has the
option to exit and show the about box.

I've cleaned up the code a bit. It's now only controlled
through the popup menu on the TaskBarIcon.
I've tested the following:
Ubuntu Hoary: OK
python version: 2.5.2
wxPython version: 2.8.7.1 (gtk2-unicode)

WinXP: OK
python version: 2.5.2
wxPython version: 2.8.9.1 (msw-unicode)

Win2003: Freeze on wx.AboutBox(info)
python version: 2.5.2
wxPython version: 2.8.9.1 (msw-unicode)

I ran your revised program, and it did not freeze on me.

My platform is Windows Server 2003 (Standard Edition, Service Pack 1) and
wxPython 2.8.7.1 (msw-unicode).

Just to confirm, this is the behaviour that I see -

1. Run the program from a console window - nothing appears on the screen,
but an icon appears on the taskbar.

2. Right-click the icon, select 'About' - the about box appears.

3. The text 'Freeze... here' appears in the console window, but the about
box is not frozen - I can select 'Developers', 'Artists', and 'Current
Stats' with no problem, and I can close it successfully.

4. While the about box is open, I cannot right-click the taskbar icon.

5. After closing the about box, I can right-click the taskbar icon again. If
I select 'About', the about box re-appears. If I select 'Exit', the program
terminates normally, the icon disappears, and the console window returns to
the prompt.

I don't know if this helps. Let me know if there is anything else you would
like me to try.

Frank

Frank Millman wrote:

[snip]
I ran your revised program, and it did not freeze on me.

My platform is Windows Server 2003 (Standard Edition, Service Pack 1) and
wxPython 2.8.7.1 (msw-unicode).

Just to confirm, this is the behaviour that I see -

1. Run the program from a console window - nothing appears on the screen,
but an icon appears on the taskbar.

2. Right-click the icon, select 'About' - the about box appears.

3. The text 'Freeze... here' appears in the console window, but the about
box is not frozen - I can select 'Developers', 'Artists', and 'Current
Stats' with no problem, and I can close it successfully.

4. While the about box is open, I cannot right-click the taskbar icon.

5. After closing the about box, I can right-click the taskbar icon again.
If
I select 'About', the about box re-appears. If I select 'Exit', the
program
terminates normally, the icon disappears, and the console window returns
to
the prompt.

I don't know if this helps. Let me know if there is anything else you
would
like me to try.

Frank

Thanks for this Frank, It seems the problem is caused by Scite (my editor).
If I run the code in the console it works like you say but from Scite it
freezes. I'm running SP2 btw.

Thanks for your assistance. I'm moving to a different editor.

Arnaud

···

--
View this message in context: http://www.nabble.com/wx.AboutBox(info)-freeze-on-Windows-tp19975747p20027882.html
Sent from the wxPython-users mailing list archive at Nabble.com.