[Deskbar] Drag & Drop for preferences dialog
- From: Sebastian Pölsterl <marduk k-d-w org>
- To: deskbar-applet-list gnome org
- Subject: [Deskbar] Drag & Drop for preferences dialog
- Date: Sun, 1 Oct 2006 13:42:56 +0200 (CEST)
Hi!
I wrote a first preview of the DnD feature.
It currently only works for local Python files. Just drag one onto the
handlers' list and it will be copyied to
~/.gnome2/deskbar-applet/handlers, loaded and initialized.
There's still a lot of work to do to achieve usability, though.
My plan is to let it look like the theme manager in the end.
--
Greetings,
Sebastian Pölsterl
### Eclipse Workspace Patch 1.0
#P deskbar-applet
Index: deskbar/ui/DeskbarPreferencesUI.py
===================================================================
RCS file: /cvs/gnome/deskbar-applet/deskbar/ui/DeskbarPreferencesUI.py,v
retrieving revision 1.23
diff -u -r1.23 DeskbarPreferencesUI.py
--- deskbar/ui/DeskbarPreferencesUI.py 29 Aug 2006 15:28:19 -0000 1.23
+++ deskbar/ui/DeskbarPreferencesUI.py 1 Oct 2006 11:21:30 -0000
@@ -1,7 +1,9 @@
from gettext import gettext as _
from os.path import join
+import shutil
import struct
import gtk, gtk.gdk, gtk.glade, gobject, gconf
+import gnomevfs
import deskbar, deskbar.Utils
from deskbar.ui.ModuleListView import ModuleListView
from deskbar import CUEMIAC_UI_NAME, ENTRIAC_UI_NAME, WINDOW_UI_NAME
@@ -202,6 +204,19 @@
self.use_selection_box.connect('toggled', self.on_use_selection_toggled, applet)
self.use_selection_id = deskbar.GCONF_CLIENT.notify_add(applet.prefs.GCONF_USE_SELECTION, lambda x, y, z, a: self.on_config_use_selection(z.value))
+ # Setup Drag & Drop
+ big_box = self.glade.get_widget("big_box")
+ self.TARGET_URI_LIST, self.TARGET_NS_URL = range(2)
+ DROP_TYPES = [('text/uri-list', 0, self.TARGET_URI_LIST),
+ ('_NETSCAPE_URL', 0, self.TARGET_NS_URL),
+ ]
+ big_box.drag_dest_set(gtk.DEST_DEFAULT_ALL, DROP_TYPES,
+ gtk.gdk.ACTION_COPY | gtk.gdk.ACTION_LINK | gtk.gdk.ACTION_MOVE)
+ big_box.connect("drag_data_received",
+ self.on_drag_data_received_data)
+ big_box.connect("drag_motion", self.on_drag_motion)
+ big_box.connect("drag_leave", self.on_drag_leave)
+
self.sync_ui()
def show_run_hide(self):
@@ -368,6 +383,40 @@
loader.stop_module_async (context)
else:
loader.initialize_module_async (context)
+
+ def on_drag_motion(self, widget, drag_context, x, y, timestamp):
+ return False
+
+ def on_drag_leave(self, big_box, drag_context, timestamp):
+ big_box.queue_draw()
+
+ def on_drag_data_received_data(self, widget, context, x, y, selection, info, etime):
+ """
+ http://cvs.gnome.org/viewcvs/gnome-control-center/capplets/theme-switcher/gnome-theme-manager.c?view=markup
+ """
+ if (not(info == self.TARGET_URI_LIST or info == self.TARGET_NS_URL)):
+ return
+
+ uri = gnomevfs.URI(selection.data.strip())
+
+ if (uri.is_local == 1):
+ local_path = uri.path
+ copy_file = True
+ else:
+ # TODO: Download
+ return
+
+ if not gnomevfs.get_mime_type(local_path) == "text/x-python":
+ return
+
+ if copy_file:
+ shutil.copy(local_path, deskbar.USER_HANDLERS_DIR[0])
+ handlers_path = join(deskbar.USER_HANDLERS_DIR[0], uri.short_name)
+
+ module_context = self.module_loader.load(handlers_path)
+ self.module_loader.initialize_module(module_context)
+
+ return
def show_preferences(applet, loader, model):
DeskbarPreferencesUI(applet, loader, model).show_run_hide()
[Date Prev][
Date Next] [Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]