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']
15 author = next(iter(books_by_author))
16 books = books_by_author[author]
17 series = {book.series for book in books}
19 grid.CreateGrid(len(books) + len(series), len(columns))
20 grid.EnableEditing(False)
21 for row in range(len(books)):
22 grid.SetRowLabelValue(row, str(row))
23 grid.AutoSizeRowLabelSize(row)
24 for col, col_name in enumerate(columns):
25 grid.SetColLabelValue(col, _(col_name))
26 grid.AutoSizeColLabelSize(col)
27 if col_name in ('ser_no', 'size'):
28 cell_attr = wx.grid.GridCellAttr()
29 cell_attr.SetAlignment(wx.ALIGN_RIGHT, wx. ALIGN_CENTRE)
30 grid.SetColAttr(col, cell_attr)
34 if book.series != series:
39 grid.SetCellAlignment(row, 0, wx.ALIGN_LEFT, wx. ALIGN_CENTRE)
40 grid.SetCellSize(row, 0, 1, len(columns))
41 grid.SetCellValue(row, 0, u'%s — %s' % (book.author1, value))
44 for col, col_name in enumerate(columns):
45 value = getattr(book, col_name)
48 elif not isinstance(value, (string_type, unicode_type)):
50 grid.SetCellValue(row, col, value)
52 grid.AutoSizeColumns()
56 class ListBooksWindow(GridWindow):
58 session_config_section_name = 'list_books'
59 window_title = u"m_Librarian: Список книг"
60 GridPanelClass = ListBooksPanel