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
1=== modified file 'qreator/QreatorWindow.py'
2--- qreator/QreatorWindow.py 2012-06-09 00:06:51 +0000
3+++ qreator/QreatorWindow.py 2012-06-09 15:58:19 +0000
4@@ -14,6 +14,8 @@
5 # with this program. If not, see <http://www.gnu.org/licenses/>.
6 ### END LICENSE
7
8+import os
9+import tempfile
10 import cairo
11 import math
12 from gi.repository import Gtk, Gdk, GdkPixbuf, GObject # pylint: disable=E0611
13@@ -77,6 +79,36 @@
14 # Add an initial text, so that there is an initial QR code
15 self.qr_code_placeholder = 'http://launchpad.net/qreator'
16
17+ # Prepare the qrcode for drag n drop
18+ self.tempfilepath = None
19+
20+ def drag_data_get_cb(widget, drag_context, selection_data,
21+ info, time):
22+ if self.tempfilepath is None:
23+ handle, self.tempfilepath = tempfile.mkstemp(
24+ suffix=".png", prefix="qreator_")
25+ pixbuf = self.get_pixbuf_from_drawing_area()
26+ pixbuf.savev(self.tempfilepath, 'png', [], [])
27+ selection_data.set_uris(["file://{}".format(self.tempfilepath)])
28+ return True
29+
30+ def remove_tempfile(path):
31+ if os.path.exists(path):
32+ os.remove(path)
33+ return False
34+
35+ def drag_end_cb(widget, drag_context):
36+ GObject.timeout_add(5, remove_tempfile, self.tempfilepath)
37+ self.tempfilepath = None
38+
39+ self.ui.qr_drawingarea.drag_source_set(Gdk.ModifierType.BUTTON1_MASK,
40+ [], Gdk.DragAction.COPY)
41+ self.ui.qr_drawingarea.drag_source_set_target_list(None)
42+ self.ui.qr_drawingarea.drag_source_add_uri_targets()
43+ self.ui.qr_drawingarea.connect("drag_data_get", drag_data_get_cb)
44+ self.ui.qr_drawingarea.connect("drag_end", drag_end_cb)
45+
46+
47 def init_qr_types(self):
48 # Set up the QR types shown in the main icon view
49 self.ui.qr_types_view.set_text_column(COL_DESC)

Subscribers

People subscribed via source and target branches

to all changes: