def paintEvent(self, event): painter = QtGui.QPainter(self) width = self.width() height = self.height() top, bottom = height * .1, height * .8 left, right = width * .1, width * .8 rect = QtCore.QRect(left, top, right, bottom) painter.fillRect(rect, QtGui.QColor('black')) #painter.setWindow(rect) dist = bottom - top relval = self.threshold.signal.buffer[-1] / self.MAX relval = min(1.0, relval) reltop = (1.0 - relval) * bottom + top relbottom = height * 0.9 - reltop rect = QtCore.QRect(left, reltop, right, relbottom) color = QtGui.QColor( 'green' if self.threshold.passfail.buffer[-1] else 'red') painter.fillRect(rect, color) thr_height = self.threshold.threshold / self.MAX thr_top = (1.0 - thr_height) * bottom + top rect = QtCore.QRect(left, thr_top, right, 2) painter.fillRect(rect, QtGui.QColor('white'))
def __init__(self, parent=None, language='Python'): super(Editor, self).__init__(parent) self.setIndentationsUseTabs(False) self.setIndentationWidth(4) # Set the default font font = QtGui.QFont() font.setFamily('DejaVu Sans Mono') font.setFixedPitch(True) font.setPointSize(10) self.setFont(font) self.setMarginsFont(font) self.zoomIn() # Margin 0 is used for line numbers fontmetrics = QtGui.QFontMetrics(font) self.setMarginsFont(font) self.setMarginWidth(0, fontmetrics.width("000") + 6) self.setMarginLineNumbers(0, True) self.setMarginsBackgroundColor(QtGui.QColor("#cccccc")) self._marker = None # Clickable margin 1 for showing markers #self.setMarginSensitivity(1, True) #self.connect(self, # SIGNAL('marginClicked(int, int, Qt::KeyboardModifiers)'), # self.on_margin_clicked) self.markerDefine(QsciScintilla.RightArrow, self.ARROW_MARKER_NUM) self.setMarkerBackgroundColor(QtGui.QColor("#ee1111"), self.ARROW_MARKER_NUM) # Brace matching: enable for a brace immediately before or after # the current position # self.setBraceMatching(QsciScintilla.SloppyBraceMatch) # Current line visible with special background color self.setCaretLineVisible(True) self.setCaretLineBackgroundColor(QtGui.QColor("#ffe4e4")) # Set Python lexer # Set style for Python comments (style number 1) to a fixed-width # courier. # lexer = getattr(Qsci, 'QsciLexer' + language)() lexer.setDefaultFont(font) self.setLexer(lexer) self.SendScintilla(QsciScintilla.SCI_STYLESETFONT, 1, b'Courier') # Don't want to see the horizontal scrollbar at all # Use raw message to Scintilla here (all messages are documented # here: http://www.scintilla.org/ScintillaDoc.html) self.SendScintilla(QsciScintilla.SCI_SETHSCROLLBAR, 0) self.setWrapMode(QsciScintilla.WrapWord) self.setEolMode(QsciScintilla.EolUnix)
def plot_data(self, *args): #ipdb.set_trace() color_pts = self.colormap.map(args[0][1]) brush = [QtGui.QBrush(QtGui.QColor(*color_pts))] self.scatter.addPoints(x=[args[0][0][0]], y=[args[0][0][1]], brush=brush)
def channels_changed(self, object, name, old, new): for channel in old: del self.plots[channel] for channel in new: plot = self._plot_widget.plot() plot.setPen(QtGui.QColor(channel.color)) self.plots[channel] = plot
def plot_data(self, *args): #ipdb.set_trace() color_pts = self.colormap.map(args[0][1][0]) brush = QtGui.QBrush(QtGui.QColor(*color_pts)) self.brushes[args[0][1][1] % self.n_points] = brush self.pos[args[0][1][1] % self.n_points, 0] = args[0][0][0] self.pos[args[0][1][1] % self.n_points, 1] = args[0][0][1] #self.scatter.addPoints(x=self.x_pos, y=self.y_pos, brush=self.brushes) self.scatter.setData(pos=self.pos, brush=self.brushes)
def chart(self, chart: 'ChartPlotWidget') -> None: # noqa self._chart = chart chart.sigRangeChanged.connect(self.update_on_resize) palette = self._label.palette() # TODO: get bg color working palette.setColor( self._label.backgroundRole(), # QtGui.QColor(chart.backgroundBrush()), QtGui.QColor(hcolor('papas_special')), )
def data(self, index, role=Qt.DisplayRole): if not index.isValid(): return row, col = index.row(), index.column() columns, multiColumns = self.window.activeColumns() colName, subCol = getColumnNameAndSub(columns, multiColumns, col) ret = None stats = self.window.sortedMarkets[row] numVal, strVal = getStatsValue(stats, colName, subCol) if role == Qt.DisplayRole: ret = strVal #elif role == Qt.ForegroundRole: elif role == Qt.BackgroundRole: if colName == 'upTrend': ret = QtGui.QColor([QtCore.Qt.red, QtCore.Qt.cyan][stats.upTrend[subCol]]) elif colName == 'stepsSinceSqueeze': if strVal == 'Squeeze': ret = QtGui.QColor(QtCore.Qt.red) elif 'Fired' in strVal: ret = QtGui.QColor(QtCore.Qt.cyan) return QtCore.QVariant(ret)
def data(self, index, role=QtCore.Qt.DisplayRole): if index.isValid(): if role == QtCore.Qt.DisplayRole: return str(self._data.values[index.row()][index.column()]) if role == QtCore.Qt.BackgroundRole: # return self._data.Color[index.row()] return QtGui.QColor(QtCore.Qt.white) if role == QtCore.Qt.ForegroundRole: pass # return self._data.Color[index.row()] return None
def restoreSettings(self, group, settings): self.settingsDialog.scaleSpinBox.setValue( float(settings.value(group + '/' + 'Scale', '0.1'))) self.settingsDialog.sbLengthSpinBox.setValue( int(settings.value(group + '/' + 'Length', '5'))) self.settingsDialog.sbXSpinBox.setValue( float(settings.value(group + '/' + 'X', '0.80'))) self.settingsDialog.sbYSpinBox.setValue( float(settings.value(group + '/' + 'Y', '0.90'))) self.settingsDialog.sbLabelYOffsetSpinBox.setValue( float(settings.value(group + '/' + 'LabelYOffset', '0.05'))) self.sbColor = QtGui.QColor( settings.value(group + '/' + 'Color', '#ffffff')) self.settingsDialog.sbColorPreview.setStyleSheet( "background-color: %s" % self.sbColor.name())
def __init__(self, parent = None): super(AppWindow, self).__init__(parent = parent) self.showMaximized() p = self.palette() p.setColor(self.backgroundRole(), QtGui.QColor('white')) self.setPalette(p) self.layout = QtGui.QHBoxLayout(self) self.demoWindow = DemoWindow(self) self.lineDiagram = LineDiagram(self) self.layout.addWidget(self.demoWindow) self.layout.addWidget(self.lineDiagram)
def __init__( self, viewbox: ViewBox, color: str = 'dad_blue', ) -> None: super().__init__(0, 0, 1, 1) # self.rbScaleBox = QtGui.QGraphicsRectItem(0, 0, 1, 1) self.vb = viewbox self._chart: 'ChartPlotWidget' = None # noqa # override selection box color color = QtGui.QColor(hcolor(color)) self.setPen(fn.mkPen(color, width=1)) color.setAlpha(66) self.setBrush(fn.mkBrush(color)) self.setZValue(1e9) self.hide() self._label = None label = self._label = QtGui.QLabel() label.setTextFormat(0) # markdown label.setFont(_font.font) label.setMargin(0) label.setAlignment( QtCore.Qt.AlignLeft # | QtCore.Qt.AlignVCenter ) # proxy is created after containing scene is initialized self._label_proxy = None self._abs_top_right = None # TODO: "swing %" might be handy here (data's max/min # % change) self._contents = [ 'change: {pchng:.2f} %', 'range: {rng:.2f}', 'bars: {nbars}', 'max: {dmx}', 'min: {dmn}', # 'time: {nbars}m', # TODO: compute this per bar size 'sigma: {std:.2f}', ]
def init(self, name, input): self.FS = 250 self.name = name epoch_samples = int(self.FS * self.epoch) self.signal = Signal(buffer_size=epoch_samples) self.passfail = Signal() self.ratio = Signal() self.threshold = 1.0 self.high_threshold = 0.0 self.calc_cnt = 0 self.bar = QtGui.QProgressBar(orientation=QtCore.Qt.Vertical) self.slider = QtGui.QSlider() self.slider.setRange(0, 17) self.bar.setRange(0, 17) self.pass_palette = self.bar.palette() self.input = input if isinstance(self.input.color, QtGui.QColor): self.color = self.input.color else: self.color = QtGui.QColor(self.input.color) self.bar.setStyleSheet(""" QProgressBar::chunk { background: red; } QProgressBar::chunk[pass='******'] { background: %s ; } """ % self.color.name()) self.button = QtGui.QPushButton("config") self.button.clicked.connect(self.configure_traits) self._widget = ThresholdWidget(self)
def __init__(self): self.settingsDialog = ScaleBarDialog() self.bar = QtGui.QGraphicsRectItem() self.label = QtGui.QGraphicsSimpleTextItem() self.dimx = 100 self.dimy = 100 self.sbColor = QtGui.QColor('#ffffff') self.settingsDialog.sbColorPreview.setStyleSheet( 'background-color: #ffffff') self.settingsDialog.scaleSpinBox.valueChanged.connect(self.render) self.settingsDialog.sbAutoButton.clicked.connect(self.setAuto) self.settingsDialog.sbLengthSpinBox.valueChanged.connect(self.render) self.settingsDialog.sbXSpinBox.valueChanged.connect(self.render) self.settingsDialog.sbYSpinBox.valueChanged.connect(self.render) self.settingsDialog.sbLabelYOffsetSpinBox.valueChanged.connect( self.render) self.settingsDialog.sbColorButton.clicked.connect(self.openColorDialog) self.settingsDialog.sbHeightSpinBox.valueChanged.connect(self.render) self.settingsDialog.okButton.clicked.connect(self.settingsDialog.close)
def __init__(self, *args, **kwargs): super(map_sim, self).__init__() self.n_points = 100 #with 1500 could see the whole orbit self.counter = 0 self.pos = np.random.random([self.n_points, 2]) + 20 values = np.zeros(self.n_points) ##This is simulation orbit undersamp = 5 self.x_pos = np.loadtxt('x_val')[::undersamp] self.y_pos = np.loadtxt('y_val')[::undersamp] ## self.win = pg.GraphicsWindow() self.win.setWindowTitle('scatt anim') self.win.show() p = self.win.addPlot() p.disableAutoRange() p.setRange(xRange=[-10, 10], yRange=[-10, 10]) p.showGrid(x=True, y=True) self.scatter = pg.ScatterPlotItem() p.addItem(self.scatter) self.colormap = self.mapping_init(0, 100) aux = self.colormap.map(values) self.brushes = [ QtGui.QBrush(QtGui.QColor(*aux[i, :].tolist())) for i in range(aux.shape[0]) ] #ipdb.set_trace() #self.values = [QtGui.QBrush(QtGui.QColor(*aux))] self.threadpool = QtCore.QThreadPool(parent=self.win) self.threadpool.setMaxThreadCount(1) self.update()
def get_data(self): [x,y] = get_pos() ###simular!! [A, B, re, im] = get_vals() #ver como importarlo.. pow_diff = 10*(np.log10(A+1)-np.log10(B+1)) ang_diff = np.rad2deg(np.arctan2(im, re)) return [[x,y], [pow_diff, ang_diff]] def process_data(self, *args) color_ang = self.color_ang.map(args[1][1]) brush_ang = [QtGui.QBrush(QtGui.QColor(*color_ang))] self.ang.addPoints(x=[args[0][0]], y=[args[0][1]], brush=brush_ang) color_pow = self.color_pow.map(args[1][0]) brush_pow = [QtGui.QBrush(QtGui.QColor(*color_pow))] self.pow.addPoints(x=[args[0][0]], y=[args[0][1]], brush=brush_pow) ################################## """ Para correrlo falta hacer
def setData(self, *args): """ Set the data to be drawn. Parameters ---------- x, y : np.ndarray, optional, default None 2D array containing the coordinates of the polygons z : np.ndarray 2D array containing the value which will be maped into the polygons colors. If x and y is None, the polygons will be displaced on a grid otherwise x and y will be used as polygons vertices coordinates as:: (x[i+1, j], y[i+1, j]) (x[i+1, j+1], y[i+1, j+1]) +---------+ | z[i, j] | +---------+ (x[i, j], y[i, j]) (x[i, j+1], y[i, j+1]) "ASCII from: <https://matplotlib.org/3.2.1/api/_as_gen/ matplotlib.pyplot.pcolormesh.html>". """ # Prepare data cd = self._prepareData(args) # Has the view bounds changed shapeChanged = False if self.qpicture is None: shapeChanged = True elif len(args) == 1: if args[0].shape[0] != self.x[:, 1][-1] or args[0].shape[ 1] != self.y[0][-1]: shapeChanged = True elif len(args) == 3: if np.any(self.x != args[0]) or np.any(self.y != args[1]): shapeChanged = True self.qpicture = QtGui.QPicture() p = QtGui.QPainter(self.qpicture) # We set the pen of all polygons once if self.edgecolors is None: p.setPen(fn.mkPen(QtGui.QColor(0, 0, 0, 0))) else: p.setPen(fn.mkPen(self.edgecolors)) if self.antialiasing: p.setRenderHint(QtGui.QPainter.RenderHint.Antialiasing) ## Prepare colormap # First we get the LookupTable pos = [i[0] for i in Gradients[self.cmap]['ticks']] color = [i[1] for i in Gradients[self.cmap]['ticks']] cmap = ColorMap(pos, color) lut = cmap.getLookupTable(0.0, 1.0, 256) # Second we associate each z value, that we normalize, to the lut vmin, vmax = self.z.min(), self.z.max() if self.levels is not None: vmin, vmax = self.levels vmin = max(vmin, self.z.min()) vmax = min(vmax, self.z.max()) norm = self.z - vmin norm_max = vmax - vmin norm = norm / norm_max norm = (norm * (len(lut) - 1)).astype(int) norm[norm < 0] = 0 norm[norm > 255] = 255 # Go through all the data and draw the polygons accordingly for xi in range(self.z.shape[0]): for yi in range(self.z.shape[1]): # Set the color of the polygon first c = lut[norm[xi][yi]] p.setBrush(fn.mkBrush(QtGui.QColor(c[0], c[1], c[2]))) polygon = QtGui.QPolygonF([ QtCore.QPointF(self.x[xi][yi], self.y[xi][yi]), QtCore.QPointF(self.x[xi + 1][yi], self.y[xi + 1][yi]), QtCore.QPointF(self.x[xi + 1][yi + 1], self.y[xi + 1][yi + 1]), QtCore.QPointF(self.x[xi][yi + 1], self.y[xi][yi + 1]) ]) # DrawConvexPlygon is faster p.drawConvexPolygon(polygon) p.end() self.update() self.prepareGeometryChange() if shapeChanged: self.informViewBoundsChanged()
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. # # # Code: """Read data distributed in a directory structure""" import os from pyqtgraph import (QtCore, QtGui) from pyqtgraph import parametertree as ptree bgBrush = QtGui.QBrush(QtGui.QColor('lightsteelblue')) class PathParams(ptree.parameterTypes.GroupParameter): def __init__(self, **opts): opts['type'] = 'group' opts['addText'] = "Add rule" opts['addList'] = ['timestamp', 'regex', 'string'] super(PathParams, self).__init__(**opts) def addNew(self, typ): val = { 'timestamp': 'YYYY-mm-dd HH:MM:SS', 'regex': '.*', 'string': '_' }[typ]