3 import wx, wx.grid # noqa: E401 multiple imports on one line
4 from ..compat import string_type, unicode_type
5 from ..translations import translations
6 from .AWindow import AWindow
9 class ListAuthorsWindow(AWindow):
11 session_config_section_name = 'list_authors'
12 window_title = u"m_Librarian: Список авторов"
14 def __init__(self, parent, search_authors_results):
15 self.search_authors_results = search_authors_results
16 AWindow.__init__(self, parent)
20 ListAuthorsPanel(self, self.search_authors_results)
23 class ListAuthorsPanel(wx.Panel):
25 def __init__(self, parent, search_authors_results):
26 wx.Panel.__init__(self, parent)
27 list_authors_sizer = wx.BoxSizer(wx.VERTICAL)
28 self.SetSizer(list_authors_sizer)
30 grid = wx.grid.Grid(self)
31 list_authors_sizer.Add(grid, 0, wx.EXPAND, 0)
33 self.InitGrid(grid, search_authors_results)
35 def InitGrid(self, grid, search_authors_results):
36 _ = getattr(translations, 'ugettext', None) or translations.gettext
37 authors = search_authors_results['authors']
38 columns = search_authors_results['columns']
39 grid.CreateGrid(len(authors), len(columns))
40 grid.EnableEditing(False)
41 for row in range(len(authors)):
42 grid.SetRowLabelValue(row, str(row))
43 grid.AutoSizeRowLabelSize(row)
44 for col, col_name in enumerate(columns):
45 grid.SetColLabelValue(col, _(col_name))
46 grid.AutoSizeColLabelSize(col)
47 if col_name == 'count':
48 cell_attr = wx.grid.GridCellAttr()
49 cell_attr.SetAlignment(wx.ALIGN_RIGHT, wx. ALIGN_CENTRE)
50 grid.SetColAttr(col, cell_attr)
51 for row, author in enumerate(authors):
52 for col, col_name in enumerate(columns):
53 value = getattr(author, col_name)
54 if not isinstance(value, (string_type, unicode_type)):
56 grid.SetCellValue(row, col, value)
57 grid.AutoSizeColumns()