]> git.phdru.name Git - m_librarian.git/commitdiff
Feat(wx): Catch `Escape` in the grid and close the window
authorOleg Broytman <phd@phdru.name>
Sun, 7 Jan 2024 21:34:17 +0000 (00:34 +0300)
committerOleg Broytman <phd@phdru.name>
Sun, 7 Jan 2024 21:45:42 +0000 (00:45 +0300)
[skip ci]

m_librarian/wx/Grids.py
m_librarian/wx/ListAuthors.py
m_librarian/wx/ListBooks.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)
index 3d73a2827c7d3949707afe07298b43ffe930b15e..8f18a7a6c29ec42aa1a96f103f363189e681fa07 100644 (file)
@@ -36,9 +36,6 @@ class ListAuthorsPanel(GridPanel):
         grid.AutoSizeColumns()
         grid.AutoSizeRows()
 
-        grid.Bind(wx.grid.EVT_GRID_CELL_LEFT_DCLICK, self.OnDClick)
-        grid.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
-
     def listBooks(self, row):
         authors = self.param['authors']
         author = authors[row]
@@ -50,7 +47,9 @@ class ListAuthorsPanel(GridPanel):
         self.listBooks(row)
 
     def OnKeyDown(self, event):
-        if event.GetKeyCode() in (wx.WXK_RETURN, wx.WXK_NUMPAD_ENTER):
+        if event.GetKeyCode() == wx.WXK_ESCAPE:
+            self.Parent.Close()
+        elif event.GetKeyCode() in (wx.WXK_RETURN, wx.WXK_NUMPAD_ENTER):
             row = self.grid.GetGridCursorRow()
             self.listBooks(row)
         else:
index 3bcd331ab152c0d217657ad71490959e6ca3fbf6..b1f84a11345449e50da3e4f06d0ea84ead2894e2 100644 (file)
@@ -52,6 +52,14 @@ class ListBooksPanel(GridPanel):
         grid.AutoSizeColumns()
         grid.AutoSizeRows()
 
+    def OnDClick(self, event):
+        pass
+
+    def OnKeyDown(self, event):
+        if event.GetKeyCode() == wx.WXK_ESCAPE:
+            self.Parent.Close()
+        else:
+            event.Skip()
 
 class ListBooksWindow(GridWindow):