1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 """The relax prompt GUI element."""
24
25
26 import sys
27 import wx
28 import wx.py
29 import wx.stc as stc
30
31
32 from gui.icons import Relax_icons
33 from info import Info_box
34 from prompt import interpreter
35 from status import Status; status = Status()
36
37
39 """The relax prompt window object."""
40
42 """Set up the relax prompt."""
43
44
45 self.gui = kwds.pop('parent')
46
47
48 kwds["style"] = wx.DEFAULT_FRAME_STYLE
49 wx.Frame.__init__(self, *args, **kwds)
50
51
52 self.SetIcons(Relax_icons())
53
54
55 self.size_x = 1000
56 self.size_y = 500
57 self.border = 0
58
59
60 sizer = self.setup_frame()
61
62
63 self.add_shell(sizer)
64
65
66 status.observers.exec_lock.register('GUI prompt', self.enable, method_name='enable')
67
68
81
82
84 """Add the relax prompt to the sizer.
85
86 @param sizer: The sizer element to pack the relax prompt into.
87 @type sizer: wx.Sizer instance
88 """
89
90
91 self.prompt = wx.py.shell.Shell(self, InterpClass=InterpClass)
92
93
94 self.prompt.StyleSetBackground(style=stc.STC_STYLE_DEFAULT, back='white')
95 self.prompt.SetCaretForeground(fore="black")
96 self.prompt.StyleClearAll()
97 self.prompt.StyleSetSpec(stc.STC_STYLE_DEFAULT, "fore:black")
98 self.prompt.StyleSetSpec(stc.STC_P_COMMENTLINE, "fore:#0000ff")
99 self.prompt.StyleSetSpec(stc.STC_P_NUMBER, "fore:#125a0a")
100 self.prompt.StyleSetSpec(stc.STC_P_STRING, "fore:#ff00ff")
101 self.prompt.StyleSetSpec(stc.STC_P_CHARACTER, "fore:#ff00ff")
102 self.prompt.StyleSetSpec(stc.STC_P_WORD, "fore:#a52a2a")
103 self.prompt.StyleSetSpec(stc.STC_P_DEFNAME, "fore:#008b8b")
104 self.prompt.StyleSetSpec(stc.STC_P_CLASSNAME, "fore:#008b8b")
105
106
107 self.prompt.setFocus()
108
109
110 for name in ['exit', 'bye', 'quit', 'q']:
111 self.prompt.interp.locals[name] = _Exit(fn=self.gui.exit_gui)
112
113
114 sizer.Add(self.prompt, 1, wx.EXPAND|wx.ALL, self.border)
115
116
127
128
130 """Event handler for the close window action.
131
132 @param event: The wx event.
133 @type event: wx event
134 """
135
136
137 self.Hide()
138
139
141 """Set up the relax controller frame.
142
143 @return: The sizer object.
144 @rtype: wx.Sizer instance
145 """
146
147
148 self.SetTitle("The relax prompt")
149
150
151 sizer = wx.BoxSizer(wx.VERTICAL)
152 self.SetSizer(sizer)
153
154
155 self.Bind(wx.EVT_CLOSE, self.handler_close)
156
157
158 self.SetSize((self.size_x, self.size_y))
159
160
161 return sizer
162
163
166 """Store the exiting function.
167
168 @keyword fn: The exiting function.
169 @type fn: func
170 """
171
172
173 self.fn = fn
174
175
177 """Exit the program."""
178
179
180 self.fn()
181
182
183 return ''
184
185
187 - def __init__(self, locals=None, rawin=None, stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr, showInterpIntro=True):
188 """Redefine the interpreter."""
189
190
191 wx.py.interpreter.Interpreter.__init__(self, locals=locals, rawin=rawin, stdin=stdin, stdout=stdout, stderr=stderr, showInterpIntro=showInterpIntro)
192
193
194 info = Info_box()
195 self.introText = info.intro_text()
196
197
198 interp = interpreter.Interpreter(show_script=False, raise_relax_error=True)
199
200
201 self.locals = interp._locals
202