Author: bugman Date: Thu Sep 16 16:05:01 2010 New Revision: 11583 URL: http://svn.gna.org/viewcvs/relax?rev=11583&view=rev Log: Created the relax prompt GUI element. Added: branches/bieri_gui/gui_bieri/relax_prompt.py Modified: branches/bieri_gui/gui_bieri/relax_gui.py Modified: branches/bieri_gui/gui_bieri/relax_gui.py URL: http://svn.gna.org/viewcvs/relax/branches/bieri_gui/gui_bieri/relax_gui.py?rev=11583&r1=11582&r2=11583&view=diff ============================================================================== --- branches/bieri_gui/gui_bieri/relax_gui.py (original) +++ branches/bieri_gui/gui_bieri/relax_gui.py Thu Sep 16 16:05:01 2010 @@ -63,6 +63,7 @@ from message import dir_message, error_message, exec_relax, missing_data, question, relax_run_ok from paths import ABOUT_RELAX_ICON, ABOUT_RELAXGUI_ICON, CONTACT_ICON, CONTROLLER_ICON, EXIT_ICON, IMAGE_PATH, LOAD_ICON, MANUAL_ICON, NEW_ICON, OPEN_ICON, REF_ICON, RELAX_PROMPT_ICON, SAVE_ICON, SAVE_AS_ICON, SETTINGS_ICON, SETTINGS_GLOBAL_ICON, SETTINGS_RESET_ICON from references import References +from relax_prompt import Prompt from settings import import_file_settings, load_sequence, relax_global_settings @@ -127,6 +128,9 @@ # Build the controller, but don't show it. self.controller = Controller(None, -1, "") + # Build the relax prompt, but don't show it. + self.relax_prompt = Prompt(None, -1, "") + rx_data = ds.relax_gui.analyses[self.noe_index[0]] self.frame_1_statusbar = self.CreateStatusBar(3, 0) @@ -292,7 +296,7 @@ # The 'View' actions. self.Bind(wx.EVT_MENU, self.show_controller, id=50) - self.Bind(wx.EVT_MENU, self.relax_prompt, id=51) + self.Bind(wx.EVT_MENU, self.show_prompt, id=51) # The 'Molecule' menu entries. menu = wx.Menu() @@ -459,6 +463,7 @@ self.controller.Destroy() self.dialog_about_gui.Destroy() self.dialog_about_relax.Destroy() + self.relax_prompt.Destroy() # Destroy the main window. self.Destroy() @@ -642,14 +647,6 @@ os.system('/usr/bin/xdg-open %s' % file) - def relax_prompt(self, event): - """Display the relax prompt. - - @param event: The wx event. - @type event: wx event - """ - - def reset_setting(self, event): #reset all settings global global_setting #import global variable if question('Do you realy want to change relax settings?'): @@ -673,6 +670,17 @@ # Open the window. self.controller.Show() + + + def show_prompt(self, event): + """Display the relax prompt window. + + @param event: The wx event. + @type event: wx event + """ + + # Open the window. + self.relax_prompt.Show() def state_load(self, event): Added: branches/bieri_gui/gui_bieri/relax_prompt.py URL: http://svn.gna.org/viewcvs/relax/branches/bieri_gui/gui_bieri/relax_prompt.py?rev=11583&view=auto ============================================================================== --- branches/bieri_gui/gui_bieri/relax_prompt.py (added) +++ branches/bieri_gui/gui_bieri/relax_prompt.py Thu Sep 16 16:05:01 2010 @@ -1,0 +1,133 @@ +############################################################################### +# # +# Copyright (C) 2010 Edward d'Auvergne # +# # +# This file is part of the program relax. # +# # +# relax 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. # +# # +# relax 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 relax; if not, write to the Free Software # +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # +# # +############################################################################### + +# Module docstring. +"""The relax prompt GUI element.""" + +# Python module imports. +import sys +import wx +import wx.py +import wx.stc as stc + +# relax module imports +from info import Info_box +from prompt import interpreter + + + +class Prompt(wx.Frame): + """The relax prompt window object.""" + + def __init__(self, *args, **kwds): + """Set up the relax prompt.""" + + # Create GUI elements + kwds["style"] = wx.DEFAULT_FRAME_STYLE + wx.Frame.__init__(self, *args, **kwds) + + # Some default values. + self.size_x = 1000 + self.size_y = 500 + self.border = 0 + + # Set up the frame. + sizer = self.setup_frame() + + # The shell. + self.add_shell(sizer) + + + def add_shell(self, sizer): + """Add the relax prompt to the sizer. + + @param sizer: The sizer element to pack the relax prompt into. + @type sizer: wx.Sizer instance + """ + + # The shell. + self.prompt = wx.py.shell.Shell(self, InterpClass=InterpClass) + + # Colours. + self.prompt.StyleSetBackground(style=stc.STC_STYLE_DEFAULT, back='black') + self.prompt.StyleSetSpec(stc.STC_STYLE_DEFAULT, "fore:light grey") + self.prompt.StyleClearAll() + self.prompt.StyleSetSpec(stc.STC_P_NUMBER, "fore:cyan") + self.prompt.StyleSetSpec(stc.STC_P_OPERATOR, "fore:white") + self.prompt.StyleSetSpec(stc.STC_P_DEFNAME, "fore:green") + self.prompt.StyleSetSpec(stc.STC_P_CLASSNAME, "fore:green") + + # Add the shell to the sizer. + sizer.Add(self.prompt, 1, wx.EXPAND|wx.ALL, self.border) + + + def handler_close(self, event): + """Event handler for the close window action. + + @param event: The wx event. + @type event: wx event + """ + + # Close the window. + self.Hide() + + + def setup_frame(self): + """Set up the relax controller frame. + + @return: The sizer object. + @rtype: wx.Sizer instance + """ + + # Set the frame title. + self.SetTitle("The relax prompt") + + # Use a box sizer for packing the shell. + sizer = wx.BoxSizer(wx.VERTICAL) + self.SetSizer(sizer) + + # Close the window cleanly (hide so it can be reopened). + self.Bind(wx.EVT_CLOSE, self.handler_close) + + # Set the default size of the controller. + self.SetSize((self.size_x, self.size_y)) + + # Return the sizer. + return sizer + + +class InterpClass(wx.py.interpreter.Interpreter): + def __init__(self, locals=None, rawin=None, stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr, showInterpIntro=True): + """Redefine the interpreter.""" + + # Execute the base class __init__() method. + wx.py.interpreter.Interpreter.__init__(self, locals=locals, rawin=rawin, stdin=stdin, stdout=stdout, stderr=stderr, showInterpIntro=showInterpIntro) + + # The introductory text. + info = Info_box() + self.introText = info.intro_text() + + # The relax interpreter. + interp = interpreter.Interpreter(show_script=False, quit=False, raise_relax_error=True) + + # The locals. + self.locals = interp._locals