More drag and drop work

This commit is contained in:
Michael Webster 2013-03-08 11:41:19 -05:00
parent edbfda1764
commit 28d89a7297
2 changed files with 27 additions and 12 deletions

View File

@ -219,7 +219,8 @@ class pluginclass( object ):
TARGET_TYPE_FAV = 81 TARGET_TYPE_FAV = 81
array = TargetEntry * 3 array = TargetEntry * 3
toFav = array( ( "FAVORITES", Gtk.TargetFlags.SAME_APP, 81 ), ( "text/plain", 0, 100 ), ( "text/uri-list", 0, 101 ) ) toFav = array( ( "FAVORITES", Gtk.TargetFlags.SAME_APP, 81 ), ( "text/plain", 0, 100 ), ( "text/uri-list", 0, 101 ) )
fromFav = TargetEntry( "FAVORITES", Gtk.TargetFlags.SAME_APP, 81 ) array1 = TargetEntry * 2
fromFav = array1( ("FAVORITES", Gtk.TargetFlags.SAME_APP, 81), ("FAVORITES", Gtk.TargetFlags.SAME_APP, 81) )
@print_timing @print_timing
def __init__( self, mintMenuWin, toggleButton, de ): def __init__( self, mintMenuWin, toggleButton, de ):
@ -275,10 +276,10 @@ class pluginclass( object ):
# Hookup for text input # Hookup for text input
self.content_holder.connect( "key-press-event", self.keyPress ) self.content_holder.connect( "key-press-event", self.keyPress )
self.favoritesBox.connect( "drag_data_received", self.ReceiveCallback ) self.favoritesBox.connect( "drag-data-received", self.ReceiveCallback )
gtk.gtk_drag_dest_set ( hash(self.favoritesBox), Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT | Gtk.DestDefaults.DROP, self.toButton, Gdk.DragAction.COPY ) gtk.gtk_drag_dest_set ( hash(self.favoritesBox), Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT | Gtk.DestDefaults.DROP, self.toButton, Gdk.DragAction.COPY )
self.showFavoritesButton.connect( "drag_data_received", self.ReceiveCallback ) self.showFavoritesButton.connect( "drag-data-received", self.ReceiveCallback )
gtk.gtk_drag_dest_set ( hash(self.showFavoritesButton), Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT | Gtk.DestDefaults.DROP, self.toButton, Gdk.DragAction.COPY ) gtk.gtk_drag_dest_set ( hash(self.showFavoritesButton), Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT | Gtk.DestDefaults.DROP, self.toButton, Gdk.DragAction.COPY )
# self.searchButton.connect( "button_release_event", self.SearchWithButton ) # self.searchButton.connect( "button_release_event", self.SearchWithButton )
@ -1430,9 +1431,9 @@ class pluginclass( object ):
favButton.position = position favButton.position = position
self.favorites.append( favButton ) self.favorites.append( favButton )
self.favoritesPositionOnGrid( favButton ) self.favoritesPositionOnGrid( favButton )
favButton.connect( "drag_data_received", self.onFavButtonDragReorder ) favButton.connect( "drag-data-received", self.onFavButtonDragReorder )
# gtk.gtk_drag_dest_set( hash(favButton), Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT | Gtk.DestDefaults.DROP, self.fromFav, Gdk.DragAction.COPY ) gtk.gtk_drag_dest_set( hash(favButton), Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT | Gtk.DestDefaults.DROP, self.fromFav, Gdk.DragAction.COPY )
favButton.connect( "drag_data_get", self.onFavButtonDragReorderGet ) favButton.connect( "drag-data-get", self.onFavButtonDragReorderGet )
gtk.gtk_drag_source_set( hash(favButton), Gdk.ModifierType.BUTTON1_MASK, self.toFav, Gdk.DragAction.COPY ) gtk.gtk_drag_source_set( hash(favButton), Gdk.ModifierType.BUTTON1_MASK, self.toFav, Gdk.DragAction.COPY )
position += 1 position += 1
@ -1511,9 +1512,9 @@ class pluginclass( object ):
self.favorites.append( favButton ) self.favorites.append( favButton )
self.favoritesPositionOnGrid( favButton ) self.favoritesPositionOnGrid( favButton )
favButton.connect( "drag_data_received", self.onFavButtonDragReorder ) favButton.connect( "drag-data-received", self.onFavButtonDragReorder )
gtk.gtk_drag_dest_set( hash(favButton), Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT | Gtk.DestDefaults.DROP, self.toFav, Gdk.DragAction.COPY ) gtk.gtk_drag_dest_set( hash(favButton), Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT | Gtk.DestDefaults.DROP, self.toFav, Gdk.DragAction.COPY )
favButton.connect( "drag_data_get", self.onFavButtonDragReorderGet ) favButton.connect( "drag-data-get", self.onFavButtonDragReorderGet )
gtk.gtk_drag_source_set ( hash(favButton), Gdk.ModifierType.BUTTON1_MASK, self.toFav, Gdk.DragAction.COPY ) gtk.gtk_drag_source_set ( hash(favButton), Gdk.ModifierType.BUTTON1_MASK, self.toFav, Gdk.DragAction.COPY )
if position >= 0: if position >= 0:
@ -1563,10 +1564,12 @@ class pluginclass( object ):
return False return False
def onFavButtonDragReorderGet( self, widget, context, selection, targetType, eventTime ): def onFavButtonDragReorderGet( self, widget, context, selection, targetType, eventTime ):
print "get"
if targetType == self.TARGET_TYPE_FAV: if targetType == self.TARGET_TYPE_FAV:
selection.set( selection.target, 8, str(widget.position) ) selection.set( selection.target, 8, str(widget.position) )
def onFavButtonDragReorder( self, widget, context, x, y, selection, targetType, time ): def onFavButtonDragReorder( self, widget, context, x, y, selection, targetType, time ):
print "reordeR"
if targetType == self.TARGET_TYPE_FAV: if targetType == self.TARGET_TYPE_FAV:
self.favoritesReorder( int(selection.data), widget.position ) self.favoritesReorder( int(selection.data), widget.position )

View File

@ -12,7 +12,10 @@ import xdg.DesktopEntry
import xdg.Menu import xdg.Menu
from filemonitor import monitor as filemonitor from filemonitor import monitor as filemonitor
import glib import glib
import ctypes
from ctypes import *
gtk = CDLL("libgtk-x11-2.0.so.0")
class IconManager(GObject.GObject): class IconManager(GObject.GObject):
@ -231,6 +234,11 @@ class easyButton( Gtk.Button ):
#[ iW, iH ] = iconManager.getIconSize( self.iconSize ) #[ iW, iH ] = iconManager.getIconSize( self.iconSize )
self.buttonImage.set_size_request( self.iconSize, self.iconSize ) self.buttonImage.set_size_request( self.iconSize, self.iconSize )
class TargetEntry(Structure):
_fields_ = [("target", c_char_p),
("flags", c_int),
("info", c_int)]
class ApplicationLauncher( easyButton ): class ApplicationLauncher( easyButton ):
def __init__( self, desktopFile, iconSize): def __init__( self, desktopFile, iconSize):
@ -262,13 +270,16 @@ class ApplicationLauncher( easyButton ):
self.setupLabels() self.setupLabels()
# Drag and Drop # Drag and Drop
self.connectSelf( "drag_data_get", self.dragDataGet ) self.connectSelf( "drag-data-get", self.dragDataGet )
#FIX self.drag_source_set( Gdk.ModifierType.BUTTON1_MASK , [ ( "text/plain", 0, 100 ), ( "text/uri-list", 0, 101 ) ], Gdk.DragAction.COPY )
array = TargetEntry * 2
targets = array(( "text/plain", 0, 100 ), ( "text/uri-list", 0, 101 ))
gtk.gtk_drag_source_set(hash(self), Gdk.ModifierType.BUTTON1_MASK, targets, Gdk.DragAction.COPY)
icon = self.getIcon( Gtk.IconSize.DND ) icon = self.getIcon( Gtk.IconSize.DND )
if icon: if icon:
#FIX # self.drag_source_set_icon_pixbuf( icon ) gtk.gtk_drag_source_set_icon_pixbuf( hash(self), hash(icon) )
del icon # del icon
self.connectSelf( "focus-in-event", self.onFocusIn ) self.connectSelf( "focus-in-event", self.onFocusIn )
self.connectSelf( "focus-out-event", self.onFocusOut ) self.connectSelf( "focus-out-event", self.onFocusOut )
@ -356,6 +367,7 @@ class ApplicationLauncher( easyButton ):
def dragDataGet( self, widget, context, selection, targetType, eventTime ): def dragDataGet( self, widget, context, selection, targetType, eventTime ):
print "drag data get"
if targetType == 100: # text/plain if targetType == 100: # text/plain
selection.set_text( "'" + self.desktopFile + "'", -1 ) selection.set_text( "'" + self.desktopFile + "'", -1 )
elif targetType == 101: # text/uri-list elif targetType == 101: # text/uri-list