]> git.phdru.name Git - m_librarian.git/blob - m_librarian/wx/ListAuthors.py
cdbf134fc17ecf06e3c47de5b9af75f08811298d
[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         self.search_authors_results = search_authors_results
28
29         list_authors_sizer = wx.BoxSizer(wx.VERTICAL)
30         self.SetSizer(list_authors_sizer)
31
32         self.grid = grid = wx.grid.Grid(self)
33         list_authors_sizer.Add(grid, 0, wx.EXPAND, 0)
34
35         self.InitGrid()
36
37     def InitGrid(self):
38         _ = getattr(translations, 'ugettext', None) or translations.gettext
39         authors = self.search_authors_results['authors']
40         columns = self.search_authors_results['columns']
41         grid = self.grid
42         grid.CreateGrid(len(authors), len(columns))
43         grid.EnableEditing(False)
44         for row in range(len(authors)):
45             grid.SetRowLabelValue(row, str(row))
46             grid.AutoSizeRowLabelSize(row)
47         for col, col_name in enumerate(columns):
48             grid.SetColLabelValue(col, _(col_name))
49             grid.AutoSizeColLabelSize(col)
50             if col_name == 'count':
51                 cell_attr = wx.grid.GridCellAttr()
52                 cell_attr.SetAlignment(wx.ALIGN_RIGHT, wx. ALIGN_CENTRE)
53                 grid.SetColAttr(col, cell_attr)
54         for row, author in enumerate(authors):
55             for col, col_name in enumerate(columns):
56                 value = getattr(author, col_name)
57                 if not isinstance(value, (string_type, unicode_type)):
58                     value = str(value)
59                 grid.SetCellValue(row, col, value)
60         grid.AutoSizeColumns()
61         grid.AutoSizeRows()