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 from .ListBooks import ListBooksWindow
10 class ListAuthorsWindow(AWindow):
12 session_config_section_name = 'list_authors'
13 window_title = u"m_Librarian: Список авторов"
15 def __init__(self, parent, search_authors_results):
16 self.search_authors_results = search_authors_results
17 AWindow.__init__(self, parent)
21 ListAuthorsPanel(self, self.search_authors_results)
24 class ListAuthorsPanel(wx.Panel):
26 def __init__(self, parent, search_authors_results):
27 wx.Panel.__init__(self, parent)
28 self.search_authors_results = search_authors_results
30 list_authors_sizer = wx.BoxSizer(wx.VERTICAL)
31 self.SetSizer(list_authors_sizer)
33 self.grid = grid = wx.grid.Grid(self)
34 list_authors_sizer.Add(grid, 0, wx.EXPAND, 0)
39 _ = getattr(translations, 'ugettext', None) or translations.gettext
40 authors = self.search_authors_results['authors']
41 columns = self.search_authors_results['columns']
43 grid.CreateGrid(len(authors), len(columns))
44 grid.EnableEditing(False)
45 for row in range(len(authors)):
46 grid.SetRowLabelValue(row, str(row))
47 grid.AutoSizeRowLabelSize(row)
48 for col, col_name in enumerate(columns):
49 grid.SetColLabelValue(col, _(col_name))
50 grid.AutoSizeColLabelSize(col)
51 if col_name == 'count':
52 cell_attr = wx.grid.GridCellAttr()
53 cell_attr.SetAlignment(wx.ALIGN_RIGHT, wx. ALIGN_CENTRE)
54 grid.SetColAttr(col, cell_attr)
55 for row, author in enumerate(authors):
56 for col, col_name in enumerate(columns):
57 value = getattr(author, col_name)
58 if not isinstance(value, (string_type, unicode_type)):
60 grid.SetCellValue(row, col, value)
61 grid.AutoSizeColumns()
64 grid.Bind(wx.grid.EVT_GRID_CELL_LEFT_DCLICK, self.OnDClick)
65 grid.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
67 def listBooks(self, row):
68 authors = self.search_authors_results['authors']
70 ListBooksWindow(self, author)
72 def OnDClick(self, event):
76 def OnKeyDown(self, event):
77 if event.GetKeyCode() in (wx.WXK_RETURN, wx.WXK_NUMPAD_ENTER):
78 row = self.grid.GetGridCursorRow()