]> git.phdru.name Git - m_librarian.git/commitdiff
Feat(wx/search): List found authors
authorOleg Broytman <phd@phdru.name>
Fri, 5 Jan 2024 21:11:54 +0000 (00:11 +0300)
committerOleg Broytman <phd@phdru.name>
Sat, 6 Jan 2024 15:33:34 +0000 (18:33 +0300)
[skip ci]

m_librarian/wx/AWindow.py
m_librarian/wx/ListAuthors.py [new file with mode: 0644]
m_librarian/wx/SearchPanel.py

index 68f673b5077dbc27eae24aecd7a821de6264830b..8c463247bec556c26adc642538ca0a3d0ed4a934 100644 (file)
@@ -36,9 +36,12 @@ class AWindow(wx.Frame):
         self.Show(True)
 
     def OnInit(self):
+        if self.Parent:
+            self.Parent.Disable()
         self.InitMenu()
         if self.session_config_section_name:
             self.Bind(wx.EVT_SIZE, self.OnSize)
+        self.Bind(wx.EVT_CLOSE, self.OnClose)
 
     def InitMenu(self):
         MenuBar = wx.MenuBar()
@@ -64,6 +67,11 @@ class AWindow(wx.Frame):
     def OnCloseCommand(self, event):
         self.Close(True)
 
+    def OnClose(self, event):
+        if self.Parent:
+            self.Parent.Enable()
+        event.Skip()  # Call other handlers
+
     def OnQuit(self, event):
         wx.GetApp().ExitMainLoop()
 
diff --git a/m_librarian/wx/ListAuthors.py b/m_librarian/wx/ListAuthors.py
new file mode 100644 (file)
index 0000000..89c2945
--- /dev/null
@@ -0,0 +1,58 @@
+# coding: utf-8
+
+import wx, wx.grid  # noqa: E401 multiple imports on one line
+from ..compat import string_type, unicode_type
+from ..translations import translations
+from .AWindow import AWindow
+
+
+class ListAuthorsWindow(AWindow):
+
+    session_config_section_name = 'list_authors'
+    window_title = u"m_Librarian: Список авторов"
+
+    def __init__(self, parent, search_authors_results):
+        self.search_authors_results = search_authors_results
+        AWindow.__init__(self, parent)
+
+    def OnInit(self):
+        AWindow.OnInit(self)
+        ListAuthorsPanel(self, self.search_authors_results)
+
+
+class ListAuthorsPanel(wx.Panel):
+
+    def __init__(self, parent, search_authors_results):
+        wx.Panel.__init__(self, parent)
+        list_authors_sizer = wx.BoxSizer(wx.VERTICAL)
+        self.SetSizer(list_authors_sizer)
+
+        grid = wx.grid.Grid(self)
+        list_authors_sizer.Add(grid, 0, wx.EXPAND, 0)
+
+        self.InitGrid(grid, search_authors_results)
+
+    def InitGrid(self, grid, search_authors_results):
+        _ = getattr(translations, 'ugettext', None) or translations.gettext
+        authors = search_authors_results['authors']
+        columns = search_authors_results['columns']
+        grid.CreateGrid(len(authors), len(columns))
+        grid.EnableEditing(False)
+        for row in range(len(authors)):
+            grid.SetRowLabelValue(row, str(row))
+            grid.AutoSizeRowLabelSize(row)
+        for col, col_name in enumerate(columns):
+            grid.SetColLabelValue(col, _(col_name))
+            grid.AutoSizeColLabelSize(col)
+            if col_name == 'count':
+                cell_attr = wx.grid.GridCellAttr()
+                cell_attr.SetAlignment(wx.ALIGN_RIGHT, wx. ALIGN_CENTRE)
+                grid.SetColAttr(col, cell_attr)
+        for row, author in enumerate(authors):
+            for col, col_name in enumerate(columns):
+                value = getattr(author, col_name)
+                if not isinstance(value, (string_type, unicode_type)):
+                    value = str(value)
+                grid.SetCellValue(row, col, value)
+        grid.AutoSizeColumns()
+        grid.AutoSizeRows()
index 89b0698c5761377390ac405c0776aa657f0a51ef..8547c313152fc07f8253e7b0305464ab508db747 100644 (file)
@@ -2,6 +2,8 @@
 
 import wx
 from ..search import search_authors_raw
+from .ListAuthors import ListAuthorsWindow
+
 
 _search_types = ['start', 'substring', 'full']
 
@@ -44,4 +46,6 @@ class SearchPanel(wx.Panel):
         search_case = self.search_case.GetValue()
         if search_case is False:
             search_case = None
-        search_authors_raw(search_authors, search_substr, search_case)
+        search_authors_results = \
+            search_authors_raw(search_authors, search_substr, search_case)
+        ListAuthorsWindow(self.Parent, search_authors_results)