minor fixes
authoretisserant
Mon, 10 Sep 2007 14:10:03 +0200
changeset 23 e007d9d466d7
parent 22 9a0c535c3272
child 24 585d5b387b6a
minor fixes
Beremiz.py
plugger.py
plugins/canfestival/canfestival.py
--- a/Beremiz.py	Fri Sep 07 10:19:04 2007 +0200
+++ b/Beremiz.py	Mon Sep 10 14:10:03 2007 +0200
@@ -578,15 +578,15 @@
                     pos=wx.Point(0, 0), size=wx.Size(100, 17), style=0)
                 boxsizer.AddWindow(statictext, 0, border=0, flag=wx.TOP|wx.LEFT|wx.BOTTOM)
                 id = wx.NewId()
-                min = -sys.maxint-1
-                max = sys.maxint
+                scmin = -(2**31)
+                scmax = 2**31-1
                 if "min" in element_infos["type"]:
-                    min = element_infos["type"]["min"]
+                    scmin = element_infos["type"]["min"]
                 if "max" in element_infos["type"]:
-                    max = element_infos["type"]["max"]
+                    scmax = element_infos["type"]["max"]
                 spinctrl = wx.SpinCtrl(id=id, name=element_infos["name"], parent=self.ParamsPanel, 
-                    pos=wx.Point(0, 0), size=wx.Size(150, 25), style=wx.SP_ARROW_KEYS|wx.ALIGN_RIGHT, 
-                    min=min, max=max)
+                    pos=wx.Point(0, 0), size=wx.Size(150, 25), style=wx.SP_ARROW_KEYS|wx.ALIGN_RIGHT)
+                spinctrl.SetRange(scmin,scmax)
                 boxsizer.AddWindow(spinctrl, 0, border=0, flag=0)
                 spinctrl.Bind(wx.EVT_SPINCTRL, self.GetTextCtrlCallBackFunction(spinctrl, element_path), id=id)
                 spinctrl.SetValue(element_infos["value"])
@@ -618,8 +618,14 @@
                     checkbox.Bind(wx.EVT_CHECKBOX, self.GetCheckBoxCallBackFunction(checkbox, element_path), id=id)
                     checkbox.SetValue(element_infos["value"])
                 elif element_infos["type"] in ["unsignedLong", "long","integer"]:
+                    if element_infos["type"].startswith("unsigned"):
+                        scmin = 0
+                    else:
+                        scmin = -(2**31)
+                    scmax = 2**31-1
                     spinctrl = wx.SpinCtrl(id=id, name=element_infos["name"], parent=self.ParamsPanel, 
                         pos=wx.Point(0, 0), size=wx.Size(150, 25), style=wx.SP_ARROW_KEYS|wx.ALIGN_RIGHT)
+                    spinctrl.SetRange(scmin, scmax)
                     boxsizer.AddWindow(spinctrl, 0, border=0, flag=0)
                     spinctrl.Bind(wx.EVT_SPINCTRL, self.GetTextCtrlCallBackFunction(spinctrl, element_path), id=id)
                     spinctrl.SetValue(element_infos["value"])
--- a/plugger.py	Fri Sep 07 10:19:04 2007 +0200
+++ b/plugger.py	Mon Sep 10 14:10:03 2007 +0200
@@ -154,7 +154,11 @@
         # recurse through all childs, and stack their results
         for PlugChild in self.IterChilds():
             # Compute child's IEC location
-            new_location = current_location + (self.BaseParams.getIEC_Channel())
+            if current_location:
+                new_location = current_location + (self.BaseParams.getIEC_Channel())
+            else:
+                # root 
+                new_location = ()
             # Get childs [(Cfiles, CFLAGS)], LDFLAGS
             CFilesAndCFLAGS, LDFLAGS = \
                 PlugChild._Generate_C(
@@ -203,6 +207,12 @@
     def GetChildByIECLocation(self, Location):
         return self._GetChildBySomething('_',"IEC_Channel", Name)
     
+    def GetCurrentLocation(self):
+        return self.PlugParent.GetCurrentLocation() + (self.BaseParams.getIEC_Channel(),)
+
+    def GetPlugRoot(self):
+        return self.PlugParent.GetPlugRoot()
+
     def GetPlugInfos(self):
         childs = []
         for child in self.IterChilds():
@@ -352,10 +362,10 @@
         for PlugDir in os.listdir(self.PlugPath()):
             if os.path.isdir(os.path.join(self.PlugPath(), PlugDir)) and \
                PlugDir.count(NameTypeSeparator) == 1:
-                try:
-                    self.PlugAddChild(*PlugDir.split(NameTypeSeparator))
-                except Exception, e:
-                    print e
+                #try:
+                self.PlugAddChild(*PlugDir.split(NameTypeSeparator))
+                #except Exception, e:
+                #    print e
 
 def _GetClassFunction(name):
     def GetRootClass():
@@ -464,7 +474,7 @@
         self.PluggedChilds = {}
         """
 
-        # self is the parent
+        # root have no parent
         self.PlugParent = None
         # Keep track of the plugin type name
         self.PlugType = "Beremiz"
@@ -479,6 +489,12 @@
         Return if a project is actually opened
         """
         return self.ProjectPath != None
+
+    def GetPlugRoot(self):
+        return self
+
+    def GetCurrentLocation(self):
+        return ()
     
     def GetProjectPath(self):
         return self.ProjectPath
@@ -609,7 +625,7 @@
         C_files.remove("POUS.c")
         C_files.remove("LOCATED_VARIABLES.h")
         # transform those base names to full names with path
-        C_files = map(lambda filename:os.path.join(self.TargetDir, filename), C_files)
+        C_files = map(lambda filename:os.path.join(buildpath, filename), C_files)
         logger.write("Extracting Located Variables...\n")
         # IEC2CC compiler generate a list of located variables : LOCATED_VARIABLES.h
         location_file = open(os.path.join(buildpath,"LOCATED_VARIABLES.h"))
@@ -657,16 +673,16 @@
         logger.write("SoftPLC code generation successfull\n")
         
         # Generate C code and compilation params from plugin hierarchy
-        try:
-            CFilesAndCFLAGS, LDFLAGS = self._Generate_C(
-                buildpath, 
-                (), 
-                self.PLCGeneratedLocatedVars,
-                logger)
-        except Exception, msg:
-            logger.write_error("Plugins code generation Failed !\n")
-            logger.write_error(str(msg))
-            return False
+        #try:
+        CFilesAndCFLAGS, LDFLAGS = self._Generate_C(
+            buildpath, 
+            None, #root has no location
+            self.PLCGeneratedLocatedVars,
+            logger)
+        #except Exception, msg:
+        #    logger.write_error("Plugins code generation Failed !\n")
+        #    logger.write_error(str(msg))
+        #    return False
 
         logger.write("Plugins code generation successfull\n")
 
--- a/plugins/canfestival/canfestival.py	Fri Sep 07 10:19:04 2007 +0200
+++ b/plugins/canfestival/canfestival.py	Mon Sep 10 14:10:03 2007 +0200
@@ -27,7 +27,8 @@
 
     def __init__(self):
         manager = NodeManager()
-        NodeList.__init__(self, manager)
+        # TODO change netname when name change
+        NodeList.__init__(self, manager, self.BaseParams.getName())
         self.LoadProject(self.PlugPath())
 
     _View = None
@@ -35,9 +36,12 @@
         if not self._View:
             def _onclose():
                 self.View = None
-            self._View = _NetworkEdit()
+            self._View = _NetworkEdit(self.GetPlugRoot().AppFrame, self)
+            # TODO redefine BusId when IEC channel change
+            self._View.SetBusId(self.GetCurrentLocation())
             self._View._onclose = _onclose
-        return self.View
+            self._View.Show()
+
     PluginMethods = [("NetworkEdit",_OpenView)]
 
     def OnPlugClose(self):
@@ -88,7 +92,7 @@
 
     PlugChildsTypes = [("CanOpenNode",_NodeListPlug)]
     
-    def PlugGenerate_C(self, buildpath, current_location, locations):
+    def PlugGenerate_C(self, buildpath, current_location, locations, logger):
         return [],""