From 3a3a05be790e9975d5ac518017f15e7b84921bd5 Mon Sep 17 00:00:00 2001 From: John Schember Date: Sun, 1 Feb 2009 21:17:40 -0500 Subject: [PATCH 1/3] Add printing support to the ebook viewer --- .../gui2/images/document-print-preview.svg | 14298 ++++++++++++++++ src/calibre/gui2/images/document-print.svg | 14229 +++++++++++++++ src/calibre/gui2/viewer/documentview.py | 26 +- src/calibre/gui2/viewer/main.py | 2 + src/calibre/gui2/viewer/main.ui | 25 +- 5 files changed, 28576 insertions(+), 4 deletions(-) create mode 100644 src/calibre/gui2/images/document-print-preview.svg create mode 100644 src/calibre/gui2/images/document-print.svg diff --git a/src/calibre/gui2/images/document-print-preview.svg b/src/calibre/gui2/images/document-print-preview.svg new file mode 100644 index 0000000000..6ffe4fafa8 --- /dev/null +++ b/src/calibre/gui2/images/document-print-preview.svg @@ -0,0 +1,14298 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/calibre/gui2/images/document-print.svg b/src/calibre/gui2/images/document-print.svg new file mode 100644 index 0000000000..dffa8b94ba --- /dev/null +++ b/src/calibre/gui2/images/document-print.svg @@ -0,0 +1,14229 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/calibre/gui2/viewer/documentview.py b/src/calibre/gui2/viewer/documentview.py index 6c1eca0061..6ce7a39e9d 100644 --- a/src/calibre/gui2/viewer/documentview.py +++ b/src/calibre/gui2/viewer/documentview.py @@ -8,7 +8,8 @@ __docformat__ = 'restructuredtext en' import os, math, re from PyQt4.Qt import QWidget, QSize, QSizePolicy, QUrl, SIGNAL, Qt, QTimer, \ QPainter, QPalette, QBrush, QFontDatabase, QDialog, \ - QByteArray, QColor, QWheelEvent, QPoint, QImage, QRegion, QFont + QByteArray, QColor, QWheelEvent, QPoint, QImage, QRegion, \ + QFont, QPrinter, QPrintPreviewDialog, QPrintDialog from PyQt4.QtWebKit import QWebPage, QWebView, QWebSettings from calibre.utils.config import Config, StringConfig @@ -305,6 +306,27 @@ class DocumentView(QWebView): def goto_bookmark(self, bm): self.document.goto_bookmark(bm) + + def print_preview(self): + printer = QPrinter(QPrinter.HighResolution) + printer.setPageMargins(1, 1, 1, 1, QPrinter.Inch) + + previewDialog = QPrintPreviewDialog(printer, self) + + self.connect(previewDialog, SIGNAL('paintRequested(QPrinter *)'), self.print_) + previewDialog.exec_() + self.disconnect(previewDialog, SIGNAL('paintRequested(QPrinter *)'), self.print_) + + def print_book(self): + printer = QPrinter(QPrinter.HighResolution) + printer.setPageMargins(1, 1, 1, 1, QPrinter.Inch) + + printDialog = QPrintDialog(printer, self) + printDialog.setWindowTitle(_("Print eBook")) + + printDialog.exec_() + if printDialog.result() == QDialog.Accepted: + self.print_(printer) def config(self, parent=None): self.document.do_config(parent) @@ -552,4 +574,4 @@ class DocumentView(QWebView): self.manager.scrolled(self.scroll_fraction) return ret - \ No newline at end of file + diff --git a/src/calibre/gui2/viewer/main.py b/src/calibre/gui2/viewer/main.py index fedebc66d7..3b9c0fca1e 100644 --- a/src/calibre/gui2/viewer/main.py +++ b/src/calibre/gui2/viewer/main.py @@ -248,6 +248,8 @@ class EbookViewer(MainWindow, Ui_EbookViewer): self.connect(self.action_back, SIGNAL('triggered(bool)'), self.back) self.connect(self.action_bookmark, SIGNAL('triggered(bool)'), self.bookmark) self.connect(self.action_forward, SIGNAL('triggered(bool)'), self.forward) + self.connect(self.action_print_preview, SIGNAL('triggered()'), self.view.print_preview) + self.connect(self.action_print, SIGNAL('triggered()'), self.view.print_book) self.connect(self.action_preferences, SIGNAL('triggered(bool)'), lambda x: self.view.config(self)) self.connect(self.pos, SIGNAL('valueChanged(double)'), self.goto_page) self.connect(self.vertical_scrollbar, SIGNAL('valueChanged(int)'), diff --git a/src/calibre/gui2/viewer/main.ui b/src/calibre/gui2/viewer/main.ui index 59f813b2bd..122993d528 100644 --- a/src/calibre/gui2/viewer/main.ui +++ b/src/calibre/gui2/viewer/main.ui @@ -27,8 +27,8 @@ - - + + about:blank @@ -87,6 +87,9 @@ + + + @@ -234,6 +237,24 @@ Toggle full screen + + + + :/images/document-print.svg:/images/document-print.svg + + + Print + + + + + + :/images/document-print-preview.svg:/images/document-print-preview.svg + + + Print Preview + + From 38c92339bb4f4a69429c4c6a2d1b8899ec51480d Mon Sep 17 00:00:00 2001 From: John Schember Date: Mon, 2 Feb 2009 19:07:57 -0500 Subject: [PATCH 2/3] Ebook Viewer: Support for printing entire book --- src/calibre/gui2/viewer/documentview.py | 68 ++++++++++++++++++------- 1 file changed, 51 insertions(+), 17 deletions(-) diff --git a/src/calibre/gui2/viewer/documentview.py b/src/calibre/gui2/viewer/documentview.py index 6ce7a39e9d..ac9cd1fe30 100644 --- a/src/calibre/gui2/viewer/documentview.py +++ b/src/calibre/gui2/viewer/documentview.py @@ -307,26 +307,60 @@ class DocumentView(QWebView): def goto_bookmark(self, bm): self.document.goto_bookmark(bm) - def print_preview(self): - printer = QPrinter(QPrinter.HighResolution) - printer.setPageMargins(1, 1, 1, 1, QPrinter.Inch) + def all_content(self): + book_content = '' - previewDialog = QPrintPreviewDialog(printer, self) - - self.connect(previewDialog, SIGNAL('paintRequested(QPrinter *)'), self.print_) - previewDialog.exec_() - self.disconnect(previewDialog, SIGNAL('paintRequested(QPrinter *)'), self.print_) + if self.manager is not None: + for path in self.manager.iterator.spine: + html = open(path, 'rb').read().decode(path.encoding) + book_content += EntityDeclarationProcessor(html).processed_html + base_url = QUrl.fromLocalFile(self.manager.iterator.spine[0]) + else: + book_content = self.page().mainFrame().toHtml() + base_url = QUrl.fromLocalFile(self.path()) + + return (book_content, base_url) - def print_book(self): - printer = QPrinter(QPrinter.HighResolution) - printer.setPageMargins(1, 1, 1, 1, QPrinter.Inch) + def print_preview(self): + print_view = QWebView() + book_content, base_url = self.all_content() + print_view.setHtml(book_content, base_url) + print_view.setTextSizeMultiplier(self.textSizeMultiplier()) + + def finished(ok): + printer = QPrinter(QPrinter.HighResolution) + printer.setPageMargins(1, 1, 1, 1, QPrinter.Inch) + + previewDialog = QPrintPreviewDialog(printer, self) + + self.connect(previewDialog, SIGNAL('paintRequested(QPrinter *)'), print_view.print_) + previewDialog.exec_() + self.disconnect(previewDialog, SIGNAL('paintRequested(QPrinter *)'), print_view.print_) + + self.disconnect(print_view, SIGNAL('loadFinished(bool)'), finished) + + self.connect(print_view, SIGNAL('loadFinished(bool)'), finished) - printDialog = QPrintDialog(printer, self) - printDialog.setWindowTitle(_("Print eBook")) - - printDialog.exec_() - if printDialog.result() == QDialog.Accepted: - self.print_(printer) + def print_book(self): + print_view = QWebView() + book_content, base_url = self.all_content() + print_view.setHtml(book_content, base_url) + print_view.setTextSizeMultiplier(self.textSizeMultiplier()) + + def finished(ok): + printer = QPrinter(QPrinter.HighResolution) + printer.setPageMargins(1, 1, 1, 1, QPrinter.Inch) + + printDialog = QPrintDialog(printer, self) + printDialog.setWindowTitle(_("Print eBook")) + + printDialog.exec_() + if printDialog.result() == QDialog.Accepted: + print_view.print_(printer) + + self.disconnect(print_view, SIGNAL('loadFinished(bool)'), finished) + + self.connect(print_view, SIGNAL('loadFinished(bool)'), finished) def config(self, parent=None): self.document.do_config(parent) From 358ec20ceb76e8fb77882d7e89d6330f30dad9db Mon Sep 17 00:00:00 2001 From: John Schember Date: Mon, 9 Feb 2009 17:34:51 -0500 Subject: [PATCH 3/3] Fix bug: 1755, add new Vendor and Product Ids for Cybook. --- src/calibre/devices/cybookg3/driver.py | 4 +-- src/calibre/devices/kindle/driver.py | 4 +-- src/calibre/devices/usbms/device.py | 39 ++++++++++++++------------ 3 files changed, 25 insertions(+), 22 deletions(-) diff --git a/src/calibre/devices/cybookg3/driver.py b/src/calibre/devices/cybookg3/driver.py index f573fb1b75..f092473675 100644 --- a/src/calibre/devices/cybookg3/driver.py +++ b/src/calibre/devices/cybookg3/driver.py @@ -17,8 +17,8 @@ class CYBOOKG3(USBMS): # Be sure these have an entry in calibre.devices.mime FORMATS = ['mobi', 'prc', 'html', 'pdf', 'rtf', 'txt'] - VENDOR_ID = 0x0bda - PRODUCT_ID = 0x0703 + VENDOR_ID = [0x0bda, 0x3034] + PRODUCT_ID = [0x0703, 0x1795] BCD = [0x110, 0x132] VENDOR_NAME = 'BOOKEEN' diff --git a/src/calibre/devices/kindle/driver.py b/src/calibre/devices/kindle/driver.py index 8ef1ba6b9b..0da1f55c5e 100755 --- a/src/calibre/devices/kindle/driver.py +++ b/src/calibre/devices/kindle/driver.py @@ -12,8 +12,8 @@ class KINDLE(USBMS): # Ordered list of supported formats FORMATS = ['azw', 'mobi', 'prc', 'txt'] - VENDOR_ID = 0x1949 - PRODUCT_ID = 0x0001 + VENDOR_ID = [0x1949] + PRODUCT_ID = [0x0001] BCD = [0x399] VENDOR_NAME = 'KINDLE' diff --git a/src/calibre/devices/usbms/device.py b/src/calibre/devices/usbms/device.py index 761fe9ba74..5943e2e13f 100644 --- a/src/calibre/devices/usbms/device.py +++ b/src/calibre/devices/usbms/device.py @@ -74,24 +74,27 @@ class Device(_Device): def get_fdi(cls): fdi = '' - fdi_base_values = dict( - app=__appname__, - deviceclass=cls.__name__, - vendor_id=hex(cls.VENDOR_ID), - product_id=hex(cls.PRODUCT_ID), - main_memory=cls.MAIN_MEMORY_VOLUME_LABEL, - storage_card=cls.STORAGE_CARD_VOLUME_LABEL, - ) - if cls.BCD is None: - fdi_base_values['BCD_start'] = '' - fdi_base_values['BCD_end'] = '' - fdi = cls.FDI_TEMPLATE % fdi_base_values - else: - for bcd in cls.BCD: - fdi_bcd_values = fdi_base_values - fdi_bcd_values['BCD_start'] = cls.FDI_BCD_TEMPLATE % dict(bcd=hex(bcd)) - fdi_bcd_values['BCD_end'] = '' - fdi += cls.FDI_TEMPLATE % fdi_bcd_values + for vid in cls.VENDOR_ID: + for pid in cls.PRODUCT_ID: + fdi_base_values = dict( + app=__appname__, + deviceclass=cls.__name__, + vendor_id=hex(vid), + product_id=hex(pid), + main_memory=cls.MAIN_MEMORY_VOLUME_LABEL, + storage_card=cls.STORAGE_CARD_VOLUME_LABEL, + ) + + if cls.BCD is None: + fdi_base_values['BCD_start'] = '' + fdi_base_values['BCD_end'] = '' + fdi += cls.FDI_TEMPLATE % fdi_base_values + else: + for bcd in cls.BCD: + fdi_bcd_values = fdi_base_values + fdi_bcd_values['BCD_start'] = cls.FDI_BCD_TEMPLATE % dict(bcd=hex(bcd)) + fdi_bcd_values['BCD_end'] = '' + fdi += cls.FDI_TEMPLATE % fdi_bcd_values return fdi