Modifying canfestival plugin to following the new Beremiz confnode paradigm
authorlaurent
Fri, 08 Jun 2012 12:39:37 +0200
changeset 762 aaacc83aa86b
parent 761 7788545f4137
child 763 c1104099c151
child 764 f338651eca36
Modifying canfestival plugin to following the new Beremiz confnode paradigm
Beremiz.py
ConfTreeNodeEditor.py
ProjectNodeEditor.py
canfestival/NetworkEditor.py
canfestival/SlaveEditor.py
canfestival/canfestival.py
targets/__init__.py
--- a/Beremiz.py	Thu Jun 07 01:14:58 2012 +0200
+++ b/Beremiz.py	Fri Jun 08 12:39:37 2012 +0200
@@ -438,7 +438,7 @@
         # Add beremiz's icon in top left corner of the frame
         self.SetIcon(wx.Icon(Bpath( "images", "brz.ico"), wx.BITMAP_TYPE_ICO))
         
-        if projectOpen is None and self.Config.HasEntry("currenteditedproject"):
+        if ctr is None and projectOpen is None and self.Config.HasEntry("currenteditedproject"):
             projectOpen = str(self.Config.Read("currenteditedproject"))
             if projectOpen == "":
                 projectOpen = None
--- a/ConfTreeNodeEditor.py	Thu Jun 07 01:14:58 2012 +0200
+++ b/ConfTreeNodeEditor.py	Fri Jun 08 12:39:37 2012 +0200
@@ -146,6 +146,7 @@
 class ConfTreeNodeEditor(EditorPanel):
     
     HAS_BASE_PARAMS = True
+    SHOW_PARAMS = True
     
     def _init_ConfNodeEditor(self, prnt):
         self.ConfNodeEditor = None
@@ -156,80 +157,86 @@
         self.SetNeedUpdating(True)
         self.SetMinimumPaneSize(1)
         
-        self.ParamsEditor = wx.ScrolledWindow(self.Editor, -1, size=wx.Size(-1, -1),
-                        style=wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER|wx.HSCROLL|wx.VSCROLL)
-        self.ParamsEditor.SetBackgroundColour(WINDOW_COLOUR)
-        self.ParamsEditor.Bind(wx.EVT_SIZE, self.OnWindowResize)
-        self.ParamsEditor.Bind(wx.EVT_MOUSEWHEEL, self.OnMouseWheel)
-        
-        # Variable allowing disabling of ParamsEditor scroll when Popup shown 
-        self.ScrollingEnabled = True
-        
-        self.ParamsEditorSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5)
-        self.ParamsEditorSizer.AddGrowableCol(0)
-        self.ParamsEditorSizer.AddGrowableRow(1)
-        
-        self.ParamsEditor.SetSizer(self.ParamsEditorSizer)
-        
-        baseparamseditor_sizer = wx.BoxSizer(wx.HORIZONTAL)
-        self.ParamsEditorSizer.AddSizer(baseparamseditor_sizer, 0, border=5, 
-                                        flag=wx.GROW|wx.LEFT|wx.RIGHT|wx.TOP)
-        
-        self.FullIECChannel = wx.StaticText(self.ParamsEditor, -1)
-        self.FullIECChannel.SetFont(
-            wx.Font(faces["size"], wx.DEFAULT, wx.NORMAL, 
-                    wx.BOLD, faceName = faces["helv"]))
-        baseparamseditor_sizer.AddWindow(self.FullIECChannel, 0, border=0, flag=wx.ALIGN_CENTER_VERTICAL)
-        
-        updownsizer = wx.BoxSizer(wx.VERTICAL)
-        baseparamseditor_sizer.AddSizer(updownsizer, 0, border=5, 
-                                    flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL)
-        
-        ieccupbutton_id = wx.NewId()
-        self.IECCUpButton = wx.lib.buttons.GenBitmapTextButton(
-              id=ieccupbutton_id, bitmap=wx.Bitmap(opjimg('IECCDown')),
-              name='IECUpButton', parent=self.ParamsEditor, pos=wx.Point(0, 0),
-              size=wx.Size(16, 16), style=wx.NO_BORDER)
-        self.IECCUpButton.Bind(wx.EVT_BUTTON, self.GetItemChannelChangedFunction(1), 
-                              id=ieccupbutton_id)
-        updownsizer.AddWindow(self.IECCUpButton, 0, border=0, flag=wx.ALIGN_LEFT)
-        
-        ieccdownbutton_id = wx.NewId()
-        self.IECCDownButton = wx.lib.buttons.GenBitmapButton(
-              id=ieccdownbutton_id, bitmap=wx.Bitmap(opjimg('IECCUp')),
-              name='IECDownButton', parent=self.ParamsEditor, pos=wx.Point(0, 0),
-              size=wx.Size(16, 16), style=wx.NO_BORDER)
-        self.IECCDownButton.Bind(wx.EVT_BUTTON, self.GetItemChannelChangedFunction(-1), 
-                                id=ieccdownbutton_id)
-        updownsizer.AddWindow(self.IECCDownButton, 0, border=0, flag=wx.ALIGN_LEFT)
-        
-        confnodename_id = wx.NewId()
-        self.ConfNodeName = wx.TextCtrl(
-              self.ParamsEditor, confnodename_id, 
-              size=wx.Size(150, 25), style=wx.NO_BORDER)
-        self.ConfNodeName.SetFont(
-            wx.Font(faces["size"] * 0.75, wx.DEFAULT, wx.NORMAL, 
-                    wx.BOLD, faceName = faces["helv"]))
-        self.ConfNodeName.Bind(wx.EVT_TEXT, 
-            self.GetTextCtrlCallBackFunction(self.ConfNodeName, "BaseParams.Name", True), 
-            id=confnodename_id)
-        baseparamseditor_sizer.AddWindow(self.ConfNodeName, 0, border=5, flag=wx.LEFT|wx.RIGHT|wx.ALIGN_CENTER_VERTICAL)
-        
-        buttons_sizer = self.GenerateMethodButtonSizer()
-        baseparamseditor_sizer.AddSizer(buttons_sizer, 0, border=0, flag=wx.ALIGN_CENTER)
-        
-        self.ConfNodeParamsSizer = wx.BoxSizer(wx.VERTICAL)
-        self.ParamsEditorSizer.AddSizer(self.ConfNodeParamsSizer, 0, border=5, 
-                                        flag=wx.LEFT|wx.RIGHT|wx.BOTTOM)
+        if self.SHOW_PARAMS:
+            self.ParamsEditor = wx.ScrolledWindow(self.Editor, -1, size=wx.Size(-1, -1),
+                            style=wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER|wx.HSCROLL|wx.VSCROLL)
+            self.ParamsEditor.SetBackgroundColour(WINDOW_COLOUR)
+            self.ParamsEditor.Bind(wx.EVT_SIZE, self.OnWindowResize)
+            self.ParamsEditor.Bind(wx.EVT_MOUSEWHEEL, self.OnMouseWheel)
+            
+            # Variable allowing disabling of ParamsEditor scroll when Popup shown 
+            self.ScrollingEnabled = True
+            
+            self.ParamsEditorSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5)
+            self.ParamsEditorSizer.AddGrowableCol(0)
+            self.ParamsEditorSizer.AddGrowableRow(1)
+            
+            self.ParamsEditor.SetSizer(self.ParamsEditorSizer)
+            
+            baseparamseditor_sizer = wx.BoxSizer(wx.HORIZONTAL)
+            self.ParamsEditorSizer.AddSizer(baseparamseditor_sizer, 0, border=5, 
+                                            flag=wx.GROW|wx.LEFT|wx.RIGHT|wx.TOP)
+            
+            self.FullIECChannel = wx.StaticText(self.ParamsEditor, -1)
+            self.FullIECChannel.SetFont(
+                wx.Font(faces["size"], wx.DEFAULT, wx.NORMAL, 
+                        wx.BOLD, faceName = faces["helv"]))
+            baseparamseditor_sizer.AddWindow(self.FullIECChannel, 0, border=0, flag=wx.ALIGN_CENTER_VERTICAL)
+            
+            updownsizer = wx.BoxSizer(wx.VERTICAL)
+            baseparamseditor_sizer.AddSizer(updownsizer, 0, border=5, 
+                                        flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL)
+            
+            ieccupbutton_id = wx.NewId()
+            self.IECCUpButton = wx.lib.buttons.GenBitmapTextButton(
+                  id=ieccupbutton_id, bitmap=wx.Bitmap(opjimg('IECCDown')),
+                  name='IECUpButton', parent=self.ParamsEditor, pos=wx.Point(0, 0),
+                  size=wx.Size(16, 16), style=wx.NO_BORDER)
+            self.IECCUpButton.Bind(wx.EVT_BUTTON, self.GetItemChannelChangedFunction(1), 
+                                  id=ieccupbutton_id)
+            updownsizer.AddWindow(self.IECCUpButton, 0, border=0, flag=wx.ALIGN_LEFT)
+            
+            ieccdownbutton_id = wx.NewId()
+            self.IECCDownButton = wx.lib.buttons.GenBitmapButton(
+                  id=ieccdownbutton_id, bitmap=wx.Bitmap(opjimg('IECCUp')),
+                  name='IECDownButton', parent=self.ParamsEditor, pos=wx.Point(0, 0),
+                  size=wx.Size(16, 16), style=wx.NO_BORDER)
+            self.IECCDownButton.Bind(wx.EVT_BUTTON, self.GetItemChannelChangedFunction(-1), 
+                                    id=ieccdownbutton_id)
+            updownsizer.AddWindow(self.IECCDownButton, 0, border=0, flag=wx.ALIGN_LEFT)
+            
+            confnodename_id = wx.NewId()
+            self.ConfNodeName = wx.TextCtrl(
+                  self.ParamsEditor, confnodename_id, 
+                  size=wx.Size(150, 25), style=wx.NO_BORDER)
+            self.ConfNodeName.SetFont(
+                wx.Font(faces["size"] * 0.75, wx.DEFAULT, wx.NORMAL, 
+                        wx.BOLD, faceName = faces["helv"]))
+            self.ConfNodeName.Bind(wx.EVT_TEXT, 
+                self.GetTextCtrlCallBackFunction(self.ConfNodeName, "BaseParams.Name", True), 
+                id=confnodename_id)
+            baseparamseditor_sizer.AddWindow(self.ConfNodeName, 0, border=5, flag=wx.LEFT|wx.RIGHT|wx.ALIGN_CENTER_VERTICAL)
+            
+            buttons_sizer = self.GenerateMethodButtonSizer()
+            baseparamseditor_sizer.AddSizer(buttons_sizer, 0, border=0, flag=wx.ALIGN_CENTER)
+            
+            self.ConfNodeParamsSizer = wx.BoxSizer(wx.VERTICAL)
+            self.ParamsEditorSizer.AddSizer(self.ConfNodeParamsSizer, 0, border=5, 
+                                            flag=wx.LEFT|wx.RIGHT|wx.BOTTOM)
+        else:
+            self.ParamsEditor = None
         
         self._init_ConfNodeEditor(self.Editor)
             
         if self.ConfNodeEditor is not None:
-            min_size = self.ParamsEditorSizer.GetMinSize()
-            self.Editor.SplitHorizontally(self.ParamsEditor, 
-                                   self.ConfNodeEditor, 
-                                   min(min_size.height, 200))
-        else:
+            if self.ParamsEditor is not None:
+                min_size = self.ParamsEditorSizer.GetMinSize()
+                self.Editor.SplitHorizontally(self.ParamsEditor, 
+                                              self.ConfNodeEditor, 
+                                              min(min_size.height, 200))
+            else:
+                self.Editor.Initialize(self.ConfNodeEditor)
+        elif self.ParamsEditor is not None:
             self.Editor.Initialize(self.ParamsEditor)
     
     def __init__(self, parent, controler, window, tagname=""):
@@ -266,9 +273,10 @@
     
     def RefreshView(self):
         EditorPanel.RefreshView(self)
-        self.ConfNodeName.ChangeValue(self.Controler.MandatoryParams[1].getName())
-        self.RefreshIECChannelControlsState()
-        self.RefreshConfNodeParamsSizer()
+        if self.ParamsEditor is not None:
+            self.ConfNodeName.ChangeValue(self.Controler.MandatoryParams[1].getName())
+            self.RefreshIECChannelControlsState()
+            self.RefreshConfNodeParamsSizer()
     
     def EnableScrolling(self, enable):
         self.ScrollingEnabled = enable
--- a/ProjectNodeEditor.py	Thu Jun 07 01:14:58 2012 +0200
+++ b/ProjectNodeEditor.py	Fri Jun 08 12:39:37 2012 +0200
@@ -7,6 +7,7 @@
 class ProjectNodeEditor(ConfTreeNodeEditor):
     
     VARIABLE_PANEL_TYPE = "config"
+    ENABLE_REQUIRED = True
     
     def _init_Editor(self, prnt):
         self.Editor = wx.ScrolledWindow(prnt, -1, size=wx.Size(-1, -1),
@@ -34,11 +35,14 @@
         self.ParamsEditorSizer.AddSizer(projectproperties_sizer, 0, border=5, 
                                         flag=wx.LEFT|wx.RIGHT|wx.BOTTOM)
         
-        self.ConfNodeParamsSizer = wx.BoxSizer(wx.VERTICAL)
-        projectproperties_sizer.AddSizer(self.ConfNodeParamsSizer, 0, border=5, 
-                                         flag=wx.RIGHT)
+        if self.SHOW_PARAMS:
+            self.ConfNodeParamsSizer = wx.BoxSizer(wx.VERTICAL)
+            projectproperties_sizer.AddSizer(self.ConfNodeParamsSizer, 0, border=5, 
+                                             flag=wx.RIGHT)
+        else:
+            self.ConfNodeParamsSizer = None
         
-        self.ProjectProperties = ProjectPropertiesPanel(self.Editor, self.Controler, self.ParentWindow)
+        self.ProjectProperties = ProjectPropertiesPanel(self.Editor, self.Controler, self.ParentWindow, self.ENABLE_REQUIRED)
         projectproperties_sizer.AddWindow(self.ProjectProperties, 0, border=0, flag=0)
         
     def __init__(self, parent, controler, window):
@@ -61,7 +65,8 @@
     
     def RefreshView(self):
         EditorPanel.RefreshView(self)
-        self.RefreshConfNodeParamsSizer()
+        if self.ConfNodeParamsSizer is not None:
+            self.RefreshConfNodeParamsSizer()
         self.ProjectProperties.RefreshView()
 
     def GetBufferState(self):
--- a/canfestival/NetworkEditor.py	Thu Jun 07 01:14:58 2012 +0200
+++ b/canfestival/NetworkEditor.py	Fri Jun 08 12:39:37 2012 +0200
@@ -3,7 +3,7 @@
 
 from subindextable import EditingPanel
 from networkedit import NetworkEditorTemplate
-from controls import EditorPanel
+from ConfTreeNodeEditor import ConfTreeNodeEditor
 
 [ID_NETWORKEDITOR, 
 ] = [wx.NewId() for _init_ctrls in range(1)]
@@ -22,7 +22,7 @@
  ID_NETWORKEDITORADDMENUMAPVARIABLE, ID_NETWORKEDITORADDMENUUSERTYPE,
 ] = [wx.NewId() for _init_coll_AddMenu_Items in range(6)]
 
-class NetworkEditor(EditorPanel, NetworkEditorTemplate):
+class NetworkEditor(ConfTreeNodeEditor, NetworkEditorTemplate):
     
     ID = ID_NETWORKEDITOR
     
@@ -39,23 +39,20 @@
         self._init_coll_MainSizer_Items(self.MainSizer)
         self._init_coll_MainSizer_Growables(self.MainSizer)
         
-        self.Editor.SetSizer(self.MainSizer)
+        self.ConfNodeEditor.SetSizer(self.MainSizer)
     
-    def _init_Editor(self, prnt):
-        self.Editor = wx.Panel(id=-1, parent=prnt, pos=wx.Point(0, 0), 
+    def _init_ConfNodeEditor(self, prnt):
+        self.ConfNodeEditor = wx.Panel(id=-1, parent=prnt, pos=wx.Point(0, 0), 
                 size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL)
         
-        NetworkEditorTemplate._init_ctrls(self, self.Editor)
+        NetworkEditorTemplate._init_ctrls(self, self.ConfNodeEditor)
         
         self._init_sizers()
         
     def __init__(self, parent, controler, window):
-        EditorPanel.__init__(self, parent, "", window, controler)
+        ConfTreeNodeEditor.__init__(self, parent, controler, window)
         NetworkEditorTemplate.__init__(self, controler, window, False)
     
-        img = wx.Bitmap(controler.GetIconPath(), wx.BITMAP_TYPE_PNG).ConvertToImage()
-        self.SetIcon(wx.BitmapFromImage(img.Rescale(16, 16)))
-        
         self.RefreshNetworkNodes()
         self.RefreshBufferState()
     
@@ -97,13 +94,8 @@
     def RefreshConfNodeMenu(self, confnode_menu):
         confnode_menu.Enable(ID_NETWORKEDITORCONFNODEMENUMASTER, self.NetworkNodes.GetSelection() == 0)
     
-    def GetTitle(self):
-        fullname = self.Controler.CTNFullName()
-        if not self.Manager.CurrentIsSaved():
-            return "~%s~" % fullname
-        return fullname
-
     def RefreshView(self):
+        ConfTreeNodeEditor.RefreshView(self)
         self.RefreshCurrentIndexList()
     
     def RefreshBufferState(self):
@@ -116,4 +108,3 @@
     def OnNodeSelectedChanged(self, event):
         NetworkEditorTemplate.OnNodeSelectedChanged(self, event)
         wx.CallAfter(self.ParentWindow.RefreshConfNodeMenu)
-        
--- a/canfestival/SlaveEditor.py	Thu Jun 07 01:14:58 2012 +0200
+++ b/canfestival/SlaveEditor.py	Fri Jun 08 12:39:37 2012 +0200
@@ -3,7 +3,7 @@
 
 from subindextable import EditingPanel
 from nodeeditor import NodeEditorTemplate
-from controls import EditorPanel
+from ConfTreeNodeEditor import ConfTreeNodeEditor
 
 [ID_SLAVEEDITORCONFNODEMENUNODEINFOS, ID_SLAVEEDITORCONFNODEMENUDS301PROFILE,
  ID_SLAVEEDITORCONFNODEMENUDS302PROFILE, ID_SLAVEEDITORCONFNODEMENUDSOTHERPROFILE,
@@ -15,18 +15,15 @@
  ID_SLAVEEDITORADDMENUMAPVARIABLE, ID_SLAVEEDITORADDMENUUSERTYPE,
 ] = [wx.NewId() for _init_coll_AddMenu_Items in range(6)]
 
-class SlaveEditor(EditorPanel, NodeEditorTemplate):
+class SlaveEditor(ConfTreeNodeEditor, NodeEditorTemplate):
     
-    def _init_Editor(self, prnt):
-        self.Editor = EditingPanel(prnt, self, self.Controler, self.Editable)
+    def _init_ConfNodeEditor(self, prnt):
+        self.ConfNodeEditor = EditingPanel(prnt, self, self.Controler, self.Editable)
         
     def __init__(self, parent, controler, window, editable=True):
         self.Editable = editable
-        EditorPanel.__init__(self, parent, "", window, controler)
+        ConfTreeNodeEditor.__init__(self, parent, controler, window)
         NodeEditorTemplate.__init__(self, controler, window, False)
-        
-        img = wx.Bitmap(controler.GetIconPath(), wx.BITMAP_TYPE_PNG).ConvertToImage()
-        self.SetIcon(wx.BitmapFromImage(img.Rescale(16, 16)))
     
     def __del__(self):
         self.Controler.OnCloseEditor(self)
@@ -59,15 +56,10 @@
     
     def RefreshConfNodeMenu(self, confnode_menu):
         confnode_menu.Enable(ID_SLAVEEDITORCONFNODEMENUDSOTHERPROFILE, False)
-    
-    def GetTitle(self):
-        fullname = self.Controler.CTNFullName()
-        if not self.Controler.CurrentIsSaved():
-            return "~%s~" % fullname
-        return fullname
 
     def RefreshView(self):
-        self.Editor.RefreshIndexList()
+        ConfTreeNodeEditor.RefreshView(self)
+        self.ConfNodeEditor.RefreshIndexList()
 
     def RefreshCurrentIndexList(self):
         self.RefreshView()
--- a/canfestival/canfestival.py	Thu Jun 07 01:14:58 2012 +0200
+++ b/canfestival/canfestival.py	Fri Jun 08 12:39:37 2012 +0200
@@ -271,11 +271,11 @@
                 app_frame.DeletePage(self._GeneratedView)
     
     ConfNodeMethods = [
-        {"bitmap" : os.path.join("images", "NetworkEdit"),
+        {"bitmap" : "NetworkEdit",
          "name" : _("Edit network"), 
          "tooltip" : _("Edit CanOpen Network with NetworkEdit"),
          "method" : "_OpenView"},
-        {"bitmap" : os.path.join("images", "ShowMaster"),
+        {"bitmap" : "ShowMaster",
          "name" : _("Show Master"), 
          "tooltip" : _("Show Master generated by config_utils"),
          "method" : "_ShowMasterGenerated"}
--- a/targets/__init__.py	Thu Jun 07 01:14:58 2012 +0200
+++ b/targets/__init__.py	Fri Jun 08 12:39:37 2012 +0200
@@ -37,8 +37,8 @@
     return lambda:getattr(__import__(name,globals(),locals()), name+"_target")
 
 targets = dict([(name, {"xsd":path.join(_base_path, name, "XSD"), 
-                  "class":_GetLocalTargetClassFactory(name),
-                  "code": path.join(path.split(__file__)[0],name,"plc_%s_main.c"%name)})
+                        "class":_GetLocalTargetClassFactory(name),
+                        "code": path.join(path.split(__file__)[0],name,"plc_%s_main.c"%name)})
                 for name in listdir(_base_path) 
                     if path.isdir(path.join(_base_path, name)) 
                        and not name.startswith("__")])