2003-05-13 08:56:33 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2006-05-08 23:51:11 +05:30
|
|
|
# Copyright (C) 2003-2006 Donald N. Allingham
|
2008-05-19 00:54:28 +05:30
|
|
|
# Copyright (C) 2008 Brian G. Matherly
|
2003-05-13 08:56:33 +05:30
|
|
|
#
|
|
|
|
# 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
|
|
|
|
#
|
|
|
|
|
2003-12-17 21:36:36 +05:30
|
|
|
# $Id$
|
|
|
|
|
2003-05-13 08:56:33 +05:30
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Provide a python evaluation window
|
2003-05-13 08:56:33 +05:30
|
|
|
"""
|
2005-03-25 05:54:37 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# standard python modules
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2003-05-14 08:15:11 +05:30
|
|
|
import cStringIO
|
|
|
|
import sys
|
2006-04-07 03:32:46 +05:30
|
|
|
from gettext import gettext as _
|
2003-05-14 08:15:11 +05:30
|
|
|
|
2005-03-25 05:54:37 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS modules
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2008-10-02 09:32:10 +05:30
|
|
|
from PluginUtils import Tool
|
2006-05-08 23:51:11 +05:30
|
|
|
import ManagedWindow
|
2009-05-15 01:45:59 +05:30
|
|
|
from glade import Glade
|
2009-04-16 00:57:17 +05:30
|
|
|
|
2005-03-25 05:54:37 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Actual tool
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2006-05-08 23:51:11 +05:30
|
|
|
class Eval(Tool.Tool,ManagedWindow.ManagedWindow):
|
|
|
|
def __init__(self,dbstate, uistate, options_class, name, callback=None):
|
|
|
|
self.title = _("Python evaluation window")
|
2003-05-13 08:56:33 +05:30
|
|
|
|
2006-05-08 23:51:11 +05:30
|
|
|
Tool.Tool.__init__(self,dbstate, options_class, name)
|
|
|
|
ManagedWindow.ManagedWindow.__init__(self,uistate,[],self.__class__)
|
2004-05-11 07:51:09 +05:30
|
|
|
|
2009-05-15 01:45:59 +05:30
|
|
|
self.glade = Glade()
|
2003-05-13 08:56:33 +05:30
|
|
|
|
2009-05-15 01:45:59 +05:30
|
|
|
window = self.glade.toplevel
|
2009-04-09 20:42:35 +05:30
|
|
|
self.dbuf = self.glade.get_object("display").get_buffer()
|
2009-05-15 01:45:59 +05:30
|
|
|
self.ebuf = self.glade.get_object("ebuf").get_buffer()
|
2009-04-09 20:42:35 +05:30
|
|
|
self.error = self.glade.get_object("error").get_buffer()
|
2003-05-13 08:56:33 +05:30
|
|
|
|
2009-04-09 20:42:35 +05:30
|
|
|
self.glade.connect_signals({
|
2003-05-13 08:56:33 +05:30
|
|
|
"on_apply_clicked" : self.apply_clicked,
|
2006-05-08 23:51:11 +05:30
|
|
|
"on_close_clicked" : self.close,
|
2003-05-13 08:56:33 +05:30
|
|
|
"on_clear_clicked" : self.clear_clicked,
|
|
|
|
})
|
|
|
|
|
2009-04-09 20:42:35 +05:30
|
|
|
self.set_window(window,self.glade.get_object('title'),self.title)
|
2006-05-08 23:51:11 +05:30
|
|
|
self.show()
|
2003-05-14 08:15:11 +05:30
|
|
|
|
2008-02-24 19:25:55 +05:30
|
|
|
def build_menu_names(self, obj):
|
2006-05-08 23:51:11 +05:30
|
|
|
return (self.title,None)
|
2004-05-11 07:51:09 +05:30
|
|
|
|
2008-02-24 19:25:55 +05:30
|
|
|
def apply_clicked(self, obj):
|
2003-12-17 21:36:36 +05:30
|
|
|
text = unicode(self.ebuf.get_text(self.ebuf.get_start_iter(),
|
2006-05-08 23:51:11 +05:30
|
|
|
self.ebuf.get_end_iter(),False))
|
2003-05-14 08:15:11 +05:30
|
|
|
|
|
|
|
outtext = cStringIO.StringIO()
|
|
|
|
errtext = cStringIO.StringIO()
|
|
|
|
sys.stdout = outtext
|
|
|
|
sys.stderr = errtext
|
2003-05-13 08:56:33 +05:30
|
|
|
exec(text)
|
2003-05-14 08:15:11 +05:30
|
|
|
self.dbuf.set_text(outtext.getvalue())
|
|
|
|
self.error.set_text(errtext.getvalue())
|
|
|
|
sys.stdout = sys.__stdout__
|
|
|
|
sys.stderr = sys.__stderr__
|
2003-05-13 08:56:33 +05:30
|
|
|
|
2008-02-24 19:25:55 +05:30
|
|
|
def clear_clicked(self, obj):
|
2003-05-14 08:15:11 +05:30
|
|
|
self.dbuf.set_text("")
|
|
|
|
self.ebuf.set_text("")
|
|
|
|
self.error.set_text("")
|
2003-05-13 08:56:33 +05:30
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2005-12-06 12:08:09 +05:30
|
|
|
class EvalOptions(Tool.ToolOptions):
|
|
|
|
"""
|
|
|
|
Defines options and provides handling interface.
|
|
|
|
"""
|
2003-05-13 08:56:33 +05:30
|
|
|
|
2008-02-24 19:25:55 +05:30
|
|
|
def __init__(self, name,person_id=None):
|
|
|
|
Tool.ToolOptions.__init__(self, name,person_id)
|