4 from ..compat import string_type, unicode_type
5 from ..translations import translations
6 from .AWindow import AWindow
9 class ListBooksWindow(AWindow):
11 session_config_section_name = 'list_books'
12 window_title = u"m_Librarian: Список книг"
14 def __init__(self, parent, books_by_author):
15 self.books_by_author = books_by_author
16 AWindow.__init__(self, parent)
20 ListBooksPanel(self, self.books_by_author)
23 class ListBooksPanel(wx.Panel):
25 def __init__(self, parent, books_by_author):
26 wx.Panel.__init__(self, parent)
27 self.books_by_author = books_by_author
29 list_books_sizer = wx.BoxSizer(wx.VERTICAL)
30 self.SetSizer(list_books_sizer)
32 self.grid = grid = wx.grid.Grid(self)
33 list_books_sizer.Add(grid, 0, wx.EXPAND, 0)
38 _ = getattr(translations, 'ugettext', None) or translations.gettext
39 books_by_author = self.books_by_author['books_by_author']
40 columns = self.books_by_author['columns']
41 author = next(iter(books_by_author))
42 books = books_by_author[author]
43 series = {book.series for book in books}
45 grid.CreateGrid(len(books) + len(series), len(columns))
46 grid.EnableEditing(False)
47 for row in range(len(books)):
48 grid.SetRowLabelValue(row, str(row))
49 grid.AutoSizeRowLabelSize(row)
50 for col, col_name in enumerate(columns):
51 grid.SetColLabelValue(col, _(col_name))
52 grid.AutoSizeColLabelSize(col)
53 if col_name in ('ser_no', 'size'):
54 cell_attr = wx.grid.GridCellAttr()
55 cell_attr.SetAlignment(wx.ALIGN_RIGHT, wx. ALIGN_CENTRE)
56 grid.SetColAttr(col, cell_attr)
60 if book.series != series:
65 grid.SetCellAlignment(row, 0, wx.ALIGN_LEFT, wx. ALIGN_CENTRE)
66 grid.SetCellSize(row, 0, 1, len(columns))
67 grid.SetCellValue(row, 0, u'%s — %s' % (book.author1, value))
70 for col, col_name in enumerate(columns):
71 value = getattr(book, col_name)
74 elif not isinstance(value, (string_type, unicode_type)):
76 grid.SetCellValue(row, col, value)
78 grid.AutoSizeColumns()