]> git.phdru.name Git - m_librarian.git/commitdiff
Feat(wx/books): List books for an author
authorOleg Broytman <phd@phdru.name>
Sat, 6 Jan 2024 15:32:05 +0000 (18:32 +0300)
committerOleg Broytman <phd@phdru.name>
Sat, 6 Jan 2024 16:21:01 +0000 (19:21 +0300)
[skip ci]

m_librarian/wx/ListAuthors.py
m_librarian/wx/ListBooks.py

index 96f5e8ba56e942bf8977adc2c8beda5b5097a3f4..15cb59cf3c45c6054a7d9234745c6631b02bf557 100644 (file)
@@ -2,6 +2,7 @@
 
 import wx, wx.grid  # noqa: E401 multiple imports on one line
 from ..compat import string_type, unicode_type
+from ..search import books_by_author
 from ..translations import translations
 from .AWindow import AWindow
 from .ListBooks import ListBooksWindow
@@ -67,7 +68,8 @@ class ListAuthorsPanel(wx.Panel):
     def listBooks(self, row):
         authors = self.search_authors_results['authors']
         author = authors[row]
-        ListBooksWindow(self, author)
+        _books_by_author = books_by_author(author.id)
+        ListBooksWindow(self, _books_by_author)
 
     def OnDClick(self, event):
         row = event.GetRow()
index 97f88268d760a46c09b43e5eb7e4f466d2559554..c8b4923b785b47647133a1e6c40b322ca97a472c 100644 (file)
@@ -1,6 +1,8 @@
 # coding: utf-8
 
 import wx
+from ..compat import string_type, unicode_type
+from ..translations import translations
 from .AWindow import AWindow
 
 
@@ -9,6 +11,55 @@ class ListBooksWindow(AWindow):
     session_config_section_name = 'list_books'
     window_title = u"m_Librarian: Список книг"
 
-    def __init__(self, parent, author):
-        self.author = author
+    def __init__(self, parent, books_by_author):
+        self.books_by_author = books_by_author
         AWindow.__init__(self, parent)
+
+    def OnInit(self):
+        AWindow.OnInit(self)
+        ListBooksPanel(self, self.books_by_author)
+
+
+class ListBooksPanel(wx.Panel):
+
+    def __init__(self, parent, books_by_author):
+        wx.Panel.__init__(self, parent)
+        self.books_by_author = books_by_author
+
+        list_books_sizer = wx.BoxSizer(wx.VERTICAL)
+        self.SetSizer(list_books_sizer)
+
+        self.grid = grid = wx.grid.Grid(self)
+        list_books_sizer.Add(grid, 0, wx.EXPAND, 0)
+
+        self.InitGrid()
+
+    def InitGrid(self):
+        _ = getattr(translations, 'ugettext', None) or translations.gettext
+        books_by_author = self.books_by_author['books_by_author']
+        columns = self.books_by_author['columns']
+        author = next(iter(books_by_author))
+        books = books_by_author[author]
+        grid = self.grid
+        grid.CreateGrid(len(books), len(columns))
+        grid.EnableEditing(False)
+        for row in range(len(books)):
+            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 in ('ser_no', 'size'):
+                cell_attr = wx.grid.GridCellAttr()
+                cell_attr.SetAlignment(wx.ALIGN_RIGHT, wx. ALIGN_CENTRE)
+                grid.SetColAttr(col, cell_attr)
+        for row, book in enumerate(books):
+            for col, col_name in enumerate(columns):
+                value = getattr(book, col_name)
+                if value is None:
+                    value = u''
+                elif not isinstance(value, (string_type, unicode_type)):
+                    value = str(value)
+                grid.SetCellValue(row, col, value)
+        grid.AutoSizeColumns()
+        grid.AutoSizeRows()