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]
44 grid.CreateGrid(len(books), len(columns))
45 grid.EnableEditing(False)
46 for row in range(len(books)):
47 grid.SetRowLabelValue(row, str(row))
48 grid.AutoSizeRowLabelSize(row)
49 for col, col_name in enumerate(columns):
50 grid.SetColLabelValue(col, _(col_name))
51 grid.AutoSizeColLabelSize(col)
52 if col_name in ('ser_no', 'size'):
53 cell_attr = wx.grid.GridCellAttr()
54 cell_attr.SetAlignment(wx.ALIGN_RIGHT, wx. ALIGN_CENTRE)
55 grid.SetColAttr(col, cell_attr)
56 for row, book in enumerate(books):
57 for col, col_name in enumerate(columns):
58 value = getattr(book, col_name)
61 elif not isinstance(value, (string_type, unicode_type)):
63 grid.SetCellValue(row, col, value)
64 grid.AutoSizeColumns()