def setupGUI(self): self.setWindowTitle("Edit Gradients") self.setGeometry(500, 300, 400, 200) self.layout = QtGui.QVBoxLayout() self.setLayout(self.layout) self.layout.setContentsMargins(0, 0, 0, 0) self.tree = pg.TreeWidget() self.layout.addWidget(self.tree) self.tree.setHeaderHidden(True) self.tree.setDragEnabled(False) self.tree.setIndentation(10) self.tree.setColumnCount(3) self.sItem = pg.TreeWidgetItem(['Original Sonic Data']) self.fItem = pg.TreeWidgetItem(['Fourrier Transform']) self.pItem = pg.TreeWidgetItem(['Fourrier Phases']) self.tree.addTopLevelItem(self.sItem) self.tree.addTopLevelItem(self.fItem) self.tree.addTopLevelItem(self.pItem) self.sgw = pg.GradientWidget(orientation='top') self.fgw = pg.GradientWidget(orientation='top') self.pgw = pg.GradientWidget(orientation='top') self.sItem.setWidget(2, self.sgw) self.fItem.setWidget(2, self.fgw) self.pItem.setWidget(2, self.pgw) self.tree.setColumnWidth(0, 150) #### widget of ok and Cancel buttons self.buttonsWidget = QtGui.QWidget() self.buttonLayout = QtGui.QHBoxLayout() self.buttonsWidget.setLayout(self.buttonLayout) self.okButton = QtGui.QPushButton("OK") self.cancelButton = QtGui.QPushButton("Cancel") self.buttonLayout.addWidget(self.okButton) self.buttonLayout.addWidget(self.cancelButton) self.buttonLayout.setContentsMargins(0, 0, 0, 5) self.layout.addWidget(self.buttonsWidget)
def __init__(self, parent): super(GradientEditor, self).__init__(parent.mainwindow) self.ui = Ui_GradientEditor() self.ui.setupUi(self) self.ui.pushButtonOk.clicked.connect(self.on_ok) self.pos_editor = pg.GradientWidget() self.ui.gridLayout.addWidget(self.pos_editor, 0, 1) self.neg_editor = pg.GradientWidget() self.ui.gridLayout.addWidget(self.neg_editor, 1, 1)
def importGradients(self, name, controls, colors, sqrt=False, editable=False): # Import a gradient into either the internal or custom gradient lists try: # FIXME: GradientWidget can accept 'allowAdd' flag for whether or # not a widget is editable newWidget = pg.GradientWidget() newWidget.hide() for tick in newWidget.listTicks(): newWidget.removeTick(tick[0]) if not isinstance(controls, (tuple, list)): # convert numpy arrays to a list so we can JSON serialize # numpy data types controls = controls.tolist() for control, color in zip(controls, colors): newWidget.addTick(control, QtGui.QColor(*(color * 255.)), movable=editable) if editable: self.user_colormap_states[name] = newWidget.saveState() self.user_colormap_states[name]["sqrt"] = sqrt else: self.builtin_colormap_states[name] = newWidget.saveState() self.updateListWidget() except AssertionError as e: LOG.error(e)
def __init__(self, parent=None): QtWidgets.QWidget.__init__(self, parent) # Inherit from QWidget self.vbl = QtWidgets.QVBoxLayout() self.w = pg.GradientWidget() self.w.loadPreset('magma') #Magma colormap set as default self.vbl.addWidget(self.w) self.setLayout(self.vbl) self.w.sigGradientChanged.connect( self.sigGradientChanged ) # If GradientWidget is changed this will receive a Signal
def __init__(self, layer): super(GrayScaleLayerCtrl, self).__init__(layer=layer) self.gradientWidget = pg.GradientWidget() d = { 'ticks': [(0.0, (165, 0, 60, 255)), (1.0, (0, 170, 60, 255))], 'mode': 'rgb' } d = pg.graphicsItems.GradientEditorItem.Gradients['grey'] self.gradientWidget.restoreState(d) self.setupUI() self.connectSignals()
def __init__(self, parent=None, background='default', decay_timing = DECAY_WITH_DATA, decay_fn = decay_fn_LINEAR, decay_args = [10, ], #10 arrays until 0.5 decay (20 for full) data_model = None, #a WaterfallModel (for now) **kargs): self._init_complete = False #base class init below triggers a lot pg.PlotWidget.__init__(self, parent, background, **kargs) #grab the rgb of the background color for palette matching later... self._bg_color = self.backgroundBrush().color().toTuple()[:3] self.setMenuEnabled(False) self.plotItem.getViewBox().setMouseEnabled(x = False, y = False) if decay_timing not in ALL_DECAY_TIMING: raise ValueError("Unsupported decay timing: %s" % decay_timing) self._decay_timing = decay_timing self._decay_fn = decay_fn self._decay_args = decay_args self._data_model = data_model self._persistent_img = None #the persistent image self._img_array = None #the persistent data (same shape as image) #The value of self._prev_t doesn't matter for the first round since the #first plot has nothing to decay... self._prev_t = 0 #We will always have a gradient editor for providing our LUT, but it #may not be visible. It can be referenced for layout, though... just grab #it after initializing the PersistencePlotWidget. self.gradient_editor = pg.GradientWidget(parent = self, orientation = "left") self.gradient_editor.setStyleSheet('background-color: black') self.gradient_editor.loadPreset("rycb") #we injected this scheme self.gradient_editor.sigGradientChanged.connect(self._onGradientChange) self._LUT_PTS = 256 self._latest_lut = self._get_lut() if self._data_model: assert isinstance(data_model, WaterfallModel) try: self._data_model.sigNewDataRow.connect(self.onNewModelData) except AttributeError: raise ValueError("data_model must be a WaterfallModel") #for now self._reset_requested = False self._init_complete = True
def __init__(self, parent=None, name=""): QtGui.QWidget.__init__(self, parent) self.speed_textbox = speed_box(self) groupbox = QtGui.QGroupBox(self) grid = QtGui.QVBoxLayout(self) self.gradient = pg.GradientWidget(orientation='left') self.gradient.setColorMode('rgb') grid.addWidget(self.gradient) grid.addWidget(self.speed_textbox) groupbox.setLayout(grid) groupbox.setTitle(name) outergrid = QtGui.QStackedLayout(self) outergrid.addWidget(groupbox) self.setLayout(outergrid)
def __init__(self): super(view_manager3D, self).__init__() self._view = viewport3D() # Define some color collections: self._cmap = pg.GradientWidget(orientation='right') self._cmap.restoreState(colorMap) self._cmap.sigGradientChanged.connect(self.gradientChangeFinished) # self._cmap.sigGradientChangeFinished.connect(self.gradientChangeFinished) self._cmap.resize(1, 1) self._lookupTable = self._cmap.getLookupTable(255, alpha=0.75) # These boxes control the levels. self._upperLevel = QtGui.QLineEdit() self._lowerLevel = QtGui.QLineEdit() self._upperLevel.returnPressed.connect(self.colorsChanged) self._lowerLevel.returnPressed.connect(self.colorsChanged) self._lowerLevel.setText(str(0.0)) self._upperLevel.setText(str(2.0)) # Fix the maximum width of the widgets: self._upperLevel.setMaximumWidth(35) self._cmap.setMaximumWidth(25) self._lowerLevel.setMaximumWidth(35) self._layout = QtGui.QHBoxLayout() self._layout.addWidget(self._view) colors = QtGui.QVBoxLayout() colors.addWidget(self._upperLevel) colors.addWidget(self._cmap) colors.addWidget(self._lowerLevel) self._layout.addLayout(colors)
def setupUi(self): main_vbox = QtGui.QVBoxLayout() self.setLayout(main_vbox) buttons_hbox = QtGui.QHBoxLayout() self.open_pick_button = QtGui.QPushButton('Open Picks') openPick = functools.partial(self.open_pick_file) self.open_pick_button.released.connect(openPick) buttons_hbox.addWidget(self.open_pick_button) self.open_cat_button = QtGui.QPushButton('Open Catalogue') openCat = functools.partial(self.open_cat_file) self.open_cat_button.released.connect(openCat) self.open_cat_button.setEnabled(False) buttons_hbox.addWidget(self.open_cat_button) self.open_ref_xml_button = QtGui.QPushButton('Open Ref StationXML') openRefXml = functools.partial(self.open_ref_xml_file) self.open_ref_xml_button.released.connect(openRefXml) self.open_ref_xml_button.setEnabled(False) buttons_hbox.addWidget(self.open_ref_xml_button) self.open_xml_button = QtGui.QPushButton('Open StationXML') openXml = functools.partial(self.open_xml_file) self.open_xml_button.released.connect(openXml) self.open_xml_button.setEnabled(False) buttons_hbox.addWidget(self.open_xml_button) self.sort_drop_down_button = QtGui.QPushButton('Sort') self.sort_drop_down_button.setEnabled(False) buttons_hbox.addWidget(self.sort_drop_down_button) # Button for plotting for single station self.plot_single_stn_button = QtGui.QPushButton('Plot Single Stn') self.plot_single_stn_button.setEnabled(False) buttons_hbox.addWidget(self.plot_single_stn_button) # button to display waveforms for station or event self.display_waveforms_button = QtGui.QPushButton('Display Waveforms') self.display_waveforms_button.setEnabled(False) buttons_hbox.addWidget(self.display_waveforms_button) # Button to Bring all events together onto a closer X axis self.gather_events_checkbox = QtGui.QCheckBox('Gather Events') Gather = functools.partial(self.gather_events_checkbox_selected) self.gather_events_checkbox.stateChanged.connect(Gather) self.gather_events_checkbox.setEnabled(False) buttons_hbox.addWidget(self.gather_events_checkbox) main_vbox.addLayout(buttons_hbox) centre_hbox = QtGui.QHBoxLayout() left_grid_lay = QtGui.QGridLayout() self.p_graph_view = pg.GraphicsLayoutWidget() # self.single_stn_p_graph_view = pg.GraphicsLayoutWidget() left_grid_lay.addWidget(self.p_graph_view, 0, 0, 3, 6) self.col_grad_w = pg.GradientWidget(orientation='bottom') self.col_grad_w.loadPreset('spectrum') self.col_grad_w.setEnabled(False) self.col_grad_w.setToolTip(""" - Click a triangle to change its color - Drag triangles to move - Click in an empty area to add a new color - Right click a triangle to remove """) self.max_lb = QtGui.QLabel("Max") self.min_lb = QtGui.QLabel("Min") self.reset_view_tool_button = QtGui.QPushButton() self.reset_view_tool_button.setIcon(QtGui.QIcon('eLsS8.png')) self.reset_view_tool_button.released.connect(self.reset_plot_view) self.reset_view_tool_button.setToolTip( "Reset the scatter plot zoom and sort method") left_grid_lay.addWidget(self.col_grad_w, 4, 1, 1, 2) left_grid_lay.addWidget(self.min_lb, 4, 0, 1, 1) left_grid_lay.addWidget(self.max_lb, 4, 4, 1, 1) left_grid_lay.addWidget(self.reset_view_tool_button, 4, 5, 1, 1) centre_hbox.addLayout(left_grid_lay) # Open StreetMAP view map_view = self.map_view = QtWebKit.QWebView() cache = QtNetwork.QNetworkDiskCache() cache.setCacheDirectory("cache") map_view.page().networkAccessManager().setCache(cache) map_view.page().networkAccessManager() map_view.page().mainFrame().addToJavaScriptWindowObject( "MainWindow", self) map_view.page().setLinkDelegationPolicy( QtWebKit.QWebPage.DelegateAllLinks) map_view.load(QtCore.QUrl('map.html')) map_view.loadFinished.connect(self.onLoadFinished) map_view.linkClicked.connect(QtGui.QDesktopServices.openUrl) centre_hbox.addWidget(map_view) main_vbox.addLayout(centre_hbox)
def __init__(self): # have EEGmodule inherit attributes of QGroupBox pg.setConfigOptions(antialias=True) super(QGroupBox, self).__init__() # set title of EEGmodule # self.setTitle("EEG Module") # create layout for EEG Module self.layout = QGridLayout() # set layout for module self.setLayout(self.layout) # Creating graphs self.alphaGraph = EEG_Graph_Submodule() self.alphaGraph.setGraphTitle( '<span style="color:white;font-size:20px">Alpha Band (8-12Hz)</span>' ) self.alphaBand = -3 self.alphaG = self.alphaGraph.plotWidgetMain ###################################### self.thetaGraph = EEG_Graph_Submodule() self.thetaGraph.setGraphTitle( '<span style="color:white;font-size:20px">Theta Band (4-7Hz)</span>' ) self.thetaBand = -2 self.thetaG = self.thetaGraph.plotWidgetMain ###################################### self.deltaGraph = EEG_Graph_Submodule() self.deltaGraph.setGraphTitle( '<span style="color:white;font-size:20px">Delta Band (0-4Hz)</span>' ) self.deltaG = self.deltaGraph.plotWidgetMain self.deltaBand = -1 ####################################### # checkbox for alphaGraph self.alphaBox = QCheckBox("Alpha Band", self) self.alphaBox.setStyleSheet("QCheckBox{color:white;}") self.alphaBox.setChecked(True) self.alphaBox.stateChanged.connect(lambda: self.hideGraph(button=self.alphaBox)) ################################################### self.thetaBox = QCheckBox("Theta Band", self) self.thetaBox.setStyleSheet("QCheckBox{color:white;}") self.thetaBox.setChecked(True) self.thetaBox.stateChanged.connect(lambda: self.hideGraph(button=self.thetaBox)) self.thetaBox.move(100, 0) ################################################### self.deltaBox = QCheckBox("Delta Band", self) self.deltaBox.setStyleSheet("QCheckBox{color:white;}") self.deltaBox.setChecked(True) self.deltaBox.stateChanged.connect(lambda: self.hideGraph(button=self.deltaBox)) self.deltaBox.move(200, 0) ################################################### ####################################################### #add check boxes to layout self.layout.addWidget(self.alphaBox,1,4) self.layout.addWidget(self.deltaBox,1,0) self.layout.addWidget(self.thetaBox,1,2) # add graphs to widget self.layout.addWidget(self.deltaG, 2, 0, 1, 2) self.layout.addWidget(self.thetaG, 2, 2, 1, 2) self.layout.addWidget(self.alphaG, 2, 4, 1, 2) #self.layout.addWidget(CmapImage(), 3, 2, 1, 2) # = QLabel("Normalized Power") #label.setStyleSheet("QLabel{color:white; font:20px;}") #self.layout.addWidget(label, 3, 1, 1,1) fill = pg.PlotWidget() fill.getPlotItem().hideAxis("bottom") fill.getPlotItem().hideAxis("left") fill.setBackground(background=None) self.layout.addWidget(fill, 4,0,1,6) # get the node positions x, y, nodeList = EEGArray() # set cmap colormap = cm.get_cmap("jet") #getting colormap from matplotlib colormap._init() lut = (colormap._lut * 255).view(np.ndarray) #convert to numpy array ticks = [] colors = [] # pos = [] # mapColors = [] self.gradient = pg.GradientWidget(allowAdd=False) for i in range(len(lut)-3): #adding colors to a gradient r=int(lut[i][0]) g=int(lut[i][1]) b=int(lut[i][2]) a=255 ticks.append(i/255) colors.append((r,g,b,a)) # pos.append(i/255) # mapColors.append((r,g,b,a)) if i%15 == 0: self.gradient.addTick(x=ticks[i], color=QColor(r,g,b,a), movable=False) if i == 0: self.gradient.setTickColor(0,QColor(r,g,b,a)) elif i == 255: self.gradient.addTick(1,QColor(r,g,b,a)) #self.pgCM = pg.ColorMap(np.array(ticks), colors) self.pgCM = self.gradient.colorMap() # self.layout.addWidget(self.gradient, 3, 4, 1, 2) ########################################################################## #creating a groupbox for the gradient and labels self.gradientBox = gradientLayout(self.gradient) ##################################### self.layout.addWidget(self.gradientBox, 3,0,1,8) ########################################################################## self.n = 64 # initialize newdata self.newdata = np.zeros(self.n) # initialize 64 by 64 data array self.data = np.zeros((self.n, self.n)) # get global max for normalization self.aglobalMax = -(sys.maxsize) - 1 self.tglobalMax = -(sys.maxsize) - 1 self.dglobalMax = -(sys.maxsize) - 1 self.setLayout(self.layout) # Open StreamInlet streams = resolve_stream() self.inlet = StreamInlet(streams[0]) # create timer self.timer = QTimer(self) # # self.timer.setInterval(10000) self.timer.timeout.connect(self.UpdateNodes) self.timer.start(20)
def __init__(self, sim, useOpenGL=False, verbosity=None): self.app = QtGui.QApplication([]) QtGui.QMainWindow.__init__(self) self.ui = Ui_MainWindow() self.ui.setupUi(self) self.useOpenGL = useOpenGL self.ui.runButton.clicked.connect(self.run) self.ui.initButton.clicked.connect(self.init) self.ui.iMatButton.clicked.connect(self.iMat) self.ui.stopButton.clicked.connect(self.stop) self.ui.reloadParamsAction.triggered.connect(self.read) self.ui.loadParamsAction.triggered.connect(self.readParamFile) #Ensure update is called if sci button pressed self.ui.instExpRadio.clicked.connect(self.update) self.ui.longExpRadio.clicked.connect(self.update) #Initialise Colour chooser self.gradient = pyqtgraph.GradientWidget(orientation="bottom") self.gradient.sigGradientChanged.connect(self.changeLUT) self.ui.verticalLayout.addWidget(self.gradient) self.gradient.restoreState(CMAP) self.sim = sim self.wfsPlots = {} self.dmPlots = {} self.sciPlots = {} self.resPlots = {} self.console = IPythonConsole(self.ui.consoleLayout, self.sim, self) self.loopRunning = False self.makingIMat = False #Init Timer to update plots self.updateTimer = QtCore.QTimer() self.updateTimer.setInterval(100) self.updateTimer.timeout.connect(self.update) self.ui.updateTimeSpin.valueChanged.connect(self.updateTimeChanged) self.updateQueue = queue.Queue(10) self.updateLock = QtCore.QMutex() #Placeholders for sim threads self.initThread = None self.iMatThread = None self.loopThread = None self.resultPlot = None #Required for plotting colors self.colorList = ["b", "g", "r", "c", "m", "y", "k"] self.colorNo = 0 self.resultPlot = PlotWidget() self.ui.plotLayout.addWidget(self.resultPlot) #sim.readParams() sim.config.calcParams() self.config = self.sim.config if verbosity is not None: self.config.sim.verbosity = verbosity self.initPlots() self.show() self.init() self.console.write("Running %s\n" % self.sim.configFile) sys.exit(self.app.exec_())
def __init__(self, geometry, plane=-1, cryostat=0, tpc=0): super(viewport, self).__init__(border=None) # add a view box, which is a widget that allows an image to be shown self._view = self.addViewBox(border=None) # add an image item which handles drawing (and refreshing) the image self._item = pg.ImageItem(useOpenGL=True) # self._item._setPen((0,0,0)) self._view.addItem(self._item) self._removed_entries = 0 self._manual_t0 = 0 self._showAnodeCathode = False self._anode_lines = [] self._cathode_lines = [] self._tpc_div_lines = [] # Overriding the default mouseDragEvent self._view.mouseDragEvent = self.customMouseDragEvent # connect the scene to click events, used to get wires self.scene().sigMouseClicked.connect(self.mouseClicked) # connect the views to mouse move events, used to update the info box at the bottom self.scene().sigMouseMoved.connect(self.mouseMoved) self._plane = plane self._tpc = tpc self._cryostat = cryostat self._cmSpace = False self._geometry = geometry self._original_image = None self._dataPoints = [] self._drawnPoints = [] self._polygon = QtGui.QPolygonF() self._path = QtGui.QPainterPath() self._path.addPolygon(self._polygon) self._polyGraphicsItem = QtGui.QGraphicsPathItem(self._path) self._view.addItem(self._polyGraphicsItem) # Connect scale changes to handle the scale bar correctly self._view.sigYRangeChanged.connect(self.scaleHandler) self._view.sigXRangeChanged.connect(self.scaleHandler) self._xBar = None self._xBarText = None # self._yBar = None # self._yBarText = None self.useScaleBar = False # Set up the blank data: # self._blankData = np.ones((self._geometry.wRange(self._plane),self._geometry.tRange())) self.setBackground('w') # self.setBackground(pg.mkColor(0, 0, 0)) self._useLogo = False self._logo = None self._drawingRawDigits = False # each drawer contains its own color gradient and levels # this class can return a widget containing the right layout for everything # Define some color collections: self._colorMap = self._geometry.colorMap(self._plane) self._cmap = pg.GradientWidget(orientation='right') self._cmap.restoreState(self._colorMap) self._cmap.sigGradientChanged.connect(self.refreshGradient) self._cmap.resize(1, 1) # These boxes control the levels. self._upperLevel = QtGui.QLineEdit() self._lowerLevel = QtGui.QLineEdit() self._upperLevel.returnPressed.connect(self.levelChanged) self._lowerLevel.returnPressed.connect(self.levelChanged) level_lower = self._geometry.getLevels(self._plane)[0] level_upper = self._geometry.getLevels(self._plane)[1] if self._drawingRawDigits: level_lower += self._geometry.getPedestal(self._plane) level_upper += self._geometry.getPedestal(self._plane) self._lowerLevel.setText(str(level_lower)) self._upperLevel.setText(str(level_upper)) # Fix the maximum width of the widgets: self._upperLevel.setMaximumWidth(35) self._cmap.setMaximumWidth(25) self._lowerLevel.setMaximumWidth(35) # The name of the viewport with appropriate tooltip name = 'View ' name += self._geometry.viewNames()[plane] name += ', Cryo ' name += str(cryostat) self._viewport_name = VerticalLabel(name) self._viewport_name.setStyleSheet('color: rgb(169,169,169);') tooltip = 'Bottom view is for TPC 0, top view is for TPC 1. ' tooltip += 'Note that the vaweforms in TPC 1 are flipped in time ' tooltip += 'so as to retain the same x direction as in TPC 0. ' if self._geometry.viewNames()[plane] == 'U': tooltip += 'NOTE: bottom image is plane 1 for TPC 0 ' tooltip += 'but top image is plane 2 for TPC 1' if self._geometry.viewNames()[plane] == 'V': tooltip += 'NOTE: bottom image is plane 2 for TPC 0 ' tooltip += 'but top image is plane 1 for TPC 1.' self._viewport_name.setToolTip(tooltip) self._viewport_name.setMaximumWidth(25) colors = QtGui.QVBoxLayout() colors.addWidget(self._upperLevel) colors.addWidget(self._cmap) colors.addWidget(self._lowerLevel) self._totalLayout = QtGui.QHBoxLayout() self._totalLayout.addWidget(self._viewport_name) self._totalLayout.addWidget(self) self._totalLayout.addLayout(colors) self._widget = QtGui.QWidget() self._widget.setLayout(self._totalLayout) self._widget.setMaximumHeight(1000) self._widget.setMinimumHeight(50)
def __init__(self, doc, parent=None, **kwargs): super(GradientControl, self).__init__(parent) l = QtGui.QGridLayout() l.setSpacing(0) self.setLayout(l) self.doc = doc self.user_colormap_states = {} self.builtin_colormap_states = {} # Setup Color Bar & clear its data self.ColorBar = pg.GradientWidget(orientation='bottom') tickList = self.ColorBar.listTicks() for tick in tickList: self.ColorBar.removeTick(tick[0]) self.ColorBar.setEnabled(False) self.CloneButton = QtGui.QPushButton("Clone Gradient") self.CloneButton.clicked.connect(self.cloneGradient) self.CloneButton.setEnabled(False) # Create Import button self.ImportButton = QtGui.QPushButton("Import Gradient") self.ImportButton.clicked.connect(self.importButtonClick) # Create Gradient List and Related Functions self.cmap_list = QtGui.QListWidget() self.cmap_list.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection) self.cmap_list.itemSelectionChanged.connect(self.updateColorBar) # Create SQRT Button and Related Functions self.sqrt = QtGui.QCheckBox("SQRT") self.sqrt.clicked.connect(self.sqrtAction) self.sqrt.setEnabled(False) # Create Close button self.CloseButton = QtGui.QPushButton("Close") self.CloseButton.clicked.connect(self.close) # Create Delete Button and Related Functions self.DeleteButton = QtGui.QPushButton("Delete Gradient") self.DeleteButton.clicked.connect(self.handle_delete_click) self.DeleteButton.setEnabled(False) # Create Export Button and Related Functions self.ExportButton = QtGui.QPushButton("Export Gradient") self.ExportButton.clicked.connect(self.exportButtonClick) self.ExportButton.setEnabled(False) # Create Save button self.SaveButton = QtGui.QPushButton("Save Gradient") self.SaveButton.clicked.connect(self.saveButtonClick) self.SaveButton.setEnabled(False) # Add widgets to their respective spots in the UI grid l.addWidget(self.ImportButton, 0, 0) l.addWidget(self.SaveButton, 0, 2) l.addWidget(self.sqrt, 1, 2) l.addWidget(self.ColorBar, 4, 1) l.addWidget(self.CloneButton, 1, 0) l.addWidget(self.cmap_list, 1, 1, 3, 1) l.addWidget(self.CloseButton, 6, 2) l.addWidget(self.ExportButton, 2, 2) l.addWidget(self.DeleteButton, 2, 0) # Import custom colormaps cmap_manager = self.doc.colormaps for cmap in cmap_manager.iter_colormaps(): editable = cmap_manager.is_writeable_colormap(cmap) cmap_obj = cmap_manager[cmap] if cmap_obj.colors and hasattr(cmap_obj, "_controls"): is_sqrt = getattr(cmap_obj, 'sqrt', False) self.importGradients(cmap, cmap_obj._controls, cmap_obj.colors._rgba, sqrt=is_sqrt, editable=editable)
def colorGradient(self): self.gw = pg.GradientWidget(orientation='right') self.gw.restoreState(self.gradientMode)
def __init__(self, geometry, plane=-1): super(viewport, self).__init__(border=None) # add a view box, which is a widget that allows an image to be shown self._view = self.addViewBox(border=None) # add an image item which handles drawing (and refreshing) the image self._item = pg.ImageItem(useOpenGL=True) # self._item._setPen((0,0,0)) self._view.addItem(self._item) # connect the scene to click events, used to get wires self.scene().sigMouseClicked.connect(self.mouseClicked) # connect the views to mouse move events, used to update the info box at the bottom self.scene().sigMouseMoved.connect(self.mouseMoved) self._plane = plane self._cmSpace = False self._geometry = geometry self._dataPoints = [] self._drawnPoints = [] self._polygon = QtGui.QPolygonF() self._path = QtGui.QPainterPath() self._path.addPolygon(self._polygon) self._polyGraphicsItem = QtGui.QGraphicsPathItem(self._path) self._view.addItem(self._polyGraphicsItem) # Connect scale changes to handle the scale bar correctly self._view.sigYRangeChanged.connect(self.scaleHandler) self._view.sigXRangeChanged.connect(self.scaleHandler) self._xBar = None self._xBarText = None # self._yBar = None # self._yBarText = None self.useScaleBar = False # Set up the blank data: # self._blankData = np.ones((self._geometry.wRange(self._plane),self._geometry.tRange())) self.setBackground('w') self._useLogo = False self._logo = None # each drawer contains its own color gradient and levels # this class can return a widget containing the right layout for everything # Define some color collections: self._colorMap = self._geometry.colorMap(self._plane) self._cmap = pg.GradientWidget(orientation='right') self._cmap.restoreState(self._colorMap) self._cmap.sigGradientChanged.connect(self.refreshGradient) self._cmap.resize(1, 1) # These boxes control the levels. self._upperLevel = QtGui.QLineEdit() self._lowerLevel = QtGui.QLineEdit() self._upperLevel.returnPressed.connect(self.levelChanged) self._lowerLevel.returnPressed.connect(self.levelChanged) self._lowerLevel.setText(str(self._geometry.getLevels(self._plane)[0])) self._upperLevel.setText(str(self._geometry.getLevels(self._plane)[1])) # Fix the maximum width of the widgets: self._upperLevel.setMaximumWidth(35) self._cmap.setMaximumWidth(25) self._lowerLevel.setMaximumWidth(35) colors = QtGui.QVBoxLayout() colors.addWidget(self._upperLevel) colors.addWidget(self._cmap) colors.addWidget(self._lowerLevel) self._totalLayout = QtGui.QHBoxLayout() self._totalLayout.addWidget(self) self._totalLayout.addLayout(colors) self._widget = QtGui.QWidget() self._widget.setLayout(self._totalLayout)
def __init__(self, data_model, parent = None, #Qt parent scale_limits = None, #(min_val, max_val) or None (autoscale to data) display_threshold = None, # > this or not displayed vertical_stretch = False, max_frame_rate_fps = 60, show_gradient_editor = True, mouse_move_crosshair = True, mouse_move_history_slicing = True, mouse_click_crosshair = True, mouse_click_history_slicing = True, ): """ num_rows == -1 means to plot all data in the model. """ assert isinstance(data_model, WaterfallModel) super(WaterfallPlotWidget, self).__init__(parent) if scale_limits is not None: try: scale_min, scale_max = scale_limits except ValueError: msg = ("If scale_limits is specified, it must be a tuple like " "(black_level, white_level)") raise ValueError(msg) self._scale_limits = scale_limits self._show_ge = show_gradient_editor self._vertical_stretch = vertical_stretch self._data_model = data_model self._mouse_move_crosshair = mouse_move_crosshair self._mouse_move_history_slicing = mouse_move_history_slicing self._mouse_click_crosshair = mouse_click_crosshair self._mouse_click_history_slicing = mouse_click_history_slicing self._pending_mouse_move_pos = None self._LUT_PTS = 256 self._latest_lut = None #create child widgets... #self._plot_widget = pg.PlotWidget(self) self._wf_img = _WaterfallImageWidget( mouse_move_crosshair = mouse_move_crosshair, mouse_click_crosshair = mouse_click_crosshair, ) if self._show_ge: self._gradient_editor = pg.GradientWidget(parent = self, orientation = "left") self._gradient_editor.setStyleSheet('background-color: black') self._gradient_editor.loadPreset('waterfall') #configure the widgets... #self._plot_widget.addItem(self._wf_img) #self._wf_img.setLookupTable(self._get_lut) #do layout... hbox = QtGui.QHBoxLayout(self) #hbox.addWidget(self._plot_widget) if self._show_ge: hbox.addWidget(self._gradient_editor) hbox.addWidget(self._wf_img) #Configure the background image renderer (but don't start it yet)... self._renderer = _WaterfallImageRenderer(data_model, self._get_lut(), scale_min, scale_max, max_frame_rate_fps) #connect signals... self._connect_signals()
def __init__(self, *args, **kwargs): super(DownCtrl, self).__init__(*args, **kwargs) self.mainLayout = QtGui.QHBoxLayout() self.setLayout(self.mainLayout) # MODE SELECTOR self.sharedCtrlLayout = QtGui.QVBoxLayout() self.mainLayout.addLayout(self.sharedCtrlLayout) self.modeSelectorComboBox = QtGui.QComboBox() self.modeSelectorComboBox.addItem('LabelMode') self.modeSelectorComboBox.addItem('None') self.modeSelectorComboBox.addItem('Features') self.modeSelectorComboBox.addItem('Black') self.modeSelectorComboBox.addItem('Probabilities') self.modeSelectorComboBox.addItem('LabelProbabilities') self.modeSelectorComboBox.addItem('McRes') self.sharedCtrlLayout.addWidget(self.modeSelectorComboBox) # Edge Size Slide self.brushSizeSlider = QtGui.QSlider(orientation=QtCore.Qt.Horizontal) self.brushSizeSlider.setValue(2) self.sharedCtrlLayout.addWidget(self.brushSizeSlider) #Save load LABELS self.saveLoadLabelsLayout = QtGui.QVBoxLayout() self.mainLayout.addLayout(self.saveLoadLabelsLayout) self.saveLabelsButton = QtGui.QPushButton('Save Labels') self.loadLabelsButton = QtGui.QPushButton('Load Labels') self.saveLoadLabelsLayout.addWidget(self.saveLabelsButton) self.saveLoadLabelsLayout.addWidget(self.loadLabelsButton) # Compute / load / save features? self.featureGetLayout = QtGui.QVBoxLayout() self.mainLayout.addLayout(self.featureGetLayout) self.computeFeaturesButton = QtGui.QPushButton('Compute Features') self.saveFeaturesButton = QtGui.QPushButton('Save Features') self.loadFeaturesButton = QtGui.QPushButton('Load Features') self.featureGetLayout.addWidget(self.computeFeaturesButton) self.featureGetLayout.addWidget(self.saveFeaturesButton) self.featureGetLayout.addWidget(self.loadFeaturesButton) # show the features self.featureShowLayout = QtGui.QVBoxLayout() self.mainLayout.addLayout(self.featureShowLayout) self.featureGradientWidget = pg.GradientWidget(orientation='top') d = { 'ticks': [(0.0, (165, 0, 60, 255)), (1.0, (0, 170, 60, 255))], 'mode': 'rgb' } self.featureGradientWidget.restoreState(d) self.featureGradientWidget.setEnabled(False) self.featureShowLayout.addWidget(self.featureGradientWidget) # train rf self.rfLayout = QtGui.QHBoxLayout() self.mainLayout.addLayout(self.rfLayout) self.rfLayout1 = QtGui.QVBoxLayout() self.rfLayout2 = QtGui.QVBoxLayout() self.rfLayout.addLayout(self.rfLayout1) self.rfLayout.addLayout(self.rfLayout2) self.trainRfButton = QtGui.QPushButton('TrainRf') self.predictProbsButton = QtGui.QPushButton('Predict Probs') self.predictMcButton = QtGui.QPushButton('MC') self.saveRfButton = QtGui.QPushButton('Save Rf') self.loadRfButton = QtGui.QPushButton('Load Rf') self.rfLayout1.addWidget(self.trainRfButton) self.rfLayout1.addWidget(self.predictProbsButton) self.rfLayout1.addWidget(self.predictMcButton) self.rfLayout2.addWidget(self.saveRfButton) self.rfLayout2.addWidget(self.loadRfButton)
def doUI(self): self.setModal(True) self.grad = pg.GradientWidget(self) self.grad.move(0, 0) self.grad.sigGradientChangeFinished.connect(self.change_gradient) self.show()
from pyqtgraph.Qt import QtCore, QtGui import numpy as np app = QtGui.QApplication([]) w = QtGui.QMainWindow() w.show() w.setWindowTitle('pyqtgraph example: GradientWidget') w.resize(400, 400) cw = QtGui.QWidget() w.setCentralWidget(cw) l = QtGui.QGridLayout() l.setSpacing(0) cw.setLayout(l) w1 = pg.GradientWidget(orientation='top') w2 = pg.GradientWidget(orientation='right', allowAdd=False) #w2.setTickColor(1, QtGui.QColor(255,255,255)) w3 = pg.GradientWidget(orientation='bottom') w4 = pg.GradientWidget(orientation='left') w4.loadPreset('spectrum') label = QtGui.QLabel(""" - Click a triangle to change its color - Drag triangles to move - Click in an empty area to add a new color (adding is disabled for the right-side widget) - Right click a triangle to remove """) l.addWidget(w1, 0, 1) l.addWidget(w2, 1, 2)
def __init__(self, plane=-1): super(viewport, self).__init__(border=None) # add a view box, which is a widget that allows an image to be shown self._plot = self.addPlot(border=None) # add an image item which handles drawing (and refreshing) the image self._item = pg.ImageItem(useOpenGL=True) self._plot.addItem(self._item) # # connect the scene to click events, used to get wires # self.scene().sigMouseClicked.connect(self.mouseClicked) # # connect the views to mouse move events, used to update the info box at the bottom self.scene().sigMouseMoved.connect(self.mouseMoved) self._plane = plane self._x_axis = self._plot.getAxis("bottom") self._y_axis = self._plot.getAxis("left") self._x_max_range = (-1, 1) self._y_max_range = (-1, 1) # Set up the blank data: self.setBackground('w') # each drawer contains its own color gradient and levels # this class can return a widget containing the right layout for everything # Define some color collections: self._bwMap = { 'ticks': [(0, (0, 0, 0, 255)), (1, (255, 255, 255, 255))], 'mode': 'rgb' } self._colorMap = { 'ticks': [(0, (30, 30, 255, 255)), (0.33333, (0, 255, 255, 255)), (0.66666, (255, 255, 100, 255)), (1, (255, 0, 0, 255))], 'mode': 'rgb' } self._activeMap = self._bwMap self._cmap = pg.GradientWidget(orientation='right') self._cmap.restoreState(self._activeMap) self._cmap.sigGradientChanged.connect(self.refreshGradient) self._cmap.resize(1, 1) # These boxes control the levels. self._upperLevel = QtGui.QLineEdit() self._lowerLevel = QtGui.QLineEdit() self._upperLevel.returnPressed.connect(self.levelChanged) self._lowerLevel.returnPressed.connect(self.levelChanged) self._lowerLevel.setText(str(-10)) self._upperLevel.setText(str(10)) # Fix the maximum width of the widgets: self._upperLevel.setMaximumWidth(35) self._cmap.setMaximumWidth(25) self._lowerLevel.setMaximumWidth(35) colors = QtGui.QVBoxLayout() colors.addWidget(self._upperLevel) colors.addWidget(self._cmap) colors.addWidget(self._lowerLevel) self._totalLayout = QtGui.QHBoxLayout() self._totalLayout.addWidget(self) self._totalLayout.addLayout(colors) self._widget = QtGui.QWidget() self._widget.setLayout(self._totalLayout)
def __init__(self, parent=None): super(TSNEPlot, self).__init__(parent=parent) self.model = ResultsTableModel() self.layout = QtGui.QGridLayout(self) self.layout.setAlignment(QtCore.Qt.AlignTop) self.random_seed = np.random.randint(1, 99999) self.perplexity = 30 self.lr = 200.0 self.plot_widget = pg.PlotWidget() self.tsne_plot = pg.ScatterPlotItem( symbol="o", size=10, pen=pg.mkPen(width=0.2, color="b"), brush=pg.mkBrush(0.7), antialias=True, ) self.tsne_plot.sigClicked.connect(self.pointClicked) self.selectedPt = None self.plot_widget.hideAxis("left") self.plot_widget.hideAxis("bottom") self.plot_widget.addItem(self.tsne_plot) self.random_seed_edit = QtGui.QLineEdit(str(self.random_seed)) self.random_seed_edit.setValidator(QtGui.QIntValidator(1, 99999)) self.random_seed_edit.setMaximumWidth(75) self.perplexity_edit = QtGui.QLineEdit(str(self.perplexity)) self.perplexity_edit.setValidator(QtGui.QIntValidator(1, 50)) self.perplexity_edit.setMaximumWidth(75) self.lr_edit = QtGui.QLineEdit(str(self.lr)) self.lr_edit.setValidator(QtGui.QDoubleValidator(10, 1000, 3)) self.lr_edit.setMaximumWidth(75) self.select_feature = QtGui.QComboBox() self.run_button = QtGui.QPushButton("Run t-SNE") self.back_button = QtGui.QPushButton("<<< Feature Selection") self.save_button = QtGui.QPushButton("Export Image") self.save_button.setIcon(self.style().standardIcon( QtGui.QStyle.SP_FileDialogStart)) self.legend = pg.GradientWidget(orientation="right") self.legend.setMaximumWidth(50) self.legend.sigGradientChangeFinished.connect(self.colorChange) # print(self.legend.colorMap()) self.layout.addWidget(QtGui.QLabel("Perplexity"), 0, 0, 1, 1) self.layout.addWidget(self.perplexity_edit, 0, 1, 1, 1) self.layout.addWidget(QtGui.QLabel("Random Seed"), 1, 0, 1, 1) self.layout.addWidget(self.random_seed_edit, 1, 1, 1, 1) self.layout.addWidget(QtGui.QLabel("Learning Rate"), 2, 0, 1, 1) self.layout.addWidget(self.lr_edit, 2, 1, 1, 1) self.layout.addWidget(self.save_button, 3, 0, 1, 1) self.layout.addWidget(self.run_button, 3, 1, 1, 2) self.layout.addWidget(self.plot_widget, 4, 0, 4, 3) self.layout.addWidget(self.select_feature, 8, 0, 1, 3) self.layout.addWidget(self.back_button, 9, 0, 1, 3) self.layout.addWidget(self.legend, 4, 4, 4, 1) # self.layout.setColumnStretch(4, 1) self.select_feature.activated[str].connect(self.setBrushes)
import pyqtgraph as pg import numpy as np imdat1 = np.random.random_integers(2, size=(100, 100)) imdat2 = np.random.random_integers(2, size=(100, 100)) #fig = plt.figure() # #cmap = plt.cm.Reds #my_cmap = cmap(np.arange(cmap.N)) #my_cmap[:,-1] = np.linspace(0, 1, cmap.N) #my_cmap = ListedColormap(my_cmap) #im1 = plt.imshow(imdat1, cmap = my_cmap) # #cmap = plt.cm.Blues #my_cmap = cmap(np.arange(cmap.N)) #my_cmap[:,-1] = np.linspace(0, 1, cmap.N) #my_cmap = ListedColormap(my_cmap) #im2 = plt.imshow(imdat2, cmap = my_cmap) p1 = pg.plot() #pos = np.array([0.0, 0.5, 1.0]) #color = np.array([[0,0,0,255], [0,0,0,255], [0,255,0,255]], dtype=np.ubyte) #cmap = pg.ColorMap(pos, color) #lut = cmap.getLookupTable(0.0, 1.0, 256) pg.GradientWidget() it1 = pg.ImageItem(imdat1) it1.setLookupTable(lut) p1.addItem(it1)
def __init__(self, name, filename, namebase, mask=None, label=None, isaMask=False, geommask=None, funcmask=None, lut_state=cm.gray_state, verbose=False): self.verbose = verbose self.name = name if label is None: self.label = name else: self.label = label self.filename = filename self.namebase = namebase if self.verbose: print('reading map ', self.name, ' from ', self.filename, '...') self.isaMask = isaMask self.gradient = pg.GradientWidget(orientation='right', allowAdd=True) self.ry_gradient = pg.GradientWidget(orientation='right', allowAdd=True) self.blb_gradient = pg.GradientWidget(orientation='right', allowAdd=True) self.lut_state = lut_state self.theLUT = None self.theRedyellowLUT = None self.theBluelightblueLUT = None self.setLUT(self.lut_state) self.readImageData(isaMask=self.isaMask) self.mask = None self.maskeddata = None self.setFuncMask(funcmask, maskdata=False) self.setGeomMask(geommask, maskdata=False) self.maskData() self.updateStats() self.space = 'unspecified' if (self.header['sform_code'] == 4) or (self.header['qform_code'] == 4): if ((self.xdim == 61) and (self.ydim == 73) and (self.zdim == 61)) or \ ((self.xdim == 91) and (self.ydim == 109) and (self.zdim == 91)): self.space = "MNI152" else: self.space = "MNI152NLin2009cAsym" if self.header['sform_code'] != 0: self.affine = self.header.get_sform() elif self.header['qform_code'] != 0: self.affine = self.header.get_qform() else: self.affine = self.header.get_base_affine() self.invaffine = np.linalg.inv(self.affine) self.xpos = 0 self.ypos = 0 self.zpos = 0 self.tpos = 0 self.xcoord = 0.0 self.ycoord = 0.0 self.zcoord = 0.0 self.tcoord = 0.0 if self.verbose: print('imagedata initialized:', self.name, self.filename, self.minval, self.dispmin, self.dispmax, self.maxval) self.summarize()
def __init__(self, controller): super().__init__() self.current_organ = None self.name_label = QLabel() self.local_outs = {} self.controller = controller self.context = QGridLayout() # Find the available screen geometry available_height = self.height() self.input_group = QGroupBox("Inputs") self.input_group.setFixedSize(300, (available_height / 2)) # We construct the input group layout here self.input_group_layout = QVBoxLayout() glob_button = QPushButton("View global inputs") glob_button.clicked.connect(self.show_globals) self.input_group_layout.addWidget(glob_button) input_gr_button_layout = QHBoxLayout() new_glob_in_button = QPushButton("New") new_glob_in_button.clicked.connect(self.new_global_input) input_gr_button_layout.addWidget(new_glob_in_button) del_glob_in_button = QPushButton("Remove") del_glob_in_button.clicked.connect(self.del_global_input) input_gr_button_layout.addWidget(del_glob_in_button) self.input_group_layout.addLayout(input_gr_button_layout) self.in_slider_layout = QGridLayout() self.input_group.setLayout(self.input_group_layout) self.context_group = QGroupBox("Context") self.context_group.setFixedSize(300, (available_height / 2)) self.output_group = QGroupBox("Outputs") self.output_group.setFixedSize(300, (available_height / 2)) self.output_grid_layout = QGridLayout() color_group = QGroupBox("Color") color_group.setFixedSize(300, (available_height / 5)) self.color_global = QLabel("") self.colorBar = pg.GradientWidget() color_layout = QGridLayout() color_layout.addWidget(self.color_global) color_layout.addWidget(self.colorBar) color_group.setLayout(color_layout) self.colorBar.loadPreset('cyclic') self.colorBar.sigGradientChangeFinished.connect( lambda: self.controller.update_colors()) layout = QGridLayout() layout.addWidget(self.input_group) layout.addWidget(self.context_group) layout.addWidget(self.output_group) layout.addWidget(color_group) self.setLayout(layout)
def __init__( self, name, filename, namebase, funcmask=None, geommask=None, label=None, report=False, lut_state=gray_state, alpha=128, endalpha=0, display_state=True, isaMask=False, init_LUT=True, verbose=False, ): self.verbose = verbose self.name = name if label is None: self.label = name else: self.label = label self.report = report self.filename = filename self.namebase = namebase if self.verbose: print("reading map ", self.name, " from ", self.filename, "...") self.readImageData(isaMask=isaMask) self.mask = None self.maskeddata = None self.setFuncMask(funcmask, maskdata=False) self.setGeomMask(geommask, maskdata=False) self.maskData() self.updateStats() if init_LUT: self.gradient = pg.GradientWidget(orientation="right", allowAdd=True) self.lut_state = lut_state self.display_state = display_state self.theLUT = None self.alpha = alpha self.endalpha = endalpha self.setLUT(self.lut_state, alpha=self.alpha, endalpha=self.endalpha) self.space = "unspecified" if (self.header["sform_code"] == 4) or (self.header["qform_code"] == 4): if ((self.xdim == 61) and (self.ydim == 73) and (self.zdim == 61)) or ((self.xdim == 91) and (self.ydim == 109) and (self.zdim == 91)): self.space = "MNI152" else: self.space = "MNI152NLin2009cAsym" if self.header["sform_code"] != 0: self.affine = self.header.get_sform() elif self.header["qform_code"] != 0: self.affine = self.header.get_qform() else: self.affine = self.header.get_base_affine() self.invaffine = np.linalg.inv(self.affine) self.xpos = 0 self.ypos = 0 self.zpos = 0 self.tpos = 0 self.xcoord = 0.0 self.ycoord = 0.0 self.zcoord = 0.0 self.tcoord = 0.0 if self.verbose: print( "Overlay initialized:", self.name, self.filename, self.minval, self.dispmin, self.dispmax, self.maxval, ) self.summarize()