objdictgen/subindextable.py
changeset 757 8150518de469
parent 748 18ed0f3b030a
child 761 efff55931763
equal deleted inserted replaced
756:4ac6fd44595b 757:8150518de469
   244         
   244         
   245         typelist = None
   245         typelist = None
   246         maplist = None
   246         maplist = None
   247         for row in range(self.GetNumberRows()):
   247         for row in range(self.GetNumberRows()):
   248             editors = self.editors[row]
   248             editors = self.editors[row]
   249             grid.SetRowMinimalHeight(row, 28)
   249             if wx.Platform == '__WXMSW__':
       
   250                 grid.SetRowMinimalHeight(row, 20)
       
   251             else:
       
   252                 grid.SetRowMinimalHeight(row, 28)
   250             grid.AutoSizeRow(row, False)
   253             grid.AutoSizeRow(row, False)
   251             for col in range(self.GetNumberCols()):
   254             for col in range(self.GetNumberCols()):
   252                 editor = None
   255                 editor = None
   253                 renderer = None
   256                 renderer = None
   254                 
   257                 
   255                 colname = self.GetColLabelValue(col, False)
   258                 colname = self.GetColLabelValue(col, False)
   256                 editortype = editors[colname]
   259                 editortype = editors[colname]
   257                 if editortype and self.Editable:
   260                 if editortype == "dcf":
       
   261                     editor = wx.grid.GridCellTextEditor()
       
   262                     renderer = wx.grid.GridCellStringRenderer()
       
   263                 elif editortype and self.Editable:
   258                     grid.SetReadOnly(row, col, False)
   264                     grid.SetReadOnly(row, col, False)
   259                     if editortype == "string":
   265                     if editortype == "string":
   260                         editor = wx.grid.GridCellTextEditor()
   266                         editor = wx.grid.GridCellTextEditor()
   261                         renderer = wx.grid.GridCellStringRenderer()
   267                         renderer = wx.grid.GridCellStringRenderer()
   262                         if colname == "value" and "length" in editors:
   268                         if colname == "value" and "length" in editors:
   295                         editor = wx.grid.GridCellTextEditor()
   301                         editor = wx.grid.GridCellTextEditor()
   296                         renderer = wx.grid.GridCellStringRenderer()
   302                         renderer = wx.grid.GridCellStringRenderer()
   297                     elif editortype == "domain":
   303                     elif editortype == "domain":
   298                         editor = wx.grid.GridCellTextEditor()
   304                         editor = wx.grid.GridCellTextEditor()
   299                         renderer = wx.grid.GridCellStringRenderer()
   305                         renderer = wx.grid.GridCellStringRenderer()
   300                     elif editortype == "dcf":
       
   301                         editor = wx.grid.GridCellTextEditor()
       
   302                         renderer = wx.grid.GridCellStringRenderer()
       
   303                 else:
   306                 else:
   304                     grid.SetReadOnly(row, col, True)
   307                     grid.SetReadOnly(row, col, True)
   305                     
   308                     
   306                 grid.SetCellEditor(row, col, editor)
   309                 grid.SetCellEditor(row, col, editor)
   307                 grid.SetCellRenderer(row, col, renderer)
   310                 grid.SetCellRenderer(row, col, renderer)
   426         wx.SplitterWindow.__init__(self, id=ID_EDITINGPANEL,
   429         wx.SplitterWindow.__init__(self, id=ID_EDITINGPANEL,
   427               name='MainSplitter', parent=prnt, point=wx.Point(0, 0),
   430               name='MainSplitter', parent=prnt, point=wx.Point(0, 0),
   428               size=wx.Size(-1, -1), style=wx.SP_3D)
   431               size=wx.Size(-1, -1), style=wx.SP_3D)
   429         self._init_utils()
   432         self._init_utils()
   430         self.SetNeedUpdating(True)
   433         self.SetNeedUpdating(True)
   431         self.SetMinimumPaneSize(1)
   434         
   432 
       
   433         self.PartList = wx.ListBox(choices=[], id=ID_EDITINGPANELPARTLIST,
   435         self.PartList = wx.ListBox(choices=[], id=ID_EDITINGPANELPARTLIST,
   434               name='PartList', parent=self, pos=wx.Point(0, 0),
   436               name='PartList', parent=self, pos=wx.Point(0, 0),
   435               size=wx.Size(-1, -1), style=0)
   437               size=wx.Size(-1, -1), style=0)
   436         self.PartList.Bind(wx.EVT_LISTBOX, self.OnPartListBoxClick,
   438         self.PartList.Bind(wx.EVT_LISTBOX, self.OnPartListBoxClick,
   437               id=ID_EDITINGPANELPARTLIST)
   439               id=ID_EDITINGPANELPARTLIST)
   438 
   440 
   439         self.SecondSplitter = wx.SplitterWindow(id=ID_EDITINGPANELSECONDSPLITTER,
   441         self.SecondSplitter = wx.SplitterWindow(id=ID_EDITINGPANELSECONDSPLITTER,
   440               name='SecondSplitter', parent=self, point=wx.Point(0, 0), 
   442               name='SecondSplitter', parent=self, point=wx.Point(0, 0), 
   441               size=wx.Size(-1, -1), style=wx.SP_3D)
   443               size=wx.Size(-1, -1), style=wx.SP_3D)
   442         self.SecondSplitter.SetMinimumPaneSize(1)
   444         self.SplitHorizontally(self.PartList, self.SecondSplitter, 110)
   443         self.SplitHorizontally(self.PartList, self.SecondSplitter,
   445         self.SetMinimumPaneSize(1)
   444               110)
   446         
   445 
       
   446         self.SubindexGridPanel = wx.Panel(id=ID_EDITINGPANELSUBINDEXGRIDPANEL,
   447         self.SubindexGridPanel = wx.Panel(id=ID_EDITINGPANELSUBINDEXGRIDPANEL,
   447               name='SubindexGridPanel', parent=self.SecondSplitter, 
   448               name='SubindexGridPanel', parent=self.SecondSplitter, 
   448               pos=wx.Point(0, 0), size=wx.Size(-1, -1), style=wx.TAB_TRAVERSAL)
   449               pos=wx.Point(0, 0), size=wx.Size(-1, -1), style=wx.TAB_TRAVERSAL)
   449 
   450 
   450         self.IndexListPanel = wx.Panel(id=ID_EDITINGPANELINDEXLISTPANEL,
   451         self.IndexListPanel = wx.Panel(id=ID_EDITINGPANELINDEXLISTPANEL,
   451               name='IndexListPanel', parent=self.SecondSplitter, 
   452               name='IndexListPanel', parent=self.SecondSplitter, 
   452               pos=wx.Point(0, 0), size=wx.Size(-1, -1), style=wx.TAB_TRAVERSAL)
   453               pos=wx.Point(0, 0), size=wx.Size(-1, -1), style=wx.TAB_TRAVERSAL)
   453         self.SecondSplitter.SplitVertically(self.IndexListPanel,
   454         self.SecondSplitter.SplitVertically(self.IndexListPanel, self.SubindexGridPanel, 280)
   454               self.SubindexGridPanel, 280)
   455         self.SecondSplitter.SetMinimumPaneSize(1)
   455 
   456         
   456         self.SubindexGrid = wx.grid.Grid(id=ID_EDITINGPANELSUBINDEXGRID,
   457         self.SubindexGrid = wx.grid.Grid(id=ID_EDITINGPANELSUBINDEXGRID,
   457               name='SubindexGrid', parent=self.SubindexGridPanel, pos=wx.Point(0,
   458               name='SubindexGrid', parent=self.SubindexGridPanel, pos=wx.Point(0,
   458               0), size=wx.Size(-1, -1), style=0)
   459               0), size=wx.Size(-1, -1), style=0)
   459         self.SubindexGrid.SetFont(wx.Font(12, 77, wx.NORMAL, wx.NORMAL, False,
   460         self.SubindexGrid.SetFont(wx.Font(12, 77, wx.NORMAL, wx.NORMAL, False,
   460               'Sans'))
   461               'Sans'))
   560                             dragSource = wx.DropSource(self.SubindexGrid)
   561                             dragSource = wx.DropSource(self.SubindexGrid)
   561                             dragSource.SetData(data)
   562                             dragSource.SetData(data)
   562                             dragSource.DoDragDrop()
   563                             dragSource.DoDragDrop()
   563             elif col == 0:
   564             elif col == 0:
   564                 selected = self.IndexList.GetSelection()
   565                 selected = self.IndexList.GetSelection()
   565                 if selected != wx.NOT_FOUND:
   566                 node_id = self.ParentWindow.GetCurrentNodeId()
       
   567                 if selected != wx.NOT_FOUND and node_id is not None:
   566                     index = self.ListIndex[selected]
   568                     index = self.ListIndex[selected]
   567                     subindex = event.GetRow()
   569                     subindex = event.GetRow()
   568                     entry_infos = self.Manager.GetEntryInfos(index)
   570                     entry_infos = self.Manager.GetEntryInfos(index)
   569                     if not entry_infos["struct"] & OD_MultipleSubindexes or subindex != 0:
   571                     if not entry_infos["struct"] & OD_MultipleSubindexes or subindex != 0:
   570                         subentry_infos = self.Manager.GetSubentryInfos(index, subindex)
   572                         subentry_infos = self.Manager.GetSubentryInfos(index, subindex)
   571                         typeinfos = self.Manager.GetEntryInfos(subentry_infos["type"])
   573                         typeinfos = self.Manager.GetEntryInfos(subentry_infos["type"])
   572                         if subentry_infos["pdo"] and typeinfos:
   574                         if subentry_infos["pdo"] and typeinfos:
   573                             bus_id = '.'.join(map(str, self.ParentWindow.GetBusId()))
   575                             bus_id = '.'.join(map(str, self.ParentWindow.GetBusId()))
   574                             node_id = self.ParentWindow.GetCurrentNodeId()
       
   575                             var_name = "%s_%04x_%02x" % (self.Manager.GetSlaveName(node_id), index, subindex)
   576                             var_name = "%s_%04x_%02x" % (self.Manager.GetSlaveName(node_id), index, subindex)
   576                             size = typeinfos["size"]
   577                             size = typeinfos["size"]
   577                             data = wx.TextDataObject(str(
   578                             data = wx.TextDataObject(str(
   578                                 ("%s%s.%d.%d.%d"%(SizeConversion[size], bus_id, node_id, index, subindex), 
   579                                 ("%s%s.%d.%d.%d"%(SizeConversion[size], bus_id, node_id, index, subindex), 
   579                                  "location", 
   580                                  "location", 
   700             event.Veto()
   701             event.Veto()
   701         else:
   702         else:
   702             event.Skip()
   703             event.Skip()
   703 
   704 
   704     def ShowDCFEntryDialog(self, row, col):
   705     def ShowDCFEntryDialog(self, row, col):
   705         if self.Editable:
   706         if self.Editable or self.ParentWindow.GetCurrentNodeId() is None:
   706             selected = self.IndexList.GetSelection()
   707             selected = self.IndexList.GetSelection()
   707             if selected != wx.NOT_FOUND:
   708             if selected != wx.NOT_FOUND:
   708                 index = self.ListIndex[selected]
   709                 index = self.ListIndex[selected]
   709                 if self.Manager.IsCurrentEntry(index):
   710                 if self.Manager.IsCurrentEntry(index):
   710                     dialog = DCFEntryValuesDialog(self)
   711                     dialog = DCFEntryValuesDialog(self, self.Editable)
   711                     dialog.SetValues(self.Table.GetValue(row, col).decode("hex_codec"))
   712                     dialog.SetValues(self.Table.GetValue(row, col).decode("hex_codec"))
   712                     if dialog.ShowModal() == wx.ID_OK:
   713                     if dialog.ShowModal() == wx.ID_OK and self.Editable:
   713                         value = dialog.GetValues()
   714                         value = dialog.GetValues()
   714                         self.Manager.SetCurrentEntry(index, row, value, "value", "dcf")
   715                         self.Manager.SetCurrentEntry(index, row, value, "value", "dcf")
   715                         self.ParentWindow.RefreshBufferState()
   716                         self.ParentWindow.RefreshBufferState()
   716                         wx.CallAfter(self.RefreshTable)
   717                         wx.CallAfter(self.RefreshTable)
   717 
   718 
   788                         self.SubindexGridMenu.FindItemByPosition(3).Enable(True)
   789                         self.SubindexGridMenu.FindItemByPosition(3).Enable(True)
   789                     else:
   790                     else:
   790                         self.SubindexGridMenu.FindItemByPosition(3).Enable(False)
   791                         self.SubindexGridMenu.FindItemByPosition(3).Enable(False)
   791                     if showpopup:
   792                     if showpopup:
   792                         self.PopupMenu(self.SubindexGridMenu)
   793                         self.PopupMenu(self.SubindexGridMenu)
   793         elif self.Table.GetColLabelValue(event.GetCol(), False) == "value":
   794         elif self.Table.GetColLabelValue(event.GetCol(), False) == "value" and self.ParentWindow.GetCurrentNodeId() is not None:
   794             selected = self.IndexList.GetSelection()
   795             selected = self.IndexList.GetSelection()
   795             if selected != wx.NOT_FOUND:
   796             if selected != wx.NOT_FOUND:
   796                 index = self.ListIndex[selected]
   797                 index = self.ListIndex[selected]
   797                 if self.Manager.IsCurrentEntry(index):
   798                 if self.Manager.IsCurrentEntry(index):
   798                     infos = self.Manager.GetEntryInfos(index)
   799                     infos = self.Manager.GetEntryInfos(index)
   930                 if self.Manager.IsCurrentEntry(index):
   931                 if self.Manager.IsCurrentEntry(index):
   931                     row = self.SubindexGrid.GetGridCursorRow()
   932                     row = self.SubindexGrid.GetGridCursorRow()
   932                     self.Manager.SetCurrentEntryToDefault(index, row)
   933                     self.Manager.SetCurrentEntryToDefault(index, row)
   933                     self.ParentWindow.RefreshBufferState()
   934                     self.ParentWindow.RefreshBufferState()
   934                     self.RefreshIndexList()
   935                     self.RefreshIndexList()
   935