From 77e779638cf6d795dc1a1bde03840b1165d829e9 Mon Sep 17 00:00:00 2001 From: Dmitri Bogomolov <4glitch@gmail.com> Date: Tue, 7 Mar 2017 15:34:45 +0200 Subject: [PATCH 1/5] Removed unnecessary code in qrcode plugin --- src/plugins/qrcodeui.py | 69 +++++++++++++++-------------------------- 1 file changed, 25 insertions(+), 44 deletions(-) diff --git a/src/plugins/qrcodeui.py b/src/plugins/qrcodeui.py index 25b1e0b1..d4dbcb69 100644 --- a/src/plugins/qrcodeui.py +++ b/src/plugins/qrcodeui.py @@ -3,12 +3,7 @@ from PyQt4 import QtGui, QtCore import qrcode -from pybitmessage.tr import translateText - -try: - _fromUtf8 = QtCore.QString.fromUtf8 -except AttributeError: - _fromUtf8 = lambda s: s +from pybitmessage.tr import _translate # http://stackoverflow.com/questions/20452486 @@ -37,65 +32,51 @@ class Image(qrcode.image.base.BaseImage): pass -class Ui_qrcodeDialog(object): - def setupUi(self, qrcodeDialog): - qrcodeDialog.setObjectName(_fromUtf8("qrcodeDialog")) - self.image = QtGui.QLabel(qrcodeDialog) - self.label = QtGui.QLabel(qrcodeDialog) +class QRCodeDialog(QtGui.QDialog): + + def __init__(self, parent): + super(QRCodeDialog, self).__init__(parent) + self.image = QtGui.QLabel(self) + self.label = QtGui.QLabel(self) font = QtGui.QFont() font.setBold(True) font.setWeight(75) self.label.setFont(font) self.label.setAlignment( QtCore.Qt.AlignCenter | QtCore.Qt.AlignVCenter) - self.buttonBox = QtGui.QDialogButtonBox(qrcodeDialog) - self.buttonBox.setOrientation(QtCore.Qt.Horizontal) - self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Ok) - layout = QtGui.QVBoxLayout(qrcodeDialog) + buttonBox = QtGui.QDialogButtonBox(self) + buttonBox.setOrientation(QtCore.Qt.Horizontal) + buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Ok) + buttonBox.accepted.connect(self.accept) + layout = QtGui.QVBoxLayout(self) layout.addWidget(self.image) layout.addWidget(self.label) - layout.addWidget(self.buttonBox) + layout.addWidget(buttonBox) + self.retranslateUi() - self.retranslateUi(qrcodeDialog) - QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL( - _fromUtf8("accepted()")), qrcodeDialog.accept) - QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL( - _fromUtf8("rejected()")), qrcodeDialog.reject) - QtCore.QMetaObject.connectSlotsByName(qrcodeDialog) - - def retranslateUi(self, qrcodeDialog): - qrcodeDialog.setWindowTitle(QtGui.QApplication.translate( - "qrcodeDialog", "QR-code", - None, QtGui.QApplication.UnicodeUTF8 - )) + def retranslateUi(self): + self.setWindowTitle(_translate("QRCodeDialog", "QR-code")) def render(self, text): self.label.setText(text) self.image.setPixmap( qrcode.make(text, image_factory=Image).pixmap()) - - -class qrcodeDialog(QtGui.QDialog): - - def __init__(self, parent): - QtGui.QWidget.__init__(self, parent) - self.ui = Ui_qrcodeDialog() - self.ui.setupUi(self) - self.parent = parent - QtGui.QWidget.resize(self, QtGui.QWidget.sizeHint(self)) + self.setFixedSize(QtGui.QWidget.sizeHint(self)) def connect_plugin(form): def on_action_ShowQR(): - form.qrcodeDialogInstance = qrcodeDialog(form) - form.qrcodeDialogInstance.ui.render( - str(form.getCurrentAccount()) - ) - form.qrcodeDialogInstance.exec_() + try: + dialog = form.qrcode_dialog + except AttributeError: + form.qrcode_dialog = dialog = QRCodeDialog(form) + dialog.render(str(form.getCurrentAccount())) + dialog.exec_() + # return form.actionShowQRCode = \ form.ui.addressContextMenuToolbarYourIdentities.addAction( - translateText("MainWindow", "Show QR-code"), + _translate("MainWindow", "Show QR-code"), on_action_ShowQR ) form.popMenuYourIdentities.addAction(form.actionShowQRCode) -- 2.45.1 From 08a21154122d246908690599ab961a009db64464 Mon Sep 17 00:00:00 2001 From: Dmitri Bogomolov <4glitch@gmail.com> Date: Tue, 7 Mar 2017 15:44:48 +0200 Subject: [PATCH 2/5] Properly renamed qrcode plugin module and made menu available for all address entries except for addressbook and blacklist --- setup.py | 3 +-- src/bitmessageqt/__init__.py | 29 +++++++++++++++++---- src/plugins/{qrcodeui.py => menu_qrcode.py} | 8 +----- 3 files changed, 26 insertions(+), 14 deletions(-) rename src/plugins/{qrcodeui.py => menu_qrcode.py} (89%) diff --git a/setup.py b/setup.py index ba34f6df..12670ed6 100644 --- a/setup.py +++ b/setup.py @@ -112,8 +112,7 @@ if __name__ == "__main__": zip_safe=False, entry_points={ 'bitmessage.gui.menu': [ - 'popMenuYourIdentities.qrcode = ' - 'pybitmessage.plugins.qrcodeui [qrcode]' + 'address.qrcode = pybitmessage.plugins.menu_qrcode [qrcode]' ], 'bitmessage.notification.message': [ 'notify2 = pybitmessage.plugins.notification_notify2' diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index b3e39001..5178392c 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -255,6 +255,18 @@ class MyForm(settingsmixin.SMainWindow): 'customContextMenuRequested(const QPoint&)'), self.on_context_menuYourIdentities) + # load all gui.menu plugins with prefix 'address' + self.menu_plugins = {'address': []} + for plugin in get_plugins('gui.menu', 'address'): + try: + handler, title = plugin(self) + except TypeError: + continue + self.menu_plugins['address'].append( + self.ui.addressContextMenuToolbarYourIdentities.addAction( + title, handler + )) + def init_chan_popup_menu(self, connectSignal=True): # Popup menu for the Channels tab self.ui.addressContextMenuToolbar = QtGui.QToolBar() @@ -3421,6 +3433,10 @@ class MyForm(settingsmixin.SMainWindow): self.popMenuSubscriptions.addSeparator() self.popMenuSubscriptions.addAction(self.actionsubscriptionsClipboard) self.popMenuSubscriptions.addSeparator() + # preloaded gui.menu plugins with prefix 'address' + for plugin in self.menu_plugins['address']: + self.popMenuSubscriptions.addAction(plugin) + self.popMenuSubscriptions.addSeparator() self.popMenuSubscriptions.addAction(self.actionMarkAllRead) self.popMenuSubscriptions.exec_( self.ui.treeWidgetSubscriptions.mapToGlobal(point)) @@ -3831,13 +3847,12 @@ class MyForm(settingsmixin.SMainWindow): self.popMenuYourIdentities.addAction(self.actionSpecialAddressBehaviorYourIdentities) self.popMenuYourIdentities.addAction(self.actionEmailGateway) self.popMenuYourIdentities.addSeparator() + # preloaded gui.menu plugins with prefix 'address' + for plugin in self.menu_plugins['address']: + self.popMenuYourIdentities.addAction(plugin) + self.popMenuYourIdentities.addSeparator() self.popMenuYourIdentities.addAction(self.actionMarkAllRead) - if get_plugins: - for plugin in get_plugins( - 'gui.menu', 'popMenuYourIdentities'): - plugin(self) - self.popMenuYourIdentities.exec_( self.ui.treeWidgetYourIdentities.mapToGlobal(point)) @@ -3857,6 +3872,10 @@ class MyForm(settingsmixin.SMainWindow): self.popMenu.addAction(self.actionEnable) self.popMenu.addAction(self.actionSetAvatar) self.popMenu.addSeparator() + # preloaded gui.menu plugins with prefix 'address' + for plugin in self.menu_plugins['address']: + self.popMenu.addAction(plugin) + self.popMenu.addSeparator() self.popMenu.addAction(self.actionMarkAllRead) self.popMenu.exec_( self.ui.treeWidgetChans.mapToGlobal(point)) diff --git a/src/plugins/qrcodeui.py b/src/plugins/menu_qrcode.py similarity index 89% rename from src/plugins/qrcodeui.py rename to src/plugins/menu_qrcode.py index d4dbcb69..0562907b 100644 --- a/src/plugins/qrcodeui.py +++ b/src/plugins/menu_qrcode.py @@ -73,10 +73,4 @@ def connect_plugin(form): dialog.render(str(form.getCurrentAccount())) dialog.exec_() - # return - form.actionShowQRCode = \ - form.ui.addressContextMenuToolbarYourIdentities.addAction( - _translate("MainWindow", "Show QR-code"), - on_action_ShowQR - ) - form.popMenuYourIdentities.addAction(form.actionShowQRCode) + return on_action_ShowQR, _translate("MainWindow", "Show QR-code") -- 2.45.1 From 3850a920c9d68b49cac74a68197be142689c5d81 Mon Sep 17 00:00:00 2001 From: Dmitri Bogomolov <4glitch@gmail.com> Date: Tue, 20 Feb 2018 16:22:46 +0200 Subject: [PATCH 3/5] Do not add gui.menu plugins with prefix 'address' to "All accounts" item --- src/bitmessageqt/__init__.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index 5178392c..001dc053 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -3847,9 +3847,10 @@ class MyForm(settingsmixin.SMainWindow): self.popMenuYourIdentities.addAction(self.actionSpecialAddressBehaviorYourIdentities) self.popMenuYourIdentities.addAction(self.actionEmailGateway) self.popMenuYourIdentities.addSeparator() - # preloaded gui.menu plugins with prefix 'address' - for plugin in self.menu_plugins['address']: - self.popMenuYourIdentities.addAction(plugin) + if currentItem.type != AccountMixin.ALL: + # preloaded gui.menu plugins with prefix 'address' + for plugin in self.menu_plugins['address']: + self.popMenuYourIdentities.addAction(plugin) self.popMenuYourIdentities.addSeparator() self.popMenuYourIdentities.addAction(self.actionMarkAllRead) -- 2.45.1 From 0ddc56e83aa6b31bbab352abcaa6b87162ad5ef2 Mon Sep 17 00:00:00 2001 From: Dmitri Bogomolov <4glitch@gmail.com> Date: Tue, 20 Feb 2018 16:47:02 +0200 Subject: [PATCH 4/5] Added schema 'bitmessage:', it's unreadable otherwise for some reason --- src/plugins/menu_qrcode.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/menu_qrcode.py b/src/plugins/menu_qrcode.py index 0562907b..bd73b3ab 100644 --- a/src/plugins/menu_qrcode.py +++ b/src/plugins/menu_qrcode.py @@ -70,7 +70,7 @@ def connect_plugin(form): dialog = form.qrcode_dialog except AttributeError: form.qrcode_dialog = dialog = QRCodeDialog(form) - dialog.render(str(form.getCurrentAccount())) + dialog.render('bitmessage:' + str(form.getCurrentAccount())) dialog.exec_() return on_action_ShowQR, _translate("MainWindow", "Show QR-code") -- 2.45.1 From 0ef0e6b020de12ae75afcd1123ec966d8c97d1ef Mon Sep 17 00:00:00 2001 From: Dmitri Bogomolov <4glitch@gmail.com> Date: Tue, 13 Mar 2018 13:39:35 +0200 Subject: [PATCH 5/5] Added docstrings. Removed unused method Image.save(). --- src/plugins/menu_qrcode.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/plugins/menu_qrcode.py b/src/plugins/menu_qrcode.py index bd73b3ab..3831e89b 100644 --- a/src/plugins/menu_qrcode.py +++ b/src/plugins/menu_qrcode.py @@ -1,4 +1,7 @@ # -*- coding: utf-8 -*- +""" +A menu plugin showing QR-Code for bitmessage address in modal dialog. +""" from PyQt4 import QtGui, QtCore import qrcode @@ -8,6 +11,7 @@ from pybitmessage.tr import _translate # http://stackoverflow.com/questions/20452486 class Image(qrcode.image.base.BaseImage): + """Image output class for qrcode using QPainter""" def __init__(self, border, width, box_size): self.border = border self.width = width @@ -18,9 +22,11 @@ class Image(qrcode.image.base.BaseImage): self._image.fill(QtCore.Qt.white) def pixmap(self): + """Get image pixmap""" return QtGui.QPixmap.fromImage(self._image) def drawrect(self, row, col): + """Draw a single rectangle - implementation""" painter = QtGui.QPainter(self._image) painter.fillRect( (col + self.border) * self.box_size, @@ -28,12 +34,9 @@ class Image(qrcode.image.base.BaseImage): self.box_size, self.box_size, QtCore.Qt.black) - def save(self, stream, kind=None): - pass - class QRCodeDialog(QtGui.QDialog): - + """The dialog""" def __init__(self, parent): super(QRCodeDialog, self).__init__(parent) self.image = QtGui.QLabel(self) @@ -55,9 +58,11 @@ class QRCodeDialog(QtGui.QDialog): self.retranslateUi() def retranslateUi(self): + """A conventional Qt Designer method for dynamic l10n""" self.setWindowTitle(_translate("QRCodeDialog", "QR-code")) def render(self, text): + """Draw QR-code and address in labels""" self.label.setText(text) self.image.setPixmap( qrcode.make(text, image_factory=Image).pixmap()) @@ -65,7 +70,9 @@ class QRCodeDialog(QtGui.QDialog): def connect_plugin(form): + """Plugin entry point""" def on_action_ShowQR(): + """A slot for popup menu action""" try: dialog = form.qrcode_dialog except AttributeError: -- 2.45.1