PLCOpenEditor.py
changeset 253 d9391572655f
parent 249 d8425712acef
child 258 bded3a67ea4b
--- a/PLCOpenEditor.py	Sun Sep 07 15:27:53 2008 +0200
+++ b/PLCOpenEditor.py	Sun Sep 07 15:29:12 2008 +0200
@@ -390,13 +390,11 @@
         
         typestreestyle = wx.TR_HAS_BUTTONS|wx.TR_SINGLE|wx.SUNKEN_BORDER
         if not self.Debug:
-            typestreestyle |= wx.TR_HIDE_ROOT
+            typestreestyle |= wx.TR_EDIT_LABELS
         self.TypesTree = wx.TreeCtrl(id=ID_PLCOPENEDITORTYPESTREE,
                   name='TypesTree', parent=self.TreeNoteBook, 
                   pos=wx.Point(0, 0), size=wx.Size(0, 0),
                   style=typestreestyle)
-        self.TreeNoteBook.AddPage(self.TypesTree, "Types")
-        
         if not self.Debug:
             if wx.Platform == '__WXMSW__':
                 self.Bind(wx.EVT_TREE_ITEM_RIGHT_CLICK, self.OnTypesTreeRightUp,
@@ -425,14 +423,15 @@
                   name='InstancesTree', parent=self.TreeNoteBook, 
                   pos=wx.Point(0, 0), size=wx.Size(0, 0),
                   style=wx.TR_HAS_BUTTONS|wx.TR_SINGLE|wx.SUNKEN_BORDER)
-        self.TreeNoteBook.AddPage(self.InstancesTree, "Instances")
-        
         if self.Debug:
             self.Bind(wx.EVT_TREE_BEGIN_DRAG, self.OnInstancesTreeBeginDrag,
                   id=ID_PLCOPENEDITORINSTANCESTREE)
             self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.OnInstancesTreeItemActivated,
                   id=ID_PLCOPENEDITORINSTANCESTREE)
             
+            self.TreeNoteBook.AddPage(self.InstancesTree, "Instances")
+            self.TreeNoteBook.AddPage(self.TypesTree, "Types")
+            
             if wx.VERSION < (2, 8, 0):
                 self.TabsOpened = wx.Notebook(id=ID_PLCOPENEDITORTABSOPENED,
                       name='TabsOpened', parent=self.MainSplitter, pos=wx.Point(0,
@@ -451,6 +450,9 @@
                         self.OnPouSelectedChanged)
                 self.AUIManager.AddPane(self.TabsOpened, wx.aui.AuiPaneInfo().CentrePane())
         else:
+            self.TreeNoteBook.AddPage(self.TypesTree, "Types")
+            self.TreeNoteBook.AddPage(self.InstancesTree, "Instances")
+            
             if wx.VERSION < (2, 8, 0):
                 self.ToolBar = self.CreateToolBar(wx.TB_HORIZONTAL|wx.TB_FLAT|wx.NO_BORDER, 
                       ID_PLCOPENEDITORTOOLBAR, 'ToolBar')
@@ -651,10 +653,13 @@
         return self.DrawingMode
 
     def RefreshTitle(self):
+        name = "PLCOpenEditor"
+        if self.Debug:
+            name += " (Debug)"
         if self.Controler.HasOpenedProject() > 0:
-            self.SetTitle("PLCOpenEditor - %s"%self.Controler.GetFilename())
-        else:
-            self.SetTitle("PLCOpenEditor")
+            self.SetTitle("%s - %s"%(name, self.Controler.GetFilename()))
+        else:
+            self.SetTitle(name)
 
     def ShowProperties(self):
         old_values = self.Controler.GetProjectProperties(self.Debug)
@@ -3643,7 +3648,9 @@
                             editor = wx.grid.GridCellChoiceEditor()
                             excluded = []
                             if self.Parent.PouIsUsed:
-                                excluded.extend(["Input","Output","InOut"])    
+                                excluded.extend(["Input","Output","InOut"])
+                            if self.Parent.IsFunctionBlockType(self.data[row]["Type"]):
+                                excluded.extend(["Local","Temp"])
                             editor.SetParameters(",".join([choice for choice in self.Parent.ClassList if choice not in excluded]))
                     elif colname in ["Retain", "Constant"]:
                         editor = wx.grid.GridCellChoiceEditor()
@@ -3960,6 +3967,14 @@
     def SetTagName(self, tagname):
         self.TagName = tagname
     
+    def IsFunctionBlockType(self, name):
+        bodytype = self.Controler.GetEditedElementBodyType(self.TagName, self.ParentWindow.Debug)
+        pouname, poutype = self.Controler.GetEditedElementType(self.TagName, self.ParentWindow.Debug)
+        if poutype != "function" and bodytype in ["ST", "IL"]:
+            return False
+        else:
+            return name in self.Controler.GetFunctionBlockTypes(self.TagName, self.ParentWindow.Debug)
+    
     def RefreshView(self):
         self.PouNames = self.Controler.GetProjectPouNames(self.ParentWindow.Debug)
         
@@ -4099,6 +4114,7 @@
     
     def OnVariablesGridEditorShown(self, event):
         row, col = event.GetRow(), event.GetCol() 
+        classtype = self.Table.GetValueByName(row, "Class")
         if self.Table.GetColLabelValue(col) == "Type":
             type_menu = wx.Menu(title='')
             base_menu = wx.Menu(title='')
@@ -4108,17 +4124,20 @@
                 self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(base_type), id=new_id)
             type_menu.AppendMenu(wx.NewId(), "Base Types", base_menu)
             datatype_menu = wx.Menu(title='')
-            for datatype in self.Controler.GetDataTypes(basetypes = False, debug = self.Debug):
+            for datatype in self.Controler.GetDataTypes(basetypes = False, debug = self.ParentWindow.Debug):
                 new_id = wx.NewId()
                 AppendMenu(datatype_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=datatype)
                 self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(datatype), id=new_id)
             type_menu.AppendMenu(wx.NewId(), "User Data Types", datatype_menu)
             functionblock_menu = wx.Menu(title='')
-            for functionblock_type in self.Controler.GetFunctionBlockTypes(debug = self.Debug):
-                new_id = wx.NewId()
-                AppendMenu(functionblock_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=functionblock_type)
-                self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(functionblock_type), id=new_id)
-            type_menu.AppendMenu(wx.NewId(), "Function Block Types", functionblock_menu)
+            bodytype = self.Controler.GetEditedElementBodyType(self.TagName, self.ParentWindow.Debug)
+            pouname, poutype = self.Controler.GetEditedElementType(self.TagName, self.ParentWindow.Debug)
+            if classtype in ["Input","Output","InOut","External","Global"] or poutype != "function" and bodytype in ["ST", "IL"]:
+                for functionblock_type in self.Controler.GetFunctionBlockTypes(self.TagName, self.ParentWindow.Debug):
+                    new_id = wx.NewId()
+                    AppendMenu(functionblock_menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=functionblock_type)
+                    self.Bind(wx.EVT_MENU, self.GetVariableTypeFunction(functionblock_type), id=new_id)
+                type_menu.AppendMenu(wx.NewId(), "Function Block Types", functionblock_menu)
             rect = self.VariablesGrid.BlockToDeviceRect((row, col), (row, col))
             self.VariablesGrid.PopupMenuXY(type_menu, rect.x + rect.width, rect.y + self.VariablesGrid.GetColLabelSize())
             event.Veto()