Bug on block properties dialog corrected
authorlbessard
Mon, 11 Jun 2007 14:56:25 +0200
changeset 16 20dcc0dce64b
parent 15 fc897b7bfa7b
child 17 faa048f4172e
Bug on block properties dialog corrected
FBDViewer.py
PLCOpenEditor.py
graphics/FBD_Objects.py
--- a/FBDViewer.py	Wed Jun 06 17:54:33 2007 +0200
+++ b/FBDViewer.py	Mon Jun 11 14:56:25 2007 +0200
@@ -400,6 +400,8 @@
  wxID_BLOCKPROPERTIESDIALOGSTATICTEXT4, 
 ] = [wx.NewId() for _init_ctrls in range(11)]
 
+[CATEGORY, BLOCK] = range(2)
+
 class BlockPropertiesDialog(wx.Dialog):
     def _init_coll_flexGridSizer1_Items(self, parent):
         # generated method, don't edit
@@ -511,10 +513,13 @@
 
     def SetBlockList(self, blocktypes):
         root = self.TypeTree.AddRoot("")
+        self.TypeTree.SetPyData(root, CATEGORY)
         for category in blocktypes:
             category_item = self.TypeTree.AppendItem(root, category["name"])
+            self.TypeTree.SetPyData(category_item, CATEGORY)
             for blocktype in category["list"]:
                 blocktype_item = self.TypeTree.AppendItem(category_item, blocktype["name"])
+                self.TypeTree.SetPyData(blocktype_item, BLOCK)
 
     def SetMinBlockSize(self, size):
         self.MinBlockSize = size
@@ -543,7 +548,7 @@
     def OnTypeTreeItemSelected(self, event):
         self.Name.SetValue("")
         selected = event.GetItem()
-        if self.TypeTree.GetItemParent(selected) != self.TypeTree.GetRootItem():
+        if self.TypeTree.GetPyData(selected) != CATEGORY:
             blocktype = GetBlockType(self.TypeTree.GetItemText(selected))
             if blocktype:
                 self.Inputs.SetValue(len(blocktype["inputs"]))
@@ -583,23 +588,28 @@
     def RefreshPreview(self):
         dc = wxClientDC(self.Preview)
         dc.Clear()
-        blocktype = self.TypeTree.GetItemText(self.TypeTree.GetSelection())
-        self.Block = FBD_Block(self.Preview, blocktype, self.Name.GetValue(), extension = self.Inputs.GetValue())
-        width, height = self.MinBlockSize
-        min_width, min_height = self.Block.GetMinSize()
-        width, height = max(min_width, width), max(min_height, height)
-        self.Block.SetSize(width, height)
-        clientsize = self.Preview.GetClientSize()
-        x = (clientsize.width - width) / 2
-        y = (clientsize.height - height) / 2
-        self.Block.SetPosition(x, y)
-        self.Block.Draw(dc)
+        item = self.TypeTree.GetSelection()
+        if self.TypeTree.GetPyData(item) == CATEGORY:
+            self.Block = None
+        else:
+            blocktype = self.TypeTree.GetItemText(item)
+            if blocktype:
+                self.Block = FBD_Block(self.Preview, blocktype, self.Name.GetValue(), extension = self.Inputs.GetValue())
+                width, height = self.MinBlockSize
+                min_width, min_height = self.Block.GetMinSize()
+                width, height = max(min_width, width), max(min_height, height)
+                self.Block.SetSize(width, height)
+                clientsize = self.Preview.GetClientSize()
+                x = (clientsize.width - width) / 2
+                y = (clientsize.height - height) / 2
+                self.Block.SetPosition(x, y)
+                self.Block.Draw(dc)
+            else:
+                self.Block = None
 
     def OnPaint(self, event):
         if self.Block:
             self.RefreshPreview()
-        else:
-            self.ErasePreview()
 
 
 #-------------------------------------------------------------------------------
--- a/PLCOpenEditor.py	Wed Jun 06 17:54:33 2007 +0200
+++ b/PLCOpenEditor.py	Mon Jun 11 14:56:25 2007 +0200
@@ -1437,9 +1437,9 @@
     def _init_ctrls(self, prnt):
         # generated method, don't edit
         wx.Dialog.__init__(self, id=wxID_POUDIALOG,
-              name='ProjectDialog', parent=prnt, pos=wx.Point(376, 223),
+              name='PouDialog', parent=prnt, pos=wx.Point(376, 223),
               size=wx.Size(300, 200), style=wx.DEFAULT_DIALOG_STYLE,
-              title='Create a new project')
+              title='Create a new POU')
         self.SetClientSize(wx.Size(300, 200))
 
         self.MainPanel = wx.Panel(id=wxID_POUDIALOGMAINPANEL,
--- a/graphics/FBD_Objects.py	Wed Jun 06 17:54:33 2007 +0200
+++ b/graphics/FBD_Objects.py	Mon Jun 11 14:56:25 2007 +0200
@@ -151,6 +151,8 @@
                     for i in xrange(self.Extension - len(blocktype["inputs"])):
                         start += 1
                         inputs.append(("IN%d"%start, inputs[-1][1], input[-1][2]))
+            else:
+                raise ValueError, "This block type isn't defined"
             self.Clean()
             # Extract the inputs properties and create the corresponding connector
             self.Inputs = []