PLCOpenEditor.py
changeset 9 b29105e29081
parent 8 7ceec5c40d77
child 10 112985848e1d
--- a/PLCOpenEditor.py	Wed Apr 11 17:26:07 2007 +0200
+++ b/PLCOpenEditor.py	Thu Apr 12 17:26:07 2007 +0200
@@ -68,19 +68,6 @@
     fileOpen = args[0]
 CWD = sys.path[0]
 
-
-# Test if identifier is valid
-def TestIdentifier(identifier):
-     if identifier[0].isdigit():
-        return False
-     words = identifier.split('_')
-     for i, word in enumerate(words):
-         if len(word) == 0 and i != 0:
-             return False
-         if len(word) != 0 and not word.isalnum():
-             return False
-     return True
-
 [wxID_PLCOPENEDITOR, wxID_PLCOPENEDITORPROJECTTREE, 
  wxID_PLCOPENEDITORSPLITTERWINDOW1, wxID_PLCOPENEDITOREDITORPANEL,
  wxID_PLCOPENEDITORTABSOPENED, wxID_PLCOPENEDITORTOOLBAR,
@@ -393,6 +380,11 @@
     def __init__(self, parent):
         self._init_ctrls(parent)
         
+        self.TreeImageList = wxImageList(16, 16)
+        for language in LANGUAGES:
+            self.TreeImageList.Add(wxBitmap(os.path.join(CWD, 'Images/%s.png'%language)))
+        self.ProjectTree.SetImageList(self.TreeImageList)
+        
         self.Controler = PLCControler()
         
         if fileOpen:
@@ -406,46 +398,48 @@
         self.RefreshToolBar()
 
     def RefreshFileMenu(self):
-        if self.Controler.HasOpenedProject():
-            if self.TabsOpened.GetPageCount() > 0:
-                self.FileMenu.FindItemByPosition(2).Enable(True)
+        if self.FileMenu:
+            if self.Controler.HasOpenedProject():
+                if self.TabsOpened.GetPageCount() > 0:
+                    self.FileMenu.FindItemByPosition(2).Enable(True)
+                else:
+                    self.FileMenu.FindItemByPosition(2).Enable(False)
+                self.FileMenu.FindItemByPosition(3).Enable(True)
+                self.FileMenu.FindItemByPosition(5).Enable(True)
+                self.FileMenu.FindItemByPosition(6).Enable(True)
+                self.FileMenu.FindItemByPosition(7).Enable(True)
+                self.FileMenu.FindItemByPosition(9).Enable(True)
             else:
                 self.FileMenu.FindItemByPosition(2).Enable(False)
-            self.FileMenu.FindItemByPosition(3).Enable(True)
-            self.FileMenu.FindItemByPosition(5).Enable(True)
-            self.FileMenu.FindItemByPosition(6).Enable(True)
-            self.FileMenu.FindItemByPosition(7).Enable(True)
-            self.FileMenu.FindItemByPosition(9).Enable(True)
-        else:
-            self.FileMenu.FindItemByPosition(2).Enable(False)
-            self.FileMenu.FindItemByPosition(3).Enable(False)
-            self.FileMenu.FindItemByPosition(5).Enable(False)
-            self.FileMenu.FindItemByPosition(6).Enable(False)
-            self.FileMenu.FindItemByPosition(7).Enable(False)
-            self.FileMenu.FindItemByPosition(9).Enable(False)
+                self.FileMenu.FindItemByPosition(3).Enable(False)
+                self.FileMenu.FindItemByPosition(5).Enable(False)
+                self.FileMenu.FindItemByPosition(6).Enable(False)
+                self.FileMenu.FindItemByPosition(7).Enable(False)
+                self.FileMenu.FindItemByPosition(9).Enable(False)
 
     def RefreshEditMenu(self):
-        self.EditMenu.FindItemByPosition(1).Enable(False)
-        self.EditMenu.FindItemByPosition(2).Enable(False)
-        if self.Controler.HasOpenedProject():
-            if self.TabsOpened.GetPageCount() > 0:
-                self.EditMenu.FindItemByPosition(0).Enable(True)
+        if self.EditMenu:
+            self.EditMenu.FindItemByPosition(1).Enable(False)
+            self.EditMenu.FindItemByPosition(2).Enable(False)
+            if self.Controler.HasOpenedProject():
+                if self.TabsOpened.GetPageCount() > 0:
+                    self.EditMenu.FindItemByPosition(0).Enable(True)
+                else:
+                    self.EditMenu.FindItemByPosition(0).Enable(False)
+                self.EditMenu.FindItemByPosition(8).Enable(True)
+                self.EditMenu.FindItemByPosition(9).Enable(True)
             else:
                 self.EditMenu.FindItemByPosition(0).Enable(False)
-            self.EditMenu.FindItemByPosition(8).Enable(True)
-            self.EditMenu.FindItemByPosition(9).Enable(True)
-        else:
-            self.EditMenu.FindItemByPosition(0).Enable(False)
-            self.EditMenu.FindItemByPosition(8).Enable(False)
-            self.EditMenu.FindItemByPosition(9).Enable(False)
-        bodytype = self.Controler.GetCurrentElementEditingBodyType()
-        if bodytype in ["IL","ST"]:
-            self.EditMenu.FindItemByPosition(4).Enable(True)
-            self.EditMenu.FindItemByPosition(5).Enable(True)
-            self.EditMenu.FindItemByPosition(6).Enable(True)
-        else:
-            self.EditMenu.FindItemByPosition(4).Enable(False)
-            self.EditMenu.FindItemByPosition(5).Enable(False)
+                self.EditMenu.FindItemByPosition(8).Enable(False)
+                self.EditMenu.FindItemByPosition(9).Enable(False)
+            bodytype = self.Controler.GetCurrentElementEditingBodyType()
+            if bodytype in ["IL","ST"]:
+                self.EditMenu.FindItemByPosition(4).Enable(True)
+                self.EditMenu.FindItemByPosition(5).Enable(True)
+                self.EditMenu.FindItemByPosition(6).Enable(True)
+            else:
+                self.EditMenu.FindItemByPosition(4).Enable(False)
+                self.EditMenu.FindItemByPosition(5).Enable(False)
             self.EditMenu.FindItemByPosition(6).Enable(False)
 
     def OnNewProjectMenu(self, event):
@@ -1005,6 +999,8 @@
         else:
             root = self.ProjectTree.AddRoot(infos["name"])
         self.ProjectTree.SetPyData(root, infos["type"])
+        if infos["type"] == ITEM_POU:
+            self.ProjectTree.SetItemImage(root, LANGUAGES.index(self.Controler.GetPouBodyType(infos["name"])))
         item, root_cookie = self.ProjectTree.GetFirstChild(root)
         if len(infos["values"]) > 0:
             for values in infos["values"]:
@@ -1348,7 +1344,7 @@
 
     def __init__(self, parent):
         self._init_ctrls(parent)
-        self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL)
+        self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL|wxCENTRE)
         self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT)
         
         EVT_BUTTON(self, self.ButtonSizer.GetAffirmativeButton().GetId(), self.OnOK)
@@ -1474,7 +1470,7 @@
 
     def __init__(self, parent):
         self._init_ctrls(parent)
-        self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL)
+        self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL|wxCENTRE)
         self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT)
         
         for option in ["function","functionBlock","program"]:
@@ -1619,7 +1615,7 @@
 
     def __init__(self, parent):
         self._init_ctrls(parent)
-        self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL)
+        self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL|wxCENTRE)
         self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT)
 
         for option in ["IL","ST","LD","FBD"]:
@@ -1735,7 +1731,7 @@
 
     def __init__(self, parent):
         self._init_ctrls(parent)
-        self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL)
+        self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL|wxCENTRE)
         self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT)
 
         for option in ["IL","ST","LD","FBD"]:
@@ -2028,7 +2024,7 @@
 
     def __init__(self, parent, name, pou_type, filter = "All"):
         self._init_ctrls(parent, name)
-        self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL)
+        self.ButtonSizer = self.CreateButtonSizer(wxOK|wxCANCEL|wxCENTRE)
         self.flexGridSizer1.Add(self.ButtonSizer, 1, wxALIGN_RIGHT)
         self.Filter = filter
         self.FilterChoices = []