I have an accelerator shortcut in a menu that is calling the method
bound to it twice. I'm running XP, with python 2.6, and wxpython
2.8. The method is also bound to a button. I can follow the series
of commands as I hit F1 (accelerator key) and process is passed to the
correct method. The method is exited and control is passed back to
the main loop and then control is immediately passed back to the
method. I don't know why the method is called twice. Thanks in
advance for any help.
Menu declaration part:
def _init_coll_menuBar1_Menus(self, parent):
# generated method, don't edit
parent.Append(menu=self.menu1, title='Menu')
def _init_coll_menu1_Items(self, parent):
# generated method, don't edit
parent.Append(help='', id=wxID_FRAME1MENU1ITEMS0,
kind=wx.ITEM_NORMAL,
text='Start/Update/Add\tF1')
parent.AppendSeparator()
parent.Append(help='', id=wxID_FRAME1MENU1ITEMS1,
kind=wx.ITEM_NORMAL,
text='Exit\tF5')
self.Bind(wx.EVT_MENU, self.OnSubButtonButton,
id=wxID_FRAME1MENU1ITEMS0)
self.Bind(wx.EVT_MENU, self.OnMenu1Items1Menu,
id=wxID_FRAME1MENU1ITEMS1)
def _init_utils(self):
# generated method, don't edit
self.menuBar1 = wx.MenuBar()
self.menu1 = wx.Menu(title='')
self._init_coll_menuBar1_Menus(self.menuBar1)
self._init_coll_menu1_Items(self.menu1)
method called twice:
def OnSubButtonButton(self, event):
event.Skip()
self.emailname = win32api.GetUserName()
print self.myinit
print 'getlabel=' + self.SubButton.GetLabel()
print 'event=' + str(event)
print 'event type = ' + str(wx.Event.GetEventType(event))
print 'event object = ' + str(wx.Event.GetEventObject(event))
if self.myinit: #set in _init function to
True
print 'came to initialize myinit=' + str(self.myinit)
adriver ='{SQL Server}'
aserver ='161.223.91.114'
adatabase ='wo_tracking_play'
auid ='sa'
apwd ='sa123IHS'
self.conn = wolibmine.db_conxn(adriver, aserver, adatabase,
auid, apwd)
self.cursor = self.conn.cursor()
# self.conn = pyodbc.connect(driver=adriver, server=aserver,
database=adatabase, uid=auid, pwd=apwd, autocommit=True)
# self.cursor = self.conn.cursor()
self.user, self.wo, self.wcat, self.proj = wolibmine.db_data
(self.cursor, self.emailname)
# self.user, self.wo, self.wcat, self.proj = wolibmine.db_data
(self.cursor, 'mkring')
# self.staticText1.SetLabel(self.user)
self.WorkOrder.SetItems(self.wo)
self.WorkClass.SetItems(self.wcat)
self.SubButton.SetLabel('Add')
self.SubButton.SetBackgroundColour(wx.Colour(128,255,255))
self.SubButton.SetToolTipString('Hit me to add an entry with
the current values.')
self.WorkOrder.SetFocus()
else:
print 'else myinit = ' + str(self.myinit)
wo, prj, wcat, date, time, stat = self.Get_Field_Values()
if not self.EditBox.IsChecked():
try:
cmd = wolibmine.insert_cmd(prj, wo, date, time,
self.user, wcat, stat)
wolibmine.SqlExec(self.cursor, cmd)
except:
dlg = wx.MessageDialog(None, 'An error occurred
while inserting into the database.', 'Error',
wx.OK | wx.ICON_ERROR)
dlg.ShowModal()
else:
dlg = wx.MessageDialog(None, 'Insert Successful.
Click MyData to see your entries.', 'Success',
wx.OK)
dlg.ShowModal()
else:
try:
cmd = wolibmine.update_cmd(self.selected, [wo,
prj, wcat, date, time, stat], self.cols)
wolibmine.SqlExec(self.cursor, cmd)
except:
dlg = wx.MessageDialog(None, 'An error occurred
while updating the database.', 'Error',
wx.OK | wx.ICON_ERROR)
dlg.ShowModal()
else:
dlg = wx.MessageDialog(None, 'Update Successful.
Click MyData to see your entries.', 'Success',
wx.OK)
dlg.ShowModal()
print 'I came here first'
self.myinit = False