Signal to notify when selection state changes

This commit is contained in:
Kovid Goyal 2013-12-03 16:40:12 +05:30
parent 107cfa8f1e
commit f1b59e849d

View File

@ -11,7 +11,7 @@ from functools import wraps
from PyQt4.Qt import ( from PyQt4.Qt import (
QWidget, QImage, QPainter, QColor, QApplication, Qt, QPixmap, QRectF, QWidget, QImage, QPainter, QColor, QApplication, Qt, QPixmap, QRectF,
QPointF, QPen) QPointF, QPen, pyqtSignal)
from calibre import fit_image from calibre import fit_image
@ -52,6 +52,12 @@ class Canvas(QWidget):
SHADE_COLOR = QColor(0, 0, 0, 180) SHADE_COLOR = QColor(0, 0, 0, 180)
SELECT_PEN = QPen(QColor(Qt.white)) SELECT_PEN = QPen(QColor(Qt.white))
selection_state_changed = pyqtSignal(object)
@property
def has_selection(self):
return self.selection_state.current_mode == 'selected'
def __init__(self, parent=None): def __init__(self, parent=None):
QWidget.__init__(self, parent) QWidget.__init__(self, parent)
self.setMouseTracking(True) self.setMouseTracking(True)
@ -209,6 +215,7 @@ class Canvas(QWidget):
self.selection_state.reset(full=False) self.selection_state.reset(full=False)
if self.selection_state.current_mode == 'select': if self.selection_state.current_mode == 'select':
self.selection_state.current_mode = 'selected' self.selection_state.current_mode = 'selected'
self.selection_state_changed.emit(True)
self.update() self.update()
@painter @painter