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
70 """Add the relax prompt to the sizer.
71
72 @param sizer: The sizer element to pack the relax prompt into.
73 @type sizer: wx.Sizer instance
74 """
75
76
77 self.prompt = wx.py.shell.Shell(self, InterpClass=InterpClass)
78
79
80 self.prompt.StyleSetBackground(style=stc.STC_STYLE_DEFAULT, back='white')
81 self.prompt.SetCaretForeground(fore="black")
82 self.prompt.StyleClearAll()
83 self.prompt.StyleSetSpec(stc.STC_STYLE_DEFAULT, "fore:black")
84 self.prompt.StyleSetSpec(stc.STC_P_COMMENTLINE, "fore:#0000ff")
85 self.prompt.StyleSetSpec(stc.STC_P_NUMBER, "fore:#125a0a")
86 self.prompt.StyleSetSpec(stc.STC_P_STRING, "fore:#ff00ff")
87 self.prompt.StyleSetSpec(stc.STC_P_CHARACTER, "fore:#ff00ff")
88 self.prompt.StyleSetSpec(stc.STC_P_WORD, "fore:#a52a2a")
89 self.prompt.StyleSetSpec(stc.STC_P_DEFNAME, "fore:#008b8b")
90 self.prompt.StyleSetSpec(stc.STC_P_CLASSNAME, "fore:#008b8b")
91
92
93 self.prompt.setFocus()
94
95
96 for name in ['exit', 'bye', 'quit', 'q']:
97 self.prompt.interp.locals[name] = _Exit(fn=self.gui.exit_gui)
98
99
100 sizer.Add(self.prompt, 1, wx.EXPAND|wx.ALL, self.border)
101
102
113
114
116 """Event handler for the close window action.
117
118 @param event: The wx event.
119 @type event: wx event
120 """
121
122
123 self.Hide()
124
125
127 """Set up the relax controller frame.
128
129 @return: The sizer object.
130 @rtype: wx.Sizer instance
131 """
132
133
134 self.SetTitle("The relax prompt")
135
136
137 sizer = wx.BoxSizer(wx.VERTICAL)
138 self.SetSizer(sizer)
139
140
141 self.Bind(wx.EVT_CLOSE, self.handler_close)
142
143
144 self.SetSize((self.size_x, self.size_y))
145
146
147 return sizer
148
149
152 """Store the exiting function.
153
154 @keyword fn: The exiting function.
155 @type fn: func
156 """
157
158
159 self.fn = fn
160
161
163 """Exit the program."""
164
165
166 self.fn()
167
168
169 return ''
170
171
173 - def __init__(self, locals=None, rawin=None, stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr, showInterpIntro=True):
174 """Redefine the interpreter."""
175
176
177 wx.py.interpreter.Interpreter.__init__(self, locals=locals, rawin=rawin, stdin=stdin, stdout=stdout, stderr=stderr, showInterpIntro=showInterpIntro)
178
179
180 info = Info_box()
181 self.introText = info.intro_text()
182
183
184 interp = interpreter.Interpreter(show_script=False, quit=False, raise_relax_error=True)
185
186
187 self.locals = interp._locals
188