PLCOpenEditor.py
changeset 680 b693147fb2c3
parent 678 9d58192e823a
child 682 4d437bc0ef3f
child 688 188906a7368c
equal deleted inserted replaced
679:91e8ff268e96 680:b693147fb2c3
   304                 remove_function(self.Controler, name)
   304                 remove_function(self.Controler, name)
   305         else:
   305         else:
   306             self.ShowErrorMessage(_("\"%s\" is used by one or more POUs. It can't be removed!")%name)
   306             self.ShowErrorMessage(_("\"%s\" is used by one or more POUs. It can't be removed!")%name)
   307     return DeleteElementFunction
   307     return DeleteElementFunction
   308 
   308 
       
   309 if wx.Platform == '__WXMSW__':
       
   310     TAB_BORDER = 6
       
   311     NOTEBOOK_BORDER = 6
       
   312 else:
       
   313     TAB_BORDER = 7
       
   314     NOTEBOOK_BORDER = 2
       
   315 
   309 def SimplifyTabOrganization(tabs, rect):
   316 def SimplifyTabOrganization(tabs, rect):
   310     for tab in tabs:
   317     for tab in tabs:
   311         if tab["pos"][0] == rect.x:
   318         if tab["pos"][0] == rect.x:
   312             others = [t for t in tabs if t != tab]
   319             others = [t for t in tabs if t != tab]
   313             others.sort(lambda x,y: cmp(x["pos"][0], y["pos"][0]))
   320             others.sort(lambda x,y: cmp(x["pos"][0], y["pos"][0]))
   314             for other in others:
   321             for other in others:
   315                 if (other["pos"][1] == tab["pos"][1] and 
   322                 if (other["pos"][1] == tab["pos"][1] and 
   316                     other["size"][1] == tab["size"][1] and
   323                     other["size"][1] == tab["size"][1] and
   317                     other["pos"][0] == tab["pos"][0] + tab["size"][0] + 7):
   324                     other["pos"][0] == tab["pos"][0] + tab["size"][0] + TAB_BORDER):
   318                     
   325                     
   319                     tab["size"] = (tab["size"][0] + other["size"][0] + 7, tab["size"][1])
   326                     tab["size"] = (tab["size"][0] + other["size"][0] + TAB_BORDER, tab["size"][1])
   320                     tab["pages"].extend(other["pages"])
   327                     tab["pages"].extend(other["pages"])
   321                     tabs.remove(other)
   328                     tabs.remove(other)
   322                     
   329                     
   323                     if tab["size"][0] == rect.width:
   330                     if tab["size"][0] == rect.width:
   324                         return True
   331                         return True
   327             others = [t for t in tabs if t != tab]
   334             others = [t for t in tabs if t != tab]
   328             others.sort(lambda x,y: cmp(x["pos"][1], y["pos"][1]))
   335             others.sort(lambda x,y: cmp(x["pos"][1], y["pos"][1]))
   329             for other in others:
   336             for other in others:
   330                 if (other["pos"][0] == tab["pos"][0] and 
   337                 if (other["pos"][0] == tab["pos"][0] and 
   331                     other["size"][0] == tab["size"][0] and
   338                     other["size"][0] == tab["size"][0] and
   332                     other["pos"][1] == tab["pos"][1] + tab["size"][1] + 7):
   339                     other["pos"][1] == tab["pos"][1] + tab["size"][1] + TAB_BORDER):
   333                     
   340                     
   334                     tab["size"] = (tab["size"][0], tab["size"][1] + other["size"][1] + 7)
   341                     tab["size"] = (tab["size"][0], tab["size"][1] + other["size"][1] + TAB_BORDER)
   335                     tab["pages"].extend(other["pages"])
   342                     tab["pages"].extend(other["pages"])
   336                     tabs.remove(other)
   343                     tabs.remove(other)
   337                     
   344                     
   338                     if tab["size"][1] == rect.height:
   345                     if tab["size"][1] == rect.height:
   339                         return True
   346                         return True
   344         return tabs
   351         return tabs
   345     if len(tabs) == 1:
   352     if len(tabs) == 1:
   346         return tabs[0]
   353         return tabs[0]
   347     split = None
   354     split = None
   348     for idx, tab in enumerate(tabs):
   355     for idx, tab in enumerate(tabs):
       
   356         if len(tab["pages"]) == 0:
       
   357         	raise "Not possible"
   349         if tab["size"][0] == rect.width:
   358         if tab["size"][0] == rect.width:
   350             if tab["pos"][1] == rect.y:
   359             if tab["pos"][1] == rect.y:
   351                 split = (wx.TOP, float(tab["size"][1]) / float(rect.height))
   360                 split = (wx.TOP, float(tab["size"][1]) / float(rect.height))
   352                 split_rect = wx.Rect(rect.x, rect.y + tab["size"][1] + 7, 
   361                 split_rect = wx.Rect(rect.x, rect.y + tab["size"][1] + TAB_BORDER, 
   353                                      rect.width, rect.height - tab["size"][1] - 7)
   362                                      rect.width, rect.height - tab["size"][1] - TAB_BORDER)
   354             elif tab["pos"][1] == rect.height + 1 - tab["size"][1]:
   363             elif tab["pos"][1] == rect.height + 1 - tab["size"][1]:
   355                 split = (wx.BOTTOM, 1.0 - float(tab["size"][1]) / float(rect.height))
   364                 split = (wx.BOTTOM, 1.0 - float(tab["size"][1]) / float(rect.height))
   356                 split_rect = wx.Rect(rect.x, rect.y, 
   365                 split_rect = wx.Rect(rect.x, rect.y, 
   357                                      rect.width, rect.height - tab["size"][1] - 7)
   366                                      rect.width, rect.height - tab["size"][1] - TAB_BORDER)
   358             break
   367             break
   359         elif tab["size"][1] == rect.height:
   368         elif tab["size"][1] == rect.height:
   360             if tab["pos"][0] == rect.x:
   369             if tab["pos"][0] == rect.x:
   361                 split = (wx.LEFT, float(tab["size"][0]) / float(rect.width))
   370                 split = (wx.LEFT, float(tab["size"][0]) / float(rect.width))
   362                 split_rect = wx.Rect(rect.x + tab["size"][0] + 7, rect.y, 
   371                 split_rect = wx.Rect(rect.x + tab["size"][0] + TAB_BORDER, rect.y, 
   363                                      rect.width - tab["size"][0] - 7, rect.height)
   372                                      rect.width - tab["size"][0] - TAB_BORDER, rect.height)
   364             elif tab["pos"][0] == rect.width + 1 - tab["size"][0]:
   373             elif tab["pos"][0] == rect.width + 1 - tab["size"][0]:
   365                 split = (wx.RIGHT, 1.0 - float(tab["size"][0]) / float(rect.width))
   374                 split = (wx.RIGHT, 1.0 - float(tab["size"][0]) / float(rect.width))
   366                 split_rect = wx.Rect(rect.x, rect.y, 
   375                 split_rect = wx.Rect(rect.x, rect.y, 
   367                                      rect.width - tab["size"][0] - 7, rect.height)
   376                                      rect.width - tab["size"][0] - TAB_BORDER, rect.height)
   368             break
   377             break
   369     if split != None:
   378     if split != None:
   370         split_tab = tabs.pop(idx)
   379         split_tab = tabs.pop(idx)
   371         return {"split": split,
   380         return {"split": split,
   372                 "tab": split_tab, 
   381                 "tab": split_tab, 
   381 #-------------------------------------------------------------------------------
   390 #-------------------------------------------------------------------------------
   382 
   391 
   383 UNEDITABLE_NAMES_DICT = dict([(_(name), name) for name in UNEDITABLE_NAMES])
   392 UNEDITABLE_NAMES_DICT = dict([(_(name), name) for name in UNEDITABLE_NAMES])
   384 
   393 
   385 class IDEFrame(wx.Frame):
   394 class IDEFrame(wx.Frame):
       
   395     
       
   396     Starting = False
   386     
   397     
   387     # Compatibility function for wx versions < 2.6
   398     # Compatibility function for wx versions < 2.6
   388     if wx.VERSION < (2, 6, 0):
   399     if wx.VERSION < (2, 6, 0):
   389         def Bind(self, event, function, id = None):
   400         def Bind(self, event, function, id = None):
   390             if id is not None:
   401             if id is not None:
   803         self.Highlights = {}
   814         self.Highlights = {}
   804         self.DrawingMode = FREEDRAWING_MODE
   815         self.DrawingMode = FREEDRAWING_MODE
   805         #self.DrawingMode = DRIVENDRAWING_MODE
   816         #self.DrawingMode = DRIVENDRAWING_MODE
   806         if USE_AUI:
   817         if USE_AUI:
   807             self.AuiTabCtrl = []
   818             self.AuiTabCtrl = []
   808         self.Starting = False
       
   809         self.DefaultPerspective = None
   819         self.DefaultPerspective = None
   810         
   820         
   811         # Initialize Printing configuring elements
   821         # Initialize Printing configuring elements
   812         self.PrintData = wx.PrintData()
   822         self.PrintData = wx.PrintData()
   813         self.PrintData.SetPaperId(wx.PAPER_A4)
   823         self.PrintData.SetPaperId(wx.PAPER_A4)
   816         self.PageSetupData.SetMarginTopLeft(wx.Point(10, 15))
   826         self.PageSetupData.SetMarginTopLeft(wx.Point(10, 15))
   817         self.PageSetupData.SetMarginBottomRight(wx.Point(10, 20))
   827         self.PageSetupData.SetMarginBottomRight(wx.Point(10, 20))
   818         
   828         
   819         self.SetRefreshFunctions()
   829         self.SetRefreshFunctions()
   820     
   830     
       
   831     def ResetStarting(self):
       
   832 		self.Starting = False
       
   833     
   821     def Show(self):
   834     def Show(self):
   822         wx.Frame.Show(self)
   835         wx.Frame.Show(self)
   823         wx.CallAfter(self.RestoreLastState)
   836         wx.CallAfter(self.RestoreLastState)
   824     
   837     
   825     def OnActivated(self, event):
   838     def OnActivated(self, event):
   832 #-------------------------------------------------------------------------------
   845 #-------------------------------------------------------------------------------
   833 
   846 
   834     def OnResize(self, event):
   847     def OnResize(self, event):
   835         if self.Starting:
   848         if self.Starting:
   836             self.RestoreLastOrganization()
   849             self.RestoreLastOrganization()
   837             self.Starting = False
   850             if wx.Platform == '__WXMSW__':
   838             self.RefreshEditor()
   851                 wx.CallAfter(self.ResetStarting)
       
   852             else:
       
   853                 self.ResetStarting()
       
   854             wx.CallAfter(self.RefreshEditor)
   839         event.Skip()
   855         event.Skip()
   840     
   856     
   841     def GetProjectConfiguration(self):
   857     def GetProjectConfiguration(self):
   842         projects = {}
   858         projects = {}
   843         try:
   859         try:
   894                     if tab_infos is not None:
   910                     if tab_infos is not None:
   895                         tab["pages"].append((tab_infos, page_idx == child.GetActivePage()))
   911                         tab["pages"].append((tab_infos, page_idx == child.GetActivePage()))
   896                 tabs.append(tab)
   912                 tabs.append(tab)
   897         tabs.sort(lambda x, y: cmp(x["pos"], y["pos"]))
   913         tabs.sort(lambda x, y: cmp(x["pos"], y["pos"]))
   898         size = notebook.GetSize()
   914         size = notebook.GetSize()
   899         return ComputeTabsOrganization(tabs, wx.Rect(1, 1, size[0] - 2, size[1] - 2))
   915         return ComputeTabsOrganization(tabs, wx.Rect(1, 1, size[0] - NOTEBOOK_BORDER, size[1] - NOTEBOOK_BORDER))
   900     
   916     
   901     def LoadTab(self, notebook, page_infos):
   917     def LoadTab(self, notebook, page_infos):
   902         if page_infos[0] == "main":
   918         if page_infos[0] == "main":
   903             infos = self.MainTabs.get(page_infos[1])
   919             infos = self.MainTabs.get(page_infos[1])
   904             if infos is not None:
   920             if infos is not None: