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


Python lib.Citation类代码示例

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


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

示例1: from_struct

def from_struct(struct):
    """
    Given a struct with metadata, create a Gramps object.
    """
    from  gramps.gen.lib import (Person, Family, Event, Source, Place, Citation,
                                 Repository, MediaObject, Note, Tag)
    if isinstance(struct, dict):
        if "_class" in struct.keys():
            if struct["_class"] == "Person":
                return Person.create(Person.from_struct(struct))
            elif struct["_class"] == "Family":
                return Family.create(Family.from_struct(struct))
            elif struct["_class"] == "Event":
                return Event.create(Event.from_struct(struct))
            elif struct["_class"] == "Source":
                return Source.create(Source.from_struct(struct))
            elif struct["_class"] == "Place":
                return Place.create(Place.from_struct(struct))
            elif struct["_class"] == "Citation":
                return Citation.create(Citation.from_struct(struct))
            elif struct["_class"] == "Repository":
                return Repository.create(Repository.from_struct(struct))
            elif struct["_class"] == "MediaObject":
                return MediaObject.create(MediaObject.from_struct(struct))
            elif struct["_class"] == "Note":
                return Note.create(Note.from_struct(struct))
            elif struct["_class"] == "Tag":
                return Tag.create(Tag.from_struct(struct))
    raise AttributeError("invalid struct: %s" % struct)
开发者ID:cicl06,项目名称:gramps,代码行数:29,代码来源:diff.py

示例2: create_event

 def create_event(self, description=_("Estimated date"),
                  type=None, date=None, source=None,
                  note_text="", modifier=None):
     event = Event()
     event.set_description(description)
     note = Note()
     note.handle = create_id()
     note.type.set(NoteType.EVENT)
     note.set(note_text)
     self.db.add_note(note, self.trans)
     event.add_note(note.handle)
     if type:
         event.set_type(EventType(type))
     if date:
         if modifier:
             date.set_modifier(modifier)
         date.set_quality(Date.QUAL_ESTIMATED)
         date.set_yr_mon_day(date.get_year(), 0, 0)
         event.set_date_object(date)
     if source:
         citation = Citation()
         citation.set_reference_handle(source.get_handle())
         self.db.add_citation(citation, self.trans)
         event.add_citation(citation.get_handle())
         self.db.commit_source(source, self.trans)
     self.db.add_event(event, self.trans)
     return event
开发者ID:daleathan,项目名称:addons-source,代码行数:27,代码来源:CalculateEstimatedDates.py

示例3: instance_from_struct

    def instance_from_struct(cls, struct):
        """
        Given a struct with metadata, create a Gramps object.

        self is class when called as a classmethod.
        """
        from  gramps.gen.lib import (Person, Family, Event, Source, Place, Citation,
                                     Repository, Media, Note, Tag, Date)
        if isinstance(struct, dict):
            if "_class" in struct.keys():
                if struct["_class"] == "Person":
                    return Person.create(Person.from_struct(struct))
                elif struct["_class"] == "Family":
                    return Family.create(Family.from_struct(struct))
                elif struct["_class"] == "Event":
                    return Event.create(Event.from_struct(struct))
                elif struct["_class"] == "Source":
                    return Source.create(Source.from_struct(struct))
                elif struct["_class"] == "Place":
                    return Place.create(Place.from_struct(struct))
                elif struct["_class"] == "Citation":
                    return Citation.create(Citation.from_struct(struct))
                elif struct["_class"] == "Repository":
                    return Repository.create(Repository.from_struct(struct))
                elif struct["_class"] == "Media":
                    return Media.create(Media.from_struct(struct))
                elif struct["_class"] == "Note":
                    return Note.create(Note.from_struct(struct))
                elif struct["_class"] == "Tag":
                    return Tag.create(Tag.from_struct(struct))
                elif struct["_class"] == "Date":
                    return Date().unserialize(Date.from_struct(struct, full=True))
        raise AttributeError("invalid struct: %s" % struct)
开发者ID:belissent,项目名称:gramps,代码行数:33,代码来源:struct.py

示例4: citation_sort_date

 def citation_sort_date(self, data):
     if data[COLUMN_DATE]:
         citation = Citation()
         citation.unserialize(data)
         retval = "%09d" % citation.get_date_object().get_sort_value()
         if not get_date_valid(citation):
             return INVALID_DATE_FORMAT % retval
         else:
             return retval
     return ''
开发者ID:belissent,项目名称:gramps,代码行数:10,代码来源:citationbasemodel.py

示例5: citation_date

 def citation_date(self, data):
     if data[COLUMN_DATE]:
         citation = Citation()
         citation.unserialize(data)
         date_str =  get_date(citation)
         if date_str != "":
             retval = escape(date_str)
         if not get_date_valid(citation):
             return INVALID_DATE_FORMAT % retval
         else:
             return retval
     return ''
开发者ID:belissent,项目名称:gramps,代码行数:12,代码来源:citationbasemodel.py

示例6: 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

示例7: get_or_create_source

 def get_or_create_source(self,source_name):
     source = None
     if source_name in self.skeys:
         source = self.db.get_source_from_handle(self.skeys[source_name])
     else:
         source = Source()
         source.set_title(source_name)
         self.db.add_source(source,self.trans)
         self.db.commit_source(source,self.trans)
         self.skeys[source_name] = source.get_handle()
     citation = Citation()
     citation.set_reference_handle(source.get_handle())
     self.db.add_citation(citation, self.trans)
     self.db.commit_citation(citation, self.trans)
     return citation
开发者ID:ewongbb,项目名称:gramps,代码行数:15,代码来源:importgeneweb.py

示例8: importData

def importData(db, filename, user):
    """Function called by Gramps to import data on persons in CSV format."""
    db.disable_signals()
    try:
        with DbTxn(_("JSON import"), db, batch=True) as trans:
            with OpenFileOrStdin(filename, encoding="utf-8") as fp:
                line = fp.readline()
                while line:
                    data = json.loads(line)
                    if data["_class"] == "Person":
                        obj = Person.create(Person.from_struct(data))
                        db.add_person(obj, trans)
                    elif data["_class"] == "Family":
                        obj = Family.create(Family.from_struct(data))
                        db.add_family(obj, trans)
                    elif data["_class"] == "Event":
                        obj = Event.create(Event.from_struct(data))
                        db.add_event(obj, trans)
                    elif data["_class"] == "Media":
                        obj = Media.create(Media.from_struct(data))
                        db.add_media(obj, trans)
                    elif data["_class"] == "Repository":
                        obj = Repository.create(Repository.from_struct(data))
                        db.add_repository(obj, trans)
                    elif data["_class"] == "Tag":
                        obj = Tag.create(Tag.from_struct(data))
                        db.add_tag(obj, trans)
                    elif data["_class"] == "Source":
                        obj = Source.create(Source.from_struct(data))
                        db.add_source(obj, trans)
                    elif data["_class"] == "Citation":
                        obj = Citation.create(Citation.from_struct(data))
                        db.add_citation(obj, trans)
                    elif data["_class"] == "Note":
                        obj = Note.create(Note.from_struct(data))
                        db.add_note(obj, trans)
                    elif data["_class"] == "Place":
                        obj = Place.create(Place.from_struct(data))
                        db.add_place(obj, trans)
                    else:
                        LOG.warn("ignored: " + data)
                    line = fp.readline()
    except EnvironmentError as err:
        user.notify_error(_("%s could not be opened\n") % filename, str(err))

    db.enable_signals()
    db.request_rebuild()
开发者ID:sam-m888,项目名称:addons-source,代码行数:47,代码来源:JSONImport.py

示例9: _add_source

    def _add_source(self,repos=None):
        # Add a Source

        with DbTxn("Add Source and Citation", self._db) as tran:
            source = Source()
            if repos is not None:
                repo_ref = RepoRef()
                repo_ref.set_reference_handle(repos.get_handle())
                source.add_repo_reference(repo_ref)
            self._db.add_source(source, tran)
            self._db.commit_source(source, tran)
            citation = Citation()
            citation.set_reference_handle(source.get_handle())
            self._db.add_citation(citation, tran)
            self._db.commit_citation(citation, tran)

        return citation
开发者ID:bastienjacquet,项目名称:gramps,代码行数:17,代码来源:grampsdbtestbase.py

示例10: find_and_set_citation

 def find_and_set_citation(self, obj, source):
     # look for the source in the existing citations for the object
     LOG.debug("find_and_set_citation: looking for source: %s",
               source.get_gramps_id())
     for citation_handle in obj.get_citation_list():
         citation = self.db.get_citation_from_handle(citation_handle)
         LOG.debug("find_and_set_citation: existing citation: %s",
                   citation.get_gramps_id())
         poss_source = self.db.get_source_from_handle(
                                 citation.get_reference_handle())
         LOG.debug("   compare source %s == %s", source.get_gramps_id(),
                   poss_source.get_gramps_id())
         if poss_source.get_handle() == source.get_handle():
             # The source is already cited
             LOG.debug("   source already cited")
             return
     # we couldn't find an appropriate citation, so we have to create one.
     citation = Citation()
     LOG.debug("   creating citation")
     citation.set_reference_handle(source.get_handle())
     self.db.add_citation(citation, self.trans)
     LOG.debug("   created citation, citation %s %s" %
               (citation, citation.get_gramps_id()))
     obj.add_citation(citation.get_handle())
开发者ID:tecknicaltom,项目名称:gramps,代码行数:24,代码来源:importcsv.py

示例11: __init__

    def __init__(self, dbstate, uistate, track, event):

        self.dbstate = dbstate
        self.uistate = uistate
        self.track = track
        self.db = dbstate.db
        
        self.event = event
        self.citation = get_census_citation(self.db, self.event)
        if self.citation is None:
            self.citation = Citation()

        ManagedWindow.__init__(self, uistate, track, event)

        self.widgets = {}
        top = self.__create_gui()
        self.set_window(top, None, self.get_menu_title())

        self._config = config.get_manager('census')
        width = self._config.get('interface.census-width')
        height = self._config.get('interface.census-height')
        self.window.resize(width, height)

        self.place_field = PlaceEntry(self.dbstate, self.uistate, self.track,
                                      self.widgets['place_text'],
                                      self.event.set_place_handle,
                                      self.event.get_place_handle,
                                      self.widgets['place_add'],
                                      self.widgets['place_share'])

        self.ref_field = MonitoredEntry(
            self.widgets['ref_entry'], 
            self.citation.set_page, 
            self.citation.get_page, 
            self.db.readonly)

        if self.event.get_handle():
            self.widgets['census_combo'].set_sensitive(False)
            self.__populate_gui(event)
            self.details.populate_gui(event)
开发者ID:SNoiraud,项目名称:addons-source,代码行数:40,代码来源:CensusGramplet.py

示例12: on_res_ok_clicked

 def on_res_ok_clicked(self, dummy):
     """ Accept changes displayed and commit to place.
     Also find or create a new enclosing place from parent. """
     # do the names
     namelist = []
     for row in self.alt_store:
         if row[0] == 'P':
             self.place.name = self.newplace.names[row[4]]
         elif row[0] == '\u2714':
             namelist.append(self.newplace.names[row[4]])
     self.place.alt_names = namelist
     # Lat/lon/ID/code/type
     self.place.lat = self.top.get_object('latitude').get_text()
     self.place.long = self.top.get_object('longitude').get_text()
     self.place.gramps_id = self.top.get_object('grampsid').get_text()
     self.place.code = self.top.get_object('postal').get_text()
     self.place.place_type.set(self.type_combo.get_values())
     # Add in URLs if wanted
     if self.keepweb:
         for url in self.newplace.links:
             self.place.add_url(url)
     # Enclose in the next level place
     next_place = False
     parent = None
     if not self.keep_enclosure or not self.place.placeref_list:
         if self.newplace.parent_ids:
             # we might have a parent with geo id 'GEO12345'
             parent = self.dbstate.db.get_place_from_gramps_id(
                 self.newplace.parent_ids[0])
         if not parent and self.newplace.parent_names:
             # make one, will have to be examined/cleaned later
             parent = Place()
             parent.title = ', '.join(self.newplace.parent_names)
             name = PlaceName()
             name.value = parent.title
             parent.name = name
             parent.gramps_id = self.newplace.parent_ids[0]
             with DbTxn(_("Add Place (%s)") % parent.title,
                        self.dbstate.db) as trans:
                 self.dbstate.db.add_place(parent, trans)
                 next_place = True
         if parent:
             if located_in(self.dbstate.db, parent.handle,
                           self.place.handle):
                 # attempting to create a place loop, not good!
                 ErrorDialog(_('Place cycle detected'),
                             msg2=_("The place you chose is enclosed in the"
                                    " place you are workin on!\n"
                                    "Please cancel and choose another "
                                    "place."),
                             parent=self.uistate.window)
                 return
             # check to see if we already have the enclosing place
             already_there = False
             for pref in self.place.placeref_list:
                 if parent.handle == pref.ref:
                     already_there = True
                     break
             if not already_there:
                 placeref = PlaceRef()
                 placeref.set_reference_handle(parent.handle)
                 self.place.set_placeref_list([placeref])
     # Add in Citation/Source if wanted
     if self.addcitation and self.newplace.geoid:
         src_hndl = self.find_or_make_source()
         cit = Citation()
         cit.set_reference_handle(src_hndl)
         cit.set_page("GeoNames ID: %s" %
                      self.newplace.geoid.replace('GEO', ''))
         with DbTxn(_("Add Citation (%s)") % "GeoNames",
                    self.dbstate.db) as trans:
             self.dbstate.db.add_citation(cit, trans)
         self.place.add_citation(cit.handle)
     # We're finally ready to commit the updated place
     with DbTxn(_("Edit Place (%s)") % self.place.title,
                self.dbstate.db) as trans:
         self.dbstate.db.commit_place(self.place, trans)
     # Jump to enclosing place to clean it if necessary
     if next_place:
         self.set_active('Place', parent.handle)
         self.place = parent
         # if geoparse fails, leave us at main view
         if self.newplace.parent_ids and \
             self.geoparse(self.newplace.parent_ids[0],
                           _(", ").join(self.newplace.parent_names),
                           self.newplace.parent_ids,
                           self.newplace.parent_names):
             # geoparse worked, lets put up the results view
             self.gui.get_child().remove(self.mainwin)
             self.gui.get_child().add(self.results_win)
             self.res_gui()
             return
     self.reset_main()
     if self.gui.get_child().get_child() == self.results_win:
         self.gui.get_child().remove(self.results_win)
         self.gui.get_child().add(self.mainwin)
开发者ID:daleathan,项目名称:addons-source,代码行数:96,代码来源:placecleanup.py

示例13: exportData

def exportData(database, filename,
               error_dialog=None, option_box=None, callback=None):
    if not callable(callback):
        callback = lambda percent: None # dummy

    with OpenFileOrStdout(filename, encoding="utf-8") as fp:

        total = (len(database.note_map) +
                 len(database.person_map) +
                 len(database.event_map) +
                 len(database.family_map) +
                 len(database.repository_map) +
                 len(database.place_map) +
                 len(database.media_map) +
                 len(database.citation_map) +
                 len(database.source_map) +
                 len(database.tag_map))
        count = 0.0

        # ---------------------------------
        # Notes
        # ---------------------------------
        for handle in database.note_map.keys():
            serial = database.note_map[handle]
            write_line(fp, Note.create(serial))
            count += 1
            callback(100 * count/total)

        # ---------------------------------
        # Event
        # ---------------------------------
        for handle in database.event_map.keys():
            serial = database.event_map[handle]
            write_line(fp, Event.create(serial))
            count += 1
            callback(100 * count/total)

        # ---------------------------------
        # Person
        # ---------------------------------
        for handle in database.person_map.keys():
            serial = database.person_map[handle]
            write_line(fp, Person.create(serial))
            count += 1
            callback(100 * count/total)

        # ---------------------------------
        # Family
        # ---------------------------------
        for handle in database.family_map.keys():
            serial = database.family_map[handle]
            write_line(fp, Family.create(serial))
            count += 1
            callback(100 * count/total)

        # ---------------------------------
        # Repository
        # ---------------------------------
        for handle in database.repository_map.keys():
            serial = database.repository_map[handle]
            write_line(fp, Repository.create(serial))
            count += 1
            callback(100 * count/total)

        # ---------------------------------
        # Place
        # ---------------------------------
        for handle in database.place_map.keys():
            serial = database.place_map[handle]
            write_line(fp, Place.create(serial))
            count += 1
            callback(100 * count/total)

        # ---------------------------------
        # Source
        # ---------------------------------
        for handle in database.source_map.keys():
            serial = database.source_map[handle]
            write_line(fp, Source.create(serial))
            count += 1
            callback(100 * count/total)

        # ---------------------------------
        # Citation
        # ---------------------------------
        for handle in database.citation_map.keys():
            serial = database.citation_map[handle]
            write_line(fp, Citation.create(serial))
            count += 1
            callback(100 * count/total)

        # ---------------------------------
        # Media
        # ---------------------------------
        for handle in database.media_map.keys():
            serial = database.media_map[handle]
            write_line(fp, Media.create(serial))
            count += 1
            callback(100 * count/total)

#.........这里部分代码省略.........
开发者ID:belissent,项目名称:addons-source,代码行数:101,代码来源:JSONExport.py

示例14: CensusEditor

class CensusEditor(ManagedWindow):
    """
    Census Editor.
    """
    def __init__(self, dbstate, uistate, track, event):

        self.dbstate = dbstate
        self.uistate = uistate
        self.track = track
        self.db = dbstate.db
        
        self.event = event
        self.citation = get_census_citation(self.db, self.event)
        if self.citation is None:
            self.citation = Citation()

        ManagedWindow.__init__(self, uistate, track, event)

        self.widgets = {}
        top = self.__create_gui()
        self.set_window(top, None, self.get_menu_title())

        self._config = config.get_manager('census')
        width = self._config.get('interface.census-width')
        height = self._config.get('interface.census-height')
        self.window.resize(width, height)

        self.place_field = PlaceEntry(self.dbstate, self.uistate, self.track,
                                      self.widgets['place_text'],
                                      self.event.set_place_handle,
                                      self.event.get_place_handle,
                                      self.widgets['place_add'],
                                      self.widgets['place_share'])

        self.ref_field = MonitoredEntry(
            self.widgets['ref_entry'], 
            self.citation.set_page, 
            self.citation.get_page, 
            self.db.readonly)

        if self.event.get_handle():
            self.widgets['census_combo'].set_sensitive(False)
            self.__populate_gui(event)
            self.details.populate_gui(event)

    def _add_tab(self, notebook, page):
        notebook.append_page(page, page.get_tab_widget())
        page.label.set_use_underline(True)
        return page

    def get_menu_title(self):
        """
        Get the menu title.
        """
        if self.event.get_handle():
            date = get_date(self.event)
            if not date:
                date = 'unknown'
            dialog_title = _('Census: %s')  % date
        else:
            dialog_title = _('New Census')
        return dialog_title

    def build_menu_names(self, event):
        """
        Build menu names. Overrides method in ManagedWindow.
        """
        return (_('Edit Census'), self.get_menu_title())

    def __create_gui(self):
        """
        Create and display the GUI components of the editor.
        """
        root = Gtk.Window(type=Gtk.WindowType.TOPLEVEL)
        root.set_transient_for(self.uistate.window)

        vbox = Gtk.VBox()

        tab = Gtk.Table(4, 4, False)
        tab.set_row_spacings(10)
        tab.set_col_spacings(10)

        census_label = Gtk.Label(_("Source:"))
        census_label.set_alignment(0.0, 0.5)
        tab.attach(census_label, 0, 1, 0, 1,
                   xoptions=Gtk.AttachOptions.FILL, xpadding=10)
        
        liststore = Gtk.ListStore(str, str, str)
        for row in get_census_sources(self.db):
            liststore.append([row[0].decode(), row[1], row[2]])

        census_combo = Gtk.ComboBox()
        census_combo.set_model(liststore)
        cell = Gtk.CellRendererText()
        census_combo.pack_start(cell, True)
        census_combo.add_attribute(cell, 'text', 1)
        #cell = Gtk.CellRendererText()
        #census_combo.pack_start(cell, True)
        #census_combo.add_attribute(cell, 'text', 2)
        census_combo.connect('changed', self.__census_changed)
#.........这里部分代码省略.........
开发者ID:SNoiraud,项目名称:addons-source,代码行数:101,代码来源:CensusGramplet.py


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