def __init__(self, _model, verbose=True, parent=None): """ Connect to all of the models signals, Whenever anything happens recheck everything. """ QtCore.QObject.__init__(self, parent) self._model = _model self.model = sip.cast(_model, QtCore.QAbstractItemModel) self.insert = [] self.remove = [] self.fetchingMore = False self._verbose = verbose assert (self.model) self.model.columnsAboutToBeInserted.connect(self.runAllTests) self.model.columnsAboutToBeRemoved.connect(self.runAllTests) self.model.columnsInserted.connect(self.runAllTests) self.model.columnsRemoved.connect(self.runAllTests) self.model.dataChanged.connect(self.runAllTests) self.model.headerDataChanged.connect(self.runAllTests) self.model.layoutAboutToBeChanged.connect(self.runAllTests) self.model.layoutChanged.connect(self.runAllTests) self.model.modelReset.connect(self.runAllTests) self.model.rowsAboutToBeInserted.connect(self.runAllTests) self.model.rowsAboutToBeRemoved.connect(self.runAllTests) self.model.rowsInserted.connect(self.runAllTests) self.model.rowsRemoved.connect(self.runAllTests) # Special checks for inserting/removing self.model.rowsAboutToBeInserted.connect(self.rowsAboutToBeInserted) self.model.rowsAboutToBeRemoved.connect(self.rowsAboutToBeRemoved) self.model.rowsInserted.connect(self.rowsInserted) self.model.rowsRemoved.connect(self.rowsRemoved) self.runAllTests()
def __init__(self, brush, matrix, pdf, pixel_page_width, pixel_page_height): self.matrix = (matrix.m11(), matrix.m12(), matrix.m21(), matrix.m22(), matrix.dx(), matrix.dy()) gradient = sip.cast(brush.gradient(), QLinearGradient) start, stop, stops = self.spread_gradient(gradient, pixel_page_width, pixel_page_height, matrix) # TODO: Handle colors with different opacities self.const_opacity = stops[0].color[-1] funcs = Array() bounds = Array() encode = Array() for i, current_stop in enumerate(stops): if i < len(stops) - 1: next_stop = stops[i+1] func = Dictionary({ 'FunctionType': 2, 'Domain': Array([0, 1]), 'C0': Array(current_stop.color[:3]), 'C1': Array(next_stop.color[:3]), 'N': 1, }) funcs.append(func) encode.extend((0, 1)) if i+1 < len(stops) - 1: bounds.append(next_stop.t) func = Dictionary({ 'FunctionType': 3, 'Domain': Array([stops[0].t, stops[-1].t]), 'Functions': funcs, 'Bounds': bounds, 'Encode': encode, }) shader = Dictionary({ 'ShadingType': 2, 'ColorSpace': Name('DeviceRGB'), 'AntiAlias': True, 'Coords': Array([start.x(), start.y(), stop.x(), stop.y()]), 'Function': func, 'Extend': Array([True, True]), }) Dictionary.__init__(self, { 'Type': Name('Pattern'), 'PatternType': 2, 'Shading': shader, 'Matrix': Array(self.matrix), }) self.cache_key = (self.__class__.__name__, self.matrix, tuple(shader['Coords']), stops)
def itemChange(self, change, value): ret = GraphicsObject.itemChange(self, change, value) ## workaround for pyqt bug: ## http://www.riverbankcomputing.com/pipermail/pyqt/2012-August/031818.html if QT_LIB in ['PyQt4', 'PyQt5' ] and change == self.ItemParentChange and isinstance( ret, QtGui.QGraphicsItem): ret = sip.cast(ret, QtGui.QGraphicsItem) if change == self.ItemScenePositionHasChanged: self.setNewBounds() return ret