Adding support for refreshing PLCOpenEditor block list
authorlbessard
Mon, 17 Sep 2007 10:13:56 +0200
changeset 92 76d5001393df
parent 91 e8e9ddeed76c
child 93 c3c24b979a4d
Adding support for refreshing PLCOpenEditor block list
PLCControler.py
PLCOpenEditor.py
plcopen/structures.py
xmlclass/xmlclass.py
--- a/PLCControler.py	Thu Sep 13 09:46:51 2007 +0200
+++ b/PLCControler.py	Mon Sep 17 10:13:56 2007 +0200
@@ -864,7 +864,7 @@
                             if isinstance(instance, plcopen.comment):
                                 block_infos["comment"] = instance.getContentText()
                     BlockTypes[-1]["list"].append(block_infos)
-
+    
     # Return Block types checking for recursion
     def GetBlockTypes(self):
         if self.CurrentElementEditing != None:
@@ -881,7 +881,7 @@
                 type = None
             if type == "function":
                 blocktypes = []
-                for category in BlockTypes[:-1]:
+                for category in BlockTypes[:-1] + PluginTypes:
                     cat = {"name" : category["name"], "list" : []}
                     for block in category["list"]:
                         if block["type"] == "function":
@@ -889,7 +889,7 @@
                     if len(cat["list"]) > 0:
                         blocktypes.append(cat)
             else:
-                blocktypes = [category for category in BlockTypes[:-1]]
+                blocktypes = [category for category in BlockTypes[:-1] + PluginTypes]
             if self.Project:
                 blocktypes.append({"name" : "User-defined POUs", "list": []})
                 for blocktype in BlockTypes[-1]["list"]:
@@ -925,7 +925,6 @@
             return blocktypes
         return []
 
-
     # Return Block types checking for recursion
     def GetBlockResource(self):
         blocktypes = []
--- a/PLCOpenEditor.py	Thu Sep 13 09:46:51 2007 +0200
+++ b/PLCOpenEditor.py	Mon Sep 17 10:13:56 2007 +0200
@@ -39,31 +39,6 @@
 
 __version__ = "$Revision$"
 
-def create(parent):
-    return PLCOpenEditor(parent)
-
-def usage():
-    print "\nUsage of PLCOpenEditor.py :"
-    print "\n   %s [Filepath]\n"%sys.argv[0]
-
-try:
-    opts, args = getopt.getopt(sys.argv[1:], "h", ["help"])
-except getopt.GetoptError:
-    # print help information and exit:
-    usage()
-    sys.exit(2)
-
-for o, a in opts:
-    if o in ("-h", "--help"):
-        usage()
-        sys.exit()
-
-fileOpen = None
-if len(args) > 1:
-    usage()
-    sys.exit()
-elif len(args) == 1:
-    fileOpen = args[0]
 CWD = os.path.split(__file__)[0]
 
 [ID_PLCOPENEDITOR, ID_PLCOPENEDITORPROJECTTREE, 
@@ -345,18 +320,19 @@
         self._init_utils()
         self.SetClientSize(wx.Size(1000, 600))
         self.SetMenuBar(self.menuBar1)
-        self.Bind(wx.EVT_CLOSE, self.OnCloseFrame, id=ID_PLCOPENEDITOR)
+        self.Bind(wx.EVT_CLOSE, self.OnCloseFrame)
         if not self.ModeSolo:
             self.Bind(wx.EVT_MENU, self.OnSaveProjectMenu, id=ID_PLCOPENEDITORFILEMENUITEMS5)
             accel = wx.AcceleratorTable([wx.AcceleratorEntry(wx.ACCEL_CTRL, 83, ID_PLCOPENEDITORFILEMENUITEMS5)])
             self.SetAcceleratorTable(accel)
+            self.Bind(wx.EVT_ACTIVATE, self.OnFrameActivated)
         
         self.MainSplitter = wx.SplitterWindow(id=ID_PLCOPENEDITORMAINSPLITTER,
               name='MainSplitter', parent=self, point=wx.Point(0, 0),
               size=wx.Size(0, 0), style=wx.SP_3D)
         self.MainSplitter.SetNeedUpdating(True)
         self.MainSplitter.SetMinimumPaneSize(1)
-
+        
         self.EditorPanel = wx.Panel(id=ID_PLCOPENEDITOREDITORPANEL, 
               name='TabPanel', parent=self.MainSplitter, pos=wx.Point(0, 0),
               size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL)
@@ -395,7 +371,7 @@
         
         self._init_sizers()
 
-    def __init__(self, parent, controler = None):
+    def __init__(self, parent, controler = None, fileOpen = None):
         self.ModeSolo = controler == None
         self._init_ctrls(parent)
         
@@ -406,13 +382,12 @@
         
         if self.ModeSolo:
             self.Controler = PLCControler()
+            if fileOpen:
+                self.Controler.OpenXMLFile(fileOpen)
+                self.RefreshProjectTree()
         else:
             self.Controler = controler
         
-        if self.ModeSolo and fileOpen:
-            self.Controler.OpenXMLFile(fileOpen)
-            self.RefreshProjectTree()
-        
         self.CurrentToolBar = []
         self.CurrentLanguage = ""
         self.DrawingMode = FREEDRAWING_MODE
@@ -499,6 +474,14 @@
             self.RefreshProjectTree()
         dialog.Destroy()
 
+    def OnFrameActivated(self, event):
+        if not self.ModeSolo and event.GetActive():
+            self.Controler.RefreshPluginsBlockLists()
+            selected = self.TabsOpened.GetSelection()
+            if selected >= 0:
+                self.TabsOpened.GetPage(selected).RefreshView()
+        event.Skip()
+
     def OnCloseFrame(self, event):
         if not self.ModeSolo and getattr(self, "_onclose", None) != None:
             self._onclose()
@@ -2806,13 +2789,36 @@
     sys.excepthook = handle_exception
 
 if __name__ == '__main__':
+    def usage():
+        print "\nUsage of PLCOpenEditor.py :"
+        print "\n   %s [Filepath]\n"%sys.argv[0]
+
+    try:
+        opts, args = getopt.getopt(sys.argv[1:], "h", ["help"])
+    except getopt.GetoptError:
+        # print help information and exit:
+        usage()
+        sys.exit(2)
+
+    for o, a in opts:
+        if o in ("-h", "--help"):
+            usage()
+            sys.exit()
+
+    fileOpen = None
+    if len(args) > 1:
+        usage()
+        sys.exit()
+    elif len(args) == 1:
+        fileOpen = args[0]
+    
     app = wx.PySimpleApp()
     wx.InitAllImageHandlers()
     
     # Install a exception handle for bug reports
     AddExceptHook(os.getcwd(),__version__)
     
-    frame = PLCOpenEditor(None)
+    frame = PLCOpenEditor(None, fileOpen=fileOpen)
 
     frame.Show()
     app.MainLoop()
--- a/plcopen/structures.py	Thu Sep 13 09:46:51 2007 +0200
+++ b/plcopen/structures.py	Mon Sep 17 10:13:56 2007 +0200
@@ -199,8 +199,12 @@
 Function that add a new plugin to the plugin list
 """
 
-def AddPlugin(blocklist):
-    PluginTypes.append(blocklist)
+def AddPluginBlockList(blocklist):
+    PluginTypes.extend(blocklist)
+    
+def ClearPluginTypes():
+    for i in xrange(len(PluginTypes)):
+        PluginTypes.pop(0)
 
 #-------------------------------------------------------------------------------
 #                           Data Types definitions
--- a/xmlclass/xmlclass.py	Thu Sep 13 09:46:51 2007 +0200
+++ b/xmlclass/xmlclass.py	Mon Sep 17 10:13:56 2007 +0200
@@ -29,13 +29,6 @@
 from new import classobj
 
 """
-Time and date definitions
-"""
-TimeType = time(0,0,0).__class__
-DateType = date(1,1,1).__class__
-DateTimeType = datetime(1,1,1,0,0,0).__class__
-
-"""
 Regular expression models for extracting dates and times from a string
 """
 time_model = re.compile('([0-9]{2}):([0-9]{2}):([0-9]{2}(?:.[0-9]*)?)')
@@ -376,9 +369,9 @@
                             time_values.extend([int(seconds), int((seconds % 1) * 1000000)])
                             return time(*time_values)
                         return time(0,0,0,0)
-                    return TimeType, GetTimeInitialValue
-                else:
-                    return TimeType, lambda:time(0,0,0,0)
+                    return time, GetTimeInitialValue
+                else:
+                    return time, lambda:time(0,0,0,0)
             elif type_compute == "date":
                 if default:
                     def GetDateInitialValue():
@@ -387,9 +380,9 @@
                             date_values = [int(v) for v in result.groups()]
                             return date(*date_values)
                         return date(1,1,1)
-                    return DateType, GetDateInitialValue
-                else:
-                    return DateType, lambda:date(1,1,1)
+                    return date, GetDateInitialValue
+                else:
+                    return date, lambda:date(1,1,1)
             elif type_compute == "dateTime":
                 if default:
                     def GetDateTimeInitialValue():
@@ -401,9 +394,9 @@
                             datetime_values.extend([int(seconds), int((seconds % 1) * 1000000)])
                             return datetime(*datetime_values)
                         return datetime(1,1,1,0,0,0,0)
-                    return DateTimeType, GetDateTimeInitialValue
-                else:
-                    return DateTimeType, lambda:datetime(1,1,1,0,0,0,0)
+                    return datetime, GetDateTimeInitialValue
+                else:
+                    return datetime, lambda:datetime(1,1,1,0,0,0,0)
             elif type_compute == "language":
                 if default:
                     def GetStringInitialValue():
@@ -505,7 +498,7 @@
                         value_type, initial = self.GetTypeInitialValue(members["basetype"])
                         if "min" in values:
                             initial = max(initial, values["min"])
-                        if "max" in values:
+                        elif "max" in values:
                             initial = min(initial, values["max"])
                         initialValues["value"] = GetInitialValueFunction(initial)
                         classmembers["value"] = initial