+ grid.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, self.OnClick)
+
+ search_button = wx.Button(self, label=u'Скачать')
+ self.GetSizer().Add(search_button, 0, wx.ALIGN_CENTER, 0)
+ search_button.Bind(wx.EVT_BUTTON, self.Download)
+
+ def toggleCB(self, row):
+ value = self.grid.GetCellValue(row, 0)
+ if value:
+ value = ''
+ else:
+ value = '1'
+ self.grid.SetCellValue(row, 0, value)
+ toggle_rows = self.toggle_rows
+ if row in toggle_rows:
+ for row_ in toggle_rows[row]:
+ self.grid.SetCellValue(row_, 0, value)
+
+ def OnClick(self, event):
+ if event.GetCol() > 0:
+ return
+ self.toggleCB(event.GetRow())
+
+ def OnDClick(self, event):
+ if event.GetCol() == 0:
+ return
+ self.toggleCB(event.GetRow())
+
+ def OnKeyDown(self, event):
+ if event.GetKeyCode() == wx.WXK_ESCAPE:
+ self.Parent.Close()
+ else:
+ event.Skip()
+
+ def Download(self, event=None):
+ book_by_row = self.book_by_row
+ found_books = False
+ try:
+ for row in self.toggle_rows[0]:
+ value = self.grid.GetCellValue(row, 0)
+ if value and row in book_by_row:
+ found_books = True
+ download(book_by_row[row])
+ except Exception as e:
+ self.report_error(str(e))
+ else:
+ if found_books:
+ self.report_success(u'Книги сохранены.')
+ else:
+ self.report_error(u'Не выбрано книг для сохранения.')
+
+ def report_success(self, message):
+ wx.MessageBox(
+ message, caption='m_Librarian download finished',
+ style=wx.OK, parent=self.Parent)
+
+ def report_error(self, error):
+ wx.MessageBox(
+ error, caption='m_Librarian download error',
+ style=wx.OK | wx.ICON_ERROR, parent=self.Parent)
+
+
+class ListBooksWindow(GridWindow):
+
+ session_config_section_name = 'list_books'
+ window_title = u"m_Librarian: Список книг"
+ GridPanelClass = ListBooksPanel
+
+ def InitMenu(self):
+ GridWindow.InitMenu(self)
+
+ download_menu = wx.Menu()
+ download = download_menu.Append(wx.ID_SAVE,
+ u"&Скачать", u"Скачать")
+ self.Bind(wx.EVT_MENU, self.OnDownload, download)
+ self.GetMenuBar().Append(download_menu, u"&Скачать")
+
+ def OnDownload(self, event):
+ self.panel.Download()