X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=m_librarian%2Fwx%2FListBooks.py;h=0ef918e7f3b2610d10fe1ab8dcc4f2953613aabc;hb=bd8fec4b316b2bfedb36fa2d159c1fb1ca432376;hp=58f910d840afd359d5351cbc0dec9dc5e5dab600;hpb=5bfb6b6513c561dcdcd7372614d23d0aa21393e4;p=m_librarian.git diff --git a/m_librarian/wx/ListBooks.py b/m_librarian/wx/ListBooks.py index 58f910d..0ef918e 100644 --- a/m_librarian/wx/ListBooks.py +++ b/m_librarian/wx/ListBooks.py @@ -2,6 +2,7 @@ import wx, wx.grid # noqa: E401 multiple imports on one line from ..compat import string_type, unicode_type +from ..download import download from ..translations import translations from .Grids import GridWindow, GridPanel @@ -105,7 +106,9 @@ class ListBooksPanel(GridPanel): grid.SetCellAlignment(row, 1, wx.ALIGN_CENTRE, wx. ALIGN_CENTRE) grid.SetCellSize(row, 1, 1, len(columns)-1) row = 1 + self.book_by_row = book_by_row = {} # map {row: book} self.toggle_rows = toggle_rows = {} # map {row: [list of subrows]} + autowrap_renderer = wx.grid.GridCellAutoWrapStringRenderer() for author in sorted(books_by_author): grid.SetCellAlignment(row, 1, wx.ALIGN_LEFT, wx. ALIGN_CENTRE) grid.SetCellSize(row, 1, 1, len(columns)-1) @@ -132,12 +135,19 @@ class ListBooksPanel(GridPanel): row += 1 series = book.series for col, col_name in enumerate(columns[1:]): + if col_name in ( + 'author1', 'author_list', 'authors', + 'genre1name', 'genre1title', 'genre_name_list', + 'genres', 'title', + ): + grid.SetCellRenderer(row, col+1, autowrap_renderer) value = getattr(book, col_name) if value is None: value = u'' elif not isinstance(value, (string_type, unicode_type)): value = str(value) grid.SetCellValue(row, col+1, value) + book_by_row[row] = book toggle_rows[author_row].append(row) toggle_rows[series_row].append(row) row += 1 @@ -146,6 +156,10 @@ class ListBooksPanel(GridPanel): grid.AutoSizeRows() 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: @@ -174,9 +188,48 @@ class ListBooksPanel(GridPanel): 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()