]> git.phdru.name Git - m_librarian.git/blob - m_librarian/wx/ListBooks.py
3bcd331ab152c0d217657ad71490959e6ca3fbf6
[m_librarian.git] / m_librarian / wx / ListBooks.py
1 # coding: utf-8
2
3 import wx
4 from ..compat import string_type, unicode_type
5 from ..translations import translations
6 from .Grids import GridWindow, GridPanel
7
8
9 class ListBooksPanel(GridPanel):
10
11     def InitGrid(self):
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}
18         grid = self.grid
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)
31         row = 0
32         series = None
33         for book in books:
34             if book.series != series:
35                 if book.series:
36                     value = book.series
37                 else:
38                     value = u'Вне серий'
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))
42                 row += 1
43                 series = book.series
44             for col, col_name in enumerate(columns):
45                 value = getattr(book, col_name)
46                 if value is None:
47                     value = u''
48                 elif not isinstance(value, (string_type, unicode_type)):
49                     value = str(value)
50                 grid.SetCellValue(row, col, value)
51             row += 1
52         grid.AutoSizeColumns()
53         grid.AutoSizeRows()
54
55
56 class ListBooksWindow(GridWindow):
57
58     session_config_section_name = 'list_books'
59     window_title = u"m_Librarian: Список книг"
60     GridPanelClass = ListBooksPanel