Fix bug when using not editable EditingPanel for displaying nodelist generated master
authorLaurent Bessard
Thu, 04 Oct 2012 17:19:55 +0200
changeset 757 8150518de469
parent 756 4ac6fd44595b
child 758 9234361a4678
child 761 efff55931763
Fix bug when using not editable EditingPanel for displaying nodelist generated master
objdictgen/commondialogs.py
objdictgen/subindextable.py
--- a/objdictgen/commondialogs.py	Thu Oct 04 17:12:34 2012 +0200
+++ b/objdictgen/commondialogs.py	Thu Oct 04 17:19:55 2012 +0200
@@ -1238,7 +1238,7 @@
     def OnImportEDSButton(self, event):
         dialog = wx.FileDialog(self,
                                _("Choose an EDS file"),
-                               os.getcwd(),
+                               os.path.expanduser("~"),
                                "",
                                _("EDS files (*.eds)|*.eds|All files|*.*"),
                                wx.OPEN)
@@ -1386,7 +1386,8 @@
             for col in range(self.GetNumberCols()):
                 editor = wx.grid.GridCellTextEditor()
                 renderer = wx.grid.GridCellStringRenderer()
-                    
+                
+                grid.SetReadOnly(row, col, self.Parent.Editable)
                 grid.SetCellEditor(row, col, editor)
                 grid.SetCellRenderer(row, col, renderer)
                 
@@ -1495,11 +1496,12 @@
         
         self._init_sizers()
 
-    def __init__(self, parent):
+    def __init__(self, parent, editable=True):
         self._init_ctrls(parent)
         
         self.Values = []
         self.DefaultValue = {"Index" : 0, "Subindex" : 0, "Size" : 1, "Value" : 0}
+        self.Editable = editable
         
         self.Table = DCFEntryValuesTable(self, [], DCFEntryTableColnames())
         self.ValuesGrid.SetTable(self.Table)
@@ -1524,9 +1526,10 @@
     def RefreshButtons(self):
         row = self.ValuesGrid.GetGridCursorRow()
         length = len(self.Table.data)
-        self.DeleteButton.Enable(length > 0)
-        self.UpButton.Enable(row > 0)
-        self.DownButton.Enable(row < length - 1)
+        self.AddButton.Enable(self.Editable)
+        self.DeleteButton.Enable(self.Editable and length > 0)
+        self.UpButton.Enable(self.Editable and row > 0)
+        self.DownButton.Enable(self.Editable and row < length - 1)
     
     def OnAddButton(self, event):
         new_row = self.DefaultValue.copy()
--- a/objdictgen/subindextable.py	Thu Oct 04 17:12:34 2012 +0200
+++ b/objdictgen/subindextable.py	Thu Oct 04 17:19:55 2012 +0200
@@ -246,7 +246,10 @@
         maplist = None
         for row in range(self.GetNumberRows()):
             editors = self.editors[row]
-            grid.SetRowMinimalHeight(row, 28)
+            if wx.Platform == '__WXMSW__':
+                grid.SetRowMinimalHeight(row, 20)
+            else:
+                grid.SetRowMinimalHeight(row, 28)
             grid.AutoSizeRow(row, False)
             for col in range(self.GetNumberCols()):
                 editor = None
@@ -254,7 +257,10 @@
                 
                 colname = self.GetColLabelValue(col, False)
                 editortype = editors[colname]
-                if editortype and self.Editable:
+                if editortype == "dcf":
+                    editor = wx.grid.GridCellTextEditor()
+                    renderer = wx.grid.GridCellStringRenderer()
+                elif editortype and self.Editable:
                     grid.SetReadOnly(row, col, False)
                     if editortype == "string":
                         editor = wx.grid.GridCellTextEditor()
@@ -297,9 +303,6 @@
                     elif editortype == "domain":
                         editor = wx.grid.GridCellTextEditor()
                         renderer = wx.grid.GridCellStringRenderer()
-                    elif editortype == "dcf":
-                        editor = wx.grid.GridCellTextEditor()
-                        renderer = wx.grid.GridCellStringRenderer()
                 else:
                     grid.SetReadOnly(row, col, True)
                     
@@ -428,8 +431,7 @@
               size=wx.Size(-1, -1), style=wx.SP_3D)
         self._init_utils()
         self.SetNeedUpdating(True)
-        self.SetMinimumPaneSize(1)
-
+        
         self.PartList = wx.ListBox(choices=[], id=ID_EDITINGPANELPARTLIST,
               name='PartList', parent=self, pos=wx.Point(0, 0),
               size=wx.Size(-1, -1), style=0)
@@ -439,10 +441,9 @@
         self.SecondSplitter = wx.SplitterWindow(id=ID_EDITINGPANELSECONDSPLITTER,
               name='SecondSplitter', parent=self, point=wx.Point(0, 0), 
               size=wx.Size(-1, -1), style=wx.SP_3D)
-        self.SecondSplitter.SetMinimumPaneSize(1)
-        self.SplitHorizontally(self.PartList, self.SecondSplitter,
-              110)
-
+        self.SplitHorizontally(self.PartList, self.SecondSplitter, 110)
+        self.SetMinimumPaneSize(1)
+        
         self.SubindexGridPanel = wx.Panel(id=ID_EDITINGPANELSUBINDEXGRIDPANEL,
               name='SubindexGridPanel', parent=self.SecondSplitter, 
               pos=wx.Point(0, 0), size=wx.Size(-1, -1), style=wx.TAB_TRAVERSAL)
@@ -450,9 +451,9 @@
         self.IndexListPanel = wx.Panel(id=ID_EDITINGPANELINDEXLISTPANEL,
               name='IndexListPanel', parent=self.SecondSplitter, 
               pos=wx.Point(0, 0), size=wx.Size(-1, -1), style=wx.TAB_TRAVERSAL)
-        self.SecondSplitter.SplitVertically(self.IndexListPanel,
-              self.SubindexGridPanel, 280)
-
+        self.SecondSplitter.SplitVertically(self.IndexListPanel, self.SubindexGridPanel, 280)
+        self.SecondSplitter.SetMinimumPaneSize(1)
+        
         self.SubindexGrid = wx.grid.Grid(id=ID_EDITINGPANELSUBINDEXGRID,
               name='SubindexGrid', parent=self.SubindexGridPanel, pos=wx.Point(0,
               0), size=wx.Size(-1, -1), style=0)
@@ -562,7 +563,8 @@
                             dragSource.DoDragDrop()
             elif col == 0:
                 selected = self.IndexList.GetSelection()
-                if selected != wx.NOT_FOUND:
+                node_id = self.ParentWindow.GetCurrentNodeId()
+                if selected != wx.NOT_FOUND and node_id is not None:
                     index = self.ListIndex[selected]
                     subindex = event.GetRow()
                     entry_infos = self.Manager.GetEntryInfos(index)
@@ -571,7 +573,6 @@
                         typeinfos = self.Manager.GetEntryInfos(subentry_infos["type"])
                         if subentry_infos["pdo"] and typeinfos:
                             bus_id = '.'.join(map(str, self.ParentWindow.GetBusId()))
-                            node_id = self.ParentWindow.GetCurrentNodeId()
                             var_name = "%s_%04x_%02x" % (self.Manager.GetSlaveName(node_id), index, subindex)
                             size = typeinfos["size"]
                             data = wx.TextDataObject(str(
@@ -702,14 +703,14 @@
             event.Skip()
 
     def ShowDCFEntryDialog(self, row, col):
-        if self.Editable:
+        if self.Editable or self.ParentWindow.GetCurrentNodeId() is None:
             selected = self.IndexList.GetSelection()
             if selected != wx.NOT_FOUND:
                 index = self.ListIndex[selected]
                 if self.Manager.IsCurrentEntry(index):
-                    dialog = DCFEntryValuesDialog(self)
+                    dialog = DCFEntryValuesDialog(self, self.Editable)
                     dialog.SetValues(self.Table.GetValue(row, col).decode("hex_codec"))
-                    if dialog.ShowModal() == wx.ID_OK:
+                    if dialog.ShowModal() == wx.ID_OK and self.Editable:
                         value = dialog.GetValues()
                         self.Manager.SetCurrentEntry(index, row, value, "value", "dcf")
                         self.ParentWindow.RefreshBufferState()
@@ -790,7 +791,7 @@
                         self.SubindexGridMenu.FindItemByPosition(3).Enable(False)
                     if showpopup:
                         self.PopupMenu(self.SubindexGridMenu)
-        elif self.Table.GetColLabelValue(event.GetCol(), False) == "value":
+        elif self.Table.GetColLabelValue(event.GetCol(), False) == "value" and self.ParentWindow.GetCurrentNodeId() is not None:
             selected = self.IndexList.GetSelection()
             if selected != wx.NOT_FOUND:
                 index = self.ListIndex[selected]
@@ -932,4 +933,3 @@
                     self.Manager.SetCurrentEntryToDefault(index, row)
                     self.ParentWindow.RefreshBufferState()
                     self.RefreshIndexList()
-        
\ No newline at end of file