From 2196057266689b71a36700225158a4c84a79e196 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gonzalo=20Pe=C3=B1a-Castellanos?= Date: Sun, 2 Aug 2015 10:54:08 -0500 Subject: [PATCH] Move MessageCheckBox widget from workers/, to helperwidgets.py --- spyderlib/spyder.py | 2 +- spyderlib/widgets/helperwidgets.py | 68 +++++++++++++++++++++++++++++- spyderlib/workers/updates.py | 61 +-------------------------- 3 files changed, 68 insertions(+), 63 deletions(-) diff --git a/spyderlib/spyder.py b/spyderlib/spyder.py index 8be8b0dbe01..76e167d08ae 100644 --- a/spyderlib/spyder.py +++ b/spyderlib/spyder.py @@ -2826,7 +2826,7 @@ def show_tour(self, index): # ---- Check for Spyder Updates def _check_updates_ready(self): """Called by WorkerUpdates when ready""" - from spyderlib.workers.updates import MessageCheckBox + from spyderlib.widgets.helperwidgets import MessageCheckBox # feedback` = False is used on startup, so only positive feedback is # given. `feedback` = True is used when after startup (when using the diff --git a/spyderlib/widgets/helperwidgets.py b/spyderlib/widgets/helperwidgets.py index 1a8ad5eabdc..b27eb3330e9 100644 --- a/spyderlib/widgets/helperwidgets.py +++ b/spyderlib/widgets/helperwidgets.py @@ -8,14 +8,19 @@ Helper widgets. """ -from spyderlib.qt.QtCore import QPoint, QSize +from spyderlib.qt.QtCore import QPoint, QSize, Qt from spyderlib.qt.QtGui import (QToolButton, QToolTip, QStyledItemDelegate, QApplication, QTextDocument, QStyleOptionViewItem, - QAbstractTextDocumentLayout, QStyle) + QAbstractTextDocumentLayout, QStyle, + QVBoxLayout, QSpacerItem, + QMessageBox, QCheckBox) + +from spyderlib.baseconfig import _ from spyderlib.utils.qthelpers import get_std_icon + class HelperToolButton(QToolButton): """Subclasses QToolButton, to provide a simple tooltip on mousedown. """ @@ -46,6 +51,48 @@ def mouseReleaseEvent(self, event): QToolTip.showText(self.mapToGlobal(QPoint(0, 0)), self._tip_text) +class MessageCheckBox(QMessageBox): + """ + A QMessageBox derived widget that includes a QCheckBox aligned to the right + under the message and on top of the buttons. + """ + def __init__(self, *args, **kwargs): + super(MessageCheckBox, self).__init__(*args, **kwargs) + + self._checkbox = QCheckBox() + + # Set layout to include checkbox + size = 9 + check_layout = QVBoxLayout() + check_layout.addItem(QSpacerItem(size, size)) + check_layout.addWidget(self._checkbox, 0, Qt.AlignRight) + check_layout.addItem(QSpacerItem(size, size)) + + # Access the Layout of the MessageBox to add the Checkbox + layout = self.layout() + layout.addLayout(check_layout, 1, 1) + + # --- Public API + # Methods to access the checkbox + def is_checked(self): + return self._checkbox.isChecked() + + def set_checked(self, value): + return self._checkbox.setChecked(value) + + def set_check_visible(self, value): + self._checkbox.setVisible(value) + + def is_check_visible(self): + self._checkbox.isVisible() + + def checkbox_text(self): + self._checkbox.text() + + def set_checkbox_text(self, text): + self._checkbox.setText(text) + + class HTMLDelegate(QStyledItemDelegate): """With this delegate, a QListWidgetItem or a QTableItem can render HTML. @@ -88,3 +135,20 @@ def sizeHint(self, option, index): doc.setTextWidth(options.rect.width()) return QSize(doc.idealWidth(), doc.size().height()) + + +def test_msgcheckbox(): + from spyderlib.utils.qthelpers import qapplication + app = qapplication() + box = MessageCheckBox() + box.setWindowTitle(_("Spyder updates")) + box.setText("Testing checkbox") + box.set_checkbox_text("Check for updates on startup?") + box.setStandardButtons(QMessageBox.Ok) + box.setDefaultButton(QMessageBox.Ok) + box.setIcon(QMessageBox.Information) + box.exec_() + + +if __name__ == '__main__': + test_msgcheckbox() diff --git a/spyderlib/workers/updates.py b/spyderlib/workers/updates.py index f9e4de88e6b..af12eb4d636 100644 --- a/spyderlib/workers/updates.py +++ b/spyderlib/workers/updates.py @@ -11,8 +11,7 @@ from spyderlib import __version__ from spyderlib.baseconfig import _ from spyderlib.py3compat import PY3 -from spyderlib.qt.QtGui import QMessageBox, QCheckBox, QSpacerItem, QVBoxLayout -from spyderlib.qt.QtCore import Signal, Qt, QObject +from spyderlib.qt.QtCore import Signal, QObject from spyderlib.utils.programs import check_version, is_stable_version @@ -23,48 +22,6 @@ from urllib2 import urlopen, URLError, HTTPError -class MessageCheckBox(QMessageBox): - """ - A QMessageBox derived widget that includes a QCheckBox aligned to the right - under the message and on top of the buttons. - """ - def __init__(self, *args, **kwargs): - super(MessageCheckBox, self).__init__(*args, **kwargs) - - self._checkbox = QCheckBox() - - # Set layout to include checkbox - size = 9 - check_layout = QVBoxLayout() - check_layout.addItem(QSpacerItem(size, size)) - check_layout.addWidget(self._checkbox, 0, Qt.AlignRight) - check_layout.addItem(QSpacerItem(size, size)) - - # Access the Layout of the MessageBox to add the Checkbox - layout = self.layout() - layout.addLayout(check_layout, 1, 1) - - # --- Public API - # Methods to access the checkbox - def is_checked(self): - return self._checkbox.isChecked() - - def set_checked(self, value): - return self._checkbox.setChecked(value) - - def set_check_visible(self, value): - self._checkbox.setVisible(value) - - def is_check_visible(self): - self._checkbox.isVisible() - - def checkbox_text(self): - self._checkbox.text() - - def set_checkbox_text(self, text): - self._checkbox.setText(text) - - class WorkerUpdates(QObject): """ Worker that checks for releases using the Github API without blocking the @@ -130,19 +87,3 @@ def start(self): self.error = error_msg self.sig_ready.emit() - - -def test_msgcheckbox(): - from spyderlib.utils.qthelpers import qapplication - app = qapplication() - box = MessageCheckBox() - box.setWindowTitle(_("Spyder updates")) - box.setText("Testing checkbox") - box.set_checkbox_text("Check for updates on startup?") - box.setStandardButtons(QMessageBox.Ok) - box.setDefaultButton(QMessageBox.Ok) - box.setIcon(QMessageBox.Information) - box.exec_() - -if __name__ == '__main__': - test_msgcheckbox()