From: Oleg Broytman Date: Fri, 5 Jan 2024 21:11:54 +0000 (+0300) Subject: Feat(wx/search): List found authors X-Git-Tag: 0.3.0~9^2~16 X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;h=1c6f1fe4d51693117625a37cf6cf85932892e368;p=m_librarian.git Feat(wx/search): List found authors [skip ci] --- diff --git a/m_librarian/wx/AWindow.py b/m_librarian/wx/AWindow.py index 68f673b..8c46324 100644 --- a/m_librarian/wx/AWindow.py +++ b/m_librarian/wx/AWindow.py @@ -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 index 0000000..89c2945 --- /dev/null +++ b/m_librarian/wx/ListAuthors.py @@ -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() diff --git a/m_librarian/wx/SearchPanel.py b/m_librarian/wx/SearchPanel.py index 89b0698..8547c31 100644 --- a/m_librarian/wx/SearchPanel.py +++ b/m_librarian/wx/SearchPanel.py @@ -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)