From 6aaccd4ca019860a9822973c7763f04efafc6537 Mon Sep 17 00:00:00 2001 From: Nick Hall Date: Thu, 3 Oct 2013 13:33:03 +0000 Subject: [PATCH] Convert python evaluation tool into a gramplet svn: r23242 --- gramps/plugins/{tool => gramplet}/eval.py | 95 ++++---- gramps/plugins/gramplet/gramplet.gpr.py | 13 ++ gramps/plugins/tool/eval.glade | 266 ---------------------- gramps/plugins/tool/tools.gpr.py | 22 -- 4 files changed, 66 insertions(+), 330 deletions(-) rename gramps/plugins/{tool => gramplet}/eval.py (59%) delete mode 100644 gramps/plugins/tool/eval.glade diff --git a/gramps/plugins/tool/eval.py b/gramps/plugins/gramplet/eval.py similarity index 59% rename from gramps/plugins/tool/eval.py rename to gramps/plugins/gramplet/eval.py index 3489968bc..74c7a2906 100644 --- a/gramps/plugins/tool/eval.py +++ b/gramps/plugins/gramplet/eval.py @@ -39,49 +39,73 @@ from gramps.gen.const import GRAMPS_LOCALE as glocale _ = glocale.translation.gettext import traceback +#------------------------------------------------------------------------- +# +# Gtk modules +# +#------------------------------------------------------------------------- +from gi.repository import Gtk + #------------------------------------------------------------------------ # -# GRAMPS modules +# Gramps modules # #------------------------------------------------------------------------ -from gramps.gui.plug import tool -from gramps.gui.managedwindow import ManagedWindow -from gramps.gui.glade import Glade +from gramps.gen.plug import Gramplet from gramps.gen.constfunc import cuni #------------------------------------------------------------------------- # -# Actual tool +# PythonEvaluation # #------------------------------------------------------------------------- -class Eval(tool.Tool,ManagedWindow): - def __init__(self,dbstate, user, options_class, name, callback=None): - uistate = user.uistate - self.title = _("Python evaluation window") +class PythonEvaluation(Gramplet): + """ + Allows the user to evaluate python code. + """ + def init(self): + self.gui.WIDGET = self.build_gui() + self.gui.get_container_widget().remove(self.gui.textview) + self.gui.get_container_widget().add_with_viewport(self.gui.WIDGET) - tool.Tool.__init__(self,dbstate, options_class, name) - ManagedWindow.__init__(self,uistate,[],self.__class__) + def build_gui(self): + """ + Build the GUI interface. + """ + self.top = Gtk.VBox() + self.top.set_border_width(6) - self.glade = Glade() + self.ebuf = self.__add_text_view(_("Evaluation")) + self.dbuf = self.__add_text_view(_("Output")) + self.error = self.__add_text_view(_("Error")) + + bbox = Gtk.HButtonBox() + apply_button = Gtk.Button(_("Apply")) + apply_button.connect('clicked', self.apply_clicked) + bbox.pack_start(apply_button, False, False, 6) + clear_button = Gtk.Button(_("Clear")) + clear_button.connect('clicked', self.clear_clicked) + bbox.pack_start(clear_button, False, False, 6) + self.top.pack_start(bbox, False, False, 6) + + self.top.show_all() - window = self.glade.toplevel - self.dbuf = self.glade.get_object("display").get_buffer() - self.ebuf = self.glade.get_object("ebuf").get_buffer() - self.error = self.glade.get_object("error").get_buffer() - self.dbstate = dbstate + return self.top - self.glade.connect_signals({ - "on_apply_clicked" : self.apply_clicked, - "on_close_clicked" : self.close, - "on_clear_clicked" : self.clear_clicked, - "on_delete_event" : self.close, - }) - - self.set_window(window, self.glade.get_object('title'), self.title) - self.show() - - def build_menu_names(self, obj): - return (self.title,None) + def __add_text_view(self, name): + """ + Add a text view to the interface. + """ + label = Gtk.Label(name) + label.set_markup('%s' % name) + label.set_alignment(0, 0.5) + self.top.pack_start(label, False, False, 6) + swin = Gtk.ScrolledWindow() + swin.set_shadow_type(Gtk.ShadowType.IN) + tview = Gtk.TextView() + swin.add_with_viewport(tview) + self.top.pack_start(swin, True, True, 6) + return tview.get_buffer() def apply_clicked(self, obj): text = cuni(self.ebuf.get_text(self.ebuf.get_start_iter(), @@ -104,16 +128,3 @@ class Eval(tool.Tool,ManagedWindow): self.dbuf.set_text("") self.ebuf.set_text("") self.error.set_text("") - -#------------------------------------------------------------------------ -# -# -# -#------------------------------------------------------------------------ -class EvalOptions(tool.ToolOptions): - """ - Defines options and provides handling interface. - """ - - def __init__(self, name,person_id=None): - tool.ToolOptions.__init__(self, name,person_id) diff --git a/gramps/plugins/gramplet/gramplet.gpr.py b/gramps/plugins/gramplet/gramplet.gpr.py index 4a44b3f63..775c4baca 100644 --- a/gramps/plugins/gramplet/gramplet.gpr.py +++ b/gramps/plugins/gramplet/gramplet.gpr.py @@ -1167,3 +1167,16 @@ register(GRAMPLET, gramplet_title=_("gramplet|To Do"), navtypes=["Media"], ) + +register(GRAMPLET, + id="Python Evaluation", + name=_("Python Evaluation"), + description = _("Gramplet allowing the evaluation of python code"), + version="1.0.0", + gramps_target_version="4.1", + status = STABLE, + fname="eval.py", + height=200, + gramplet = 'PythonEvaluation', + gramplet_title=_("Python Evaluation"), + ) diff --git a/gramps/plugins/tool/eval.glade b/gramps/plugins/tool/eval.glade deleted file mode 100644 index d405c4841..000000000 --- a/gramps/plugins/tool/eval.glade +++ /dev/null @@ -1,266 +0,0 @@ - - - - - True - False - 450 - 500 - dialog - - - - True - False - - - True - False - end - - - gtk-clear - False - True - True - True - False - False - True - - - - False - False - 0 - - - - - gtk-close - False - True - True - True - False - False - True - - - - False - False - 1 - - - - - gtk-execute - False - True - True - True - False - False - True - - - - False - False - 2 - - - - - False - True - end - 0 - - - - - True - False - 6 - 6 - - - True - False - - - False - False - 0 - - - - - True - False - 6 - 6 - 2 - 6 - 6 - - - - - - - - - - - - True - True - in - - - True - True - - - - - 1 - 2 - 1 - 2 - - - - - True - True - in - - - True - True - False - - - - - 1 - 2 - 3 - 4 - GTK_FILL - - - - - True - False - 0 - Evaluation Window - - - - - - 2 - GTK_FILL - - - - - - True - False - 0 - Output Window - - - - - - 2 - 2 - 3 - GTK_FILL - - - - - - True - True - in - - - True - True - False - - - - - 1 - 2 - 5 - 6 - GTK_FILL - - - - - True - False - 0 - Error Window - - - - - - 2 - 4 - 5 - GTK_FILL - - - - - - True - True - 1 - - - - - True - False - 6 - 6 - end - - - False - True - 2 - - - - - False - True - 1 - - - - - - button1 - button3 - button2 - - - diff --git a/gramps/plugins/tool/tools.gpr.py b/gramps/plugins/tool/tools.gpr.py index 903b621ed..7bfced6fe 100644 --- a/gramps/plugins/tool/tools.gpr.py +++ b/gramps/plugins/tool/tools.gpr.py @@ -116,28 +116,6 @@ tool_modes = [TOOL_MODE_GUI] ) -#------------------------------------------------------------------------ -# -# Python Evaluation Window -# -#------------------------------------------------------------------------ - -register(TOOL, -id = 'eval', -name = "Python Evaluation Window", -description = "Provides a window that can evaluate python code", -version = '1.0', -gramps_target_version = '4.1', -status = STABLE, -fname = 'eval.py', -authors = ["Donald N. Allingham"], -authors_email = ["don@gramps-project.org"], -category = TOOL_DEBUG, -toolclass = 'Eval', -optionclass = 'EvalOptions', -tool_modes = [TOOL_MODE_GUI] - ) - #------------------------------------------------------------------------ # # Compare Individual Events