コード例 #1
0
 def add_reference(self, person, rect):
     """
     Add a reference to the media object to the specified person.
     """
     mediaref = MediaRef()
     mediaref.ref = self.get_current_handle()
     mediaref.set_rectangle(rect)
     person.add_media_reference(mediaref)
     self.commit_person(person)
     return mediaref
コード例 #2
0
 def add_reference(self, person, rect):
     """
     Add a reference to the media object to the specified person.
     """
     mediaref = MediaRef()
     mediaref.ref = self.get_current_handle()
     mediaref.set_rectangle(rect)
     person.add_media_reference(mediaref)
     self.commit_person(person)
     return mediaref
コード例 #3
0
 def add_button_clicked(self, obj):
     try:
         from .. import EditMediaRef
         EditMediaRef(self.dbstate, self.uistate, self.track, MediaObject(),
                      MediaRef(), self.add_callback)
     except WindowActiveError:
         pass
コード例 #4
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 = MediaRef()
            try:
                from .. import EditMediaRef
                EditMediaRef(self.dbstate, self.uistate, self.track, src, sref,
                             self.add_callback)
            except WindowActiveError:
                from ...dialog import WarningDialog
                WarningDialog(_("Cannot share this reference"),
                              self.__blocked_text())
コード例 #5
0
ファイル: gallerytab.py プロジェクト: gogglesguy/gramps
    def drag_data_received(self, widget, context, x, y, sel_data, info, time):
        """
        Handle the standard gtk interface for drag_data_received.

        If the selection data is define, extract the value from sel_data.data,
        and decide if this is a move or a reorder.
        """
        if sel_data and sel_data.get_data():
            try:
                (mytype, selfid, obj, row_from) = pickle.loads(sel_data.get_data())

                # make sure this is the correct DND type for this object
                if mytype == self._DND_TYPE.drag_type:
                    
                    # determine the destination row
                    data = self.iconlist.get_dest_item_at_pos(x, y)
                    if data:
                        (path, pos) = data
                        row = path.get_indices()[0]
                        if pos ==  Gtk.IconViewDropPosition.DROP_LEFT:
                            row = max(row, 0)
                        elif pos == Gtk.IconViewDropPosition.DROP_RIGHT:
                            row = min(row, len(self.get_data()))
                        elif pos == Gtk.IconViewDropPosition.DROP_INTO:
                            row = min(row+1, len(self.get_data()))
                    else:
                        row = len(self.get_data())
                    
                    # if the is same object, we have a move, otherwise,
                    # it is a standard drag-n-drop
                    
                    if id(self) == selfid:
                        self._move(row_from, row, obj)
                    else:
                        self._handle_drag(row, obj)
                    self.rebuild()
                elif mytype == DdTargets.MEDIAOBJ.drag_type:
                    oref = MediaRef()
                    oref.set_reference_handle(obj)
                    self.get_data().append(oref)
                    self.changed = True
                    self.rebuild()
                elif self._DND_EXTRA and mytype == self._DND_EXTRA.drag_type:
                    self.handle_extra_type(mytype, obj)
            except pickle.UnpicklingError:
                files =  sel_data.get_uris()
                for file in files:
                    protocol, site, mfile, j, k, l = urlparse(file)
                    if protocol == "file":
                        name = url2pathname(mfile)
                        mime = get_type(name)
                        if not is_valid_type(mime):
                            return
                        photo = MediaObject()
                        self.uistate.set_busy_cursor(True)
                        photo.set_checksum(create_checksum(name))
                        self.uistate.set_busy_cursor(False)
                        base_dir = str(media_path(self.dbstate.db))
                        if os.path.exists(base_dir):
                            name = relative_path(name, base_dir)
                        photo.set_path(name)
                        photo.set_mime_type(mime)
                        basename = os.path.basename(name)
                        (root, ext) = os.path.splitext(basename)
                        photo.set_description(root)
                        with DbTxn(_("Drag Media Object"),
                                   self.dbstate.db) as trans:
                            self.dbstate.db.add_object(photo, trans)
                            oref = MediaRef()
                            oref.set_reference_handle(photo.get_handle())
                            self.get_data().append(oref)
                            self.changed = True
                    self.rebuild()
コード例 #6
0
    def drag_data_received(self, widget, context, x, y, sel_data, info, time):
        """
        Handle the standard gtk interface for drag_data_received.

        If the selection data is define, extract the value from sel_data.data,
        and decide if this is a move or a reorder.
        """
        if sel_data and sel_data.get_data():
            try:
                (mytype, selfid, obj,
                 row_from) = pickle.loads(sel_data.get_data())

                # make sure this is the correct DND type for this object
                if mytype == self._DND_TYPE.drag_type:

                    # determine the destination row
                    data = self.iconlist.get_dest_item_at_pos(x, y)
                    if data:
                        (path, pos) = data
                        row = path.get_indices()[0]
                        if pos == Gtk.IconViewDropPosition.DROP_LEFT:
                            row = max(row, 0)
                        elif pos == Gtk.IconViewDropPosition.DROP_RIGHT:
                            row = min(row, len(self.get_data()))
                        elif pos == Gtk.IconViewDropPosition.DROP_INTO:
                            row = min(row + 1, len(self.get_data()))
                    else:
                        row = len(self.get_data())

                    # if the is same object, we have a move, otherwise,
                    # it is a standard drag-n-drop

                    if id(self) == selfid:
                        self._move(row_from, row, obj)
                    else:
                        self._handle_drag(row, obj)
                    self.rebuild()
                elif mytype == DdTargets.MEDIAOBJ.drag_type:
                    oref = MediaRef()
                    oref.set_reference_handle(obj)
                    self.get_data().append(oref)
                    self.changed = True
                    self.rebuild()
                elif self._DND_EXTRA and mytype == self._DND_EXTRA.drag_type:
                    self.handle_extra_type(mytype, obj)
            except pickle.UnpicklingError:
                files = sel_data.get_uris()
                for file in files:
                    protocol, site, mfile, j, k, l = urlparse(file)
                    if protocol == "file":
                        name = url2pathname(mfile)
                        mime = get_type(name)
                        if not is_valid_type(mime):
                            return
                        photo = MediaObject()
                        self.uistate.set_busy_cursor(True)
                        photo.set_checksum(create_checksum(name))
                        self.uistate.set_busy_cursor(False)
                        base_dir = str(media_path(self.dbstate.db))
                        if os.path.exists(base_dir):
                            name = relative_path(name, base_dir)
                        photo.set_path(name)
                        photo.set_mime_type(mime)
                        basename = os.path.basename(name)
                        (root, ext) = os.path.splitext(basename)
                        photo.set_description(root)
                        with DbTxn(_("Drag Media Object"),
                                   self.dbstate.db) as trans:
                            self.dbstate.db.add_object(photo, trans)
                            oref = MediaRef()
                            oref.set_reference_handle(photo.get_handle())
                            self.get_data().append(oref)
                            self.changed = True
                    self.rebuild()
コード例 #7
0
    def __avatar_gen(self, media_handles, people, value):
        """
        Add the image(s) chosen in the menu options to the people.
        """
        counter = 0
        name_txt = _("Avatar Generator")

        if value == 0:  # Single image mode
            with DbTxn(name_txt, self.db, batch=True) as self.trans:
                self.db.disable_signals()
                num_people = len(people)
                self.progress.set_pass(_('Add avatar images...'), num_people)
                for person_handle in people:  # people = list of people handles
                    person = self.__db.get_person_from_handle(person_handle)
                    if person.get_media_list() == []:
                        mediaref = MediaRef()
                        mediaref.ref = media_handles[0]
                        person.add_media_reference(mediaref)
                        self.db.commit_person(person, self.trans)
                        counter += 1
                    self.progress.step()
            self.db.enable_signals()
            self.db.request_rebuild()

        elif value == 1:  # male/female/unknown
            with DbTxn(name_txt, self.db, batch=True) as self.trans:
                self.db.disable_signals()
                num_people = len(people[0]) + len(people[1]) + len(people[2])
                self.progress.set_pass(_('Add avatar images...'), num_people)
                # people = contains 3 lists here
                # each containing people handels of unknown, males or females
                for person_handle in people[0]:  # unknown people handles
                    person = self.__db.get_person_from_handle(person_handle)
                    if person.get_media_list() == []:
                        mediaref = MediaRef()
                        mediaref.ref = media_handles[0]
                        person.add_media_reference(mediaref)
                        self.db.commit_person(person, self.trans)
                        counter += 1
                    self.progress.step()
                for person_handle in people[1]:  # male people handles
                    person = self.__db.get_person_from_handle(person_handle)
                    if person.get_media_list() == []:
                        mediaref = MediaRef()
                        mediaref.ref = media_handles[1]
                        person.add_media_reference(mediaref)
                        self.db.commit_person(person, self.trans)
                        counter += 1
                    self.progress.step()
                for person_handle in people[2]:  # female people handles
                    person = self.__db.get_person_from_handle(person_handle)
                    if person.get_media_list() == []:
                        mediaref = MediaRef()
                        mediaref.ref = media_handles[2]
                        person.add_media_reference(mediaref)
                        self.db.commit_person(person, self.trans)
                        counter += 1
                    self.progress.step()
            self.db.enable_signals()
            self.db.request_rebuild()

        if counter > 0:
            info_text = _("{} avatar images were sucessfully added.")
            info_text2 = info_text.format(counter)
            OkDialog(_("INFO"), info_text2, parent=self.window)
        else:
            txt1 = _("There was no avatar image to add. ")
            txt2 = _("All persons already had one.")
            OkDialog(_("INFO"), (txt1 + txt2), parent=self.window)