Esempio n. 1
0
    def on_name_changed(self, *obj):
        """
        Called anytime the filename text window changes. Checks to
        see if the file exists. If it does, the image is loaded into
        the preview window.
        """
        fname = self.file_text.get_filename()
        if not fname:
            return
        filename = fname
        basename = os.path.basename(filename)
        (root, ext) = os.path.splitext(basename)
        old_title = self.description.get_text()

        if old_title == "" or old_title == self.temp_name:
            self.description.set_text(root)
        self.temp_name = root

        filename = find_file(filename)
        if filename:
            mtype = get_type(filename)
            if mtype and mtype.startswith("image"):
                image = scale_image(filename, THUMBSCALE)
            else:
                image = find_mime_type_pixbuf(mtype)
            self.image.set_from_pixbuf(image)
Esempio n. 2
0
    def on_name_changed(self, *obj):
        """
        Called anytime the filename text window changes. Checks to
        see if the file exists. If it does, the image is loaded into
        the preview window.
        """
        fname = self.file_text.get_filename()
        if not fname:
            return
        filename = conv_to_unicode(fname)
        basename = os.path.basename(filename)
        (root, ext) = os.path.splitext(basename)
        old_title = str(self.description.get_text())

        if old_title == '' or old_title == self.temp_name:
            self.description.set_text(root)
        self.temp_name = root

        filename = find_file(filename)
        if filename:
            mtype = get_type(filename)
            if mtype and mtype.startswith("image"):
                image = scale_image(filename, THUMBSCALE)
            else:
                image = find_mime_type_pixbuf(mtype)
            self.image.set_from_pixbuf(image)
Esempio n. 3
0
    def determine_mime(self):
        descr = get_description(self.obj.get_mime_type())
        if descr:
            self.mimetext.set_text(descr)

        path = self.file_path.get_text()
        path_full = media_path_full(self.db, path)
        if path != self.obj.get_path() and path_full != self.obj.get_path():
            #redetermine mime
            mime = get_type(find_file(path_full))
            self.obj.set_mime_type(mime)
            descr = get_description(mime)
            if descr:
                self.mimetext.set_text(descr)
            else:
                self.mimetext.set_text(_('Unknown'))
        #if mime type not set, is note
        if not self.obj.get_mime_type():
            self.mimetext.set_text(_('Note'))
Esempio n. 4
0
    def determine_mime(self):
        descr = get_description(self.obj.get_mime_type())
        if descr:
            self.mimetext.set_text(descr)

        path = self.file_path.get_text()
        path_full = media_path_full(self.db, path)
        if path != self.obj.get_path() and path_full != self.obj.get_path():
            # redetermine mime
            mime = get_type(find_file(path_full))
            self.obj.set_mime_type(mime)
            descr = get_description(mime)
            if descr:
                self.mimetext.set_text(descr)
            else:
                self.mimetext.set_text(_("Unknown"))
        # if mime type not set, is note
        if not self.obj.get_mime_type():
            self.mimetext.set_text(_("Note"))
Esempio n. 5
0
    def on_name_changed(self, *obj):
        """
        Called anytime the filename text window changes. Checks to
        see if the file exists. If it does, the image is loaded into
        the preview window.
        """
        fname = self.file_text.get_filename()
        if not fname:
            return
        filename = fname
        basename = os.path.basename(filename)
        (root, ext) = os.path.splitext(basename)
        old_title = self.description.get_text()

        if old_title == '' or old_title == self.temp_name:
            self.description.set_text(root)
        self.temp_name = root

        filename = find_file(filename)
        if filename:
            mtype = get_type(filename)
            image = get_thumbnail_image(filename, mtype)
            self.image.set_from_pixbuf(image)
Esempio n. 6
0
    def get_person_label(self, person):
        "return person label string"
        # see if we have an image to use for this person
        image_path = None
        if self.use_html_output:
            media_list = person.get_media_list()
            if len(media_list) > 0:
                media_handle = media_list[0].get_reference_handle()
                media = self._db.get_media_from_handle(media_handle)
                media_mime_type = media.get_mime_type()
                if media_mime_type[0:5] == "image":
                    image_path = get_thumbnail_path(
                        media_path_full(self._db, media.get_path()),
                        rectangle=media_list[0].get_rectangle())
                    # test if thumbnail actually exists in thumbs
                    # (import of data means media files might not be present
                    image_path = find_file(image_path)

        label = ""
        line_delimiter = '\\n'

        # If we have an image, then start an HTML table; remember to close
        # the table afterwards!
        #
        # This isn't a free-form HTML format here...just a few keywords that
        # happen to be
        # similar to keywords commonly seen in HTML.  For additional
        # information on what
        # is allowed, see:
        #
        #       http://www.graphviz.org/info/shapes.html#html
        #
        if self.use_html_output and image_path:
            line_delimiter = '<BR/>'
            label += '<TABLE BORDER="0" CELLSPACING="2" CELLPADDING="0" '
            label += 'CELLBORDER="0"><TR><TD></TD><TD>'
            label += '<IMG SRC="%s"/></TD><TD></TD>' % image_path
            if self.imgpos == 0:
                #trick it into not stretching the image
                label += '</TR><TR><TD COLSPAN="3">'
            else:
                label += '<TD>'
        else:
            #no need for html label with this person
            self.use_html_output = False

        # at the very least, the label must have the person's name
        p_name = self._name_display.display(person)
        if self.use_html_output:
            # avoid < and > in the name, as this is html text
            label += p_name.replace('<', '&#60;').replace('>', '&#62;')
        else:
            label += p_name
        p_id = person.get_gramps_id()
        if self.includeid == 1:  # same line
            label += " (%s)" % p_id
        elif self.includeid == 2:  # own line
            label += "%s(%s)" % (line_delimiter, p_id)
        if self.event_choice != 0:
            b_date, d_date, b_place, d_place, b_type, d_type = \
                self.get_event_strings(person)
            if self.event_choice in [1, 2, 3, 4, 5] and (b_date or d_date):
                label += '%s(' % line_delimiter
                if b_date:
                    label += '%s' % b_date
                label += ' - '
                if d_date:
                    label += '%s' % d_date
                label += ')'
            if (self.event_choice in [2, 3, 5, 6] and (b_place or d_place)
                    and not (self.event_choice == 3 and (b_date or d_date))):
                label += '%s(' % line_delimiter
                if b_place:
                    label += '%s' % b_place
                label += ' - '
                if d_place:
                    label += '%s' % d_place
                label += ')'
        if self.event_choice == 7:
            if b_type:
                label += '%s%s' % (line_delimiter, b_type.get_abbreviation())
                if b_date:
                    label += ' %s' % b_date
                if b_place:
                    label += ' %s' % b_place

            if d_type:
                label += '%s%s' % (line_delimiter, d_type.get_abbreviation())
                if d_date:
                    label += ' %s' % d_date
                if d_place:
                    label += ' %s' % d_place

        if self.increlname and self.center_person != person:
            # display relationship info
            if self.advrelinfo:
                (relationship, _ga, _gb) = self.rel_calc.get_one_relationship(
                    self._db,
                    self.center_person,
                    person,
                    extra_info=True,
                    olocale=self._locale)
                if relationship:
                    label += "%s(%s Ga=%d Gb=%d)" % (line_delimiter,
                                                     relationship, _ga, _gb)
            else:
                relationship = self.rel_calc.get_one_relationship(
                    self._db, self.center_person, person, olocale=self._locale)
                if relationship:
                    label += "%s(%s)" % (line_delimiter, relationship)

        if self.occupation > 0:
            event_refs = person.get_primary_event_ref_list()
            events = [
                event for event in [
                    self._db.get_event_from_handle(ref.ref)
                    for ref in event_refs
                ] if event.get_type() == EventType(EventType.OCCUPATION)
            ]
            if len(events) > 0:
                events.sort(key=lambda x: x.get_date_object())
                if self.occupation == 1:
                    occupation = events[-1].get_description()
                    if occupation:
                        label += "%s(%s)" % (line_delimiter, occupation)
                elif self.occupation == 2:
                    for evt in events:
                        date = self.get_date_string(evt)
                        place = self.get_place_string(evt)
                        desc = evt.get_description()
                        if not date and not desc and not place:
                            continue
                        label += '%s(' % line_delimiter
                        if date:
                            label += '%s' % date
                            if desc:
                                label += ' '
                        if desc:
                            label += '%s' % desc
                        if place:
                            if date or desc:
                                label += ', '
                            label += '%s' % place
                        label += ')'

        # see if we have a table that needs to be terminated
        if self.use_html_output:
            label += '</TD></TR></TABLE>'
            return label
        else:
            # non html label is enclosed by "" so escape other "
            return label.replace('"', '\\\"')
Esempio n. 7
0
    def get_person_label(self, person):
        "return person label string"
        # see if we have an image to use for this person
        image_path = None
        if self.use_html_output:
            media_list = person.get_media_list()
            if len(media_list) > 0:
                media_handle = media_list[0].get_reference_handle()
                media = self._db.get_media_from_handle(media_handle)
                media_mime_type = media.get_mime_type()
                if media_mime_type[0:5] == "image":
                    image_path = get_thumbnail_path(
                        media_path_full(self._db, media.get_path()),
                        rectangle=media_list[0].get_rectangle())
                    # test if thumbnail actually exists in thumbs
                    # (import of data means media files might not be present
                    image_path = find_file(image_path)

        label = ""
        line_delimiter = '\\n'

        # If we have an image, then start an HTML table; remember to close
        # the table afterwards!
        #
        # This isn't a free-form HTML format here...just a few keywords that
        # happen to be
        # similar to keywords commonly seen in HTML.  For additional
        # information on what
        # is allowed, see:
        #
        #       http://www.graphviz.org/info/shapes.html#html
        #
        if self.use_html_output and image_path:
            line_delimiter = '<BR/>'
            label += '<TABLE BORDER="0" CELLSPACING="2" CELLPADDING="0" '
            label += 'CELLBORDER="0"><TR><TD></TD><TD>'
            label += '<IMG SRC="%s"/></TD><TD></TD>' % image_path
            if self.imgpos == 0:
                #trick it into not stretching the image
                label += '</TR><TR><TD COLSPAN="3">'
            else:
                label += '<TD>'
        else:
            #no need for html label with this person
            self.use_html_output = False

        # at the very least, the label must have the person's name
        p_name = self._name_display.display(person)
        if self.use_html_output:
            # avoid < and > in the name, as this is html text
            label += p_name.replace('<', '&#60;').replace('>', '&#62;')
        else:
            label += p_name
        p_id = person.get_gramps_id()
        if self.includeid == 1: # same line
            label += " (%s)" % p_id
        elif self.includeid == 2: # own line
            label += "%s(%s)" % (line_delimiter, p_id)
        if self.event_choice != 0:
            b_date, d_date, b_place, d_place, b_type, d_type = \
                self.get_event_strings(person)
            if self.event_choice in [1, 2, 3, 4, 5] and (b_date or d_date):
                label += '%s(' % line_delimiter
                if b_date:
                    label += '%s' % b_date
                label += ' - '
                if d_date:
                    label += '%s' % d_date
                label += ')'
            if (self.event_choice in [2, 3, 5, 6] and
                    (b_place or d_place) and
                    not (self.event_choice == 3 and (b_date or d_date))
               ):
                label += '%s(' % line_delimiter
                if b_place:
                    label += '%s' % b_place
                label += ' - '
                if d_place:
                    label += '%s' % d_place
                label += ')'
        if self.event_choice == 7:
            if b_type:
                label += '%s%s' % (line_delimiter, b_type.get_abbreviation())
                if b_date:
                    label += ' %s' % b_date
                if b_place:
                    label += ' %s' % b_place

            if d_type:
                label += '%s%s' % (line_delimiter, d_type.get_abbreviation())
                if d_date:
                    label += ' %s' % d_date
                if d_place:
                    label += ' %s' % d_place

        if self.increlname and self.center_person != person:
            # display relationship info
            if self.advrelinfo:
                (relationship, _ga, _gb) = self.rel_calc.get_one_relationship(
                    self._db, self.center_person, person,
                    extra_info=True, olocale=self._locale)
                if relationship:
                    label += "%s(%s Ga=%d Gb=%d)" % (line_delimiter,
                                                     relationship, _ga, _gb)
            else:
                relationship = self.rel_calc.get_one_relationship(
                    self._db, self.center_person, person,
                    olocale=self._locale)
                if relationship:
                    label += "%s(%s)" % (line_delimiter, relationship)

        if self.occupation > 0:
            event_refs = person.get_primary_event_ref_list()
            events = [event for event in
                      [self._db.get_event_from_handle(ref.ref)
                       for ref in event_refs]
                      if event.get_type() == EventType(EventType.OCCUPATION)]
            if len(events) > 0:
                events.sort(key=lambda x: x.get_date_object())
                if self.occupation == 1:
                    occupation = events[-1].get_description()
                    if occupation:
                        label += "%s(%s)" % (line_delimiter, occupation)
                elif self.occupation == 2:
                    for evt in events:
                        date = self.get_date_string(evt)
                        place = self.get_place_string(evt)
                        desc = evt.get_description()
                        if not date and not desc and not place:
                            continue
                        label += '%s(' % line_delimiter
                        if date:
                            label += '%s' % date
                            if desc:
                                label += ' '
                        if desc:
                            label += '%s' % desc
                        if place:
                            if date or desc:
                                label += self._(', ') # Arabic OK
                            label += '%s' % place
                        label += ')'

        # see if we have a table that needs to be terminated
        if self.use_html_output:
            label += '</TD></TR></TABLE>'
            return label
        else:
            # non html label is enclosed by "" so escape other "
            return label.replace('"', '\\\"')
Esempio n. 8
0
    def get_person_label(self, person):
        "return person label string"
        # see if we have an image to use for this person
        imagePath = None
        if self.bUseHtmlOutput:
            mediaList = person.get_media_list()
            if len(mediaList) > 0:
                mediaHandle = mediaList[0].get_reference_handle()
                media = self.database.get_object_from_handle(mediaHandle)
                mediaMimeType = media.get_mime_type()
                if mediaMimeType[0:5] == "image":
                    imagePath = get_thumbnail_path(
                        media_path_full(self.database, media.get_path()),
                        rectangle=mediaList[0].get_rectangle())
                    # test if thumbnail actually exists in thumbs
                    # (import of data means media files might not be present
                    imagePath = find_file(imagePath)

        label = ""
        lineDelimiter = '\\n'

        # If we have an image, then start an HTML table; remember to close
        # the table afterwards!
        #
        # This isn't a free-form HTML format here...just a few keywords that
        # happen to be
        # similar to keywords commonly seen in HTML.  For additional
        # information on what
        # is allowed, see:
        #
        #       http://www.graphviz.org/info/shapes.html#html
        #
        if self.bUseHtmlOutput and imagePath:
            lineDelimiter = '<BR/>'
            label += '<TABLE BORDER="0" CELLSPACING="2" CELLPADDING="0" CELLBORDER="0"><TR><TD></TD><TD><IMG SRC="%s"/></TD><TD></TD>' % imagePath
            if self.imgpos == 0:
                #trick it into not stretching the image
                label += '</TR><TR><TD COLSPAN="3">'
            else:
                label += '<TD>'
        else:
            #no need for html label with this person
            self.bUseHtmlOutput = False

        # at the very least, the label must have the person's name
        nm = self._name_display.display(person)
        if self.bUseHtmlOutput:
            # avoid < and > in the name, as this is html text
            label += nm.replace('<', '&#60;').replace('>', '&#62;')
        else:
            label += nm
        p_id = person.get_gramps_id()
        if self.includeid == 1:  # same line
            label += " (%s)" % p_id
        elif self.includeid == 2:  # own line
            label += "%s(%s)" % (lineDelimiter, p_id)
        if self.event_choice != 0:
            b_date, d_date, b_place, d_place = self.get_event_strings(person)
            if self.event_choice in [1, 2, 3, 4, 5] and (b_date or d_date):
                label += '%s(' % lineDelimiter
                if b_date:
                    label += '%s' % b_date
                label += ' - '
                if d_date:
                    label += '%s' % d_date
                label += ')'
            if (self.event_choice in [2, 3, 5, 6] and (b_place or d_place)
                    and not (self.event_choice == 3 and (b_date or d_date))):
                label += '%s(' % lineDelimiter
                if b_place:
                    label += '%s' % b_place
                label += ' - '
                if d_place:
                    label += '%s' % d_place
                label += ')'

        if self.increlname and self.center_person != person:
            # display relationship info
            if self.advrelinfo:
                (relationship, Ga,
                 Gb) = self.rel_calc.get_one_relationship(self.database,
                                                          self.center_person,
                                                          person,
                                                          extra_info=True,
                                                          olocale=self._locale)
                if relationship:
                    label += "%s(%s Ga=%d Gb=%d)" % (lineDelimiter,
                                                     relationship, Ga, Gb)
            else:
                relationship = self.rel_calc.get_one_relationship(
                    self.database,
                    self.center_person,
                    person,
                    olocale=self._locale)
                if relationship:
                    label += "%s(%s)" % (lineDelimiter, relationship)

        # see if we have a table that needs to be terminated
        if self.bUseHtmlOutput:
            label += '</TD></TR></TABLE>'
            return label
        else:
            # non html label is enclosed by "" so escape other "
            return label.replace('"', '\\\"')
Esempio n. 9
0
    def get_person_label(self, person):
        "return person label string"
        # see if we have an image to use for this person
        imagePath = None
        if self.bUseHtmlOutput:
            mediaList = person.get_media_list()
            if len(mediaList) > 0:
                mediaHandle = mediaList[0].get_reference_handle()
                media = self.database.get_object_from_handle(mediaHandle)
                mediaMimeType = media.get_mime_type()
                if mediaMimeType[0:5] == "image":
                    imagePath = get_thumbnail_path(
                                    media_path_full(self.database, 
                                                    media.get_path()),
                                    rectangle=mediaList[0].get_rectangle())
                    # test if thumbnail actually exists in thumbs
                    # (import of data means media files might not be present
                    imagePath = find_file(imagePath)

        label = ""
        lineDelimiter = '\\n'

        # If we have an image, then start an HTML table; remember to close
        # the table afterwards!
        #
        # This isn't a free-form HTML format here...just a few keywords that
        # happen to be
        # similar to keywords commonly seen in HTML.  For additional
        # information on what
        # is allowed, see:
        #
        #       http://www.graphviz.org/info/shapes.html#html
        #
        if self.bUseHtmlOutput and imagePath:
            lineDelimiter = '<BR/>'
            label += '<TABLE BORDER="0" CELLSPACING="2" CELLPADDING="0" CELLBORDER="0"><TR><TD></TD><TD><IMG SRC="%s"/></TD><TD></TD>'  % imagePath
            if self.imgpos == 0:
                #trick it into not stretching the image
                label += '</TR><TR><TD COLSPAN="3">'
            else :
                label += '<TD>'
        else :
            #no need for html label with this person
            self.bUseHtmlOutput = False

        # at the very least, the label must have the person's name
        nm = self._name_display.display(person)
        if self.bUseHtmlOutput :
            # avoid < and > in the name, as this is html text
            label += nm.replace('<', '&#60;').replace('>', '&#62;')
        else :
            label += nm
        p_id = person.get_gramps_id()
        if self.includeid == 1: # same line
            label += " (%s)" % p_id
        elif self.includeid == 2: # own line
            label += "%s(%s)" % (lineDelimiter, p_id)
        if self.event_choice != 0:
            b_date, d_date, b_place, d_place = self.get_event_strings(person)
            if self.event_choice in [1, 2, 3, 4, 5] and (b_date or d_date):
                label += '%s(' % lineDelimiter
                if b_date:
                    label += '%s' % b_date
                label += ' - '
                if d_date:
                    label += '%s' % d_date
                label += ')'
            if (self.event_choice in [2, 3, 5, 6] and
                (b_place or d_place) and
                not (self.event_choice == 3 and (b_date or d_date))
               ):
                label += '%s(' % lineDelimiter
                if b_place:
                    label += '%s' % b_place
                label += ' - '
                if d_place:
                    label += '%s' % d_place
                label += ')'

        if self.increlname and self.center_person != person:
            # display relationship info
            if self.advrelinfo:
                (relationship, Ga, Gb) = self.rel_calc.get_one_relationship(
                            self.database, self.center_person, person,
                            extra_info=True, olocale=self._locale)
                if relationship:
                    label += "%s(%s Ga=%d Gb=%d)" % (lineDelimiter,
                                                     relationship, Ga, Gb)
            else:
                relationship = self.rel_calc.get_one_relationship(
                            self.database, self.center_person, person,
                            olocale=self._locale)
                if relationship:
                    label += "%s(%s)" % (lineDelimiter, relationship)

        # see if we have a table that needs to be terminated
        if self.bUseHtmlOutput:
            label += '</TD></TR></TABLE>'
            return label
        else :
            # non html label is enclosed by "" so escape other "
            return label.replace('"', '\\\"')