Added "Default value" to context menu on subindex grid in objdictedit.
authoretisserant
Mon, 02 Jul 2007 18:25:31 +0200
changeset 237 5dcfc996e563
parent 236 905677ed00f3
child 238 be485a93e3f7
Added "Default value" to context menu on subindex grid in objdictedit.
objdictgen/nodemanager.py
objdictgen/subindextable.py
--- a/objdictgen/nodemanager.py	Mon Jul 02 18:22:58 2007 +0200
+++ b/objdictgen/nodemanager.py	Mon Jul 02 18:25:31 2007 +0200
@@ -596,6 +596,15 @@
                 self.CurrentNode.SetParamsEntry(index, None, callback = value)
                 self.BufferCurrentNode()
 
+    def ResetCurrentDefaultValue(self, index, subIndex):
+        subentry_infos = self.GetSubentryInfos(index, subIndex)
+        if "default" in subentry_infos:
+            default = subentry_infos["default"]
+        else:
+            default = self.GetTypeDefaultValue(subentry_infos["type"])
+        self.CurrentNode.SetEntry(index, subIndex, default)
+        
+
     def SetCurrentEntry(self, index, subIndex, value, name, editor):
         if self.CurrentNode and self.CurrentNode.IsEntry(index):
             if name == "value":
--- a/objdictgen/subindextable.py	Mon Jul 02 18:22:58 2007 +0200
+++ b/objdictgen/subindextable.py	Mon Jul 02 18:25:31 2007 +0200
@@ -249,8 +249,8 @@
  wxID_EDITINGPANELINDEXLISTMENUITEMS2, 
 ] = [wx.NewId() for _init_coll_IndexListMenu_Items in range(3)]
 
-[wxID_EDITINGPANELMENU1ITEMS0, wxID_EDITINGPANELMENU1ITEMS1, 
-] = [wx.NewId() for _init_coll_SubindexGridMenu_Items in range(2)]
+[wxID_EDITINGPANELMENU1ITEMS0, wxID_EDITINGPANELMENU1ITEMS1, wxID_EDITINGPANELMENU1ITEMS2,
+] = [wx.NewId() for _init_coll_SubindexGridMenu_Items in range(3)]
 
 class EditingPanel(wx.SplitterWindow):
     def _init_coll_AddToListSizer_Items(self, parent):
@@ -295,10 +295,14 @@
               kind=wx.ITEM_NORMAL, text='Add')
         parent.Append(help='', id=wxID_EDITINGPANELMENU1ITEMS1,
               kind=wx.ITEM_NORMAL, text='Delete')
+        parent.Append(help='', id=wxID_EDITINGPANELMENU1ITEMS2,
+              kind=wx.ITEM_NORMAL, text='Default Value')
         self.Bind(wx.EVT_MENU, self.OnAddSubindexMenu,
               id=wxID_EDITINGPANELMENU1ITEMS0)
         self.Bind(wx.EVT_MENU, self.OnDeleteSubindexMenu,
               id=wxID_EDITINGPANELMENU1ITEMS1)
+        self.Bind(wx.EVT_MENU, self.OnDefaultValueSubindexMenu,
+              id=wxID_EDITINGPANELMENU1ITEMS2)
 
     def _init_coll_IndexListMenu_Items(self, parent):
         # generated method, don't edit
@@ -632,8 +636,16 @@
                 index = self.ListIndex[selected]
                 if self.Manager.IsCurrentEntry(index):
                     infos = self.Manager.GetEntryInfos(index)
-                    if index >= 0x2000 and infos["struct"] & OD_MultipleSubindexes or infos["struct"] & OD_IdenticalSubindexes:
-                        self.PopupMenu(self.SubindexGridMenu)
+                    if 0x5fff >= index >= 0x2000 and infos["struct"] & OD_MultipleSubindexes or infos["struct"] & OD_IdenticalSubindexes:
+                        # enable add and delet entries
+                        self.SubindexGridMenu.FindItemById(wxID_EDITINGPANELMENU1ITEMS0).Enable(True)
+                        self.SubindexGridMenu.FindItemById(wxID_EDITINGPANELMENU1ITEMS1).Enable(True)
+                    else:
+                        # disable add and delet entries
+                        self.SubindexGridMenu.FindItemById(wxID_EDITINGPANELMENU1ITEMS0).Enable(False)
+                        self.SubindexGridMenu.FindItemById(wxID_EDITINGPANELMENU1ITEMS1).Enable(False)
+                    self.SubindexGrid.SetGridCursor(event.GetRow(), event.GetCol())
+                    wxCallAfter(self.PopupMenu,self.SubindexGridMenu)
         event.Skip()
 
     def OnRenameIndexMenu(self, event):
@@ -725,3 +737,14 @@
                     dialog.Destroy()
         event.Skip()
 
+    def OnDefaultValueSubindexMenu(self, event):
+        if self.Editable:
+            selected = self.IndexList.GetSelection()
+            if selected != wxNOT_FOUND:
+                index = self.ListIndex[selected]
+                if self.Manager.IsCurrentEntry(index):
+                    self.Manager.ResetCurrentDefaultValue(index,self.SubindexGrid.GetGridCursorRow())
+                    self.Parent.RefreshBufferState()
+                    self.RefreshIndexList()
+        event.Skip()
+