def paintEvent(self, event): if (not self.m_displayedWhenStopped) and (not self.isAnimated()): return width = min(self.width(), self.height()) painter = QtGui.QPainter(self) painter.setRenderHint(QtGui.QPainter.Antialiasing) outerRadius = (width - 1) * 0.5 innerRadius = (width - 1) * 0.5 * 0.38 capsuleHeight = outerRadius - innerRadius capsuleWidth = capsuleHeight * .23 if (width > 32) else capsuleHeight * .35 capsuleRadius = capsuleWidth / 2 for i in range(0, 12): color = QtGui.QColor(self.m_color) if self.isAnimated(): color.setAlphaF(1.0 - (i / 12.0)) else: color.setAlphaF(0.2) painter.setPen(QtCore.Qt.NoPen) painter.setBrush(color) painter.save() painter.translate(self.rect().center()) painter.rotate(self.m_angle - (i * 30.0)) painter.drawRoundedRect(capsuleWidth * -0.5, (innerRadius + capsuleHeight) * -1, capsuleWidth, capsuleHeight, capsuleRadius, capsuleRadius) painter.restore()
def open_menu(self, position): menu = QtGui.QMenu() expand_all_action = QtGui.QAction('Expand all', self) expand_all_action.triggered.connect(self.expandAll) menu.addAction(expand_all_action) collapse_all_action = QtGui.QAction('Collapse all', self) collapse_all_action.triggered.connect(self.collapseAll) menu.addAction(collapse_all_action) menu.exec_(self.viewport().mapToGlobal(position))
def add_page(self, widget): scrollarea = QtGui.QScrollArea(self) scrollarea.setWidgetResizable(True) scrollarea.setWidget(widget) self.pages_widget.addWidget(scrollarea) item = QtGui.QListWidgetItem(self.contents_widget) try: item.setIcon(widget.icon) except TypeError: pass item.setText(widget.title) item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) item.setSizeHint(QtCore.QSize(0, 25))
def __init__(self, *args, **kwargs): super(preferencesWidget, self).__init__(*args, **kwargs) self.vbox = vbox = QtGui.QVBoxLayout() self.description = QtGui.QLabel( '<p>Modify the configuration for your need. ' 'Changes will be applied if they are valid according to the ' 'type of the parameter</p>', parent=self) vbox.addWidget(self.description) self.tree = tree = PreferencesTree(self.preferences, parent=self) vbox.addWidget(self.tree) self.setLayout(vbox)
def TestProgressIndicator(): app = QtGui.QApplication(sys.argv) progress = QProgressIndicator(None) progress.setAnimationDelay(70) progress.startAnimation() # Execute the application sys.exit(app.exec_())
def start(): # Main thread from spectrochempy_gui.pyqtgraph.Qt import QtGui from spectrochempy_gui.mainwindow import MainWindow gui = QtGui.QApplication(sys.argv) mw = MainWindow(show=True) gui.exec_() # Quit gui.quit()
def func(): editor = self.itemWidget(item.child(0), self.value_col) s = editor.toPlainText() try: key = item.text(0) # expected traits try: val = eval(s) except Exception as e: val = s # validation trait = self.preferences.traits()[key] val = trait.validate(key, val) except Exception as e: item.setIcon(1, QtGui.QIcon(str(geticon('invalid.png')))) item.setToolTip(1, "Wrong value: %s" % e) return item.setIcon(1, QtGui.QIcon(str(geticon('valid.png')))) setattr(self.preferences, key, val)
def initialize(self): """ Fill the items of the Preferences into the tree """ preferences = self.preferences.traits(config=True, gui=True) actualpreferences = self.preferences.config[self.preferences.name] vcol = self.value_col for i, (key, val) in enumerate(sorted(preferences.items())): desc = val.help info = val.info_text try: type = val.trait_types except AttributeError: type = val.__class__ val = actualpreferences.get(key, val.default_value) if str(val) in ['traitlets.Undefined']: val = '' item = QtGui.QTreeWidgetItem(0) item.setText(0, key) item.setToolTip(0, f"{key} ({info})") item.setIcon(1, QtGui.QIcon(str(geticon('valid.png')))) if desc: item.setText(vcol, desc) item.setToolTip(vcol, desc) child = QtGui.QTreeWidgetItem(0) item.addChild(child) self.addTopLevelItem(item) editor = QtGui.QTextEdit(self) # set maximal height of the editor to 1 rows editor.setMaximumHeight(1.5 * QtGui.QFontMetrics(editor.font()).height()) editor.setPlainText(str(val)) self.setItemWidget(child, vcol, editor) editor.textChanged.connect(self.validate(item)) self.resizeColumnToContents(0) self.resizeColumnToContents(1)
def buildTree(self, obj, parent, name=''): if obj is None: node = QtGui.QTreeWidgetItem(['No project', '']) parent.addChild(node) return typeStr, id = obj.id.split('_') # type(obj).__name__ if typeStr == 'Project': name = obj.name id = ' ' node = QtGui.QTreeWidgetItem([name, typeStr, id]) parent.addChild(node) if typeStr == 'Project': for k in obj.allnames: self.buildTree(obj[k], node, k) node.setIcon(0, QtGui.QIcon(str(geticon('folder.png')))) elif typeStr == 'NDDataset': node.setFlags( QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable) # QtCore.Qt.ItemIsUserCheckable | # node.setCheckState(1, QtCore.Qt.Unchecked) node.setIcon(0, QtGui.QIcon(str(geticon('file.png')))) else: return
def __init__(self, dpi=100): QtGui.QWidget.__init__(self) a = 236. / 255. self.fig = Figure(dpi=dpi, facecolor=(a, a, a)) self.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding) self.canvas = FigureCanvas(self.fig) self.canvas.setParent(self) self.toolbar = NavigationToolbar(self.canvas, self) self.vbox = QtGui.QVBoxLayout() self.vbox.addWidget(self.toolbar) self.vbox.addWidget(self.canvas) self.setLayout(self.vbox)
def showContextMenuEvent(self, event): self.contextMenu = QtGui.QMenu() # Infos about the selected node. index = self.indexAt(event) if not index.isValid(): return item = self.itemAt(event) name = item.text(0) if item.text(1) == 'Project': # self.contextMenu.addAction('Rename').triggered.connect(partial(self.editname, item)) self.contextMenu.addAction('Add new dataset').triggered.connect( self.emitAddDataset) if name != self.project.name: # can't remove the top element without cloing the project self.contextMenu.addAction('Remove').triggered.connect( partial(self.emitRemove, item)) self.contextMenu.popup(self.mapToGlobal(event))
def __init__(self, main=None): super().__init__(parent=main) self.setWindowTitle('Preferences') # Widgets self.pages_widget = QtGui.QStackedWidget() self.contents_widget = QtGui.QListWidget() self.bt_reset = QtGui.QPushButton('Reset to defaults') self.bbox = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok) self.setAttribute(QtCore.Qt.WA_DeleteOnClose) self.setWindowTitle('Preferences') self.contents_widget.setMovement(QtGui.QListView.Static) self.contents_widget.setSpacing(1) self.contents_widget.setCurrentRow(0) # Layout hsplitter = QtGui.QSplitter() hsplitter.addWidget(self.contents_widget) hsplitter.addWidget(self.pages_widget) hsplitter.setStretchFactor(1, 1) btnlayout = QtGui.QHBoxLayout() btnlayout.addStretch(1) btnlayout.addWidget(self.bt_reset) btnlayout.addWidget(self.bbox) vlayout = QtGui.QVBoxLayout() vlayout.addWidget(hsplitter) vlayout.addLayout(btnlayout) self.setLayout(vlayout) # Signals self.bbox.accepted.connect(self.accept) self.bt_reset.clicked.connect(scp.reset_preferences) self.pages_widget.currentChanged.connect(self.current_page_changed) self.contents_widget.currentRowChanged.connect( self.pages_widget.setCurrentIndex)
def getMenu(self): """ Create the menu """ if self.menu is None: self.menu = QtGui.QMenu() self.PlotModeMenu = QtGui.QMenu("Plot mode") self.plotModeCombo = QtGui.QComboBox() self.modeItems = [ 'pen', 'scatter', 'scatter+pen', 'bar' ] if self.ndim < 2 else ['stack', 'map', 'image', 'surface'] self.plotModeCombo.insertItems(1, self.modeItems) self.plotModeCombo.activated.connect(self.emitPlotModeChanged) self.plotModeAction = QtGui.QWidgetAction(None) self.plotModeAction.setDefaultWidget(self.plotModeCombo) self.PlotModeMenu.addAction(self.plotModeAction) self.menu.addMenu(self.PlotModeMenu) if self.ndim == 2: self.ColorMapMenu = QtGui.QMenu("Colormap") self.colorMapCombo = QtGui.QComboBox() self.colorMapItems = plt.colormaps() self.colorMapCombo.insertItems(1, self.colorMapItems) self.colorMapCombo.setCurrentIndex( self.colorMapItems.index(self.prefs.colormap)) self.colorMapCombo.activated.connect(self.emitColorMapChanged) self.colorMapAction = QtGui.QWidgetAction(None) self.colorMapAction.setDefaultWidget(self.colorMapCombo) self.ColorMapMenu.addAction(self.colorMapAction) self.menu.addMenu(self.ColorMapMenu) self.LineMenu = QtGui.QMenu("Linewidth") self.lineSpinBox = pg.SpinBox(value=1, step=0.1, decimals=3) self.lineSpinBox.sigValueChanged.connect(self.emitLineWidthChanged) self.lineAction = QtGui.QWidgetAction(None) self.lineAction.setDefaultWidget(self.lineSpinBox) self.LineMenu.addAction(self.lineAction) self.menu.addMenu(self.LineMenu) self.viewAll = QtGui.QAction("Zoom reset", self.menu) self.viewAll.triggered.connect(self.autoRange) self.menu.addAction(self.viewAll) self.leftMenu = QtGui.QMenu("Left mouse click mode") group = QtGui.QActionGroup(self) pan = QtGui.QAction(u'Pan', self.leftMenu) zoom = QtGui.QAction(u'Zoom', self.leftMenu) self.leftMenu.addAction(pan) self.leftMenu.addAction(zoom) pan.triggered.connect(self.setPanMode) zoom.triggered.connect(self.setRectMode) pan.setCheckable(True) zoom.setCheckable(True) pan.setActionGroup(group) zoom.setActionGroup(group) self.menu.addMenu(self.leftMenu) self.menu.addSeparator() return self.menu
def __init__(self, show=True): super().__init__() pg.setConfigOption('background', 'w') pg.setConfigOption('foreground', 'k') siz = QtWidgets.QDesktopWidget().screenGeometry(-1) self.ww, self.wh = ww, wh = min(1500, siz.width() * .80), min( 900, siz.height() * .80) self.move(QtCore.QPoint(10, 10)) # TODO: center it ? # -------------------------------------------------------------------------------------------------------------- # Logging # -------------------------------------------------------------------------------------------------------------- if not __DEV__: # production scp.app.log_level = logging.WARNING else: # development scp.app.log_level = logging.DEBUG # -------------------------------------------------------------------------------------------------------------- # Main area # -------------------------------------------------------------------------------------------------------------- self.area = area = LockedDockArea() self.setCentralWidget(area) self.setWindowIcon(QtGui.QIcon(str(geticon('scpy.png')))) self.setWindowTitle('SpectroChemPy GUI') # -------------------------------------------------------------------------------------------------------------- # Create status bar # -------------------------------------------------------------------------------------------------------------- self.statusbar = self.statusBar() self.statusbar.showMessage('Welcome to SpectroChemPy') # -------------------------------------------------------------------------------------------------------------- # Create doc for plots # -------------------------------------------------------------------------------------------------------------- # we need to create a dock object for this branch self.dplot = dplot = LockedDock('Plot', closable=False) dplot.hideTitleBar() # -------------------------------------------------------------------------------------------------------------- # Create project window # -------------------------------------------------------------------------------------------------------------- self.dproject = dproject = LockedDock("Project", size=(300, wh * .30)) self.projectwidget = ProjectTreeWidget(showHeader=False, parent=self) self.project = Project(parent=self) dproject.addWidget(self.projectwidget) dproject.setMinimumWidth(300) dproject.setMaximumWidth(300) # -------------------------------------------------------------------------------------------------------------- # Controller window # -------------------------------------------------------------------------------------------------------------- dcontroller = LockedDock("Controller", size=(300, wh * .70)) self.controller = Controller(parent=self) dcontroller.addWidget(self.controller) # -------------------------------------------------------------------------------------------------------------- # set layout # -------------------------------------------------------------------------------------------------------------- self.area.addDock(dproject, 'left') self.area.addDock(dplot, 'right') self.area.addDock(dcontroller, 'bottom', dproject) self.resize(ww, wh) # -------------------------------------------------------------------------------------------------------------- # Create Menubar and actions # -------------------------------------------------------------------------------------------------------------- # MENU FILE # ------------------------------------------------------------------- project_menu = QtGui.QMenu('&Project', parent=self) self.menuBar().addMenu(project_menu) # Project menu # ---------------------------------------------------------------------------------------------------------- self.new_action = QtGui.QAction('&New project', self) self.new_action.setShortcut(QtGui.QKeySequence.New) self.new_action.setStatusTip('Create a new main project') self.new_action.triggered.connect( partial(self.project.openProject, new=True)) project_menu.addAction(self.new_action) self.open_action = QtGui.QAction('&Open project', self) self.open_action.setShortcut(QtGui.QKeySequence.Open) self.open_action.setStatusTip('Open a new main project') self.open_action.triggered.connect( partial(self.project.openProject, new=False)) project_menu.addAction(self.open_action) # Dataset menu # -------------------------------------------------------------------------------------------------------------- project_menu.addSeparator() self.add_dataset_action = QtGui.QAction('Add dataset', self) self.add_dataset_action.triggered.connect(self.project.addDataset) self.add_dataset_action.setShortcut( QtGui.QKeySequence('Ctrl+A', QtGui.QKeySequence.NativeText)) self.add_dataset_action.setDisabled(True) project_menu.addAction(self.add_dataset_action) self.remove_dataset_action = QtGui.QAction('remove selected dataset', self) self.remove_dataset_action.triggered.connect( self.project.removeDataset) self.remove_dataset_action.setShortcut( QtGui.QKeySequence('Ctrl+D', QtGui.QKeySequence.NativeText)) self.remove_dataset_action.setDisabled(True) project_menu.addAction(self.remove_dataset_action) # Save project menu # ---------------------------------------------------------------------------------------------------------- project_menu.addSeparator() self.save_action = QtGui.QAction('&Save project', self) self.save_action.setStatusTip('Save the entire project into a file') self.save_action.setShortcut(QtGui.QKeySequence.Save) self.save_action.triggered.connect( partial(self.project.saveProject, force=True)) self.save_action.setDisabled(True) project_menu.addAction(self.save_action) self.save_as_action = QtGui.QAction('Save project as...', self) self.save_as_action.setStatusTip( 'Save the entire project into a new file') self.save_as_action.setShortcut(QtGui.QKeySequence.SaveAs) self.save_as_action.triggered.connect( partial(self.project.saveProject, force=True, saveas=True)) self.save_as_action.setDisabled(True) project_menu.addAction(self.save_as_action) # Close project menu # ---------------------------------------------------------------------------------------------------------- project_menu.addSeparator() self.close_action = QtGui.QAction('Close project', self) self.close_action.setShortcut( QtGui.QKeySequence('Ctrl+Shift+W', QtGui.QKeySequence.NativeText)) self.close_action.setStatusTip( 'Close the main project and delete all data and plots out of ' 'memory') self.close_action.triggered.connect(self.project.closeProject) self.close_action.setDisabled(True) project_menu.addAction(self.close_action) # Quit # -------------------------------------------------------------------------------------------------------------- if sys.platform != 'darwin': # mac os makes this anyway quit_action = QtGui.QAction('Quit', self) quit_action.triggered.connect( QtCore.QCoreApplication.instance().quit) quit_action.setShortcut(QtGui.QKeySequence.Quit) project_menu.addAction(quit_action) self.menuBar().addMenu(project_menu) # Processing menu # --------------- proc_menu = QtGui.QMenu('Script', parent=self) self.menuBar().addMenu(proc_menu) # export script export_script_action = QtGui.QAction('Export script', self) export_script_action.triggered.connect(self.controller.exportScript) proc_menu.addAction(export_script_action) # import script import_script_action = QtGui.QAction('Import script', self) import_script_action.triggered.connect(self.controller.importScript) proc_menu.addAction(import_script_action) # Help menu # -------------------------------------------------------------------------------------------------------------- help_menu = QtGui.QMenu('Help', parent=self) self.menuBar().addMenu(help_menu) # About about_action = QtGui.QAction('About', self) about_action.triggered.connect(self.onAbout) help_menu.addAction(about_action) # Preferences prefs_action = QtGui.QAction('Preferences', self) prefs_action.triggered.connect(lambda: self.onEditPreferences(True)) prefs_action.setShortcut(QtGui.QKeySequence.Preferences) help_menu.addAction(prefs_action) # Documentation doc_action = QtGui.QAction('Documentationt', self) doc_action.triggered.connect(self.onDoc) help_menu.addAction(doc_action) # Console # console_action = QtGui.QAction('Console', self) # console_action.triggered.connect(self.show_console) # help_menu.addAction(console_action) if sys.platform == 'darwin': self.menuBar().setNativeMenuBar( False ) # this put the menu in the # window itself in OSX, as in windows. # TODO: set this in # preferences self.preference_pages.extend([ GeneralPreferencesWidget, ]) # -------------------------------------------------------------------------------------------------------------- # Signal connections # -------------------------------------------------------------------------------------------------------------- # user requests self.projectwidget.sigDatasetSelected.connect( self.project.onSelectDataset) self.projectwidget.sigDatasetAdded.connect(self.project.addDataset) self.projectwidget.sigDatasetRemoved.connect( self.project.removeDataset) # model changes self.project.sigProjectChanged.connect( self.controller.onProjectChanged) self.project.sigDatasetChanged.connect( self.controller.onDatasetChanged) # -------------------------------------------------------------------------------------------------------------- # Show window # -------------------------------------------------------------------------------------------------------------- if show: self.show() self.controller.onProjectChanged('opened')
def icon(self): return QtGui.QIcon(geticon('preferences.png'))