diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index dd5fe50f4..003a0216d 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -5,7 +5,16 @@ * src/DisplayTabs/_EmbeddedList.py: use cPickle instead of pickle * src/DisplayTabs/_GalleryTab.py: add dnd functionality * src/DdTargets.py: add URI_LIST and APP_ROOT - + * src/DataViews/_MediaView.py: slightly improve dnd + * src/DisplayModels/_BaseModel.py: handle sort column map + * src/DisplayModels/_MediaModel.py: handle sort column map + * src/DisplayModels/_RepositoryModel.py: handle sort column map + * src/DisplayModels/_SourceModel.py: handle sort column map + * src/DisplayModels/_EventModel.py: handle sort column map + * src/DisplayModels/_FamilyModel.py: handle sort column map + * src/DisplayModels/_PlaceModel.py: handle sort column map + * src/PageView.py: handle sort column map + 2006-08-10 Alex Roitman * src/Filters/SideBar/_PersonSidebarFilter.py (get_filter): Typo. diff --git a/gramps2/src/DataViews/_MediaView.py b/gramps2/src/DataViews/_MediaView.py index 5121ffec5..e2a32c156 100644 --- a/gramps2/src/DataViews/_MediaView.py +++ b/gramps2/src/DataViews/_MediaView.py @@ -25,6 +25,8 @@ # #------------------------------------------------------------------------- from gettext import gettext as _ +import urlparse +import os #------------------------------------------------------------------------- # @@ -45,10 +47,14 @@ import const import Config import Utils import Bookmarks +import Mime +import RelLib + from Editors import EditMedia import Errors from QuestionDialog import QuestionDialog from Filters.SideBar import MediaSidebarFilter +from DdTargets import DdTargets column_names = [ _('Title'), @@ -70,6 +76,8 @@ class MediaView(PageView.ListView): EDIT_MSG = _("Edit the selected media object") DEL_MSG = _("Delete the selected media object") + _DND_TYPE = DdTargets.URI_LIST + def __init__(self,dbstate,uistate): signal_map = { @@ -88,6 +96,83 @@ class MediaView(PageView.ListView): Config.client.notify_add("/apps/gramps/interface/filter", self.filter_toggle) + def _set_dnd(self): + """ + Sets up drag-n-drop. The source and destionation are set by calling .target() + on the _DND_TYPE. Obviously, this means that there must be a _DND_TYPE + variable defined that points to an entry in DdTargets. + """ + + dnd_types = [ self._DND_TYPE.target() ] + + self.list.drag_dest_set(gtk.DEST_DEFAULT_ALL, dnd_types, + gtk.gdk.ACTION_COPY) + self.list.drag_source_set(gtk.gdk.BUTTON1_MASK, + [self._DND_TYPE.target()], + gtk.gdk.ACTION_COPY) + self.list.connect('drag_data_get', self.drag_data_get) + self.list.connect('drag_data_received', self.drag_data_received) + + def drag_data_get(self, widget, context, sel_data, info, time): + """ + Provide the drag_data_get function, which passes a tuple consisting of: + + 1) Drag type defined by the .drag_type field specfied by the value + assigned to _DND_TYPE + 2) The id value of this object, used for the purpose of determining + the source of the object. If the source of the object is the same + as the object, we are doing a reorder instead of a normal drag + and drop + 3) Pickled data. The pickled version of the selected object + 4) Source row. Used for a reorder to determine the original position + of the object + """ + + # get the selected object, returning if not is defined + obj = self.get_selected() + if not obj: + return + + # pickle the data, and build the tuple to be passed + value = (self._DND_TYPE.drag_type, id(self), obj, self.find_index(obj)) + data = pickle.dumps(value) + + # pass as a string (8 bits) + sel_data.set(sel_data.target, 8, data) + + def find_index(self, obj): + """ + returns the index of the object within the associated data + """ + return self.model.indexlist[obj] + + def drag_data_received(self, widget, context, x, y, sel_data, info, time): + """ + Handle the standard gtk interface for drag_data_received. + + If the selection data is define, extract the value from sel_data.data, + and decide if this is a move or a reorder. + """ + + if sel_data and sel_data.data: + d = Utils.fix_encoding(sel_data.data.replace('\0',' ').strip()) + protocol,site,mfile,j,k,l = urlparse.urlparse(d) + if protocol == "file": + name = Utils.fix_encoding(mfile) + mime = Mime.get_type(name) + if not Mime.is_valid_type(mime): + return + photo = RelLib.MediaObject() + photo.set_path(name) + photo.set_mime_type(mime) + basename = os.path.basename(name) + (root,ext) = os.path.splitext(basename) + photo.set_description(root) + trans = self.dbstate.db.transaction_begin() + self.dbstate.db.add_object(photo, trans) + self.dbstate.db.transaction_commit(trans, + _("Drag Media Object")) + def get_bookmarks(self): return self.dbstate.db.get_media_bookmarks() @@ -150,6 +235,7 @@ class MediaView(PageView.ListView): vbox.pack_start(base,True) self.selection.connect('changed',self.row_change) + self._set_dnd() return vbox def row_change(self,obj): diff --git a/gramps2/src/DataViews/_PersonView.py b/gramps2/src/DataViews/_PersonView.py index e5654daa8..75127497d 100644 --- a/gramps2/src/DataViews/_PersonView.py +++ b/gramps2/src/DataViews/_PersonView.py @@ -478,13 +478,6 @@ class PersonView(PageView.PersonNavView): else: self.dirty = True -# if Config.get(Config.FILTER): -# self.search_bar.hide() -# self.filter_pane.show() -# else: -# self.search_bar.show() -# self.filter_pane.hide() - def filter_toggle(self, client, cnxn_id, etnry, data): if Config.get(Config.FILTER): self.search_bar.hide() diff --git a/gramps2/src/DisplayModels/_BaseModel.py b/gramps2/src/DisplayModels/_BaseModel.py index a539ef46a..811fbc88c 100644 --- a/gramps2/src/DisplayModels/_BaseModel.py +++ b/gramps2/src/DisplayModels/_BaseModel.py @@ -52,13 +52,18 @@ from Filters import SearchFilter class BaseModel(gtk.GenericTreeModel): def __init__(self, db, scol=0, order=gtk.SORT_ASCENDING, - tooltip_column=None, search=None, skip=set()): + tooltip_column=None, search=None, skip=set(), + sort_map=None): gtk.GenericTreeModel.__init__(self) self.prev_handle = None self.prev_data = None self.set_property("leak_references",False) self.db = db - self.sort_func = self.smap[scol] + if sort_map: + col = sort_map[scol][1] + self.sort_func = self.smap[col] + else: + self.sort_func = self.smap[scol] self.sort_col = scol self.skip = skip diff --git a/gramps2/src/DisplayModels/_EventModel.py b/gramps2/src/DisplayModels/_EventModel.py index 7b3162649..40c6c8bf8 100644 --- a/gramps2/src/DisplayModels/_EventModel.py +++ b/gramps2/src/DisplayModels/_EventModel.py @@ -59,7 +59,7 @@ from _BaseModel import BaseModel class EventModel(BaseModel): def __init__(self, db, scol=0, order=gtk.SORT_ASCENDING, search=None, - skip=set()): + skip=set(), sort_map=None): self.gen_cursor = db.get_event_cursor self.map = db.get_raw_event_data @@ -78,7 +78,7 @@ class EventModel(BaseModel): self.column_description, self.column_id, self.column_type, - self.column_date, + self.sort_date, self.column_place, self.column_cause, self.sort_change, @@ -86,7 +86,7 @@ class EventModel(BaseModel): self.column_tooltip, ] BaseModel.__init__(self, db, scol, order, tooltip_column=8, - search=search, skip=skip) + search=search, skip=skip, sort_map=sort_map) def on_get_n_columns(self): return len(self.fmap)+1 @@ -116,6 +116,13 @@ class EventModel(BaseModel): return DateHandler.get_date(event) return u'' + def sort_date(self,data): + if data[3]: + event = RelLib.Event() + event.unserialize(data) + return "%09d" % event.get_date_object().get_sort_value() + return u'' + def column_handle(self,data): return unicode(data[0]) diff --git a/gramps2/src/DisplayModels/_FamilyModel.py b/gramps2/src/DisplayModels/_FamilyModel.py index 79602efcb..9cc3c484b 100644 --- a/gramps2/src/DisplayModels/_FamilyModel.py +++ b/gramps2/src/DisplayModels/_FamilyModel.py @@ -61,7 +61,7 @@ from _BaseModel import BaseModel class FamilyModel(BaseModel): def __init__(self, db, scol=0, order=gtk.SORT_ASCENDING, search=None, - skip=set()): + skip=set(), sort_map=None): self.gen_cursor = db.get_family_cursor self.map = db.get_raw_family_data self.fmap = [ @@ -83,7 +83,7 @@ class FamilyModel(BaseModel): self.column_tooltip ] BaseModel.__init__(self, db, scol, order, tooltip_column=6, - search=search, skip=skip) + search=search, skip=skip, sort_map=sort_map) def on_get_n_columns(self): return len(self.fmap)+1 diff --git a/gramps2/src/DisplayModels/_MediaModel.py b/gramps2/src/DisplayModels/_MediaModel.py index 073706bf8..90c045114 100644 --- a/gramps2/src/DisplayModels/_MediaModel.py +++ b/gramps2/src/DisplayModels/_MediaModel.py @@ -61,7 +61,7 @@ from _BaseModel import BaseModel class MediaModel(BaseModel): def __init__(self, db, scol=0, order=gtk.SORT_ASCENDING, search=None, - skip=set()): + skip=set(), sort_map=None): self.gen_cursor = db.get_media_cursor self.map = db.get_raw_object_data @@ -85,7 +85,7 @@ class MediaModel(BaseModel): self.column_handle, ] BaseModel.__init__(self, db, scol, order, tooltip_column=7, - search=search, skip=skip) + search=search, skip=skip, sort_map=sort_map) def on_get_n_columns(self): return len(self.fmap)+1 diff --git a/gramps2/src/DisplayModels/_PlaceModel.py b/gramps2/src/DisplayModels/_PlaceModel.py index 10bdb3396..78e311b1b 100644 --- a/gramps2/src/DisplayModels/_PlaceModel.py +++ b/gramps2/src/DisplayModels/_PlaceModel.py @@ -58,7 +58,7 @@ from _BaseModel import BaseModel class PlaceModel(BaseModel): def __init__(self,db,scol=0,order=gtk.SORT_ASCENDING,search=None, - skip=set()): + skip=set(), sort_map=None): self.gen_cursor = db.get_place_cursor self.map = db.get_raw_place_data self.fmap = [ @@ -91,7 +91,7 @@ class PlaceModel(BaseModel): self.column_handle, ] BaseModel.__init__(self, db, scol, order, tooltip_column=12, - search=search, skip=skip) + search=search, skip=skip, sort_map=sort_map) def on_get_n_columns(self): return len(self.fmap)+1 diff --git a/gramps2/src/DisplayModels/_RepositoryModel.py b/gramps2/src/DisplayModels/_RepositoryModel.py index 2d649e761..a1f249f28 100644 --- a/gramps2/src/DisplayModels/_RepositoryModel.py +++ b/gramps2/src/DisplayModels/_RepositoryModel.py @@ -55,7 +55,7 @@ from _BaseModel import BaseModel class RepositoryModel(BaseModel): def __init__(self, db, scol=0, order=gtk.SORT_ASCENDING, search=None, - skip=set()): + skip=set(), sort_map=None): self.gen_cursor = db.get_repository_cursor self.get_handles = db.get_repository_handles self.map = db.get_raw_repository_data @@ -93,7 +93,7 @@ class RepositoryModel(BaseModel): ] BaseModel.__init__(self, db, scol, order, tooltip_column=12, - search=search, skip=skip) + search=search, skip=skip, sort_map=sort_map) def on_get_n_columns(self): return len(self.fmap)+1 diff --git a/gramps2/src/DisplayModels/_SourceModel.py b/gramps2/src/DisplayModels/_SourceModel.py index 09fd7d6ac..2a06d682f 100644 --- a/gramps2/src/DisplayModels/_SourceModel.py +++ b/gramps2/src/DisplayModels/_SourceModel.py @@ -58,7 +58,7 @@ from _BaseModel import BaseModel class SourceModel(BaseModel): def __init__(self,db,scol=0,order=gtk.SORT_ASCENDING,search=None, - skip=set()): + skip=set(), sort_map=None): self.map = db.get_raw_source_data self.gen_cursor = db.get_source_cursor self.fmap = [ @@ -80,7 +80,7 @@ class SourceModel(BaseModel): self.sort_change, ] BaseModel.__init__(self,db,scol,order,tooltip_column=7,search=search, - skip=skip) + skip=skip, sort_map=sort_map) def on_get_n_columns(self): return len(self.fmap)+1 diff --git a/gramps2/src/PageView.py b/gramps2/src/PageView.py index d1a114f06..edafcc0b6 100644 --- a/gramps2/src/PageView.py +++ b/gramps2/src/PageView.py @@ -627,7 +627,8 @@ class ListView(BookMarkView): search = self.search_bar.get_value() self.model = self.make_model(self.dbstate.db, self.sort_col, order, - search=search) + search=search, + sort_map=self.column_order()) self.list.set_model(self.model) colmap = self.column_order() diff --git a/gramps2/src/RelLib/_Date.py b/gramps2/src/RelLib/_Date.py index f1c0727c6..66585e077 100644 --- a/gramps2/src/RelLib/_Date.py +++ b/gramps2/src/RelLib/_Date.py @@ -216,7 +216,6 @@ class Date: cal = " (%s)" % Date.calendar_names[self.calendar] else: cal = "" - if self.modifier == Date.MOD_TEXTONLY: val = self.text