From a1c363e4bd514d4664ad81256476d0ee49accb93 Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Sun, 5 Nov 2006 23:11:02 +0000 Subject: [PATCH] 2006-11-05 Don Allingham * src/DataViews/_PlaceView.py: drag-n-drop support * src/GrampsWidgets.py: drag-n-drop support for place selector widget * src/ScratchPad.py: drag-n-drop support for places * src/DdTargets.py: drag-n-drop support for places svn: r7555 --- gramps2/ChangeLog | 6 ++++ gramps2/src/DataViews/_PlaceView.py | 4 +++ gramps2/src/DdTargets.py | 2 ++ gramps2/src/GrampsWidgets.py | 12 +++++++ gramps2/src/ScratchPad.py | 51 +++++++++++++++++++++++------ 5 files changed, 65 insertions(+), 10 deletions(-) diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index b35ecd99d..8e7bf35cd 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -1,3 +1,9 @@ +2006-11-05 Don Allingham + * src/DataViews/_PlaceView.py: drag-n-drop support + * src/GrampsWidgets.py: drag-n-drop support for place selector widget + * src/ScratchPad.py: drag-n-drop support for places + * src/DdTargets.py: drag-n-drop support for places + 2006-11-05 Alex Roitman * NEWS: Update. * configure.in (ALL_LINGUAS): Add Turkish language. diff --git a/gramps2/src/DataViews/_PlaceView.py b/gramps2/src/DataViews/_PlaceView.py index b439a3480..6d188ed2f 100644 --- a/gramps2/src/DataViews/_PlaceView.py +++ b/gramps2/src/DataViews/_PlaceView.py @@ -39,6 +39,7 @@ import Errors import Bookmarks import const import Config +from DdTargets import DdTargets from Editors import EditPlace, DeletePlaceQuery from QuestionDialog import QuestionDialog, ErrorDialog from Filters.SideBar import PlaceSidebarFilter @@ -111,6 +112,9 @@ class PlaceView(PageView.ListView): self.add_action('FilterEdit', None, _('Place Filter Editor'), callback=self.filter_editor,) + def drag_info(self): + return DdTargets.PLACE_LINK + def filter_toggle(self, client, cnxn_id, etnry, data): if Config.get(Config.FILTER): self.search_bar.hide() diff --git a/gramps2/src/DdTargets.py b/gramps2/src/DdTargets.py index 3979561cc..b30ee33d3 100644 --- a/gramps2/src/DdTargets.py +++ b/gramps2/src/DdTargets.py @@ -115,6 +115,7 @@ class _DdTargets(object): self.SOURCEREF = _DdType(self,'srcref') self.REPOREF = _DdType(self,'reporef') self.REPO_LINK = _DdType(self,'repo-link') + self.PLACE_LINK= _DdType(self,'place-link') self.NAME = _DdType(self,'name') self.MEDIAOBJ = _DdType(self,'mediaobj') self.MEDIAREF = _DdType(self,'mediaref') @@ -143,6 +144,7 @@ class _DdTargets(object): self.MEDIAOBJ, self.MEDIAREF, self.REPO_LINK, + self.PLACE_LINK, self.SOURCE_LINK, self.PERSON_LINK, self.PERSON_LINK_LIST] diff --git a/gramps2/src/GrampsWidgets.py b/gramps2/src/GrampsWidgets.py index dea25c252..01679d583 100644 --- a/gramps2/src/GrampsWidgets.py +++ b/gramps2/src/GrampsWidgets.py @@ -22,6 +22,7 @@ import cgi import os +import cPickle as pickle from gettext import gettext as _ #------------------------------------------------------------------------- @@ -38,6 +39,7 @@ import DateHandler import DateEdit import const import Errors +from DdTargets import DdTargets _lock_path = os.path.join(const.image_dir, 'stock_lock.png') _lock_open_path = os.path.join(const.image_dir, 'stock_lock-open.png') @@ -531,6 +533,10 @@ class PlaceEntry: self.uistate = uistate self.track = track + self.obj.drag_dest_set(gtk.DEST_DEFAULT_ALL, [DdTargets.PLACE_LINK.target()], + gtk.gdk.ACTION_COPY) + self.obj.connect('drag_data_received', self.drag_data_received) + if get_val(): self.set_button(True) p = self.db.get_place_from_handle(self.get_val()) @@ -571,6 +577,12 @@ class PlaceEntry: except Errors.WindowActiveError: pass + def drag_data_received(self, widget, context, x, y, selection, info, time): + (drag_type, idval, obj, val) = pickle.loads(selection.data) + + data = self.db.get_place_from_handle(obj) + self.place_added(data) + def place_added(self, data): self.set_val(data.handle) self.obj.set_text("%s [%s]" % (data.get_title(),data.gramps_id)) diff --git a/gramps2/src/ScratchPad.py b/gramps2/src/ScratchPad.py index 2c8bfb2c2..07b25b2b2 100644 --- a/gramps2/src/ScratchPad.py +++ b/gramps2/src/ScratchPad.py @@ -256,6 +256,35 @@ class ScratchPadEvent(ScratchPadWrapper): return True return False +class ScratchPadPlace(ScratchPadWrapper): + + DROP_TARGETS = [DdTargets.PLACE_LINK] + DRAG_TARGET = DdTargets.PLACE_LINK + ICON = LINK_PIC + + def __init__(self,dbstate,obj): + ScratchPadWrapper.__init__(self,dbstate,obj) + self._type = _("Place") + + (drag_type, idval, handle, val) = pickle.loads(obj) + + value = self._db.get_place_from_handle(handle) + + self._title = value.get_title() + self._value = "" #value.get_description() + + def tooltip(self): + global escape + return "" + + def is_valid(self): + data = pickle.loads(self._obj) + handle = data[2] + obj = self._db.get_place_from_handle(handle) + if obj: + return True + return False + class ScratchPadFamilyEvent(ScratchPadGrampsTypeWrapper): DROP_TARGETS = [DdTargets.FAMILY_EVENT] @@ -786,7 +815,6 @@ class ScratchPadListView: 'family-delete', 'family-rebuild', 'source-update', - 'source-delete', 'source-rebuild', 'place-update', 'place-delete', @@ -795,16 +823,18 @@ class ScratchPadListView: 'media-delete', 'media-rebuild', 'event-update', - 'event-delete', 'event-rebuild', 'repository-update', - 'repository-delete', 'repository-rebuild' ) for signal in db_signals: self._db.connect(signal,self.remove_invalid_objects) - self._db.connect('person-delete', self.person_delete) + + self._db.connect('person-delete', gen_del_obj(self.delete_object, 'person-link')) + self._db.connect('source-delete', gen_del_obj(self.delete_object, 'source-link')) + self._db.connect('repository-delete', gen_del_obj(self.delete_object, 'repo-link')) + self._db.connect('event-delete', gen_del_obj(self.delete_object, 'pevent')) self.remove_invalid_objects() @@ -816,13 +846,12 @@ class ScratchPadListView: if not o[1].is_valid(): model.remove(o.iter) - def person_delete(self, handle_list): - + def delete_object(self, handle_list, link_type): model = self._widget.get_model() if model: for o in model: - if o[0] == 'person-link': + if o[0] == link_type: data = pickle.loads(o[1]._obj) if data[2] in handle_list: model.remove(o.iter) @@ -833,6 +862,7 @@ class ScratchPadListView: self.register_wrapper_class(ScratchPadAddress) self.register_wrapper_class(ScratchPadLocation) self.register_wrapper_class(ScratchPadEvent) + self.register_wrapper_class(ScratchPadPlace) self.register_wrapper_class(ScratchPadEventRef) self.register_wrapper_class(ScratchPadSourceRef) self.register_wrapper_class(ScratchPadRepoRef) @@ -853,7 +883,6 @@ class ScratchPadListView: for drop_target in wrapper_class.DROP_TARGETS: self._target_type_to_wrapper_class_map[drop_target.drag_type] = wrapper_class - # Methods for rendering the cells. def object_pixbuf(self, column, cell, model, node, user_data=None): @@ -867,7 +896,6 @@ class ScratchPadListView: def object_title(self, column, cell, model, node, user_data=None): o = model.get_value(node, 1) cell.set_property('text', o.get_title()) - def object_value(self, column, cell, model, node, user_data=None): o = model.get_value(node, 1) @@ -918,7 +946,7 @@ class ScratchPadListView: # the time values are the same so we can drop all but the first. if realTime == self._previous_drop_time: return - + # Find a wrapper class possible_wrappers = [target for target in context.targets \ if target in self._target_type_to_wrapper_class_map.keys()] @@ -1100,6 +1128,9 @@ def place_title(db,event): else: return u'' +def gen_del_obj(func, t): + return lambda l : func(l, t) + #------------------------------------------------------------------------- # #