Beremiz.py
changeset 402 984e238e63d0
parent 401 8106a853a7c7
child 403 ae4a85291441
equal deleted inserted replaced
401:8106a853a7c7 402:984e238e63d0
   365               name='PLCConfig', parent=self.LeftNoteBook, pos=wx.Point(0, 0),
   365               name='PLCConfig', parent=self.LeftNoteBook, pos=wx.Point(0, 0),
   366               size=wx.Size(-1, -1), style=wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER|wx.HSCROLL|wx.VSCROLL)
   366               size=wx.Size(-1, -1), style=wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER|wx.HSCROLL|wx.VSCROLL)
   367         self.PLCConfig.SetBackgroundColour(wx.WHITE)
   367         self.PLCConfig.SetBackgroundColour(wx.WHITE)
   368         self.PLCConfig.Bind(wx.EVT_LEFT_DOWN, self.OnPanelLeftDown)
   368         self.PLCConfig.Bind(wx.EVT_LEFT_DOWN, self.OnPanelLeftDown)
   369         self.PLCConfig.Bind(wx.EVT_SIZE, self.OnMoveWindow)
   369         self.PLCConfig.Bind(wx.EVT_SIZE, self.OnMoveWindow)
   370         self.LeftNoteBook.AddPage(self.PLCConfig, _("Topology"))
   370         self.BottomNoteBook.InsertPage(0, self.PLCConfig, _("Topology"), True)
   371         
   371         
   372         self.LogConsole = wx.TextCtrl(id=ID_BEREMIZLOGCONSOLE, value='',
   372         self.LogConsole = wx.TextCtrl(id=ID_BEREMIZLOGCONSOLE, value='',
   373                   name='LogConsole', parent=self.BottomNoteBook, pos=wx.Point(0, 0),
   373                   name='LogConsole', parent=self.BottomNoteBook, pos=wx.Point(0, 0),
   374                   size=wx.Size(0, 0), style=wx.TE_MULTILINE|wx.TE_RICH2)
   374                   size=wx.Size(0, 0), style=wx.TE_MULTILINE|wx.TE_RICH2)
   375         self.LogConsole.Bind(wx.EVT_LEFT_DCLICK, self.OnLogConsoleDClick)
   375         self.LogConsole.Bind(wx.EVT_LEFT_DCLICK, self.OnLogConsoleDClick)
   389         
   389         
   390         self.DisableEvents = False
   390         self.DisableEvents = False
   391         
   391         
   392         self.PluginInfos = {}
   392         self.PluginInfos = {}
   393         
   393         
   394         if projectOpen:
   394         if projectOpen is not None and os.path.isdir(projectOpen):
   395             self.PluginRoot = PluginsRoot(self, self.Log)
   395             self.PluginRoot = PluginsRoot(self, self.Log)
   396             self.Controler = self.PluginRoot
   396             self.Controler = self.PluginRoot
   397             self.PluginRoot.LoadProject(projectOpen, buildpath)
   397             self.PluginRoot.LoadProject(projectOpen, buildpath)
   398             self._Refresh(TYPESTREE, INSTANCESTREE, LIBRARYTREE)
   398             self._Refresh(TYPESTREE, INSTANCESTREE, LIBRARYTREE)
   399             self.RefreshAll()
   399             self.RefreshAll()
   726 
   726 
   727     def ExpandLocation(self, locations_infos, group, force = False):
   727     def ExpandLocation(self, locations_infos, group, force = False):
   728         for child in locations_infos[group]["children"]:
   728         for child in locations_infos[group]["children"]:
   729             locations_infos[child]["left"].Show()
   729             locations_infos[child]["left"].Show()
   730             locations_infos[child]["right"].Show()
   730             locations_infos[child]["right"].Show()
   731             if force or not locations_infos[child]["expanded"]:
   731             if force or locations_infos[child]["expanded"]:
   732                 self.ExpandLocation(locations_infos, child, force)
   732                 self.ExpandLocation(locations_infos, child, force)
   733                 if force:
   733                 if force:
   734                     locations_infos[child]["expanded"] = True
   734                     locations_infos[child]["expanded"] = True
   735     
   735     
   736     def CollapseLocation(self, locations_infos, group, force = False):
   736     def CollapseLocation(self, locations_infos, group, force = False):
   755             self.PluginInfos[plugin] = {"expanded" : False, "right_visible" : False}
   755             self.PluginInfos[plugin] = {"expanded" : False, "right_visible" : False}
   756             
   756             
   757         self.PluginInfos[plugin]["children"] = plugin.IECSortedChilds()
   757         self.PluginInfos[plugin]["children"] = plugin.IECSortedChilds()
   758         plugin_locations = []
   758         plugin_locations = []
   759         if len(self.PluginInfos[plugin]["children"]) == 0:
   759         if len(self.PluginInfos[plugin]["children"]) == 0:
   760             plugin_locations = plugin.GetVariableLocationTree()
   760             plugin_locations = plugin.GetVariableLocationTree()["children"]
   761             if not self.PluginInfos[plugin].has_key("locations_infos"):
   761             if not self.PluginInfos[plugin].has_key("locations_infos"):
   762                 self.PluginInfos[plugin]["locations_infos"] = {"root": {"expanded" : False}}
   762                 self.PluginInfos[plugin]["locations_infos"] = {"root": {"expanded" : False}}
   763                 
   763                 
   764             self.PluginInfos[plugin]["locations_infos"]["root"]["children"] = []
   764             self.PluginInfos[plugin]["locations_infos"]["root"]["children"] = []
   765         
   765         
   854               size=wx.Size(13, 13), style=wx.NO_BORDER)
   854               size=wx.Size(13, 13), style=wx.NO_BORDER)
   855         expandbutton.labelDelta = 0
   855         expandbutton.labelDelta = 0
   856         expandbutton.SetBezelWidth(0)
   856         expandbutton.SetBezelWidth(0)
   857         expandbutton.SetUseFocusIndicator(False)
   857         expandbutton.SetUseFocusIndicator(False)
   858         expandbutton.SetBitmapSelected(wx.Bitmap(Bpath( 'images', 'minus.png')))
   858         expandbutton.SetBitmapSelected(wx.Bitmap(Bpath( 'images', 'minus.png')))
   859         expandbutton.SetToggle(self.PluginInfos[plugin]["expanded"])
       
   860             
   859             
   861         if len(self.PluginInfos[plugin]["children"]) > 0:
   860         if len(self.PluginInfos[plugin]["children"]) > 0:
       
   861             expandbutton.SetToggle(self.PluginInfos[plugin]["expanded"])
   862             def togglebutton(event):
   862             def togglebutton(event):
   863                 if expandbutton.GetToggle():
   863                 if expandbutton.GetToggle():
   864                     self.ExpandPlugin(plugin)
   864                     self.ExpandPlugin(plugin)
   865                 else:
   865                 else:
   866                     self.CollapsePlugin(plugin)
   866                     self.CollapsePlugin(plugin)
   869                 self.RefreshScrollBars()
   869                 self.RefreshScrollBars()
   870                 event.Skip()
   870                 event.Skip()
   871             expandbutton.Bind(wx.EVT_BUTTON, togglebutton, id=expandbutton_id)
   871             expandbutton.Bind(wx.EVT_BUTTON, togglebutton, id=expandbutton_id)
   872         elif len(plugin_locations) > 0:
   872         elif len(plugin_locations) > 0:
   873             locations_infos = self.PluginInfos[plugin]["locations_infos"]
   873             locations_infos = self.PluginInfos[plugin]["locations_infos"]
       
   874             expandbutton.SetToggle(locations_infos["root"]["expanded"])
   874             def togglebutton(event):
   875             def togglebutton(event):
   875                 if expandbutton.GetToggle():
   876                 if expandbutton.GetToggle():
   876                     self.ExpandLocation(locations_infos, "root")
   877                     self.ExpandLocation(locations_infos, "root")
   877                 else:
   878                 else:
   878                     self.CollapseLocation(locations_infos, "root")
   879                     self.CollapseLocation(locations_infos, "root")
   960                 locations_infos["root"]["children"].append("root.%s" % location["name"])
   961                 locations_infos["root"]["children"].append("root.%s" % location["name"])
   961                 self.GenerateLocationTreeBranch(locations_infos, "root", location)
   962                 self.GenerateLocationTreeBranch(locations_infos, "root", location)
   962                 if not locations_infos["root"]["expanded"]:
   963                 if not locations_infos["root"]["expanded"]:
   963                     self.CollapseLocation(locations_infos, "root")
   964                     self.CollapseLocation(locations_infos, "root")
   964         
   965         
   965     LOCATION_BITMAP = {LOCATION_VAR_INPUT: "VAR_INPUT",
   966     LOCATION_BITMAP = {LOCATION_PLUGIN: "CONFIGURATION",
       
   967                        LOCATION_MODULE: "RESOURCE",
       
   968                        LOCATION_GROUP: "PROGRAM",
       
   969                        LOCATION_VAR_INPUT: "VAR_INPUT",
   966                        LOCATION_VAR_OUTPUT: "VAR_OUTPUT",
   970                        LOCATION_VAR_OUTPUT: "VAR_OUTPUT",
   967                        LOCATION_VAR_MEMORY: "VAR_LOCAL"}
   971                        LOCATION_VAR_MEMORY: "VAR_LOCAL"}
   968     
   972     
   969     def GenerateLocationTreeBranch(self, locations_infos, parent, location):
   973     def GenerateLocationTreeBranch(self, locations_infos, parent, location):
   970         leftwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1))
   974         leftwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1))
   977         self.PluginTreeSizer.AddWindow(rightwindow, 0, border=0, flag=wx.GROW)
   981         self.PluginTreeSizer.AddWindow(rightwindow, 0, border=0, flag=wx.GROW)
   978         
   982         
   979         location_name = "%s.%s" % (parent, location["name"])
   983         location_name = "%s.%s" % (parent, location["name"])
   980         if not locations_infos.has_key(location_name):
   984         if not locations_infos.has_key(location_name):
   981             locations_infos[location_name] = {"expanded" : False}
   985             locations_infos[location_name] = {"expanded" : False}
   982         
       
   983         locations_infos[location_name]["children"] = ["%s.%s" % (location_name, child["name"]) for child in location["children"]]
       
   984         
   986         
   985         if location["type"] in [LOCATION_PLUGIN, LOCATION_MODULE, LOCATION_GROUP]:
   987         if location["type"] in [LOCATION_PLUGIN, LOCATION_MODULE, LOCATION_GROUP]:
   986             leftwindow.SetBackgroundColour(WINDOW_COLOUR)
   988             leftwindow.SetBackgroundColour(WINDOW_COLOUR)
   987             rightwindow.SetBackgroundColour(WINDOW_COLOUR)
   989             rightwindow.SetBackgroundColour(WINDOW_COLOUR)
   988                     
   990                     
   997                   size=wx.Size(13, 13), style=wx.NO_BORDER)
   999                   size=wx.Size(13, 13), style=wx.NO_BORDER)
   998             expandbutton.labelDelta = 0
  1000             expandbutton.labelDelta = 0
   999             expandbutton.SetBezelWidth(0)
  1001             expandbutton.SetBezelWidth(0)
  1000             expandbutton.SetUseFocusIndicator(False)
  1002             expandbutton.SetUseFocusIndicator(False)
  1001             expandbutton.SetBitmapSelected(wx.Bitmap(Bpath( 'images', 'minus.png')))
  1003             expandbutton.SetBitmapSelected(wx.Bitmap(Bpath( 'images', 'minus.png')))
  1002             expandbutton.SetToggle(self.PluginInfos[plugin]["expanded"])
  1004             expandbutton.SetToggle(locations_infos[location_name]["expanded"])
  1003                 
  1005                 
  1004             if len(location["children"]) > 0:
  1006             if len(location["children"]) > 0:
  1005                 def togglebutton(event):
  1007                 def togglebutton(event):
  1006                     if expandbutton.GetToggle():
  1008                     if expandbutton.GetToggle():
  1007                         self.ExpandLocation(locations_infos, location_name)
  1009                         self.ExpandLocation(locations_infos, location_name)
  1018             
  1020             
  1019         else:
  1021         else:
  1020             leftwindow.SetBackgroundColour(wx.WHITE)
  1022             leftwindow.SetBackgroundColour(wx.WHITE)
  1021             rightwindow.SetBackgroundColour(wx.WHITE)
  1023             rightwindow.SetBackgroundColour(wx.WHITE)
  1022             
  1024             
  1023             leftwindowsizer.Add(wx.Size(50, 16), 0)
  1025             leftwindowsizer.Add(wx.Size(20, 16), 0)
  1024             
  1026             
  1025             st = wx.StaticBitmap(leftwindow, -1)
  1027         sb = wx.StaticBitmap(leftwindow, -1)
  1026             st.SetBitmap(wx.Bitmap(os.path.join(base_folder, "plcopeneditor", 'Images', '%s.png' % self.LOCATION_BITMAP[location["type"]])))
  1028         sb.SetBitmap(wx.Bitmap(os.path.join(base_folder, "plcopeneditor", 'Images', '%s.png' % self.LOCATION_BITMAP[location["type"]])))
  1027             leftwindowsizer.AddWindow(st, 0, border=5, flag=wx.RIGHT)
  1029         leftwindowsizer.AddWindow(sb, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL)
  1028         
  1030         
  1029         st_id = wx.NewId()
  1031         st_id = wx.NewId()
  1030         st = wx.StaticText(leftwindow, st_id, size=wx.DefaultSize, style=wx.NO_BORDER)
  1032         st = wx.StaticText(leftwindow, st_id, size=wx.DefaultSize, style=wx.NO_BORDER)
  1031         st.SetFont(wx.Font(faces["size"] * 0.5, wx.DEFAULT, wx.NORMAL, wx.NORMAL, faceName = faces["helv"]))
  1033         label = location["name"]
  1032         st.SetLabel(location["name"])
       
  1033         if location["type"] in [LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY]:
  1034         if location["type"] in [LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY]:
       
  1035             label += " (%s)" % location["location"]
  1034             infos = location.copy()
  1036             infos = location.copy()
  1035             infos.pop("children")
  1037             infos.pop("children")
       
  1038             st.SetFont(wx.Font(faces["size"] * 0.5, wx.DEFAULT, wx.NORMAL, wx.NORMAL, faceName = faces["helv"]))
  1036             st.Bind(wx.EVT_LEFT_DOWN, self.GenerateLocationLeftDownFunction(infos))
  1039             st.Bind(wx.EVT_LEFT_DOWN, self.GenerateLocationLeftDownFunction(infos))
       
  1040         else:
       
  1041             st.SetFont(wx.Font(faces["size"] * 0.75, wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = faces["helv"]))
       
  1042         st.SetLabel(label)
  1037         leftwindowsizer.AddWindow(st, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL)
  1043         leftwindowsizer.AddWindow(st, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL)
  1038         
  1044         
  1039         locations_infos[location_name]["left"] = leftwindow
  1045         locations_infos[location_name]["left"] = leftwindow
  1040         locations_infos[location_name]["right"] = rightwindow
  1046         locations_infos[location_name]["right"] = rightwindow
  1041         for child in locations_infos[location_name]["children"]:
  1047         locations_infos[location_name]["children"] = []
  1042             self.GenerateLocationTreeBranch(child)
  1048         for child in location["children"]:
  1043             if not locations_infos[child]["expanded"]:
  1049             child_name = "%s.%s" % (location_name, child["name"])
  1044                 self.CollapseLocation(locations_infos, child)
  1050             locations_infos[location_name]["children"].append(child_name)
       
  1051             self.GenerateLocationTreeBranch(locations_infos, location_name, child)
       
  1052             if not locations_infos[child_name]["expanded"]:
       
  1053                 self.CollapseLocation(locations_infos, child_name)
  1045     
  1054     
  1046     def GenerateLocationLeftDownFunction(self, infos):
  1055     def GenerateLocationLeftDownFunction(self, infos):
  1047         def OnLocationLeftDownFunction(event):
  1056         def OnLocationLeftDownFunction(event):
  1048             data = wx.TextDataObject(str((infos["location"], "location", infos["IEC_type"], infos["name"], infos["description"])))
  1057             data = wx.TextDataObject(str((infos["location"], "location", infos["IEC_type"], infos["name"], infos["description"])))
  1049             dragSource = wx.DropSource(self)
  1058             dragSource = wx.DropSource(self)