コード例 #1
0
ファイル: treebasemodel.py プロジェクト: mahsoud/gramps
    def __rebuild_filter(self, dfilter, skip, items, gen_cursor, data_map,
                         add_func):
        """
        Rebuild the data map for a single Gramps object type, where a filter
        is applied.
        """
        pmon = progressdlg.ProgressMonitor(progressdlg.GtkProgressDialog,
                                           popup_time=2)
        status = progressdlg.LongOpStatus(msg=_("Building View"),
                                          total_steps=3,
                                          interval=1)
        pmon.add_op(status)
        status_ppl = progressdlg.LongOpStatus(msg=_("Loading items..."),
                                              total_steps=items,
                                              interval=items // 10)
        pmon.add_op(status_ppl)

        self.__total += items

        with gen_cursor() as cursor:
            for handle, data in cursor:
                if not isinstance(handle, str):
                    handle = handle.decode('utf-8')
                status_ppl.heartbeat()
                if not handle in skip:
                    if not dfilter or dfilter.match(handle, self.db):
                        add_func(handle, data)
                        self.__displayed += 1
        status_ppl.end()
        status.end()
コード例 #2
0
ファイル: treebasemodel.py プロジェクト: goetzk/gramps
    def __rebuild_filter(self, dfilter, skip, items, gen_cursor, data_map,
                         add_func):
        """
        Rebuild the data map for a single Gramps object type, where a filter 
        is applied.
        """
        pmon = progressdlg.ProgressMonitor(progressdlg.GtkProgressDialog,
                                           popup_time=2)
        status = progressdlg.LongOpStatus(msg=_("Building View"),
                                          total_steps=3,
                                          interval=1)
        pmon.add_op(status)
        status_ppl = progressdlg.LongOpStatus(msg=_("Obtaining all rows"),
                                              total_steps=items,
                                              interval=items // 10)
        pmon.add_op(status_ppl)

        self.__total += items

        def beat(key):
            status_ppl.heartbeat()
            # for python3 this returns a byte object, so conversion needed
            if not isinstance(key, str):
                key = key.decode('utf-8')
            return key

        with gen_cursor() as cursor:
            handle_list = [beat(key) for key, data in cursor]
        status_ppl.end()
        status.heartbeat()

        if dfilter:
            _LOG.debug("rebuild filter %s" % dfilter)
            _LOG.debug("    list before filter %s" % handle_list)
            status_filter = progressdlg.LongOpStatus(msg=_("Applying filter"),
                                                     total_steps=items,
                                                     interval=items // 10)
            pmon.add_op(status_filter)
            handle_list = dfilter.apply(self.db,
                                        handle_list,
                                        cb_progress=status_filter.heartbeat)
            _LOG.debug("    list after filter %s" % handle_list)
            status_filter.end()
        status.heartbeat()

        todisplay = len(handle_list)
        status_col = progressdlg.LongOpStatus(
            msg=_("Constructing column data"),
            total_steps=todisplay,
            interval=todisplay // 10)
        pmon.add_op(status_col)
        for handle in handle_list:
            status_col.heartbeat()
            data = data_map(handle)
            if not handle in skip:
                add_func(handle, data)
                self.__displayed += 1
        status_col.end()
        status.end()
コード例 #3
0
    def __rebuild_filter(self, dfilter, skip, items, gen_cursor, data_map,
                         add_func):
        """
        Rebuild the data map for a single Gramps object type, where a filter
        is applied.
        """
        pmon = progressdlg.ProgressMonitor(progressdlg.StatusProgress,
                                           (self.uistate, ),
                                           popup_time=2,
                                           title=_("Loading items..."))
        status_ppl = progressdlg.LongOpStatus(total_steps=items,
                                              interval=items // 20)
        pmon.add_op(status_ppl)

        self.__total += items
        assert not skip
        if dfilter:
            for handle in dfilter.apply(self.db,
                                        user=User(parent=self.uistate.window)):
                status_ppl.heartbeat()
                data = data_map(handle)
                add_func(handle, data)
                self.__displayed += 1
        else:
            with gen_cursor() as cursor:
                for handle, data in cursor:
                    status_ppl.heartbeat()
                    add_func(handle, data)
                    self.__displayed += 1

        status_ppl.end()
コード例 #4
0
ファイル: treebasemodel.py プロジェクト: goetzk/gramps
 def __rebuild_search(self, dfilter, skip, items, gen_cursor, add_func):
     """
     Rebuild the data map for a single Gramps object type, where a search 
     condition is applied.
     """
     pmon = progressdlg.ProgressMonitor(progressdlg.GtkProgressDialog,
                                        popup_time=2)
     status = progressdlg.LongOpStatus(msg=_("Building View"),
                                       total_steps=items,
                                       interval=items // 20,
                                       can_cancel=True)
     pmon.add_op(status)
     with gen_cursor() as cursor:
         for handle, data in cursor:
             # for python3 this returns a byte object, so conversion needed
             if not isinstance(handle, str):
                 handle = handle.decode('utf-8')
             status.heartbeat()
             if status.should_cancel():
                 break
             self.__total += 1
             if not (handle in skip or
                     (dfilter and not dfilter.match(handle, self.db))):
                 _LOG.debug("    add %s %s" % (handle, data))
                 self.__displayed += 1
                 add_func(handle, data)
     if not status.was_cancelled():
         status.end()
コード例 #5
0
 def __rebuild_search(self, dfilter, skip, items, gen_cursor, add_func):
     """
     Rebuild the data map for a single Gramps object type, where a search
     condition is applied.
     """
     pmon = progressdlg.ProgressMonitor(progressdlg.StatusProgress,
                                        (self.uistate, ),
                                        popup_time=2,
                                        title=_("Loading items..."))
     status = progressdlg.LongOpStatus(total_steps=items,
                                       interval=items // 20)
     pmon.add_op(status)
     with gen_cursor() as cursor:
         for handle, data in cursor:
             # for python3 this returns a byte object, so conversion needed
             if not isinstance(handle, str):
                 handle = handle.decode('utf-8')
             status.heartbeat()
             self.__total += 1
             if not (handle in skip or
                     (dfilter and not dfilter.match(handle, self.db))):
                 _LOG.debug("    add %s %s" % (handle, data))
                 self.__displayed += 1
                 add_func(handle, data)
     status.end()
コード例 #6
0
    def cb_remove_clicked(self, button, top):
        """
        Remove the selected tag.
        """
        store, iter_ = self.namemodel.get_selected()
        if iter_ is None:
            return
        tag_handle = store.get_value(iter_, 1)
        tag_name = store.get_value(iter_, 2)
    
        yes_no = QuestionDialog2(
            _("Remove tag '%s'?") % tag_name,
            _("The tag definition will be removed.  "
              "The tag will be also removed from all objects in the database."),
            _("Yes"),
            _("No"))
        prompt = yes_no.run()
        if prompt:

            fnc = {'Person': (self.db.get_person_from_handle,
                              self.db.commit_person),
                   'Family': (self.db.get_family_from_handle,
                              self.db.commit_family),
                   'Event': (self.db.get_event_from_handle,
                             self.db.commit_event),
                   'Place': (self.db.get_place_from_handle,
                             self.db.commit_place),
                   'Source': (self.db.get_source_from_handle,
                              self.db.commit_source),
                   'Citation': (self.db.get_citation_from_handle,
                                self.db.commit_citation),
                   'Repository': (self.db.get_repository_from_handle,
                                  self.db.commit_repository),
                   'MediaObject': (self.db.get_object_from_handle,
                                   self.db.commit_media_object),
                   'Note': (self.db.get_note_from_handle,
                            self.db.commit_note)}

            links = [link for link in self.db.find_backlink_handles(tag_handle)]
            # Make the dialog modal so that the user can't start another
            # database transaction while the one removing tags is still running.
            pmon = progressdlg.ProgressMonitor(progressdlg.GtkProgressDialog, 
                       ("", self.parent_window, Gtk.DialogFlags.MODAL), popup_time=2)
            status = progressdlg.LongOpStatus(msg=_("Removing Tags"),
                                              total_steps=len(links),
                                              interval=len(links)//20)
            pmon.add_op(status)

            msg = _('Delete Tag (%s)') % tag_name
            with DbTxn(msg, self.db) as trans:
                for classname, handle in links:
                    status.heartbeat()
                    obj = fnc[classname][0](handle) # get from handle
                    obj.remove_tag(tag_handle)
                    fnc[classname][1](obj, trans) # commit

                self.db.remove_tag(tag_handle, trans)
                self.__change_tag_priority(trans)
            self.namemodel.remove(iter_)
            status.end()
コード例 #7
0
ファイル: tags.py プロジェクト: uli22/gramps
 def tag_selected_rows(self, tag_handle):
     """
     Tag the selected rows with the given tag.
     """
     view = self.uistate.viewmanager.active_page
     selected = view.selected_handles()
     # Make the dialog modal so that the user can't start another
     # database transaction while the one setting tags is still running.
     pmon = progressdlg.ProgressMonitor(progressdlg.GtkProgressDialog,
             ("", self.uistate.window, Gtk.DialogFlags.MODAL), popup_time=2)
     status = progressdlg.LongOpStatus(msg=_("Adding Tags"),
                                       total_steps=len(selected),
                                       interval=len(selected)//20)
     pmon.add_op(status)
     tag = self.db.get_tag_from_handle(tag_handle)
     msg = _('Tag Selection (%s)') % tag.get_name()
     with DbTxn(msg, self.db) as trans:
         for object_handle in selected:
             status.heartbeat()
             view.add_tag(trans, object_handle, tag_handle)
     status.end()