Merge lp:~stefan-schwarzburg/qreator/drag_n_drop_support into lp:~dpm/qreator/trunk

Proposed by Schwarzburg
Status: Merged
Merged at revision: 88
Proposed branch: lp:~stefan-schwarzburg/qreator/drag_n_drop_support
Merge into: lp:~dpm/qreator/trunk
Diff against target: 49 lines (+32/-0)
1 file modified
qreator/QreatorWindow.py (+32/-0)
To merge this branch: bzr merge lp:~stefan-schwarzburg/qreator/drag_n_drop_support
Reviewer Review Type Date Requested Status
David Planella Approve
Review via email: mp+109489@code.launchpad.net

Description of the change

This adds basic drag support: the qrcode image can be draged into other applications. This behaves like the save feature: not the pixbuf is dragged, but the uri to a temporary file.

To post a comment you must log in.
88. By David Planella

Merged drag and drop support from lp:~stefan-schwarzburg/qreator/drag_n_drop_support

Revision history for this message
David Planella (dpm) wrote :

I like it, so merged it, thanks! :-)

A couple of things:

- I've changed the names of the callbacks to follow the same convention across the file (on_something instead of something_cb)
- Just an alternative, but instead of relying on a timeout to delete the temp file, you could have also used the atexit() function to delete it on exit
- I've tested the feature to work with Nautilus, but it does not work with Eye Of GNOME (on dragging and dropping the QR code, eog tells me it cannot find the file pointed by the UIR). Any ideas why not?

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'qreator/QreatorWindow.py'
--- qreator/QreatorWindow.py 2012-06-09 00:06:51 +0000
+++ qreator/QreatorWindow.py 2012-06-09 15:58:19 +0000
@@ -14,6 +14,8 @@
14# with this program. If not, see <http://www.gnu.org/licenses/>.14# with this program. If not, see <http://www.gnu.org/licenses/>.
15### END LICENSE15### END LICENSE
1616
17import os
18import tempfile
17import cairo19import cairo
18import math20import math
19from gi.repository import Gtk, Gdk, GdkPixbuf, GObject # pylint: disable=E061121from gi.repository import Gtk, Gdk, GdkPixbuf, GObject # pylint: disable=E0611
@@ -77,6 +79,36 @@
77 # Add an initial text, so that there is an initial QR code79 # Add an initial text, so that there is an initial QR code
78 self.qr_code_placeholder = 'http://launchpad.net/qreator'80 self.qr_code_placeholder = 'http://launchpad.net/qreator'
7981
82 # Prepare the qrcode for drag n drop
83 self.tempfilepath = None
84
85 def drag_data_get_cb(widget, drag_context, selection_data,
86 info, time):
87 if self.tempfilepath is None:
88 handle, self.tempfilepath = tempfile.mkstemp(
89 suffix=".png", prefix="qreator_")
90 pixbuf = self.get_pixbuf_from_drawing_area()
91 pixbuf.savev(self.tempfilepath, 'png', [], [])
92 selection_data.set_uris(["file://{}".format(self.tempfilepath)])
93 return True
94
95 def remove_tempfile(path):
96 if os.path.exists(path):
97 os.remove(path)
98 return False
99
100 def drag_end_cb(widget, drag_context):
101 GObject.timeout_add(5, remove_tempfile, self.tempfilepath)
102 self.tempfilepath = None
103
104 self.ui.qr_drawingarea.drag_source_set(Gdk.ModifierType.BUTTON1_MASK,
105 [], Gdk.DragAction.COPY)
106 self.ui.qr_drawingarea.drag_source_set_target_list(None)
107 self.ui.qr_drawingarea.drag_source_add_uri_targets()
108 self.ui.qr_drawingarea.connect("drag_data_get", drag_data_get_cb)
109 self.ui.qr_drawingarea.connect("drag_end", drag_end_cb)
110
111
80 def init_qr_types(self):112 def init_qr_types(self):
81 # Set up the QR types shown in the main icon view113 # Set up the QR types shown in the main icon view
82 self.ui.qr_types_view.set_text_column(COL_DESC)114 self.ui.qr_types_view.set_text_column(COL_DESC)

Subscribers

People subscribed via source and target branches

to all changes: