3 import wx, wx.grid # noqa: E401 multiple imports on one line
4 from ..compat import string_type, unicode_type
5 from ..search import books_by_author
6 from ..translations import translations
7 from .Grids import GridWindow, GridPanel
8 from .ListBooks import ListBooksWindow
11 class ListAuthorsPanel(GridPanel):
14 _ = getattr(translations, 'ugettext', None) or translations.gettext
15 authors = self.param['authors']
16 columns = self.param['columns']
18 grid.CreateGrid(len(authors), len(columns))
19 grid.EnableEditing(False)
20 for row in range(len(authors)):
21 grid.SetRowLabelValue(row, str(row))
22 grid.AutoSizeRowLabelSize(row)
23 for col, col_name in enumerate(columns):
24 grid.SetColLabelValue(col, _(col_name))
25 grid.AutoSizeColLabelSize(col)
26 if col_name == 'count':
27 cell_attr = wx.grid.GridCellAttr()
28 cell_attr.SetAlignment(wx.ALIGN_RIGHT, wx. ALIGN_CENTRE)
29 grid.SetColAttr(col, cell_attr)
30 for row, author in enumerate(authors):
31 for col, col_name in enumerate(columns):
32 value = getattr(author, col_name)
33 if not isinstance(value, (string_type, unicode_type)):
35 grid.SetCellValue(row, col, value)
36 grid.AutoSizeColumns()
39 def listBooks(self, row):
40 authors = self.param['authors']
42 _books_by_author = books_by_author(author.id)
43 ListBooksWindow(self, _books_by_author)
45 def OnDClick(self, event):
49 def OnKeyDown(self, event):
50 if event.GetKeyCode() == wx.WXK_ESCAPE:
52 elif event.GetKeyCode() in (wx.WXK_RETURN, wx.WXK_NUMPAD_ENTER):
53 row = self.grid.GetGridCursorRow()
59 class ListAuthorsWindow(GridWindow):
61 session_config_section_name = 'list_authors'
62 window_title = u"m_Librarian: Список авторов"
63 GridPanelClass = ListAuthorsPanel