1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import os.path
20
21 import wx.adv
22
23 from timelinelib.calendar.pharaonic.pharaonic import PharaonicDateTime
24 from timelinelib.calendar.pharaonic.time import PharaonicTime
25 from timelinelib.calendar.pharaonic.timepicker.date import PharaonicDatePicker
26 from timelinelib.calendar.pharaonic.timepicker.time import PharaonicTimePicker
27 from timelinelib.calendar.pharaonic.timetype import PharaonicTimeType
28 from timelinelib.config.paths import ICONS_DIR
29 from timelinelib.wxgui.utils import display_information_message
30
31
32 ERROR_MESSAGE = _("The date control can't handle the given date")
33
34
36
37 - def __init__(self, parent, show_time=True, config=None, on_change=None):
47
49 calendar_popup = CalendarPopup(self, wx_date, self.config)
50 calendar_popup.Bind(wx.adv.EVT_CALENDAR_SEL_CHANGED,
51 self._calendar_on_date_changed)
52 calendar_popup.Bind(wx.adv.EVT_CALENDAR,
53 self._calendar_on_date_changed_dclick)
54 btn = evt.GetEventObject()
55 pos = btn.ClientToScreen((0, 0))
56 sz = btn.GetSize()
57 calendar_popup.Position(pos, (0, sz[1]))
58 calendar_popup.Popup()
59 self.calendar_popup = calendar_popup
60
66
72
74 self.time_picker.Show(show)
75 self.GetSizer().Layout()
76
82
85
87 self.date_picker = self._create_date_picker()
88 image = wx.Bitmap(os.path.join(ICONS_DIR, "calendar.bmp"))
89 self.date_button = wx.BitmapButton(self, bitmap=image)
90 self.Bind(wx.EVT_BUTTON, self._date_button_on_click, self.date_button)
91 self.time_picker = PharaonicTimePicker(self)
92
93 sizer = wx.BoxSizer(wx.HORIZONTAL)
94 sizer.Add(self.date_picker, proportion=1,
95 flag=wx.ALIGN_CENTER_VERTICAL)
96 sizer.Add(self.date_button, proportion=0,
97 flag=wx.ALIGN_CENTER_VERTICAL)
98 sizer.Add(self.time_picker, proportion=0,
99 flag=wx.ALIGN_CENTER_VERTICAL)
100 self.SetSizerAndFit(sizer)
101
104
107
109 """It's is a limitation in the wx.adv.CalendarCtrl class
110 that has this date limit."""
111 return str(wx_date) < '1601-01-01 00:00:00'
112
117
119 self.time_picker.SetFocus()
120 self.calendar_popup.Dismiss()
121
122
124
125 - def __init__(self, view, date_picker, time_picker, now_fn, on_change):
126 self._view = view
127 self.date_picker = date_picker
128 self.time_picker = time_picker
129 self.now_fn = now_fn
130 self.on_change = on_change
131
133 if self.time_picker.IsShown():
134 hour, minute, second = self.time_picker.GetPharaonicTime()
135 else:
136 hour, minute, second = (0, 0, 0)
137 year, month, day = self.date_picker.GetPharaonicDate()
138 return PharaonicDateTime(year, month, day, hour, minute, second).to_time()
139
147
149 year, month, day = date
150 return wx.DateTime.FromDMY(day, month - 1, year, 0, 0, 0)
151
153 return (wx_date.year, wx_date.month + 1, wx_date.day)
154
168
169
171
178
184
186 style = self._get_cal_style()
187 cal = wx.adv.CalendarCtrl(self, -1, wx_date,
188 pos=(border, border), style=style)
189 self._set_cal_range(cal)
190 return cal
191
193 style = (wx.adv.CAL_SHOW_HOLIDAYS |
194 wx.adv.CAL_SEQUENTIAL_MONTH_SELECTION)
195 if self.config.get_week_start() == "monday":
196 style |= wx.adv.CAL_MONDAY_FIRST
197 else:
198 style |= wx.adv.CAL_SUNDAY_FIRST
199 return style
200
207
209 year, month, day = PharaonicDateTime.from_time(time).to_date_tuple()
210 try:
211 return wx.DateTime.FromDMY(day, month - 1, year, 0, 0, 0)
212 except OverflowError:
213 if year < 0:
214 year, month, day = PharaonicDateTime.from_time(PharaonicTime(0, 0)).to_date_tuple()
215 return wx.DateTime.FromDMY(day, month - 1, year, 0, 0, 0)
216
220
221 def on_day(evt):
222 self.controller.on_day()
223
224 self.cal.Bind(wx.adv.EVT_CALENDAR_MONTH, on_month)
225 self.cal.Bind(wx.adv.EVT_CALENDAR_DAY, on_day)
226
229
230
232
234 self.calendar_popup = calendar_popup
235 self.repop = False
236 self.repoped = False
237
240
243
245
246
247
248 if self.repop and not self.repoped:
249 try:
250 self.calendar_popup.Popup()
251 except wx.PyAssertionError:
252
253
254
255
256 pass
257 self.repoped = True
258