* 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
	


svn: r7153
This commit is contained in:
Don Allingham 2006-08-11 22:14:18 +00:00
parent 8b2e263f69
commit 6e47c80b0c
12 changed files with 125 additions and 25 deletions

View File

@ -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 <shura@gramps-project.org>
* src/Filters/SideBar/_PersonSidebarFilter.py (get_filter): Typo.

View File

@ -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):

View File

@ -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()

View File

@ -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

View File

@ -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])

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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()

View File

@ -216,7 +216,6 @@ class Date:
cal = " (%s)" % Date.calendar_names[self.calendar]
else:
cal = ""
if self.modifier == Date.MOD_TEXTONLY:
val = self.text