From 7b3352daa8d57878f0d727f1a4f4b1f2fc9609da Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Wed, 10 Jan 2024 03:42:04 +0300 Subject: [PATCH] Feat(wx/books): Download books [skip ci] --- m_librarian/wx/ListBooks.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/m_librarian/wx/ListBooks.py b/m_librarian/wx/ListBooks.py index 58f910d..fb15d1f 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,6 +106,7 @@ 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]} for author in sorted(books_by_author): grid.SetCellAlignment(row, 1, wx.ALIGN_LEFT, wx. ALIGN_CENTRE) @@ -138,6 +140,7 @@ class ListBooksPanel(GridPanel): 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 +149,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,6 +181,13 @@ class ListBooksPanel(GridPanel): else: event.Skip() + def Download(self, event): + 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]) + class ListBooksWindow(GridWindow): -- 2.39.2