Ejemplo n.º 1
0
 def _handle_valid_path(self):
     try:
         db_to_import = db_open(self.view.GetFilePath())
     except Exception as e:
         self._set_error(_("Unable to load events: %s.") % ex_msg(e))
     else:
         self._report_nbr_of_events_in_db(db_to_import)
Ejemplo n.º 2
0
 def _read_calendar_object(self, file_contents):
     try:
         return Calendar.from_ical(file_contents)
     except Exception as pe:
         msg1 = _("Unable to read calendar data.")
         msg2 = "\n\n" + ex_msg(pe)
         raise TimelineIOError(msg1 + msg2)
Ejemplo n.º 3
0
 def _handle_valid_path(self):
     try:
         db_to_import = db_open(self.view.GetFilePath())
     except Exception as e:
         self._set_error(_("Unable to load events: %s.") % ex_msg(e))
     else:
         self._report_nbr_of_events_in_db(db_to_import)
Ejemplo n.º 4
0
    def _load(self):
        """
        Load timeline data from the file that this timeline points to.

        This should only be done once when this class is created.

        The data is stored internally until we do a save.

        If a read error occurs a TimelineIOError will be raised.
        """
        if not os.path.exists(self.path):
            # Nothing to load. Will create a new timeline on save.
            return
        try:
            # _parse_version will create the rest of the schema dynamically
            partial_schema = Tag("timeline", SINGLE, None,
                                 [Tag("version", SINGLE, self._parse_version)])
            tmp_dict = {
                "partial_schema": partial_schema,
                "category_map": {},
                "hidden_categories": [],
            }
            self.disable_save()
            parse(self.path, partial_schema, tmp_dict)
            self.enable_save(call_save=False)
        except Exception, e:
            msg = _("Unable to read timeline data from '%s'.")
            whole_msg = (msg + "\n\n%s") % (abspath(self.path), ex_msg(e))
            raise TimelineIOError(whole_msg)
Ejemplo n.º 5
0
 def ok_button_clicked(self, evt):
     try:
         if self.view.GetTime() is None:
             raise ValueError(_("Invalid date"))
     except ValueError as ex:
         display_error_message(ex_msg(ex))
     else:
         self.view.Close()
Ejemplo n.º 6
0
 def on_return(self):
     try:
         self.time = self.time_picker.get_value()
         if not self.checkbox.IsChecked():
             gt = gregorian.from_time(self.time)
             gt.hour = 12
             self.time = gt.to_time()
     except ValueError, ex:
         display_error_message(ex_msg(ex))
Ejemplo n.º 7
0
 def on_return(self):
     try:
         self.time = self.time_picker.get_value()
         if not self.checkbox.IsChecked():
             gt = gregorian.from_time(self.time)
             gt.hour = 12
             self.time = gt.to_time()
     except ValueError, ex:
         display_error_message(ex_msg(ex))
Ejemplo n.º 8
0
 def _save_application_config(self):
     self.config.set_window_size(self.GetSize())
     self.config.set_window_pos(self.GetPosition())
     self.config.window_maximized = self.IsMaximized()
     self.config.sidebar_width = self.main_panel.get_sidebar_width()
     try:
         self.config.write()
     except IOError as ex:
         friendly = _("Unable to write configuration file.")
         msg = "%s\n\n%s" % (friendly, ex_msg(ex))
         display_error_message(msg, self)
Ejemplo n.º 9
0
 def Navigate(self, navigation_fn):
     try:
         TimelineCanvas.Navigate(self, navigation_fn)
     except (TimeOutOfRangeLeftError) as e:
         self._status_bar.set_text(_("Can't scroll more to the left"))
     except (TimeOutOfRangeRightError) as e:
         self._status_bar.set_text(_("Can't scroll more to the right"))
     except (ValueError, OverflowError) as e:
         self._status_bar.set_text(ex_msg(e))
     else:
         self._status_bar.set_text("")
Ejemplo n.º 10
0
 def _save_application_config(self):
     self.config.set_window_size(self.GetSize())
     self.config.set_window_pos(self.GetPosition())
     self.config.window_maximized = self.IsMaximized()
     self.config.sidebar_width = self.main_panel.get_sidebar_width()
     try:
         self.config.write()
     except IOError as ex:
         friendly = _("Unable to write configuration file.")
         msg = "%s\n\n%s" % (friendly, ex_msg(ex))
         display_error_message(msg, self)
Ejemplo n.º 11
0
 def ok_button_clicked(self, evt):
     try:
         time = self.view.GetTime()
         if time is None:
             raise ValueError(_("Invalid date"))
         if self.time_type.is_date_time_type():
             if not self.view.ShowTimeIsChecked():
                 gt = self.time_type.get_utils().from_time(time)
                 gt.hour = 12
                 self.view.SetTime(gt.to_time())
     except ValueError, ex:
         display_error_message(ex_msg(ex))
Ejemplo n.º 12
0
 def ok_button_clicked(self, evt):
     try:
         time = self.view.GetTime()
         if time is None:
             raise ValueError(_("Invalid date"))
         if self.time_type.is_date_time_type():
             if not self.view.ShowTimeIsChecked():
                 gt = self.time_type.get_utils().from_time(time)
                 gt.hour = 12
                 self.view.SetTime(gt.to_time())
     except ValueError, ex:
         display_error_message(ex_msg(ex))
Ejemplo n.º 13
0
 def _get_period_from_view(self):
     try:
         period = self.view.GetPeriod()
     except ValueError as ex:
         self.view.DisplayInvalidPeriod("%s" % ex_msg(ex))
         raise ValueError()
     (start, end) = (period.get_start_time(), period.get_end_time())
     if self.event is not None and self.view.GetLocked():
         self._verify_that_time_has_not_been_changed(start, end)
     end = self._adjust_end_if_ends_today(start, end)
     TimePeriod(start, end)
     return (start, end)
Ejemplo n.º 14
0
 def _load(self):
     try:
         # _parse_version will create the rest of the schema dynamically
         partial_schema = Tag("timeline", SINGLE, None,
                              [Tag("version", SINGLE, self._parse_version)])
         tmp_dict = {
             "partial_schema": partial_schema,
             "category_map": {},
             "hidden_categories": [],
         }
         parse(self.path, partial_schema, tmp_dict)
     except Exception as e:
         msg = _("Unable to read timeline data from '%s'.")
         whole_msg = (msg + "\n\n%s") % (abspath(self.path), ex_msg(e))
         raise TimelineIOError(whole_msg)
Ejemplo n.º 15
0
 def _load(self):
     try:
         # _parse_version will create the rest of the schema dynamically
         partial_schema = Tag("timeline", SINGLE, None, [
             Tag("version", SINGLE, self._parse_version)
         ])
         tmp_dict = {
             "partial_schema": partial_schema,
             "category_map": {},
             "hidden_categories": [],
         }
         parse(self.path, partial_schema, tmp_dict)
     except Exception as e:
         msg = _("Unable to read timeline data from '%s'.")
         whole_msg = (msg + "\n\n%s") % (abspath(self.path), ex_msg(e))
         raise TimelineIOError(whole_msg)
Ejemplo n.º 16
0
def _load(db, path):
    try:
        ics_file = open(path, "rb")
        try:
            file_contents = ics_file.read()
            try:
                cal = Calendar.from_ical(file_contents)
                for event in cal.walk("VEVENT"):
                    _load_event(db, event)
            except Exception, pe:
                msg1 = _("Unable to read timeline data from '%s'.")
                msg2 = "\n\n" + ex_msg(pe)
                raise TimelineIOError((msg1 % abspath(path)) + msg2)
        finally:
            ics_file.close()
    except IOError, e:
        msg = _("Unable to read from file '%s'.")
        whole_msg = (msg + "\n\n%s") % (abspath(path), e)
        raise TimelineIOError(whole_msg)
Ejemplo n.º 17
0
 def import_timeline(self, path):
     try:
         ics_file = open(path, "rb")
         try:
             file_contents = ics_file.read()
             try:
                 cal = Calendar.from_ical(file_contents)
                 for event in cal.walk("VEVENT"):
                     event["timeline_id"] = self.event_id_counter.get_next()
                 self.cals.append(cal)
             except Exception, pe:
                 msg1 = _("Unable to read timeline data from '%s'.")
                 msg2 = "\n\n" + ex_msg(pe)
                 raise TimelineIOError((msg1 % abspath(path)) + msg2)
         finally:
             ics_file.close()
     except IOError, e:
         msg = _("Unable to read from file '%s'.")
         whole_msg = (msg + "\n\n%s") % (abspath(self.path), e)
         raise TimelineIOError(whole_msg)
Ejemplo n.º 18
0
Archivo: ics.py Proyecto: sk/gnumed
 def import_timeline(self, path):
     try:
         ics_file = open(path, "rb")
         try:
             file_contents = ics_file.read()
             try:
                 cal = Calendar.from_ical(file_contents)
                 for event in cal.walk("VEVENT"):
                     event["timeline_id"] = self.event_id_counter.get_next()
                 self.cals.append(cal)
             except Exception, pe:
                 msg1 = _("Unable to read timeline data from '%s'.")
                 msg2 = "\n\n" + ex_msg(pe)
                 raise TimelineIOError((msg1 % abspath(path)) + msg2)
         finally:
             ics_file.close()
     except IOError, e:
         msg = _("Unable to read from file '%s'.")
         whole_msg = (msg + "\n\n%s") % (abspath(self.path), e)
         raise TimelineIOError(whole_msg)
Ejemplo n.º 19
0
 def populate(self, error):
     self.txt_error.SetLabel(ex_msg(error))
Ejemplo n.º 20
0
 def populate(self, error):
     self.txt_error.SetLabel(ex_msg(error))