2008-01-30 Raphael Ackermann <raphael.ackermann@gmail.com>

* src/FilterEditor/_FilterEditor.py: pylint fixes and 
	work on 0001660: Title for all Edit Filter windows not translated correctly

svn: r9965
This commit is contained in:
Raphael Ackermann 2008-01-30 20:55:39 +00:00
parent e16c8973c5
commit 6374fa2163
2 changed files with 54 additions and 47 deletions

View File

@ -1,3 +1,7 @@
2008-01-30 Raphael Ackermann <raphael.ackermann@gmail.com>
* src/FilterEditor/_FilterEditor.py: pylint fixes and
work on 0001660: Title for all Edit Filter windows not translated correctly
2008-01-30 Raphael Ackermann <raphael.ackermann@gmail.com> 2008-01-30 Raphael Ackermann <raphael.ackermann@gmail.com>
* src/FilterEditor/_EditFilter.py: self.space --> self.namespace * src/FilterEditor/_EditFilter.py: self.space --> self.namespace
* src/FilterEditor/_FilterEditor.py: self.space --> self.namespace * src/FilterEditor/_FilterEditor.py: self.space --> self.namespace

View File

@ -58,12 +58,20 @@ from Filters.Rules._MatchesFilterBase import MatchesFilterBase
import ListModel import ListModel
import ManagedWindow import ManagedWindow
from QuestionDialog import QuestionDialog from QuestionDialog import QuestionDialog
from FilterEditor._EditFilter import EditFilter
# dictionary mapping FILTER_TYPE of views to Filter window name
_TITLES = {
'Person' : _("Person Filters"),
'Family' : _('Family Filters'),
'Event' : _('Event Filters'),
'Place' : _('Place Filters'),
'Source' : _('Source Filters'),
'MediaObject' : _('Media Object Filters'),
'Repository' : _('Repository Filters'),
'Note' : _('Note Filters'),
}
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
class FilterEditor(ManagedWindow.ManagedWindow): class FilterEditor(ManagedWindow.ManagedWindow):
def __init__(self, namespace, filterdb, dbstate, uistate): def __init__(self, namespace, filterdb, dbstate, uistate):
@ -88,7 +96,8 @@ class FilterEditor(ManagedWindow.ManagedWindow):
self.set_window(self.get_widget('filter_list'), self.set_window(self.get_widget('filter_list'),
self.get_widget('title'), self.get_widget('title'),
_('%s filters') % _(self.namespace)) _TITLES[self.namespace])
# _('%s filters') % _(self.namespace))
self.edit.connect('clicked', self.edit_filter) self.edit.connect('clicked', self.edit_filter)
self.clone.connect('clicked', self.clone_filter) self.clone.connect('clicked', self.clone_filter)
@ -99,25 +108,25 @@ class FilterEditor(ManagedWindow.ManagedWindow):
self.connect_button('close', self.close) self.connect_button('close', self.close)
self.connect_button('add', self.add_new_filter) self.connect_button('add', self.add_new_filter)
self.uistate.connect('filter-name-changed',self.clean_after_rename) self.uistate.connect('filter-name-changed', self.clean_after_rename)
self.clist = ListModel.ListModel( self.clist = ListModel.ListModel(
self.filter_list, self.filter_list,
[(_('Filter'),0,150),(_('Comment'),1,150)], [(_('Filter'), 0, 150), (_('Comment'), 1, 150)],
self.filter_select_row, self.filter_select_row,
self.edit_filter) self.edit_filter)
self.draw_filters() self.draw_filters()
self.show() self.show()
def build_menu_names(self, obj): def build_menu_names(self, obj):
return (_("Custom Filter Editor"), _("Custom Filter Editor")) return (_("Custom Filter Editor"), _("Custom Filter Editor"))
def help_clicked(self,obj): def help_clicked(self, obj):
"""Display the relevant portion of GRAMPS manual""" """Display the relevant portion of GRAMPS manual"""
GrampsDisplay.help('tools-util-cfe') GrampsDisplay.help('tools-util-cfe')
def filter_select_row(self,obj): def filter_select_row(self, obj):
store,node = self.clist.get_selected() store, node = self.clist.get_selected()
if node: if node:
self.edit.set_sensitive(True) self.edit.set_sensitive(True)
self.clone.set_sensitive(True) self.clone.set_sensitive(True)
@ -129,61 +138,55 @@ class FilterEditor(ManagedWindow.ManagedWindow):
self.delete.set_sensitive(False) self.delete.set_sensitive(False)
self.test.set_sensitive(False) self.test.set_sensitive(False)
def close(self,*obj): def close(self, *obj):
self.filterdb.save() self.filterdb.save()
reload_custom_filters() reload_custom_filters()
reload_system_filters() reload_system_filters()
self.uistate.emit('filters-changed',(self.namespace,)) self.uistate.emit('filters-changed', (self.namespace,))
ManagedWindow.ManagedWindow.close(self,*obj) ManagedWindow.ManagedWindow.close(self, *obj)
def draw_filters(self): def draw_filters(self):
self.clist.clear() self.clist.clear()
for f in self.filterdb.get_filters(self.namespace): for f in self.filterdb.get_filters(self.namespace):
self.clist.add([f.get_name(),f.get_comment()],f) self.clist.add([f.get_name(), f.get_comment()], f)
def add_new_filter(self,obj):
from _EditFilter import EditFilter
def add_new_filter(self, obj):
the_filter = GenericFilterFactory(self.namespace)() the_filter = GenericFilterFactory(self.namespace)()
EditFilter(self.namespace, self.dbstate, self.uistate, self.track, EditFilter(self.namespace, self.dbstate, self.uistate, self.track,
the_filter, self.filterdb, self.draw_filters) the_filter, self.filterdb, self.draw_filters)
def edit_filter(self,obj): def edit_filter(self, obj):
store,node = self.clist.get_selected() store, node = self.clist.get_selected()
if node: if node:
from _EditFilter import EditFilter
gfilter = self.clist.get_object(node) gfilter = self.clist.get_object(node)
EditFilter(self.namespace, self.dbstate, self.uistate, self.track, EditFilter(self.namespace, self.dbstate, self.uistate, self.track,
gfilter, self.filterdb, self.draw_filters) gfilter, self.filterdb, self.draw_filters)
def clone_filter(self,obj): def clone_filter(self, obj):
store,node = self.clist.get_selected() store, node = self.clist.get_selected()
if node: if node:
from _EditFilter import EditFilter
old_filter = self.clist.get_object(node) old_filter = self.clist.get_object(node)
the_filter = GenericFilterFactory(self.namespace)(old_filter) the_filter = GenericFilterFactory(self.namespace)(old_filter)
the_filter.set_name('') the_filter.set_name('')
EditFilter(self.namespace, self.dbstate, self.uistate, self.track, EditFilter(self.namespace, self.dbstate, self.uistate, self.track,
the_filter, self.filterdb, self.draw_filters) the_filter, self.filterdb, self.draw_filters)
def test_clicked(self,obj): def test_clicked(self, obj):
store,node = self.clist.get_selected() store, node = self.clist.get_selected()
if node: if node:
from _ShowResults import ShowResults from FilterEditor._ShowResults import ShowResults
filt = self.clist.get_object(node) filt = self.clist.get_object(node)
handle_list = filt.apply(self.db,self.get_all_handles()) handle_list = filt.apply(self.db, self.get_all_handles())
ShowResults(self.db, self.uistate, self.track, handle_list, ShowResults(self.db, self.uistate, self.track, handle_list,
filt.get_name(),self.namespace) filt.get_name(),self.namespace)
def delete_filter(self,obj): def delete_filter(self, obj):
store,node = self.clist.get_selected() store, node = self.clist.get_selected()
if node: if node:
gfilter = self.clist.get_object(node) gfilter = self.clist.get_object(node)
name = gfilter.get_name() name = gfilter.get_name()
if self.check_recursive_filters(self.namespace,name): if self.check_recursive_filters(self.namespace, name):
QuestionDialog( _('Delete Filter?'), QuestionDialog( _('Delete Filter?'),
_('This filter is currently being used ' _('This filter is currently being used '
'as the base for other filters. Deleting' 'as the base for other filters. Deleting'
@ -196,23 +199,23 @@ class FilterEditor(ManagedWindow.ManagedWindow):
self._do_delete_selected_filter() self._do_delete_selected_filter()
def _do_delete_selected_filter(self): def _do_delete_selected_filter(self):
store,node = self.clist.get_selected() store, node = self.clist.get_selected()
if node: if node:
gfilter = self.clist.get_object(node) gfilter = self.clist.get_object(node)
self._do_delete_filter(self.namespace,gfilter) self._do_delete_filter(self.namespace, gfilter)
self.draw_filters() self.draw_filters()
def _do_delete_filter(self,space,gfilter): def _do_delete_filter(self, space, gfilter):
# Find everything we need to remove # Find everything we need to remove
filter_set = set() filter_set = set()
self._find_dependent_filters(space,gfilter,filter_set) self._find_dependent_filters(space, gfilter, filter_set)
# Remove what we found # Remove what we found
filters = self.filterdb.get_filters(space) filters = self.filterdb.get_filters(space)
for the_filter in filter_set: for the_filter in filter_set:
filters.remove(the_filter) filters.remove(the_filter)
def _find_dependent_filters(self,space,gfilter,filter_set): def _find_dependent_filters(self, space, gfilter, filter_set):
""" """
This method recursively calls itself to find all filters that This method recursively calls itself to find all filters that
depend on the given filter, either directly through one of the rules, depend on the given filter, either directly through one of the rules,
@ -225,9 +228,9 @@ class FilterEditor(ManagedWindow.ManagedWindow):
for the_filter in filters: for the_filter in filters:
for rule in the_filter.get_rules(): for rule in the_filter.get_rules():
values = rule.values() values = rule.values()
if issubclass(rule.__class__,MatchesFilterBase) \ if issubclass(rule.__class__, MatchesFilterBase) \
and (name in values): and (name in values):
self._find_dependent_filters(space,the_filter,filter_set) self._find_dependent_filters(space, the_filter, filter_set)
break break
# Add itself to the filter_set # Add itself to the filter_set
filter_set.add(gfilter) filter_set.add(gfilter)
@ -250,7 +253,7 @@ class FilterEditor(ManagedWindow.ManagedWindow):
elif self.namespace == 'Note': elif self.namespace == 'Note':
return self.db.get_note_handles() return self.db.get_note_handles()
def clean_after_rename(self,space,old_name,new_name): def clean_after_rename(self, space, old_name, new_name):
if old_name == "": if old_name == "":
return return
@ -260,16 +263,16 @@ class FilterEditor(ManagedWindow.ManagedWindow):
for the_filter in self.filterdb.get_filters(space): for the_filter in self.filterdb.get_filters(space):
for rule in the_filter.get_rules(): for rule in the_filter.get_rules():
values = rule.values() values = rule.values()
if issubclass(rule.__class__,MatchesFilterBase) \ if issubclass(rule.__class__, MatchesFilterBase) \
and (old_name in values): and (old_name in values):
ind = values.index(old_name) ind = values.index(old_name)
values[ind] = new_name values[ind] = new_name
def check_recursive_filters(self,space,name): def check_recursive_filters(self, space, name):
for the_filter in self.filterdb.get_filters(space): for the_filter in self.filterdb.get_filters(space):
for rule in the_filter.get_rules(): for rule in the_filter.get_rules():
values = rule.values() values = rule.values()
if issubclass(rule.__class__,MatchesFilterBase) \ if issubclass(rule.__class__, MatchesFilterBase) \
and (name in values): and (name in values):
return True return True
return False return False