Esempio n. 1
0
    def textview_drag_received(self, widget, context, x, y, selection, targetType, time):
        if targetType == config.data.target_type['timestamp']:
            data=decode_drop_parameters(selection.get_data().decode('utf-8'))
            position=int(data['timestamp'])
            #(x, y) = self.textview.get_window()_to_buffer_coords(Gtk.TextWindowType.TEXT,
            #                                               int(x),
            #                                               int(y))
            it=self.textview.get_iter_at_location(x, y)
            if it is None:
                return False
            # Check that preceding mark.value is lower
            m, i=self.find_preceding_mark(it.iter)
            if m is not None and m.value > position:
                self.message(_("Invalid timestamp mark"))
                return False
            m, i=self.find_following_mark(it.iter)
            if m is not None and m.value < position:
                self.message(_("Invalid timestamp mark"))
                return False
            # Create the timestamp
            self.create_timestamp_mark(position, it.iter)

            # If the drag originated from our own widgets, remove it.
            source=Gtk.drag_get_source_widget(context)
            if source in self.marks:
                self.remove_timestamp_mark(source)
            return True
        return False
Esempio n. 2
0
 def __onDragMotion(self, arrow, context, x, y, timestamp):
     if not self.hovered and self.__containsPoint(x, y):
         self.hovered = True
         self.emit("hovered", Gtk.drag_get_source_widget(context))
     elif self.hovered and not self.__containsPoint(x, y):
         self.hovered = False
         self.emit("left")
Esempio n. 3
0
        def drag_received_cb(widget, context, x, y, selection, targetType,
                             time):
            """Handle the drop of an annotation type.
            """
            if Gtk.drag_get_source_widget(context).is_ancestor(self.widget):
                # Ignore drops from our own widget
                return False

            if targetType == config.data.target_type['annotation']:
                sources = [
                    self.controller.package.annotations.get(uri)
                    for uri in str(selection.get_data(), 'utf8').split('\n')
                ]
                if sources:
                    self.set_elements(sources)
                return True
            elif targetType == config.data.target_type['annotation-type']:
                sources = [
                    self.controller.package.annotationTypes.get(uri)
                    for uri in str(selection.get_data(), 'utf8').split('\n')
                ]
                if sources:
                    self.set_elements(sources[0].annotations)
                return True
            return False
Esempio n. 4
0
    def __drag_data_get(self, view, ctx, sel, tid, etime):
        model, paths = self.get_selection().get_selected_rows()
        if tid == DND_QL:
            songs = [
                model[path][0] for path in paths if model[path][0].can_add
            ]
            if len(songs) != len(paths):
                qltk.ErrorMessage(
                    qltk.get_top_parent(self), _("Unable to copy songs"),
                    _("The files selected cannot be copied to other "
                      "song lists or the queue.")).run()
                Gdk.drag_abort(ctx, etime)
                return

            qltk.selection_set_songs(sel, songs)

            # DEM 2018/05/25: The below check is a deliberate repitition of
            # code in the drag-motion signal handler.  In MacOS/Quartz, the
            # context action is not propogated between event handlers for
            # drag-motion and drag-data-get using "ctx.get_actions()".  It is
            # unclear if this is a bug or expected behavior.  Regardless, the
            # context widget information is the same so identical behavior can
            # be achieved by simply using the same widget check as in the move
            # action.
            if Gtk.drag_get_source_widget(ctx) == self and \
                    not self.__force_copy:
                self.__drag_iters = list(map(model.get_iter, paths))
            else:
                self.__drag_iters = []
        else:
            uris = [model[path][0]("~uri") for path in paths]
            sel.set_uris(uris)
            self.__drag_iters = []
Esempio n. 5
0
    def drag_data_received_cb(self, widget, context, x, y, selection, info, t):
        if "application/x-color" not in map(str, context.list_targets()):
            return False
        data = selection.get_data()
        data_type = selection.get_data_type()
        fmt = selection.get_format()
        logger.debug("drag-data-received: got type=%r", data_type)
        logger.debug("drag-data-received: got fmt=%r", fmt)
        logger.debug("drag-data-received: got data=%r len=%r", data, len(data))
        color = RGBColor.new_from_drag_data(data)
        target_index = self.get_index_at_pos(x, y)

        mgr = self.get_color_manager()
        if Gtk.drag_get_source_widget(context) is self:
            # Move/copy
            current_index = mgr.palette.match_position
            logger.debug("Move/copy %r -> %r", current_index, target_index)
            assert current_index is not None
            mgr.palette.reposition(current_index, target_index)
        else:
            if target_index is None:
                # Append if the drop wasn't over a swatch
                target_index = len(mgr.palette)
            else:
                # Insert before populated swatches, or overwrite empties
                if mgr.palette.get_color(target_index) is None:
                    mgr.palette.pop(target_index)
            mgr.palette.insert(target_index, color)
        self.queue_draw()
        self._drag_insertion_index = None
        context.finish(True, True, t)
        self.set_managed_color(color)
        mgr.palette.set_match_position(target_index)
Esempio n. 6
0
    def __drag_data_get(self, view, ctx, sel, tid, etime):
        model, paths = self.get_selection().get_selected_rows()
        if tid == DND_QL:
            songs = [model[path][0] for path in paths
                     if model[path][0].can_add]
            if len(songs) != len(paths):
                qltk.ErrorMessage(
                    qltk.get_top_parent(self), _("Unable to copy songs"),
                    _("The files selected cannot be copied to other "
                      "song lists or the queue.")).run()
                Gdk.drag_abort(ctx, etime)
                return

            qltk.selection_set_songs(sel, songs)

            # DEM 2018/05/25: The below check is a deliberate repitition of
            # code in the drag-motion signal handler.  In MacOS/Quartz, the
            # context action is not propogated between event handlers for
            # drag-motion and drag-data-get using "ctx.get_actions()".  It is
            # unclear if this is a bug or expected behavior.  Regardless, the
            # context widget information is the same so identical behavior can
            # be achieved by simply using the same widget check as in the move
            # action.
            if Gtk.drag_get_source_widget(ctx) == self and \
                    not self.__force_copy:
                self.__drag_iters = list(map(model.get_iter, paths))
            else:
                self.__drag_iters = []
        else:
            uris = [model[path][0]("~uri") for path in paths]
            sel.set_uris(uris)
            self.__drag_iters = []
Esempio n. 7
0
    def drag_motion_cb(self, widget, context, x, y, t):
        if "application/x-color" not in map(str, context.list_targets()):
            return False

        # Default action: copy means insert or overwrite
        action = Gdk.DragAction.COPY

        # Update the insertion marker
        i = self.get_index_at_pos(x, y)
        if i != self._drag_insertion_index:
            self.queue_draw()
        self._drag_insertion_index = i

        # Dragging around inside the widget implies moving, by default
        source_widget = Gtk.drag_get_source_widget(context)
        if source_widget is self:
            action = Gdk.DragAction.MOVE
            if i is None:
                action = Gdk.DragAction.DEFAULT  # it'll be ignored
            else:
                mgr = self.get_color_manager()
                if mgr.palette.get_color(i) is None:
                    # Empty swatch, convert moves to copies
                    action = Gdk.DragAction.COPY

        # Cursor and status update
        Gdk.drag_status(context, action, t)
Esempio n. 8
0
    def textview_drag_received(self, widget, context, x, y, selection, targetType, time):
        if targetType == config.data.target_type['timestamp']:
            data=decode_drop_parameters(selection.get_data().decode('utf-8'))
            position=int(data['timestamp'])
            #(x, y) = self.textview.get_window()_to_buffer_coords(Gtk.TextWindowType.TEXT,
            #                                               int(x),
            #                                               int(y))
            it=self.textview.get_iter_at_location(x, y)
            if it is None:
                return False
            # Check that preceding mark.value is lower
            m, i=self.find_preceding_mark(it.iter)
            if m is not None and m.value > position:
                self.message(_("Invalid timestamp mark"))
                return False
            m, i=self.find_following_mark(it.iter)
            if m is not None and m.value < position:
                self.message(_("Invalid timestamp mark"))
                return False
            # Create the timestamp
            self.create_timestamp_mark(position, it.iter)

            # If the drag originated from our own widgets, remove it.
            source=Gtk.drag_get_source_widget(context)
            if source in self.marks:
                self.remove_timestamp_mark(source)
            return True
        return False
Esempio n. 9
0
 def __onDragMotion (self, arrow, context, x, y, timestamp):
     if not self.hovered and self.__containsPoint(x,y):
         self.hovered = True
         self.emit("hovered", Gtk.drag_get_source_widget(context))
     elif self.hovered and not self.__containsPoint(x,y):
         self.hovered = False
         self.emit("left")
Esempio n. 10
0
    def drag_data_received(self, tv, context, x, y, selection, info, etime):
        """
            Called when someone drags some thing onto the playlist panel
        """
        # if the drag originated from radio view deny it
        # TODO this might change if we are allowed to change the order of radio
        if Gtk.drag_get_source_widget(context) == tv:
            context.drop_finish(False, etime)
            return

        locs = list(selection.get_uris())

        path = self.tree.get_path_at_pos(x, y)
        if path:
            # Add whatever we received to the playlist at path
            iter = self.model.get_iter(path[0])
            current_playlist = self.model.get_value(iter, 2)

            # if it's a track that we've dragged to, get the parent
            if isinstance(current_playlist, playlistpanel.TrackWrapper):
                current_playlist = current_playlist.playlist

            elif not isinstance(current_playlist, xl.playlist.Playlist):
                self._add_new_station(locs)
                return
            (tracks, playlists) = self.tree.get_drag_data(locs)
            current_playlist.extend(tracks)
            # Do we save in the case when a user drags a file onto a playlist in the playlist panel?
            # note that the playlist does not have to be open for this to happen
            self.playlist_manager.save_playlist(current_playlist, overwrite=True)
            self._load_playlist_nodes(current_playlist)
        else:
            self._add_new_station(locs)
Esempio n. 11
0
    def __drag_drop(self, destino, drag_context, x, y, n):
        """
        Ejecuta drop sobre un destino.
        """

        videoitem = Gtk.drag_get_source_widget(drag_context)

        if videoitem.get_parent() == destino:
            return

        else:
            # E try siguiente es para evitar problemas cuando:
            # El drag termina luego de que el origen se ha
            # comenzado a descargar y por lo tanto, no tiene padre.
            try:
                videoitem.get_parent().remove(videoitem)
                destino.pack_start(videoitem, False, False, 1)

            except:
                return

            if destino == self.paneltube.descargar:
                text = TipDescargas

            elif destino == self.paneltube.encontrados:
                text = TipEncontrados

            videoitem.set_tooltip_text(text)
Esempio n. 12
0
	def got_data_cb(self, windowid, context, x, y, data, info, time):
		treeselection = windowid.get_selection()
		model, paths = treeselection.get_selected_rows()
		refs = []
		for path in paths:
    			refs.append(Gtk.TreeRowReference.new(model, path))
		#refs = [path.append(Gtk.TreeRowReference.new(model, path)) for path in paths# different way of wording the above
		destpath = windowid.get_dest_row_at_pos(x, y)
		if destpath:
			destpath, position = destpath
			destiter = model.get_iter(destpath)
		else:
			#print "outside the rows"
			try: destiter = model.get_iter(len(model))
			except: destiter = False
		#handle internal drag/drops here
		sourceWidget = Gtk.drag_get_source_widget(context)		
		if sourceWidget == windowid:
			#print "internals"			
			if not destpath in paths:
				if (position == Gtk.TreeViewDropPosition.BEFORE):# or position == Gtk.TreeViewDropPosition.INTO_OR_BEFORE):
					print("into or before")
					for currentref in refs:
						model.move_before(model.get_iter(currentref.get_path()), destiter)
				else:
					print("else")
					for currentref in reversed(refs):
						model.move_after(model.get_iter(currentref.get_path()), destiter)
		else:

			##detach model improves performance but causes flicker # MAKES MIKE A SAD PANDA
			windowid.set_model(None)
			#f****n file managers handling differently :( nautilus sends plaintext, but pcman sends uris
			tempArray = []
			if data.get_text():
				for i in data.get_text().splitlines():
					tempArray.append(i)
			else:
				for i in data.get_uris():
					tempArray.append(i)
			from time import time as systime
			systime1 = systime()
			#got the data now split it up
			for i in tempArray:
				i = i.replace('file://','').replace('%20',' ') #simple but is way too slow
				if os.path.isdir(i):
					for root, dirs, files in os.walk(i):
						while Gtk.events_pending():
	    						Gtk.main_iteration()
						for name in files:
							#print(name)
							self.add_row(os.path.join(root, name), model, destiter)
				else:
					self.add_row(i, model, destiter)
			##reattach model
			print("%s%f%s%i" % ("Add Operation took ",systime() - systime1," Items:", len(model)))
			del(systime)
			windowid.set_model(model)

		context.finish(True, False, time)
Esempio n. 13
0
    def drag_motion_cb(self, widget, context, x, y, t):
        if "application/x-color" not in map(str, context.list_targets()):
            return False

        # Default action: copy means insert or overwrite
        action = Gdk.DragAction.COPY

        # Update the insertion marker
        i = self.get_index_at_pos(x, y)
        if i != self._drag_insertion_index:
            self.queue_draw()
        self._drag_insertion_index = i

        # Dragging around inside the widget implies moving, by default
        source_widget = Gtk.drag_get_source_widget(context)
        if source_widget is self:
            action = Gdk.DragAction.MOVE
            if i is None:
                action = Gdk.DragAction.DEFAULT  # it'll be ignored
            else:
                mgr = self.get_color_manager()
                if mgr.palette.get_color(i) is None:
                    # Empty swatch, convert moves to copies
                    action = Gdk.DragAction.COPY

        # Cursor and status update
        Gdk.drag_status(context, action, t)
Esempio n. 14
0
    def drag_data_received_cb(self, widget, context, x, y,
                              selection, info, t):
        if "application/x-color" not in map(str, context.list_targets()):
            return False
        data = selection.get_data()
        data_type = selection.get_data_type()
        fmt = selection.get_format()
        logger.debug("drag-data-received: got type=%r", data_type)
        logger.debug("drag-data-received: got fmt=%r", fmt)
        logger.debug("drag-data-received: got data=%r len=%r", data, len(data))
        color = gui.uicolor.from_drag_data(data)
        target_index = self.get_index_at_pos(x, y)

        mgr = self.get_color_manager()
        if Gtk.drag_get_source_widget(context) is self:
            # Move/copy
            current_index = mgr.palette.match_position
            logger.debug("Move/copy %r -> %r", current_index, target_index)
            assert current_index is not None
            mgr.palette.reposition(current_index, target_index)
        else:
            if target_index is None:
                # Append if the drop wasn't over a swatch
                target_index = len(mgr.palette)
            else:
                # Insert before populated swatches, or overwrite empties
                if mgr.palette.get_color(target_index) is None:
                    mgr.palette.pop(target_index)
            mgr.palette.insert(target_index, color)
        self.queue_draw()
        self._drag_insertion_index = None
        context.finish(True, True, t)
        self.set_managed_color(color)
        mgr.palette.set_match_position(target_index)
Esempio n. 15
0
 def _internal_drag(self, context):
     source_widget = Gtk.drag_get_source_widget(context)
     if source_widget is None:
         return False
     view_ancestor = source_widget.get_ancestor(Gtk.Viewport)
     if view_ancestor is self._viewport:
         return True
     return False
Esempio n. 16
0
 def _internal_drag(self, context):
     source_widget = Gtk.drag_get_source_widget(context)
     if source_widget is None:
         return False
     view_ancestor = source_widget.get_ancestor(Gtk.Viewport)
     if view_ancestor is self._viewport:
         return True
     else:
         return False
Esempio n. 17
0
 def drag_data_received(self, widget, drag_context, x, y, data, info, time):
     palette = Gtk.Widget.get_ancestor(
         Gtk.drag_get_source_widget(drag_context), Gtk.ToolPalette)
     if palette is not None:
         item = Gtk.ToolPalette.get_drag_item(palette, data)
         if item is not None:
             topology_object = copy.copy(item.object_button.topology_object)
             add_object_task = AddObjectTask(topology_object, x, y)
             execute_task(None, add_object_task)
Esempio n. 18
0
 def __onDragMotion (self, arrow, context, x, y, timestamp):
     position = self.__getButtonAtPoint(x, y)
     if self.currentHovered != position:
         self.currentHovered = position
         if position > -1:
             self.emit("hovered", position, Gtk.drag_get_source_widget(context))
         else: self.emit("left")
     
     if position > -1:
         Gdk.drag_status(context, Gdk.DragAction.MOVE, timestamp)
         return True
     Gdk.drag_status(context, Gdk.DragAction.DEFAULT, timestamp)
Esempio n. 19
0
 def __drag_motion(self, view, ctx, x, y, time):
     if self.__drop_by_row:
         self.set_drag_dest(x, y)
         self.scroll_motion(x, y)
         if Gtk.drag_get_source_widget(ctx) == self:
             kind = Gdk.DragAction.MOVE
         else:
             kind = Gdk.DragAction.COPY
         Gdk.drag_status(ctx, kind, time)
         return True
     else:
         self.get_parent().drag_highlight()
         Gdk.drag_status(ctx, Gdk.DragAction.COPY, time)
         return True
Esempio n. 20
0
 def __drag_motion(self, view, ctx, x, y, time):
     if self.__drop_by_row:
         self.set_drag_dest(x, y)
         self.scroll_motion(x, y)
         if Gtk.drag_get_source_widget(ctx) == self:
             kind = Gdk.DragAction.MOVE
         else:
             kind = Gdk.DragAction.COPY
         Gdk.drag_status(ctx, kind, time)
         return True
     else:
         self.get_parent().drag_highlight()
         Gdk.drag_status(ctx, Gdk.DragAction.COPY, time)
         return True
Esempio n. 21
0
    def drag_n_drop_event(self, widget, context, x, y, selection, drag_id, eventtime):
        """
        Handle drag-n-drop events on the main layout area
        """

        # The drag source is inside MComix itself, so we ignore.
        if Gtk.drag_get_source_widget(context) is not None:
            return

        uris = selection.get_uris()
        if not uris:
            return

        paths = [Path(url2pathname(urlparse(uri).path)) for uri in uris]
        self.__file_handler.open_file_init(paths)
Esempio n. 22
0
    def on_stop_button_drag_data_received(self, widget, context, x, y, selection, info, time):
        """
            Allows for triggering the SPAT feature
            by dropping tracks on the stop button
        """
        source_widget = Gtk.drag_get_source_widget(context)

        if selection.target.name() == 'exaile-index-list' and isinstance(source_widget, PlaylistView):
            position = int(selection.data.split(',')[0])
            
            if position == source_widget.playlist.spat_position:
                position = -1

            source_widget.playlist.spat_position = position
            source_widget.queue_draw()
    def on_drag_data_received(self, widget, drag_context, x, y, data, info,
                              time):
        """ Callback ejecutado en evento 'drag-data-received'. Este se utiliza
        comunmente para terminar de transferir los datos de origin al widget destino.

        """
        print 'Datos recibidos', data
        new_img = Gtk.Image()
        new_img.set_from_pixbuf(data.get_pixbuf())
        widget.set_image(new_img)

        # Destruir origen.
        source_widget = Gtk.drag_get_source_widget(drag_context)
        if source_widget.get_name() == 'Las tijeras':
            source_widget.destroy()
Esempio n. 24
0
    def on_drag_data_received(self, treeview, context, x, y, selection, info,
                              timestamp):
        logging.debug('Storage on_drag_data_received')
        model = self.get_model().get_model()
        drop_info = self.get_dest_row_at_pos(x, y)

        # ff - from_filter
        ff_tree = Gtk.drag_get_source_widget(context)
        ff_model, ff_paths = ff_tree.get_selection().get_selected_rows()
        treerows = [ff_model[ff_path] for ff_path in ff_paths]
        if drop_info:
            path, position = drop_info
            iter = model.get_iter(path)

        if self == ff_tree:
            ff_row_refs = [
                Gtk.TreeRowReference.new(ff_model, ff_path)
                for ff_path in ff_paths
            ]

            def add_childs(treerow, new_iter):
                for ch_row in treerow.iterchildren():
                    niter = model.append(new_iter, [col for col in ch_row])
                    add_childs(ch_row, niter)

            for treerow, ref in zip(treerows, ff_row_refs):
                row = [col for col in treerow]
                if drop_info:
                    if position == Gtk.TreeViewDropPosition.BEFORE:
                        new_iter = model.insert_before(None, iter, row)
                    elif (position == Gtk.TreeViewDropPosition.INTO_OR_BEFORE
                          or position
                          == Gtk.TreeViewDropPosition.INTO_OR_AFTER):
                        if model.get_value(iter, self.is_file[0]):
                            new_iter = model.insert_after(None, iter, row)
                            iter = model.iter_next(iter)
                        else:
                            new_iter = model.append(iter, row)
                    else:
                        new_iter = model.insert_after(None, iter, row)
                        iter = model.iter_next(iter)
                else:
                    new_iter = model.append(None, row)
                treerow = model[ref.get_path()]  # reinitialize
                add_childs(treerow, new_iter)
            self.remove_replaced(ff_model, ff_row_refs)

        self.stop_emission('drag-data-received')
Esempio n. 25
0
    def __drag_drop_cb(self, widget, drag_context, x, y, time):
        ball = Gtk.drag_get_source_widget(drag_context)
        if not self.eraser:
            self.set_ball(ball.ball)
            self.set_draggable(self.ball != BallType.NULL)
            self.set_dest_drag(self.ball == BallType.NULL)

        if not ball.origin:
            ball.set_ball(BallType.NULL)
            ball.set_draggable(False)
            ball.set_dest_drag(True)

        if self.eraser and not ball.origin:
            ball.emit("id-changed")

        elif not self.eraser:
            self.emit("id-changed")
Esempio n. 26
0
    def on_drag_data_received(self, treeview, context, x, y, selection, info, timestamp):
        logging.debug("Storage on_drag_data_received")
        model = self.get_model().get_model()
        drop_info = self.get_dest_row_at_pos(x, y)

        # ff - from_filter
        ff_tree = Gtk.drag_get_source_widget(context)
        ff_model, ff_paths = ff_tree.get_selection().get_selected_rows()
        treerows = [ff_model[ff_path] for ff_path in ff_paths]
        if drop_info:
            path, position = drop_info
            iter = model.get_iter(path)

        if self == ff_tree:
            ff_row_refs = [Gtk.TreeRowReference.new(ff_model, ff_path) for ff_path in ff_paths]

            def add_childs(treerow, new_iter):
                for ch_row in treerow.iterchildren():
                    niter = model.append(new_iter, [col for col in ch_row])
                    add_childs(ch_row, niter)

            for treerow, ref in zip(treerows, ff_row_refs):
                row = [col for col in treerow]
                if drop_info:
                    if position == Gtk.TreeViewDropPosition.BEFORE:
                        new_iter = model.insert_before(None, iter, row)
                    elif (
                        position == Gtk.TreeViewDropPosition.INTO_OR_BEFORE
                        or position == Gtk.TreeViewDropPosition.INTO_OR_AFTER
                    ):
                        if model.get_value(iter, self.is_file[0]):
                            new_iter = model.insert_after(None, iter, row)
                            iter = model.iter_next(iter)
                        else:
                            new_iter = model.append(iter, row)
                    else:
                        new_iter = model.insert_after(None, iter, row)
                        iter = model.iter_next(iter)
                else:
                    new_iter = model.append(None, row)
                treerow = model[ref.get_path()]  # reinitialize
                add_childs(treerow, new_iter)
            self.remove_replaced(ff_model, ff_row_refs)

        self.stop_emission("drag-data-received")
Esempio n. 27
0
        def drag_received_cb(widget, context, x, y, selection, targetType, time):
            """Handle the drop of an annotation type.
            """
            if Gtk.drag_get_source_widget(context).is_ancestor(self.widget):
                # Ignore drops from our own widget
                return False

            if targetType == config.data.target_type['annotation']:
                sources=[ self.controller.package.annotations.get(uri) for uri in str(selection.get_data(), 'utf8').split('\n') ]
                if sources:
                    self.set_elements(sources)
                return True
            elif targetType == config.data.target_type['annotation-type']:
                sources=[ self.controller.package.annotationTypes.get(uri) for uri in str(selection.get_data(), 'utf8').split('\n') ]
                if sources:
                    self.set_elements(sources[0].annotations)
                return True
            return False
Esempio n. 28
0
    def drag_data_received_cb(self, widget, context, x, y, selection, info,
                              time):
        if info != DRAG_ITEM_ID:
            return False
        data = selection.get_text()
        data_type = selection.get_data_type()
        fmt = selection.get_format()
        logger.debug("drag-data-received: got type=%r", data_type)
        logger.debug("drag-data-received: got fmt=%r", fmt)
        logger.debug("drag-data-received: got data=%r len=%r", data, len(data))

        # isc always valid, we reject drops at invalid idx
        target_item_idx = self.index(x, y)

        src_widget = Gtk.drag_get_source_widget(context)
        is_copy = context.get_selected_action() == Gdk.DragAction.COPY
        success = self.on_drag_data(is_copy, src_widget, data, target_item_idx)
        context.finish(success, False, time)
        return True
Esempio n. 29
0
 def drag_received(widget, context, x, y, selection, targetType, time):
     if targetType == config.data.target_type['annotation']:
         sources = [
             self.controller.package.annotations.get(uri)
             for uri in str(selection.get_data(), 'utf8').split('\n')
         ]
         for ann in sources:
             self.insert(ann, i)
             # If the origin is from the same montage, then
             # consider it is a move and remove the origin
             # annotation
             w = Gtk.drag_get_source_widget(context)
             if w in self.contents:
                 self.contents.remove(w)
         self.refresh()
         return True
     else:
         logger.warning("Unknown target type for drag: %d", targetType)
     return False
Esempio n. 30
0
    def drag_data_received_cb(self, widget, context, x, y, selection,
                              info, time):
        if info != DRAG_ITEM_ID:
            return False
        data = selection.get_text()
        data_type = selection.get_data_type()
        fmt = selection.get_format()
        logger.debug("drag-data-received: got type=%r", data_type)
        logger.debug("drag-data-received: got fmt=%r", fmt)
        logger.debug("drag-data-received: got data=%r len=%r", data, len(data))

        # isc always valid, we reject drops at invalid idx
        target_item_idx = self.index(x, y)

        src_widget = Gtk.drag_get_source_widget(context)
        is_copy = context.get_selected_action() == Gdk.DragAction.COPY
        success = self.on_drag_data(is_copy, src_widget, data, target_item_idx)
        context.finish(success, False, time)
        return True
Esempio n. 31
0
 def drag_motion_cb(self, widget, context, x, y, time):
     if not self.dragging_allowed:
         return False
     action = None
     source_widget = Gtk.drag_get_source_widget(context)
     if self is source_widget:
         # Only moves are possible
         action = Gdk.DragAction.MOVE
     else:
         # Dragging from another widget, is always a copy
         action = Gdk.DragAction.COPY
     Gdk.drag_status(context, action, time)
     if not self.drag_highlighted:
         self.drag_highlighted = True
         self.queue_draw()
     if self.drag_highlighted:
         i = self.index(x, y)
         if i != self.drag_insertion_index:
             self.queue_draw()
             self.drag_insertion_index = i
Esempio n. 32
0
 def drag_motion_cb(self, widget, context, x, y, time):
     if not self.dragging_allowed:
         return False
     action = None
     source_widget = Gtk.drag_get_source_widget(context)
     if self is source_widget:
         # Only moves are possible
         action = Gdk.DragAction.MOVE
     else:
         # Dragging from another widget, is always a copy
         action = Gdk.DragAction.COPY
     Gdk.drag_status(context, action, time)
     if not self.drag_highlighted:
         self.drag_highlighted = True
         self.queue_draw()
     if self.drag_highlighted:
         i = self.index(x, y)
         if i != self.drag_insertion_index:
             self.queue_draw()
             self.drag_insertion_index = i
Esempio n. 33
0
    def drag_n_drop_event(self, widget, context, x, y, selection, drag_id,
                          eventtime):
        '''Handle drag-n-drop events on the main layout area.'''
        # The drag source is inside MComix itself, so we ignore.

        if (Gtk.drag_get_source_widget(context) is not None):
            return

        uris = selection.get_uris()

        if not uris:
            return

        # Normalize URIs
        uris = [portability.normalize_uri(uri) for uri in uris]
        paths = [urllib.request.url2pathname(uri) for uri in uris]

        if len(paths) > 1:
            self._window.filehandler.open_file(paths)
        else:
            self._window.filehandler.open_file(paths[0])
Esempio n. 34
0
    def _drag_data_received_cb(self, widget, drag_context, x, y,
                               selection_data, unused_info, timestamp):
        if not self.clip:
            # Indicate that a drop will not be accepted.
            Gdk.drag_status(drag_context, 0, timestamp)
            return

        if self.effects_listbox.get_row_at_y(y):
            # Drop happened inside the lisbox
            drop_index = widget.get_index()
        else:
            drop_index = len(self.effects_listbox.get_children()) - 1

        if drag_context.get_suggested_action() == Gdk.DragAction.COPY:
            # An effect dragged probably from the effects list.
            factory_name = str(selection_data.get_data(), "UTF-8")

            top_effect_index = drop_index + len(self.__get_time_effects())
            self.debug(
                "Effect dragged at position %s - computed top effect index %s",
                drop_index, top_effect_index)
            effect_info = self.app.effects.get_info(factory_name)
            pipeline = self.app.project_manager.current_project.pipeline
            with self.app.action_log.started(
                    "add effect",
                    finalizing_action=CommitTimelineFinalizingAction(pipeline),
                    toplevel=True):
                effect = self.clip.ui.add_effect(effect_info)
                if effect:
                    self.clip.set_top_effect_index(effect, top_effect_index)

        elif drag_context.get_suggested_action() == Gdk.DragAction.MOVE:
            # An effect dragged from the same listbox to change its position.
            source_eventbox = Gtk.drag_get_source_widget(drag_context)
            source_row = source_eventbox.get_parent()
            source_index = source_row.get_index()

            self._move_effect(self.clip, source_index, drop_index)

        drag_context.finish(True, False, timestamp)
Esempio n. 35
0
    def on_drag_data_received(self, treeview, context, x, y, selection, info, timestamp):
        logging.debug('Playlist on_drag_data_received')
        model = self.get_model().get_model()
        drop_info = self.get_dest_row_at_pos(x, y)

        if drop_info:
            path, position = drop_info
            iter = model.get_iter(path)

        files = sorted([file for file in get_files_from_gtk_selection_data(selection)
                if os.path.isdir(file) or get_file_extension(file) in FC().all_support_formats],
                key=lambda x: x[self.text[0]])
        if files:
            '''dnd from the outside of the player'''
            if self.is_empty():
                if len(files) == 1 and os.path.isdir(files[0]):
                    tabname = os.path.basename(files[0])
                else:
                    tabname = os.path.split(os.path.dirname(files[0]))[1]
                self.controls.notetabs.rename_tab(self.scroll, tabname)
            for i, file in enumerate(files):
                if os.path.isdir(file):
                    sorted_dirs = []
                    sorted_files = []
                    for f in sorted(os.listdir(file), key=lambda x: x):
                        f = os.path.join(file, f)
                        if os.path.isdir(f):
                            sorted_dirs.append(f)
                        elif get_file_extension(f) in FC().all_support_formats:
                            sorted_files.append(f)

                    listdir = sorted_dirs + sorted_files
                    '''
                    listdir = sorted(filter(lambda x: get_file_extension(x) in FC().all_support_formats or os.path.isdir(x),
                                     [os.path.join(file, f) for f in os.listdir(file)]), key=lambda x: x)
                    '''
                    for k, path in enumerate(listdir):
                        files.insert(i + k + 1, path)

            rows = self.file_paths_to_rows(files)
            if not rows:
                return
            rows = self.playlist_filter(rows)
            for row in rows:
                if drop_info:
                    if (position == Gtk.TREE_VIEW_DROP_BEFORE
                        or position == Gtk.TREE_VIEW_DROP_INTO_OR_BEFORE):
                        model.insert_before(None, iter, row)
                    else:
                        model.insert_after(None, iter, row)
                        iter = model.iter_next(iter)
                else:
                    model.append(None, row)

        else:
            '''dnd inside the player'''
            # ff - from_filter
            ff_tree = Gtk.drag_get_source_widget(context)
            ff_model, ff_paths = ff_tree.get_selection().get_selected_rows()
            treerows = [ff_model[ff_path] for ff_path in ff_paths]

            if self is ff_tree:
                '''internal dnd'''
                ff_row_refs = [Gtk.TreeRowReference.new(ff_model, ff_path) for ff_path in ff_paths]
                for ff_row_ref in ff_row_refs:
                    ff_iter = self.get_iter_from_row_reference(ff_row_ref)
                    f_iter = ff_model.convert_iter_to_child_iter(ff_iter)
                    if drop_info:
                        if (position == Gtk.TREE_VIEW_DROP_BEFORE
                            or position == Gtk.TREE_VIEW_DROP_INTO_OR_BEFORE):
                            model.move_before(f_iter, iter)
                        else:
                            model.move_after(f_iter, iter)
                            iter = model.iter_next(iter)
                    else:
                        model.move_before(f_iter, None)
                return

            else:
                '''dnd from other tree'''
                if self.is_empty():
                    path = treerows[0][self.path[0]]
                    if path:
                        if len(treerows) == 1 and os.path.isdir(path):
                            tabname = os.path.basename(path)
                        else:
                            tabname = os.path.split(os.path.dirname(path))[1]
                        self.controls.notetabs.rename_tab(self.scroll, tabname)
                    else:
                        pass
                for i, treerow in enumerate(treerows):

                    for k, ch_row in enumerate(treerow.iterchildren()):
                        treerows.insert(i + k + 1, ch_row)

                #treerows = self.playlist_filter(treerows)

                for i, treerow in enumerate(treerows):
                    if is_playlist(treerow[self.path[0]]):
                        rows = self.file_paths_to_rows([treerow[self.path[0]]])
                        if rows:
                            rows.reverse()
                            map(lambda row: treerows.insert(i + 1, row), rows)
                            continue
                    row = [col for col in treerow]
                    if drop_info:
                        if (position == Gtk.TREE_VIEW_DROP_BEFORE
                            or position == Gtk.TREE_VIEW_DROP_INTO_OR_BEFORE):
                            model.insert_before(None, iter, row)
                        else:
                            model.insert_after(None, iter, row)
                            iter = model.iter_next(iter)
                    else:
                        model.append(None, row)


        thread.start_new_thread(self.safe_fill_treerows, ())

        context.finish(True, False, timestamp)
        self.stop_emission('drag-data-received')
        return True
Esempio n. 36
0
 def __onDragDrop(self, arrow, context, x, y, timestamp):
     if self.__containsPoint(x, y):
         self.emit("dropped", Gtk.drag_get_source_widget(context))
         context.finish(True, True, timestamp)
         return True
Esempio n. 37
0
    def __drag_data_received(self, view, ctx, x, y, sel, info, etime, library):
        model = view.get_model()
        if info == DND_QL:
            filenames = qltk.selection_get_filenames(sel)
            move = bool(ctx.get_selected_action() & Gdk.DragAction.MOVE)
        elif info == DND_URI_LIST:
            def to_filename(s):
                try:
                    return uri2fsn(s)
                except ValueError:
                    return None

            filenames = list(filter(None, map(
                to_filename, sel.get_uris())))
            move = False
        else:
            Gtk.drag_finish(ctx, False, False, etime)
            return

        to_add = []
        for filename in filenames:
            if filename not in library.librarian:
                library.add_filename(filename)
            elif filename not in library:
                to_add.append(library.librarian[filename])
        library.add(to_add)
        songs = list(filter(None, map(library.get, filenames)))
        if not songs:
            Gtk.drag_finish(ctx, bool(not filenames), False, etime)
            return

        if not self.__drop_by_row:
            success = self.__drag_data_browser_dropped(songs)
            Gtk.drag_finish(ctx, success, False, etime)
            return

        try:
            path, position = view.get_dest_row_at_pos(x, y)
        except TypeError:
            path = max(0, len(model) - 1)
            position = Gtk.TreeViewDropPosition.AFTER

        if move and Gtk.drag_get_source_widget(ctx) == view:
            iter = model.get_iter(path) # model can't be empty, we're moving
            if position in (Gtk.TreeViewDropPosition.BEFORE,
                            Gtk.TreeViewDropPosition.INTO_OR_BEFORE):
                while self.__drag_iters:
                    model.move_before(self.__drag_iters.pop(0), iter)
            else:
                while self.__drag_iters:
                    model.move_after(self.__drag_iters.pop(), iter)
            Gtk.drag_finish(ctx, True, False, etime)
        else:
            song = songs.pop(0)
            try:
                iter = model.get_iter(path)
            except ValueError:
                iter = model.append(row=[song]) # empty model
            else:
                if position in (Gtk.TreeViewDropPosition.BEFORE,
                                Gtk.TreeViewDropPosition.INTO_OR_BEFORE):
                    iter = model.insert_before(iter, [song])
                else:
                    iter = model.insert_after(iter, [song])
            for song in songs:
                iter = model.insert_after(iter, [song])
            Gtk.drag_finish(ctx, True, move, etime)
Esempio n. 38
0
    def got_data_cb(self, windowid, context, x, y, data, info, time):
        treeselection = windowid.get_selection()
        model, paths = treeselection.get_selected_rows()
        refs = []
        for path in paths:
            refs.append(Gtk.TreeRowReference.new(model, path))
        #refs = [path.append(Gtk.TreeRowReference.new(model, path)) for path in paths# different way of wording the above
        destpath = windowid.get_dest_row_at_pos(x, y)
        if destpath:
            destpath, position = destpath
            destiter = model.get_iter(destpath)
        else:
            #print "outside the rows"
            try:
                destiter = model.get_iter(len(model))
            except:
                destiter = False
        #handle internal drag/drops here
        sourceWidget = Gtk.drag_get_source_widget(context)
        if sourceWidget == windowid:
            #print "internals"
            if not destpath in paths:
                if (
                        position == Gtk.TreeViewDropPosition.BEFORE
                ):  # or position == Gtk.TreeViewDropPosition.INTO_OR_BEFORE):
                    print("into or before")
                    for currentref in refs:
                        model.move_before(
                            model.get_iter(currentref.get_path()), destiter)
                else:
                    print("else")
                    for currentref in reversed(refs):
                        model.move_after(model.get_iter(currentref.get_path()),
                                         destiter)
        else:

            ##detach model improves performance but causes flicker # MAKES MIKE A SAD PANDA
            windowid.set_model(None)
            #f****n file managers handling differently :( nautilus sends plaintext, but pcman sends uris
            tempArray = []
            if data.get_text():
                for i in data.get_text().splitlines():
                    tempArray.append(i)
            else:
                for i in data.get_uris():
                    tempArray.append(i)
            from time import time as systime
            systime1 = systime()
            #got the data now split it up
            for i in tempArray:
                i = i.replace('file://',
                              '').replace('%20',
                                          ' ')  #simple but is way too slow
                if os.path.isdir(i):
                    for root, dirs, files in os.walk(i):
                        while Gtk.events_pending():
                            Gtk.main_iteration()
                        for name in files:
                            #print(name)
                            self.add_row(os.path.join(root, name), model,
                                         destiter)
                else:
                    self.add_row(i, model, destiter)
            ##reattach model
            print("%s%f%s%i" % ("Add Operation took ", systime() - systime1,
                                " Items:", len(model)))
            del (systime)
            windowid.set_model(model)

        context.finish(True, False, time)
Esempio n. 39
0
 def __onDragDrop(self, arrow, context, x, y, timestamp):
     position = self.__getButtonAtPoint(x, y)
     if position > -1:
         self.emit("dropped", position, Gtk.drag_get_source_widget(context))
         context.finish(True, True, timestamp)
         return True
Esempio n. 40
0
 def __onDragDrop (self, arrow, context, x, y, timestamp):
     if self.__containsPoint(x,y):
         self.emit("dropped", Gtk.drag_get_source_widget(context))
         context.finish(True, True, timestamp)
         return True
Esempio n. 41
0
    def on_drag_data_received(self, treeview, context, x, y, selection, info, timestamp):
        logging.debug('Playlist on_drag_data_received')
        model = self.get_model().get_model()
        drop_info = self.get_dest_row_at_pos(x, y)

        if drop_info:
            path, position = drop_info
            iter = model.get_iter(path)

        files = sorted([file for file in get_files_from_gtk_selection_data(selection)
                if os.path.isdir(file) or get_file_extension(file) in FC().all_support_formats],
                key=lambda x: x[self.text[0]])
        if files:
            '''dnd from the outside of the player'''
            if self.is_empty():
                if len(files) == 1 and os.path.isdir(files[0]):
                    tabname = os.path.basename(files[0])
                else:
                    tabname = os.path.split(os.path.dirname(files[0]))[1]
                self.controls.notetabs.rename_tab(self.scroll, tabname)
            for i, file in enumerate(files):
                if os.path.isdir(file):
                    sorted_dirs = []
                    sorted_files = []
                    for f in sorted(os.listdir(file), key=lambda x: x):
                        f = os.path.join(file, f)
                        if os.path.isdir(f):
                            sorted_dirs.append(f)
                        elif get_file_extension(f) in FC().all_support_formats:
                            sorted_files.append(f)

                    listdir = sorted_dirs + sorted_files
                    '''
                    listdir = sorted(filter(lambda x: get_file_extension(x) in FC().all_support_formats or os.path.isdir(x),
                                     [os.path.join(file, f) for f in os.listdir(file)]), key=lambda x: x)
                    '''
                    for k, path in enumerate(listdir):
                        files.insert(i + k + 1, path)

            rows = self.file_paths_to_rows(files)
            if not rows:
                return
            rows = self.playlist_filter(rows)
            for row in rows:
                if drop_info:
                    if (position == Gtk.TREE_VIEW_DROP_BEFORE
                        or position == Gtk.TREE_VIEW_DROP_INTO_OR_BEFORE):
                        model.insert_before(None, iter, row)
                    else:
                        model.insert_after(None, iter, row)
                        iter = model.iter_next(iter)
                else:
                    model.append(None, row)

        else:
            '''dnd inside the player'''
            # ff - from_filter
            ff_tree = Gtk.drag_get_source_widget(context)
            ff_model, ff_paths = ff_tree.get_selection().get_selected_rows()
            treerows = [ff_model[ff_path] for ff_path in ff_paths]

            if self is ff_tree:
                '''internal dnd'''
                ff_row_refs = [Gtk.TreeRowReference.new(ff_model, ff_path) for ff_path in ff_paths]
                for ff_row_ref in ff_row_refs:
                    ff_iter = self.get_iter_from_row_reference(ff_row_ref)
                    f_iter = ff_model.convert_iter_to_child_iter(ff_iter)
                    if drop_info:
                        if (position == Gtk.TREE_VIEW_DROP_BEFORE
                            or position == Gtk.TREE_VIEW_DROP_INTO_OR_BEFORE):
                            model.move_before(f_iter, iter)
                        else:
                            model.move_after(f_iter, iter)
                            iter = model.iter_next(iter)
                    else:
                        model.move_before(f_iter, None)
                return

            else:
                '''dnd from other tree'''
                if self.is_empty():
                    path = treerows[0][self.path[0]]
                    if path:
                        if len(treerows) == 1 and os.path.isdir(path):
                            tabname = os.path.basename(path)
                        else:
                            tabname = os.path.split(os.path.dirname(path))[1]
                        self.controls.notetabs.rename_tab(self.scroll, tabname)
                    else:
                        pass
                for i, treerow in enumerate(treerows):

                    for k, ch_row in enumerate(treerow.iterchildren()):
                        treerows.insert(i + k + 1, ch_row)

                #treerows = self.playlist_filter(treerows)

                for i, treerow in enumerate(treerows):
                    if is_playlist(treerow[self.path[0]]):
                        rows = self.file_paths_to_rows([treerow[self.path[0]]])
                        if rows:
                            rows.reverse()
                            map(lambda row: treerows.insert(i + 1, row), rows)
                            continue
                    row = [col for col in treerow]
                    if drop_info:
                        if (position == Gtk.TREE_VIEW_DROP_BEFORE
                            or position == Gtk.TREE_VIEW_DROP_INTO_OR_BEFORE):
                            model.insert_before(None, iter, row)
                        else:
                            model.insert_after(None, iter, row)
                            iter = model.iter_next(iter)
                    else:
                        model.append(None, row)


        thread.start_new_thread(self.safe_fill_treerows, ())

        context.finish(True, False, timestamp)
        self.stop_emission('drag-data-received')
        return True
Esempio n. 42
0
    def __drag_data_received(self, view, ctx, x, y, sel, info, etime, library):
        model = view.get_model()
        if info == DND_QL:
            filenames = qltk.selection_get_filenames(sel)
            move = (Gtk.drag_get_source_widget(ctx) == view)
        elif info == DND_URI_LIST:
            def to_filename(s):
                try:
                    return URI(s).filename
                except ValueError:
                    return None

            filenames = filter(None, map(to_filename, sel.get_uris()))
            move = False
        else:
            Gtk.drag_finish(ctx, False, False, etime)
            return

        to_add = []
        for filename in filenames:
            if filename not in library.librarian:
                library.add_filename(filename)
            elif filename not in library:
                to_add.append(library.librarian[filename])
        library.add(to_add)
        songs = filter(None, map(library.get, filenames))
        if not songs:
            Gtk.drag_finish(ctx, bool(not filenames), False, etime)
            return

        if not self.__drop_by_row:
            success = self.__drag_data_browser_dropped(songs)
            Gtk.drag_finish(ctx, success, False, etime)
            return

        try:
            path, position = view.get_dest_row_at_pos(x, y)
        except TypeError:
            path = max(0, len(model) - 1)
            position = Gtk.TreeViewDropPosition.AFTER

        if move and Gtk.drag_get_source_widget(ctx) == view:
            iter = model.get_iter(path) # model can't be empty, we're moving
            if position in (Gtk.TreeViewDropPosition.BEFORE,
                            Gtk.TreeViewDropPosition.INTO_OR_BEFORE):
                while self.__drag_iters:
                    model.move_before(self.__drag_iters.pop(0), iter)
            else:
                while self.__drag_iters:
                    model.move_after(self.__drag_iters.pop(), iter)
            Gtk.drag_finish(ctx, True, False, etime)
        else:
            song = songs.pop(0)
            try:
                iter = model.get_iter(path)
            except ValueError:
                iter = model.append(row=[song]) # empty model
            else:
                if position in (Gtk.TreeViewDropPosition.BEFORE,
                                Gtk.TreeViewDropPosition.INTO_OR_BEFORE):
                    iter = model.insert_before(iter, [song])
                else:
                    iter = model.insert_after(iter, [song])
            for song in songs:
                iter = model.insert_after(iter, [song])
            Gtk.drag_finish(ctx, True, move, etime)
Esempio n. 43
0
    def _drag_motion(self, treeview, context, x, y, *args):
        '''Set the library statusbar text when hovering a drag-n-drop over
        a collection (either books or from the collection area itself).
        Also set the TreeView to accept drops only when we are hovering over
        a valid drop position for the current drop type.

        This isn't pretty, but the details of treeviews and drag-n-drops
        are not pretty to begin with.
        '''
        drop_row = treeview.get_dest_row_at_pos(x, y)
        src_collection = self.get_current_collection()
        # Why isn't the drag ID passed along with drag-motion events?
        if Gtk.drag_get_source_widget(
                context) is self._treeview:  # Moving collection.
            model, src_iter = treeview.get_selection().get_selected()
            if drop_row is None:  # Drop "after" the last row.
                dest_path, pos = (len(model) -
                                  1, ), Gtk.TreeViewDropPosition.AFTER
            else:
                dest_path, pos = drop_row
            dest_iter = model.get_iter(dest_path)
            if model.is_ancestor(src_iter, dest_iter):  # No cycles!
                self._set_acceptable_drop(False)
                self._library.set_status_message('')
                return
            dest_collection = self._get_collection_at_path(dest_path)
            if pos in (Gtk.TreeViewDropPosition.BEFORE,
                       Gtk.TreeViewDropPosition.AFTER):
                dest_collection = self._library.backend.get_supercollection(
                    dest_collection)
            if (_COLLECTION_ALL in (src_collection, dest_collection)
                    or _COLLECTION_RECENT in (src_collection, dest_collection)
                    or src_collection == dest_collection):
                self._set_acceptable_drop(False)
                self._library.set_status_message('')
                return
            src_name = self._library.backend.get_collection_name(
                src_collection)
            if dest_collection is None:
                dest_name = _('Root')
            else:
                dest_name = self._library.backend.get_collection_name(
                    dest_collection)
            message = (_(
                'Put the collection "%(subcollection)s" in the collection "%(supercollection)s".'
            ) % {
                'subcollection': src_name,
                'supercollection': dest_name
            })
        else:  # Moving book(s).
            if drop_row is None:
                self._set_acceptable_drop(False)
                self._library.set_status_message('')
                return
            dest_path, pos = drop_row
            if pos in (Gtk.TreeViewDropPosition.BEFORE,
                       Gtk.TreeViewDropPosition.AFTER):
                self._set_acceptable_drop(False)
                self._library.set_status_message('')
                return
            dest_collection = self._get_collection_at_path(dest_path)
            if (src_collection == dest_collection
                    or dest_collection == _COLLECTION_ALL):
                self._set_acceptable_drop(False)
                self._library.set_status_message('')
                return
            dest_name = self._library.backend.get_collection_name(
                dest_collection)
            if src_collection == _COLLECTION_ALL:
                message = _('Add books to "%s".') % dest_name
            else:
                src_name = self._library.backend.get_collection_name(
                    src_collection)
                message = (_(
                    'Move books from "%(source collection)s" to "%(destination collection)s".'
                ) % {
                    'source collection': src_name,
                    'destination collection': dest_name
                })
        self._set_acceptable_drop(True)
        self._library.set_status_message(message)
Esempio n. 44
0
def _sig_drag_data_received(widget, context, x, y, selection, info, timestamp):
    print('drag-data-received:', selection.get_data())
    src_widget = Gtk.drag_get_source_widget(context)
    the_page_number = int(selection.get_data())
    child_widget = src_widget.get_nth_page(the_page_number)
    child_widget.set_text('Thank you!')
Esempio n. 45
0
    def drag_motion(self, tv, context, x, y, time):
        """
            Sets the appropriate drag action based on what we are hovering over

            hovering over playlists causes the copy action to occur
            hovering over tracks within the same playlist causes the move
                action to occur
            hovering over tracks within different playlist causes the move
                action to occur

            Called on the destination widget
        """
        # Reset any target to be default to moving tracks
        self.tree.enable_model_drag_dest([self.track_target],
                                         Gdk.DragAction.DEFAULT)
        # Determine where the drag is coming from
        dragging_playlist = False
        if tv == self.tree:
            selected_playlist = self.tree.get_selected_page()
            if selected_playlist is not None:
                dragging_playlist = True

        # Find out where they are dropping onto
        drop_info = tv.get_dest_row_at_pos(x, y)
        if drop_info:
            path, position = drop_info
            iter = self.model.get_iter(path)
            drop_target = self.model.get_value(iter, 2)

            if isinstance(drop_target, xl_playlist.Playlist):
                if dragging_playlist:
                    # If we drag onto  we copy, if we drag between we move
                    if (position == Gtk.TreeViewDropPosition.INTO_OR_BEFORE
                            or position
                            == Gtk.TreeViewDropPosition.INTO_OR_AFTER):
                        Gdk.drag_status(context, Gdk.DragAction.COPY, time)
                    else:
                        Gdk.drag_status(context, Gdk.DragAction.MOVE, time)
                        # Change target as well
                        self.tree.enable_model_drag_dest(
                            [self.playlist_target], Gdk.DragAction.DEFAULT)
                else:
                    Gdk.drag_status(context, Gdk.DragAction.COPY, time)
            elif isinstance(drop_target, TrackWrapper):
                # We are dragging onto another track
                # make it a move operation if we are only dragging
                # tracks within our widget
                # We do a copy if we are draggin from another playlist
                if Gtk.drag_get_source_widget(
                        context) == tv and not dragging_playlist:
                    Gdk.drag_status(context, Gdk.DragAction.MOVE, time)
                else:
                    Gdk.drag_status(context, Gdk.DragAction.COPY, time)
            else:
                # Prevent drop operation by changing the targets
                self.tree.enable_model_drag_dest(self.deny_targets,
                                                 Gdk.DragAction.DEFAULT)
                return False
            return True
        else:  # No drop info
            if dragging_playlist:
                context.drag_status(Gdk.DragAction.MOVE, time)
                # Change target as well
                self.tree.enable_model_drag_dest([self.playlist_target],
                                                 Gdk.DragAction.DEFAULT)
Esempio n. 46
0
    def drag_motion(self, tv, context, x, y, time):
        """
            Sets the appropriate drag action based on what we are hovering over

            hovering over playlists causes the copy action to occur
            hovering over tracks within the same playlist causes the move
                action to occur
            hovering over tracks within different playlist causes the move 
                action to occur

            Called on the destination widget
        """
        # Reset any target to be default to moving tracks
        self.tree.enable_model_drag_dest([self.track_target],
            Gdk.DragAction.DEFAULT)
        # Determine where the drag is coming from
        dragging_playlist = False
        if tv == self.tree:
            selected_playlist = self.tree.get_selected_page()
            if selected_playlist is not None:
                dragging_playlist = True

        # Find out where they are dropping onto
        drop_info = tv.get_dest_row_at_pos(x, y)
        if drop_info:
            path, position = drop_info
            iter = self.model.get_iter(path)
            drop_target = self.model.get_value(iter, 2)

            if isinstance(drop_target, playlist.Playlist):
                if dragging_playlist:
                    # If we drag onto  we copy, if we drag between we move
                    if position == Gtk.TreeViewDropPosition.INTO_OR_BEFORE or \
                        position == Gtk.TreeViewDropPosition.INTO_OR_AFTER:
                        Gdk.drag_status(context, Gdk.DragAction.COPY, time)
                    else:
                        Gdk.drag_status(context, Gdk.DragAction.MOVE, time)
                        # Change target as well
                        self.tree.enable_model_drag_dest([self.playlist_target],
                                                         Gdk.DragAction.DEFAULT)
                else:
                    Gdk.drag_status(context, Gdk.DragAction.COPY, time)
            elif isinstance(drop_target, TrackWrapper):
                # We are dragging onto another track
                # make it a move operation if we are only dragging
                # tracks within our widget
                # We do a copy if we are draggin from another playlist
                if Gtk.drag_get_source_widget(context) == tv and \
                    dragging_playlist == False:
                    Gdk.drag_status(context, Gdk.DragAction.MOVE, time)
                else:
                    Gdk.drag_status(context, Gdk.DragAction.COPY, time)
            else:
                # Prevent drop operation by changing the targets
                self.tree.enable_model_drag_dest(self.deny_targets,
                                                 Gdk.DragAction.DEFAULT)
                return False
            return True
        else: # No drop info
            if dragging_playlist:
                context.drag_status(Gdk.DragAction.MOVE, time)
                # Change target as well
                self.tree.enable_model_drag_dest([self.playlist_target],
                                                     Gdk.DragAction.DEFAULT)
Esempio n. 47
0
 def __onDragDrop (self, arrow, context, x, y, timestamp):
     position = self.__getButtonAtPoint(x, y)
     if position > -1:
         self.emit("dropped", position, Gtk.drag_get_source_widget(context))
         context.finish(True, True, timestamp)
         return True
Esempio n. 48
0
    def on_drag_data_received(self, treeview, context, x, y, selection, info, timestamp):
        logging.debug('Storage on_drag_data_received')
        model = self.get_model().get_model()
        drop_info = self.get_dest_row_at_pos(x, y)

        # ff - from_filter
        ff_tree = Gtk.drag_get_source_widget(context)
        ff_model, ff_paths = ff_tree.get_selection().get_selected_rows()
        treerows = [ff_model[ff_path] for ff_path in ff_paths]
        if drop_info:
            path, position = drop_info
            iter = model.get_iter(path)
            if position == Gtk.TREE_VIEW_DROP_INTO_OR_BEFORE or position == Gtk.TREE_VIEW_DROP_INTO_OR_AFTER:
                self.model[path][self.font[0]] = 'bold'

        if self == ff_tree:
            ff_row_refs = [Gtk.TreeRowReference.new(ff_model, ff_path) for ff_path in ff_paths]

            def add_childs(treerow, new_iter):
                    for ch_row in treerow.iterchildren():
                        niter = model.append(new_iter, [col for col in ch_row])
                        add_childs(ch_row, niter)
            for treerow, ref in zip(treerows, ff_row_refs):
                row = [col for col in treerow]
                if drop_info:
                    if position == Gtk.TREE_VIEW_DROP_BEFORE:
                        new_iter = model.insert_before(None, iter, row)
                    elif (position == Gtk.TREE_VIEW_DROP_INTO_OR_BEFORE or
                          position == Gtk.TREE_VIEW_DROP_INTO_OR_AFTER):
                        new_iter = model.append(iter, row)
                    else:
                        new_iter = model.insert_after(None, iter, row)
                        iter = model.iter_next(iter)
                else:
                    new_iter = model.append(None, row)
                treerow = model[ref.get_path()]     # reinitialize
                add_childs(treerow, new_iter)
            self.remove_replaced(ff_model, ff_row_refs)
        else:
            for treerow in treerows:
                row = [col for col in treerow]
                if drop_info:
                    if position == Gtk.TREE_VIEW_DROP_BEFORE:
                        new_iter = model.insert_before(None, iter, row)
                    elif (position == Gtk.TREE_VIEW_DROP_INTO_OR_BEFORE or
                          position == Gtk.TREE_VIEW_DROP_INTO_OR_AFTER):
                        new_iter = model.append(iter, row)
                    else:
                        new_iter = model.insert_after(None, iter, row)
                        iter = model.iter_next(iter)
                else:
                    new_iter = model.append(None, row)
                if len(treerows) == 1 and treerow[self.font[0]] == 'bold':
                    while treerow.next and treerow.next[self.font[0]] != 'bold':
                        treerow = treerow.next
                        treerows.append(treerow)
                        drop_info = True
                        iter = new_iter
                        position = Gtk.TREE_VIEW_DROP_INTO_OR_AFTER

        self.stop_emission('drag-data-received')