Hello,
I am having a problem showing a popup menu in my wxpython script on fedora 5 (fc5); this problem does not occur on xp. I am using wxPython-2.6.3.2-1.fc5, unicode version.
I need to add an item to a popup menu after the user selects a file using wx.FileDialog, and then need to show the popup menu immediately after the file selection to inform the user of the files that have been selected thus far.
The popup menu will not show on fc5 if I first display the wx.FileDialog control - if I avoid wx.FileDialog the popup menu appears without a problem.
#!/usr/bin/python
import wx, time, os
thislimit = 5
thispopupmenu = None
def MakeThePopup(self):
global thispopupmenu
menu = wx.Menu()
ids = []
for ii in range(thislimit):
mnuid = wx.NewId()
ids.append(mnuid)
menu.Append(mnuid, "File " + str(ii+1))
menu.AppendSeparator()
add_popupmenu_id = 10102
ids.append(add_popupmenu_id)
menu.Append(add_popupmenu_id, "Add a File")
for daid in ids:
wx.EVT_MENU(self, daid, PopupClicked)
thispopupmenu = menu
### --- end of MakeThePopup function --- ###
def PopupClicked(event):
# get the text of the menu item that was clicked
mnulabel = event.GetEventObject().GetLabel(event.GetId())
# let's be certain that a menu click is being processed
daframe.SetTitle(mnulabel + ' - ' + str(time.time()))
# activate wx.FileDialog if appropriate popup menu item is clicked
if (mnulabel == "Add a File"):
global thislimit
thislimit = thislimit + 1
daframe.SetTitle(mnulabel)
dlg = wx.FileDialog(daframe, message="Select a File:",\
defaultDir=os.getcwd(), defaultFile="",\
wildcard="All files (*.*)|*.*",style=wx.OPEN)
### uncomment the following 2 lines of code and
### the popup menu will not appear on fc5
#if dlg.ShowModal() == wx.ID_OK:
# thisresult = "a file was selected"
### ######################
# make the poup menu
MakeThePopup(daframe.button)
# show the popup menu over the button
daframe.button.PopupMenu(thispopupmenu,wx.Point(5,5))
# the popup fails to show if a wx.FileDialog has
# been activated previously
return True
event.Skip()
### --- end of PopupClicked function --- ###
class DisFrame(wx.Frame):
def __init__(self, *args, **kwargs):
wx.Frame.__init__(self, *args, **kwargs)
# make a panel with a button
panel = wx.Panel(self)
self.button = wx.Button(panel, -1, "Show popup menu")
self.button.Bind(wx.EVT_BUTTON, self.ButtonClicked)
bs = wx.BoxSizer(wx.HORIZONTAL)
bs.Add(self.button,0,wx.ALL,30)
panel.SetSizer(bs)
MakeThePopup(self)
def ButtonClicked(self, event):
# make the popup
MakeThePopup(self)
# show the popup over the button
self.button.PopupMenu(thispopupmenu)
event.Skip()
### --- end of DisFrame class --- ###
if __name__ == '__main__':
app = wx.App()
daframe = DisFrame(None)
daframe.Show()
app.MainLoop()
The popup menu appears if running the above script on fc5.
However, if I uncomment the 2 lines of code that show the wx.FileDialog, the popup fails to appear on fc5 and I need to click 'Stop Executing' after closing the application if running the script through SciTE.
How can I show the popup menu after activating a wx.FileDialog control ?
Any help will be appreciated. Thanks.
_