X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;ds=sidebyside;f=m_librarian%2Fwx%2FListAuthors.py;h=8f18a7a6c29ec42aa1a96f103f363189e681fa07;hb=9f269c21f91b1865ffe2c8bfdab4974d26c97295;hp=cdbf134fc17ecf06e3c47de5b9af75f08811298d;hpb=73d5cd7b4ae212cb3f913bac350d2cb7e9a45889;p=m_librarian.git diff --git a/m_librarian/wx/ListAuthors.py b/m_librarian/wx/ListAuthors.py index cdbf134..8f18a7a 100644 --- a/m_librarian/wx/ListAuthors.py +++ b/m_librarian/wx/ListAuthors.py @@ -2,42 +2,18 @@ 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 .Grids import GridWindow, GridPanel +from .ListBooks import ListBooksWindow -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) - self.search_authors_results = search_authors_results - - list_authors_sizer = wx.BoxSizer(wx.VERTICAL) - self.SetSizer(list_authors_sizer) - - self.grid = grid = wx.grid.Grid(self) - list_authors_sizer.Add(grid, 0, wx.EXPAND, 0) - - self.InitGrid() +class ListAuthorsPanel(GridPanel): def InitGrid(self): _ = getattr(translations, 'ugettext', None) or translations.gettext - authors = self.search_authors_results['authors'] - columns = self.search_authors_results['columns'] + authors = self.param['authors'] + columns = self.param['columns'] grid = self.grid grid.CreateGrid(len(authors), len(columns)) grid.EnableEditing(False) @@ -59,3 +35,29 @@ class ListAuthorsPanel(wx.Panel): grid.SetCellValue(row, col, value) grid.AutoSizeColumns() grid.AutoSizeRows() + + def listBooks(self, row): + authors = self.param['authors'] + author = authors[row] + _books_by_author = books_by_author(author.id) + ListBooksWindow(self, _books_by_author) + + def OnDClick(self, event): + row = event.GetRow() + self.listBooks(row) + + def OnKeyDown(self, event): + 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: + event.Skip() + + +class ListAuthorsWindow(GridWindow): + + session_config_section_name = 'list_authors' + window_title = u"m_Librarian: Список авторов" + GridPanelClass = ListAuthorsPanel