Beispiel #1
0
    def copy_file(self, from_fname, to_fname, to_dir=''):
        """
        Copy a file from a source to a (report) destination.
        If to_dir is not present, then the destination directory will be created.

        Normally 'to_fname' will be just a filename, without directory path.

        'to_dir' is the relative path name in the destination root. It will
        be prepended before 'to_fname'.
        """
        #build absolute path
        dest = os.path.join(self._backend.datadirfull(), to_dir, to_fname)

        destdir = os.path.dirname(dest)
        if not os.path.isdir(destdir):
            os.makedirs(destdir)

        if from_fname != dest:
            shutil.copyfile(from_fname, dest)
        elif self.warn_dir:
            from QuestionDialog import WarningDialog
            WarningDialog(
                _("Possible destination error") + "\n" +
                _("You appear to have set your target directory "
                  "to a directory used for data storage. This "
                  "could create problems with file management. "
                  "It is recommended that you consider using "
                  "a different directory to store your generated "
                  "web pages."))
            self.warn_dir = False
Beispiel #2
0
def _display_welcome_message():
    """
    Display a welcome message to the user.
    """
    if not config.get('behavior.betawarn'):
        from QuestionDialog import WarningDialog
        WarningDialog(
            _('Danger: This is unstable code!'),
            _("This Gramps 3.x-trunk is a development release. "
              "This version is not meant for normal usage. Use "
              "at your own risk.\n"
              "\n"
              "This version may:\n"
              "1) Work differently than you expect.\n"
              "2) Fail to run at all.\n"
              "3) Crash often.\n"
              "4) Corrupt your data.\n"
              "5) Save data in a format that is incompatible with the "
              "official release.\n"
              "\n"
              "<b>BACKUP</b> your existing databases before opening "
              "them with this version, and make sure to export your "
              "data to XML every now and then."))
        config.set('behavior.autoload', False)
        #        config.set('behavior.betawarn', True)
        config.set('behavior.betawarn', config.get('behavior.betawarn'))
Beispiel #3
0
 def __warn(self, *obj):
     """
     Don't let the user close the progress dialog.
     """
     from QuestionDialog import WarningDialog
     WarningDialog(_("Attempt to force closing the dialog"),
                   _("Please do not force closing this important dialog."),
                   self.__dialog)
     return True
Beispiel #4
0
 def add_bookmark(self, obj):
     mlist = self.selected_handles()
     if mlist:
         self.bookmarks.add(mlist[0])
     else:
         from QuestionDialog import WarningDialog
         WarningDialog(
             _("Could Not Set a Bookmark"), 
             _("A bookmark could not be set because "
               "no one was selected."))
 def home(self, obj):
     """
     Move to the default person.
     """
     defperson = self.dbstate.db.get_default_person()
     if defperson:
         self.change_active(defperson.get_handle())
     else:
         from QuestionDialog import WarningDialog
         WarningDialog(_("No Home Person"), 
                       _("You need to set a 'default person' to go to."))
Beispiel #6
0
 def warn(self, title, warning=""):
     """
     Warn the user.
     
     @param title: the title of the warning
     @type title: str
     @param warning: the warning
     @type warning: str
     @returns: none
     """
     WarningDialog(title, warning)
Beispiel #7
0
    def add_bookmark(self, obj):
        mlist = []
        self.selection.selected_foreach(self.blist, mlist)

        if mlist:
            self.bookmarks.add(mlist[0])
        else:
            from QuestionDialog import WarningDialog
            WarningDialog(
                _("Could Not Set a Bookmark"),
                _("A bookmark could not be set because "
                  "nothing was selected."))
 def time_str_to_sec(self, time_str):
     time_sec = None
     iso_date_time = self.add_time(time_str)
     try:
         time_tup = time.strptime(iso_date_time, "%Y-%m-%d %H:%M:%S")
         time_sec = time.mktime(time_tup)
     except ValueError:
         from QuestionDialog import WarningDialog
         WarningDialog(_("Wrong format of date-time"),
             _("Only date-times in the iso format of yyyy-mm-dd "
               "hh:mm:ss, where the time part is optional, are "
               "accepted. %s does not satisfy.") % iso_date_time)
     return time_sec
Beispiel #9
0
 def edit_button_clicked(self, obj):
     ref = self.get_selected()
     if ref:
         obj = self.dbstate.db.get_object_from_handle(
             ref.get_reference_handle())
         try:
             from gui.editors import EditMediaRef
             EditMediaRef(self.dbstate, self.uistate, self.track, obj, ref,
                          self.edit_callback)
         except Errors.WindowActiveError:
             from QuestionDialog import WarningDialog
             WarningDialog(_("Cannot edit this reference"),
                           self.__blocked_text())
    def share_button_clicked(self, obj):
        SelectCitation = SelectorFactory('Citation')

        sel = SelectCitation(self.dbstate, self.uistate, self.track)
        object = sel.run()
        LOG.debug("selected object: %s" % object)
        # the object returned should either be a Source or a Citation
        if object:
            if isinstance(object, Source):
                try:
                    from gui.editors import EditCitation
                    EditCitation(self.dbstate,
                                 self.uistate,
                                 self.track,
                                 gen.lib.Citation(),
                                 object,
                                 callback=self.add_callback,
                                 callertitle=self.callertitle)
                except Errors.WindowActiveError:
                    from QuestionDialog import WarningDialog
                    WarningDialog(_("Cannot share this reference"),
                                  self.__blocked_text())
            elif isinstance(object, Citation):
                try:
                    from gui.editors import EditCitation
                    EditCitation(self.dbstate,
                                 self.uistate,
                                 self.track,
                                 object,
                                 callback=self.add_callback,
                                 callertitle=self.callertitle)
                except Errors.WindowActiveError:
                    from QuestionDialog import WarningDialog
                    WarningDialog(_("Cannot share this reference"),
                                  self.__blocked_text())
            else:
                raise ValueError("selection must be either source or citation")
Beispiel #11
0
    def share_button_clicked(self, obj):
        SelectEvent = SelectorFactory('Event')

        sel = SelectEvent(self.dbstate, self.uistate, self.track)
        event = sel.run()
        if event:
            try:
                ref = gen.lib.EventRef()
                ref.set_role(self.default_role())
                self.get_ref_editor()(self.dbstate, self.uistate, self.track,
                                      event, ref, self.object_added)
            except Errors.WindowActiveError:
                from QuestionDialog import WarningDialog
                WarningDialog(_("Cannot share this reference"),
                              self.__blocked_text())
Beispiel #12
0
 def link_place(self, menu, event, lat, lon):
     """
     Link an existing place using longitude and latitude of location centered
     on the map
     If we have a place history, we must show all places to avoid an empty
     place selection in the PlaceSelection.
     """
     if self.uistate.get_active('Place'):
         self._createmap(None)
     selector = SelectPlace(self.dbstate, self.uistate, [])
     place = selector.run()
     if place:
         loc = place.get_main_location()
         oldv = (loc.get_country(), loc.get_state(),
                 loc.get_county()) if loc else None
         places_handle = self.dbstate.db.iter_place_handles()
         nb_places = 0
         gids = ""
         for place_hdl in places_handle:
             plce = self.dbstate.db.get_place_from_handle(place_hdl)
             if plce.get_title() == place.get_title():
                 nb_places += 1
                 if gids == "":
                     gids = plce.gramps_id
                 else:
                     gids = gids + ", " + plce.gramps_id
         if nb_places > 1:
             from QuestionDialog import WarningDialog
             WarningDialog(
                 _('You have at least two places with the same title.'),
                 _("The title of the places is :\n"
                   "<b>%(title)s</b>\n"
                   "The following places are similar : %(gid)s\n"
                   "Eiher you rename the places either you merge them."
                   "\n\n<b>I can't proceed your request</b>.\n") % {
                       'title': place.get_title(),
                       'gid': gids
                   })
         else:
             self.mark = [
                 None, None, None, None, None, None, None, None, None,
                 place.gramps_id, None, None
             ]
             self.select_fct = PlaceSelection(self.uistate, self.dbstate,
                                              self.osm,
                                              self.selection_layer,
                                              self.place_list, lat, lon,
                                              self.__edit_place, oldv)
    def add_bookmark(self, obj):
        """
        Add a bookmark to the list.
        """
        from gen.display.name import displayer as name_displayer

        active_handle = self.uistate.get_active('Person')
        active_person = self.dbstate.db.get_person_from_handle(active_handle)
        if active_person:
            self.bookmarks.add(active_handle)
            name = name_displayer.display(active_person)
            self.uistate.push_message(self.dbstate, 
                                      _("%s has been bookmarked") % name)
        else:
            from QuestionDialog import WarningDialog
            WarningDialog(
                _("Could Not Set a Bookmark"), 
                _("A bookmark could not be set because "
                  "no one was selected."))
 def _handle_drag(self, row, handle):
     """
     A CITATION_LINK has been dragged
     """
     if handle:
         object = self.dbstate.db.get_citation_from_handle(handle)
         if isinstance(object, Citation):
             try:
                 from gui.editors import EditCitation
                 EditCitation(self.dbstate,
                              self.uistate,
                              self.track,
                              object,
                              callback=self.add_callback,
                              callertitle=self.callertitle)
             except Errors.WindowActiveError:
                 from QuestionDialog import WarningDialog
                 WarningDialog(_("Cannot share this reference"),
                               self.__blocked_text())
         else:
             raise ValueError("selection must be either source or citation")
Beispiel #15
0
    def share_button_clicked(self, obj):
        """
        Function called when the Share button is clicked. 
        
        This function should be overridden by the derived class.
        
        """
        SelectObject = SelectorFactory('MediaObject')

        sel = SelectObject(self.dbstate, self.uistate, self.track)
        src = sel.run()
        if src:
            sref = gen.lib.MediaRef()
            try:
                from gui.editors import EditMediaRef
                EditMediaRef(self.dbstate, self.uistate, self.track, src, sref,
                             self.add_callback)
            except Errors.WindowActiveError:
                from QuestionDialog import WarningDialog
                WarningDialog(_("Cannot share this reference"),
                              self.__blocked_text())
 def handle_extra_type(self, objtype, handle):
     """
     A SOURCE_LINK object has been dragged
     """
     if handle:
         object = self.dbstate.db.get_source_from_handle(handle)
         if isinstance(object, Source):
             try:
                 from gui.editors import EditCitation
                 EditCitation(self.dbstate,
                              self.uistate,
                              self.track,
                              gen.lib.Citation(),
                              object,
                              callback=self.add_callback,
                              callertitle=self.callertitle)
             except Errors.WindowActiveError:
                 from QuestionDialog import WarningDialog
                 WarningDialog(_("Cannot share this reference"),
                               self.__blocked_text())
         else:
             raise ValueError("selection must be either source or citation")