]> git.phdru.name Git - m_librarian.git/blobdiff - m_librarian/wx/Grids.py
Feat(wx): Catch `Escape` in the grid and close the window
[m_librarian.git] / m_librarian / wx / Grids.py
index 415f68423c9c1b9024164656043cc2e6f2fbdf84..fe2f8d0174c68ef3dc4bbd734bd456879167eb6d 100644 (file)
@@ -14,11 +14,33 @@ class GridPanel(wx.Panel):
         self.grid = grid = wx.grid.Grid(self)
         vsizer.Add(grid, 0, wx.EXPAND, 0)
 
+        grid.Bind(wx.grid.EVT_GRID_CELL_LEFT_DCLICK, self.OnDClick)
+        grid.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
+
         self.InitGrid()
+        grid.SetFocus()
+
+        parent.Bind(wx.EVT_ACTIVATE, self.OnActivate)
+        parent.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus)
+        self.Bind(wx.EVT_ACTIVATE, self.OnActivate)
+        self.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus)
 
     def InitGrid(self):
         raise NotImplementedError
 
+    def OnDClick(self, event):
+        raise NotImplementedError
+
+    def OnKeyDown(self, event):
+        raise NotImplementedError
+
+    def OnActivate(self, event):
+        if event.GetActive():
+            self.grid.SetFocus()
+
+    def OnSetFocus(self, event):
+        self.grid.SetFocus()
+
 
 class GridWindow(AWindow):
 
@@ -33,4 +55,4 @@ class GridWindow(AWindow):
 
     def OnInit(self):
         AWindow.OnInit(self)
-        self.GridPanelClass(self, self.param)
+        self.panel = self.GridPanelClass(self, self.param)