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 info import Info_box
33 from prompt import interpreter
34 from status import Status; status = Status()
35
36
37 from gui.icons import relax_icons
38
39
41 """The relax prompt window object."""
42
44 """Set up the relax prompt."""
45
46
47 self.gui = kwds.pop('parent')
48
49
50 kwds["style"] = wx.DEFAULT_FRAME_STYLE
51 wx.Frame.__init__(self, *args, **kwds)
52
53
54 self.SetIcons(relax_icons)
55
56
57 self.size_x = 1000
58 self.size_y = 500
59 self.border = 0
60
61
62 sizer = self.setup_frame()
63
64
65 self.add_shell(sizer)
66
67
68 status.observers.exec_lock.register('GUI prompt', self.enable, method_name='enable')
69
70
72 """Add the relax prompt to the sizer.
73
74 @param sizer: The sizer element to pack the relax prompt into.
75 @type sizer: wx.Sizer instance
76 """
77
78
79 self.prompt = wx.py.shell.Shell(self, InterpClass=InterpClass)
80
81
82 self.prompt.StyleSetBackground(style=stc.STC_STYLE_DEFAULT, back='white')
83 self.prompt.SetCaretForeground(fore="black")
84 self.prompt.StyleClearAll()
85 self.prompt.StyleSetSpec(stc.STC_STYLE_DEFAULT, "fore:black")
86 self.prompt.StyleSetSpec(stc.STC_P_COMMENTLINE, "fore:#0000ff")
87 self.prompt.StyleSetSpec(stc.STC_P_NUMBER, "fore:#125a0a")
88 self.prompt.StyleSetSpec(stc.STC_P_STRING, "fore:#ff00ff")
89 self.prompt.StyleSetSpec(stc.STC_P_CHARACTER, "fore:#ff00ff")
90 self.prompt.StyleSetSpec(stc.STC_P_WORD, "fore:#a52a2a")
91 self.prompt.StyleSetSpec(stc.STC_P_DEFNAME, "fore:#008b8b")
92 self.prompt.StyleSetSpec(stc.STC_P_CLASSNAME, "fore:#008b8b")
93
94
95 self.prompt.setFocus()
96
97
98 for name in ['exit', 'bye', 'quit', 'q']:
99 self.prompt.interp.locals[name] = _Exit(fn=self.gui.exit_gui)
100
101
102 sizer.Add(self.prompt, 1, wx.EXPAND|wx.ALL, self.border)
103
104
115
116
118 """Event handler for the close window action.
119
120 @param event: The wx event.
121 @type event: wx event
122 """
123
124
125 self.Hide()
126
127
129 """Set up the relax controller frame.
130
131 @return: The sizer object.
132 @rtype: wx.Sizer instance
133 """
134
135
136 self.SetTitle("The relax prompt")
137
138
139 sizer = wx.BoxSizer(wx.VERTICAL)
140 self.SetSizer(sizer)
141
142
143 self.Bind(wx.EVT_CLOSE, self.handler_close)
144
145
146 self.SetSize((self.size_x, self.size_y))
147
148
149 return sizer
150
151
154 """Store the exiting function.
155
156 @keyword fn: The exiting function.
157 @type fn: func
158 """
159
160
161 self.fn = fn
162
163
165 """Exit the program."""
166
167
168 self.fn()
169
170
171 return ''
172
173
175 - def __init__(self, locals=None, rawin=None, stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr, showInterpIntro=True):
176 """Redefine the interpreter."""
177
178
179 wx.py.interpreter.Interpreter.__init__(self, locals=locals, rawin=rawin, stdin=stdin, stdout=stdout, stderr=stderr, showInterpIntro=showInterpIntro)
180
181
182 info = Info_box()
183 self.introText = info.intro_text()
184
185
186 interp = interpreter.Interpreter(show_script=False, quit=False, raise_relax_error=True)
187
188
189 self.locals = interp._locals
190