-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathwxutils.py
49 lines (42 loc) · 1.2 KB
/
wxutils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Author: terryh.tp at gmail.com
import wx
import datetime
# TODO, only keep one version
def _p2w(date):
assert isinstance(date, (datetime.datetime, datetime.date))
tt = date.timetuple()
dmy = (tt[2], tt[1]-1, tt[0])
return wx.DateTimeFromDMY(*dmy)
def _w2p(date):
assert isinstance(date, wx.DateTime)
if date.IsValid():
ymd = map(int, date.FormatISODate().split('-'))
return datetime.date(*ymd)
else:
return None
def wxd_to_python(value):
# parse wx.DateTime to python datetime.date
year = value.GetYear()
month = value.GetMonth() + 1
day = value.GetDay()
return datetime.date(year,month,day)
def python_to_wxd(value):
# parse python datetime.date to wx.DateTime
wxd = wx.DateTime()
wxd.ParseDate(str(value))
return wxd
def showMsg(self, msg):
try:
dlg = wx.MessageDialog( self, msg,'', wx.OK | wx.ICON_INFORMATION )
dlg.ShowModal()
finally:
dlg.Destroy()
def ShowBusyCursor(f):
def func(*args, **kwargs):
wx.BeginBusyCursor()
ret = f(*args, **kwargs)
wx.EndBusyCursor()
return ret
return func