problem: when I bind my DatePicker obj with a function it works fine within that function but when I try to get that same value appended to a list in another function it does 1 or 2 things , the error would say
[<bound method F_Main.date_Begin of <guiwm.F_Main object at 0x08D01490>>, (15, 48, 55)]
which I know mean is LITERALLY calling the function so I should just add a parenthesis "()" at the end of my Function call but when I do add it I get the following error
date_Begin() missing 1 required positional argument: 'event'
below is my some of my code along with the event bindings
self.dateBegin.Bind( wx.adv.EVT_DATE_CHANGED, self.date_Begin )
def date_Begin( self, event ):
aStringDate = self.dateBegin.GetValue().Format("%m-%d-%y")
print(aStringDate)
return aStringDate
event.Skip()
def time_Begin(self):
aStringTime = self.timeBegin.GetTime()
print(aStringTime)
return aStringTime
and here's me calling in another function
def clickBtn_Generate( self, event ):
a = self.date_Begin()
b = self.time_Begin()
list = []
list.append(a)
list.append(b)
print(list)
return list
event.Skip()
I've tried removing and keeping the parenthesis on
a = self.date_Begin
but none of them works. Any idea how to work around this ?
class F_Main ( wx.Frame ):
def __init__( self, parent ):
wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = u"Generator", pos = wx.DefaultPosition, size = wx.Size( 800,800 ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL )
self.SetSizeHints( wx.DefaultSize, wx.DefaultSize )
self.SetForegroundColour( wx.SystemSettings.GetColour( wx.SYS_COLOUR_WINDOW ) )
self.SetBackgroundColour( wx.Colour( 255, 255, 0 ) )
bSizer5 = wx.BoxSizer( wx.HORIZONTAL )
self.lbl_WS1 = wx.StaticText( self, wx.ID_ANY, u"Wafer Sort 1", wx.DefaultPosition, wx.DefaultSize, 0 )
self.lbl_WS1.Wrap( -1 )
self.lbl_WS1.SetBackgroundColour( wx.SystemSettings.GetColour( wx.SYS_COLOUR_ACTIVECAPTION ) )
bSizer5.Add( self.lbl_WS1, 0, wx.ALL, 10 )
self.dateBegin = wx.adv.DatePickerCtrl( self, wx.ID_ANY, wx.DefaultDateTime, wx.DefaultPosition, wx.DefaultSize, wx.adv.DP_DROPDOWN )
bSizer5.Add( self.dateBegin, 0, wx.ALL, 5 )
self.timeBegin = wx.adv.TimePickerCtrl( self, wx.ID_ANY, wx.DefaultDateTime, wx.DefaultPosition, wx.DefaultSize, wx.adv.DP_DEFAULT )
bSizer5.Add( self.timeBegin, 0, wx.ALL, 5 )
self.dateEnd = wx.adv.DatePickerCtrl( self, wx.ID_ANY, wx.DefaultDateTime, wx.DefaultPosition, wx.DefaultSize, wx.adv.DP_DROPDOWN )
bSizer5.Add( self.dateEnd, 0, wx.ALL, 5 )
self.timeEnd = wx.adv.TimePickerCtrl( self, wx.ID_ANY, wx.DefaultDateTime, wx.DefaultPosition, wx.DefaultSize, wx.adv.DP_DEFAULT )
bSizer5.Add( self.timeEnd, 0, wx.ALL, 5 )
self.btnGenerate = wx.Button( self, wx.ID_ANY, u"MyButton", wx.DefaultPosition, wx.DefaultSize, 0 )
bSizer5.Add( self.btnGenerate, 0, wx.ALL, 5 )
self.SetSizer( bSizer5 )
self.Layout()
self.Centre( wx.BOTH )
# Connect Events
self.dateBegin.Bind( wx.adv.EVT_DATE_CHANGED, self.date_Begin )
#self.timeBegin.Bind(wx.adv.EVT_TIME_CHANGED, self.time_Begin)
self.dateEnd.Bind( wx.adv.EVT_DATE_CHANGED, self.date_End )
self.timeEnd.Bind(wx.adv.EVT_TIME_CHANGED, self.time_End)
self.btnGenerate.Bind( wx.EVT_BUTTON, self.clickBtn_Generate )
def __del__( self ):
pass
# Virtual event handlers, overide them in your derived class
def date_Begin( self, event ):
aStringDate = self.dateBegin.GetValue().Format("%m-%d-%y")
print(aStringDate)
return aStringDate
event.Skip()
def time_Begin(self):
aStringTime = self.timeBegin.GetTime()
print(aStringTime)
return aStringTime
def date_End( self, event ):
aStringDate = event.GetDate()
event.Skip()
def time_End(self, event):
aStringTime = event.GetDate()
print(aStringTime)
def clickBtn_Generate( self, event ):
a = self.date_Begin()
b = self.time_Begin()
list = []
list.append(a)
list.append(b)
print(list)
return list
event.Skip()
You are missing the event.
The way around this is to send None
instead i.e.
a = self.date_Begin(None)
Because of the way that you have coded that function, you will also need to check for an event before you make a call to Skip()
i.e.
def date_Begin( self, event ):
aStringDate = self.dateBegin.GetValue().Format("%m-%d-%y")
print(aStringDate)
return aStringDate
if event:
event.Skip()
In response to your comment about Skip
Skip(self, skip=True) This method can be used inside an event handler to control whether further event handlers bound to this event will be called after the current one returns.
Without Skip (or equivalently if Skip(false) is used), the event will not be processed any more. If Skip(true) is called, the event processing system continues searching for a further handler function for this event, even though it has been processed already in the current handler.
In general, it is recommended to skip all non-command events to allow the default handling to take place. The command events are, however, normally not skipped as usually a single command such as a button click or menu item selection must only be processed by one handler.
Parameters: skip (bool)