]> git.phdru.name Git - m_librarian.git/blob - m_librarian/wx/ListAuthors.py
89c294529da74668e26af471e272c5f96f9a962f
[m_librarian.git] / m_librarian / wx / ListAuthors.py
1 # coding: utf-8
2
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
7
8
9 class ListAuthorsWindow(AWindow):
10
11     session_config_section_name = 'list_authors'
12     window_title = u"m_Librarian: Список авторов"
13
14     def __init__(self, parent, search_authors_results):
15         self.search_authors_results = search_authors_results
16         AWindow.__init__(self, parent)
17
18     def OnInit(self):
19         AWindow.OnInit(self)
20         ListAuthorsPanel(self, self.search_authors_results)
21
22
23 class ListAuthorsPanel(wx.Panel):
24
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)
29
30         grid = wx.grid.Grid(self)
31         list_authors_sizer.Add(grid, 0, wx.EXPAND, 0)
32
33         self.InitGrid(grid, search_authors_results)
34
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)):
55                     value = str(value)
56                 grid.SetCellValue(row, col, value)
57         grid.AutoSizeColumns()
58         grid.AutoSizeRows()