Home | Trees | Indices | Help |
|
---|
|
1 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 Rickard Lindberg, Roger Lindberg 2 # 3 # This file is part of Timeline. 4 # 5 # Timeline is free software: you can redistribute it and/or modify 6 # it under the terms of the GNU General Public License as published by 7 # the Free Software Foundation, either version 3 of the License, or 8 # (at your option) any later version. 9 # 10 # Timeline is distributed in the hope that it will be useful, 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 # GNU General Public License for more details. 14 # 15 # You should have received a copy of the GNU General Public License 16 # along with Timeline. If not, see <http://www.gnu.org/licenses/>. 17 18 19 """Contains the class NumTimeType.""" 20 21 22 import math 23 import re 24 25 from timelinelib.calendar.num.time import NumDelta 26 from timelinelib.calendar.num.time import NumTime 27 from timelinelib.calendar.timetype import TimeType 28 from timelinelib.canvas.data import TimePeriod 29 from timelinelib.canvas.data import time_period_center 30 from timelinelib.canvas.drawing.interface import Strip 31 3234 35 """The class.""" 36142 14338 return isinstance(other, NumTimeType)39 42 4547 match = re.search(r"^([-]?\d+(.\d+)?(e[+]\d+)?)$", time_string) 48 if match: 49 if '.' in time_string or 'e' in time_string: 50 time = float(match.group(1)) 51 else: 52 time = int(match.group(1)) 53 try: 54 return NumTime(time) 55 except ValueError: 56 raise ValueError("Invalid time, time string = '%s'" % time_string) 57 else: 58 raise ValueError("Time not on correct format = '%s'" % time_string)59 6870 """Returns a unicode string describing the time period.""" 71 if time_period.is_period(): 72 label = "%s to %s" % ( 73 time_period.start_time.value, 74 time_period.end_time.value 75 ) 76 else: 77 label = "%s" % time_period.start_time.value 78 return label79 82 85 8890 # Choose an exponent that will make the minor strip just larger than 91 # the displayed period: 92 # 93 # 10**x > period_delta => 94 # x > log(period_delta) 95 exponent = int(math.log(metrics.time_period.delta().value, 10)) + 1 96 # Keep decreasing the exponent until the minor strip is small enough. 97 while True: 98 if exponent == 0: 99 break 100 next_minor_strip_with_px = metrics.calc_exact_width( 101 TimePeriod( 102 NumTime(0), 103 NumTime(10 ** (exponent - 1)) 104 ) 105 ) 106 if next_minor_strip_with_px > 30: 107 exponent -= 1 108 else: 109 break 110 return (NumStrip(10 ** (exponent + 1)), NumStrip(10 ** exponent))111 114116 return NumTime(0)117119 return (NumDelta(5), _("Can't zoom deeper than 5"))120 123125 return [ 126 (_("1-period"), lambda p, d: move_period(p, d)), 127 (_("10-period"), lambda p, d: move_period(p, d * 10)), 128 (_("100-period"), lambda p, d: move_period(p, d * 100)), 129 (_("1000-period"), lambda p, d: move_period(p, d * 1000)), 130 ]131 134136 from timelinelib.calendar.num.timepicker import NumTimePicker 137 return NumTimePicker(parent, *args, **kwargs)138140 from timelinelib.calendar.num.periodpicker import NumPeriodPicker 141 return NumPeriodPicker(parent, *args, **kwargs)145 148 151160 161 164 165 169 main_frame.display_time_editor_dialog( 170 NumTimeType(), 171 current_period.mean_time(), 172 navigate_to, 173 _("Go to Time") 174 ) 175 176153 start = int(time.value / self.size) * self.size 154 if time < NumTime(0): 155 start -= self.size 156 return NumTime(start)157178 delta = current_period.start_time - current_period.end_time 179 navigation_fn(lambda tp: tp.move_delta(delta))180 181183 delta = current_period.end_time - current_period.start_time 184 navigation_fn(lambda tp: tp.move_delta(delta))185 186188 delta = NumDelta(num) 189 start_time = period.start_time + delta 190 end_time = period.end_time + delta 191 return TimePeriod(start_time, end_time)192
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Sun Nov 10 02:55:34 2019 | http://epydoc.sourceforge.net |