Beispiel #1
0
 def _run(self):
     """
     Go through directories that are mentioned in the database via
     media files, and include all images that are not all ready
     included.
     """
     if not self.prepared:
         self.prepare()
     self.set_total(len(self.dir_list))
     for directory in self.dir_list:
         for (dirpath, dirnames, filenames) in os.walk(directory):
             if ".git" in dirnames:
                 dirnames.remove('.git')  # don't visit .git directories
             for filename in filenames:
                 media_full_path = os.path.join(dirpath, filename)
                 if media_full_path not in self.path_list:
                     self.path_list.append(media_full_path)
                     mime_type = get_type(media_full_path)
                     if is_image_type(mime_type):
                         obj = MediaObject()
                         obj.set_path(media_full_path)
                         obj.set_mime_type(mime_type)
                         (root, ext) = os.path.splitext(filename)
                         obj.set_description(root)
                         self.db.add_object(obj, self.trans)
         self.update()
     return True
Beispiel #2
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.
        The only data we accept on mediaview is dropping a file, so URI_LIST.
        We assume this is what we obtain
        """
        if not sel_data:
            return
        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)
        widget.emit_stop_by_name('drag_data_received')
Beispiel #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
Beispiel #4
0
 def sort_date(self, data):
     obj = MediaObject()
     obj.unserialize(data)
     d = obj.get_date_object()
     if d:
         return "%09d" % d.get_sort_value()
     else:
         return ''
Beispiel #5
0
 def _prepare(self):
     self.set_total(self.db.get_number_of_media_objects())
     with self.db.get_media_cursor() as cursor:
         for handle, data in cursor:
             obj = MediaObject()
             obj.unserialize(data)
             if os.path.isabs(obj.path):
                 self.handle_list.append(handle)
                 self.path_list.append(obj.path)
             self.update()
     self.reset()
Beispiel #6
0
 def call_editor(self, obj=None):
     if obj is None:
         object = MediaObject()
         func = self.obj_added
     else:
         object = obj
         func = self.after_edit
     try:
         EditMedia(self.dbstate, self.uistate, self.track, object, func)
     except WindowActiveError:
         pass
Beispiel #7
0
 def _prepare(self):
     from_text = str(self.from_entry.get_text())
     self.set_total(self.db.get_number_of_media_objects())
     with self.db.get_media_cursor() as cursor:
         for handle, data in cursor:
             obj = MediaObject()
             obj.unserialize(data)
             if obj.get_path().find(from_text) != -1:
                 self.handle_list.append(handle)
                 self.path_list.append(obj.path)
             self.update()
     self.reset()
     self.prepared = True
Beispiel #8
0
 def _prepare(self):
     """
     Get all of the fullpaths, and the directories of media
     objects in the database.
     """
     self.dir_list = set()
     self.set_total(self.db.get_number_of_media_objects())
     with self.db.get_media_cursor() as cursor:
         for handle, data in cursor:
             obj = MediaObject()
             obj.unserialize(data)
             self.handle_list.append(handle)
             full_path = media_path_full(self.db, obj.path)
             self.path_list.append(full_path)
             directory, filename = os.path.split(full_path)
             if directory not in self.dir_list:
                 self.dir_list.add(directory)
             self.update()
     self.reset()
Beispiel #9
0
 def empty_object(self):
     return MediaObject()
Beispiel #10
0
 def add(self, obj):
     """Add a new media object to the media list"""
     try:
         EditMedia(self.dbstate, self.uistate, [], MediaObject())
     except WindowActiveError:
         pass
Beispiel #11
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()