[r21449]grampletpane: Replace diagnostic prints with log warnings.

And improve warning when unable to save the Dashboard layout.

svn: r21454
This commit is contained in:
John Ralls 2013-02-26 00:23:31 +00:00
parent 44f065eabf
commit b99e2e29df

View File

@ -48,6 +48,10 @@ if sys.version_info[0] < 3:
else: else:
import configparser import configparser
import logging
LOG = logging.getLogger(".")
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# GRAMPS modules # GRAMPS modules
@ -141,7 +145,7 @@ def get_gramplet_opts(name, opts):
my_data.update(opts) my_data.update(opts)
return my_data return my_data
else: else:
print(("Unknown gramplet name: '%s'" % name)) LOG.warn("Unknown gramplet name: '%s'", name)
return {} return {}
def get_gramplet_options_by_name(name): def get_gramplet_options_by_name(name):
@ -151,7 +155,7 @@ def get_gramplet_options_by_name(name):
if name in AVAILABLE_GRAMPLETS(): if name in AVAILABLE_GRAMPLETS():
return GET_AVAILABLE_GRAMPLETS(name).copy() return GET_AVAILABLE_GRAMPLETS(name).copy()
else: else:
print(("Unknown gramplet name: '%s'" % name)) LOG.warn("Unknown gramplet name: '%s'", name)
return None return None
def get_gramplet_options_by_tname(name): def get_gramplet_options_by_tname(name):
@ -161,7 +165,7 @@ def get_gramplet_options_by_tname(name):
for key in AVAILABLE_GRAMPLETS(): for key in AVAILABLE_GRAMPLETS():
if GET_AVAILABLE_GRAMPLETS(key)["tname"] == name: if GET_AVAILABLE_GRAMPLETS(key)["tname"] == name:
return GET_AVAILABLE_GRAMPLETS(key).copy() return GET_AVAILABLE_GRAMPLETS(key).copy()
print(("Unknown gramplet name: '%s'" % name)) LOG.warn("Unknown gramplet name: '%s'",name)
return None return None
def make_requested_gramplet(gui_class, pane, opts, dbstate, uistate): def make_requested_gramplet(gui_class, pane, opts, dbstate, uistate):
@ -178,10 +182,11 @@ def make_requested_gramplet(gui_class, pane, opts, dbstate, uistate):
if module: if module:
getattr(module, opts["content"])(gui) getattr(module, opts["content"])(gui)
else: else:
print("Error loading gramplet '%s': skipping content" % name) LOG.warn("Error loading gramplet '%s': skipping content",
name)
return gui return gui
else: else:
print("Error loading gramplet: unknown name") LOG.warn("Error loading gramplet: unknown name")
return None return None
def logical_true(value): def logical_true(value):
@ -507,7 +512,7 @@ class GuiGramplet(object):
url = attributes["wiki"] url = attributes["wiki"]
self.link_region(start, stop, "WIKI", url) # tooltip? self.link_region(start, stop, "WIKI", url) # tooltip?
else: else:
print("warning: no url on link: '%s'" % text[start, stop]) LOG.warn("warning: no url on link: '%s'", text[start, stop])
def link_region(self, start, stop, link_type, url): def link_region(self, start, stop, link_type, url):
link_data = (LinkTag(self.buffer), link_type, url, url) link_data = (LinkTag(self.buffer), link_type, url, url)
@ -1043,7 +1048,7 @@ class GrampletPane(Gtk.ScrolledWindow):
self.gramplet_map[unique] = g self.gramplet_map[unique] = g
self.frame_map[str(g.mainframe)] = g self.frame_map[str(g.mainframe)] = g
else: else:
print("Can't make gramplet of type '%s'." % name) LOG.warn("Can't make gramplet of type '%s'.", name)
self.place_gramplets() self.place_gramplets()
def show_all(self): def show_all(self):
@ -1172,8 +1177,9 @@ class GrampletPane(Gtk.ScrolledWindow):
filename = self.configfile filename = self.configfile
try: try:
fp = io.open(filename, "w", encoding='utf-8') fp = io.open(filename, "w", encoding='utf-8')
except IOError: except IOError as err:
print("Failed writing '%s'; gramplets not saved" % filename) LOG.warn("Failed to open %s because $s; gramplets not saved",
filename, str(err))
return return
fp.write(";; Gramps gramplets file\n") fp.write(";; Gramps gramplets file\n")
fp.write(";; Automatically created at %s" % fp.write(";; Automatically created at %s" %
@ -1344,7 +1350,7 @@ class GrampletPane(Gtk.ScrolledWindow):
self.gramplet_map[opts["title"]] = g self.gramplet_map[opts["title"]] = g
self.frame_map[str(g.mainframe)] = g self.frame_map[str(g.mainframe)] = g
else: else:
print("Can't make gramplet of type '%s'." % name) LOG.warn("Can't make gramplet of type '%s'.", name)
if g: if g:
gramplet = g gramplet = g
gramplet.gstate = "maximized" gramplet.gstate = "maximized"
@ -1368,7 +1374,8 @@ class GrampletPane(Gtk.ScrolledWindow):
all_opts = get_gramplet_options_by_tname(tname) all_opts = get_gramplet_options_by_tname(tname)
name = all_opts["name"] name = all_opts["name"]
if all_opts is None: if all_opts is None:
print("Unknown gramplet type: '%s'; bad gramplets.ini file?" % name) LOG.warn("Unknown gramplet type: '%s'; bad gramplets.ini file?",
name)
return return
if "title" not in all_opts: if "title" not in all_opts:
all_opts["title"] = "Untitled Gramplet" all_opts["title"] = "Untitled Gramplet"
@ -1404,7 +1411,7 @@ class GrampletPane(Gtk.ScrolledWindow):
gramplet.pui.active = True gramplet.pui.active = True
gramplet.pui.update() gramplet.pui.update()
else: else:
print("Can't make gramplet of type '%s'." % name) LOG.warn("Can't make gramplet of type '%s'.", name)
def _button_press(self, obj, event): def _button_press(self, obj, event):
if is_right_click(event): if is_right_click(event):