* src/Selectors/_Select*.py: Subclass from BaseSelector.

* src/Selectors/Makefile.am: Ship new file.
	* src/Selectors/_BaseSelector.py: Add new file.



svn: r6673
This commit is contained in:
Alex Roitman 2006-05-15 20:50:25 +00:00
parent a97e7e2abd
commit 8884528ee1
10 changed files with 233 additions and 332 deletions

View File

@ -8,6 +8,10 @@
* src/Selectors/_SelectPerson.py: cleaner interface to filters * src/Selectors/_SelectPerson.py: cleaner interface to filters
2006-05-15 Alex Roitman <shura@gramps-project.org> 2006-05-15 Alex Roitman <shura@gramps-project.org>
* src/Selectors/_Select*.py: Subclass from BaseSelector.
* src/Selectors/Makefile.am: Ship new file.
* src/Selectors/_BaseSelector.py: Add new file.
* src/DataViews/_SourceView.py (edit,on_double_click): Catch exception. * src/DataViews/_SourceView.py (edit,on_double_click): Catch exception.
* configure.in: Generate new Makefile. * configure.in: Generate new Makefile.
* src/Makefile.am: adapt to new module. * src/Makefile.am: adapt to new module.

View File

@ -204,6 +204,7 @@ src/ObjectSelector/_PersonPreviewFrame.py
src/ObjectSelector/_PersonTreeFrame.py src/ObjectSelector/_PersonTreeFrame.py
src/ObjectSelector/_PreviewFrameBase.py src/ObjectSelector/_PreviewFrameBase.py
src/ObjectSelector/_TreeFrameBase.py src/ObjectSelector/_TreeFrameBase.py
src/Selectors/_BaseSelector.py
src/Selectors/_SelectEvent.py src/Selectors/_SelectEvent.py
src/Selectors/_SelectFamily.py src/Selectors/_SelectFamily.py
src/Selectors/_SelectObject.py src/Selectors/_SelectObject.py

View File

@ -7,6 +7,7 @@ pkgdatadir = $(datadir)/@PACKAGE@/Selectors
pkgdata_PYTHON = \ pkgdata_PYTHON = \
__init__.py \ __init__.py \
_BaseSelector.py \
_SelectEvent.py \ _SelectEvent.py \
_SelectFamily.py \ _SelectFamily.py \
_SelectObject.py \ _SelectObject.py \

View File

@ -0,0 +1,127 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2003-2006 Donald N. Allingham
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# $Id: SelectEvent.py 6155 2006-03-16 20:24:27Z rshura $
#-------------------------------------------------------------------------
#
# GTK/Gnome modules
#
#-------------------------------------------------------------------------
import gtk
import gtk.glade
#-------------------------------------------------------------------------
#
# gramps modules
#
#-------------------------------------------------------------------------
import const
import ListModel
import ManagedWindow
#-------------------------------------------------------------------------
#
# SelectEvent
#
#-------------------------------------------------------------------------
class BaseSelector(ManagedWindow.ManagedWindow):
def __init__(self, dbstate, uistate, track, title):
self.title = title
ManagedWindow.ManagedWindow.__init__(self, uistate, track, self)
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.set_window(window,title_label,self.title)
titles = self.get_column_titles() + [('',0,0)]
self.ncols = len(titles)
self.model = ListModel.ListModel(self.elist,titles)
self.redraw()
self.show()
def build_menu_names(self,obj):
return (self.title, None)
def redraw(self):
self.model.clear()
self.model.new_model()
cursor_func = self.get_cursor_func()
class_func = self.get_class_func()
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)
else:
return_value = None
self.close()
return return_value
else:
self.close()
return None
def get_column_titles(self):
# return [(_('Title'),4,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]
assert False, "Must be defined in the subclass"

View File

@ -32,99 +32,38 @@ __revision__ = "$Revision$"
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gettext import gettext as _ from gettext import gettext as _
#-------------------------------------------------------------------------
#
# GTK/Gnome modules
#
#-------------------------------------------------------------------------
import gtk
import gtk.glade
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# gramps modules # gramps modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import const
import ListModel
import DateHandler import DateHandler
import ManagedWindow from RelLib import Event
from _BaseSelector import BaseSelector
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# SelectEvent # SelectEvent
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class SelectEvent(ManagedWindow.ManagedWindow): class SelectEvent(BaseSelector):
"""
Selects an event from the list of available events
"""
def __init__(self, dbstate, uistate, track, title): def get_column_titles(self):
""" return [(_('Description'), 4, 250), (_('ID'), 1, 75),
Create an Event Selector, allowing the user to select on of the (_('Type'), 2, 75), (_('Date'), 3, 150) ]
events in the event list.
"""
self.title = title def get_from_handle_func(self):
ManagedWindow.ManagedWindow.__init__(self, uistate, track, self) return self.db.get_event_from_handle
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.set_window(window, title_label, self.title)
titles = [(_('Description'), 4, 250), (_('ID'), 1, 75),
(_('Type'), 2, 75), (_('Date'), 3, 150), ('', 4, 0) ]
self.ncols = len(titles)
self.model = ListModel.ListModel(self.elist, titles)
self.redraw()
self.show()
def build_menu_names(self,obj):
return (self.title, None)
def redraw(self):
"""
Redraws the event list
"""
self.model.clear() def get_cursor_func(self):
self.model.new_model() return self.db.get_event_cursor
for handle in self.db.get_event_handles(): def get_class_func(self):
event = self.db.get_event_from_handle(handle) return Event
desc = event.get_description()
name = str(event.get_type())
the_id = event.get_gramps_id()
date = DateHandler.get_date(event)
self.model.add([desc, the_id, name, date], handle)
self.model.connect_model() def get_model_row_data(self,obj):
desc = obj.get_description()
def run(self): the_id = obj.get_gramps_id()
""" name = str(obj.get_type())
Runs te dialog, returning None if the event was not selected, date = DateHandler.get_date(obj)
or the event that was selected. return [desc, the_id, name, date]
"""
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[4]
return_value = self.db.get_event_from_handle(handle)
else:
return_value = None
self.close()
return return_value
else:
self.close()
return None

View File

@ -1,7 +1,7 @@
# #
# Gramps - a GTK+/GNOME based genealogy program # Gramps - a GTK+/GNOME based genealogy program
# #
# Copyright (C) 2003-2004 Donald N. Allingham # Copyright (C) 2003-2006 Donald N. Allingham
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by

View File

@ -44,90 +44,51 @@ from gettext import gettext as _
# GTK/Gnome modules # GTK/Gnome modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gtk.gdk import INTERP_BILINEAR
import gtk
import gtk.glade
import gtk.gdk
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# gramps modules # gramps modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import const from ImgManip import get_thumb_from_obj
import ListModel from Mime import get_description
import ImgManip from ListModel import IMAGE
import Mime from RelLib import MediaObject
import ManagedWindow from _BaseSelector import BaseSelector
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# SelectPerson # SelectObject
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class SelectObject(ManagedWindow.ManagedWindow): class SelectObject(BaseSelector):
def __init__(self, dbstate, uistate, track, title): def get_column_titles(self):
self.title = title return [(_('Preview'),0,50,IMAGE),
ManagedWindow.ManagedWindow.__init__(self, uistate, track, self) (_('Title'),1,150),
(_('ID'),2,50),
(_('Type'),3,70)]
self.db = dbstate.db def get_from_handle_func(self):
self.glade = gtk.glade.XML(const.gladeFile,"select_person","gramps") return self.db.get_object_from_handle
window = self.glade.get_widget('select_person')
title_label = self.glade.get_widget('object_title')
self.object_tree = self.glade.get_widget('plist')
self.set_window(window,title_label,self.title)
titles = [
(_('Preview'),0,50,ListModel.IMAGE),
(_('Title'),1,150),
(_('ID'),2,50),
(_('Type'),3,70),
('',4,0)
]
self.ncols = len(titles) def get_cursor_func(self):
return self.db.get_media_cursor
self.object_model = ListModel.ListModel(self.object_tree,titles) def get_class_func(self):
self.selection = self.object_tree.get_selection() return MediaObject
self.redraw() def get_model_row_data(self,obj):
self.show() 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 build_menu_names(self,obj): def close(self,*obj):
return (self.title, None) # needed to collect garbage on closing
BaseSelector.close(self,*obj)
def redraw(self): gc.collect()
self.object_model.clear()
self.object_model.new_model()
for key in self.db.get_media_object_handles():
obj = self.db.get_object_from_handle(key)
title = obj.get_description()
the_type = Mime.get_description(obj.get_mime_type())
pixbuf = ImgManip.get_thumb_from_obj(obj)
pixbuf = pixbuf.scale_simple(pixbuf.get_width()/2,
pixbuf.get_height()/2,
gtk.gdk.INTERP_BILINEAR)
self.object_model.add([pixbuf,title,obj.get_gramps_id(),the_type],key)
self.object_model.connect_model()
def run(self):
val = self.window.run()
if val == gtk.RESPONSE_OK:
store,node = self.object_model.get_selected()
if node:
data = self.object_model.get_data(node,range(self.ncols))
handle = data[4]
return_value = self.db.get_object_from_handle(handle)
else:
return_value = None
self.close()
gc.collect()
return return_value
else:
self.close()
gc.collect()
return None

View File

@ -27,78 +27,34 @@
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gettext import gettext as _ from gettext import gettext as _
#-------------------------------------------------------------------------
#
# GTK/Gnome modules
#
#-------------------------------------------------------------------------
import gtk
import gtk.glade
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# gramps modules # gramps modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import const from RelLib import Place
import ListModel from _BaseSelector import BaseSelector
import ManagedWindow
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# SelectEvent # SelectPlace
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class SelectPlace(ManagedWindow.ManagedWindow): class SelectPlace(BaseSelector):
def __init__(self, dbstate, uistate, track, title): def get_column_titles(self):
self.title = title return [(_('Title'),4,350), (_('ID'),1,50)]
ManagedWindow.ManagedWindow.__init__(self, uistate, track, self)
self.db = dbstate.db def get_from_handle_func(self):
self.glade = gtk.glade.XML(const.gladeFile,"select_person","gramps") return self.db.get_place_from_handle
window = self.glade.get_widget('select_person')
title_label = self.glade.get_widget('title') def get_cursor_func(self):
self.elist = self.glade.get_widget('plist') return self.db.get_place_cursor
self.set_window(window,title_label,self.title) def get_class_func(self):
return Place
titles = [(_('Title'),4,350), (_('ID'),1,50), ('',0,0)] def get_model_row_data(self,obj):
self.ncols = len(titles) name = obj.get_title()
the_id = obj.get_gramps_id()
self.model = ListModel.ListModel(self.elist,titles) return [name,the_id]
self.redraw()
self.show()
def build_menu_names(self,obj):
return (self.title, None)
def redraw(self):
self.model.clear()
self.model.new_model()
for handle in self.db.get_place_handles():
place = self.db.get_place_from_handle(handle)
desc = place.get_title()
the_id = place.get_gramps_id()
self.model.add([desc,the_id,handle])
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[2]
return_value = self.db.get_place_from_handle(handle)
else:
return_value = None
self.close()
return return_value
else:
self.close()
return None

View File

@ -27,78 +27,34 @@
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gettext import gettext as _ from gettext import gettext as _
#-------------------------------------------------------------------------
#
# GTK/Gnome modules
#
#-------------------------------------------------------------------------
import gtk
import gtk.glade
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# gramps modules # gramps modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import const from RelLib import Repository
import ListModel from _BaseSelector import BaseSelector
import ManagedWindow
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# SelectRepository # SelectRepository
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class SelectRepository(ManagedWindow.ManagedWindow): class SelectRepository(BaseSelector):
def __init__(self, dbstate, uistate, track, title): def get_column_titles(self):
self.title = title return [(_('Title'),4,350), (_('ID'),1,50)]
ManagedWindow.ManagedWindow.__init__(self, uistate, track, self)
self.db = dbstate.db def get_from_handle_func(self):
self.glade = gtk.glade.XML(const.gladeFile,"select_person","gramps") return self.db.get_repository_from_handle
window = self.glade.get_widget('select_person')
title_label = self.glade.get_widget('title') def get_cursor_func(self):
self.elist = self.glade.get_widget('plist') return self.db.get_repository_cursor
self.set_window(window,title_label,self.title) def get_class_func(self):
return Repository
titles = [(_('Title'),4,350), (_('ID'),1,50), ('',0,0)] def get_model_row_data(self,obj):
self.ncols = len(titles) name = obj.get_name()
the_id = obj.get_gramps_id()
self.model = ListModel.ListModel(self.elist,titles) return [name,the_id]
self.redraw()
self.show()
def build_menu_names(self,obj):
return (self.title, None)
def redraw(self):
self.model.clear()
self.model.new_model()
for handle in self.db.get_repository_handles():
repository = self.db.get_repository_from_handle(handle)
desc = repository.get_name()
the_id = repository.get_gramps_id()
self.model.add([desc,the_id,handle])
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[2]
return_value = self.db.get_repository_from_handle(handle)
else:
return_value = None
self.close()
return return_value
else:
self.close()
return None

View File

@ -27,78 +27,34 @@
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gettext import gettext as _ from gettext import gettext as _
#-------------------------------------------------------------------------
#
# GTK/Gnome modules
#
#-------------------------------------------------------------------------
import gtk
import gtk.glade
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# gramps modules # gramps modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import const from RelLib import Source
import ListModel from _BaseSelector import BaseSelector
import ManagedWindow
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# SelectEvent # SelectSource
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class SelectSource(ManagedWindow.ManagedWindow): class SelectSource(BaseSelector):
def __init__(self, dbstate, uistate, track, title): def get_column_titles(self):
self.title = title return [(_('Title'),4,350), (_('ID'),1,50)]
ManagedWindow.ManagedWindow.__init__(self, uistate, track, self)
self.db = dbstate.db def get_from_handle_func(self):
self.glade = gtk.glade.XML(const.gladeFile,"select_person","gramps") return self.db.get_source_from_handle
window = self.glade.get_widget('select_person')
title_label = self.glade.get_widget('title') def get_cursor_func(self):
self.elist = self.glade.get_widget('plist') return self.db.get_source_cursor
self.set_window(window,title_label,self.title) def get_class_func(self):
return Source
titles = [(_('Title'),4,350), (_('ID'),1,50), ('',0,0)] def get_model_row_data(self,obj):
self.ncols = len(titles) name = obj.get_title()
the_id = obj.get_gramps_id()
self.model = ListModel.ListModel(self.elist,titles) return [name,the_id]
self.redraw()
self.show()
def build_menu_names(self,obj):
return (self.title, None)
def redraw(self):
self.model.clear()
self.model.new_model()
for handle in self.db.get_source_handles():
source = self.db.get_source_from_handle(handle)
desc = source.get_title()
the_id = source.get_gramps_id()
self.model.add([desc,the_id,handle])
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[2]
return_value = self.db.get_source_from_handle(handle)
else:
return_value = None
self.close()
return return_value
else:
self.close()
return None