From dff2e9ddc06eb9022da0f791c9f3406651c952da Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Sat, 17 May 2003 03:20:50 +0000 Subject: [PATCH] Icons for drag and drop svn: r1535 --- gramps2/src/FamilyView.py | 19 +++++++++++++++++-- gramps2/src/ImageSelect.py | 18 ++++++++++++------ gramps2/src/MediaView.py | 29 ++++++++++++++++++++++------- gramps2/src/const.py.in | 1 + 4 files changed, 52 insertions(+), 15 deletions(-) diff --git a/gramps2/src/FamilyView.py b/gramps2/src/FamilyView.py index 9af7302da..1b36e7421 100644 --- a/gramps2/src/FamilyView.py +++ b/gramps2/src/FamilyView.py @@ -600,8 +600,23 @@ class FamilyView: data = str(('child',id)); sel_data.set(sel_data.target, bits_per, data) - def drag_begin(self, context, a): - return + def drag_begin(self, obj, context): + return +# model, iter = self.child_selection.get_selected() +# path = model.get_path(iter) +# pixmap = self.child_list.create_row_drag_icon(path) +# print "map",pixmap + +# myimage = gtk.Image() +# print "set",pixmap +# myimage.set_from_pixmap(pixmap,None) + +# print "image" +# pixbuf = myimage.get_pixbuf() +# print "buf", pixbuf + +# context.set_icon_pixbuf(pixbuf,0,0) +# return #------------------------------------------------------------------------- # diff --git a/gramps2/src/ImageSelect.py b/gramps2/src/ImageSelect.py index 4e6fe5e14..fc9586b38 100644 --- a/gramps2/src/ImageSelect.py +++ b/gramps2/src/ImageSelect.py @@ -219,6 +219,7 @@ class Gallery(ImageSelect): self.on_photolist_drag_data_received) icon_list.connect("drag_data_get", self.on_photolist_drag_data_get) + icon_list.connect("drag_begin", self.on_drag_begin) _iconlist_refs.append(icon_list) @@ -251,6 +252,13 @@ class Gallery(ImageSelect): Handle resize events over the canvas, redrawing if the size changes """ + def on_drag_begin(self,obj,context): + if const.dnd_iamges: + mtype = self.sel_obj.getReference().getMimeType() + name = Utils.thumb_path(self.db.getSavePath(),self.sel_obj.getReference()) + pix = gtk.gdk.pixbuf_new_from_file(name) + context.set_icon_pixbuf(pix,0,0) + def item_event(self, widget, event=None): if self.button and event.type == gtk.gdk.MOTION_NOTIFY : @@ -258,10 +266,13 @@ class Gallery(ImageSelect): event.x,event.y): self.drag_item = widget.get_item_at(self.remember_x, self.remember_y) + icon_index = self.get_index(widget,event.x,event.y)-1 + self.sel_obj = self.dataobj.getPhotoList()[icon_index] if self.drag_item: widget.drag_begin(_drag_targets, gtk.gdk.ACTION_COPY|gtk.gdk.ACTION_MOVE, self.button, event) + return gtk.TRUE style = self.iconlist.get_style() @@ -458,7 +469,6 @@ class Gallery(ImageSelect): photo.setPath(name) except: photo.setPath(tfile) - # w.drag_finish(context, 1, 0, time) return self.add_thumbnail(oref) self.parent.lists_changed = 1 @@ -472,10 +482,8 @@ class Gallery(ImageSelect): for p in self.dataobj.getPhotoList(): if data.data == p.getReference().getId(): if index == icon_index or icon_index == -1: - # w.drag_finish(context, 0, 0, time) return else: - # w.drag_finish(context, 1, 0, time) nl = self.dataobj.getPhotoList() item = nl[index] if icon_index == 0: @@ -810,12 +818,10 @@ class GlobalMediaProperties: d = [attr.getType(),attr.getValue()] self.atree.add(d,attr) - def button_press(self,obj,event): + def button_press(self,obj): store,iter = self.refmodel.selection.get_selected() if not iter: return - if event.button == 1 and event.type == gtk.gdk._2BUTTON_PRESS: - pass def display_refs(self): if self.refs == 1: diff --git a/gramps2/src/MediaView.py b/gramps2/src/MediaView.py index 73538bddc..2624bc4fa 100644 --- a/gramps2/src/MediaView.py +++ b/gramps2/src/MediaView.py @@ -111,6 +111,11 @@ class MediaView: self.list.drag_dest_set(gtk.DEST_DEFAULT_ALL, t,gtk.gdk.ACTION_COPY|gtk.gdk.ACTION_MOVE) + + self.list.connect("drag_data_received", self.on_drag_data_received) + self.list.connect("drag_data_get", self.on_drag_data_get) + self.list.connect("drag_begin", self.on_drag_begin) + self.update = update self.list.connect('button-press-event',self.on_button_press_event) self.selection.connect('changed',self.on_select_row) @@ -275,12 +280,26 @@ class MediaView: if o.getReference() == mobj: return 1 return 0 - + + def on_drag_begin(self,obj,context): + store,iter = self.selection.get_selected() + if not iter: + return + if (const.dnd_images): + object = self.db.getObject(store.get_value(iter,1)) + mtype = object.getMimeType() + name = Utils.thumb_path(self.db.getSavePath(),object) + pix = gtk.gdk.pixbuf_new_from_file(name) + context.set_icon_pixbuf(pix,0,0) + def on_drag_data_get(self,w, context, selection_data, info, time): if info == 1: return - d = w.get_row_data(w.focus_row) - id = d.getId() + + store,iter = self.selection.get_selected() + if not iter: + return + id = store.get_value(iter,1) selection_data.set(selection_data.target, 8, id) def on_drag_data_received(self,w, context, x, y, data, info, time): @@ -298,7 +317,6 @@ class MediaView: photo.setDescription(description) self.db.addObject(photo) Utils.modified() - w.drag_finish(context, 1, 0, time) self.load_media() if GrampsCfg.mediaref == 0: name = RelImage.import_media_object(name, @@ -336,12 +354,9 @@ class MediaView: photo.setPath(name) except: photo.setPath(tfile) - w.drag_finish(context, 1, 0, time) return Utils.modified() if GrampsCfg.globalprop: ImageSelect.GlobalMediaProperties(self.db,photo,None) - else: - w.drag_finish(context, 0, 0, time) diff --git a/gramps2/src/const.py.in b/gramps2/src/const.py.in index f004a6600..2c71ea723 100644 --- a/gramps2/src/const.py.in +++ b/gramps2/src/const.py.in @@ -96,6 +96,7 @@ template_dir = "%s/templates" % dataDir fdl = "%s/fdl.txt" % dataDir startup = 1 +dnd_images = 1 #------------------------------------------------------------------------- #