IDEFrame.py
branchpython3
changeset 3750 f62625418bff
parent 3716 3dafdb6ad023
child 3752 9f6f46dbe3ae
equal deleted inserted replaced
3749:fda6c1a37662 3750:f62625418bff
    20 #
    20 #
    21 # You should have received a copy of the GNU General Public License
    21 # You should have received a copy of the GNU General Public License
    22 # along with this program; if not, write to the Free Software
    22 # along with this program; if not, write to the Free Software
    23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    24 
    24 
    25 from __future__ import absolute_import
    25 
    26 from __future__ import division
    26 
    27 import sys
    27 import sys
    28 import base64
    28 import base64
    29 from future.builtins import \
    29 from future.builtins import \
    30     round, \
    30     round, \
    31     str as text
    31     str as text
   119 
   119 
   120 
   120 
   121 [
   121 [
   122     TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU, PROJECTTREE,
   122     TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU, PROJECTTREE,
   123     POUINSTANCEVARIABLESPANEL, LIBRARYTREE, SCALING, PAGETITLES
   123     POUINSTANCEVARIABLESPANEL, LIBRARYTREE, SCALING, PAGETITLES
   124 ] = range(10)
   124 ] = list(range(10))
   125 
   125 
   126 
   126 
   127 def GetShortcutKeyCallbackFunction(viewer_function):
   127 def GetShortcutKeyCallbackFunction(viewer_function):
   128     def ShortcutKeyFunction(self, event):
   128     def ShortcutKeyFunction(self, event):
   129         control = self.FindFocus()
   129         control = self.FindFocus()
   341                        ID_PLCOPENEDITOREDITORTOOLBARMOTION, "OnMotionTool",
   341                        ID_PLCOPENEDITOREDITORTOOLBARMOTION, "OnMotionTool",
   342                        "move", _("Move the view"))],
   342                        "move", _("Move the view"))],
   343         }
   343         }
   344 
   344 
   345     def _init_coll_MenuBar_Menus(self, parent):
   345     def _init_coll_MenuBar_Menus(self, parent):
   346         parent.Append(menu=self.FileMenu, title=_(u'&File'))
   346         parent.Append(menu=self.FileMenu, title=_('&File'))
   347         parent.Append(menu=self.EditMenu, title=_(u'&Edit'))
   347         parent.Append(menu=self.EditMenu, title=_('&Edit'))
   348         parent.Append(menu=self.DisplayMenu, title=_(u'&Display'))
   348         parent.Append(menu=self.DisplayMenu, title=_('&Display'))
   349         parent.Append(menu=self.HelpMenu, title=_(u'&Help'))
   349         parent.Append(menu=self.HelpMenu, title=_('&Help'))
   350 
   350 
   351     def _init_coll_FileMenu_Items(self, parent):
   351     def _init_coll_FileMenu_Items(self, parent):
   352         pass
   352         pass
   353 
   353 
   354     def _init_coll_AddMenu_Items(self, parent, add_config=True):
   354     def _init_coll_AddMenu_Items(self, parent, add_config=True):
   355         AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUADDDATATYPE,
   355         AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUADDDATATYPE,
   356                    kind=wx.ITEM_NORMAL, text=_(u'&Data Type'))
   356                    kind=wx.ITEM_NORMAL, text=_('&Data Type'))
   357         AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUADDFUNCTION,
   357         AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUADDFUNCTION,
   358                    kind=wx.ITEM_NORMAL, text=_(u'&Function'))
   358                    kind=wx.ITEM_NORMAL, text=_('&Function'))
   359         AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUADDFUNCTIONBLOCK,
   359         AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUADDFUNCTIONBLOCK,
   360                    kind=wx.ITEM_NORMAL, text=_(u'Function &Block'))
   360                    kind=wx.ITEM_NORMAL, text=_('Function &Block'))
   361         AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUADDPROGRAM,
   361         AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUADDPROGRAM,
   362                    kind=wx.ITEM_NORMAL, text=_(u'&Program'))
   362                    kind=wx.ITEM_NORMAL, text=_('&Program'))
   363         AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUADDRESOURCE,
   363         AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUADDRESOURCE,
   364                    kind=wx.ITEM_NORMAL, text=_(u'&Resource'))
   364                    kind=wx.ITEM_NORMAL, text=_('&Resource'))
   365         if add_config:
   365         if add_config:
   366             AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUADDCONFIGURATION,
   366             AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUADDCONFIGURATION,
   367                        kind=wx.ITEM_NORMAL, text=_(u'&Configuration'))
   367                        kind=wx.ITEM_NORMAL, text=_('&Configuration'))
   368 
   368 
   369     def _init_coll_EditMenu_Items(self, parent):
   369     def _init_coll_EditMenu_Items(self, parent):
   370         AppendMenu(parent, help='', id=wx.ID_UNDO,
   370         AppendMenu(parent, help='', id=wx.ID_UNDO,
   371                    kind=wx.ITEM_NORMAL, text=_(u'Undo') + '\tCTRL+Z')
   371                    kind=wx.ITEM_NORMAL, text=_('Undo') + '\tCTRL+Z')
   372         AppendMenu(parent, help='', id=wx.ID_REDO,
   372         AppendMenu(parent, help='', id=wx.ID_REDO,
   373                    kind=wx.ITEM_NORMAL, text=_(u'Redo') + '\tCTRL+Y')
   373                    kind=wx.ITEM_NORMAL, text=_('Redo') + '\tCTRL+Y')
   374         parent.AppendSeparator()
   374         parent.AppendSeparator()
   375         AppendMenu(parent, help='', id=wx.ID_CUT,
   375         AppendMenu(parent, help='', id=wx.ID_CUT,
   376                    kind=wx.ITEM_NORMAL, text=_(u'Cut') + '\tCTRL+X')
   376                    kind=wx.ITEM_NORMAL, text=_('Cut') + '\tCTRL+X')
   377         AppendMenu(parent, help='', id=wx.ID_COPY,
   377         AppendMenu(parent, help='', id=wx.ID_COPY,
   378                    kind=wx.ITEM_NORMAL, text=_(u'Copy') + '\tCTRL+C')
   378                    kind=wx.ITEM_NORMAL, text=_('Copy') + '\tCTRL+C')
   379         AppendMenu(parent, help='', id=wx.ID_PASTE,
   379         AppendMenu(parent, help='', id=wx.ID_PASTE,
   380                    kind=wx.ITEM_NORMAL, text=_(u'Paste') + '\tCTRL+V')
   380                    kind=wx.ITEM_NORMAL, text=_('Paste') + '\tCTRL+V')
   381         parent.AppendSeparator()
   381         parent.AppendSeparator()
   382         AppendMenu(parent, help='', id=wx.ID_FIND,
   382         AppendMenu(parent, help='', id=wx.ID_FIND,
   383                    kind=wx.ITEM_NORMAL, text=_(u'Find') + '\tCTRL+F')
   383                    kind=wx.ITEM_NORMAL, text=_('Find') + '\tCTRL+F')
   384         AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUFINDNEXT,
   384         AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUFINDNEXT,
   385                    kind=wx.ITEM_NORMAL, text=_(u'Find Next') + '\tCTRL+K')
   385                    kind=wx.ITEM_NORMAL, text=_('Find Next') + '\tCTRL+K')
   386         AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUFINDPREVIOUS,
   386         AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUFINDPREVIOUS,
   387                    kind=wx.ITEM_NORMAL, text=_(u'Find Previous') + '\tCTRL+SHIFT+K')
   387                    kind=wx.ITEM_NORMAL, text=_('Find Previous') + '\tCTRL+SHIFT+K')
   388         parent.AppendSeparator()
   388         parent.AppendSeparator()
   389         AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUSEARCHINPROJECT,
   389         AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUSEARCHINPROJECT,
   390                    kind=wx.ITEM_NORMAL, text=_(u'Search in Project') + '\tCTRL+SHIFT+F')
   390                    kind=wx.ITEM_NORMAL, text=_('Search in Project') + '\tCTRL+SHIFT+F')
   391         parent.AppendSeparator()
   391         parent.AppendSeparator()
   392         add_menu = wx.Menu(title='')
   392         add_menu = wx.Menu(title='')
   393         self._init_coll_AddMenu_Items(add_menu)
   393         self._init_coll_AddMenu_Items(add_menu)
   394         parent.Append(wx.ID_ADD, _(u"&Add Element"), add_menu)
   394         parent.Append(wx.ID_ADD, _("&Add Element"), add_menu)
   395         AppendMenu(parent, help='', id=wx.ID_SELECTALL,
   395         AppendMenu(parent, help='', id=wx.ID_SELECTALL,
   396                    kind=wx.ITEM_NORMAL, text=_(u'Select All') + '\tCTRL+A')
   396                    kind=wx.ITEM_NORMAL, text=_('Select All') + '\tCTRL+A')
   397         AppendMenu(parent, help='', id=wx.ID_DELETE,
   397         AppendMenu(parent, help='', id=wx.ID_DELETE,
   398                    kind=wx.ITEM_NORMAL, text=_(u'&Delete'))
   398                    kind=wx.ITEM_NORMAL, text=_('&Delete'))
   399         self.Bind(wx.EVT_MENU, self.OnUndoMenu, id=wx.ID_UNDO)
   399         self.Bind(wx.EVT_MENU, self.OnUndoMenu, id=wx.ID_UNDO)
   400         self.Bind(wx.EVT_MENU, self.OnRedoMenu, id=wx.ID_REDO)
   400         self.Bind(wx.EVT_MENU, self.OnRedoMenu, id=wx.ID_REDO)
   401         # self.Bind(wx.EVT_MENU, self.OnEnableUndoRedoMenu, id=ID_PLCOPENEDITOREDITMENUENABLEUNDOREDO)
   401         # self.Bind(wx.EVT_MENU, self.OnEnableUndoRedoMenu, id=ID_PLCOPENEDITOREDITMENUENABLEUNDOREDO)
   402         self.Bind(wx.EVT_MENU, self.OnCutMenu, id=wx.ID_CUT)
   402         self.Bind(wx.EVT_MENU, self.OnCutMenu, id=wx.ID_CUT)
   403         self.Bind(wx.EVT_MENU, self.OnCopyMenu, id=wx.ID_COPY)
   403         self.Bind(wx.EVT_MENU, self.OnCopyMenu, id=wx.ID_COPY)
   422         self.Bind(wx.EVT_MENU, self.OnAddConfigurationMenu,
   422         self.Bind(wx.EVT_MENU, self.OnAddConfigurationMenu,
   423                   id=ID_PLCOPENEDITOREDITMENUADDCONFIGURATION)
   423                   id=ID_PLCOPENEDITOREDITMENUADDCONFIGURATION)
   424         self.Bind(wx.EVT_MENU, self.OnSelectAllMenu, id=wx.ID_SELECTALL)
   424         self.Bind(wx.EVT_MENU, self.OnSelectAllMenu, id=wx.ID_SELECTALL)
   425         self.Bind(wx.EVT_MENU, self.OnDeleteMenu, id=wx.ID_DELETE)
   425         self.Bind(wx.EVT_MENU, self.OnDeleteMenu, id=wx.ID_DELETE)
   426 
   426 
   427         self.AddToMenuToolBar([(wx.ID_UNDO, "undo", _(u'Undo'), None),
   427         self.AddToMenuToolBar([(wx.ID_UNDO, "undo", _('Undo'), None),
   428                                (wx.ID_REDO, "redo", _(u'Redo'), None),
   428                                (wx.ID_REDO, "redo", _('Redo'), None),
   429                                None,
   429                                None,
   430                                (wx.ID_CUT, "cut", _(u'Cut'), None),
   430                                (wx.ID_CUT, "cut", _('Cut'), None),
   431                                (wx.ID_COPY, "copy", _(u'Copy'), None),
   431                                (wx.ID_COPY, "copy", _('Copy'), None),
   432                                (wx.ID_PASTE, "paste", _(u'Paste'), None),
   432                                (wx.ID_PASTE, "paste", _('Paste'), None),
   433                                None,
   433                                None,
   434                                (ID_PLCOPENEDITOREDITMENUSEARCHINPROJECT, "find", _(u'Search in Project'), None),
   434                                (ID_PLCOPENEDITOREDITMENUSEARCHINPROJECT, "find", _('Search in Project'), None),
   435                                (ID_PLCOPENEDITORDISPLAYMENUFULLSCREEN, "fullscreen", _(u'Toggle fullscreen mode'), None)])
   435                                (ID_PLCOPENEDITORDISPLAYMENUFULLSCREEN, "fullscreen", _('Toggle fullscreen mode'), None)])
   436 
   436 
   437     def _init_coll_DisplayMenu_Items(self, parent):
   437     def _init_coll_DisplayMenu_Items(self, parent):
   438         AppendMenu(parent, help='', id=wx.ID_REFRESH,
   438         AppendMenu(parent, help='', id=wx.ID_REFRESH,
   439                    kind=wx.ITEM_NORMAL, text=_(u'Refresh') + '\tCTRL+R')
   439                    kind=wx.ITEM_NORMAL, text=_('Refresh') + '\tCTRL+R')
   440         if self.EnableDebug:
   440         if self.EnableDebug:
   441             AppendMenu(parent, help='', id=wx.ID_CLEAR,
   441             AppendMenu(parent, help='', id=wx.ID_CLEAR,
   442                        kind=wx.ITEM_NORMAL, text=_(u'Clear Errors') + '\tCTRL+K')
   442                        kind=wx.ITEM_NORMAL, text=_('Clear Errors') + '\tCTRL+K')
   443         parent.AppendSeparator()
   443         parent.AppendSeparator()
   444         zoommenu = wx.Menu(title='')
   444         zoommenu = wx.Menu(title='')
   445         parent.Append(wx.ID_ZOOM_FIT, _("Zoom"), zoommenu)
   445         parent.Append(wx.ID_ZOOM_FIT, _("Zoom"), zoommenu)
   446         for idx, value in enumerate(ZOOM_FACTORS):
   446         for idx, value in enumerate(ZOOM_FACTORS):
   447             new_item = AppendMenu(zoommenu, help='',
   447             new_item = AppendMenu(zoommenu, help='',
   448                        kind=wx.ITEM_RADIO, text=str(int(round(value * 100))) + "%")
   448                        kind=wx.ITEM_RADIO, text=str(int(round(value * 100))) + "%")
   449             self.Bind(wx.EVT_MENU, self.GenerateZoomFunction(idx), new_item)
   449             self.Bind(wx.EVT_MENU, self.GenerateZoomFunction(idx), new_item)
   450 
   450 
   451         parent.AppendSeparator()
   451         parent.AppendSeparator()
   452         AppendMenu(parent, help='', id=ID_PLCOPENEDITORDISPLAYMENUSWITCHPERSPECTIVE,
   452         AppendMenu(parent, help='', id=ID_PLCOPENEDITORDISPLAYMENUSWITCHPERSPECTIVE,
   453                    kind=wx.ITEM_NORMAL, text=_(u'Switch perspective') + '\tF12')
   453                    kind=wx.ITEM_NORMAL, text=_('Switch perspective') + '\tF12')
   454         self.Bind(wx.EVT_MENU, self.SwitchPerspective, id=ID_PLCOPENEDITORDISPLAYMENUSWITCHPERSPECTIVE)
   454         self.Bind(wx.EVT_MENU, self.SwitchPerspective, id=ID_PLCOPENEDITORDISPLAYMENUSWITCHPERSPECTIVE)
   455 
   455 
   456         AppendMenu(parent, help='', id=ID_PLCOPENEDITORDISPLAYMENUFULLSCREEN,
   456         AppendMenu(parent, help='', id=ID_PLCOPENEDITORDISPLAYMENUFULLSCREEN,
   457                    kind=wx.ITEM_NORMAL, text=_(u'Full screen') + '\tShift-F12')
   457                    kind=wx.ITEM_NORMAL, text=_('Full screen') + '\tShift-F12')
   458         self.Bind(wx.EVT_MENU, self.SwitchFullScrMode, id=ID_PLCOPENEDITORDISPLAYMENUFULLSCREEN)
   458         self.Bind(wx.EVT_MENU, self.SwitchFullScrMode, id=ID_PLCOPENEDITORDISPLAYMENUFULLSCREEN)
   459 
   459 
   460         AppendMenu(parent, help='', id=ID_PLCOPENEDITORDISPLAYMENURESETPERSPECTIVE,
   460         AppendMenu(parent, help='', id=ID_PLCOPENEDITORDISPLAYMENURESETPERSPECTIVE,
   461                    kind=wx.ITEM_NORMAL, text=_(u'Reset Perspective'))
   461                    kind=wx.ITEM_NORMAL, text=_('Reset Perspective'))
   462         self.Bind(wx.EVT_MENU, self.OnResetPerspective, id=ID_PLCOPENEDITORDISPLAYMENURESETPERSPECTIVE)
   462         self.Bind(wx.EVT_MENU, self.OnResetPerspective, id=ID_PLCOPENEDITORDISPLAYMENURESETPERSPECTIVE)
   463 
   463 
   464         self.Bind(wx.EVT_MENU, self.OnRefreshMenu, id=wx.ID_REFRESH)
   464         self.Bind(wx.EVT_MENU, self.OnRefreshMenu, id=wx.ID_REFRESH)
   465         if self.EnableDebug:
   465         if self.EnableDebug:
   466             self.Bind(wx.EVT_MENU, self.OnClearErrorsMenu, id=wx.ID_CLEAR)
   466             self.Bind(wx.EVT_MENU, self.OnClearErrorsMenu, id=wx.ID_CLEAR)
   790     # -------------------------------------------------------------------------------
   790     # -------------------------------------------------------------------------------
   791     #                Saving and restoring frame organization functions
   791     #                Saving and restoring frame organization functions
   792     # -------------------------------------------------------------------------------
   792     # -------------------------------------------------------------------------------
   793 
   793 
   794     def GetTabInfos(self, tab):
   794     def GetTabInfos(self, tab):
   795         for page_name, (page_ref, _page_title) in self.MainTabs.iteritems():
   795         for page_name, (page_ref, _page_title) in self.MainTabs.items():
   796             if page_ref == tab:
   796             if page_ref == tab:
   797                 return ("main", page_name)
   797                 return ("main", page_name)
   798         return None
   798         return None
   799 
   799 
   800     def SaveTabLayout(self, notebook):
   800     def SaveTabLayout(self, notebook):
   803             if isinstance(child, wx.aui.AuiTabCtrl):
   803             if isinstance(child, wx.aui.AuiTabCtrl):
   804                 if child.GetPageCount() > 0:
   804                 if child.GetPageCount() > 0:
   805                     pos = child.GetPosition()
   805                     pos = child.GetPosition()
   806                     tab = {"pos": (pos.x, pos.y), "pages": []}
   806                     tab = {"pos": (pos.x, pos.y), "pages": []}
   807                     tab_size = child.GetSize()
   807                     tab_size = child.GetSize()
   808                     for page_idx in xrange(child.GetPageCount()):
   808                     for page_idx in range(child.GetPageCount()):
   809                         page = child.GetWindowFromIdx(page_idx)
   809                         page = child.GetWindowFromIdx(page_idx)
   810                         if "size" not in tab:
   810                         if "size" not in tab:
   811                             tab["size"] = (tab_size[0], tab_size[1] + page.GetSize()[1])
   811                             tab["size"] = (tab_size[0], tab_size[1] + page.GetSize()[1])
   812                         tab_infos = self.GetTabInfos(page)
   812                         tab_infos = self.GetTabInfos(page)
   813                         if tab_infos is not None:
   813                         if tab_infos is not None:
   869     def ResetPerspective(self):
   869     def ResetPerspective(self):
   870         if self.DefaultPerspective is not None:
   870         if self.DefaultPerspective is not None:
   871             self.AUIManager.LoadPerspective(self.DefaultPerspective["perspective"])
   871             self.AUIManager.LoadPerspective(self.DefaultPerspective["perspective"])
   872 
   872 
   873             for notebook in [self.LeftNoteBook, self.BottomNoteBook, self.RightNoteBook]:
   873             for notebook in [self.LeftNoteBook, self.BottomNoteBook, self.RightNoteBook]:
   874                 for dummy in xrange(notebook.GetPageCount()):
   874                 for dummy in range(notebook.GetPageCount()):
   875                     notebook.RemovePage(0)
   875                     notebook.RemovePage(0)
   876 
   876 
   877             notebooks = self.DefaultPerspective["notebooks"]
   877             notebooks = self.DefaultPerspective["notebooks"]
   878             for notebook, entry_name in [(self.LeftNoteBook, "leftnotebook"),
   878             for notebook, entry_name in [(self.LeftNoteBook, "leftnotebook"),
   879                                          (self.BottomNoteBook, "bottomnotebook"),
   879                                          (self.BottomNoteBook, "bottomnotebook"),
   980 
   980 
   981     def GetDrawingMode(self):
   981     def GetDrawingMode(self):
   982         return self.DrawingMode
   982         return self.DrawingMode
   983 
   983 
   984     def RefreshScaling(self):
   984     def RefreshScaling(self):
   985         for i in xrange(self.TabsOpened.GetPageCount()):
   985         for i in range(self.TabsOpened.GetPageCount()):
   986             editor = self.TabsOpened.GetPage(i)
   986             editor = self.TabsOpened.GetPage(i)
   987             editor.RefreshScaling()
   987             editor.RefreshScaling()
   988 
   988 
   989     def EditProjectSettings(self):
   989     def EditProjectSettings(self):
   990         old_values = self.Controler.GetProjectProperties()
   990         old_values = self.Controler.GetProjectProperties()
  1012         """
  1012         """
  1013         self.TabsOpened.AddPage(window, text)
  1013         self.TabsOpened.AddPage(window, text)
  1014         self.RefreshTabCtrlEvent()
  1014         self.RefreshTabCtrlEvent()
  1015 
  1015 
  1016     def DeletePage(self, window):
  1016     def DeletePage(self, window):
  1017         for idx in xrange(self.TabsOpened.GetPageCount()):
  1017         for idx in range(self.TabsOpened.GetPageCount()):
  1018             if self.TabsOpened.GetPage(idx) == window:
  1018             if self.TabsOpened.GetPage(idx) == window:
  1019                 self.TabsOpened.DeletePage(idx)
  1019                 self.TabsOpened.DeletePage(idx)
  1020                 self.RefreshTabCtrlEvent()
  1020                 self.RefreshTabCtrlEvent()
  1021                 return
  1021                 return
  1022 
  1022 
  1023     def DeleteAllPages(self):
  1023     def DeleteAllPages(self):
  1024         """Function that fix difference in deleting all tabs between
  1024         """Function that fix difference in deleting all tabs between
  1025         wx.Notebook and wx.aui.AUINotebook.
  1025         wx.Notebook and wx.aui.AUINotebook.
  1026         """
  1026         """
  1027         for dummy in xrange(self.TabsOpened.GetPageCount()):
  1027         for dummy in range(self.TabsOpened.GetPageCount()):
  1028             self.TabsOpened.DeletePage(0)
  1028             self.TabsOpened.DeletePage(0)
  1029         self.RefreshTabCtrlEvent()
  1029         self.RefreshTabCtrlEvent()
  1030 
  1030 
  1031     def SetPageBitmap(self, idx, bitmap):
  1031     def SetPageBitmap(self, idx, bitmap):
  1032         """Function that fix difference in setting picture on tab between
  1032         """Function that fix difference in setting picture on tab between
  1063             if answer == wx.ID_YES:
  1063             if answer == wx.ID_YES:
  1064                 self.SaveProject()
  1064                 self.SaveProject()
  1065             elif answer == wx.ID_CANCEL:
  1065             elif answer == wx.ID_CANCEL:
  1066                 return False
  1066                 return False
  1067 
  1067 
  1068         for idx in xrange(self.TabsOpened.GetPageCount()):
  1068         for idx in range(self.TabsOpened.GetPageCount()):
  1069             window = self.TabsOpened.GetPage(idx)
  1069             window = self.TabsOpened.GetPage(idx)
  1070             if not window.CheckSaveBeforeClosing():
  1070             if not window.CheckSaveBeforeClosing():
  1071                 return False
  1071                 return False
  1072 
  1072 
  1073         return True
  1073         return True
  1112         selected = self.TabsOpened.GetSelection()
  1112         selected = self.TabsOpened.GetSelection()
  1113         if selected != -1:
  1113         if selected != -1:
  1114             window = self.TabsOpened.GetPage(selected)
  1114             window = self.TabsOpened.GetPage(selected)
  1115             data = wx.PrintDialogData(self.PrintData)
  1115             data = wx.PrintDialogData(self.PrintData)
  1116             properties = self.Controler.GetProjectProperties(window.IsDebugging())
  1116             properties = self.Controler.GetProjectProperties(window.IsDebugging())
  1117             page_size = map(int, properties["pageSize"])
  1117             page_size = list(map(int, properties["pageSize"]))
  1118             margins = (self.PageSetupData.GetMarginTopLeft(), self.PageSetupData.GetMarginBottomRight())
  1118             margins = (self.PageSetupData.GetMarginTopLeft(), self.PageSetupData.GetMarginBottomRight())
  1119             printout = GraphicPrintout(window, page_size, margins, True)
  1119             printout = GraphicPrintout(window, page_size, margins, True)
  1120             printout2 = GraphicPrintout(window, page_size, margins, True)
  1120             printout2 = GraphicPrintout(window, page_size, margins, True)
  1121             preview = wx.PrintPreview(printout, printout2, data)
  1121             preview = wx.PrintPreview(printout, printout2, data)
  1122 
  1122 
  1136         if selected != -1:
  1136         if selected != -1:
  1137             window = self.TabsOpened.GetPage(selected)
  1137             window = self.TabsOpened.GetPage(selected)
  1138             dialog_data = wx.PrintDialogData(self.PrintData)
  1138             dialog_data = wx.PrintDialogData(self.PrintData)
  1139             dialog_data.SetToPage(1)
  1139             dialog_data.SetToPage(1)
  1140             properties = self.Controler.GetProjectProperties(window.IsDebugging())
  1140             properties = self.Controler.GetProjectProperties(window.IsDebugging())
  1141             page_size = map(int, properties["pageSize"])
  1141             page_size = list(map(int, properties["pageSize"]))
  1142             margins = (self.PageSetupData.GetMarginTopLeft(), self.PageSetupData.GetMarginBottomRight())
  1142             margins = (self.PageSetupData.GetMarginTopLeft(), self.PageSetupData.GetMarginBottomRight())
  1143             printer = wx.Printer(dialog_data)
  1143             printer = wx.Printer(dialog_data)
  1144             printout = GraphicPrintout(window, page_size, margins)
  1144             printout = GraphicPrintout(window, page_size, margins)
  1145 
  1145 
  1146             if not printer.Print(self, printout, True) and printer.GetLastError() != wx.PRINTER_CANCELLED:
  1146             if not printer.Print(self, printout, True) and printer.GetLastError() != wx.PRINTER_CANCELLED:
  1225             MenuToolBar.EnableTool(ID_PLCOPENEDITOREDITMENUSEARCHINPROJECT, False)
  1225             MenuToolBar.EnableTool(ID_PLCOPENEDITOREDITMENUSEARCHINPROJECT, False)
  1226             self.EditMenu.Enable(wx.ID_ADD, False)
  1226             self.EditMenu.Enable(wx.ID_ADD, False)
  1227             self.EditMenu.Enable(wx.ID_DELETE, False)
  1227             self.EditMenu.Enable(wx.ID_DELETE, False)
  1228 
  1228 
  1229     def CloseTabsWithoutModel(self, refresh=True):
  1229     def CloseTabsWithoutModel(self, refresh=True):
  1230         idxs = range(self.TabsOpened.GetPageCount())
  1230         idxs = list(range(self.TabsOpened.GetPageCount()))
  1231         idxs.reverse()
  1231         idxs.reverse()
  1232         for idx in idxs:
  1232         for idx in idxs:
  1233             window = self.TabsOpened.GetPage(idx)
  1233             window = self.TabsOpened.GetPage(idx)
  1234             if window.HasNoModel():
  1234             if window.HasNoModel():
  1235                 self.TabsOpened.DeletePage(idx)
  1235                 self.TabsOpened.DeletePage(idx)
  1473                         window = child.GetWindowFromIdx(active_page)
  1473                         window = child.GetWindowFromIdx(active_page)
  1474                         window.RefreshView()
  1474                         window.RefreshView()
  1475             self._Refresh(FILEMENU, EDITMENU, DISPLAYMENU, EDITORTOOLBAR)
  1475             self._Refresh(FILEMENU, EDITMENU, DISPLAYMENU, EDITORTOOLBAR)
  1476 
  1476 
  1477     def RefreshEditorNames(self, old_tagname, new_tagname):
  1477     def RefreshEditorNames(self, old_tagname, new_tagname):
  1478         for i in xrange(self.TabsOpened.GetPageCount()):
  1478         for i in range(self.TabsOpened.GetPageCount()):
  1479             editor = self.TabsOpened.GetPage(i)
  1479             editor = self.TabsOpened.GetPage(i)
  1480             if editor.GetTagName() == old_tagname:
  1480             if editor.GetTagName() == old_tagname:
  1481                 editor.SetTagName(new_tagname)
  1481                 editor.SetTagName(new_tagname)
  1482 
  1482 
  1483     def IsOpened(self, tagname):
  1483     def IsOpened(self, tagname):
  1484         for idx in xrange(self.TabsOpened.GetPageCount()):
  1484         for idx in range(self.TabsOpened.GetPageCount()):
  1485             if self.TabsOpened.GetPage(idx).IsViewing(tagname):
  1485             if self.TabsOpened.GetPage(idx).IsViewing(tagname):
  1486                 return idx
  1486                 return idx
  1487         return None
  1487         return None
  1488 
  1488 
  1489     def RefreshPageTitles(self):
  1489     def RefreshPageTitles(self):
  1490         for idx in xrange(self.TabsOpened.GetPageCount()):
  1490         for idx in range(self.TabsOpened.GetPageCount()):
  1491             window = self.TabsOpened.GetPage(idx)
  1491             window = self.TabsOpened.GetPage(idx)
  1492             icon = window.GetIcon()
  1492             icon = window.GetIcon()
  1493             if icon is not None:
  1493             if icon is not None:
  1494                 self.SetPageBitmap(idx, icon)
  1494                 self.SetPageBitmap(idx, icon)
  1495             self.TabsOpened.SetPageText(idx, window.GetTitle())
  1495             self.TabsOpened.SetPageText(idx, window.GetTitle())
  1599         if self.ProjectTree is not None:
  1599         if self.ProjectTree is not None:
  1600             root = self.ProjectTree.GetRootItem()
  1600             root = self.ProjectTree.GetRootItem()
  1601             if root is not None and root.IsOk():
  1601             if root is not None and root.IsOk():
  1602                 words = tagname.split("::")
  1602                 words = tagname.split("::")
  1603                 result = self.RecursiveProjectTreeItemSelection(
  1603                 result = self.RecursiveProjectTreeItemSelection(
  1604                     root, zip(words[1:], self.TagNamePartsItemTypes.get(words[0], [])))
  1604                     root, list(zip(words[1:], self.TagNamePartsItemTypes.get(words[0], []))))
  1605         return result
  1605         return result
  1606 
  1606 
  1607     def RecursiveProjectTreeItemSelection(self, root, items):
  1607     def RecursiveProjectTreeItemSelection(self, root, items):
  1608         found = False
  1608         found = False
  1609         item, root_cookie = self.ProjectTree.GetFirstChild(root)
  1609         item, root_cookie = self.ProjectTree.GetFirstChild(root)
  1888                 openedidx = self.IsOpened(tagname)
  1888                 openedidx = self.IsOpened(tagname)
  1889                 old_selected = self.TabsOpened.GetSelection()
  1889                 old_selected = self.TabsOpened.GetSelection()
  1890                 if old_selected != openedidx:
  1890                 if old_selected != openedidx:
  1891                     if old_selected >= 0:
  1891                     if old_selected >= 0:
  1892                         self.TabsOpened.GetPage(old_selected).ResetBuffer()
  1892                         self.TabsOpened.GetPage(old_selected).ResetBuffer()
  1893                 for i in xrange(self.TabsOpened.GetPageCount()):
  1893                 for i in range(self.TabsOpened.GetPageCount()):
  1894                     window = self.TabsOpened.GetPage(i)
  1894                     window = self.TabsOpened.GetPage(i)
  1895                     if window == new_window:
  1895                     if window == new_window:
  1896                         self.TabsOpened.SetSelection(i)
  1896                         self.TabsOpened.SetSelection(i)
  1897                         window.SetFocus()
  1897                         window.SetFocus()
  1898                 self.RefreshPageTitles()
  1898                 self.RefreshPageTitles()
  2081         if self.EnableDebug:
  2081         if self.EnableDebug:
  2082             self.DebugVariablePanel.ResetGraphicsValues()
  2082             self.DebugVariablePanel.ResetGraphicsValues()
  2083 
  2083 
  2084     def CloseObsoleteDebugTabs(self):
  2084     def CloseObsoleteDebugTabs(self):
  2085         if self.EnableDebug:
  2085         if self.EnableDebug:
  2086             idxs = range(self.TabsOpened.GetPageCount())
  2086             idxs = list(range(self.TabsOpened.GetPageCount()))
  2087             idxs.reverse()
  2087             idxs.reverse()
  2088             for idx in idxs:
  2088             for idx in idxs:
  2089                 editor = self.TabsOpened.GetPage(idx)
  2089                 editor = self.TabsOpened.GetPage(idx)
  2090                 if isinstance(editor, Viewer) and editor.IsDebugging():
  2090                 if isinstance(editor, Viewer) and editor.IsDebugging():
  2091                     instance_infos = self.Controler.GetInstanceInfos(editor.GetInstancePath(), self.EnableDebug)
  2091                     instance_infos = self.Controler.GetInstanceInfos(editor.GetInstancePath(), self.EnableDebug)
  2570 
  2570 
  2571     def ClearHighlights(self, highlight_type=None):
  2571     def ClearHighlights(self, highlight_type=None):
  2572         if highlight_type is None:
  2572         if highlight_type is None:
  2573             self.Highlights = {}
  2573             self.Highlights = {}
  2574         else:
  2574         else:
  2575             self.Highlights = dict([(name, highlight) for name, highlight in self.Highlights.iteritems() if highlight != highlight_type])
  2575             self.Highlights = dict([(name, highlight) for name, highlight in self.Highlights.items() if highlight != highlight_type])
  2576         self.RefreshProjectTree()
  2576         self.RefreshProjectTree()
  2577         for i in xrange(self.TabsOpened.GetPageCount()):
  2577         for i in range(self.TabsOpened.GetPageCount()):
  2578             viewer = self.TabsOpened.GetPage(i)
  2578             viewer = self.TabsOpened.GetPage(i)
  2579             viewer.ClearHighlights(highlight_type)
  2579             viewer.ClearHighlights(highlight_type)
  2580 
  2580 
  2581     def ClearErrors(self):
  2581     def ClearErrors(self):
  2582         self.ClearHighlights(ERROR_HIGHLIGHT)
  2582         self.ClearHighlights(ERROR_HIGHLIGHT)