gramps/gramps2/src/plugins/eval.py
Alex Roitman 9f84452198 * src/Sources.py: Unicode conversion from gtk.TextView.
* src/Witness.py: Unicode conversion from gtk.TextView.
* src/Report.py: Unicode conversion from gtk.TextView.
* src/NameEdit.py: Unicode conversion from gtk.TextView.
* src/Marriage.py: Unicode conversion from gtk.TextView.
* src/ImageSelect.py: Unicode conversion from gtk.TextView.
* src/EventEdit.py: Unicode conversion from gtk.TextView.
* src/EditSource.py: Unicode conversion from gtk.TextView.
* src/EditPlace.py: Unicode conversion from gtk.TextView.
* src/EditPerson.py: Unicode conversion from gtk.TextView.
* src/AutoComp.py: Unicode conversion from gtk.TextView.
* src/AttrEdit.py: Unicode conversion from gtk.TextView.
* src/AddrEdit.py: Unicode conversion from gtk.TextView.
* src/plugins/BookReport.py: Unicode conversion from gtk.Entry
and gtk.TextView.
* src/plugins/ChangeTypes.py: Unicode conversion.
* src/plugins/EventCmp.py: Unicode conversion.
* src/plugins/FilterEditor.py: Unicode conversion.
* src/plugins/SimpleBookTitle.py: Unicode conversion.
* src/plugins/TimeLine.py: Unicode conversion.
* src/plugins/WebPage.py: Unicode conversion.
* src/plugins/WriteGedcom.py: Unicode conversion.
* src/plugins/WritePkg.py: Unicode conversion.
* src/plugins/eval.py: Unicode conversion.
* src/plugins/soundgen.py: Unicode conversion.


svn: r2536
2003-12-17 16:06:36 +00:00

97 lines
2.8 KiB
Python

#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2003 Donald N. Allingham
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# $Id$
"""
Provides a python evaluation window
"""
import os
import cStringIO
import sys
import gtk
import gtk.glade
import Utils
from gettext import gettext as _
class EvalWindow:
def __init__(self):
glade_file = "%s/%s" % (os.path.dirname(__file__),"eval.glade")
self.glade = gtk.glade.XML(glade_file,"top","gramps")
self.top = self.glade.get_widget("top")
self.dbuf = self.glade.get_widget("display").get_buffer()
self.ebuf = self.glade.get_widget("eval").get_buffer()
self.error = self.glade.get_widget("error").get_buffer()
self.glade.signal_autoconnect({
"on_apply_clicked" : self.apply_clicked,
"on_close_clicked" : self.close_clicked,
"on_clear_clicked" : self.clear_clicked,
})
Utils.set_titles(self.top,self.glade.get_widget('title'),
_("Python Evaluation Window"))
def apply_clicked(self,obj):
text = unicode(self.ebuf.get_text(self.ebuf.get_start_iter(),
self.ebuf.get_end_iter(),gtk.FALSE))
outtext = cStringIO.StringIO()
errtext = cStringIO.StringIO()
sys.stdout = outtext
sys.stderr = errtext
exec(text)
self.dbuf.set_text(outtext.getvalue())
self.error.set_text(errtext.getvalue())
sys.stdout = sys.__stdout__
sys.stderr = sys.__stderr__
def clear_clicked(self,obj):
self.dbuf.set_text("")
self.ebuf.set_text("")
self.error.set_text("")
def close_clicked(self,obj):
self.top.destroy()
#------------------------------------------------------------------------
#
#
#
#------------------------------------------------------------------------
from Plugins import register_tool
def runtool(database,person,callback):
EvalWindow()
register_tool(
runtool,
_("Python evaluation window"),
category=_("Debug"),
description=_("Provides a window that can evaluate python code")
)