1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import re
20
21 from timelinelib.calendar.bosparanian.bosparanian import BosparanianDateTime
22 from timelinelib.calendar.bosparanian.monthnames import bosp_abbreviated_name_of_month
23 from timelinelib.calendar.bosparanian.monthnames import bosp_name_of_month
24 from timelinelib.calendar.bosparanian.time import BosparanianDelta
25 from timelinelib.calendar.bosparanian.time import BosparanianTime
26 from timelinelib.calendar.bosparanian.weekdaynames import bosp_abbreviated_name_of_weekday
27 from timelinelib.calendar.gregorian.timetype import DAYS
28 from timelinelib.calendar.gregorian.timetype import DurationFormatter
29 from timelinelib.calendar.gregorian.timetype import HOURS
30 from timelinelib.calendar.gregorian.timetype import MINUTES
31 from timelinelib.calendar.gregorian.timetype import SECONDS
32 from timelinelib.calendar.gregorian.timetype import SECONDS_IN_DAY
33 from timelinelib.calendar.gregorian.timetype import YEARS
34 from timelinelib.calendar.timetype import TimeType
35 from timelinelib.canvas.data import TimeOutOfRangeLeftError
36 from timelinelib.canvas.data import TimeOutOfRangeRightError
37 from timelinelib.canvas.data import TimePeriod
38 from timelinelib.canvas.data import time_period_center
39 from timelinelib.canvas.drawing.interface import Strip
40
41
43
45 self.major_strip_is_decade = False
46 self.saved_now = None
47
50
52 return not (self == other)
53
56
58 match = re.search(r"^(-?\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+)$", time_string)
59 if match:
60 year = int(match.group(1))
61 month = int(match.group(2))
62 day = int(match.group(3))
63 hour = int(match.group(4))
64 minute = int(match.group(5))
65 second = int(match.group(6))
66 try:
67 return BosparanianDateTime(year, month, day, hour, minute, second).to_time()
68 except ValueError:
69 raise ValueError("Invalid time, time string = '%s'" % time_string)
70 else:
71 raise ValueError("Time not on correct format = '%s'" % time_string)
72
74 return [
75 (_("Open &Now Date Editor") + "\tCtrl+T", open_now_date_editor),
76 (_("Go to &Date...") + "\tCtrl+G", go_to_date_fn),
77 ("SEP", None),
78 (_("Backward") + "\tPgUp", backward_fn),
79 (_("Forward") + "\tPgDn", forward_fn),
80 (_("Forward One Wee&k") + "\tCtrl+K", forward_one_week_fn),
81 (_("Back One &Week") + "\tCtrl+W", backward_one_week_fn),
82 (_("Forward One Mont&h") + "\tCtrl+H", forward_one_month_fn),
83 (_("Back One &Month") + "\tCtrl+M", backward_one_month_fn),
84 (_("Forward One Yea&r") + "\tCtrl+R", forward_one_year_fn),
85 (_("Back One &Year") + "\tCtrl+Y", backward_one_year_fn),
86 ("SEP", None),
87 (_("Fit Millennium"), fit_millennium_fn),
88 (_("Fit Century"), fit_century_fn),
89 (_("Fit Decade"), fit_decade_fn),
90 (_("Fit Year"), fit_year_fn),
91 (_("Fit Month"), fit_month_fn),
92 (_("Fit Week"), fit_week_fn),
93 (_("Fit Day"), fit_day_fn),
94 ("SEP", None),
95 ]
96
101
102 def label_without_time(time):
103 bosparanian_datetime = BosparanianDateTime.from_time(time)
104 return u"%s %s %s" % (bosparanian_datetime.day, bosp_abbreviated_name_of_month(bosparanian_datetime.month), bosparanian_datetime.year)
105
106 def time_label(time):
107 return "%02d:%02d" % time.get_time_of_day()[:-1]
108 if time_period.is_period():
109 if has_nonzero_time(time_period):
110 label = u"%s to %s" % (label_with_time(time_period.start_time),
111 label_with_time(time_period.end_time))
112 else:
113 label = u"%s to %s" % (label_without_time(time_period.start_time),
114 label_without_time(time_period.end_time))
115 else:
116 if has_nonzero_time(time_period):
117 label = u"%s" % label_with_time(time_period.start_time)
118 else:
119 label = u"%s" % label_without_time(time_period.start_time)
120 return label
121
127
130
133
135 """
136 Return a tuple (major_strip, minor_strip) for current time period and
137 window size.
138 """
139 day_period = TimePeriod(BosparanianTime(0, 0), BosparanianTime(1, 0))
140 one_day_width = metrics.calc_exact_width(day_period)
141 self.major_strip_is_decade = False
142 if one_day_width > 20000:
143 return (StripHour(), StripMinute())
144 elif one_day_width > 600:
145 return (StripDay(), StripHour())
146 elif one_day_width > 60:
147 return (StripMonth(), StripWeekday())
148 elif one_day_width > 25:
149 return (StripMonth(), StripDay())
150 elif one_day_width > 10:
151 return (StripMonth(), StripWeek())
152 elif one_day_width > 1.75:
153 return (StripYear(), StripMonth())
154 elif one_day_width > 0.5:
155 return (StripYear(), StripQuarter())
156 elif one_day_width > 0.12:
157 self.major_strip_is_decade = True
158 return (StripDecade(), StripYear())
159 elif one_day_width > 0.012:
160 return (StripCentury(), StripDecade())
161 else:
162 return (StripCentury(), StripCentury())
163
166
169
171 self.saved_now = time
172
177
180
182 return u"bosparaniantime"
183
191
194
197
199 return time.julian_day % 7
200
204
208
209
211 def navigate_to(time):
212 navigation_fn(lambda tp: tp.center(time))
213 main_frame.display_now_date_editor_dialog(navigate_to, _("Change Now Date"))
214
215
217 def navigate_to(time):
218 navigation_fn(lambda tp: tp.center(time))
219 main_frame.display_time_editor_dialog(
220 BosparanianTimeType(), current_period.mean_time(), navigate_to, _("Go to Date"))
221
222
223 -def backward_fn(main_frame, current_period, navigation_fn):
224 _move_page_smart(current_period, navigation_fn, -1)
225
226
227 -def forward_fn(main_frame, current_period, navigation_fn):
228 _move_page_smart(current_period, navigation_fn, 1)
229
230
231 -def _move_page_smart(current_period, navigation_fn, direction):
232 if _whole_number_of_years(current_period):
233 _move_page_years(current_period, navigation_fn, direction)
234 elif _whole_number_of_months(current_period):
235 _move_page_months(current_period, navigation_fn, direction)
236 else:
237 navigation_fn(lambda tp: tp.move_delta(direction * current_period.delta()))
238
239
244
245
246 -def _move_page_years(curret_period, navigation_fn, direction):
247 def navigate(tp):
248 year_delta = direction * _calculate_year_diff(curret_period)
249 bosparanian_start = BosparanianDateTime.from_time(curret_period.start_time)
250 bosparanian_end = BosparanianDateTime.from_time(curret_period.end_time)
251 new_start_year = bosparanian_start.year + year_delta
252 new_end_year = bosparanian_end.year + year_delta
253 try:
254 new_start = bosparanian_start.replace(year=new_start_year).to_time()
255 new_end = bosparanian_end.replace(year=new_end_year).to_time()
256 if new_end > BosparanianTimeType().get_max_time():
257 raise ValueError()
258 if new_start < BosparanianTimeType().get_min_time():
259 raise ValueError()
260 except ValueError:
261 if direction < 0:
262 raise TimeOutOfRangeLeftError()
263 else:
264 raise TimeOutOfRangeRightError()
265 return tp.update(new_start, new_end)
266 navigation_fn(navigate)
267
268
272
273
282
283
284 -def _move_page_months(curret_period, navigation_fn, direction):
285 def navigate(tp):
286 start = BosparanianDateTime.from_time(curret_period.start_time)
287 end = BosparanianDateTime.from_time(curret_period.end_time)
288 start_months = start.year * 13 + start.month
289 end_months = end.year * 13 + end.month
290 month_diff = end_months - start_months
291 month_delta = month_diff * direction
292 new_start_year, new_start_month = _months_to_year_and_month(start_months + month_delta)
293 new_end_year, new_end_month = _months_to_year_and_month(end_months + month_delta)
294 try:
295 new_start = start.replace(year=new_start_year, month=new_start_month)
296 new_end = end.replace(year=new_end_year, month=new_end_month)
297 start = new_start.to_time()
298 end = new_end.to_time()
299 if end > BosparanianTimeType().get_max_time():
300 raise ValueError()
301 if start < BosparanianTimeType().get_min_time():
302 raise ValueError()
303 except ValueError:
304 if direction < 0:
305 raise TimeOutOfRangeLeftError()
306 else:
307 raise TimeOutOfRangeRightError()
308 return tp.update(start, end)
309 navigation_fn(navigate)
310
311
313 years = int(months / 13)
314 month = months - years * 13
315 if month == 0:
316 month = 13
317 years -= 1
318 return years, month
319
320
324
325
329
330
336
337
340
341
344
345
349
350
354
355
365
366
369
370
373
374
377
378
388
389
395
396
397 -def fit_year_fn(main_frame, current_period, navigation_fn):
402
403
404 -def fit_month_fn(main_frame, current_period, navigation_fn):
412
413
414 -def fit_day_fn(main_frame, current_period, navigation_fn):
419
420
421 -def fit_week_fn(main_frame, current_period, navigation_fn):
430
431
433
434 - def label(self, time, major=False):
435 if major:
436
437 time = BosparanianDateTime.from_time(time)
438 start_year = self._century_start_year(time.year)
439 century = (start_year + 100) / 100
440 if century <= 0:
441 century -= 1
442 return str(century) + " century BF"
443 return ""
444
448
452
454 year = (int(year) / 100) * 100
455 return year
456
457
459
460 - def label(self, time, major=False):
463
468
472
474
475
476
477 return (int(year) / 10) * 10 - 10
478
479
481
482 - def label(self, time, major=False):
484
489
493
494
496
497 - def label(self, time, major=False):
505
510
514
515
517
523
524 - def label(self, time, major=False):
525 q = self.get_quarter(time)
526 if q == 0:
527 return "NLD"
528 return "Q%d" % q
529
537
545
546
548
549 - def label(self, time, major=False):
556
561
564
567
568
570
573
574 - def label(self, time, major=False):
582
584 start = BosparanianDateTime.from_time(start)
585 end = BosparanianDateTime.from_time(end)
586 if start.year == end.year:
587 if start.month == end.month:
588 return "%s-%s %s %s" % (start.day, end.day,
589 bosp_abbreviated_name_of_month(start.month),
590 format_year(start.year))
591 return "%s %s-%s %s %s" % (start.day,
592 bosp_abbreviated_name_of_month(start.month),
593 end.day,
594 bosp_abbreviated_name_of_month(end.month),
595 format_year(start.year))
596 return "%s %s %s-%s %s %s" % (start.day,
597 bosp_abbreviated_name_of_month(start.month),
598 format_year(start.year),
599 end.day,
600 bosp_abbreviated_name_of_month(end.month),
601 format_year(end.year))
602
606
609
610
612
613 - def label(self, time, major=False):
623
628
631
634
635
637
638 - def label(self, time, major=False):
644
648
651
652
654
655 - def label(self, time, major=False):
661
665
668
669
672
673
676
677
683
684
690
691
723
724
735
736
740