IDEFrame.py
changeset 1736 7e61baa047f0
parent 1734 750eeb7230a1
child 1737 a39c2918c015
equal deleted inserted replaced
1735:c02818d7e29f 1736:7e61baa047f0
   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):
   243     NOTEBOOK_BORDER = 6
   250     NOTEBOOK_BORDER = 6
   244 else:
   251 else:
   245     TAB_BORDER = 7
   252     TAB_BORDER = 7
   246     NOTEBOOK_BORDER = 2
   253     NOTEBOOK_BORDER = 2
   247 
   254 
       
   255 
   248 def SimplifyTabLayout(tabs, rect):
   256 def SimplifyTabLayout(tabs, rect):
   249     for tab in tabs:
   257     for tab in tabs:
   250         if tab["pos"][0] == rect.x:
   258         if tab["pos"][0] == rect.x:
   251             others = [t for t in tabs if t != tab]
   259             others = [t for t in tabs if t != tab]
   252             others.sort(lambda x,y: cmp(x["pos"][0], y["pos"][0]))
   260             others.sort(lambda x,y: cmp(x["pos"][0], y["pos"][0]))
   275                     tabs.remove(other)
   283                     tabs.remove(other)
   276 
   284 
   277                     if tab["size"][1] == rect.height:
   285                     if tab["size"][1] == rect.height:
   278                         return True
   286                         return True
   279     return False
   287     return False
       
   288 
   280 
   289 
   281 def ComputeTabsLayout(tabs, rect):
   290 def ComputeTabsLayout(tabs, rect):
   282     if len(tabs) == 0:
   291     if len(tabs) == 0:
   283         return tabs
   292         return tabs
   284     if len(tabs) == 1:
   293     if len(tabs) == 1:
   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