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