2006-05-16 Alex Roitman <shura@gramps-project.org>
* src/Editors/_EditLdsOrd.py: Adapt to new selector. * src/DisplayTabs/_SourceEmbedList.py: Adapt to new selector. * src/DisplayTabs/_EventEmbedList.py: Adapt to new selector. * src/DisplayTabs/_GalleryTab.py: Adapt to new selector. * src/Selectors/_BaseSelector.py: Use DisplaModel models. * src/Selectors/_SelectRepository.py: Use DisplaModel models. * src/Selectors/_SelectSource.py: Use DisplaModel models. * src/Selectors/_SelectEvent.py: Use DisplaModel models. * src/Selectors/_SelectFamily.py: Use DisplaModel models. * src/Selectors/_SelectPlace.py: Use DisplaModel models. * src/Selectors/_SelectObject.py: Use DisplaModel models. svn: r6687
This commit is contained in:
parent
3b894e16dd
commit
a90a6fb15f
13
ChangeLog
13
ChangeLog
@ -1,3 +1,16 @@
|
||||
2006-05-16 Alex Roitman <shura@gramps-project.org>
|
||||
* src/Editors/_EditLdsOrd.py: Adapt to new selector.
|
||||
* src/DisplayTabs/_SourceEmbedList.py: Adapt to new selector.
|
||||
* src/DisplayTabs/_EventEmbedList.py: Adapt to new selector.
|
||||
* src/DisplayTabs/_GalleryTab.py: Adapt to new selector.
|
||||
* src/Selectors/_BaseSelector.py: Use DisplaModel models.
|
||||
* src/Selectors/_SelectRepository.py: Use DisplaModel models.
|
||||
* src/Selectors/_SelectSource.py: Use DisplaModel models.
|
||||
* src/Selectors/_SelectEvent.py: Use DisplaModel models.
|
||||
* src/Selectors/_SelectFamily.py: Use DisplaModel models.
|
||||
* src/Selectors/_SelectPlace.py: Use DisplaModel models.
|
||||
* src/Selectors/_SelectObject.py: Use DisplaModel models.
|
||||
|
||||
2006-05-16 Don Allingham <don@gramps-project.org>
|
||||
* src/Editors/_EditEvent.py: start of SelectPlace integration
|
||||
* src/glade/gramps.glade: start of SelectPlace integration
|
||||
|
@ -117,8 +117,7 @@ class EventEmbedList(EmbeddedList):
|
||||
from Selectors import selector_factory
|
||||
SelectEvent = selector_factory('Event')
|
||||
|
||||
sel = SelectEvent(self.dbstate,self.uistate,self.track,
|
||||
_("Select event"))
|
||||
sel = SelectEvent(self.dbstate,self.uistate,self.track)
|
||||
event = sel.run()
|
||||
if event:
|
||||
try:
|
||||
|
@ -220,8 +220,7 @@ class GalleryTab(ButtonTab):
|
||||
from Selectors import selector_factory
|
||||
SelectObject = selector_factory('MediaObject')
|
||||
|
||||
sel = SelectObject(self.dbstate,self.uistate,self.track,
|
||||
_("Select media"))
|
||||
sel = SelectObject(self.dbstate,self.uistate,self.track)
|
||||
src = sel.run()
|
||||
if src:
|
||||
sref = RelLib.MediaRef()
|
||||
|
@ -98,11 +98,7 @@ class SourceEmbedList(EmbeddedList):
|
||||
from Selectors import selector_factory
|
||||
SelectSource = selector_factory('Source')
|
||||
|
||||
sel = SelectSource(
|
||||
self.dbstate,
|
||||
self.uistate,
|
||||
self.track,
|
||||
_("Select source"))
|
||||
sel = SelectSource(self.dbstate,self.uistate,self.track)
|
||||
|
||||
src = sel.run()
|
||||
if src:
|
||||
|
@ -220,7 +220,7 @@ class EditLdsOrd(EditSecondary):
|
||||
from Selectors import selector_factory
|
||||
SelectFamily = selector_factory('Family')
|
||||
|
||||
dialog = SelectFamily(self.dbstate.db, _('Select Family'))
|
||||
dialog = SelectFamily(self.dbstate,self.uistate,self.track)
|
||||
family = dialog.run()
|
||||
if family:
|
||||
self.obj.set_family_handle(family.handle)
|
||||
|
@ -25,9 +25,9 @@
|
||||
# GTK/Gnome modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
|
||||
import gtk
|
||||
import gtk.glade
|
||||
import pango
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
@ -35,7 +35,6 @@ import gtk.glade
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import const
|
||||
import ListModel
|
||||
import ManagedWindow
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
@ -44,84 +43,92 @@ import ManagedWindow
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
class BaseSelector(ManagedWindow.ManagedWindow):
|
||||
NONE = -1
|
||||
TEXT = 0
|
||||
MARKUP = 1
|
||||
IMAGE = 2
|
||||
|
||||
def __init__(self, dbstate, uistate, track=[], filter=None, skip=[]):
|
||||
self.title = self.get_window_title()
|
||||
|
||||
def __init__(self, dbstate, uistate, track, title):
|
||||
self.title = title
|
||||
ManagedWindow.ManagedWindow.__init__(self, uistate, track, self)
|
||||
|
||||
self.renderer = gtk.CellRendererText()
|
||||
self.renderer.set_property('ellipsize',pango.ELLIPSIZE_END)
|
||||
|
||||
self.db = dbstate.db
|
||||
self.glade = gtk.glade.XML(const.gladeFile,"select_person","gramps")
|
||||
window = self.glade.get_widget('select_person')
|
||||
title_label = self.glade.get_widget('title')
|
||||
self.elist = self.glade.get_widget('plist')
|
||||
self.tree = self.glade.get_widget('plist')
|
||||
|
||||
self.set_window(window,title_label,self.title)
|
||||
|
||||
titles = self.get_column_titles() + [('',0,0)]
|
||||
self.ncols = len(titles)
|
||||
self.model = self.get_model_class()(self.db)
|
||||
self.selection = self.tree.get_selection()
|
||||
|
||||
self.model = ListModel.ListModel(self.elist,titles)
|
||||
|
||||
self.redraw()
|
||||
# self.redraw()
|
||||
self.tree.set_model(self.model)
|
||||
self.add_columns(self.tree)
|
||||
self.show()
|
||||
|
||||
def add_columns(self,tree):
|
||||
tree.set_fixed_height_mode(True)
|
||||
titles = self.get_column_titles()
|
||||
for ix in range(len(titles)):
|
||||
item = titles[ix]
|
||||
if item[2] == BaseSelector.NONE:
|
||||
continue
|
||||
elif item[2] == BaseSelector.TEXT:
|
||||
column = gtk.TreeViewColumn(item[0],self.renderer,text=ix)
|
||||
elif item[2] == BaseSelector.MARKUP:
|
||||
column = gtk.TreeViewColumn(item[0],self.renderer,markup=ix)
|
||||
column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
|
||||
column.set_fixed_width(item[1])
|
||||
tree.append_column(column)
|
||||
|
||||
def build_menu_names(self,obj):
|
||||
return (self.title, None)
|
||||
|
||||
def redraw(self):
|
||||
self.model.clear()
|
||||
self.model.new_model()
|
||||
def get_selected_ids(self):
|
||||
mlist = []
|
||||
self.selection.selected_foreach(self.select_function,mlist)
|
||||
return mlist
|
||||
|
||||
cursor_func = self.get_cursor_func()
|
||||
class_func = self.get_class_func()
|
||||
def select_function(self,store,path,iter,id_list):
|
||||
handle_column = self.get_handle_column()
|
||||
id_list.append(self.model.get_value(iter,handle_column))
|
||||
|
||||
cursor = cursor_func()
|
||||
item = cursor.first()
|
||||
while item:
|
||||
(handle,data) = item
|
||||
obj = class_func()
|
||||
obj.unserialize(data)
|
||||
model_row_data = self.get_model_row_data(obj)
|
||||
self.model.add(model_row_data,handle)
|
||||
item = cursor.next()
|
||||
cursor.close()
|
||||
self.model.connect_model()
|
||||
|
||||
def run(self):
|
||||
val = self.window.run()
|
||||
|
||||
if val == gtk.RESPONSE_OK:
|
||||
store,node = self.model.get_selected()
|
||||
if node:
|
||||
data = self.model.get_data(node,range(self.ncols))
|
||||
handle = data[-1]
|
||||
return_value = self.get_from_handle_func()(handle)
|
||||
id_list = self.get_selected_ids()
|
||||
self.close()
|
||||
if id_list and id_list[0]:
|
||||
return_value = self.get_from_handle_func()(id_list[0])
|
||||
else:
|
||||
return_value = None
|
||||
self.close()
|
||||
return return_value
|
||||
else:
|
||||
self.close()
|
||||
return None
|
||||
|
||||
def get_window_title(self):
|
||||
# return _("Select something")
|
||||
assert False, "Must be defined in the subclass"
|
||||
|
||||
def get_model_class(self):
|
||||
# return SourceModel
|
||||
assert False, "Must be defined in the subclass"
|
||||
|
||||
def get_column_titles(self):
|
||||
# return [(_('Title'),4,350), (_('ID'),1,50)]
|
||||
# return [(_('Title'),350,), (_('ID'),1,50)]
|
||||
assert False, "Must be defined in the subclass"
|
||||
|
||||
def get_from_handle_func(self):
|
||||
# return self.db.get_source_from_handle
|
||||
assert False, "Must be defined in the subclass"
|
||||
|
||||
def get_cursor_func(self):
|
||||
# return self.db.get_source_cursor
|
||||
assert False, "Must be defined in the subclass"
|
||||
|
||||
def get_class_func(self):
|
||||
# return RelLib.Source
|
||||
assert False, "Must be defined in the subclass"
|
||||
|
||||
def get_model_row_data(self,obj):
|
||||
# name = obj.get_title()
|
||||
# the_id = obj.get_gramps_id()
|
||||
# return [name,the_id]
|
||||
def get_handle_column(self):
|
||||
# return 3
|
||||
assert False, "Must be defined in the subclass"
|
||||
|
@ -37,8 +37,7 @@ from gettext import gettext as _
|
||||
# gramps modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import DateHandler
|
||||
from RelLib import Event
|
||||
from DisplayModels import EventModel
|
||||
from _BaseSelector import BaseSelector
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
@ -48,22 +47,22 @@ from _BaseSelector import BaseSelector
|
||||
#-------------------------------------------------------------------------
|
||||
class SelectEvent(BaseSelector):
|
||||
|
||||
def get_window_title(self):
|
||||
return _("Select Event")
|
||||
|
||||
def get_model_class(self):
|
||||
return EventModel
|
||||
|
||||
def get_column_titles(self):
|
||||
return [(_('Description'), 4, 250), (_('ID'), 1, 75),
|
||||
(_('Type'), 2, 75), (_('Date'), 3, 150) ]
|
||||
return [
|
||||
(_('Description'), 250, BaseSelector.TEXT),
|
||||
(_('ID'), 75, BaseSelector.TEXT),
|
||||
(_('Type'), 75, BaseSelector.TEXT),
|
||||
(_('Date'), 150, BaseSelector.TEXT)
|
||||
]
|
||||
|
||||
def get_from_handle_func(self):
|
||||
return self.db.get_event_from_handle
|
||||
|
||||
def get_cursor_func(self):
|
||||
return self.db.get_event_cursor
|
||||
|
||||
def get_class_func(self):
|
||||
return Event
|
||||
|
||||
def get_model_row_data(self,obj):
|
||||
desc = obj.get_description()
|
||||
the_id = obj.get_gramps_id()
|
||||
name = str(obj.get_type())
|
||||
date = DateHandler.get_date(obj)
|
||||
return [desc, the_id, name, date]
|
||||
def get_handle_column(self):
|
||||
return 7
|
||||
|
@ -27,93 +27,36 @@
|
||||
#-------------------------------------------------------------------------
|
||||
from gettext import gettext as _
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# GTK/Gnome modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import gtk
|
||||
import gtk.glade
|
||||
import pango
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# gramps modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import const
|
||||
import Utils
|
||||
import DisplayModels
|
||||
import ManagedWindow
|
||||
from DisplayModels import FamilyModel
|
||||
from _BaseSelector import BaseSelector
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# SelectFamily
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
class SelectFamily(ManagedWindow.ManagedWindow):
|
||||
class SelectFamily(BaseSelector):
|
||||
|
||||
def __init__(self, dbstate, uistate, filter=None, skip=[]):
|
||||
|
||||
ManagedWindow.ManagedWindow.__init__(self, uistate, [], self)
|
||||
def get_window_title(self):
|
||||
return _("Select Family")
|
||||
|
||||
self.renderer = gtk.CellRendererText()
|
||||
self.renderer.set_property('ellipsize',pango.ELLIPSIZE_END)
|
||||
self.db = dbstate.db
|
||||
self.glade = gtk.glade.XML(const.gladeFile,"select_person","gramps")
|
||||
self.plist = self.glade.get_widget('plist')
|
||||
self.notebook = self.glade.get_widget('notebook')
|
||||
def get_model_class(self):
|
||||
return FamilyModel
|
||||
|
||||
self.set_window(
|
||||
self.glade.get_widget('select_person'),
|
||||
self.glade.get_widget('title'),
|
||||
_('Select Family'))
|
||||
def get_column_titles(self):
|
||||
return [
|
||||
(_('ID'), 75, BaseSelector.TEXT),
|
||||
(_('Father'), 200, BaseSelector.TEXT),
|
||||
(_('Mother'), 200, BaseSelector.TEXT),
|
||||
]
|
||||
|
||||
self.model = DisplayModels.FamilyModel(self.db)
|
||||
|
||||
self.add_columns(self.plist)
|
||||
self.plist.set_model(self.model)
|
||||
self.show()
|
||||
|
||||
def add_columns(self,tree):
|
||||
column = gtk.TreeViewColumn(_('ID'), self.renderer, text=0)
|
||||
column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
|
||||
column.set_fixed_width(75)
|
||||
tree.append_column(column)
|
||||
|
||||
tree.set_fixed_height_mode(True)
|
||||
column = gtk.TreeViewColumn(_('Father'), self.renderer, text=1)
|
||||
column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
|
||||
column.set_fixed_width(200)
|
||||
tree.append_column(column)
|
||||
|
||||
column = gtk.TreeViewColumn(_('Mother'), self.renderer, text=2)
|
||||
column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
|
||||
column.set_fixed_width(200)
|
||||
tree.append_column(column)
|
||||
def get_from_handle_func(self):
|
||||
return self.db.get_family_from_handle
|
||||
|
||||
def select_function(self,store,path,iter,id_list):
|
||||
id_list.append(self.model.get_value(iter,5))
|
||||
|
||||
|
||||
def build_menu_names(self,obj):
|
||||
return (_('Select Family'), None)
|
||||
|
||||
def get_selected_ids(self):
|
||||
mlist = []
|
||||
self.plist.get_selection().selected_foreach(self.select_function,mlist)
|
||||
return mlist
|
||||
|
||||
def run(self):
|
||||
val = self.window.run()
|
||||
if val == gtk.RESPONSE_OK:
|
||||
idlist = self.get_selected_ids()
|
||||
self.close()
|
||||
if idlist and idlist[0]:
|
||||
return_value = self.db.get_family_from_handle(idlist[0])
|
||||
else:
|
||||
return_value = None
|
||||
return return_value
|
||||
else:
|
||||
self.close()
|
||||
return None
|
||||
def get_handle_column(self):
|
||||
return 5
|
||||
|
@ -25,13 +25,6 @@
|
||||
# largely based on the MediaView and SelectPerson by Don Allingham
|
||||
#
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# general modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import gc
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# internationalization
|
||||
@ -39,22 +32,12 @@ import gc
|
||||
#-------------------------------------------------------------------------
|
||||
from gettext import gettext as _
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# GTK/Gnome modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from gtk.gdk import INTERP_BILINEAR
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# gramps modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from ImgManip import get_thumb_from_obj
|
||||
from Mime import get_description
|
||||
from ListModel import IMAGE
|
||||
from RelLib import MediaObject
|
||||
from DisplayModels import MediaModel
|
||||
from _BaseSelector import BaseSelector
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
@ -64,31 +47,21 @@ from _BaseSelector import BaseSelector
|
||||
#-------------------------------------------------------------------------
|
||||
class SelectObject(BaseSelector):
|
||||
|
||||
def get_column_titles(self):
|
||||
return [(_('Preview'),0,50,IMAGE),
|
||||
(_('Title'),1,150),
|
||||
(_('ID'),2,50),
|
||||
(_('Type'),3,70)]
|
||||
def get_window_title(self):
|
||||
return _("Select Media Object")
|
||||
|
||||
def get_model_class(self):
|
||||
return MediaModel
|
||||
|
||||
def get_from_handle_func(self):
|
||||
return self.db.get_object_from_handle
|
||||
|
||||
def get_cursor_func(self):
|
||||
return self.db.get_media_cursor
|
||||
def get_handle_column(self):
|
||||
return 6
|
||||
|
||||
def get_class_func(self):
|
||||
return MediaObject
|
||||
|
||||
def get_model_row_data(self,obj):
|
||||
title = obj.get_description()
|
||||
the_type = get_description(obj.get_mime_type())
|
||||
pixbuf = get_thumb_from_obj(obj)
|
||||
pixbuf = pixbuf.scale_simple(pixbuf.get_width()/2,
|
||||
pixbuf.get_height()/2,
|
||||
INTERP_BILINEAR)
|
||||
return [pixbuf,title,obj.get_gramps_id(),the_type]
|
||||
|
||||
def close(self,*obj):
|
||||
# needed to collect garbage on closing
|
||||
BaseSelector.close(self,*obj)
|
||||
gc.collect()
|
||||
def get_column_titles(self):
|
||||
return [
|
||||
(_('Title'), 350, BaseSelector.TEXT),
|
||||
(_('ID'), 75, BaseSelector.TEXT),
|
||||
(_('Type'), 75, BaseSelector.TEXT),
|
||||
]
|
||||
|
@ -32,7 +32,7 @@ from gettext import gettext as _
|
||||
# gramps modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from RelLib import Place
|
||||
from DisplayModels import PlaceModel
|
||||
from _BaseSelector import BaseSelector
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
@ -42,19 +42,20 @@ from _BaseSelector import BaseSelector
|
||||
#-------------------------------------------------------------------------
|
||||
class SelectPlace(BaseSelector):
|
||||
|
||||
def get_window_title(self):
|
||||
return _("Select Place")
|
||||
|
||||
def get_model_class(self):
|
||||
return PlaceModel
|
||||
|
||||
def get_column_titles(self):
|
||||
return [(_('Title'),4,350), (_('ID'),1,50)]
|
||||
return [
|
||||
(_('Title'), 350, BaseSelector.TEXT),
|
||||
(_('ID'), 75, BaseSelector.TEXT)
|
||||
]
|
||||
|
||||
def get_from_handle_func(self):
|
||||
return self.db.get_place_from_handle
|
||||
|
||||
def get_cursor_func(self):
|
||||
return self.db.get_place_cursor
|
||||
|
||||
def get_class_func(self):
|
||||
return Place
|
||||
|
||||
def get_model_row_data(self,obj):
|
||||
name = obj.get_title()
|
||||
the_id = obj.get_gramps_id()
|
||||
return [name,the_id]
|
||||
def get_handle_column(self):
|
||||
return 11
|
||||
|
@ -32,7 +32,7 @@ from gettext import gettext as _
|
||||
# gramps modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from RelLib import Repository
|
||||
from DisplayModels import RepositoryModel
|
||||
from _BaseSelector import BaseSelector
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
@ -42,19 +42,20 @@ from _BaseSelector import BaseSelector
|
||||
#-------------------------------------------------------------------------
|
||||
class SelectRepository(BaseSelector):
|
||||
|
||||
def get_window_title(self):
|
||||
return _("Select Repository")
|
||||
|
||||
def get_model_class(self):
|
||||
return RepositoryModel
|
||||
|
||||
def get_column_titles(self):
|
||||
return [(_('Title'),4,350), (_('ID'),1,50)]
|
||||
return [
|
||||
(_('Title'), 350, BaseSelector.TEXT),
|
||||
(_('ID'), 75, BaseSelector.TEXT)
|
||||
]
|
||||
|
||||
def get_handle_column(self):
|
||||
return 12
|
||||
|
||||
def get_from_handle_func(self):
|
||||
return self.db.get_repository_from_handle
|
||||
|
||||
def get_cursor_func(self):
|
||||
return self.db.get_repository_cursor
|
||||
|
||||
def get_class_func(self):
|
||||
return Repository
|
||||
|
||||
def get_model_row_data(self,obj):
|
||||
name = obj.get_name()
|
||||
the_id = obj.get_gramps_id()
|
||||
return [name,the_id]
|
||||
|
@ -32,7 +32,7 @@ from gettext import gettext as _
|
||||
# gramps modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from RelLib import Source
|
||||
from DisplayModels import SourceModel
|
||||
from _BaseSelector import BaseSelector
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
@ -42,19 +42,20 @@ from _BaseSelector import BaseSelector
|
||||
#-------------------------------------------------------------------------
|
||||
class SelectSource(BaseSelector):
|
||||
|
||||
def get_window_title(self):
|
||||
return _("Select Source")
|
||||
|
||||
def get_model_class(self):
|
||||
return SourceModel
|
||||
|
||||
def get_column_titles(self):
|
||||
return [(_('Title'),4,350), (_('ID'),1,50)]
|
||||
return [
|
||||
(_('Title'), 350, BaseSelector.TEXT),
|
||||
(_('ID'), 75, BaseSelector.TEXT)
|
||||
]
|
||||
|
||||
def get_from_handle_func(self):
|
||||
return self.db.get_source_from_handle
|
||||
|
||||
def get_cursor_func(self):
|
||||
return self.db.get_source_cursor
|
||||
|
||||
def get_class_func(self):
|
||||
return Source
|
||||
|
||||
def get_model_row_data(self,obj):
|
||||
name = obj.get_title()
|
||||
the_id = obj.get_gramps_id()
|
||||
return [name,the_id]
|
||||
def get_handle_column(self):
|
||||
return 6
|
||||
|
Loading…
Reference in New Issue
Block a user