191 # Helper Functions |
191 # Helper Functions |
192 #------------------------------------------------------------------------------- |
192 #------------------------------------------------------------------------------- |
193 |
193 |
194 import base64 |
194 import base64 |
195 |
195 |
|
196 |
196 def EncodeFileSystemPath(path, use_base64=True): |
197 def EncodeFileSystemPath(path, use_base64=True): |
197 path = path.encode(sys.getfilesystemencoding()) |
198 path = path.encode(sys.getfilesystemencoding()) |
198 if use_base64: |
199 if use_base64: |
199 return base64.encodestring(path) |
200 return base64.encodestring(path) |
200 return path |
201 return path |
201 |
202 |
|
203 |
202 def DecodeFileSystemPath(path, is_base64=True): |
204 def DecodeFileSystemPath(path, is_base64=True): |
203 if is_base64: |
205 if is_base64: |
204 path = base64.decodestring(path) |
206 path = base64.decodestring(path) |
205 return unicode(path, sys.getfilesystemencoding()) |
207 return unicode(path, sys.getfilesystemencoding()) |
206 |
208 |
207 # Compatibility function for wx versions < 2.6 |
209 |
208 def AppendMenu(parent, help, id, kind, text): |
210 def AppendMenu(parent, help, id, kind, text): |
|
211 """ |
|
212 Compatibility function for wx versions < 2.6 |
|
213 """ |
209 if wx.VERSION >= (2, 6, 0): |
214 if wx.VERSION >= (2, 6, 0): |
210 parent.Append(help=help, id=id, kind=kind, text=text) |
215 parent.Append(help=help, id=id, kind=kind, text=text) |
211 else: |
216 else: |
212 parent.Append(helpString=help, id=id, kind=kind, item=text) |
217 parent.Append(helpString=help, id=id, kind=kind, item=text) |
213 |
218 |
214 [TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU, PROJECTTREE, |
219 [TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU, PROJECTTREE, |
215 POUINSTANCEVARIABLESPANEL, LIBRARYTREE, SCALING, PAGETITLES |
220 POUINSTANCEVARIABLESPANEL, LIBRARYTREE, SCALING, PAGETITLES |
216 ] = range(10) |
221 ] = range(10) |
|
222 |
217 |
223 |
218 def GetShortcutKeyCallbackFunction(viewer_function): |
224 def GetShortcutKeyCallbackFunction(viewer_function): |
219 def ShortcutKeyFunction(self, event): |
225 def ShortcutKeyFunction(self, event): |
220 control = self.FindFocus() |
226 control = self.FindFocus() |
221 if control is not None and control.GetName() in ["Viewer", "TextViewer"]: |
227 if control is not None and control.GetName() in ["Viewer", "TextViewer"]: |
223 elif isinstance(control, wx.stc.StyledTextCtrl): |
229 elif isinstance(control, wx.stc.StyledTextCtrl): |
224 getattr(control, viewer_function)() |
230 getattr(control, viewer_function)() |
225 elif isinstance(control, wx.TextCtrl): |
231 elif isinstance(control, wx.TextCtrl): |
226 control.ProcessEvent(event) |
232 control.ProcessEvent(event) |
227 return ShortcutKeyFunction |
233 return ShortcutKeyFunction |
|
234 |
228 |
235 |
229 def GetDeleteElementFunction(remove_function, parent_type=None, check_function=None): |
236 def GetDeleteElementFunction(remove_function, parent_type=None, check_function=None): |
230 def DeleteElementFunction(self, selected): |
237 def DeleteElementFunction(self, selected): |
231 name = self.ProjectTree.GetItemText(selected) |
238 name = self.ProjectTree.GetItemText(selected) |
232 if check_function is None or check_function(name): |
239 if check_function is None or check_function(name): |
320 #------------------------------------------------------------------------------- |
329 #------------------------------------------------------------------------------- |
321 # IDEFrame Base Class |
330 # IDEFrame Base Class |
322 #------------------------------------------------------------------------------- |
331 #------------------------------------------------------------------------------- |
323 |
332 |
324 UNEDITABLE_NAMES_DICT = dict([(_(name), name) for name in UNEDITABLE_NAMES]) |
333 UNEDITABLE_NAMES_DICT = dict([(_(name), name) for name in UNEDITABLE_NAMES]) |
|
334 |
325 |
335 |
326 class IDEFrame(wx.Frame): |
336 class IDEFrame(wx.Frame): |
327 |
337 |
328 # Compatibility function for wx versions < 2.6 |
338 # Compatibility function for wx versions < 2.6 |
329 if wx.VERSION < (2, 6, 0): |
339 if wx.VERSION < (2, 6, 0): |
2547 # Viewer Printout |
2557 # Viewer Printout |
2548 #------------------------------------------------------------------------------- |
2558 #------------------------------------------------------------------------------- |
2549 |
2559 |
2550 UPPER_DIV = lambda x, y: (x / y) + {True : 0, False : 1}[(x % y) == 0] |
2560 UPPER_DIV = lambda x, y: (x / y) + {True : 0, False : 1}[(x % y) == 0] |
2551 |
2561 |
|
2562 |
2552 class GraphicPrintout(wx.Printout): |
2563 class GraphicPrintout(wx.Printout): |
2553 def __init__(self, viewer, page_size, margins, preview = False): |
2564 def __init__(self, viewer, page_size, margins, preview = False): |
2554 wx.Printout.__init__(self) |
2565 wx.Printout.__init__(self) |
2555 self.Viewer = viewer |
2566 self.Viewer = viewer |
2556 self.PageSize = page_size |
2567 self.PageSize = page_size |