Fixed date filters, allow for a reload plugin functionality

svn: r512
This commit is contained in:
Don Allingham 2001-10-27 14:10:07 +00:00
parent 3c10bc0a95
commit b697bde6de
6 changed files with 154 additions and 181 deletions

View File

@ -105,6 +105,15 @@ class Date:
self.stop = SingleDate() self.stop = SingleDate()
return self.get_stop_date().getDay() return self.get_stop_date().getDay()
def greater_than(self,other):
return compare_dates(self,other) > 0
def less_than(self,other):
return compare_dates(self,other) < 0
def equal_to(self,other):
return compare_dates(other) == 0
#-------------------------------------------------------------------- #--------------------------------------------------------------------
# #
# #
@ -347,7 +356,7 @@ class SingleDate:
# #
# #
#-------------------------------------------------------------------- #--------------------------------------------------------------------
def __cmp__(self,other): def my__cmp__(self,other):
if other == None: if other == None:
return 0 return 0
elif self.year != other.year: elif self.year != other.year:

View File

@ -56,18 +56,23 @@ _reports = []
_tools = [] _tools = []
_imports = [] _imports = []
_exports = [] _exports = []
_success = []
_failed = []
_attempt = []
_loaddir = []
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# #
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
OBJECT = "o"
DOCSTRING = "d" DOCSTRING = "d"
IMAGE = "i" IMAGE = "i"
TASK = "f" TASK = "f"
TITLE = "t" TITLE = "t"
pymod = re.compile(r"^(.*)\.py$")
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# #
@ -81,16 +86,34 @@ class ReportPlugins:
self.dialog = libglade.GladeXML(const.pluginsFile,"report") self.dialog = libglade.GladeXML(const.pluginsFile,"report")
self.dialog.signal_autoconnect({ self.dialog.signal_autoconnect({
"on_report_apply_clicked" : on_report_apply_clicked, "on_report_apply_clicked" : self.on_report_apply_clicked,
"on_report_ok_clicked" : on_report_apply_clicked, "on_report_ok_clicked" : self.on_report_apply_clicked,
"destroy_passed_object" : utils.destroy_passed_object "destroy_passed_object" : utils.destroy_passed_object
}) })
top = self.dialog.get_widget("report") top = self.dialog.get_widget("report")
top.set_data(OBJECT,self)
tree = self.dialog.get_widget("tree1") tree = self.dialog.get_widget("tree1")
self.run_tool = None self.run_tool = None
build_tree(tree,_reports,on_report_node_selected,self) build_tree(tree,_reports,self.on_report_node_selected)
def on_report_apply_clicked(self,obj):
utils.destroy_passed_object(obj)
if self.run_tool:
self.run_tool(self.db,self.active)
def on_report_node_selected(self,obj):
doc = obj.get_data(DOCSTRING)
xpm = obj.get_data(IMAGE)
title = obj.get_data(TITLE)
img = self.dialog.get_widget("image")
self.dialog.get_widget("description").set_text(doc)
i,m = create_pixmap_from_xpm_d(GtkWindow(),None,xpm)
img.set(i,m)
self.dialog.get_widget("report_title").set_text(title)
self.run_tool = obj.get_data(TASK)
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -105,28 +128,39 @@ class ToolPlugins:
self.dialog = libglade.GladeXML(const.pluginsFile,"pluginsel") self.dialog = libglade.GladeXML(const.pluginsFile,"pluginsel")
self.dialog.signal_autoconnect({ self.dialog.signal_autoconnect({
"on_apply_clicked" : on_apply_clicked, "on_apply_clicked" : self.on_apply_clicked,
"on_ok_clicked" : on_ok_clicked, "on_ok_clicked" : self.on_apply_clicked,
"destroy_passed_object" : utils.destroy_passed_object "destroy_passed_object" : utils.destroy_passed_object
}) })
top = self.dialog.get_widget("pluginsel") top = self.dialog.get_widget("pluginsel")
top.set_data(OBJECT,self)
tree = self.dialog.get_widget("tree") tree = self.dialog.get_widget("tree")
self.run_tool = None self.run_tool = None
build_tree(tree,_tools,on_node_selected,self) build_tree(tree,_tools,self.on_node_selected)
def on_apply_clicked(self,obj):
utils.destroy_passed_object(obj)
if self.run_tool:
self.run_tool(self.db,self.active,self.update)
def on_node_selected(self,obj):
doc = obj.get_data(DOCSTRING)
title = obj.get_data(TITLE)
self.dialog.get_widget("description").set_text(doc)
self.dialog.get_widget("pluginTitle").set_text(title)
self.run_tool = obj.get_data(TASK)
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# #
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
def build_tree(tree,list,task,obj): def build_tree(tree,list,task):
item_hash = {} item_hash = {}
for report in list: for report in list:
item = GtkTreeItem(report[2]) item = GtkTreeItem(report[2])
item.connect("select",task) item.connect("select",task)
item.set_data(OBJECT,obj)
item.set_data(TASK,report[0]) item.set_data(TASK,report[0])
item.set_data(TITLE,report[2]) item.set_data(TITLE,report[2])
item.set_data(DOCSTRING,report[3]) item.set_data(DOCSTRING,report[3])
@ -151,146 +185,84 @@ def build_tree(tree,list,task,obj):
item.show() item.show()
subtree.append(item) subtree.append(item)
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
def on_node_selected(obj):
myobj = obj.get_data(OBJECT)
doc = obj.get_data(DOCSTRING)
title = obj.get_data(TITLE)
myobj.dialog.get_widget("description").set_text(doc)
myobj.dialog.get_widget("pluginTitle").set_text(title)
myobj.run_tool = obj.get_data(TASK)
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
def on_report_node_selected(obj):
myobj = obj.get_data(OBJECT)
doc = obj.get_data(DOCSTRING)
xpm = obj.get_data(IMAGE)
title = obj.get_data(TITLE)
img = myobj.dialog.get_widget("image")
myobj.dialog.get_widget("description").set_text(doc)
i,m = create_pixmap_from_xpm_d(GtkWindow(),None,xpm)
img.set(i,m)
myobj.dialog.get_widget("report_title").set_text(title)
myobj.run_tool = obj.get_data(TASK)
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
def on_apply_clicked(obj):
myobj = obj.get_data(OBJECT)
utils.destroy_passed_object(obj)
if myobj.run_tool:
myobj.run_tool(myobj.db,myobj.active,myobj.update)
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
def on_report_apply_clicked(obj):
myobj = obj.get_data(OBJECT)
utils.destroy_passed_object(obj)
if myobj.run_tool:
myobj.run_tool(myobj.db,myobj.active)
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
def on_ok_clicked(obj):
on_apply_clicked(obj)
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# #
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
def load_plugins(dir): def load_plugins(dir):
pymod = re.compile(r"^(.*)\.py$") global _success,_failed,_attempt,_loaddir
if not os.path.isdir(dir): if not os.path.isdir(dir):
return return
if dir not in _loaddir:
_loaddir.append(dir)
sys.path.append(dir) sys.path.append(dir)
for file in os.listdir(dir): for file in os.listdir(dir):
name = os.path.split(file) name = os.path.split(file)
match = pymod.match(name[1]) match = pymod.match(name[1])
if not match: if not match:
continue continue
_attempt.append(file)
plugin = match.groups()[0] plugin = match.groups()[0]
try: try:
__import__(plugin) a = __import__(plugin)
_success.append(a)
except: except:
print _("Failed to load the module: %s") % plugin print _("Failed to load the module: %s") % plugin
import traceback import traceback
traceback.print_exc() traceback.print_exc()
_failed.append(plugin)
def reload_plugins(obj):
for plugin in _success:
try:
reload(plugin)
except:
print _("Failed to load the module: %s") % plugin
import traceback
traceback.print_exc()
_failed.append(plugin)
for plugin in _failed:
try:
__import__(plugin)
print plugin
except:
print _("Failed to load the module: %s") % plugin
import traceback
traceback.print_exc()
_failed.append(plugin)
for dir in _loaddir:
for file in os.listdir(dir):
name = os.path.split(file)
match = pymod.match(name[1])
if not match:
continue
_attempt.append(file)
plugin = match.groups()[0]
try:
a = __import__(plugin)
_success.append(a)
except:
print _("Failed to load the module: %s") % plugin
import traceback
traceback.print_exc()
_failed.append(plugin)
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# # Plugin registering
#
#-------------------------------------------------------------------------
def build_export_menu(top_menu,callback):
myMenu = GtkMenu()
for report in _exports:
item = GtkMenuItem(report[1])
item.connect("activate", callback ,report[0])
item.show()
myMenu.append(item)
top_menu.set_submenu(myMenu)
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
def build_import_menu(top_menu,callback):
myMenu = GtkMenu()
for report in _imports:
item = GtkMenuItem(report[1])
item.connect("activate", callback ,report[0])
item.show()
myMenu.append(item)
top_menu.set_submenu(myMenu)
#-------------------------------------------------------------------------
#
#
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
def register_export(task, name): def register_export(task, name):
_exports.append((task, name)) _exports.append((task, name))
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
def register_import(task, name): def register_import(task, name):
_imports.append((task, name)) _imports.append((task, name))
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
def register_report(task, name, category=None, description=None, xpm=None): def register_report(task, name, category=None, description=None, xpm=None):
if xpm == None: if xpm == None:
xpm_data = no_image() xpm_data = no_image()
@ -306,11 +278,6 @@ def register_report(task, name, category=None, description=None, xpm=None):
_reports.append((task, category, name, description, xpm_data)) _reports.append((task, category, name, description, xpm_data))
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
def register_tool(task, name, category=None, description=None, xpm=None): def register_tool(task, name, category=None, description=None, xpm=None):
if xpm == None: if xpm == None:
xpm_data = no_image() xpm_data = no_image()
@ -328,7 +295,7 @@ def register_tool(task, name, category=None, description=None, xpm=None):
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# # Building pulldown menus
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
def build_menu(top_menu,list,callback): def build_menu(top_menu,list,callback):
@ -360,22 +327,33 @@ def build_menu(top_menu,list,callback):
submenu.append(subentry) submenu.append(subentry)
top_menu.set_submenu(report_menu) top_menu.set_submenu(report_menu)
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
def build_report_menu(top_menu,callback): def build_report_menu(top_menu,callback):
build_menu(top_menu,_reports,callback) build_menu(top_menu,_reports,callback)
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
def build_tools_menu(top_menu,callback): def build_tools_menu(top_menu,callback):
build_menu(top_menu,_tools,callback) build_menu(top_menu,_tools,callback)
def build_export_menu(top_menu,callback):
myMenu = GtkMenu()
for report in _exports:
item = GtkMenuItem(report[1])
item.connect("activate", callback ,report[0])
item.show()
myMenu.append(item)
top_menu.set_submenu(myMenu)
def build_import_menu(top_menu,callback):
myMenu = GtkMenu()
for report in _imports:
item = GtkMenuItem(report[1])
item.connect("activate", callback ,report[0])
item.show()
myMenu.append(item)
top_menu.set_submenu(myMenu)
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# #

View File

@ -21,7 +21,6 @@
"People with an event after ..." "People with an event after ..."
import Filter import Filter
import string
import Date import Date
import RelLib import RelLib
import intl import intl
@ -35,33 +34,23 @@ _ = intl.gettext
class EventAfter(Filter.Filter): class EventAfter(Filter.Filter):
"People with an event after ..." "People with an event after ..."
#--------------------------------------------------------------------
#
#
#
#--------------------------------------------------------------------
def __init__(self,text): def __init__(self,text):
self.date = Date.Date() self.date = Date.Date()
self.date.set(text) self.date.set(text)
#-------------------------------------------------------------------- def match(self,p):
# for event in p.getEventList() + [p.getBirth(), p.getDeath()]:
#
#
#--------------------------------------------------------------------
def match(self,person):
val = 0
list = person.getEventList()[:]
list.append(person.getBirth())
list.append(person.getDeath())
for event in list:
if self.date.getDate() == "" or event.getDate() == "": if self.date.getDate() == "" or event.getDate() == "":
continue continue
if self.date < event.getDateObj(): if event.getDateObj().greater_than(self.date):
val = 1 return 1
break return 0
return val
#--------------------------------------------------------------------
#
#
#
#--------------------------------------------------------------------
Filter.register_filter(EventAfter, Filter.register_filter(EventAfter,
description=_("People with an event after ..."), description=_("People with an event after ..."),
qualifier=1) qualifier=1)

View File

@ -21,7 +21,6 @@
"People with an event before ..." "People with an event before ..."
import Filter import Filter
import string
import Date import Date
import RelLib import RelLib
import intl import intl
@ -35,33 +34,17 @@ _ = intl.gettext
class EventBefore(Filter.Filter): class EventBefore(Filter.Filter):
"People with an event before ..." "People with an event before ..."
#--------------------------------------------------------------------
#
#
#
#--------------------------------------------------------------------
def __init__(self,text): def __init__(self,text):
self.date = Date.Date() self.date = Date.Date()
self.date.set(text) self.date.set(text)
self.text = text
#-------------------------------------------------------------------- def match(self,p):
# for event in p.getEventList() + [p.getBirth(), p.getDeath()]:
#
#
#--------------------------------------------------------------------
def match(self,person):
val = 0
list = person.getEventList()[:]
list.append(person.getBirth())
list.append(person.getDeath())
for event in list:
if self.date.getDate() == "" or event.getDate() == "": if self.date.getDate() == "" or event.getDate() == "":
continue continue
if self.date > event.getDateObj(): if event.getDateObj().less_than(self.date):
val = 1 return 1
break return 0
return val
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #

View File

@ -126,7 +126,7 @@
</signal> </signal>
<label>_Revert</label> <label>_Revert</label>
<right_justify>False</right_justify> <right_justify>False</right_justify>
<stock_icon>GNOME_STOCK_MENU_UNDO</stock_icon> <stock_icon>GNOME_STOCK_MENU_REVERT</stock_icon>
</widget> </widget>
<widget> <widget>
@ -154,6 +154,19 @@
<right_justify>False</right_justify> <right_justify>False</right_justify>
</widget> </widget>
<widget>
<class>GtkPixmapMenuItem</class>
<name>reload_plugins</name>
<signal>
<name>activate</name>
<handler>on_reload_plugins_activate</handler>
<last_modification_time>Sat, 27 Oct 2001 03:56:20 GMT</last_modification_time>
</signal>
<label>Reload Plugins</label>
<right_justify>False</right_justify>
<stock_icon>GNOME_STOCK_MENU_REFRESH</stock_icon>
</widget>
<widget> <widget>
<class>GtkMenuItem</class> <class>GtkMenuItem</class>
<name>separator1</name> <name>separator1</name>

View File

@ -2694,6 +2694,7 @@ def main(arg):
"on_merge_activate" : on_merge_activate, "on_merge_activate" : on_merge_activate,
"on_places_activate" : on_places_activate, "on_places_activate" : on_places_activate,
"on_preferences_activate" : on_preferences_activate, "on_preferences_activate" : on_preferences_activate,
"on_reload_plugins_activate" : Plugins.reload_plugins,
"on_remove_child_clicked" : on_remove_child_clicked, "on_remove_child_clicked" : on_remove_child_clicked,
"on_reports_clicked" : on_reports_clicked, "on_reports_clicked" : on_reports_clicked,
"on_revert_activate" : on_revert_activate, "on_revert_activate" : on_revert_activate,