Skip to content

Commit

Permalink
Merge pull request #2582 from goanpeca/reorganize-helper
Browse files Browse the repository at this point in the history
Move MessageCheckBox widget from workers to helperwidgets.py
  • Loading branch information
ccordoba12 committed Aug 5, 2015
2 parents ad6ccf9 + 2196057 commit 2ce3b4d
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 63 deletions.
2 changes: 1 addition & 1 deletion spyderlib/spyder.py
Original file line number Diff line number Diff line change
Expand Up @@ -2827,7 +2827,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
Expand Down
68 changes: 66 additions & 2 deletions spyderlib/widgets/helperwidgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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()
61 changes: 1 addition & 60 deletions spyderlib/workers/updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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
Expand Down Expand Up @@ -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()

0 comments on commit 2ce3b4d

Please sign in to comment.