4 from ..compat import string_type, unicode_type
5 from ..translations import translations
6 from .Grids import GridWindow, GridPanel
9 class ListBooksPanel(GridPanel):
12 _ = getattr(translations, 'ugettext', None) or translations.gettext
13 books_by_author = self.param['books_by_author']
14 columns = self.param['columns']
16 for author in books_by_author:
17 books = books_by_author[author]
18 series = {book.series for book in books}
19 total_rows += len(books) + len(series)
21 grid.CreateGrid(total_rows, len(columns))
22 grid.EnableEditing(False)
23 for row in range(total_rows):
24 grid.SetRowLabelValue(row, str(row))
25 grid.AutoSizeRowLabelSize(row)
26 for col, col_name in enumerate(columns):
27 grid.SetColLabelValue(col, _(col_name))
28 grid.AutoSizeColLabelSize(col)
29 if col_name in ('ser_no', 'size'):
30 cell_attr = wx.grid.GridCellAttr()
31 cell_attr.SetAlignment(wx.ALIGN_RIGHT, wx. ALIGN_CENTRE)
32 grid.SetColAttr(col, cell_attr)
34 for author in sorted(books_by_author):
35 books = books_by_author[author]
38 if book.series != series:
43 grid.SetCellAlignment(row, 0, wx.ALIGN_LEFT, wx. ALIGN_CENTRE)
44 grid.SetCellSize(row, 0, 1, len(columns))
45 grid.SetCellValue(row, 0, u'%s — %s' % (book.author1, value))
48 for col, col_name in enumerate(columns):
49 value = getattr(book, col_name)
52 elif not isinstance(value, (string_type, unicode_type)):
54 grid.SetCellValue(row, col, value)
56 grid.AutoSizeColumns()
59 def OnDClick(self, event):
62 def OnKeyDown(self, event):
63 if event.GetKeyCode() == wx.WXK_ESCAPE:
68 class ListBooksWindow(GridWindow):
70 session_config_section_name = 'list_books'
71 window_title = u"m_Librarian: Список книг"
72 GridPanelClass = ListBooksPanel