Example #1
0
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.canvas.data.db import MemoryDB
        from timelinelib.calendar.gregorian.timetype import GregorianTimeType
        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
Example #2
0
def export_to_images(main_frame):
    path = _get_image_path(main_frame)
    if path is not None:
        try:
            periods, current_period = main_frame.get_export_periods()
        except ValueError:
            msg = _(
                "The first image contains a Julian day < 0\n\nNavigate to first event or\nUse the feature 'Accept negative Julian days'"
            )
            display_warning_message(msg)
            return
        view_properties = DrawingAreaProxy(main_frame).view_properties
        view_properties.set_use_fixed_event_vertical_pos(True)
        path_without_extension, extension = path.rsplit(".", 1)
        view_properties.set_use_fixed_event_vertical_pos(True)
        view_properties.periods = periods
        count = 1
        paths = []
        for period in periods:
            path = "%s_%d.%s" % (path_without_extension, count, extension)
            if _overwrite_existing_path(main_frame, path):
                main_frame.main_panel.timeline_panel.timeline_canvas.Navigate(
                    lambda tp: period)
                main_frame.main_panel.timeline_panel.timeline_canvas.SaveAsPng(
                    path)
            count += 1
            paths.append(path)
        view_properties.set_use_fixed_event_vertical_pos(False)
        main_frame.main_panel.timeline_panel.timeline_canvas.Navigate(
            lambda tp: current_period)
        merged_image_path = "%s_merged.%s" % (path_without_extension,
                                              extension)
        merge_images(paths, merged_image_path)
Example #3
0
def export_to_images(main_frame):
    path = get_image_path(main_frame)
    if path is not None:
        try:
            periods, current_period = main_frame.get_export_periods()
        except ValueError:
            msg = _("The first image contains a Julian day < 0\n\nNavigate to first event or\nUse the feature 'Accept negative Julian days'")
            display_warning_message(msg)
            return
        view_properties = main_frame.main_panel.timeline_panel.timeline_canvas.controller.view_properties
        view_properties.set_use_fixed_event_vertical_pos(True)
        path_without_extension, extension = path.rsplit(".", 1)
        view_properties.set_use_fixed_event_vertical_pos(True)
        view_properties.periods = periods
        count = 1
        paths = []
        for period in periods:
            path = "%s_%d.%s" % (path_without_extension, count, extension)
            if overwrite_existing_path(main_frame, path):
                main_frame.main_panel.timeline_panel.timeline_canvas.Navigate(lambda tp: period)
                main_frame.main_panel.timeline_panel.timeline_canvas.SaveAsPng(path)
            count += 1
            paths.append(path)
        view_properties.set_use_fixed_event_vertical_pos(False)
        main_frame.main_panel.timeline_panel.timeline_canvas.Navigate(lambda tp: current_period)
        merged_image_path = "%s_merged.%s" % (path_without_extension, extension)
        merge_images(paths, merged_image_path)
def export_to_images(main_frame):
    path, image_type = get_image_path(main_frame)
    if path is not None:
        try:
            periods, current_period = main_frame.get_export_periods()
        except ValueError:
            msg = _(
                "The first image contains a Julian day < 0\n\nNavigate to first event or\nUse the feature 'Accept negative Julian days'"
            )
            display_warning_message(msg)
            return
        view_properties = main_frame.main_panel.timeline_panel.timeline_canvas.controller.view_properties
        view_properties.set_use_fixed_event_vertical_pos(True)
        path_without_extension, extension = path.rsplit(".", 1)
        view_properties.set_use_fixed_event_vertical_pos(True)
        view_properties.periods = periods
        count = 1
        for period in periods:
            path = "%s_%d.%s" % (path_without_extension, count, extension)
            if overwrite_existing_path(main_frame, path):
                main_frame.main_panel.timeline_panel.timeline_canvas.controller.view_properties.displayed_period = period
                main_frame.main_panel.redraw_timeline()
                bitmap = main_frame.main_panel.get_current_image()
                image = wx.ImageFromBitmap(bitmap)
                image.SaveFile(path, image_type)
            count += 1
        view_properties.set_use_fixed_event_vertical_pos(False)
        main_frame.main_panel.timeline_panel.timeline_canvas.controller.view_properties.displayed_period = current_period
        main_frame.main_panel.redraw_timeline()
Example #5
0
 def ok_to_edit(self):
     if self._timeline is None:
         return True
     if self._timeline.is_read_only():
         return False
     if self._locked():
         display_warning_message(
             "The Timeline is Locked by someone else.\nTry again later")
         return False
     if self._timeline_path_doesnt_exists_yet():
         self._lock()
         return True
     last_changed = self._get_modification_date()
     if last_changed > self._last_changed:
         ack = get_user_ack(
             _("Someoneelse has changed the Timeline.\nYou have two choices!\n  1. Set Timeline in Read-Only mode.\n  2. Synchronize Timeline.\n\nDo you want to Synchronize?"
               ))
         if ack:
             self.reload_from_disk()
         else:
             self.set_timeline_in_readonly_mode()
         return False
     if last_changed > 0:
         self._lock()
     return True
Example #6
0
 def _set_new_shortcut_for_selected_function(self):
     try:
         self._validate_input()
         self._validate_shortcut()
         function = self.view.get_function()
         shortcut = self._get_shortcut()
         self.shortcut_config.edit(function, shortcut)
     except MissingInput, ex:
         display_warning_message(ex.message)
Example #7
0
 def _set_new_shortcut_for_selected_function(self):
     try:
         self._validate_input()
         self._validate_shortcut()
         function = self.view.get_function()
         shortcut = self._get_shortcut()
         self.shortcut_config.edit(function, shortcut)
     except MissingInput, ex:
         display_warning_message(ex.message)
Example #8
0
 def _lock(self):
     fp = None
     if not self._timeline.get_should_lock():
         return
     try:
         ts = self._get_timestamp_string()
         path = self._get_lockpath()
         fp = open(path, "w")
         fp.write("%s\n%s\n%s" % (getpass.getuser(), ts, os.getpid()))
     except Exception:
         msg = _(
             "Unable to take lock on %s\nThis means you can't edit the timeline.\nCheck if you have write access to this directory.") % self._timelinepath
         display_warning_message(msg, self._main_frame)
         raise LockedException()
     finally:
         if fp is not None:
             fp.close()
Example #9
0
def db_open_ics(path, import_timeline=False):
    global current_timeline
    try:
        import icalendar
    except ImportError:
        raise TimelineIOError(_("Could not find iCalendar Python package. It is required for working with ICS files. See the Timeline website or the doc/installing.rst file for instructions how to install it."))
    else:
        from timelinelib.db.backends.ics import IcsTimeline
        if import_timeline and current_timeline:
            extension = current_timeline.path.rsplit(".", 1)[1]
            if extension != "ics":
                display_warning_message(_("Only %s files can be imported") % extension)
                return current_timeline
            current_timeline.import_timeline(path)
        else:
            current_timeline = IcsTimeline(path)
        return current_timeline
Example #10
0
 def _lock(self):
     fp = None
     if not self._timeline.get_should_lock():
         return
     try:
         ts = self._get_timestamp_string()
         path = self._get_lockpath()
         fp = open(path, "w")
         fp.write("%s\n%s\n%s" % (getpass.getuser(), ts, os.getpid()))
     except Exception:
         msg = _(
             "Unable to take lock on %s\nThis means you can't edit the timeline.\nCheck if you have write access to this directory."
         ) % self._timelinepath
         display_warning_message(msg, self._main_frame)
         raise LockedException()
     finally:
         if fp is not None:
             fp.close()
Example #11
0
def db_open_ics(path, import_timeline=False):
    global current_timeline
    try:
        import icalendar
    except ImportError:
        raise TimelineIOError(
            _("Could not find iCalendar Python package. It is required for working with ICS files. See the Timeline website or the doc/installing.rst file for instructions how to install it."
              ))
    else:
        from timelinelib.db.backends.ics import IcsTimeline
        if import_timeline and current_timeline:
            extension = current_timeline.path.rsplit(".", 1)[1]
            if extension != "ics":
                display_warning_message(
                    _("Only %s files can be imported") % extension)
                return current_timeline
            current_timeline.import_timeline(path)
        else:
            current_timeline = IcsTimeline(path)
        return current_timeline
Example #12
0
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
Example #13
0
 def ok_to_edit(self):
     if self._timeline is None:
         return True
     if self._timeline.is_read_only():
         return False
     if self._locked():
         display_warning_message("The Timeline is Locked by someone else.\nTry again later")
         return False
     if self._timeline_path_doesnt_exists_yet():
         self._lock()
         return True
     last_changed = self._get_modification_date()
     if last_changed > self._last_changed:
         ack = get_user_ack(
             _("Someoneelse has changed the Timeline.\nYou have two choices!\n  1. Set Timeline in Read-Only mode.\n  2. Synchronize Timeline.\n\nDo you want to Synchronize?"))
         if ack:
             self.reload_from_disk()
         else:
             self.set_timeline_in_readonly_mode()
         return False
     if last_changed > 0:
         self._lock()
     return True
Example #14
0
def db_import_timeline(path):
    global current_timeline
    if os.path.isdir(current_timeline.path):
        display_warning_message(_("Other timelines can't be imported to a directory timeline"))
        return current_timeline
    if current_timeline.path == ":tutorial:":
        display_warning_message(_("Tutorial must be saved as a timeline to be able to import other timeline"))
        return current_timeline
    extension = current_timeline.path.rsplit(".", 1)[1]
    if extension != "timeline":
        display_warning_message(_("Only %s files can be imported") % extension)
        return current_timeline
    current_timeline.import_timeline(path)
    return current_timeline
Example #15
0
def db_import_timeline(path):
    global current_timeline
    if os.path.isdir(current_timeline.path):
        display_warning_message(
            _("Other timelines can't be imported to a directory timeline"))
        return current_timeline
    if current_timeline.path == ":tutorial:":
        display_warning_message(
            _("Tutorial must be saved as a timeline to be able to import other timeline"
              ))
        return current_timeline
    extension = current_timeline.path.rsplit(".", 1)[1]
    if extension != "timeline":
        display_warning_message(_("Only %s files can be imported") % extension)
        return current_timeline
    current_timeline.import_timeline(path)
    return current_timeline
Example #16
0
class ShortcutsEditor(object):
    def __init__(self, view, shortcut_config):
        self.view = view
        self.shortcut_config = shortcut_config
        self._populate_view()

    #
    # View API
    #
    def on_function_selected(self):
        self._select_modifier_and_key_for_selected_function()
        
    def apply(self):
        self._set_new_shortcut_for_selected_function()
        pass

    #
    # Internals
    #
    def _select_modifier_and_key_for_selected_function(self):
        function = self.view.get_function()
        modifier, key = self.shortcut_config.get_modifier_and_key(function)
        self.view.set_modifier(modifier)
        self.view.set_shortcut_key(key)
            
    def _set_new_shortcut_for_selected_function(self):
        try:
            self._validate_input()
            self._validate_shortcut()
            function = self.view.get_function()
            shortcut = self._get_shortcut()
            self.shortcut_config.edit(function, shortcut)
        except MissingInput, ex:
            display_warning_message(ex.message)
        except DuplicateShortcut, ex:
            display_warning_message(ex.message)
Example #17
0
 def DisplayWarningMessage(self, text):
     display_warning_message(text)
Example #18
0
    def _report_other_process_uses_lockfile(self, lockpath):
        message = _(
            """The lockfile used to protect the timeline from concurrent updates is opened by another program or process.
This lockfile must be removed in order be able to continue editing the timeline!
The lockfile is found at: %s""") % lockpath
        display_warning_message(message)
Example #19
0
 def DisplayWarningMessage(self, text):
     display_warning_message(text)
Example #20
0
 def _report_on_vevents_not_loaded(self):
     if len(self.vevents_not_loaded) > 0:
         message = ("Some events couldn't be loaded!\n" +
                    "The first 10 failing events are shown below.\n" +
                    self._format_vevents_not_loaded())
         display_warning_message(message)
Example #21
0
    def _report_other_process_uses_lockfile(self, lockpath):
        message = _("""The lockfile used to protect the timeline from concurrent updates is opened by another program or process.
This lockfile must be removed in order be able to continue editing the timeline!
The lockfile is found at: %s""") % lockpath
        display_warning_message(message)