当前位置: 首页>>代码示例>>Python>>正文


Python utils.ProgressMeter类代码示例

本文整理汇总了Python中gramps.gui.utils.ProgressMeter的典型用法代码示例。如果您正苦于以下问题:Python ProgressMeter类的具体用法?Python ProgressMeter怎么用?Python ProgressMeter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ProgressMeter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: generate_md5

    def generate_md5(self, button):
        """
        Generate md5 hashes for media files.
        """
        self.clear_models()

        progress = ProgressMeter(self.window_name, can_cancel=True,
                                 parent=self.window)

        length = self.db.get_number_of_media()
        progress.set_pass(_('Generating media hashes'), length)

        with DbTxn(_("Set media hashes"), self.db, batch=True) as trans:

            for handle in self.db.get_media_handles():
                media = self.db.get_media_from_handle(handle)

                full_path = media_path_full(self.db, media.get_path())
                md5sum = create_checksum(full_path)
                if not md5sum:
                    error_msg = 'IOError: %s' % full_path
                    self.models[5].append((error_msg, None))
                    progress.step()
                    continue

                media.set_checksum(md5sum)
                self.db.commit_media(media, trans)

                progress.step()
                if progress.get_cancelled():
                    break

        self.show_tabs()
        progress.close()
开发者ID:daleathan,项目名称:addons-source,代码行数:34,代码来源:MediaVerify.py

示例2: _execute

    def _execute(self):
        """ execute all primary objects and reorder if neccessary """

        # Update progress calculation
        if self.uistate:
            self.progress = ProgressMeter(_('Reorder Gramps IDs'), '')
        else:
            total_objs = 0
            for prim_obj, dummy in self.xobjects:
                if self.obj_values[prim_obj].active_obj:
                    total_objs += self.obj_values[prim_obj].quant_id
            self.set_total(total_objs)

        # Update database
        self.db.disable_signals()
        for prim_obj, prim_objs in self.xobjects:
            with DbTxn(_('Reorder %s IDs ...') % prim_obj,
                       self.db, batch=True) as self.trans:
                if self.obj_values[prim_obj].active_obj:
                    if self.uistate:
                        self.progress.set_pass(
                            _('Reorder %s IDs ...') % _(prim_objs.title()),
                            self.obj_values[prim_obj].quant_id)
                    # Process reordering
                    self._reorder(prim_obj)

        self.db.enable_signals()
        self.db.request_rebuild()

        # Update progress calculation
        if self.uistate:
            self.progress.close()
        else:
            print('\nDone.')
开发者ID:prculley,项目名称:gramps,代码行数:34,代码来源:reorderids.py

示例3: on_ok_clicked

    def on_ok_clicked(self):
        """
        Method that is run when you click the OK button.
        """
        downloaded = {}

        # Get a directory to put the media files in. If the media path in
        # preferences is not just the user's home, then we will use that. If it
        # is the user's home, we create a new directory below that, so we don't
        # splatter files into home.
        media_path = self.db.get_mediapath()
        if media_path == USER_HOME or media_path == "" or media_path == None:
            media_path = os.path.join(USER_HOME, "mediadir")
        if not os.path.isdir(media_path):
            os.makedirs(media_path)

        # Many thanks to 'sirex' from whom I have taken the code he submitted as
        # part of bug 0003553: Import media files from GEDCOM
        file_pattern = re.compile(r'.*\.(png|jpg|jpeg|gif)$')

        def fetch_file(url, filename):
            LOG.debug("Downloading url %s to file %s" % (url, filename))
            fr = urlopen(url)
            fw = open(filename, 'wb')
            for block in fr:
                fw.write(block)
            fw.close()
            fr.close()

        self.progress = ProgressMeter(
            _('Downloading files'), '')
        self.progress.set_pass(_('Downloading files'),
                               self.db.get_number_of_media_objects())

        self.db.disable_signals()
        with DbTxn('Download files', self.db) as trans:
            for media_handle in self.db.media_map.keys():
                media = self.db.get_object_from_handle(media_handle)
                url = media.get_path()
                res = urlparse(url)
                LOG.debug(res)
                if res.scheme == "http" or res.scheme == "https":
                    if file_pattern.match(url):
                        if url in downloaded:
                            full_path = downloaded[url]
                        else:
                            filename = url.split('/')[-1]
                            full_path = os.path.join(media_path, filename)
                            fetch_file(url, full_path)
                            downloaded[url] = full_path
                            self.num_downloads += 1
                        media.set_path(full_path)
                        media.set_mime_type(get_type(full_path))
                        self.db.commit_media_object(media, trans)

                self.progress.step()

        self.db.enable_signals()
        self.db.request_rebuild()
        self.progress.close()
开发者ID:killes,项目名称:addons-source,代码行数:60,代码来源:DownloadMedia.py

示例4: generate_md5

    def generate_md5(self, button):
        """
        Generate md5 hashes for media files and attach them as attributes to
        media objects.
        """
        self.clear_models()

        progress = ProgressMeter(self.window_name, can_cancel=True,
                                 parent=self.window)

        length = self.db.get_number_of_media_objects()
        progress.set_pass(_('Generating media hashes'), length)

        with DbTxn(_("Set media hashes"), self.db, batch=True) as trans:

            for handle in self.db.get_media_object_handles():
                media = self.db.get_object_from_handle(handle)

                full_path = media_path_full(self.db, media.get_path())
                try:
                    with io.open(full_path, 'rb') as media_file:
                        md5sum = hashlib.md5(media_file.read()).hexdigest()
                except IOError as err:
                    error_msg = '%s: %s' % (err.strerror, full_path)
                    self.models[5].append((error_msg, None))
                    progress.step()
                    continue

                for attr in media.get_attribute_list():
                    if str(attr.get_type()) == 'md5':
                        media.remove_attribute(attr)
                        break

                attr = Attribute()
                attr.set_type(AttributeType('md5'))
                attr.set_value(md5sum)

                media.add_attribute(attr)
                
                self.db.commit_media_object(media, trans)

                progress.step()
                if progress.get_cancelled():
                    break

        self.show_tabs()
        progress.close()
开发者ID:SNoiraud,项目名称:addons-source,代码行数:47,代码来源:MediaVerify.py

示例5: display

 def display(self):
     try:
         from bsddb3.db import DBError
     except:
         class DBError(Exception):
             """
             Dummy.
             """
     self.parent = self.top.get_toplevel()
     progress = ProgressMeter(
         _('Updating display...'), '', parent=self.parent)
     self.model.clear()
     self.junk = []
     gc.collect(2)
     self.junk = gc.garbage
     self.label.set_text(_('Uncollected Objects: %s') %
                         str(len(self.junk)))
     progress.set_pass(_('Updating display...'), len(self.junk))
     for count in range(0, len(self.junk)):
         progress.step()
         try:
             refs = []
             referrers = gc.get_referrers(self.junk[count])
             for referrer in referrers:
                 try:
                     if referrer is not self.junk:
                         for indx in range(0, len(self.junk)):
                             if referrer is self.junk[indx]:
                                 refs.append(str(indx) + ' ')
                                 break
                 except:
                     print(sys.exc_info())
             if len(refs) > 3:
                 ref = ' '.join(refs[0:2]) + "..."
             else:
                 ref = ' '.join(refs)
             try:
                 self.model.append((count, ref, str(self.junk[count])))
             except DBError:
                 self.model.append((count, ref,
                                   'db.DB instance at %s' %
                                    id(self.junk[count])))
             except ReferenceError:
                 self.model.append((
                     count, ref,
                     'weakly-referenced object no longer exists %s'
                     % type(self.junk[count])))
             except TypeError:
                 self.model.append((
                     count, ref,
                     'Object cannot be displayed %s'
                     % type(self.junk[count])))
             except:
                 print(sys.exc_info())
         except ReferenceError:
             InfoDialog(_('Reference Error'), "Refresh to correct",
                        parent=self.parent)
     progress.close()
开发者ID:cz172638,项目名称:gramps,代码行数:58,代码来源:leak.py

示例6: prepare

    def prepare(self, db):
        # FIXME: this should user the User class
        from gramps.gui.utils import ProgressMeter
        root_person_id = self.list[0]
        root_person = db.get_person_from_gramps_id(root_person_id)

        progress = ProgressMeter(_('Finding relationship paths'))
        progress.set_pass(header=_('Evaluating people'), mode=ProgressMeter.MODE_ACTIVITY)

        filter_name = self.list[1]
        target_people = filter_database(db, progress, filter_name)

        paths = find_deep_relations(db, progress, root_person, [], [], target_people)

        progress.close()
        progress = None

        self.__matches = set()
        list(map(self.__matches.update, paths))
开发者ID:tester0077,项目名称:gramps,代码行数:19,代码来源:_deeprelationshippathbetween.py

示例7: cleanup

    def cleanup(self, button):
        """
        Cleanup Notes.
        """
        self.clear_models()

        progress = ProgressMeter(self.window_name, can_cancel=True,
                                 parent=self.window)

        length = self.db.get_number_of_notes()
        progress.set_pass(_('Scanning Notes'), length)

        for handle in self.db.get_note_handles():
            note = self.db.get_note_from_handle(handle)
            g_id = note.gramps_id
            stext = note.get_styledtext()
            handle = handle.decode('utf-8')
            optype = -1
            ## find the notes and do cleanup
            if not stext.tags:
                result = self.convert_to_styled(stext.string)
                indx = len(self.changelist)
                for styledtext_tag in result.tags:
                    if int(styledtext_tag.name) == StyledTextTagType.HIGHLIGHT:
                        optype = ISSUE
                        break
                    elif int(styledtext_tag.name) == StyledTextTagType.LINK:
                        optype = LINK
                while True:
                    if optype == ISSUE:
                        # make list of notes with errors
                        self.models[ISSUE].append((self.preview(stext, g_id), indx))
                    elif stext.string != result.string:
                        # Make list of edited notes
                        self.models[CLEANED].append((self.preview(stext, g_id), indx))
                    elif optype == LINK:
                        # make list of notes with only links
                        self.models[LINK].append((self.preview(stext, g_id), indx))
                    else:
                        break
                    self.changelist.append((handle, stext, result))
                    break

            progress.step()
            if progress.get_cancelled():
                break

        self.show_tabs()
        progress.close()
开发者ID:phejl,项目名称:addons-source,代码行数:49,代码来源:NoteCleanup.py

示例8: build_row_data

    def build_row_data(self):
        self.progress_bar = ProgressMeter(_('Comparing Events'),'',
                                            parent=self.window)
        self.progress_bar.set_pass(_('Building data'),len(self.my_list))
        for individual_id in self.my_list:
            individual = self.db.get_person_from_handle(individual_id)
            name = individual.get_primary_name().get_name()
            gid = individual.get_gramps_id()

            the_map = defaultdict(list)
            for ievent_ref in individual.get_event_ref_list():
                ievent = self.db.get_event_from_handle(ievent_ref.ref)
                event_name = str(ievent.get_type())
                the_map[event_name].append(ievent_ref.ref)

            first = True
            done = False
            while not done:
                added = False
                tlist = [name, gid] if first else ["", ""]

                for ename in self.event_titles:
                    if ename in the_map and len(the_map[ename]) > 0:
                        event_handle = the_map[ename][0]
                        del the_map[ename][0]
                        date = place = ""

                        if event_handle:
                            event = self.db.get_event_from_handle(event_handle)
                            date = get_date(event)
                            sortdate = "%09d" % (
                                       event.get_date_object().get_sort_value()
                                       )
                            place_handle = event.get_place_handle()
                            if place_handle:
                                place = self.db.get_place_from_handle(
                                            place_handle).get_title()
                        tlist += [date, sortdate, place]
                        added = True
                    else:
                        tlist += [""]*3

                if first:
                    first = False
                    self.row_data.append(tlist)
                elif not added:
                    done = True
                else:
                    self.row_data.append(tlist)
            self.progress_bar.step()
开发者ID:goetzk,项目名称:gramps,代码行数:50,代码来源:eventcmp.py

示例9: on_ok_clicked

    def on_ok_clicked(self):
        """
        Method that is run when you click the OK button. The numbers of sources
        and citations are retrieved from the entry box and used to govern the
        amount of data generated
        """

        num_sources_text = self.sources_entry.get_text()
        try:
            num_sources = int(num_sources_text)
        except:
            return
        num_citations_text = self.citations_entry.get_text()
        num_citations = int(num_citations_text)

        self.progress = ProgressMeter(
            'Generating data', '', parent=self.uistate.window)
        self.progress.set_pass('Generating data',
                               num_sources*num_citations)
        LOG.debug("sources %04d citations %04d" % (num_sources,
                                                     num_citations))

        source = Source()
        citation = Citation()

        self.db.disable_signals()
        with DbTxn('Populate sources and citations', self.db) as trans:
            for i in range(num_sources):
                source.gramps_id = None
                source.handle = None
                source.title = "Source %04d" % (i + 1)
                source_handle = self.db.add_source(source, trans)

                for j in range(num_citations):
                    citation.gramps_id = None
                    citation.handle = None
                    citation.source_handle = source_handle
                    citation.page = "Page %04d" % (j + 1)
                    self.db.add_citation(citation, trans)
                    self.progress.step()
            LOG.debug("sources and citations added")
        self.db.enable_signals()
        self.db.request_rebuild()
        self.progress.close()

        self.options.handler.options_dict['sources'] = num_sources
        self.options.handler.options_dict['citations'] = num_citations
        # Save options
        self.options.handler.save_options()
开发者ID:belissent,项目名称:gramps,代码行数:49,代码来源:populatesources.py

示例10: generate_md5

    def generate_md5(self, button):
        """
        Generate md5 hashes for media files.
        """
        self.clear_models()

        progress = ProgressMeter(self.window_name, can_cancel=True,
                                 parent=self.window)

        length = self.db.get_number_of_media()
        progress.set_pass(_('Generating media hashes'), length)

        with DbTxn(_("Set media hashes"), self.db, batch=True) as trans:

            for handle in self.db.get_media_handles():
                media = self.db.get_media_from_handle(handle)

                full_path = media_path_full(self.db, media.get_path())
                try:
                    with io.open(full_path, 'rb') as media_file:
                        md5sum = hashlib.md5(media_file.read()).hexdigest()
                except IOError as err:
                    error_msg = '%s: %s' % (err.strerror, full_path)
                    self.models[5].append((error_msg, None))
                    progress.step()
                    continue

                media.set_checksum(md5sum)
                self.db.commit_media(media, trans)

                progress.step()
                if progress.get_cancelled():
                    break

        self.show_tabs()
        progress.close()
开发者ID:belissent,项目名称:addons-source,代码行数:36,代码来源:MediaVerify.py

示例11: __init__

    def __init__(self, dbstate, user, options_class, name, callback=None):
        uistate = user.uistate
        self.label = _('Check Place title')
        tool.BatchTool.__init__(self, dbstate, user, options_class, name)
        if self.fail:
            return

        ManagedWindow.__init__(self,uistate,[], self.__class__)
        self.set_window(Gtk.Window(),Gtk.Label(),'')

        # retrieve options CLI?
        #copy = self.options.handler.options_dict['copy']
        #clean = self.options.handler.options_dict['clean']

        self.db = dbstate.db

        self.total = self.db.get_number_of_places()
        self.progress = ProgressMeter(_('Checking Place Titles'), '',
                                      parent=uistate.window)
        self.progress.set_pass(_('Looking for place fields'),
                               self.total)

        self.name_list = []
        count = 0
        for handle in self.db.get_place_handles(True):
            self.progress.step()
            place = self.db.get_place_from_handle(handle)
            title = place.title
            descr = place_displayer.display(self.db, place)
            if title != (descr and ""):
                count += 1
            if title != "":
                self.name_list.append((handle.decode('utf8'), title, descr))

        self.progress.close()

        if self.name_list:
            self.display()
            OkDialog(_('Differences'),
                     '%s/%s' % (count, self.total),
                     parent=uistate.window)
        else:
            self.progress.close()
            self.close()
            OkDialog(_('No need modifications'),
                     _("No changes need."),
                     parent=uistate.window)
开发者ID:phejl,项目名称:addons-source,代码行数:47,代码来源:checkplacetitles.py

示例12: draw_page

 def draw_page(self, operation, context, page_nr):
     if page_nr == 0:
         self.progress = ProgressMeter(
             _("Printing the tree"), can_cancel=True, cancel_callback=self.cancel_print, parent=self.uistate.window
         )
         message = _("Need to print %(pages)s pages (%(format)s format)")
         self.progress.set_pass(message % {"pages": self.nb_pages, "format": self.format}, self.nb_pages)
     cr = context.get_cairo_context()
     x = y = 0
     x = ((page_nr % self.pages_per_row) * self.width_used) if page_nr > 0 else 0
     y = int(page_nr / self.pages_per_row) * self.height_used
     cr.save()
     cr.translate(-x, -y)
     cr.scale(self.print_zoom, self.print_zoom)
     self.canvas.draw(cr)
     cr.restore()
     if page_nr == self.nb_pages - 1:
         self.progress.close()
     self.progress.step()
开发者ID:sam-m888,项目名称:addons-source,代码行数:19,代码来源:QuiltView.py

示例13: on_apply_clicked

    def on_apply_clicked(self, obj):
        cfilter = self.filter_model[self.filters.get_active()][1]

        progress_bar = ProgressMeter(_("Comparing events"), "", parent=self.window)
        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"), parent=self.window)
        else:
            DisplayChart(self.dbstate, self.uistate, plist, self.track)
开发者ID:jesslinn,项目名称:gramps,代码行数:18,代码来源:eventcmp.py

示例14: fix_media

    def fix_media(self, button):
        """
        Fix paths to moved media files.
        """
        progress = ProgressMeter(self.window_name, can_cancel=True,
                                 parent=self.window)
        progress.set_pass(_('Fixing file paths'), len(self.moved_files))

        with DbTxn(_("Fix media paths"), self.db, batch=True) as trans:

            for handle, new_path in self.moved_files:
                media = self.db.get_object_from_handle(handle)
                media.set_path(new_path)
                self.db.commit_media_object(media, trans)

                progress.step()
                if progress.get_cancelled():
                    break

        self.models[0].clear()
        self.show_tabs()
        progress.close()
开发者ID:killes,项目名称:addons-source,代码行数:22,代码来源:MediaVerify.py

示例15: write_report

    def write_report(self):
        """
        The routine the actually creates the report. At this point, the document
        is opened and ready for writing.
        """

        # Create progress meter bar
        self.progress = ProgressMeter(_("Liste Eclair"), '')

        # Write the title line. Set in INDEX marker so that this section will be
        # identified as a major category if this is included in a Book report.

        title = _("Liste Eclair")
        mark = IndexMark(title, INDEX_TYPE_TOC, 1)
        self.doc.start_paragraph("Eclair-ReportTitle")
        self.doc.write_text(title, mark)
        self.doc.end_paragraph()
        self.__write_all_places()

        # Close the progress meter
        self.progress.close()
开发者ID:belissent,项目名称:addons-source,代码行数:21,代码来源:ListeEclair.py


注:本文中的gramps.gui.utils.ProgressMeter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。