2007-09-11 Don Allingham <don@gramps-project.org>

* src/PageView.py: add some documentation



svn: r8962
This commit is contained in:
Don Allingham 2007-09-12 03:59:39 +00:00
parent fd5bb08aa3
commit 55d5734423
2 changed files with 207 additions and 130 deletions

View File

@ -1,3 +1,6 @@
2007-09-11 Don Allingham <don@gramps-project.org>
* src/PageView.py: add some documentation
2007-09-08 Benny Malengier <benny.malengier@gramps-project.org>
* src/PageView.py : cleanup
* src/QuickReports.py: fix error getting source handle

View File

@ -20,6 +20,10 @@
# $Id$
"""
Provide the base classes for GRAMPS' DataView classes
"""
#----------------------------------------------------------------
#
# python
@ -55,12 +59,17 @@ NAVIGATION_PERSON = 0
EMPTY_SEARCH = (0, '', False)
#----------------------------------------------------------------
#------------------------------------------------------------------------------
#
# PageView
#
#----------------------------------------------------------------
#------------------------------------------------------------------------------
class PageView:
"""
The PageView class is the base class for all Data Views in GRAMPS. All
Views should derive from this class. The ViewManager understands the public
interface of this class
"""
def __init__(self, title, dbstate, uistate):
self.title = title
@ -73,21 +82,29 @@ class PageView:
self.additional_uis = []
self.widget = None
self.model = None
self.ui = '<ui></ui>'
self.ui_def = '<ui></ui>'
self.dbstate.connect('no-database', self.disable_action_group)
self.dbstate.connect('database-changed', self.enable_action_group)
self.dirty = True
self.active = False
self.handle_col = 0
self.selection = None
self.func_list = {}
def call_function(self, key):
"""
Calls the function associated with the key value
"""
self.func_list.get(key)()
def post(self):
pass
def set_active(self):
"""
Called with the PageView is set as active. If the page is "dirty",
then we rebuild the data.
"""
self.active = True
if self.dirty:
self.uistate.set_busy_cursor(True)
@ -95,49 +112,97 @@ class PageView:
self.uistate.set_busy_cursor(False)
def set_inactive(self):
"""
Marks page as being active (currently displayed)
"""
self.active = False
def build_tree(self):
pass
"""
Rebuilds the current display. This must be overridden by the derived
class.
"""
raise NotImplementedError
def navigation_type(self):
"""
Indictates the navigation type. Currently, we only support navigation
for views that are Person centric.
"""
return NAVIGATION_NONE
def ui_definition(self):
return self.ui
"""
returns the XML UI definition for the UIManager
"""
return self.ui_def
def additional_ui_definitions(self):
"""
Returns any additional interfaces for the UIManager that the view
needs to define.
"""
return self.additional_uis
def disable_action_group(self):
"""
Turns off the visibility of the View's action group, if defined
"""
if self.action_group:
self.action_group.set_visible(False)
def enable_action_group(self, obj):
"""
Turns on the visibility of the View's action group, if defined
"""
if self.action_group:
self.action_group.set_visible(True)
def get_stock(self):
try:
return gtk.STOCK_MEDIA_MISSING
except AttributeError:
"""
Returns image associated with the view, which is used for the
icon for the button.
"""
return gtk.STOCK_MISSING_IMAGE
def get_title(self):
"""
Returns the title of the view. This is used to define the text for the
button, and for the tab label.
"""
return self.title
def get_display(self):
"""
Builds the graphical display, returning the top level widget.
"""
if not self.widget:
self.widget = self.build_widget()
return self.widget
def build_widget(self):
assert False
"""
Builds the container widget for the interface. Must be overridden by the
the base class. Returns a gtk container widget.
"""
raise NotImplementedError
def define_actions(self):
assert False
"""
Defines the UIManager actions. Called by the ViewManager to set up the
View. The user typically defines self.action_list and
self.action_toggle_list in this function.
def _build_action_group(self):
Derived classes must override this function.
"""
raise NotImplementedError
def __build_action_group(self):
"""
Creates an UIManager ActionGroup from the values in self.action_list
and self.action_toggle_list. The user should define these in
self.define_actions
"""
self.action_group = gtk.ActionGroup(self.title)
if len(self.action_list) > 0:
self.action_group.add_actions(self.action_list)
@ -155,7 +220,7 @@ class PageView:
def get_actions(self):
if not self.action_group:
self._build_action_group()
self.__build_action_group()
return [self.action_group] + self.additional_action_groups
def add_action_group(self, group):
@ -165,13 +230,22 @@ class PageView:
self.uistate.clear_filter_results()
def edit(self, obj):
pass
"""
Template function to allow the editing of the selected object
"""
raise NotImplementedError
def remove(self, obj):
pass
"""
Template function to allow the removal of the selected object
"""
raise NotImplementedError
def add(self, obj):
pass
"""
Template function to allow the adding of a new object
"""
raise NotImplementedError
def key_press(self, obj, event):
#act if no modifier, and allow Num Lock as MOD2_MASK
@ -181,8 +255,8 @@ class PageView:
return True
return False
def blist(self,store,path,iter,sel_list):
handle = store.get_value(iter,self.handle_col)
def blist(self, store, path, node, sel_list):
handle = store.get_value(node, self.handle_col)
sel_list.append(handle)
def selected_handles(self):
@ -206,7 +280,7 @@ class BookMarkView(PageView):
self.setup_bookmarks(bookmarks)
def goto_handle(self, obj):
pass
raise NotImplementedError
def setup_bookmarks(self, bookmarks):
self.bookmarks = self.bm_type(
@ -379,7 +453,7 @@ class PersonNavView(BookMarkView):
FilterEditor('Person', const.CUSTOM_FILTERS,
self.dbstate, self.uistate)
except Errors.WindowActiveError:
pass
return
def fwd_clicked(self, obj, step=1):
hobj = self.uistate.phistory
@ -523,7 +597,8 @@ class ListView(BookMarkView):
dialog = gtk.Dialog(_('Jump to by GRAMPS ID'), None,
gtk.DIALOG_NO_SEPARATOR)
dialog.set_border_width(12)
label = gtk.Label('<span weight="bold" size="larger">%s</span>' % _('Jump to by GRAMPS ID'))
label = gtk.Label('<span weight="bold" size="larger">%s</span>' %
_('Jump to by GRAMPS ID'))
label.set_use_markup(True)
dialog.vbox.add(label)
dialog.vbox.set_spacing(10)
@ -688,7 +763,6 @@ class ListView(BookMarkView):
sort_map=self.column_order())
self.list.set_model(self.model)
colmap = self.column_order()
if handle:
path = self.model.on_get_path(handle)
@ -770,7 +844,7 @@ class ListView(BookMarkView):
FilterEditor(self.FILTER_TYPE , const.CUSTOM_FILTERS,
self.dbstate, self.uistate)
except Errors.WindowActiveError:
pass
return
def change_db(self, db):
for sig in self.signal_map:
@ -839,7 +913,7 @@ class ListView(BookMarkView):
callback=self.filter_toggle_action)
def column_editor(self, obj):
pass
raise NotImplementedError
def button_press(self, obj, event):
from QuickReports import create_quickreport_menu