[wxPython] 2 questions about WxMenu and EVT_UPDATE_UI

G'day all,

I have a simple wxTextCtrl in a wxFrame that has a popup menu when you right
click on it.
It uses EVT_UPDATE_UI to enable/disable menu items on this menu.

How do I get rid of the memory leak messages for this menu. If I attach them
to a
menubar they are cleaned up properly, but I really don't want them on a
menubar.

I also have noticed something really weird in this simple application when I
add the
EVT_UPDATE_UI section I get the following error message under windows
(under GTK it works fine)

Fatal Python error: PyThreadState_Get: no current thread
abnormal program termination

There are no threading functions or methods used anywhere.

the relevant code snipet is here.....

  self.menu = wxMenu()
  reuseID = wxNewId()
  self.menu.Append( reuseID, "Start Logging to file..." ,"Begin logging to a
file" )
  # if I uncomment the next line the abnormal program termination occurs.
#EVT_UPDATE_UI( self, reuseID, self.isLogging)
  EVT_MENU( self, reuseID, self.startLogging )

  reuseID = wxNewId()
  self.menu.Append( reuseID, "Stop Logging to file" ,"Stop logging to a
file" )
  EVT_UPDATE_UI( self, reuseID, self.isNotLogging)
  EVT_MENU( self, reuseID, self.stopLogging )

  reuseID = wxNewId()
  self.menu.Append( reuseID, "Dump to file", "Saves the text windows
contents to a file" )
  EVT_MENU( self, reuseID, self.saveToFile )

  EVT_RIGHT_DOWN( self, self.onRightClick )

  try:
       self.GetParent().GetParent().GetMenuBar().Append(self.menu,"Logging")
  except:
        pass

def isLogging( self, event):
  if LOGFILE == 0: event.Enable(1); return
  event.Enable(0)
  return

def isNotLogging( self, event):
  if LOGFILE == 0: event.Enable(0); return
  event.Enable(1)
  return

···

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

Thanks in advance for any help.

---Gareth Walters

How do I get rid of the memory leak messages for this menu. If I attach

them

to a
menubar they are cleaned up properly, but I really don't want them on a
menubar.

You should call menu.Destroy() on popup menus when you are done with them.

I also have noticed something really weird in this simple application when

I

add the
EVT_UPDATE_UI section I get the following error message under windows
(under GTK it works fine)

Fatal Python error: PyThreadState_Get: no current thread
abnormal program termination

Ouch! I'm not sure what could be causing this if you are not using multiple
threads. Please send me a full test case.

···

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

> add the
> EVT_UPDATE_UI section I get the following error message under windows
> (under GTK it works fine)
>
>
> Fatal Python error: PyThreadState_Get: no current thread
> abnormal program termination
>
Ouch! I'm not sure what could be causing this if you are not using

multiple

threads. Please send me a full test case.

I have since encountered this twice more, once on Windows and once under
GTK.

The problem in windows was "solved" by adding a global variable.(weird
though it sounds) The global variable waws not used for anything but once it
was there the problem went way.

The problem under GTK dissappeared while I was trying to debug it.
I added several print statements (to see which line it died on) and
eventually it stopped happening, if I removed one of the print statements it
started again.

If more details are required I will supply them, I cannot reproduce the
error reliably either as if I run it on other machines it does not
necessarily.

I have verified that all the dynamic libraries are the correct versions.

Any assistance would be appreciated.

(could this be a Python error instead of a wxPython one?)

----Gareth Walters

···

----- Original Message -----
From: "Robin Dunn" <robin@alldunn.com>
To: <wxpython-users@lists.wxwindows.org>
Sent: Friday, September 14, 2001 3:22 PM
Subject: Re: [wxPython] 2 questions about WxMenu and EVT_UPDATE_UI