Beremiz.py
changeset 401 8106a853a7c7
parent 396 d1083f580ca1
child 402 984e238e63d0
equal deleted inserted replaced
400:2c786431fe72 401:8106a853a7c7
   111 from plugger import PluginsRoot, MATIEC_ERROR_MODEL
   111 from plugger import PluginsRoot, MATIEC_ERROR_MODEL
   112 from wxPopen import ProcessLogger
   112 from wxPopen import ProcessLogger
   113 
   113 
   114 from docutils import *
   114 from docutils import *
   115 from PLCOpenEditor import IDEFrame, Viewer, AppendMenu, TITLE, TOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU, TYPESTREE, INSTANCESTREE, LIBRARYTREE, SCALING
   115 from PLCOpenEditor import IDEFrame, Viewer, AppendMenu, TITLE, TOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU, TYPESTREE, INSTANCESTREE, LIBRARYTREE, SCALING
       
   116 from PLCControler import LOCATION_PLUGIN, LOCATION_MODULE, LOCATION_GROUP, LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY
   116 
   117 
   117 SCROLLBAR_UNIT = 10
   118 SCROLLBAR_UNIT = 10
   118 WINDOW_COLOUR = wx.Colour(240,240,240)
   119 WINDOW_COLOUR = wx.Colour(240,240,240)
   119 TITLE_COLOUR = wx.Colour(200,200,220)
   120 TITLE_COLOUR = wx.Colour(200,200,220)
   120 CHANGED_TITLE_COLOUR = wx.Colour(220,200,220)
   121 CHANGED_TITLE_COLOUR = wx.Colour(220,200,220)
   524                 self.FileMenu.Enable(wx.ID_PRINT, False)
   525                 self.FileMenu.Enable(wx.ID_PRINT, False)
   525             self.FileMenu.Enable(wx.ID_PAGE_SETUP, True)
   526             self.FileMenu.Enable(wx.ID_PAGE_SETUP, True)
   526             self.FileMenu.Enable(wx.ID_SAVE, True)
   527             self.FileMenu.Enable(wx.ID_SAVE, True)
   527             self.FileMenu.Enable(wx.ID_PROPERTIES, True)
   528             self.FileMenu.Enable(wx.ID_PROPERTIES, True)
   528             self.FileMenu.Enable(wx.ID_CLOSE_ALL, True)
   529             self.FileMenu.Enable(wx.ID_CLOSE_ALL, True)
   529             self.FileMenu.Enable(wx.ID_SAVEAS, True)
       
   530         else:
   530         else:
   531             self.FileMenu.Enable(wx.ID_CLOSE, False)
   531             self.FileMenu.Enable(wx.ID_CLOSE, False)
   532             self.FileMenu.Enable(wx.ID_PAGE_SETUP, False)
   532             self.FileMenu.Enable(wx.ID_PAGE_SETUP, False)
   533             self.FileMenu.Enable(wx.ID_PREVIEW, False)
   533             self.FileMenu.Enable(wx.ID_PREVIEW, False)
   534             self.FileMenu.Enable(wx.ID_PRINT, False)
   534             self.FileMenu.Enable(wx.ID_PRINT, False)
   535             self.FileMenu.Enable(wx.ID_SAVE, False)
   535             self.FileMenu.Enable(wx.ID_SAVE, False)
   536             self.FileMenu.Enable(wx.ID_PROPERTIES, False)
   536             self.FileMenu.Enable(wx.ID_PROPERTIES, False)
   537             self.FileMenu.Enable(wx.ID_CLOSE_ALL, False)
   537             self.FileMenu.Enable(wx.ID_CLOSE_ALL, False)
   538             self.FileMenu.Enable(wx.ID_SAVEAS, False)
   538         
   539 
       
   540     def RefreshScrollBars(self):
   539     def RefreshScrollBars(self):
   541         xstart, ystart = self.PLCConfig.GetViewStart()
   540         xstart, ystart = self.PLCConfig.GetViewStart()
   542         window_size = self.PLCConfig.GetClientSize()
   541         window_size = self.PLCConfig.GetClientSize()
   543         sizer = self.PLCConfig.GetSizer()
   542         sizer = self.PLCConfig.GetSizer()
   544         if sizer:
   543         if sizer:
   558                 bkgdclr = CHANGED_TITLE_COLOUR
   557                 bkgdclr = CHANGED_TITLE_COLOUR
   559             else:
   558             else:
   560                 bkgdclr = TITLE_COLOUR
   559                 bkgdclr = TITLE_COLOUR
   561                 
   560                 
   562             if self.PluginRoot not in self.PluginInfos:
   561             if self.PluginRoot not in self.PluginInfos:
   563                 self.PluginInfos[self.PluginRoot] = {"middle_visible" : False}
   562                 self.PluginInfos[self.PluginRoot] = {"right_visible" : False}
   564             
   563             
   565             plcwindow.SetBackgroundColour(TITLE_COLOUR)
   564             plcwindow.SetBackgroundColour(TITLE_COLOUR)
   566             plcwindow.Bind(wx.EVT_LEFT_DOWN, self.OnPanelLeftDown)
   565             plcwindow.Bind(wx.EVT_LEFT_DOWN, self.OnPanelLeftDown)
   567             self.PLCParamsSizer.AddWindow(plcwindow, 0, border=0, flag=wx.GROW)
   566             self.PLCParamsSizer.AddWindow(plcwindow, 0, border=0, flag=wx.GROW)
   568             
   567             
   586             plcwindowsizer.AddSizer(plcwindowmainsizer, 0, border=5, flag=wx.ALL)
   585             plcwindowsizer.AddSizer(plcwindowmainsizer, 0, border=5, flag=wx.ALL)
   587             
   586             
   588             plcwindowbuttonsizer = wx.BoxSizer(wx.HORIZONTAL)
   587             plcwindowbuttonsizer = wx.BoxSizer(wx.HORIZONTAL)
   589             plcwindowmainsizer.AddSizer(plcwindowbuttonsizer, 0, border=0, flag=wx.ALIGN_CENTER)
   588             plcwindowmainsizer.AddSizer(plcwindowbuttonsizer, 0, border=0, flag=wx.ALIGN_CENTER)
   590             
   589             
   591             msizer = self.GenerateMethodButtonSizer(self.PluginRoot, plcwindow, not self.PluginInfos[self.PluginRoot]["middle_visible"])
   590             msizer = self.GenerateMethodButtonSizer(self.PluginRoot, plcwindow, not self.PluginInfos[self.PluginRoot]["right_visible"])
   592             plcwindowbuttonsizer.AddSizer(msizer, 0, border=0, flag=wx.GROW)
   591             plcwindowbuttonsizer.AddSizer(msizer, 0, border=0, flag=wx.GROW)
   593             
   592             
   594             paramswindow = wx.Panel(plcwindow, -1, size=wx.Size(-1, -1), style=wx.TAB_TRAVERSAL)
   593             paramswindow = wx.Panel(plcwindow, -1, size=wx.Size(-1, -1), style=wx.TAB_TRAVERSAL)
   595             paramswindow.SetBackgroundColour(TITLE_COLOUR)
   594             paramswindow.SetBackgroundColour(TITLE_COLOUR)
   596             paramswindow.Bind(wx.EVT_LEFT_DOWN, self.OnPanelLeftDown)
   595             paramswindow.Bind(wx.EVT_LEFT_DOWN, self.OnPanelLeftDown)
   600             paramswindow.SetSizer(psizer)
   599             paramswindow.SetSizer(psizer)
   601             
   600             
   602             plugin_infos = self.PluginRoot.GetParamsAttributes()
   601             plugin_infos = self.PluginRoot.GetParamsAttributes()
   603             self.RefreshSizerElement(paramswindow, psizer, self.PluginRoot, plugin_infos, None, False)
   602             self.RefreshSizerElement(paramswindow, psizer, self.PluginRoot, plugin_infos, None, False)
   604             
   603             
   605             if not self.PluginInfos[self.PluginRoot]["middle_visible"]:
   604             if not self.PluginInfos[self.PluginRoot]["right_visible"]:
   606                 paramswindow.Hide()
   605                 paramswindow.Hide()
   607             
   606             
   608             minimizebutton_id = wx.NewId()
   607             minimizebutton_id = wx.NewId()
   609             minimizebutton = wx.lib.buttons.GenBitmapToggleButton(id=minimizebutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'Maximize.png')),
   608             minimizebutton = wx.lib.buttons.GenBitmapToggleButton(id=minimizebutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'Maximize.png')),
   610                   name='MinimizeButton', parent=plcwindow, pos=wx.Point(0, 0),
   609                   name='MinimizeButton', parent=plcwindow, pos=wx.Point(0, 0),
   611                   size=wx.Size(24, 24), style=wx.NO_BORDER)
   610                   size=wx.Size(24, 24), style=wx.NO_BORDER)
   612             make_genbitmaptogglebutton_flat(minimizebutton)
   611             make_genbitmaptogglebutton_flat(minimizebutton)
   613             minimizebutton.SetBitmapSelected(wx.Bitmap(Bpath( 'images', 'Minimize.png')))
   612             minimizebutton.SetBitmapSelected(wx.Bitmap(Bpath( 'images', 'Minimize.png')))
   614             minimizebutton.SetToggle(self.PluginInfos[self.PluginRoot]["middle_visible"])
   613             minimizebutton.SetToggle(self.PluginInfos[self.PluginRoot]["right_visible"])
   615             plcwindowbuttonsizer.AddWindow(minimizebutton, 0, border=5, flag=wx.ALL)
   614             plcwindowbuttonsizer.AddWindow(minimizebutton, 0, border=5, flag=wx.ALL)
   616             
   615             
   617 #            if len(self.PluginRoot.PlugChildsTypes) > 0:
       
   618 #                addsizer = self.GenerateAddButtonSizer(self.PluginRoot, plcwindow)
       
   619 #                plcwindowbuttonsizer.AddSizer(addsizer, 0, border=0, flag=0)
       
   620 #            else:
       
   621 #                addsizer = None
       
   622 
       
   623             def togglewindow(event):
   616             def togglewindow(event):
   624                 if minimizebutton.GetToggle():
   617                 if minimizebutton.GetToggle():
   625                     paramswindow.Show()
   618                     paramswindow.Show()
   626                     msizer.SetCols(1)
   619                     msizer.SetCols(1)
   627 #                    if addsizer is not None:
       
   628 #                        addsizer.SetCols(1)
       
   629                 else:
   620                 else:
   630                     paramswindow.Hide()
   621                     paramswindow.Hide()
   631                     msizer.SetCols(len(self.PluginRoot.PluginMethods))
   622                     msizer.SetCols(len(self.PluginRoot.PluginMethods))
   632 #                    if addsizer is not None:
   623                 self.PluginInfos[self.PluginRoot]["right_visible"] = minimizebutton.GetToggle()
   633 #                        addsizer.SetCols(len(self.PluginRoot.PlugChildsTypes))
       
   634                 self.PluginInfos[self.PluginRoot]["middle_visible"] = minimizebutton.GetToggle()
       
   635                 self.PLCConfigMainSizer.Layout()
   624                 self.PLCConfigMainSizer.Layout()
   636                 self.RefreshScrollBars()
   625                 self.RefreshScrollBars()
   637                 event.Skip()
   626                 event.Skip()
   638             minimizebutton.Bind(wx.EVT_BUTTON, togglewindow, id=minimizebutton_id)
   627             minimizebutton.Bind(wx.EVT_BUTTON, togglewindow, id=minimizebutton_id)
   639         
   628         
   641             self.PluginInfos[self.PluginRoot]["params"] = paramswindow
   630             self.PluginInfos[self.PluginRoot]["params"] = paramswindow
   642             
   631             
   643         self.PLCConfigMainSizer.Layout()
   632         self.PLCConfigMainSizer.Layout()
   644         self.RefreshScrollBars()
   633         self.RefreshScrollBars()
   645         self.Thaw()
   634         self.Thaw()
   646 
       
   647 #    def GenerateAddButtonSizer(self, plugin, parent, horizontal = True):
       
   648 #        if horizontal:
       
   649 #            addsizer = wx.FlexGridSizer(cols=len(plugin.PluginMethods))
       
   650 #        else:
       
   651 #            addsizer = wx.FlexGridSizer(cols=1)
       
   652 #        for name, XSDClass, help in plugin.PlugChildsTypes:
       
   653 #            addbutton_id = wx.NewId()
       
   654 #            addbutton = wx.lib.buttons.GenButton(id=addbutton_id, label="Add %s"%help,
       
   655 #                  name='AddPluginButton', parent=parent, pos=wx.Point(0, 0),
       
   656 #                  style=wx.NO_BORDER)
       
   657 #            font = addbutton.GetFont()
       
   658 #            font.SetUnderlined(True)
       
   659 #            addbutton.SetFont(font)
       
   660 #            addbutton._GetLabelSize = gen_textbutton_GetLabelSize(addbutton)
       
   661 #            addbutton.SetForegroundColour(wx.BLUE)
       
   662 #            addbutton.SetToolTipString("Add a \"%s\" plugin to this one"%name)
       
   663 #            addbutton.Bind(wx.EVT_BUTTON, self._GetAddPluginFunction(name, plugin), id=addbutton_id)
       
   664 #            addsizer.AddWindow(addbutton, 0, border=0, flag=0)
       
   665 #        return addsizer
       
   666 
   635 
   667     normal_bt_font=wx.Font(faces["size"] / 3, wx.DEFAULT, wx.NORMAL, wx.NORMAL, faceName = faces["helv"])
   636     normal_bt_font=wx.Font(faces["size"] / 3, wx.DEFAULT, wx.NORMAL, wx.NORMAL, faceName = faces["helv"])
   668     mouseover_bt_font=wx.Font(faces["size"] / 3, wx.DEFAULT, wx.NORMAL, wx.NORMAL, underline=True, faceName = faces["helv"])
   637     mouseover_bt_font=wx.Font(faces["size"] / 3, wx.DEFAULT, wx.NORMAL, wx.NORMAL, underline=True, faceName = faces["helv"])
   669     def GenerateMethodButtonSizer(self, plugin, parent, horizontal = True):
   638     def GenerateMethodButtonSizer(self, plugin, parent, horizontal = True):
   670         if horizontal:
   639         if horizontal:
   716             if plugin == self.PluginRoot:
   685             if plugin == self.PluginRoot:
   717                 bkgdclr = CHANGED_TITLE_COLOUR
   686                 bkgdclr = CHANGED_TITLE_COLOUR
   718                 items = ["main", "params"]
   687                 items = ["main", "params"]
   719             else:
   688             else:
   720                 bkgdclr = CHANGED_WINDOW_COLOUR
   689                 bkgdclr = CHANGED_WINDOW_COLOUR
   721                 items = ["left", "middle", "params"]
   690                 items = ["left", "right", "params"]
   722             for i in items:
   691             for i in items:
   723                 self.PluginInfos[plugin][i].SetBackgroundColour(bkgdclr)
   692                 self.PluginInfos[plugin][i].SetBackgroundColour(bkgdclr)
   724                 self.PluginInfos[plugin][i].Refresh()
   693                 self.PluginInfos[plugin][i].Refresh()
   725         return res
   694         return res
   726 
   695 
   727     def ExpandPlugin(self, plugin, force = False):
   696     def ExpandPlugin(self, plugin, force = False):
   728         for child in self.PluginInfos[plugin]["children"]:
   697         for child in self.PluginInfos[plugin]["children"]:
   729             self.PluginInfos[child]["left"].Show()
   698             self.PluginInfos[child]["left"].Show()
   730             self.PluginInfos[child]["middle"].Show()
   699             self.PluginInfos[child]["right"].Show()
   731 #            self.PluginTreeSizer.Show(self.PluginInfos[child]["right"])
       
   732             if force or not self.PluginInfos[child]["expanded"]:
   700             if force or not self.PluginInfos[child]["expanded"]:
   733                 self.ExpandPlugin(child, force)
   701                 self.ExpandPlugin(child, force)
   734                 if force:
   702                 if force:
   735                     self.PluginInfos[child]["expanded"] = True
   703                     self.PluginInfos[child]["expanded"] = True
       
   704         locations_infos = self.PluginInfos[plugin].get("locations_infos", None)
       
   705         if locations_infos is not None:
       
   706             if force or locations_infos["root"]["expanded"]:
       
   707                 self.ExpandLocation(locations_infos, "root", force)
       
   708                 if force:
       
   709                     locations_infos["root"]["expanded"] = True
       
   710                 
   736     
   711     
   737     def CollapsePlugin(self, plugin, force = False):
   712     def CollapsePlugin(self, plugin, force = False):
   738         for child in self.PluginInfos[plugin]["children"]:
   713         for child in self.PluginInfos[plugin]["children"]:
   739             self.PluginInfos[child]["left"].Hide()
   714             self.PluginInfos[child]["left"].Hide()
   740             self.PluginInfos[child]["middle"].Hide()
   715             self.PluginInfos[child]["right"].Hide()
   741 #            self.PluginTreeSizer.Hide(self.PluginInfos[child]["right"])
       
   742             if force or self.PluginInfos[child]["expanded"]:
   716             if force or self.PluginInfos[child]["expanded"]:
   743                 self.CollapsePlugin(child, force)
   717                 self.CollapsePlugin(child, force)
   744                 if force:
   718                 if force:
   745                     self.PluginInfos[child]["expanded"] = False
   719                     self.PluginInfos[child]["expanded"] = False
       
   720         locations_infos = self.PluginInfos[plugin].get("locations_infos", None)
       
   721         if locations_infos is not None:
       
   722             if force or not locations_infos["root"]["expanded"]:
       
   723                 self.CollapseLocation(locations_infos, "root", force)
       
   724                 if force:
       
   725                     locations_infos["root"]["expanded"] = False
       
   726 
       
   727     def ExpandLocation(self, locations_infos, group, force = False):
       
   728         for child in locations_infos[group]["children"]:
       
   729             locations_infos[child]["left"].Show()
       
   730             locations_infos[child]["right"].Show()
       
   731             if force or not locations_infos[child]["expanded"]:
       
   732                 self.ExpandLocation(locations_infos, child, force)
       
   733                 if force:
       
   734                     locations_infos[child]["expanded"] = True
       
   735     
       
   736     def CollapseLocation(self, locations_infos, group, force = False):
       
   737         for child in locations_infos[group]["children"]:
       
   738             locations_infos[child]["left"].Hide()
       
   739             locations_infos[child]["right"].Hide()
       
   740             if force or not locations_infos[child]["expanded"]:
       
   741                 self.CollapseLocation(locations_infos, child, force)
       
   742                 if force:
       
   743                     locations_infos[child]["expanded"] = False
   746 
   744 
   747     def GenerateTreeBranch(self, plugin):
   745     def GenerateTreeBranch(self, plugin):
   748         leftwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1))
   746         leftwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1))
   749         if plugin.PlugTestModified():
   747         if plugin.PlugTestModified():
   750             bkgdclr=CHANGED_WINDOW_COLOUR
   748             bkgdclr=CHANGED_WINDOW_COLOUR
   751         else:
   749         else:
   752             bkgdclr=WINDOW_COLOUR
   750             bkgdclr=WINDOW_COLOUR
   753 
   751 
   754         leftwindow.SetBackgroundColour(bkgdclr)
   752         leftwindow.SetBackgroundColour(bkgdclr)
   755         
   753         
   756         if plugin not in self.PluginInfos:
   754         if not self.PluginInfos.has_key(plugin):
   757             self.PluginInfos[plugin] = {"expanded" : False, "left_visible" : False, "middle_visible" : False}
   755             self.PluginInfos[plugin] = {"expanded" : False, "right_visible" : False}
   758             
   756             
   759         self.PluginInfos[plugin]["children"] = plugin.IECSortedChilds()
   757         self.PluginInfos[plugin]["children"] = plugin.IECSortedChilds()
       
   758         plugin_locations = []
       
   759         if len(self.PluginInfos[plugin]["children"]) == 0:
       
   760             plugin_locations = plugin.GetVariableLocationTree()
       
   761             if not self.PluginInfos[plugin].has_key("locations_infos"):
       
   762                 self.PluginInfos[plugin]["locations_infos"] = {"root": {"expanded" : False}}
       
   763                 
       
   764             self.PluginInfos[plugin]["locations_infos"]["root"]["children"] = []
   760         
   765         
   761         self.PluginTreeSizer.AddWindow(leftwindow, 0, border=0, flag=wx.GROW)
   766         self.PluginTreeSizer.AddWindow(leftwindow, 0, border=0, flag=wx.GROW)
   762         
   767         
   763         leftwindowsizer = wx.FlexGridSizer(cols=1, rows=3)
   768         leftwindowsizer = wx.FlexGridSizer(cols=1, rows=2)
   764         leftwindowsizer.AddGrowableCol(0)
   769         leftwindowsizer.AddGrowableCol(0)
   765         leftwindowsizer.AddGrowableRow(2)
       
   766         leftwindow.SetSizer(leftwindowsizer)
   770         leftwindow.SetSizer(leftwindowsizer)
   767         
   771         
   768         leftbuttonmainsizer = wx.FlexGridSizer(cols=3, rows=1)
   772         leftbuttonmainsizer = wx.FlexGridSizer(cols=3, rows=1)
   769         leftbuttonmainsizer.AddGrowableCol(0)
   773         leftbuttonmainsizer.AddGrowableCol(0)
   770         leftwindowsizer.AddSizer(leftbuttonmainsizer, 0, border=5, flag=wx.GROW|wx.LEFT|wx.RIGHT) #|wx.TOP
   774         leftwindowsizer.AddSizer(leftbuttonmainsizer, 0, border=5, flag=wx.GROW|wx.LEFT|wx.RIGHT) #|wx.TOP
   863                 self.PluginInfos[plugin]["expanded"] = expandbutton.GetToggle()
   867                 self.PluginInfos[plugin]["expanded"] = expandbutton.GetToggle()
   864                 self.PLCConfigMainSizer.Layout()
   868                 self.PLCConfigMainSizer.Layout()
   865                 self.RefreshScrollBars()
   869                 self.RefreshScrollBars()
   866                 event.Skip()
   870                 event.Skip()
   867             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:
       
   873             locations_infos = self.PluginInfos[plugin]["locations_infos"]
       
   874             def togglebutton(event):
       
   875                 if expandbutton.GetToggle():
       
   876                     self.ExpandLocation(locations_infos, "root")
       
   877                 else:
       
   878                     self.CollapseLocation(locations_infos, "root")
       
   879                 locations_infos["root"]["expanded"] = expandbutton.GetToggle()
       
   880                 self.PLCConfigMainSizer.Layout()
       
   881                 self.RefreshScrollBars()
       
   882                 event.Skip()
       
   883             expandbutton.Bind(wx.EVT_BUTTON, togglebutton, id=expandbutton_id)
   868         else:
   884         else:
   869             expandbutton.Enable(False)
   885             expandbutton.Enable(False)
   870         iecsizer.AddWindow(expandbutton, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL)
   886         iecsizer.AddWindow(expandbutton, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL)
   871         
   887         
   872         tc_id = wx.NewId()
   888         tc_id = wx.NewId()
   874         tc.SetFont(wx.Font(faces["size"] * 0.75, wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = faces["helv"]))
   890         tc.SetFont(wx.Font(faces["size"] * 0.75, wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = faces["helv"]))
   875         tc.ChangeValue(plugin.MandatoryParams[1].getName())
   891         tc.ChangeValue(plugin.MandatoryParams[1].getName())
   876         tc.Bind(wx.EVT_TEXT, self.GetTextCtrlCallBackFunction(tc, plugin, "BaseParams.Name"), id=tc_id)
   892         tc.Bind(wx.EVT_TEXT, self.GetTextCtrlCallBackFunction(tc, plugin, "BaseParams.Name"), id=tc_id)
   877         iecsizer.AddWindow(tc, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL)
   893         iecsizer.AddWindow(tc, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL)
   878        
   894        
   879 
   895         rightwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1))
   880         leftminimizebutton_id = wx.NewId()
   896         rightwindow.SetBackgroundColour(bkgdclr)
   881         leftminimizebutton = wx.lib.buttons.GenBitmapToggleButton(id=leftminimizebutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'ShowVars.png')),
   897         
   882               name='MinimizeButton', parent=leftwindow, pos=wx.Point(0, 0),
   898         self.PluginTreeSizer.AddWindow(rightwindow, 0, border=0, flag=wx.GROW)
       
   899         
       
   900         rightwindowmainsizer = wx.BoxSizer(wx.VERTICAL)
       
   901         rightwindow.SetSizer(rightwindowmainsizer)
       
   902         
       
   903         rightwindowsizer = wx.FlexGridSizer(cols=2, rows=1)
       
   904         rightwindowsizer.AddGrowableCol(1)
       
   905         rightwindowsizer.AddGrowableRow(0)
       
   906         rightwindowmainsizer.AddSizer(rightwindowsizer, 0, border=8, flag=wx.TOP|wx.GROW)
       
   907         
       
   908         msizer = self.GenerateMethodButtonSizer(plugin, rightwindow, not self.PluginInfos[plugin]["right_visible"])
       
   909         rightwindowsizer.AddSizer(msizer, 0, border=0, flag=wx.GROW)
       
   910         
       
   911         rightparamssizer = wx.BoxSizer(wx.HORIZONTAL)
       
   912         rightwindowsizer.AddSizer(rightparamssizer, 0, border=0, flag=wx.ALIGN_RIGHT)
       
   913         
       
   914         paramswindow = wx.Panel(rightwindow, -1, size=wx.Size(-1, -1))
       
   915         paramswindow.SetBackgroundColour(bkgdclr)
       
   916         
       
   917         psizer = wx.BoxSizer(wx.HORIZONTAL)
       
   918         paramswindow.SetSizer(psizer)
       
   919         self.PluginInfos[plugin]["params"] = paramswindow
       
   920         
       
   921         rightparamssizer.AddWindow(paramswindow, 0, border=5, flag=wx.ALL)
       
   922         
       
   923         plugin_infos = plugin.GetParamsAttributes()
       
   924         self.RefreshSizerElement(paramswindow, psizer, plugin, plugin_infos, None, False)
       
   925         
       
   926         if not self.PluginInfos[plugin]["right_visible"]:
       
   927             paramswindow.Hide()
       
   928         
       
   929         rightminimizebutton_id = wx.NewId()
       
   930         rightminimizebutton = wx.lib.buttons.GenBitmapToggleButton(id=rightminimizebutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'Maximize.png')),
       
   931               name='MinimizeButton', parent=rightwindow, pos=wx.Point(0, 0),
   883               size=wx.Size(24, 24), style=wx.NO_BORDER)
   932               size=wx.Size(24, 24), style=wx.NO_BORDER)
   884         make_genbitmaptogglebutton_flat(leftminimizebutton)
   933         make_genbitmaptogglebutton_flat(rightminimizebutton)
   885         leftminimizebutton.SetBitmapSelected(wx.Bitmap(Bpath( 'images', 'HideVars.png')))
   934         rightminimizebutton.SetBitmapSelected(wx.Bitmap(Bpath( 'images', 'Minimize.png')))
   886         leftminimizebutton.SetToggle(self.PluginInfos[plugin]["left_visible"])
   935         rightminimizebutton.SetToggle(self.PluginInfos[plugin]["right_visible"])
   887         def toggleleftwindow(event):
   936         rightparamssizer.AddWindow(rightminimizebutton, 0, border=5, flag=wx.ALL)
   888             if leftminimizebutton.GetToggle():
   937                     
   889                 leftwindowsizer.Show(1)
   938         def togglerightwindow(event):
       
   939             if rightminimizebutton.GetToggle():
       
   940                 rightparamssizer.Show(0)
       
   941                 msizer.SetCols(1)
   890             else:
   942             else:
   891                 leftwindowsizer.Hide(1)
   943                 rightparamssizer.Hide(0)
   892             self.PluginInfos[plugin]["left_visible"] = leftminimizebutton.GetToggle()
   944                 msizer.SetCols(len(plugin.PluginMethods))
       
   945             self.PluginInfos[plugin]["right_visible"] = rightminimizebutton.GetToggle()
   893             self.PLCConfigMainSizer.Layout()
   946             self.PLCConfigMainSizer.Layout()
   894             self.RefreshScrollBars()
   947             self.RefreshScrollBars()
   895             event.Skip()
   948             event.Skip()
   896         leftminimizebutton.Bind(wx.EVT_BUTTON, toggleleftwindow, id=leftminimizebutton_id)
   949         rightminimizebutton.Bind(wx.EVT_BUTTON, togglerightwindow, id=rightminimizebutton_id)
   897         leftbuttonmainsizer.AddWindow(leftminimizebutton, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER)
       
   898 
       
   899         locations = plugin.GetLocations()
       
   900         lb = wx.ListBox(leftwindow, -1, size=wx.Size(-1, max(1, min(len(locations), 4)) * 25), style=wx.NO_BORDER)
       
   901         for location in locations:
       
   902             lb.Append(location["NAME"].replace("__", "%").replace("_", "."))
       
   903         if not self.PluginInfos[plugin]["left_visible"]:
       
   904             lb.Hide()
       
   905         self.PluginInfos[plugin]["variable_list"] = lb
       
   906         leftwindowsizer.AddWindow(lb, 0, border=5, flag=wx.GROW|wx.LEFT|wx.RIGHT|wx.BOTTOM)
       
   907 
       
   908         middlewindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1))
       
   909         middlewindow.SetBackgroundColour(bkgdclr)
       
   910         
       
   911         self.PluginTreeSizer.AddWindow(middlewindow, 0, border=0, flag=wx.GROW)
       
   912         
       
   913         middlewindowmainsizer = wx.BoxSizer(wx.VERTICAL)
       
   914         middlewindow.SetSizer(middlewindowmainsizer)
       
   915         
       
   916         middlewindowsizer = wx.FlexGridSizer(cols=2, rows=1)
       
   917         middlewindowsizer.AddGrowableCol(1)
       
   918         middlewindowsizer.AddGrowableRow(0)
       
   919         middlewindowmainsizer.AddSizer(middlewindowsizer, 0, border=8, flag=wx.TOP|wx.GROW)
       
   920         
       
   921         msizer = self.GenerateMethodButtonSizer(plugin, middlewindow, not self.PluginInfos[plugin]["middle_visible"])
       
   922         middlewindowsizer.AddSizer(msizer, 0, border=0, flag=wx.GROW)
       
   923         
       
   924         middleparamssizer = wx.BoxSizer(wx.HORIZONTAL)
       
   925         middlewindowsizer.AddSizer(middleparamssizer, 0, border=0, flag=wx.ALIGN_RIGHT)
       
   926         
       
   927         paramswindow = wx.Panel(middlewindow, -1, size=wx.Size(-1, -1))
       
   928         paramswindow.SetBackgroundColour(bkgdclr)
       
   929         
       
   930         psizer = wx.BoxSizer(wx.HORIZONTAL)
       
   931         paramswindow.SetSizer(psizer)
       
   932         self.PluginInfos[plugin]["params"] = paramswindow
       
   933         
       
   934         middleparamssizer.AddWindow(paramswindow, 0, border=5, flag=wx.ALL)
       
   935         
       
   936         plugin_infos = plugin.GetParamsAttributes()
       
   937         self.RefreshSizerElement(paramswindow, psizer, plugin, plugin_infos, None, False)
       
   938         
       
   939         if not self.PluginInfos[plugin]["middle_visible"]:
       
   940             paramswindow.Hide()
       
   941         
       
   942         middleminimizebutton_id = wx.NewId()
       
   943         middleminimizebutton = wx.lib.buttons.GenBitmapToggleButton(id=middleminimizebutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'Maximize.png')),
       
   944               name='MinimizeButton', parent=middlewindow, pos=wx.Point(0, 0),
       
   945               size=wx.Size(24, 24), style=wx.NO_BORDER)
       
   946         make_genbitmaptogglebutton_flat(middleminimizebutton)
       
   947         middleminimizebutton.SetBitmapSelected(wx.Bitmap(Bpath( 'images', 'Minimize.png')))
       
   948         middleminimizebutton.SetToggle(self.PluginInfos[plugin]["middle_visible"])
       
   949         middleparamssizer.AddWindow(middleminimizebutton, 0, border=5, flag=wx.ALL)
       
   950         
       
   951 #        rightwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1))
       
   952 #        rightwindow.SetBackgroundColour(wx.Colour(240,240,240))
       
   953 #        
       
   954 #        self.PluginTreeSizer.AddWindow(rightwindow, 0, border=0, flag=wx.GROW)
       
   955 #        
       
   956 #        rightsizer = wx.BoxSizer(wx.VERTICAL)
       
   957 #        rightwindow.SetSizer(rightsizer)
       
   958 #        
       
   959 #        rightmainsizer = wx.BoxSizer(wx.VERTICAL)
       
   960 #        rightsizer.AddSizer(rightmainsizer, 0, border=5, flag=wx.ALL)
       
   961 #        
       
   962 #        if len(plugin.PlugChildsTypes) > 0:
       
   963 #            addsizer = self.GenerateAddButtonSizer(plugin, rightwindow)
       
   964 #            rightmainsizer.AddSizer(addsizer, 0, border=4, flag=wx.TOP)
       
   965 #        else:
       
   966 #            addsizer = None
       
   967             
       
   968         def togglemiddlerightwindow(event):
       
   969             if middleminimizebutton.GetToggle():
       
   970                 middleparamssizer.Show(0)
       
   971                 msizer.SetCols(1)
       
   972 #                if addsizer is not None:
       
   973 #                    addsizer.SetCols(1)
       
   974             else:
       
   975                 middleparamssizer.Hide(0)
       
   976                 msizer.SetCols(len(plugin.PluginMethods))
       
   977 #                if addsizer is not None:
       
   978 #                    addsizer.SetCols(len(plugin.PlugChildsTypes))
       
   979             self.PluginInfos[plugin]["middle_visible"] = middleminimizebutton.GetToggle()
       
   980             self.PLCConfigMainSizer.Layout()
       
   981             self.RefreshScrollBars()
       
   982             event.Skip()
       
   983         middleminimizebutton.Bind(wx.EVT_BUTTON, togglemiddlerightwindow, id=middleminimizebutton_id)
       
   984         
   950         
   985         self.PluginInfos[plugin]["left"] = leftwindow
   951         self.PluginInfos[plugin]["left"] = leftwindow
   986         self.PluginInfos[plugin]["middle"] = middlewindow
   952         self.PluginInfos[plugin]["right"] = rightwindow
   987 #        self.PluginInfos[plugin]["right"] = rightwindow
       
   988         for child in self.PluginInfos[plugin]["children"]:
   953         for child in self.PluginInfos[plugin]["children"]:
   989             self.GenerateTreeBranch(child)
   954             self.GenerateTreeBranch(child)
   990             if not self.PluginInfos[child]["expanded"]:
   955             if not self.PluginInfos[child]["expanded"]:
   991                 self.CollapsePlugin(child)
   956                 self.CollapsePlugin(child)
   992 
   957         if len(plugin_locations) > 0:
   993     def RefreshVariableLists(self):
   958             locations_infos = self.PluginInfos[plugin]["locations_infos"]
   994         for plugin, infos in self.PluginInfos.items():
   959             for location in plugin_locations:
   995             locations = plugin.GetLocations()
   960                 locations_infos["root"]["children"].append("root.%s" % location["name"])
   996             infos["variable_list"].SetSize(wx.Size(-1, max(1, min(len(locations), 4)) * 25))
   961                 self.GenerateLocationTreeBranch(locations_infos, "root", location)
   997             infos["variable_list"].Clear()
   962                 if not locations_infos["root"]["expanded"]:
   998             for location in locations:
   963                     self.CollapseLocation(locations_infos, "root")
   999                 infos["variable_list"].Append(location["NAME"].replace("__", "%").replace("_", "."))
   964         
  1000         self.PLCConfigMainSizer.Layout()
   965     LOCATION_BITMAP = {LOCATION_VAR_INPUT: "VAR_INPUT",
  1001         self.RefreshScrollBars()
   966                        LOCATION_VAR_OUTPUT: "VAR_OUTPUT",
  1002         
   967                        LOCATION_VAR_MEMORY: "VAR_LOCAL"}
       
   968     
       
   969     def GenerateLocationTreeBranch(self, locations_infos, parent, location):
       
   970         leftwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1))
       
   971         self.PluginTreeSizer.AddWindow(leftwindow, 0, border=0, flag=wx.GROW)
       
   972         
       
   973         leftwindowsizer = wx.BoxSizer(wx.HORIZONTAL)
       
   974         leftwindow.SetSizer(leftwindowsizer)
       
   975         
       
   976         rightwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1))
       
   977         self.PluginTreeSizer.AddWindow(rightwindow, 0, border=0, flag=wx.GROW)
       
   978         
       
   979         location_name = "%s.%s" % (parent, location["name"])
       
   980         if not locations_infos.has_key(location_name):
       
   981             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         
       
   985         if location["type"] in [LOCATION_PLUGIN, LOCATION_MODULE, LOCATION_GROUP]:
       
   986             leftwindow.SetBackgroundColour(WINDOW_COLOUR)
       
   987             rightwindow.SetBackgroundColour(WINDOW_COLOUR)
       
   988                     
       
   989             st = wx.StaticText(leftwindow, -1)
       
   990             st.SetFont(wx.Font(faces["size"], wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = faces["helv"]))
       
   991             st.SetLabel(location["location"])
       
   992             leftwindowsizer.AddWindow(st, 0, border=5, flag=wx.RIGHT)
       
   993             
       
   994             expandbutton_id = wx.NewId()
       
   995             expandbutton = wx.lib.buttons.GenBitmapToggleButton(id=expandbutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'plus.png')),
       
   996                   name='ExpandButton', parent=leftwindow, pos=wx.Point(0, 0),
       
   997                   size=wx.Size(13, 13), style=wx.NO_BORDER)
       
   998             expandbutton.labelDelta = 0
       
   999             expandbutton.SetBezelWidth(0)
       
  1000             expandbutton.SetUseFocusIndicator(False)
       
  1001             expandbutton.SetBitmapSelected(wx.Bitmap(Bpath( 'images', 'minus.png')))
       
  1002             expandbutton.SetToggle(self.PluginInfos[plugin]["expanded"])
       
  1003                 
       
  1004             if len(location["children"]) > 0:
       
  1005                 def togglebutton(event):
       
  1006                     if expandbutton.GetToggle():
       
  1007                         self.ExpandLocation(locations_infos, location_name)
       
  1008                     else:
       
  1009                         self.CollapseLocation(locations_infos, location_name)
       
  1010                     locations_infos[location_name]["expanded"] = expandbutton.GetToggle()
       
  1011                     self.PLCConfigMainSizer.Layout()
       
  1012                     self.RefreshScrollBars()
       
  1013                     event.Skip()
       
  1014                 expandbutton.Bind(wx.EVT_BUTTON, togglebutton, id=expandbutton_id)
       
  1015             else:
       
  1016                 expandbutton.Enable(False)
       
  1017             leftwindowsizer.AddWindow(expandbutton, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL)
       
  1018             
       
  1019         else:
       
  1020             leftwindow.SetBackgroundColour(wx.WHITE)
       
  1021             rightwindow.SetBackgroundColour(wx.WHITE)
       
  1022             
       
  1023             leftwindowsizer.Add(wx.Size(50, 16), 0)
       
  1024             
       
  1025             st = wx.StaticBitmap(leftwindow, -1)
       
  1026             st.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)
       
  1028         
       
  1029         st_id = wx.NewId()
       
  1030         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"]))
       
  1032         st.SetLabel(location["name"])
       
  1033         if location["type"] in [LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY]:
       
  1034             infos = location.copy()
       
  1035             infos.pop("children")
       
  1036             st.Bind(wx.EVT_LEFT_DOWN, self.GenerateLocationLeftDownFunction(infos))
       
  1037         leftwindowsizer.AddWindow(st, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL)
       
  1038         
       
  1039         locations_infos[location_name]["left"] = leftwindow
       
  1040         locations_infos[location_name]["right"] = rightwindow
       
  1041         for child in locations_infos[location_name]["children"]:
       
  1042             self.GenerateLocationTreeBranch(child)
       
  1043             if not locations_infos[child]["expanded"]:
       
  1044                 self.CollapseLocation(locations_infos, child)
       
  1045     
       
  1046     def GenerateLocationLeftDownFunction(self, infos):
       
  1047         def OnLocationLeftDownFunction(event):
       
  1048             data = wx.TextDataObject(str((infos["location"], "location", infos["IEC_type"], infos["name"], infos["description"])))
       
  1049             dragSource = wx.DropSource(self)
       
  1050             dragSource.SetData(data)
       
  1051             dragSource.DoDragDrop()
       
  1052             event.Skip()
       
  1053         return OnLocationLeftDownFunction
       
  1054     
  1003     def RefreshAll(self):
  1055     def RefreshAll(self):
  1004         self.RefreshPLCParams()
  1056         self.RefreshPLCParams()
  1005         self.RefreshPluginTree()
  1057         self.RefreshPluginTree()
  1006         
  1058         
  1007     def GetItemChannelChangedFunction(self, plugin, value):
  1059     def GetItemChannelChangedFunction(self, plugin, value):