def __init__(self, time_picker): self.time_picker = time_picker self.original_bg = self.time_picker.GetBackgroundColour() self.separator = GregorianTimeType().event_time_string( GregorianTimeType().now())[2] self.hour_part = 0 self.minute_part = 1 self.last_selection = None
def __init__(self, date_picker, error_bg="pink"): self.date_picker = date_picker self.error_bg = error_bg self.original_bg = self.date_picker.GetBackgroundColour() self.separator = GregorianTimeType().event_date_string( GregorianTimeType().now())[4] self.region_year = 0 self.region_month = 1 self.region_day = 2 self.region_siblings = ((self.region_year, self.region_month), (self.region_month, self.region_day)) self.preferred_day = None self.save_preferred_day = True self.last_selection = None
def db_open_newtype_timeline(path, timetype=None): if os.path.exists(path): from timelinelib.dataimport.timelinexml import import_db_from_timeline_xml db = import_db_from_timeline_xml(path) if dir_is_read_only(path): from timelinelib.wxgui.utils import display_warning_message db.set_readonly() display_warning_message( _("Since the directory of the Timeline file is not writable,\nthe timeline is opened in read-only mode" )) return db else: from timelinelib.data.db import MemoryDB db = MemoryDB() if timetype is None: db.set_time_type(GregorianTimeType()) else: db.set_time_type(timetype) def save_callback(): from timelinelib.dataexport.timelinexml import export_db_to_timeline_xml export_db_to_timeline_xml(db, path) db.register_save_callback(save_callback) db.set_should_lock(True) return db
def decrement_month(date): year, month, day = date if month > 1: return self._set_valid_day(year, month - 1, day) elif year > gregorian.from_time( GregorianTimeType().get_min_time()[0]).year: return self._set_valid_day(year - 1, 12, day) return date
def increment_day(date): year, month, day = date time = gregorian.from_date(year, month, day).to_time() if time < GregorianTimeType().get_max_time()[0] - delta_from_days( 1): return gregorian.from_time(time + delta_from_days(1)).to_date_tuple() return date
def __init__(self, parent, show_time=True, config=None): wx.Panel.__init__(self, parent) self.config = config self._create_gui() self.controller = GregorianDateTimePickerController( self.date_picker, self.time_picker, GregorianTimeType().now) self.show_time(show_time) self.parent = parent
def _parse_timetype(self, text, tmp_dict): self.time_type = None valid_time_types = (GregorianTimeType(), NumTimeType()) for timetype in valid_time_types: if text == timetype.get_name(): self.time_type = timetype break if self.time_type is None: raise ParseException("Invalid timetype '%s' found." % text)
def decrement_day(date): year, month, day = date if day > 1: return self._set_valid_day(year, month, day - 1) elif month > 1: return self._set_valid_day(year, month - 1, 31) elif year > GregorianUtils.from_time( GregorianTimeType().get_min_time()[0]).year: return self._set_valid_day(year - 1, 12, 31) return date
def __init__(self): self.db = MemoryDB() from timelinelib.time.gregoriantime import GregorianTimeType self.db.time_type = GregorianTimeType() now = gregorian.from_time(self.db.time_type.now()) self.start = self.get_time(now.year, now.month, 1) self.end = self.start + self.get_days_delta(30) self.db._set_displayed_period(TimePeriod(self.db.get_time_type(), self.start, self.end)) self.last_cat = None
def _parse_timetype(self, text, tmp_dict): self.db.set_time_type(None) valid_time_types = (GregorianTimeType(), BosparanianTimeType(), NumTimeType()) for timetype in valid_time_types: if text == timetype.get_name(): self.db.set_time_type(timetype) if timetype.get_name() == BosparanianTimeType().get_name(): set_date_formatter(BosparanianDateFormatter()) else: set_date_formatter(DefaultDateFormatter()) break if self.db.get_time_type() is None: raise ParseException("Invalid timetype '%s' found." % text)
def __init__(self): Observable.__init__(self) self.path = "" self.categories = [] self.category_id_counter = IdCounter() self.events = [] self.event_id_counter = IdCounter() self.displayed_period = None self.hidden_categories = [] self.save_disabled = False from timelinelib.time.gregoriantime import GregorianTimeType self.time_type = GregorianTimeType() self.readonly = False self.importing = False
def on_down(self): def decrement_year(date): year, month, day = date if year > gregorian.from_time( GregorianTimeType().get_min_time()[0]).year: return self._set_valid_day(year - 1, month, day) return date def decrement_month(date): year, month, day = date if month > 1: return self._set_valid_day(year, month - 1, day) elif year > gregorian.from_time( GregorianTimeType().get_min_time()[0]).year: return self._set_valid_day(year - 1, 12, day) return date def decrement_day(date): year, month, day = date if day > 1: return self._set_valid_day(year, month, day - 1) elif month > 1: return self._set_valid_day(year, month - 1, 31) elif year > gregorian.from_time( GregorianTimeType().get_min_time()[0]).year: return self._set_valid_day(year - 1, 12, 31) return date if not self._current_date_is_valid(): return selection = self.date_picker.GetSelection() current_date = self.get_value() if self._insertion_point_in_region(self.region_year): new_date = decrement_year(current_date) elif self._insertion_point_in_region(self.region_month): new_date = decrement_month(current_date) else: year, month, day = current_date gregorian.from_date(year, month, day) if gregorian.from_date( year, month, day).to_time() == GregorianTimeType().get_min_time()[0]: return new_date = decrement_day(current_date) self._save_preferred_day(new_date) if current_date != new_date: self._set_new_date_and_restore_selection(new_date, selection)
def on_up(self): max_year = gregorian.from_time( GregorianTimeType().get_max_time()[0]).year def increment_year(date): year, month, day = date if year < max_year - 1: return self._set_valid_day(year + 1, month, day) return date def increment_month(date): year, month, day = date if month < 12: return self._set_valid_day(year, month + 1, day) elif year < max_year - 1: return self._set_valid_day(year + 1, 1, day) return date def increment_day(date): year, month, day = date time = gregorian.from_date(year, month, day).to_time() if time < GregorianTimeType().get_max_time()[0] - delta_from_days( 1): return gregorian.from_time(time + delta_from_days(1)).to_date_tuple() return date if not self._current_date_is_valid(): return selection = self.date_picker.GetSelection() current_date = self.get_value() if self._insertion_point_in_region(self.region_year): new_date = increment_year(current_date) elif self._insertion_point_in_region(self.region_month): new_date = increment_month(current_date) else: new_date = increment_day(current_date) self._save_preferred_day(new_date) if current_date != new_date: self._set_new_date_and_restore_selection(new_date, selection)
def _set_cal_range(self, cal): min_date, _ = GregorianTimeType().get_min_time() max_date, _ = GregorianTimeType().get_max_time() min_date = self.time_to_wx_date(min_date) max_date = self.time_to_wx_date(max_date) - wx.DateSpan.Day() cal.SetDateRange(min_date, max_date)
def _ensure_within_allowed_period(self, date): year, month, day = date time = Gregorian(year, month, day, 0, 0, 0).to_time() if (time >= GregorianTimeType().get_max_time()[0] or time < GregorianTimeType().get_min_time()[0]): raise ValueError()
def decrement_year(date): year, month, day = date if year > GregorianUtils.from_time( GregorianTimeType().get_min_time()[0]).year: return self._set_valid_day(year - 1, month, day) return date
def _select_timetype(self, timetype): if timetype == None: timetype = GregorianTimeType() return timetype
def import_db_from_timeline_xml(path): db = MemoryDB() db.path = path db.set_time_type(GregorianTimeType()) Parser(db, path).parse() return db
def get_time_type(self): return GregorianTimeType()