def _get_pos_widget(name, backgroundColor, foregroundColor): label = QLabel() label.setAttribute(Qt.WA_TransparentForMouseEvents, True) pixmap = QPixmap(25 * 10, 25 * 10) pixmap.fill(backgroundColor) painter = QPainter() painter.begin(pixmap) pen = QPen(foregroundColor) painter.setPen(pen) painter.setRenderHint(QPainter.Antialiasing) font = QFont() font.setBold(True) font.setPixelSize(25 * 10 - 30) path = QPainterPath() path.addText(QPointF(50, 25 * 10 - 50), font, name) brush = QBrush(foregroundColor) painter.setBrush(brush) painter.drawPath(path) painter.setFont(font) painter.end() pixmap = pixmap.scaled(QSize(20, 20), Qt.KeepAspectRatio, Qt.SmoothTransformation) label.setPixmap(pixmap) spinbox = QSpinBox() spinbox.setAttribute(Qt.WA_TransparentForMouseEvents, True) spinbox.setEnabled(False) spinbox.setAlignment(Qt.AlignCenter) spinbox.setToolTip("{0} Spin Box".format(name)) spinbox.setButtonSymbols(QAbstractSpinBox.NoButtons) spinbox.setMaximumHeight(20) spinbox.setMaximum(9999) font = spinbox.font() font.setPixelSize(14) spinbox.setFont(font) sheet = TEMPLATE.format(foregroundColor.name(), backgroundColor.name()) spinbox.setStyleSheet(sheet) return label, spinbox
def __insertItem(self, item, index): """ Insert category item at index. """ grid = WidgetToolGrid() grid.setModel(item.model(), item.index()) grid.actionTriggered.connect(self.triggered) grid.actionHovered.connect(self.hovered) grid.setIconSize(self.__iconSize) grid.setButtonSize(self.__buttonSize) text = item.text() icon = item.icon() tooltip = item.toolTip() # Set the 'tab-title' property to text. grid.setProperty("tab-title", text) grid.setObjectName("widgets-toolbox-grid") self.insertItem(index, grid, text, icon, tooltip) button = self.tabButton(index) # Set the 'highlight' color if item.data(Qt.BackgroundRole) is not None: brush = item.background() elif item.data(QtWidgetRegistry.BACKGROUND_ROLE) is not None: brush = item.data(QtWidgetRegistry.BACKGROUND_ROLE) else: brush = self.palette().brush(QPalette.Button) if not brush.gradient(): gradient = create_gradient(brush.color()) brush = QBrush(gradient) palette = button.palette() palette.setBrush(QPalette.Highlight, brush) button.setPalette(palette)
def update_remote_files(self): """ Updates the list of remote files. :return: None """ self.RemoteFileListView.clear() files = self.queries.get_all_remote_files() hash_list = [] list_widget_index = 0 for file in files: self.RemoteFileListView.addItem(file[0]) # Change text color of changed files to red if not self.general_functions.get_file_hash(file): self.RemoteFileListView.item(list_widget_index).setSelected( True) for item in self.RemoteFileListView.selectedItems(): item.setForeground(QBrush(Qt.red, Qt.SolidPattern)) list_widget_index += 1
def __init__(self): super(ControllerGui, self).__init__() self.setupUi(self) self.m_clear.clicked.connect(self.clear_plot) self.m_send.clicked.connect(self.send_start) self.m_stop.clicked.connect(self.send_stop) self.interface = SerialInterface() self.interface.received.connect(self.show_received) self.m_interval.setValidator(QIntValidator(0, 10000)) self.m_interval.returnPressed.connect(self.send_start) brush = QBrush(QColor(255, 255, 255)) box = QVBoxLayout(self.m_list) self.temperature_plot = PlotWidget(self) self.temperature_plot.setBackgroundBrush(brush) self.temperature_plot.setFixedHeight(300) box.addWidget(self.temperature_plot) self.temperature_curves = {} self.humidity_plot = PlotWidget(self) self.humidity_plot.setBackgroundBrush(brush) self.humidity_plot.setFixedHeight(300) box.addWidget(self.humidity_plot) self.humidity_curves = {} self.illumination_plot = PlotWidget(self) self.illumination_plot.setBackgroundBrush(brush) self.illumination_plot.setFixedHeight(300) box.addWidget(self.illumination_plot) self.illumination_curves = {} box.addItem(QSpacerItem(40, 20, QSizePolicy.Maximum, QSizePolicy.Expanding)) self.m_list.setLayout(box) box = QVBoxLayout(self.m_devices) box.addItem(QSpacerItem(40, 20, QSizePolicy.Maximum, QSizePolicy.Expanding)) self.m_devices.setLayout(box) self.file = open('result.txt', 'w')
def process_error(self, error): """Listen to the error signals from the running process.""" self.lblInput.hide() self.input.hide() self._proc.kill() format_ = QTextCharFormat() format_.setAnchor(True) font = QFont(settings.FONT_FAMILY, settings.FONT_SIZE) format_.setFont(font) format_.setForeground( QBrush( QColor( resources.CUSTOM_SCHEME.get( "error-underline", resources.COLOR_SCHEME["error-underline"])))) if error == 0: self.output.textCursor().insertText(self.tr('Failed to start'), format_) else: self.output.textCursor().insertText( (self.tr('Error during execution, QProcess error: %d') % error), format_)
def setTiles(self): #background brush = QBrush() pix = QPixmap(os.getcwd() + "/robotImages/tile.png") brush.setTexture(pix) brush.setStyle(24) self.setBackgroundBrush(brush) #wall #left left = QGraphicsRectItem() pix = QPixmap(os.getcwd() + "/robotImages/tileVert.png") left.setRect(QtCore.QRectF(0, 0, pix.width(), self.height)) brush.setTexture(pix) brush.setStyle(24) left.setBrush(brush) left.name = 'left' self.addItem(left) #right right = QGraphicsRectItem() right.setRect(self.width - pix.width(), 0, pix.width(), self.height) right.setBrush(brush) right.name = 'right' self.addItem(right) #top top = QGraphicsRectItem() pix = QPixmap(os.getcwd() + "/robotImages/tileHori.png") top.setRect(QtCore.QRectF(0, 0, self.width, pix.height())) brush.setTexture(pix) brush.setStyle(24) top.setBrush(brush) top.name = 'top' self.addItem(top) #bottom bottom = QGraphicsRectItem() bottom.setRect(0, self.height - pix.height(), self.width, pix.height()) bottom.setBrush(brush) bottom.name = 'bottom' self.addItem(bottom)
def colorizeDiff(self, diffinfos): cursor = self.textCursor() cursor.setPosition(QTextCursor.Start) text = self.toPlainText() keys = diffinfos.keys() keys.sort() for offset in keys: difflen = diffinfos[offset] pos = (offset * 2) + offset count = difflen + (((offset + difflen) / 16) - (offset / 16)) cursor.setPosition(pos, QTextCursor.MoveAnchor) cursor.movePosition(QTextCursor.NextWord, QTextCursor.KeepAnchor, count) format = QTextCharFormat() format.setFont(self.sfont) format.setForeground(QBrush(QColor(Qt.red))) cursor.setCharFormat(format) cursor.setPosition(QTextCursor.Start, QTextCursor.MoveAnchor)
def __init__(self, mapCanvas, geometry, layer): super(GeometryHighlightItem, self).__init__(mapCanvas) self._mapCanvas = None # QgsMapCanvas self._geometry = None # QgsGeometry() self._brush = QBrush() self._pen = QPen() self._mapCanvas = mapCanvas if not geometry or not isinstance(geometry, QgsGeometry) or geometry.isEmpty( ) or not geometry.isGeosValid(): return self._geometry = QgsGeometry(geometry) # Force deep copy self.setLineColor(Application.highlightLineColor()) self.setFillColor(Application.highlightFillColor()) if (layer and self._mapCanvas.mapSettings().hasCrsTransformEnabled()): ct = self._mapCanvas.mapSettings().layerTransform(layer) if ct: self._geometry.transform(ct) self.updateRect() self.update()
def AddMorePhotosToList(self): oldst = self.loadListCount n = 100 QApplication.setOverrideCursor(Qt.WaitCursor) if not self.GetPhotosList(self.loadListCount + 1, self.loadListCount + n): QApplication.restoreOverrideCursor() return tbl = self.tblPhotos tbl.verticalHeader().resizeSection(0, 50) for i in range(oldst, self.loadListCount): fn = os.path.join(self.folderpath, self.photolist[i].filename) self.photolist[i].filePath = fn tp = os.path.join(os.path.join(self.folderpath, 'thumb'), str(self.photolist[i].p_id) + '.png') self.photolist[i].thumbPath = tp item = ImgWidget(fn, tp, self) hd = QTableWidgetItem(str(self.photolist[i].p_id)) tbl.insertColumn(i) tbl.setHorizontalHeaderItem(i, hd) tbl.setCellWidget(0, i, item) b = QtGui.QTableWidgetItem(self.photolist[i].filename) b.setData(32, self.photolist[i]) tbl.setItem(1, i, b) if self.photolist[i].lon == 0 and self.photolist[i].lat == 0: tbl.item(1, i).setBackground(QBrush(QColor('#CCFFFF'))) if self.photolist[i].keywords: tbl.setItem(2, i, QtGui.QTableWidgetItem(self.photolist[i].keywords)) QgsMessageLog.logMessage(u"LoadPhoto..." + str(i), tag="LoadMorePhotoThread", level=QgsMessageLog.INFO) QApplication.restoreOverrideCursor()
def rounded_corners(image, radius=0, **kwargs): """ Appliquer un découpage du masque de l'image en rectangle arrondi :param image: image PIL :param radius: rayon en pixels des coins arrondis """ if radius == "full" or isinstance(radius, (int, float)): qimage = _pil_to_qt(image) newimage = _qt_canvas(image) painter = QPainter(newimage) painter.setRenderHint(QPainter.Antialiasing, True) painter.setBrush(QBrush(qimage)) painter.setPen(QColor(0, 0, 0, 0)) if radius == "full": # découper en ellipse painter.drawEllipse(0, 0, qimage.width(), qimage.height()) elif isinstance(radius, (int, float)): # découper en rectangle arrondi painter.drawRoundedRect(0, 0, qimage.width(), qimage.height(), radius, radius) painter.end() return _qt_to_pil(newimage) return image
def __init__(self, parent): QFrame.__init__(self, parent) self.fUseCustomPaint = False self.fMouseDown = False self.fViewBg = QColor(0, 0, 0) self.fViewBrush = QBrush(QColor(75, 75, 255, 30)) self.fViewPen = QPen(Qt.blue, 1) self.fScale = 1.0 self.fScene = None self.fRealParent = None self.fFakeWidth = 0.0 self.fFakeHeight = 0.0 self.fRenderSource = self.getRenderSource() self.fRenderTarget = QRectF(0, 0, 0, 0) self.fViewPadX = 0.0 self.fViewPadY = 0.0 self.fViewRect = [0.0, 0.0, 10.0, 10.0]
def configure_area(self, x_title='Index', x_unit='', y_title='Values', y_unit=''): """ Configure the plot to: Show a X,Y grid. Sets the colors to a white background theme. Sets the axis range and labels. :param x_title: The x axis label. :param x_unit: The unit names of the x values. :param y_title: The y axis label. :param y_unit: The unit names of the y axis. """ self.plotWidget.showGrid(True, True) # Colors: self.plotWidget.setBackgroundBrush(QBrush(QColor.fromRgb(255, 255, 255))) self.plotWidget.getAxis('left').setPen(QPen(QColor.fromRgb(0, 0, 0))) self.plotWidget.getAxis('bottom').setPen(QPen(QColor.fromRgb(0, 0, 0))) self.plotWidget.getAxis('left').setPen(QPen(QColor.fromRgb(0, 0, 0))) self.plotWidget.getAxis('bottom').setPen(QPen(QColor.fromRgb(0, 0, 0))) # Axis: self.plotWidget.setXRange(0, self.qnt_points) self.plotWidget.setYRange(self.__y_range[0], self.__y_range[1]) self.plotWidget.setLabel('bottom', x_title, units=x_unit) self.plotWidget.setLabel('left', y_title, units=y_unit)
def data(self, index, role): row, col = index.row(), index.column() if role in (Qt.DisplayRole, Qt.ToolTipRole): ret = self.df.iat[row, col] if ret is not None and ret == ret: #convert to str except for None, NaN, NaT if isinstance(ret, float): ret = "{:n}".format(ret) elif isinstance(ret, datetime.date): #FIXME: show microseconds optionally ret = ret.strftime( ("%x", "%c")[isinstance(ret, datetime.datetime)]) else: ret = str(ret) if role == Qt.ToolTipRole: if len(ret) < self.options["tooltip_min_len"]: ret = "" return ret elif role == Qt.BackgroundRole: if self.options["striped"] and row % 2: return QBrush(QColor(self.options["stripesColor"])) elif role in (HorizontalHeaderDataRole, VerticalHeaderDataRole): hm = QtGui.QStandardItemModel() hm.appendRow(self.readLevel(orient=role)) return hm
def setNameAndBrush(self, sigma, color=Qt.black): self.sigma = sigma self.setText(decode_to_qstring("σ=%.1fpx" % self.sigma, 'utf-8')) # This file is encoded as utf-8, so this string should be decoded as such. total_window = (1 + 2 * int(self.sigma * self.window_size + 0.5) ) self.setToolTip( "sigma = {:.1f} pixels, window diameter = {:.1f}".format(self.sigma, total_window) ) font = QFont() font.setPointSize(10) font.setBold(True) self.setFont(font) self.setForeground(color) pixmap = QPixmap(self.pixmapSize) pixmap.fill(Qt.transparent) painter = QPainter() painter.begin(pixmap) painter.setRenderHint(QPainter.Antialiasing, True) painter.setPen(color) brush = QBrush(color) painter.setBrush(brush) painter.drawEllipse(QRect(self.pixmapSize.width()/2 - self.brushSize/2, self.pixmapSize.height()/2 - self.brushSize/2, self.brushSize, self.brushSize)) painter.end() self.setIcon(QIcon(pixmap)) self.setTextAlignment(Qt.AlignVCenter)
def __init__(self, parent, _name, path): QTreeWidgetItem.__init__(self, parent) self._parent = parent self.setText(0, _name) self.path = path self.isFolder = True self.setForeground(0, QBrush(Qt.darkGray)) project = json_manager.read_ninja_project(path) self.name = project.get('name', '') if self.name == '': self.name = _name self.setText(0, self.name) self.projectType = project.get('project-type', '') self.description = project.get('description', '') self.url = project.get('url', '') self.license = project.get('license', '') self.mainFile = project.get('mainFile', '') self.extensions = project.get('supported-extensions', settings.SUPPORTED_EXTENSIONS) self.pythonPath = project.get('pythonPath', settings.PYTHON_PATH) self.programParams = project.get('programParams', '') self.venv = project.get('venv', '') self.addedToConsole = False
def hexagon_mask(image, hexa=False, **kwargs): """ Appliquer un découpage du masque de l'image en hexagone arrondi :param image: image PIL :param hexa: False ou le rayon des arrondis de l'hexagone en pixels :return: Une image PIL dont le contour est un haxagone aux angles arrondis ou l'image originale """ if hexa is not False: try: qimage = _pil_to_qt(image) # Créer une image de la même taille que l'originale newimage = _qt_canvas(image) painter = QPainter(newimage) painter.setRenderHint(QPainter.Antialiasing, True) # Dessiner un hexagone offset = hexa * 2.0 width, height, bottom, top, t, l = qimage.width( ) - offset * 2, qimage.height( ) - offset * 2, 0.759, 0.241, offset, offset points = [ l + width / 2.0, t + 0, l + width, t + height * top, l + width, t + height * bottom, l + width / 2.0, t + height, l + 0, t + height * bottom, l + 0, t + height * top ] brush = QBrush(qimage) pen = QPen(brush, offset * 2.0, cap=Qt.RoundCap, join=Qt.RoundJoin) pen.setColor(QColor(0, 0, 0, 0)) painter.setBrush(brush) painter.setPen(pen) painter.drawPolygon(QPolygon(points)) painter.end() return _qt_to_pil(newimage) except Exception: return image else: return image
def paint(self, painter, option, widget): painter.save() dirtyColor = QColor(255, 0, 0) painter.setOpacity(0.5) painter.setBrush(QBrush(dirtyColor, Qt.SolidPattern)) painter.setPen(dirtyColor) intersected = self._tiling.intersected(option.exposedRect) #print "pies are painting at ", option.exposedRect progress = 0.0 for i in intersected: progress += self._indicate[i] if not (self._indicate[i] < 1.0): # only paint for less than 100% progress continue # Don't show unless a delay time has passed since the tile progress was reset. delta = datetime.datetime.now() - self._zeroProgressTimestamp[i] if delta < self.delay: t = QTimer.singleShot(int(delta.total_seconds() * 1000.0), self.update) continue p = self._tiling.tileRectFs[i] w, h = p.width(), p.height() r = min(w, h) rectangle = QRectF(p.center() - QPointF(r / 4, r / 4), QSizeF(r / 2, r / 2)) startAngle = 0 * 16 spanAngle = min(360 * 16, int((1.0 - self._indicate[i]) * 360.0) * 16) painter.drawPie(rectangle, startAngle, spanAngle) painter.restore()
def addRectIndependencePearson(self, rect, x, y, w, h, xAttr_xVal, yAttr_yVal, actual, sum, width): xAttr, xVal = xAttr_xVal yAttr, yVal = yAttr_yVal expected = float(xVal * yVal) / float(sum) pearson = (actual - expected) / sqrt(expected) if pearson > 0: # if there are more examples that we would expect under the null hypothesis intPearson = floor(pearson) pen = QPen(QColor(0, 0, 255), width) rect.setPen(pen) b = 255 r = g = 255 - intPearson * 20 r = g = max(r, 55) # elif pearson < 0: intPearson = ceil(pearson) pen = QPen(QColor(255, 0, 0), width) rect.setPen(pen) r = 255 b = g = 255 + intPearson * 20 b = g = max(b, 55) else: pen = QPen(QColor(255, 255, 255), width) r = g = b = 255 # white color = QColor(r, g, b) brush = QBrush(color) rect.setBrush(brush) if pearson > 0: pearson = min(pearson, 10) kvoc = 1 - 0.08 * pearson # if pearson in [0..10] --> kvoc in [1..0.2] else: pearson = max(pearson, -10) kvoc = 1 - 0.4 * pearson pen.setWidth(1) self.addLines(x, y, w, h, kvoc, pen)
def paint(self, painter, option, widget): x, y = 0, 0 + self.height - self.descent if self.vdebug: painter.save() painter.setPen(QPen(Qt.yellow, 1, Qt.DotLine)) painter.drawRect(self.boundingRect()) painter.restore() painter.save() painter.setPen(QPen(Qt.NoPen)) for c in self.children(): painter.setBrush(c.brush) painter.drawRect(c.boundingRect()) painter.restore() painter.save() for tok in self.tokens: if isinstance(tok, (int, float)): x += tok elif isinstance(tok, Word): painter.setFont(tok.font) if tok.highlight: painter.save() painter.setPen(QPen(Qt.NoPen)) painter.setBrush(QBrush(Qt.yellow)) painter.drawRect(x, 0, tok.width, tok.height) painter.restore() painter.setPen(QPen(tok.text_color)) if tok.valign is None: painter.drawText(x, y, tok.string) elif tok.valign == 'Sub': painter.drawText(x + 1, y + self.descent / 1.5, tok.string) elif tok.valign == 'Sup': painter.drawText(x + 1, y - 2. * self.descent, tok.string) x += tok.width else: painter.drawPixmap(x, 0, tok.pixmap()) x += tok.width painter.restore()
def __init__(self, parent): QPlainTextEdit.__init__(self, parent) self._parent = parent self.setReadOnly(True) self.maxValue = 0 self.actualValue = 0 #traceback pattern self.patLink = re.compile(r'(\s)*File "(.*?)", line \d.+') #formats self.plain_format = QTextCharFormat() self.plain_format.setForeground( QBrush( QColor( resources.CUSTOM_SCHEME.get( "editor-text", resources.COLOR_SCHEME["editor-text"])))) self.error_format = QTextCharFormat() self.error_format.setAnchor(True) self.error_format.setFontUnderline(True) self.error_format.setUnderlineStyle(QTextCharFormat.SingleUnderline) self.error_format.setUnderlineColor(Qt.red) self.error_format.setForeground(Qt.blue) self.error_format.setToolTip(self.tr("Click to show the source")) self.connect(self, SIGNAL("blockCountChanged(int)"), self._scroll_area) css = 'QPlainTextEdit {color: %s; background-color: %s;' \ 'selection-color: %s; selection-background-color: %s;}' \ % (resources.CUSTOM_SCHEME.get('editor-text', resources.COLOR_SCHEME['editor-text']), resources.CUSTOM_SCHEME.get('editor-background', resources.COLOR_SCHEME['editor-background']), resources.CUSTOM_SCHEME.get('editor-selection-color', resources.COLOR_SCHEME['editor-selection-color']), resources.CUSTOM_SCHEME.get('editor-selection-background', resources.COLOR_SCHEME['editor-selection-background'])) self.setStyleSheet(css)
def updateColor(self): """ Update the color on the sampleModel modify to fit to the actual view """ if not self.view.sampleTableView.selectedIndexes( ): #not self.acTree.selectedIndexes(): return idx = self.view.sampleTableView.selectedIndexes()[0] sample = self.model.sample(idx.data().toString(), fullNameEntry=False) if sample is None: self.view.showErrorMessage('Error', 'Please choose only one file...') return color = QColorDialog.getColor() if not color.isValid(): return sample.color = color.getRgbF()[:-1] #make the gradient color here to color = QColor.fromRgbF(*(sample.color + (1., ))) colorr = QColor.fromRgbF(*(sample.color + (.5, ))) gradient = QLinearGradient(-100, -100, 100, 100) gradient.setColorAt(0.7, colorr) gradient.setColorAt(1, color) #for m in (self.view.sampleModel, self.view.spectraModel, self.view.peakModel, # self.view.clusterModel):#self.view.chromaModel, for i in xrange(self.view.sampleModel.rowCount()): item = self.view.sampleModel.item(i, 0) if item.text() == sample.shortName(): item.setBackground(QBrush(gradient))
def setNameAndBrush(self, sigma, color=Qt.black): self.sigma = sigma self.setText(str(self.brushSize)) font = QFont() font.setPointSize(10) font.setBold(True) self.setFont(font) self.setForeground(color) pixmap = QPixmap(self.pixmapSize) pixmap.fill(Qt.transparent) painter = QPainter() painter.begin(pixmap) painter.setRenderHint(QPainter.Antialiasing, True) painter.setPen(color) brush = QBrush(color) painter.setBrush(brush) painter.drawEllipse( QRect(self.pixmapSize.width() / 2 - self.brushSize / 2, self.pixmapSize.height() / 2 - self.brushSize / 2, self.brushSize, self.brushSize)) painter.end() self.setIcon(QIcon(pixmap)) self.setTextAlignment(Qt.AlignVCenter)
def __call__(self, painter, imageid): if imageid == len(self.images): return head_size = self.head_size color = self.color line_width = self.line_width max_velocity = self.max_velocity img1 = self.image_list[imageid] img2 = self.image_list[imageid + 1] d1 = self.data[img1] d2 = self.data[img2] dt = d2.time - d1.time pen = QPen(color) pen.setWidthF(line_width) brush = QBrush(color) painter.setPen(pen) painter.setBrush(brush) for pt_id in d1: if pt_id in d2: p = d1[pt_id] if self.forward else d2[pt_id] v = (d2[pt_id] - d1[pt_id]) / dt * self.factor vl = length(v) if abs(vl / max_velocity) > 1e-3: self.drawArrow(painter, p, v, head_size)
def paint(self, painter, option, widget=None): painter.save() path = self.path() brush = QBrush(self.brush()) pen = QPen(self.pen()) if option.state & QStyle.State_Selected: pen.setColor(Qt.red) brush.setStyle(Qt.DiagCrossPattern) brush.setColor(QColor(40, 40, 40, 100)) elif option.state & QStyle.State_MouseOver: pen.setColor(Qt.blue) if option.state & QStyle.State_MouseOver: brush.setColor(QColor(100, 100, 100, 100)) if brush.style() == Qt.NoBrush: # Make sure the highlight is actually visible. brush.setStyle(Qt.SolidPattern) painter.setPen(pen) painter.setBrush(brush) painter.drawPath(path) painter.restore()
def __init__(o, parent, puzzle_client, mainwindow, *args): QGraphicsScene.__init__(o, parent, *args) o._input_tracker = InputTracker(o, accepts=sum(KEYS.values(), [])) o.setBackgroundBrush(QBrush(QColor("darkGray"))) o.client = puzzle_client o.mainwindow = mainwindow o.cluster_map = {} # connect my events o.client.puzzle.connect(o._display_puzzle) o.client.piece_pixmaps.connect(o._set_piece_pixmaps) o.client.clusters.connect(o.OnClustersChanged) o.client.grabbed.connect(o.onClustersGrabbed) o.client.moved.connect(o.onClustersMoved) o.client.dropped.connect(o.onClustersDropped) o.client.joined.connect(o.onClustersJoined) # request puzzle data from server o.client.get_puzzle() # init piece movement o.rotations = 1 # number of rotations that the puzzle allows # List of cluster (widgets) that have been grabbed locally. dict clusterid -> ClusterWidget o.grabbed_widgets = {} # number of rotations (relative to initial rotation) having been applied to the grabbed widgets. o._move_rotation = 0 # time of last position update (for rate limit) o._last_move_send_time = 0 # init selection o._drag_start = None o._rubberband = QGraphicsRectItem(QRectF(0., 0., 100., 100.)) p = QPen(QColor(255, 255, 255)) o._rubberband.setPen(p) o._rubberband.hide() o.addItem(o._rubberband)
def paint(self, painter, option, widget): dirtyColor = QColor(255,0,0) painter.setOpacity(0.5) painter.save() painter.setBrush(QBrush(dirtyColor, Qt.SolidPattern)) painter.setPen(dirtyColor) for i,p in enumerate(self._tiling.tileRectFs): if self._indicate[i] == 1.0: continue # Don't show unless 1000 millisecs have passed since the tile progress was reset. startTime = self._zeroProgressTimestamp[i] if startTime is not None and datetime.datetime.now() - startTime < datetime.timedelta(milliseconds=1000): continue w,h = p.width(), p.height() r = min(w,h) rectangle = QRectF(p.center()-QPointF(r/4,r/4), QSizeF(r/2, r/2)); startAngle = 0 * 16 spanAngle = min(360*16, int((1.0-self._indicate[i])*360.0) * 16) painter.drawPie(rectangle, startAngle, spanAngle) painter.restore()
def __init__(self, parent=None, text=None, EditorHighlighterClass=PythonHighlighter, indenter=PythonCodeIndenter): QPlainTextEdit.__init__(self, parent) self.setFrameStyle(QFrame.NoFrame) self.setTabStopWidth(4) self.setLineWrapMode(QPlainTextEdit.NoWrap) font = QFont() font.setFamily("lucidasanstypewriter") font.setFixedPitch(True) font.setPointSize(10) self.setFont(font) self.highlighter = EditorHighlighterClass(self) if text: self.setPlainText(text) self.frame_style = self.frameStyle() self.draw_line = True self.print_width = self.fontMetrics().width("x" * 78) self.line_pen = QPen(QColor("lightgrey")) self.last_row = self.last_col = -1 self.last_block = None self.highlight_line = True self.highlight_color = self.palette().highlight().color().light(175) self.highlight_brush = QBrush(QColor(self.highlight_color)) self.connect(self, SIGNAL("cursorPositionChanged()"), self.onCursorPositionChanged) self.indenter = indenter(RopeEditorWrapper(self)) # True if you want to catch Emacs keys in actions self.disable_shortcuts = False self.prj = get_no_project() self.prj.root = None self.calltip = CallTip(self) self.autocomplete = AutoComplete(self)
def paint(self, painter, option, widget=None): crop_extents_3d = self._crop_extents_model.crop_extents() crop_extents = copy.deepcopy(crop_extents_3d) crop_extents.pop(self._parent.axis) width, height = self._parent.dataShape (left, right), (top, bottom) = crop_extents if None in (left, right, top, bottom, width, height): # Don't paint if the crop settings aren't initialized yet. return # Black brush, 50% alpha brush = QBrush(QColor(0, 0, 0, 128)) rects = [ (0.0, 0.0, left, top), (0.0, top, left, bottom), (0.0, bottom, left, height), (left, 0.0, right, top), #(left, top, right, bottom), # Don't cover the middle. (left, bottom, right, height), (right, 0.0, width, top), (right, top, width, bottom), (right, bottom, width, height) ] with painter_context(painter): t = painter.transform() painter.setTransform(self.scene().data2scene * t) for rect_points in rects: x1, y1, x2, y2 = rect_points p1 = QPointF(x1, y1) p2 = QPointF(x2, y2) painter.fillRect(QRectF(p1, p2), brush)
def paintEvent(self, event): if self._isRunning: anglestep = 360. / self._steps fillsteps = self._fillsteps factor = min(self.width(), self.height()) / 16. bw = self._bw p = QPainter(self) p.setRenderHint(QPainter.Antialiasing, True) p.scale(factor, factor) p.setPen(Qt.NoPen) for i in range(self._steps): x1, y1 = self._coords[i] c = fillsteps[self._steps - 1 - i] a = anglestep * i p.setBrush(QBrush(QColor.fromRgbF(bw, bw, bw, c))) p.save() p.translate(x1 - 2, y1 - 1) p.translate(2, 1) p.rotate(a) p.translate(-2, -1) p.drawPath(self._path) p.restore()
def initUI(self): # create a class object self.setStyleSheet('QPushButton {font-family: cursive, sans-serif; font-weight: 300; font-size: 14px; color: #CD853F; }') self.montage = Montages() # create buttons createPath = QPushButton(self) createPath.setText("Choose the directory of your photos") createPath.clicked.connect(self.cPath) savePath = QPushButton(self) savePath.setText("Choose the directory to save your plot") savePath.clicked.connect(self.sPath) create = QPushButton(self) create.setText("Create plot") create.clicked.connect(self.createPlot) # set layout sbox = QGridLayout(self) sbox.addWidget(createPath, 1, 0) sbox.addWidget(savePath, 2, 0) sbox.addWidget(create, 3, 1) self.setLayout(sbox) # set background as transparent palette = QPalette() palette.setBrush(QPalette.Background,QBrush(QPixmap())) self.setPalette(palette)