Exemplo n.º 1
0
 def _handle_drag(self, row, obj):
     """
     An event reference that is from a drag and drop has
     an unknown event reference role, so it cannot just be added,
     it needs to be edited and confirmed
     """
     if row[0] == self._WORKGROUP:
         from gen.lib import EventRoleType
         obj.set_role((EventRoleType.UNKNOWN, ''))
         #add the event
         GroupEmbeddedList._handle_drag(self, row, obj)
         #call editor to set new eventref
         event = self.dbstate.db.get_event_from_handle(obj.ref)
         try:
             self.get_ref_editor()(self.dbstate, self.uistate, self.track,
                                   event, obj, self.object_edited)
         except Errors.WindowActiveError:
             from QuestionDialog import WarningDialog
             WarningDialog(
                 _("Cannot edit this reference"),
                 _("This event reference cannot be edited at this time. "
                   "Either the associated event is already being edited "
                   "or another event reference that is associated with "
                   "the same event is being edited.\n\nTo edit this event "
                   "reference, you need to close the event."))
     else:
         self.dropnotworkgroup(row, obj)
Exemplo n.º 2
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
Exemplo n.º 3
0
 def on_save_clicked(self, obj):
     """
     Save the current book in the xml booklist file. 
     """
     self.book_list = BookList(self.file, self.db)
     name = unicode(self.name_entry.get_text())
     if not name:
         WarningDialog(
             _('No book name'),
             _('You are about to save away a book with no name.\n\n'
               'Please give it a name before saving it away.'))
         return
     if name in self.book_list.get_book_names():
         from QuestionDialog import QuestionDialog2
         q = QuestionDialog2(
             _('Book name already exists'),
             _('You are about to save away a '
               'book with a name which already exists.'), _('Proceed'),
             _('Cancel'))
         if q.run():
             self.book.set_name(name)
         else:
             return
     else:
         self.book.set_name(name)
     self.book.set_dbname(self.db.get_save_path())
     self.book_list.set_book(name, self.book)
     self.book_list.save()
Exemplo n.º 4
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'))
Exemplo n.º 5
0
 def _non_native_change(self):
     """
     handle change request of non native data
     """
     from QuestionDialog import WarningDialog
     WarningDialog(
         _("Cannot change Family"),
         _("You cannot change Family events in the Person Editor"))
Exemplo n.º 6
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
Exemplo n.º 7
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."))
Exemplo n.º 8
0
 def on_book_ok_clicked(self, obj):
     """
     Run final BookReportDialog with the current book. 
     """
     if self.book.item_list:
         BookReportDialog(self.dbstate, self.uistate, self.book,
                          BookOptions)
     else:
         WarningDialog(_('No items'), _('This book has no items.'))
         return
     self.close()
Exemplo n.º 9
0
 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."))
Exemplo n.º 10
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)
Exemplo n.º 11
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."))
Exemplo n.º 12
0
 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
Exemplo n.º 13
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())
Exemplo n.º 14
0
    def check_for_family_change(self, handles):
        """
        Callback for family-update signal
        1. This method checks to see if the family shown has been changed. This 
            is possible eg in the relationship view. If the family was changed, 
            the view is refreshed and a warning dialog shown to indicate all 
            changes have been lost.
            If a source/note/event is deleted, this method is called too. This
            is unfortunate as the displaytabs can track themself a delete and
            correct the view for this. Therefore, these tabs are not rebuild.
            Conclusion: this method updates so that remove/change of parent or
            remove/change of children in relationship view reloads the family
            from db.
        2. Changes in other families are of no consequence to the family shown
        """
        if self.obj.get_handle() in handles:
            #rebuild data
            ## Todo: Gallery and note tab are not rebuild ??
            objreal = self.dbstate.db.get_family_from_handle(
                self.obj.get_handle())
            #update selection of data that we obtain from database change:
            maindatachanged = (
                self.obj.gramps_id != objreal.gramps_id
                or self.obj.father_handle != objreal.father_handle
                or self.obj.mother_handle != objreal.mother_handle
                or self.obj.private != objreal.private
                or self.obj.type != objreal.type
                or self.obj.get_tag_list() != objreal.get_tag_list()
                or self.obj.child_ref_list != objreal.child_ref_list)
            if maindatachanged:
                self.obj.gramps_id = objreal.gramps_id
                self.obj.father_handle = objreal.father_handle
                self.obj.mother_handle = objreal.mother_handle
                self.obj.private = objreal.private
                self.obj.type = objreal.type
                self.obj.set_tag_list(objreal.get_tag_list())
                self.obj.child_ref_list = objreal.child_ref_list
                self.reload_people()

            # No matter why the family changed (eg delete of a source), we notify
            # the user
            WarningDialog(
                _("Family has changed"),
                _("The %(object)s you are editing has changed outside this editor."
                  " This can be due to a change in one of the main views, for "
                  "example a source used here is deleted in the source view.\n"
                  "To make sure the information shown is still correct, the "
                  "data shown has been updated. Some edits you have made may have"
                  " been lost.") % {'object': _('family')},
                parent=self.window)
Exemplo n.º 15
0
    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")
Exemplo n.º 16
0
 def edit_button_clicked(self, obj):
     ref = self.get_selected()
     if ref and ref[1] is not None and ref[0] == self._WORKGROUP:
         event = self.dbstate.db.get_event_from_handle(ref[1].ref)
         try:
             self.get_ref_editor()(self.dbstate, self.uistate, self.track,
                                   event, ref[1], self.object_edited)
         except Errors.WindowActiveError:
             from QuestionDialog import WarningDialog
             WarningDialog(_("Cannot edit this reference"),
                           self.__blocked_text())
     elif ref and ref[0] != self._WORKGROUP:
         #bring up family editor
         key = self._groups[ref[0]][0]
         self.editnotworkgroup(key)
Exemplo n.º 17
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())
Exemplo n.º 18
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)
Exemplo n.º 19
0
    def open_book(self, book):
        """
        Open the book: set the current set of selections to this book's items.
        
        book:   the book object to load.
        """
        if book.get_dbname() == self.db.get_save_path():
            same_db = 1
        else:
            same_db = 0
            WarningDialog(
                _('Different database'),
                _('This book was created with the references to database '
                  '%s.\n\n This makes references to the central person '
                  'saved in the book invalid.\n\n'
                  'Therefore, the central person for each item is being set '
                  'to the active person of the currently opened database.') %
                book.get_dbname())

        self.book.clear()
        self.book_model.clear()
        for saved_item in book.get_item_list():
            name = saved_item.get_name()
            item = BookItem(self.db, name)
            item.option_class = saved_item.option_class

            # The option values were loaded magically by the book parser.
            # But they still need to be applied to the menu options.
            opt_dict = item.option_class.handler.options_dict
            menu = item.option_class.menu
            for optname in opt_dict:
                menu_option = menu.get_option_by_name(optname)
                if menu_option:
                    menu_option.set_value(opt_dict[optname])

            _initialize_options(item.option_class, self.dbstate, self.uistate)
            item.set_style_name(saved_item.get_style_name())
            self.book.append_item(item)

            data = [
                item.get_translated_name(),
                item.get_category(),
                item.get_name()
            ]

            data[2] = _get_subject(item.option_class, self.db)
            self.book_model.add(data)
Exemplo n.º 20
0
    def on_apply_clicked(self, obj):
        cfilter = self.filter_model[self.filters.get_active()][1]

        progress_bar = ProgressMeter(_('Comparing events'), '')
        progress_bar.set_pass(_('Selecting people'), 1)

        plist = cfilter.apply(self.db, self.db.iter_person_handles())

        progress_bar.step()
        progress_bar.close()
        self.options.handler.options_dict['filter'] = self.filters.get_active()
        # Save options
        self.options.handler.save_options()

        if len(plist) == 0:
            WarningDialog(_("No matches were found"))
        else:
            DisplayChart(self.dbstate, self.uistate, plist, self.track)
Exemplo n.º 21
0
    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."))
Exemplo n.º 22
0
    def check_for_existing_family(self, father_handle, mother_handle,
                                  family_handle):

        if father_handle:
            father = self.dbstate.db.get_person_from_handle(father_handle)
            ffam = set(father.get_family_handle_list())
            if mother_handle:
                mother = self.dbstate.db.get_person_from_handle(mother_handle)
                mfam = set(mother.get_family_handle_list())
                common = list(mfam.intersection(ffam))
                if len(common) > 0:
                    if self.add_parent or self.obj.handle not in common:
                        WarningDialog(
                            _('Duplicate Family'),
                            _('A family with these parents already exists '
                              'in the database. If you save, you will create '
                              'a duplicate family. It is recommended that '
                              'you cancel the editing of this window, and '
                              'select the existing family'),
                            parent=self.window)
Exemplo n.º 23
0
    def add(self, handle):
        """Append the citation to the bottom of the bookmarks."""
        if self.dbstate.db.get_citation_from_handle(handle):
            ListBookmarks.add(self, handle)
        else:
            # Probably trying to bookmark a source when the navigation type is
            # citation. This can occur when in the Citation Tree View and we
            # bookmark a source.

            # FIXME: See http://www.gramps-project.org/bugs/view.php?id=6352 a
            # more comprehensive solution is needed in the long term. See also
            # change_active in CitatinTreeView
            from QuestionDialog import WarningDialog
            WarningDialog(
                _("Cannot bookmark this reference"),
                "Only Citations can be bookmarked in this view. "
                "You are probably trying to bookmark a Source in the "
                "Citation Tree View. In this view, only Citations "
                "can be bookmarked. To bookmark a Source, switch to "
                "the Source View")
Exemplo n.º 24
0
 def edit_button_clicked(self, obj):
     ref = self.get_selected()
     if ref:
         repo = self.dbstate.db.get_repository_from_handle(ref.ref)
         try:
             from gui.editors import EditRepoRef
             EditRepoRef(
                 self.dbstate, self.uistate, self.track, repo, 
                 ref, self.edit_callback)
         except Errors.WindowActiveError:
             from QuestionDialog import WarningDialog
             WarningDialog(
                 _("Cannot edit this reference"),
                 _("This repository reference cannot be edited at this "
                   "time. Either the associated repository is already "
                   "being edited or another repository reference that is "
                   "associated with the same repository is being edited."
                   "\n\nTo edit this repository reference, you need to "
                   "close the repository.")
                 )
Exemplo n.º 25
0
 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")
Exemplo n.º 26
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())
Exemplo n.º 27
0
 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")
Exemplo n.º 28
0
 def edit(self, obj):
     """
     Edit either a Source or a Citation, depending on user selection
     """
     for handle in self.selected_handles():
         # The handle will either be a Source handle or a Citation handle
         source = self.dbstate.db.get_source_from_handle(handle)
         citation = self.dbstate.db.get_citation_from_handle(handle)
         if (not source and not citation) or (source and citation):
             raise ValueError("selection must be either source or citation")
         if citation:
             try:
                 EditCitation(self.dbstate, self.uistate, [], citation)
             except Errors.WindowActiveError:
                 pass
         else: # FIXME need try block here
             try:
                 EditSource(self.dbstate, self.uistate, [], source)
             except Errors.WindowActiveError:
                 from QuestionDialog import WarningDialog
                 WarningDialog(_("Cannot share this reference"),
                               self.__blocked_text2())
Exemplo n.º 29
0
    def on_setup_clicked(self, obj):
        """
        Configure currently selected item.
        """
        store, the_iter = self.book_model.get_selected()
        if not the_iter:
            WarningDialog(_('No selected book item'),
                          _('Please select a book item to configure.'))
            return
        data = self.book_model.get_data(the_iter, range(self.book_nr_cols))
        row = self.book_model.get_selected_row()
        item = self.book.get_item(row)
        option_class = item.option_class
        option_class.handler.set_default_stylesheet_name(item.get_style_name())
        item.is_from_saved_book = bool(self.book.get_name())
        item_dialog = BookItemDialog(self.dbstate, self.uistate, item,
                                     self.track)

        while True:
            response = item_dialog.window.run()
            if response == gtk.RESPONSE_OK:
                # dialog will be closed by connect, now continue work while
                # rest of dialog is unresponsive, release when finished
                style = option_class.handler.get_default_stylesheet_name()
                item.set_style_name(style)
                subject = _get_subject(option_class, self.db)
                self.book_model.model.set_value(the_iter, 2, subject)
                self.book.set_item(row, item)
                item_dialog.close()
                break
            elif response == gtk.RESPONSE_CANCEL:
                item_dialog.close()
                break
            elif response == gtk.RESPONSE_DELETE_EVENT:
                #just stop, in ManagedWindow, delete-event is already coupled to
                #correct action.
                break
Exemplo n.º 30
0
 def share(self, obj):
     """
     share:      Add a new citation to an existing source (when a source is
                   selected)
     """
     for handle in self.selected_handles():
         # The handle will either be a Source handle or a Citation handle
         source = self.dbstate.db.get_source_from_handle(handle)
         citation = self.dbstate.db.get_citation_from_handle(handle)
         if (not source and not citation) or (source and citation):
             raise ValueError("selection must be either source or citation")
         if source:
             try:
                 EditCitation(self.dbstate, self.uistate, [], 
                              gen.lib.Citation(), source)
             except Errors.WindowActiveError:
                 from QuestionDialog import WarningDialog
                 WarningDialog(_("Cannot share this reference"),
                               self.__blocked_text())
         else:
             msg = _("Cannot add citation.")
             msg2 = _("In order to add a citation to an existing source, "
                      " you must select a source.")
             ErrorDialog(msg, msg2)