##// END OF EJS Templates
[gui/wx] added options save/restore for history widget
ldufrechou -
Show More
@@ -1,411 +1,475 b''
1 #!/usr/bin/python
1 #!/usr/bin/python
2 # -*- coding: iso-8859-15 -*-
2 # -*- coding: iso-8859-15 -*-
3 import wx
3 import wx
4 import wx.stc as stc
4 import wx.stc as stc
5 import keyword
5 import keyword
6
6
7 #-----------------------------------------
7 #-----------------------------------------
8 # History widget for IPython
8 # History widget for IPython
9 __version__ = 0.5
9 __version__ = 0.5
10 __author__ = "Laurent Dufrechou"
10 __author__ = "Laurent Dufrechou"
11 __email__ = "laurent.dufrechou _at_ gmail.com"
11 __email__ = "laurent.dufrechou _at_ gmail.com"
12 __license__ = "BSD"
12 __license__ = "BSD"
13 #-----------------------------------------
13 #-----------------------------------------
14 class IPythonHistoryPanel(wx.Panel):
14 class IPythonHistoryPanel(wx.Panel):
15
15
16 def __init__(self, parent,flt_empty=True,
16 def __init__(self, parent,flt_empty=True,
17 flt_doc=True,flt_cmd=True,flt_magic=True):
17 flt_doc=True,flt_cmd=True,flt_magic=True):
18
18
19 wx.Panel.__init__(self,parent,-1)
19 wx.Panel.__init__(self,parent,-1)
20 #text_ctrl = wx.TextCtrl(self, -1, style=wx.TE_MULTILINE)
20 #text_ctrl = wx.TextCtrl(self, -1, style=wx.TE_MULTILINE)
21 text_ctrl = PythonSTC(self, -1)
21 text_ctrl = PythonSTC(self, -1)
22
22
23
23
24 st_filt = wx.StaticText(self, -1, " Filter:")
24 st_filt = wx.StaticText(self, -1, " Filter:")
25
25
26 self.filter_empty = wx.CheckBox(self, -1, "Empty commands")
26 self.filter_empty = wx.CheckBox(self, -1, "Empty commands")
27 self.filter_doc = wx.CheckBox(self, -1, "?: Doc commands")
27 self.filter_doc = wx.CheckBox(self, -1, "?: Doc commands")
28 self.filter_cmd = wx.CheckBox(self, -1, "!: Sys commands")
28 self.filter_cmd = wx.CheckBox(self, -1, "!: Sys commands")
29 self.filter_magic = wx.CheckBox(self, -1, "%: Magic keys")
29 self.filter_magic = wx.CheckBox(self, -1, "%: Magic keys")
30
30
31 self.filter_empty.SetValue(flt_empty)
31 self.options={'filter_empty':{'value':'True',
32 self.filter_doc.SetValue(flt_doc)
32 'checkbox':self.filter_empty,'True':True,'False':False,
33 self.filter_cmd.SetValue(flt_cmd)
33 'setfunc':lambda x:None},
34 self.filter_magic.SetValue(flt_magic)
34 'filter_doc':{'value':'True',
35 'checkbox':self.filter_doc,'True':True,'False':False,
36 'setfunc':lambda x:None},
37 'filter_cmd':{'value':'True',
38 'checkbox':self.filter_cmd,'True':True,'False':False,
39 'setfunc':lambda x:None},
40 'filter_magic':{'value':'True',
41 'checkbox':self.filter_magic,'True':True,'False':False,
42 'setfunc':lambda x:None},
43 }
44 self.reloadOptions(self.options)
45
46 self.filter_empty.Bind(wx.EVT_CHECKBOX, self.evtCheckEmptyFilter)
47 self.filter_doc.Bind(wx.EVT_CHECKBOX, self.evtCheckDocFilter)
48 self.filter_cmd.Bind(wx.EVT_CHECKBOX, self.evtCheckCmdFilter)
49 self.filter_magic.Bind(wx.EVT_CHECKBOX, self.evtCheckMagicFilter)
50
51 #self.filter_empty.SetValue(flt_empty)
52 #self.filter_doc.SetValue(flt_doc)
53 #self.filter_cmd.SetValue(flt_cmd)
54 #self.filter_magic.SetValue(flt_magic)
35
55
36 sizer = wx.BoxSizer(wx.VERTICAL)
56 sizer = wx.BoxSizer(wx.VERTICAL)
37
57
38 sizer.Add(text_ctrl, 1, wx.EXPAND)
58 sizer.Add(text_ctrl, 1, wx.EXPAND)
39 sizer.AddMany( [(5,5),
59 sizer.AddMany( [(5,5),
40 st_filt,
60 st_filt,
41 (10,10),
61 (10,10),
42 self.filter_empty,
62 self.filter_empty,
43 self.filter_doc,
63 self.filter_doc,
44 self.filter_cmd,
64 self.filter_cmd,
45 self.filter_magic,
65 self.filter_magic,
46 (10,10),
66 (10,10),
47 ])
67 ])
48 self.SetAutoLayout(True)
68 self.SetAutoLayout(True)
49 sizer.Fit(self)
69 sizer.Fit(self)
50 sizer.SetSizeHints(self)
70 sizer.SetSizeHints(self)
51 self.SetSizer(sizer)
71 self.SetSizer(sizer)
52 self.text_ctrl=text_ctrl
72 self.text_ctrl=text_ctrl
53 #text_ctrl.SetText(demoText + open('Main.py').read())
73 #text_ctrl.SetText(demoText + open('Main.py').read())
54 text_ctrl.EmptyUndoBuffer()
74 text_ctrl.EmptyUndoBuffer()
55 text_ctrl.Colourise(0, -1)
75 text_ctrl.Colourise(0, -1)
56
76
57 # line numbers in the margin
77 # line numbers in the margin
58 text_ctrl.SetMarginType(1, stc.STC_MARGIN_NUMBER)
78 text_ctrl.SetMarginType(1, stc.STC_MARGIN_NUMBER)
59 text_ctrl.SetMarginWidth(1, 15)
79 text_ctrl.SetMarginWidth(1, 15)
60
80
61
81
62 def write(self,history_line):
82 def write(self,history_line):
63 add = True
83 add = True
64 if self.filter_empty.GetValue() == True and history_line == '':
84 if self.filter_empty.GetValue() == True and history_line == '':
65 add = False
85 add = False
66 if len(history_line)>0:
86 if len(history_line)>0:
67 if self.filter_doc.GetValue() == True and history_line[-1:] == '?':
87 if self.filter_doc.GetValue() == True and history_line[-1:] == '?':
68 add = False
88 add = False
69 if self.filter_cmd.GetValue() == True and history_line[0] == '!':
89 if self.filter_cmd.GetValue() == True and history_line[0] == '!':
70 add = False
90 add = False
71 if self.filter_magic.GetValue() == True and history_line[0] == '%':
91 if self.filter_magic.GetValue() == True and history_line[0] == '%':
72 add = False
92 add = False
73 if add:
93 if add:
74 self.text_ctrl.AppendText(history_line+'\n')
94 self.text_ctrl.AppendText(history_line+'\n')
75
95
96 #------------------------ Option Section -----------------------------------
97 def processOptionCheckedEvt(self, event, name):
98 if event.IsChecked():
99 self.options[name]['value']='True'
100 else:
101 self.options[name]['value']='False'
102 self.updateOptionTracker(name,
103 self.options[name]['value'])
104
105 def evtCheckEmptyFilter(self, event):
106 self.processOptionCheckedEvt(event, 'filter_empty')
107
108 def evtCheckDocFilter(self, event):
109 self.processOptionCheckedEvt(event, 'filter_doc')
110
111 def evtCheckCmdFilter(self, event):
112 self.processOptionCheckedEvt(event, 'filter_cmd')
76
113
114 def evtCheckMagicFilter(self, event):
115 self.processOptionCheckedEvt(event, 'filter_magic')
116
117 def getOptions(self):
118 return self.options
119
120 def reloadOptions(self,options):
121 self.options = options
122 for key in self.options.keys():
123 value = self.options[key]['value']
124 self.options[key]['checkbox'].SetValue(self.options[key][value])
125 self.options[key]['setfunc'](value)
126
127 #------------------------ Hook Section -----------------------------------
128 def updateOptionTracker(self,name,value):
129 '''
130 Default history tracker (does nothing)
131 '''
132 pass
133
134 def setOptionTrackerHook(self,func):
135 '''
136 Define a new history tracker
137 '''
138 self.updateOptionTracker = func
139
140
77 #----------------------------------------------------------------------
141 #----------------------------------------------------------------------
78 # Font definition for Styled Text Control
142 # Font definition for Styled Text Control
79
143
80 if wx.Platform == '__WXMSW__':
144 if wx.Platform == '__WXMSW__':
81 faces = { 'times': 'Times New Roman',
145 faces = { 'times': 'Times New Roman',
82 'mono' : 'Courier New',
146 'mono' : 'Courier New',
83 'helv' : 'Arial',
147 'helv' : 'Arial',
84 'other': 'Comic Sans MS',
148 'other': 'Comic Sans MS',
85 'size' : 8,
149 'size' : 8,
86 'size2': 6,
150 'size2': 6,
87 }
151 }
88 elif wx.Platform == '__WXMAC__':
152 elif wx.Platform == '__WXMAC__':
89 faces = { 'times': 'Times New Roman',
153 faces = { 'times': 'Times New Roman',
90 'mono' : 'Monaco',
154 'mono' : 'Monaco',
91 'helv' : 'Arial',
155 'helv' : 'Arial',
92 'other': 'Comic Sans MS',
156 'other': 'Comic Sans MS',
93 'size' : 8,
157 'size' : 8,
94 'size2': 6,
158 'size2': 6,
95 }
159 }
96 else:
160 else:
97 faces = { 'times': 'Times',
161 faces = { 'times': 'Times',
98 'mono' : 'Courier',
162 'mono' : 'Courier',
99 'helv' : 'Helvetica',
163 'helv' : 'Helvetica',
100 'other': 'new century schoolbook',
164 'other': 'new century schoolbook',
101 'size' : 8,
165 'size' : 8,
102 'size2': 6,
166 'size2': 6,
103 }
167 }
104
168
105
169
106 #----------------------------------------------------------------------
170 #----------------------------------------------------------------------
107
171
108 class PythonSTC(stc.StyledTextCtrl):
172 class PythonSTC(stc.StyledTextCtrl):
109
173
110 fold_symbols = 3
174 fold_symbols = 3
111
175
112 def __init__(self, parent, ID,
176 def __init__(self, parent, ID,
113 pos=wx.DefaultPosition, size=wx.DefaultSize,
177 pos=wx.DefaultPosition, size=wx.DefaultSize,
114 style=0):
178 style=0):
115 stc.StyledTextCtrl.__init__(self, parent, ID, pos, size, style)
179 stc.StyledTextCtrl.__init__(self, parent, ID, pos, size, style)
116 #self.CmdKeyAssign(ord('B'), stc.STC_SCMOD_CTRL, stc.STC_CMD_ZOOMIN)
180 #self.CmdKeyAssign(ord('B'), stc.STC_SCMOD_CTRL, stc.STC_CMD_ZOOMIN)
117 #self.CmdKeyAssign(ord('N'), stc.STC_SCMOD_CTRL, stc.STC_CMD_ZOOMOUT)
181 #self.CmdKeyAssign(ord('N'), stc.STC_SCMOD_CTRL, stc.STC_CMD_ZOOMOUT)
118
182
119 self.SetLexer(stc.STC_LEX_PYTHON)
183 self.SetLexer(stc.STC_LEX_PYTHON)
120 self.SetKeyWords(0, " ".join(keyword.kwlist))
184 self.SetKeyWords(0, " ".join(keyword.kwlist))
121
185
122 #self.SetProperty("fold", "1")
186 #self.SetProperty("fold", "1")
123 #self.SetProperty("tab.timmy.whinge.level", "1")
187 #self.SetProperty("tab.timmy.whinge.level", "1")
124 #self.SetMargins(0,0)
188 #self.SetMargins(0,0)
125
189
126 #self.SetViewWhiteSpace(False)
190 #self.SetViewWhiteSpace(False)
127 #self.SetBufferedDraw(False)
191 #self.SetBufferedDraw(False)
128 #self.SetViewEOL(True)
192 #self.SetViewEOL(True)
129 self.SetEOLMode(stc.STC_EOL_CRLF)
193 self.SetEOLMode(stc.STC_EOL_CRLF)
130 #self.SetUseAntiAliasing(True)
194 #self.SetUseAntiAliasing(True)
131
195
132 self.SetEdgeMode(stc.STC_EDGE_LINE)
196 self.SetEdgeMode(stc.STC_EDGE_LINE)
133 self.SetEdgeColumn(80)
197 self.SetEdgeColumn(80)
134 self.SetEdgeColour(wx.LIGHT_GREY)
198 self.SetEdgeColour(wx.LIGHT_GREY)
135 self.SetLayoutCache(stc.STC_CACHE_PAGE)
199 self.SetLayoutCache(stc.STC_CACHE_PAGE)
136
200
137 # Setup a margin to hold fold markers
201 # Setup a margin to hold fold markers
138 #self.SetFoldFlags(16) ### WHAT IS THIS VALUE? WHAT ARE THE OTHER FLAGS? DOES IT MATTER?
202 #self.SetFoldFlags(16) ### WHAT IS THIS VALUE? WHAT ARE THE OTHER FLAGS? DOES IT MATTER?
139 self.SetMarginType(2, stc.STC_MARGIN_SYMBOL)
203 self.SetMarginType(2, stc.STC_MARGIN_SYMBOL)
140 self.SetMarginMask(2, stc.STC_MASK_FOLDERS)
204 self.SetMarginMask(2, stc.STC_MASK_FOLDERS)
141 self.SetMarginSensitive(2, True)
205 self.SetMarginSensitive(2, True)
142 self.SetMarginWidth(2, 12)
206 self.SetMarginWidth(2, 12)
143
207
144 if self.fold_symbols == 0:
208 if self.fold_symbols == 0:
145 # Arrow pointing right for contracted folders, arrow pointing down for expanded
209 # Arrow pointing right for contracted folders, arrow pointing down for expanded
146 self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPEN, stc.STC_MARK_ARROWDOWN, "black", "black")
210 self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPEN, stc.STC_MARK_ARROWDOWN, "black", "black")
147 self.MarkerDefine(stc.STC_MARKNUM_FOLDER, stc.STC_MARK_ARROW, "black", "black")
211 self.MarkerDefine(stc.STC_MARKNUM_FOLDER, stc.STC_MARK_ARROW, "black", "black")
148 self.MarkerDefine(stc.STC_MARKNUM_FOLDERSUB, stc.STC_MARK_EMPTY, "black", "black")
212 self.MarkerDefine(stc.STC_MARKNUM_FOLDERSUB, stc.STC_MARK_EMPTY, "black", "black")
149 self.MarkerDefine(stc.STC_MARKNUM_FOLDERTAIL, stc.STC_MARK_EMPTY, "black", "black")
213 self.MarkerDefine(stc.STC_MARKNUM_FOLDERTAIL, stc.STC_MARK_EMPTY, "black", "black")
150 self.MarkerDefine(stc.STC_MARKNUM_FOLDEREND, stc.STC_MARK_EMPTY, "white", "black")
214 self.MarkerDefine(stc.STC_MARKNUM_FOLDEREND, stc.STC_MARK_EMPTY, "white", "black")
151 self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPENMID, stc.STC_MARK_EMPTY, "white", "black")
215 self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPENMID, stc.STC_MARK_EMPTY, "white", "black")
152 self.MarkerDefine(stc.STC_MARKNUM_FOLDERMIDTAIL, stc.STC_MARK_EMPTY, "white", "black")
216 self.MarkerDefine(stc.STC_MARKNUM_FOLDERMIDTAIL, stc.STC_MARK_EMPTY, "white", "black")
153
217
154 elif self.fold_symbols == 1:
218 elif self.fold_symbols == 1:
155 # Plus for contracted folders, minus for expanded
219 # Plus for contracted folders, minus for expanded
156 self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPEN, stc.STC_MARK_MINUS, "white", "black")
220 self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPEN, stc.STC_MARK_MINUS, "white", "black")
157 self.MarkerDefine(stc.STC_MARKNUM_FOLDER, stc.STC_MARK_PLUS, "white", "black")
221 self.MarkerDefine(stc.STC_MARKNUM_FOLDER, stc.STC_MARK_PLUS, "white", "black")
158 self.MarkerDefine(stc.STC_MARKNUM_FOLDERSUB, stc.STC_MARK_EMPTY, "white", "black")
222 self.MarkerDefine(stc.STC_MARKNUM_FOLDERSUB, stc.STC_MARK_EMPTY, "white", "black")
159 self.MarkerDefine(stc.STC_MARKNUM_FOLDERTAIL, stc.STC_MARK_EMPTY, "white", "black")
223 self.MarkerDefine(stc.STC_MARKNUM_FOLDERTAIL, stc.STC_MARK_EMPTY, "white", "black")
160 self.MarkerDefine(stc.STC_MARKNUM_FOLDEREND, stc.STC_MARK_EMPTY, "white", "black")
224 self.MarkerDefine(stc.STC_MARKNUM_FOLDEREND, stc.STC_MARK_EMPTY, "white", "black")
161 self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPENMID, stc.STC_MARK_EMPTY, "white", "black")
225 self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPENMID, stc.STC_MARK_EMPTY, "white", "black")
162 self.MarkerDefine(stc.STC_MARKNUM_FOLDERMIDTAIL, stc.STC_MARK_EMPTY, "white", "black")
226 self.MarkerDefine(stc.STC_MARKNUM_FOLDERMIDTAIL, stc.STC_MARK_EMPTY, "white", "black")
163
227
164 elif self.fold_symbols == 2:
228 elif self.fold_symbols == 2:
165 # Like a flattened tree control using circular headers and curved joins
229 # Like a flattened tree control using circular headers and curved joins
166 self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPEN, stc.STC_MARK_CIRCLEMINUS, "white", "#404040")
230 self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPEN, stc.STC_MARK_CIRCLEMINUS, "white", "#404040")
167 self.MarkerDefine(stc.STC_MARKNUM_FOLDER, stc.STC_MARK_CIRCLEPLUS, "white", "#404040")
231 self.MarkerDefine(stc.STC_MARKNUM_FOLDER, stc.STC_MARK_CIRCLEPLUS, "white", "#404040")
168 self.MarkerDefine(stc.STC_MARKNUM_FOLDERSUB, stc.STC_MARK_VLINE, "white", "#404040")
232 self.MarkerDefine(stc.STC_MARKNUM_FOLDERSUB, stc.STC_MARK_VLINE, "white", "#404040")
169 self.MarkerDefine(stc.STC_MARKNUM_FOLDERTAIL, stc.STC_MARK_LCORNERCURVE, "white", "#404040")
233 self.MarkerDefine(stc.STC_MARKNUM_FOLDERTAIL, stc.STC_MARK_LCORNERCURVE, "white", "#404040")
170 self.MarkerDefine(stc.STC_MARKNUM_FOLDEREND, stc.STC_MARK_CIRCLEPLUSCONNECTED, "white", "#404040")
234 self.MarkerDefine(stc.STC_MARKNUM_FOLDEREND, stc.STC_MARK_CIRCLEPLUSCONNECTED, "white", "#404040")
171 self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPENMID, stc.STC_MARK_CIRCLEMINUSCONNECTED, "white", "#404040")
235 self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPENMID, stc.STC_MARK_CIRCLEMINUSCONNECTED, "white", "#404040")
172 self.MarkerDefine(stc.STC_MARKNUM_FOLDERMIDTAIL, stc.STC_MARK_TCORNERCURVE, "white", "#404040")
236 self.MarkerDefine(stc.STC_MARKNUM_FOLDERMIDTAIL, stc.STC_MARK_TCORNERCURVE, "white", "#404040")
173
237
174 elif self.fold_symbols == 3:
238 elif self.fold_symbols == 3:
175 # Like a flattened tree control using square headers
239 # Like a flattened tree control using square headers
176 self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPEN, stc.STC_MARK_BOXMINUS, "white", "#808080")
240 self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPEN, stc.STC_MARK_BOXMINUS, "white", "#808080")
177 self.MarkerDefine(stc.STC_MARKNUM_FOLDER, stc.STC_MARK_BOXPLUS, "white", "#808080")
241 self.MarkerDefine(stc.STC_MARKNUM_FOLDER, stc.STC_MARK_BOXPLUS, "white", "#808080")
178 self.MarkerDefine(stc.STC_MARKNUM_FOLDERSUB, stc.STC_MARK_VLINE, "white", "#808080")
242 self.MarkerDefine(stc.STC_MARKNUM_FOLDERSUB, stc.STC_MARK_VLINE, "white", "#808080")
179 self.MarkerDefine(stc.STC_MARKNUM_FOLDERTAIL, stc.STC_MARK_LCORNER, "white", "#808080")
243 self.MarkerDefine(stc.STC_MARKNUM_FOLDERTAIL, stc.STC_MARK_LCORNER, "white", "#808080")
180 self.MarkerDefine(stc.STC_MARKNUM_FOLDEREND, stc.STC_MARK_BOXPLUSCONNECTED, "white", "#808080")
244 self.MarkerDefine(stc.STC_MARKNUM_FOLDEREND, stc.STC_MARK_BOXPLUSCONNECTED, "white", "#808080")
181 self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPENMID, stc.STC_MARK_BOXMINUSCONNECTED, "white", "#808080")
245 self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPENMID, stc.STC_MARK_BOXMINUSCONNECTED, "white", "#808080")
182 self.MarkerDefine(stc.STC_MARKNUM_FOLDERMIDTAIL, stc.STC_MARK_TCORNER, "white", "#808080")
246 self.MarkerDefine(stc.STC_MARKNUM_FOLDERMIDTAIL, stc.STC_MARK_TCORNER, "white", "#808080")
183
247
184
248
185 self.Bind(stc.EVT_STC_UPDATEUI, self.OnUpdateUI)
249 self.Bind(stc.EVT_STC_UPDATEUI, self.OnUpdateUI)
186 self.Bind(stc.EVT_STC_MARGINCLICK, self.OnMarginClick)
250 self.Bind(stc.EVT_STC_MARGINCLICK, self.OnMarginClick)
187 self.Bind(wx.EVT_KEY_DOWN, self.OnKeyPressed)
251 self.Bind(wx.EVT_KEY_DOWN, self.OnKeyPressed)
188
252
189 # Make some styles, The lexer defines what each style is used for, we
253 # Make some styles, The lexer defines what each style is used for, we
190 # just have to define what each style looks like. This set is adapted from
254 # just have to define what each style looks like. This set is adapted from
191 # Scintilla sample property files.
255 # Scintilla sample property files.
192
256
193 # Global default styles for all languages
257 # Global default styles for all languages
194 self.StyleSetSpec(stc.STC_STYLE_DEFAULT, "face:%(helv)s,size:%(size)d" % faces)
258 self.StyleSetSpec(stc.STC_STYLE_DEFAULT, "face:%(helv)s,size:%(size)d" % faces)
195 self.StyleClearAll() # Reset all to be like the default
259 self.StyleClearAll() # Reset all to be like the default
196
260
197 # Global default styles for all languages
261 # Global default styles for all languages
198 self.StyleSetSpec(stc.STC_STYLE_DEFAULT, "face:%(helv)s,size:%(size)d" % faces)
262 self.StyleSetSpec(stc.STC_STYLE_DEFAULT, "face:%(helv)s,size:%(size)d" % faces)
199 self.StyleSetSpec(stc.STC_STYLE_LINENUMBER, "back:#C0C0C0,face:%(helv)s,size:%(size2)d" % faces)
263 self.StyleSetSpec(stc.STC_STYLE_LINENUMBER, "back:#C0C0C0,face:%(helv)s,size:%(size2)d" % faces)
200 self.StyleSetSpec(stc.STC_STYLE_CONTROLCHAR, "face:%(other)s" % faces)
264 self.StyleSetSpec(stc.STC_STYLE_CONTROLCHAR, "face:%(other)s" % faces)
201 self.StyleSetSpec(stc.STC_STYLE_BRACELIGHT, "fore:#FFFFFF,back:#0000FF,bold")
265 self.StyleSetSpec(stc.STC_STYLE_BRACELIGHT, "fore:#FFFFFF,back:#0000FF,bold")
202 self.StyleSetSpec(stc.STC_STYLE_BRACEBAD, "fore:#000000,back:#FF0000,bold")
266 self.StyleSetSpec(stc.STC_STYLE_BRACEBAD, "fore:#000000,back:#FF0000,bold")
203
267
204 # Python styles
268 # Python styles
205 # Default
269 # Default
206 self.StyleSetSpec(stc.STC_P_DEFAULT, "fore:#000000,face:%(helv)s,size:%(size)d" % faces)
270 self.StyleSetSpec(stc.STC_P_DEFAULT, "fore:#000000,face:%(helv)s,size:%(size)d" % faces)
207 # Comments
271 # Comments
208 self.StyleSetSpec(stc.STC_P_COMMENTLINE, "fore:#007F00,face:%(other)s,size:%(size)d" % faces)
272 self.StyleSetSpec(stc.STC_P_COMMENTLINE, "fore:#007F00,face:%(other)s,size:%(size)d" % faces)
209 # Number
273 # Number
210 self.StyleSetSpec(stc.STC_P_NUMBER, "fore:#007F7F,size:%(size)d" % faces)
274 self.StyleSetSpec(stc.STC_P_NUMBER, "fore:#007F7F,size:%(size)d" % faces)
211 # String
275 # String
212 self.StyleSetSpec(stc.STC_P_STRING, "fore:#7F007F,face:%(helv)s,size:%(size)d" % faces)
276 self.StyleSetSpec(stc.STC_P_STRING, "fore:#7F007F,face:%(helv)s,size:%(size)d" % faces)
213 # Single quoted string
277 # Single quoted string
214 self.StyleSetSpec(stc.STC_P_CHARACTER, "fore:#7F007F,face:%(helv)s,size:%(size)d" % faces)
278 self.StyleSetSpec(stc.STC_P_CHARACTER, "fore:#7F007F,face:%(helv)s,size:%(size)d" % faces)
215 # Keyword
279 # Keyword
216 self.StyleSetSpec(stc.STC_P_WORD, "fore:#00007F,bold,size:%(size)d" % faces)
280 self.StyleSetSpec(stc.STC_P_WORD, "fore:#00007F,bold,size:%(size)d" % faces)
217 # Triple quotes
281 # Triple quotes
218 self.StyleSetSpec(stc.STC_P_TRIPLE, "fore:#7F0000,size:%(size)d" % faces)
282 self.StyleSetSpec(stc.STC_P_TRIPLE, "fore:#7F0000,size:%(size)d" % faces)
219 # Triple double quotes
283 # Triple double quotes
220 self.StyleSetSpec(stc.STC_P_TRIPLEDOUBLE, "fore:#7F0000,size:%(size)d" % faces)
284 self.StyleSetSpec(stc.STC_P_TRIPLEDOUBLE, "fore:#7F0000,size:%(size)d" % faces)
221 # Class name definition
285 # Class name definition
222 self.StyleSetSpec(stc.STC_P_CLASSNAME, "fore:#0000FF,bold,underline,size:%(size)d" % faces)
286 self.StyleSetSpec(stc.STC_P_CLASSNAME, "fore:#0000FF,bold,underline,size:%(size)d" % faces)
223 # Function or method name definition
287 # Function or method name definition
224 self.StyleSetSpec(stc.STC_P_DEFNAME, "fore:#007F7F,bold,size:%(size)d" % faces)
288 self.StyleSetSpec(stc.STC_P_DEFNAME, "fore:#007F7F,bold,size:%(size)d" % faces)
225 # Operators
289 # Operators
226 self.StyleSetSpec(stc.STC_P_OPERATOR, "bold,size:%(size)d" % faces)
290 self.StyleSetSpec(stc.STC_P_OPERATOR, "bold,size:%(size)d" % faces)
227 # Identifiers
291 # Identifiers
228 self.StyleSetSpec(stc.STC_P_IDENTIFIER, "fore:#000000,face:%(helv)s,size:%(size)d" % faces)
292 self.StyleSetSpec(stc.STC_P_IDENTIFIER, "fore:#000000,face:%(helv)s,size:%(size)d" % faces)
229 # Comment-blocks
293 # Comment-blocks
230 self.StyleSetSpec(stc.STC_P_COMMENTBLOCK, "fore:#7F7F7F,size:%(size)d" % faces)
294 self.StyleSetSpec(stc.STC_P_COMMENTBLOCK, "fore:#7F7F7F,size:%(size)d" % faces)
231 # End of line where string is not closed
295 # End of line where string is not closed
232 self.StyleSetSpec(stc.STC_P_STRINGEOL, "fore:#000000,face:%(mono)s,back:#E0C0E0,eol,size:%(size)d" % faces)
296 self.StyleSetSpec(stc.STC_P_STRINGEOL, "fore:#000000,face:%(mono)s,back:#E0C0E0,eol,size:%(size)d" % faces)
233
297
234 self.SetCaretForeground("BLUE")
298 self.SetCaretForeground("BLUE")
235
299
236
300
237 # register some images for use in the AutoComplete box.
301 # register some images for use in the AutoComplete box.
238 #self.RegisterImage(1, images.getSmilesBitmap())
302 #self.RegisterImage(1, images.getSmilesBitmap())
239 #self.RegisterImage(2,
303 #self.RegisterImage(2,
240 # wx.ArtProvider.GetBitmap(wx.ART_NEW, size=(16,16)))
304 # wx.ArtProvider.GetBitmap(wx.ART_NEW, size=(16,16)))
241 #self.RegisterImage(3,
305 #self.RegisterImage(3,
242 # wx.ArtProvider.GetBitmap(wx.ART_COPY, size=(16,16)))
306 # wx.ArtProvider.GetBitmap(wx.ART_COPY, size=(16,16)))
243
307
244
308
245 def OnKeyPressed(self, event):
309 def OnKeyPressed(self, event):
246 if self.CallTipActive():
310 if self.CallTipActive():
247 self.CallTipCancel()
311 self.CallTipCancel()
248 key = event.GetKeyCode()
312 key = event.GetKeyCode()
249
313
250 if key == 32 and event.ControlDown():
314 if key == 32 and event.ControlDown():
251 pos = self.GetCurrentPos()
315 pos = self.GetCurrentPos()
252
316
253 # Tips
317 # Tips
254 if event.ShiftDown():
318 if event.ShiftDown():
255 self.CallTipSetBackground("yellow")
319 self.CallTipSetBackground("yellow")
256 self.CallTipShow(pos, 'lots of of text: blah, blah, blah\n\n'
320 self.CallTipShow(pos, 'lots of of text: blah, blah, blah\n\n'
257 'show some suff, maybe parameters..\n\n'
321 'show some suff, maybe parameters..\n\n'
258 'fubar(param1, param2)')
322 'fubar(param1, param2)')
259 # Code completion
323 # Code completion
260 else:
324 else:
261 #lst = []
325 #lst = []
262 #for x in range(50000):
326 #for x in range(50000):
263 # lst.append('%05d' % x)
327 # lst.append('%05d' % x)
264 #st = " ".join(lst)
328 #st = " ".join(lst)
265 #print len(st)
329 #print len(st)
266 #self.AutoCompShow(0, st)
330 #self.AutoCompShow(0, st)
267
331
268 kw = keyword.kwlist[:]
332 kw = keyword.kwlist[:]
269
333
270 kw.sort() # Python sorts are case sensitive
334 kw.sort() # Python sorts are case sensitive
271 self.AutoCompSetIgnoreCase(False) # so this needs to match
335 self.AutoCompSetIgnoreCase(False) # so this needs to match
272
336
273 # Images are specified with a appended "?type"
337 # Images are specified with a appended "?type"
274 for i in range(len(kw)):
338 for i in range(len(kw)):
275 if kw[i] in keyword.kwlist:
339 if kw[i] in keyword.kwlist:
276 kw[i] = kw[i]# + "?1"
340 kw[i] = kw[i]# + "?1"
277
341
278 self.AutoCompShow(0, " ".join(kw))
342 self.AutoCompShow(0, " ".join(kw))
279 else:
343 else:
280 event.Skip()
344 event.Skip()
281
345
282
346
283 def OnUpdateUI(self, evt):
347 def OnUpdateUI(self, evt):
284 # check for matching braces
348 # check for matching braces
285 braceAtCaret = -1
349 braceAtCaret = -1
286 braceOpposite = -1
350 braceOpposite = -1
287 charBefore = None
351 charBefore = None
288 caretPos = self.GetCurrentPos()
352 caretPos = self.GetCurrentPos()
289
353
290 if caretPos > 0:
354 if caretPos > 0:
291 charBefore = self.GetCharAt(caretPos - 1)
355 charBefore = self.GetCharAt(caretPos - 1)
292 styleBefore = self.GetStyleAt(caretPos - 1)
356 styleBefore = self.GetStyleAt(caretPos - 1)
293
357
294 # check before
358 # check before
295 if charBefore and chr(charBefore) in "[]{}()" and styleBefore == stc.STC_P_OPERATOR:
359 if charBefore and chr(charBefore) in "[]{}()" and styleBefore == stc.STC_P_OPERATOR:
296 braceAtCaret = caretPos - 1
360 braceAtCaret = caretPos - 1
297
361
298 # check after
362 # check after
299 if braceAtCaret < 0:
363 if braceAtCaret < 0:
300 charAfter = self.GetCharAt(caretPos)
364 charAfter = self.GetCharAt(caretPos)
301 styleAfter = self.GetStyleAt(caretPos)
365 styleAfter = self.GetStyleAt(caretPos)
302
366
303 if charAfter and chr(charAfter) in "[]{}()" and styleAfter == stc.STC_P_OPERATOR:
367 if charAfter and chr(charAfter) in "[]{}()" and styleAfter == stc.STC_P_OPERATOR:
304 braceAtCaret = caretPos
368 braceAtCaret = caretPos
305
369
306 if braceAtCaret >= 0:
370 if braceAtCaret >= 0:
307 braceOpposite = self.BraceMatch(braceAtCaret)
371 braceOpposite = self.BraceMatch(braceAtCaret)
308
372
309 if braceAtCaret != -1 and braceOpposite == -1:
373 if braceAtCaret != -1 and braceOpposite == -1:
310 self.BraceBadLight(braceAtCaret)
374 self.BraceBadLight(braceAtCaret)
311 else:
375 else:
312 self.BraceHighlight(braceAtCaret, braceOpposite)
376 self.BraceHighlight(braceAtCaret, braceOpposite)
313 #pt = self.PointFromPosition(braceOpposite)
377 #pt = self.PointFromPosition(braceOpposite)
314 #self.Refresh(True, wxRect(pt.x, pt.y, 5,5))
378 #self.Refresh(True, wxRect(pt.x, pt.y, 5,5))
315 #print pt
379 #print pt
316 #self.Refresh(False)
380 #self.Refresh(False)
317
381
318
382
319 def OnMarginClick(self, evt):
383 def OnMarginClick(self, evt):
320 # fold and unfold as needed
384 # fold and unfold as needed
321 if evt.GetMargin() == 2:
385 if evt.GetMargin() == 2:
322 if evt.GetShift() and evt.GetControl():
386 if evt.GetShift() and evt.GetControl():
323 self.FoldAll()
387 self.FoldAll()
324 else:
388 else:
325 lineClicked = self.LineFromPosition(evt.GetPosition())
389 lineClicked = self.LineFromPosition(evt.GetPosition())
326
390
327 if self.GetFoldLevel(lineClicked) & stc.STC_FOLDLEVELHEADERFLAG:
391 if self.GetFoldLevel(lineClicked) & stc.STC_FOLDLEVELHEADERFLAG:
328 if evt.GetShift():
392 if evt.GetShift():
329 self.SetFoldExpanded(lineClicked, True)
393 self.SetFoldExpanded(lineClicked, True)
330 self.Expand(lineClicked, True, True, 1)
394 self.Expand(lineClicked, True, True, 1)
331 elif evt.GetControl():
395 elif evt.GetControl():
332 if self.GetFoldExpanded(lineClicked):
396 if self.GetFoldExpanded(lineClicked):
333 self.SetFoldExpanded(lineClicked, False)
397 self.SetFoldExpanded(lineClicked, False)
334 self.Expand(lineClicked, False, True, 0)
398 self.Expand(lineClicked, False, True, 0)
335 else:
399 else:
336 self.SetFoldExpanded(lineClicked, True)
400 self.SetFoldExpanded(lineClicked, True)
337 self.Expand(lineClicked, True, True, 100)
401 self.Expand(lineClicked, True, True, 100)
338 else:
402 else:
339 self.ToggleFold(lineClicked)
403 self.ToggleFold(lineClicked)
340
404
341
405
342 def FoldAll(self):
406 def FoldAll(self):
343 lineCount = self.GetLineCount()
407 lineCount = self.GetLineCount()
344 expanding = True
408 expanding = True
345
409
346 # find out if we are folding or unfolding
410 # find out if we are folding or unfolding
347 for lineNum in range(lineCount):
411 for lineNum in range(lineCount):
348 if self.GetFoldLevel(lineNum) & stc.STC_FOLDLEVELHEADERFLAG:
412 if self.GetFoldLevel(lineNum) & stc.STC_FOLDLEVELHEADERFLAG:
349 expanding = not self.GetFoldExpanded(lineNum)
413 expanding = not self.GetFoldExpanded(lineNum)
350 break
414 break
351
415
352 lineNum = 0
416 lineNum = 0
353
417
354 while lineNum < lineCount:
418 while lineNum < lineCount:
355 level = self.GetFoldLevel(lineNum)
419 level = self.GetFoldLevel(lineNum)
356 if level & stc.STC_FOLDLEVELHEADERFLAG and \
420 if level & stc.STC_FOLDLEVELHEADERFLAG and \
357 (level & stc.STC_FOLDLEVELNUMBERMASK) == stc.STC_FOLDLEVELBASE:
421 (level & stc.STC_FOLDLEVELNUMBERMASK) == stc.STC_FOLDLEVELBASE:
358
422
359 if expanding:
423 if expanding:
360 self.SetFoldExpanded(lineNum, True)
424 self.SetFoldExpanded(lineNum, True)
361 lineNum = self.Expand(lineNum, True)
425 lineNum = self.Expand(lineNum, True)
362 lineNum = lineNum - 1
426 lineNum = lineNum - 1
363 else:
427 else:
364 lastChild = self.GetLastChild(lineNum, -1)
428 lastChild = self.GetLastChild(lineNum, -1)
365 self.SetFoldExpanded(lineNum, False)
429 self.SetFoldExpanded(lineNum, False)
366
430
367 if lastChild > lineNum:
431 if lastChild > lineNum:
368 self.HideLines(lineNum+1, lastChild)
432 self.HideLines(lineNum+1, lastChild)
369
433
370 lineNum = lineNum + 1
434 lineNum = lineNum + 1
371
435
372
436
373
437
374 def Expand(self, line, doExpand, force=False, visLevels=0, level=-1):
438 def Expand(self, line, doExpand, force=False, visLevels=0, level=-1):
375 lastChild = self.GetLastChild(line, level)
439 lastChild = self.GetLastChild(line, level)
376 line = line + 1
440 line = line + 1
377
441
378 while line <= lastChild:
442 while line <= lastChild:
379 if force:
443 if force:
380 if visLevels > 0:
444 if visLevels > 0:
381 self.ShowLines(line, line)
445 self.ShowLines(line, line)
382 else:
446 else:
383 self.HideLines(line, line)
447 self.HideLines(line, line)
384 else:
448 else:
385 if doExpand:
449 if doExpand:
386 self.ShowLines(line, line)
450 self.ShowLines(line, line)
387
451
388 if level == -1:
452 if level == -1:
389 level = self.GetFoldLevel(line)
453 level = self.GetFoldLevel(line)
390
454
391 if level & stc.STC_FOLDLEVELHEADERFLAG:
455 if level & stc.STC_FOLDLEVELHEADERFLAG:
392 if force:
456 if force:
393 if visLevels > 1:
457 if visLevels > 1:
394 self.SetFoldExpanded(line, True)
458 self.SetFoldExpanded(line, True)
395 else:
459 else:
396 self.SetFoldExpanded(line, False)
460 self.SetFoldExpanded(line, False)
397
461
398 line = self.Expand(line, doExpand, force, visLevels-1)
462 line = self.Expand(line, doExpand, force, visLevels-1)
399
463
400 else:
464 else:
401 if doExpand and self.GetFoldExpanded(line):
465 if doExpand and self.GetFoldExpanded(line):
402 line = self.Expand(line, True, force, visLevels-1)
466 line = self.Expand(line, True, force, visLevels-1)
403 else:
467 else:
404 line = self.Expand(line, False, force, visLevels-1)
468 line = self.Expand(line, False, force, visLevels-1)
405 else:
469 else:
406 line = line + 1
470 line = line + 1
407
471
408 return line
472 return line
409
473
410
474
411 #----------------------------------------------------------------------
475 #----------------------------------------------------------------------
@@ -1,2 +1,6 b''
1 completion=IPYTHON
1 completion=IPYTHON
2 background_color=BLACK
2 background_color=BLACK
3 filter_empty=True
4 filter_magic=True
5 filter_doc=True
6 filter_cmd=True
@@ -1,225 +1,240 b''
1 #!/usr/bin/python
1 #!/usr/bin/python
2 # -*- coding: iso-8859-15 -*-
2 # -*- coding: iso-8859-15 -*-
3
3
4 import wx.aui
4 import wx.aui
5
5
6 #used for about dialog
6 #used for about dialog
7 from wx.lib.wordwrap import wordwrap
7 from wx.lib.wordwrap import wordwrap
8
8
9 #used for ipython GUI objects
9 #used for ipython GUI objects
10 from IPython.gui.wx.ipython_view import IPShellWidget
10 from IPython.gui.wx.ipython_view import IPShellWidget
11 from IPython.gui.wx.ipython_history import IPythonHistoryPanel
11 from IPython.gui.wx.ipython_history import IPythonHistoryPanel
12
12
13 __version__ = 0.8
13 __version__ = 0.8
14 __author__ = "Laurent Dufrechou"
14 __author__ = "Laurent Dufrechou"
15 __email__ = "laurent.dufrechou _at_ gmail.com"
15 __email__ = "laurent.dufrechou _at_ gmail.com"
16 __license__ = "BSD"
16 __license__ = "BSD"
17
17
18 #-----------------------------------------
18 #-----------------------------------------
19 # Creating one main frame for our
19 # Creating one main frame for our
20 # application with movables windows
20 # application with movables windows
21 #-----------------------------------------
21 #-----------------------------------------
22 class MyFrame(wx.Frame):
22 class MyFrame(wx.Frame):
23 """Creating one main frame for our
23 """Creating one main frame for our
24 application with movables windows"""
24 application with movables windows"""
25 def __init__(self, parent=None, id=-1, title="WxIPython",
25 def __init__(self, parent=None, id=-1, title="WxIPython",
26 pos=wx.DefaultPosition,
26 pos=wx.DefaultPosition,
27 size=(800, 600), style=wx.DEFAULT_FRAME_STYLE):
27 size=(800, 600), style=wx.DEFAULT_FRAME_STYLE):
28 wx.Frame.__init__(self, parent, id, title, pos, size, style)
28 wx.Frame.__init__(self, parent, id, title, pos, size, style)
29 self._mgr = wx.aui.AuiManager()
29 self._mgr = wx.aui.AuiManager()
30
30
31 # notify PyAUI which frame to use
31 # notify PyAUI which frame to use
32 self._mgr.SetManagedWindow(self)
32 self._mgr.SetManagedWindow(self)
33
33
34 #create differents panels and make them persistant
34 #create differents panels and make them persistant
35 self.history_panel = IPythonHistoryPanel(self)
35 self.history_panel = IPythonHistoryPanel(self)
36
37 self.history_panel.setOptionTrackerHook(self.optionSave)
36
38
37 self.ipython_panel = IPShellWidget(self,background_color = "BLACK")
39 self.ipython_panel = IPShellWidget(self,background_color = "BLACK")
38
39 #self.ipython_panel = IPShellWidget(self,background_color = "WHITE")
40 #self.ipython_panel = IPShellWidget(self,background_color = "WHITE")
40
41
41 self.ipython_panel.setHistoryTrackerHook(self.history_panel.write)
42 self.ipython_panel.setHistoryTrackerHook(self.history_panel.write)
42 self.ipython_panel.setStatusTrackerHook(self.updateStatus)
43 self.ipython_panel.setStatusTrackerHook(self.updateStatus)
43 self.ipython_panel.setAskExitHandler(self.OnExitDlg)
44 self.ipython_panel.setAskExitHandler(self.OnExitDlg)
44 self.ipython_panel.setOptionTrackerHook(self.optionSave)
45 self.ipython_panel.setOptionTrackerHook(self.optionSave)
45 self.optionLoad()
46
46
47 self.optionLoad()
47
48
48 self.statusbar = self.createStatus()
49 self.statusbar = self.createStatus()
49 self.createMenu()
50 self.createMenu()
50
51
51 ########################################################################
52 ########################################################################
52 ### add the panes to the manager
53 ### add the panes to the manager
53 # main panels
54 # main panels
54 self._mgr.AddPane(self.ipython_panel , wx.CENTER, "IPython Shell")
55 self._mgr.AddPane(self.ipython_panel , wx.CENTER, "IPython Shell")
55 self._mgr.AddPane(self.history_panel , wx.RIGHT, "IPython history")
56 self._mgr.AddPane(self.history_panel , wx.RIGHT, "IPython history")
56
57
57 # now we specify some panel characteristics
58 # now we specify some panel characteristics
58 self._mgr.GetPane(self.ipython_panel).CaptionVisible(True);
59 self._mgr.GetPane(self.ipython_panel).CaptionVisible(True);
59 self._mgr.GetPane(self.history_panel).CaptionVisible(True);
60 self._mgr.GetPane(self.history_panel).CaptionVisible(True);
60 self._mgr.GetPane(self.history_panel).MinSize((200,400));
61 self._mgr.GetPane(self.history_panel).MinSize((200,400));
61
62
62 # tell the manager to "commit" all the changes just made
63 # tell the manager to "commit" all the changes just made
63 self._mgr.Update()
64 self._mgr.Update()
64
65
65 #global event handling
66 #global event handling
66 self.Bind(wx.EVT_CLOSE, self.OnClose)
67 self.Bind(wx.EVT_CLOSE, self.OnClose)
67 self.Bind(wx.EVT_MENU, self.OnClose,id=wx.ID_EXIT)
68 self.Bind(wx.EVT_MENU, self.OnClose,id=wx.ID_EXIT)
68 self.Bind(wx.EVT_MENU, self.OnShowIPythonPanel,id=wx.ID_HIGHEST+1)
69 self.Bind(wx.EVT_MENU, self.OnShowIPythonPanel,id=wx.ID_HIGHEST+1)
69 self.Bind(wx.EVT_MENU, self.OnShowHistoryPanel,id=wx.ID_HIGHEST+2)
70 self.Bind(wx.EVT_MENU, self.OnShowHistoryPanel,id=wx.ID_HIGHEST+2)
70 self.Bind(wx.EVT_MENU, self.OnShowAbout, id=wx.ID_HIGHEST+3)
71 self.Bind(wx.EVT_MENU, self.OnShowAbout, id=wx.ID_HIGHEST+3)
71 self.Bind(wx.EVT_MENU, self.OnShowAllPanel,id=wx.ID_HIGHEST+6)
72 self.Bind(wx.EVT_MENU, self.OnShowAllPanel,id=wx.ID_HIGHEST+6)
72
73
73 warn_text = 'Hello from IPython and wxPython.\n'
74 warn_text = 'Hello from IPython and wxPython.\n'
74 warn_text +='Please Note that this work is still EXPERIMENTAL\n'
75 warn_text +='Please Note that this work is still EXPERIMENTAL\n'
75 warn_text +='It does NOT emulate currently all the IPython functions.\n'
76 warn_text +='It does NOT emulate currently all the IPython functions.\n'
76
77
77 dlg = wx.MessageDialog(self,
78 dlg = wx.MessageDialog(self,
78 warn_text,
79 warn_text,
79 'Warning Box',
80 'Warning Box',
80 wx.OK | wx.ICON_INFORMATION
81 wx.OK | wx.ICON_INFORMATION
81 )
82 )
82 dlg.ShowModal()
83 dlg.ShowModal()
83 dlg.Destroy()
84 dlg.Destroy()
84
85
85 def optionSave(self, name, value):
86 def optionSave(self, name, value):
86 opt = open('options.conf','w')
87 opt = open('options.conf','w')
87 options = self.ipython_panel.getOptions()
88
88 for key in options.keys():
89 try:
89 opt.write(key + '=' + options[key]['value']+'\n')
90 options_ipython_panel = self.ipython_panel.getOptions()
90 opt.close()
91 options_history_panel = self.history_panel.getOptions()
92
93 for key in options_ipython_panel.keys():
94 opt.write(key + '=' + options_ipython_panel[key]['value']+'\n')
95 for key in options_history_panel.keys():
96 opt.write(key + '=' + options_history_panel[key]['value']+'\n')
97 finally:
98 opt.close()
91
99
92 def optionLoad(self):
100 def optionLoad(self):
93 opt = open('options.conf','r')
101 opt = open('options.conf','r')
94 lines = opt.readlines()
102 lines = opt.readlines()
95 opt.close()
103 opt.close()
96
104
97 options = self.ipython_panel.getOptions()
105 options_ipython_panel = self.ipython_panel.getOptions()
106 options_history_panel = self.history_panel.getOptions()
98
107
99 for line in lines:
108 for line in lines:
100 key = line.split('=')[0]
109 key = line.split('=')[0]
101 value = line.split('=')[1].replace('\n','').replace('\r','')
110 value = line.split('=')[1].replace('\n','').replace('\r','')
102 options[key]['value'] = value
111 if key in options_ipython_panel.keys():
103 self.ipython_panel.reloadOptions(options)
112 options_ipython_panel[key]['value'] = value
113 elif key in options_history_panel.keys():
114 options_history_panel[key]['value'] = value
115 else:
116 print >>sys.__stdout__,"Warning: key ",key,"not found in widget options. Check Options.conf"
117 self.ipython_panel.reloadOptions(options_ipython_panel)
118 self.history_panel.reloadOptions(options_history_panel)
104
119
105 def createMenu(self):
120 def createMenu(self):
106 """local method used to create one menu bar"""
121 """local method used to create one menu bar"""
107
122
108 mb = wx.MenuBar()
123 mb = wx.MenuBar()
109
124
110 file_menu = wx.Menu()
125 file_menu = wx.Menu()
111 file_menu.Append(wx.ID_EXIT, "Exit")
126 file_menu.Append(wx.ID_EXIT, "Exit")
112
127
113 view_menu = wx.Menu()
128 view_menu = wx.Menu()
114 view_menu.Append(wx.ID_HIGHEST+1, "Show IPython Panel")
129 view_menu.Append(wx.ID_HIGHEST+1, "Show IPython Panel")
115 view_menu.Append(wx.ID_HIGHEST+2, "Show History Panel")
130 view_menu.Append(wx.ID_HIGHEST+2, "Show History Panel")
116 view_menu.AppendSeparator()
131 view_menu.AppendSeparator()
117 view_menu.Append(wx.ID_HIGHEST+6, "Show All")
132 view_menu.Append(wx.ID_HIGHEST+6, "Show All")
118
133
119 about_menu = wx.Menu()
134 about_menu = wx.Menu()
120 about_menu.Append(wx.ID_HIGHEST+3, "About")
135 about_menu.Append(wx.ID_HIGHEST+3, "About")
121
136
122 #view_menu.AppendSeparator()
137 #view_menu.AppendSeparator()
123 #options_menu = wx.Menu()
138 #options_menu = wx.Menu()
124 #options_menu.AppendCheckItem(wx.ID_HIGHEST+7, "Allow Floating")
139 #options_menu.AppendCheckItem(wx.ID_HIGHEST+7, "Allow Floating")
125 #options_menu.AppendCheckItem(wx.ID_HIGHEST+8, "Transparent Hint")
140 #options_menu.AppendCheckItem(wx.ID_HIGHEST+8, "Transparent Hint")
126 #options_menu.AppendCheckItem(wx.ID_HIGHEST+9, "Transparent Hint Fade-in")
141 #options_menu.AppendCheckItem(wx.ID_HIGHEST+9, "Transparent Hint Fade-in")
127
142
128
143
129 mb.Append(file_menu, "File")
144 mb.Append(file_menu, "File")
130 mb.Append(view_menu, "View")
145 mb.Append(view_menu, "View")
131 mb.Append(about_menu, "About")
146 mb.Append(about_menu, "About")
132 #mb.Append(options_menu, "Options")
147 #mb.Append(options_menu, "Options")
133
148
134 self.SetMenuBar(mb)
149 self.SetMenuBar(mb)
135
150
136 def createStatus(self):
151 def createStatus(self):
137 statusbar = self.CreateStatusBar(2, wx.ST_SIZEGRIP)
152 statusbar = self.CreateStatusBar(2, wx.ST_SIZEGRIP)
138 statusbar.SetStatusWidths([-2, -3])
153 statusbar.SetStatusWidths([-2, -3])
139 statusbar.SetStatusText("Ready", 0)
154 statusbar.SetStatusText("Ready", 0)
140 statusbar.SetStatusText("WxIPython "+str(__version__), 1)
155 statusbar.SetStatusText("WxIPython "+str(__version__), 1)
141 return statusbar
156 return statusbar
142
157
143 def updateStatus(self,text):
158 def updateStatus(self,text):
144 states = {'IDLE':'Idle',
159 states = {'IDLE':'Idle',
145 'DO_EXECUTE_LINE':'Send command',
160 'DO_EXECUTE_LINE':'Send command',
146 'WAIT_END_OF_EXECUTION':'Running command',
161 'WAIT_END_OF_EXECUTION':'Running command',
147 'WAITING_USER_INPUT':'Waiting user input',
162 'WAITING_USER_INPUT':'Waiting user input',
148 'SHOW_DOC':'Showing doc',
163 'SHOW_DOC':'Showing doc',
149 'SHOW_PROMPT':'Showing prompt'}
164 'SHOW_PROMPT':'Showing prompt'}
150 self.statusbar.SetStatusText(states[text], 0)
165 self.statusbar.SetStatusText(states[text], 0)
151
166
152 def OnClose(self, event):
167 def OnClose(self, event):
153 """#event used to close program """
168 """#event used to close program """
154 # deinitialize the frame manager
169 # deinitialize the frame manager
155 self._mgr.UnInit()
170 self._mgr.UnInit()
156 self.Destroy()
171 self.Destroy()
157 event.Skip()
172 event.Skip()
158
173
159 def OnExitDlg(self, event):
174 def OnExitDlg(self, event):
160 dlg = wx.MessageDialog(self, 'Are you sure you want to quit WxIPython',
175 dlg = wx.MessageDialog(self, 'Are you sure you want to quit WxIPython',
161 'WxIPython exit',
176 'WxIPython exit',
162 wx.ICON_QUESTION |
177 wx.ICON_QUESTION |
163 wx.YES_NO | wx.NO_DEFAULT
178 wx.YES_NO | wx.NO_DEFAULT
164 )
179 )
165 if dlg.ShowModal() == wx.ID_YES:
180 if dlg.ShowModal() == wx.ID_YES:
166 dlg.Destroy()
181 dlg.Destroy()
167 self._mgr.UnInit()
182 self._mgr.UnInit()
168 self.Destroy()
183 self.Destroy()
169 dlg.Destroy()
184 dlg.Destroy()
170
185
171 #event to display IPython pannel
186 #event to display IPython pannel
172 def OnShowIPythonPanel(self,event):
187 def OnShowIPythonPanel(self,event):
173 """ #event to display Boxpannel """
188 """ #event to display Boxpannel """
174 self._mgr.GetPane(self.ipython_panel).Show(True)
189 self._mgr.GetPane(self.ipython_panel).Show(True)
175 self._mgr.Update()
190 self._mgr.Update()
176 #event to display History pannel
191 #event to display History pannel
177 def OnShowHistoryPanel(self,event):
192 def OnShowHistoryPanel(self,event):
178 self._mgr.GetPane(self.history_panel).Show(True)
193 self._mgr.GetPane(self.history_panel).Show(True)
179 self._mgr.Update()
194 self._mgr.Update()
180
195
181 def OnShowAllPanel(self,event):
196 def OnShowAllPanel(self,event):
182 """#event to display all Pannels"""
197 """#event to display all Pannels"""
183 self._mgr.GetPane(self.ipython_panel).Show(True)
198 self._mgr.GetPane(self.ipython_panel).Show(True)
184 self._mgr.GetPane(self.history_panel).Show(True)
199 self._mgr.GetPane(self.history_panel).Show(True)
185 self._mgr.Update()
200 self._mgr.Update()
186
201
187 def OnShowAbout(self, event):
202 def OnShowAbout(self, event):
188 # First we create and fill the info object
203 # First we create and fill the info object
189 info = wx.AboutDialogInfo()
204 info = wx.AboutDialogInfo()
190 info.Name = "WxIPython"
205 info.Name = "WxIPython"
191 info.Version = str(__version__)
206 info.Version = str(__version__)
192 info.Copyright = "(C) 2007 Laurent Dufrechou"
207 info.Copyright = "(C) 2007 Laurent Dufrechou"
193 info.Description = wordwrap(
208 info.Description = wordwrap(
194 "A Gui that embbed a multithreaded IPython Shell",
209 "A Gui that embbed a multithreaded IPython Shell",
195 350, wx.ClientDC(self))
210 350, wx.ClientDC(self))
196 info.WebSite = ("http://ipython.scipy.org/", "IPython home page")
211 info.WebSite = ("http://ipython.scipy.org/", "IPython home page")
197 info.Developers = [ "Laurent Dufrechou" ]
212 info.Developers = [ "Laurent Dufrechou" ]
198 licenseText="BSD License.\nAll rights reserved. This program and the accompanying materials are made available under the terms of the BSD which accompanies this distribution, and is available at http://www.opensource.org/licenses/bsd-license.php"
213 licenseText="BSD License.\nAll rights reserved. This program and the accompanying materials are made available under the terms of the BSD which accompanies this distribution, and is available at http://www.opensource.org/licenses/bsd-license.php"
199 info.License = wordwrap(licenseText, 500, wx.ClientDC(self))
214 info.License = wordwrap(licenseText, 500, wx.ClientDC(self))
200
215
201 # Then we call wx.AboutBox giving it that info object
216 # Then we call wx.AboutBox giving it that info object
202 wx.AboutBox(info)
217 wx.AboutBox(info)
203
218
204 #-----------------------------------------
219 #-----------------------------------------
205 #Creating our application
220 #Creating our application
206 #-----------------------------------------
221 #-----------------------------------------
207 class MyApp(wx.PySimpleApp):
222 class MyApp(wx.PySimpleApp):
208 """Creating our application"""
223 """Creating our application"""
209 def __init__(self):
224 def __init__(self):
210 wx.PySimpleApp.__init__(self)
225 wx.PySimpleApp.__init__(self)
211
226
212 self.frame = MyFrame()
227 self.frame = MyFrame()
213 self.frame.Show()
228 self.frame.Show()
214
229
215 #-----------------------------------------
230 #-----------------------------------------
216 #Main loop
231 #Main loop
217 #-----------------------------------------
232 #-----------------------------------------
218 def main():
233 def main():
219 app = MyApp()
234 app = MyApp()
220 app.SetTopWindow(app.frame)
235 app.SetTopWindow(app.frame)
221 app.MainLoop()
236 app.MainLoop()
222
237
223 #if launched as main program run this
238 #if launched as main program run this
224 if __name__ == '__main__':
239 if __name__ == '__main__':
225 main()
240 main()
General Comments 0
You need to be logged in to leave comments. Login now