X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=m_librarian%2Fwx%2FListBooks.py;h=fcf7eab52c9b7d3d112872a5dabab0f9a58105a0;hb=8de27024bcd0eb7d8dbede490368a68261204955;hp=fb15d1fe671844c57b8bb81d25c13da00ef4c75c;hpb=7b3352daa8d57878f0d727f1a4f4b1f2fc9609da;p=m_librarian.git diff --git a/m_librarian/wx/ListBooks.py b/m_librarian/wx/ListBooks.py index fb15d1f..fcf7eab 100644 --- a/m_librarian/wx/ListBooks.py +++ b/m_librarian/wx/ListBooks.py @@ -181,12 +181,25 @@ class ListBooksPanel(GridPanel): else: event.Skip() - def Download(self, event): + def Download(self, event=None): book_by_row = self.book_by_row - for row in self.toggle_rows[0]: - value = self.grid.GetCellValue(row, 0) - if value and row in book_by_row: - download(book_by_row[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 not found_books: + self.report_error(u'Не выбрано книг для сохранения.') + + 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): @@ -194,3 +207,15 @@ 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()