Convert python evaluation tool into a gramplet

svn: r23242
This commit is contained in:
Nick Hall 2013-10-03 13:33:03 +00:00
parent c7f4a540b1
commit 6aaccd4ca0
4 changed files with 66 additions and 330 deletions

View File

@ -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('<b>%s</b>' % 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)

View File

@ -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"),
)

View File

@ -1,266 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtk+ 3.0 -->
<object class="GtkDialog" id="eval">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="default_width">450</property>
<property name="default_height">500</property>
<property name="type_hint">dialog</property>
<signal name="delete-event" handler="on_delete_event" swapped="no"/>
<child internal-child="vbox">
<object class="GtkBox" id="dialog-vbox1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child internal-child="action_area">
<object class="GtkButtonBox" id="dialog-action_area1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="button1">
<property name="label">gtk-clear</property>
<property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="receives_default">False</property>
<property name="use_action_appearance">False</property>
<property name="use_stock">True</property>
<signal name="clicked" handler="on_clear_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button3">
<property name="label">gtk-close</property>
<property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="receives_default">False</property>
<property name="use_action_appearance">False</property>
<property name="use_stock">True</property>
<signal name="clicked" handler="on_close_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button2">
<property name="label">gtk-execute</property>
<property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="receives_default">False</property>
<property name="use_action_appearance">False</property>
<property name="use_stock">True</property>
<signal name="clicked" handler="on_apply_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkVBox" id="vbox1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="border_width">6</property>
<property name="spacing">6</property>
<child>
<object class="GtkLabel" id="title">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkTable" id="table2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="border_width">6</property>
<property name="n_rows">6</property>
<property name="n_columns">2</property>
<property name="column_spacing">6</property>
<property name="row_spacing">6</property>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<object class="GtkScrolledWindow" id="scrolledwindow1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkTextView" id="ebuf">
<property name="visible">True</property>
<property name="can_focus">True</property>
</object>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
</packing>
</child>
<child>
<object class="GtkScrolledWindow" id="scrolledwindow2">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkTextView" id="display">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="editable">False</property>
</object>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Evaluation Window</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
</object>
<packing>
<property name="right_attach">2</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Output Window</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
</object>
<packing>
<property name="right_attach">2</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<object class="GtkScrolledWindow" id="scrolledwindow3">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkTextView" id="error">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="editable">False</property>
</object>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">5</property>
<property name="bottom_attach">6</property>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label4">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Error Window</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
</object>
<packing>
<property name="right_attach">2</property>
<property name="top_attach">4</property>
<property name="bottom_attach">5</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options"></property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkHButtonBox" id="hbuttonbox1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="border_width">6</property>
<property name="spacing">6</property>
<property name="layout_style">end</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
<action-widgets>
<action-widget response="0">button1</action-widget>
<action-widget response="0">button3</action-widget>
<action-widget response="0">button2</action-widget>
</action-widgets>
</object>
</interface>

View File

@ -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