I have little experience of wxPython, so please forgive me if this is a
silly question.
My project has a wx.calendar.CalendarCtrl, and I am trying to set the
date. According to the documentation I have found, the way to do this is
using the SetDate() method. This, it seems, requires an argument of class
wx.DateTime.
The date I have (no time component) is in a reqular Python datetime.date
object. So my question is this: What is the best way to transfer the
value into the wx.DateTime instance?
I have managed to achieve this, but only by doing some quite ugly string
maninpulation (see code snippet below), but I am sure that there must be
a more elegant or 'best practice' way to do it.
Secondly, a pointer to any documentation on this type of issue would be
appreciated.
Code snippet(extra balan lines inserted to avoid wrapping):
I have little experience of wxPython, so please forgive me if this is a
silly question.
My project has a wx.calendar.CalendarCtrl, and I am trying to set the
date. According to the documentation I have found, the way to do this is
using the SetDate() method. This, it seems, requires an argument of class
wx.DateTime.
The date I have (no time component) is in a reqular Python datetime.date
object. So my question is this: What is the best way to transfer the
value into the wx.DateTime instance?
I have managed to achieve this, but only by doing some quite ugly string
maninpulation (see code snippet below), but I am sure that there must be
a more elegant or 'best practice' way to do it.
Secondly, a pointer to any documentation on this type of issue would be
appreciated.
Code snippet(extra balan lines inserted to avoid wrapping):
action_date_wx = wx.DateTime()
action_date_wx.Set(int(str(action_date_dt)[8:]),
int(str(action_date_dt)[5:7]) - 1,
int(str(action_date_dt)[:4]))
self.calendar.SetDate(action_date_wx)
I use a validator to get/set and here is what it does:
get:
dateVal = datetime.datetime(self.tCtrl.GetValue().GetYear(),
self.tCtrl.GetValue().GetMonth()+1,
self.tCtrl.GetValue().GetDay())
set:
value = self.getCtrlValue() # will get a datetime from the database
if value:
self.tCtrl.SetValue(wx.DateTimeFromDMY(value.day,
value.month-1,
value.year))
I have little experience of wxPython, so please forgive me if this is a
silly question.
My project has a wx.calendar.CalendarCtrl, and I am trying to set the
date. According to the documentation I have found, the way to do this
is using the SetDate() method. This, it seems, requires an argument of
class wx.DateTime.
The date I have (no time component) is in a reqular Python
datetime.date object. So my question is this: What is the best way to
transfer the value into the wx.DateTime instance?
Have a look at Robin's reply at the bottom of this page:
Many thanks for this C W, and thank you also to werner.
Robin's two helper functions have allowed me to simplify my code, and
they certainly seem to work perfectly.
C W: I have just one slight doubt: I note that the name of each of the
two helper functions starts with an underscore. Does that mean I should
not really be using them, or are my fears groundless in this case?
···
On Sun, 11 Mar 2012 13:13:12 -0400, C M wrote:
On Sun, Mar 11, 2012 at 1:00 PM, Walter Hurry > <walterhurry@lavabit.com>wrote:
I doubt it’s a problem. I see in the wxPython coding guidelines: “Things in a module that are not meant to be used outside the module should be named with a leading underscore.” That said, Robin himself suggested using it in that thread and I can’t see why it would be a problem to use it.
>
>> Hi,
>>
>> I have little experience of wxPython, so please forgive me if this
>> is a silly question.
>>
>> My project has a wx.calendar.CalendarCtrl, and I am trying to set
>> the date. According to the documentation I have found, the way to do
>> this is using the SetDate() method. This, it seems, requires an
>> argument of class wx.DateTime.
>>
>> The date I have (no time component) is in a reqular Python
>> datetime.date object. So my question is this: What is the best way
>> to transfer the value into the wx.DateTime instance?
>>
>>
> Have a look at Robin's reply at the bottom of this page:
>
> http://wxpython-users.1045709.n5.nabble.com/wx-DateTime-lt-gt-Python-
datetime-td2338084.html<http://wxpython-users.1045709.n5.nabble.com/wx-
DateTime-lt-gt-Python-%0Adatetime-td2338084.html>
>
> So apparently you could just make use of what is already in
> wx.calendar,
> like this:
>
> my_wx_date = wx,calendar._pydate2wxdate(my_python_date)
Many thanks for this C W, and thank you also to werner.
Robin's two helper functions have allowed me to simplify my code, and
they certainly seem to work perfectly.
C W: I have just one slight doubt: I note that the name of each of the
two helper functions starts with an underscore. Does that mean I should
not really be using them, or are my fears groundless in this case?
I doubt it's a problem. I see in the wxPython coding guidelines:
"Things in a module that are not meant to be used outside the module
should be named with a leading underscore." That said, Robin himself
suggested using it in that thread and I can't see why it would be a
problem to use it.
OK. Thanks again. I'll stop worrying about it.
···
On Sun, 11 Mar 2012 19:34:14 -0400, C M wrote:
On Sun, Mar 11, 2012 at 6:03 PM, Walter Hurry > <walterhurry@lavabit.com>wrote:
On Sun, 11 Mar 2012 13:13:12 -0400, C M wrote:
> On Sun, Mar 11, 2012 at 1:00 PM, Walter Hurry >> > <walterhurry@lavabit.com>wrote: