def __init__(self, gui): #TODO: make pyqtgraph optics(colortheme...) directly changeable - not just # at reload QtGui.QWidget.__init__(self) self.gui = gui session = gui.app.session #CONNECT SAVE/RESTORE: session.sigSave.connect(self._save) session.sigRestore.connect(self._restore) #LAYOUT: layout = QtGui.QVBoxLayout() layout.setAlignment(QtCore.Qt.AlignTop) self.setLayout(layout) hlayout = QtGui.QHBoxLayout() layout.addLayout(hlayout) self.label_colorTheme = QtGui.QLabel('Color theme') hlayout.addWidget(self.label_colorTheme) self.combo_colorTheme = QtGui.QComboBox() hlayout.addWidget(self.combo_colorTheme) self.combo_colorTheme.addItems(('dark', 'bright')) self.combo_colorTheme.currentIndexChanged.connect( lambda i, self=self: self.setColorTheme(self.combo_colorTheme. currentText())) self.check_antialiasting = QtGui.QCheckBox('Antialiasting') layout.addWidget(self.check_antialiasting) self.check_antialiasting.stateChanged.connect(self._setAntialiasting) combo_profile = ChooseProfile(session) layout.addWidget(combo_profile)
def drawCell(self, p, x0, x1, y0, y1, subx, suby): w, h = x1 - x0, y1 - y0 rect = QtCore.QRectF(x0, y0, w, h) # rect: pp1 = QtGui.QPainterPath() pp1.addRect(rect) # busbars: # TODO: make width variable ... currently fixed to 1e-3 ps = QtGui.QPainterPath() for yi in subx: yi = y0 + yi * (y1 - y0) ps.addRect(QtCore.QRectF(x0, yi, w, 1e-3)) for xi in suby: xi = x0 + xi * (x1 - x0) ps.addRect(QtCore.QRectF(xi, y0, 1e-3, h)) if not self.circleOffs.isNull(): # intersect rect with ellipse to create pseudo rect shape: # scale rect: c = rect.center() esize = rect.size() * 2**0.5 - self.circleOffs esize.setWidth(max(rect.width(), esize.width())) esize.setHeight(max(rect.height(), esize.height())) rect.setSize(esize) rect.moveCenter(c) pp2 = QtGui.QPainterPath() pp2.addEllipse(rect) pp1 = pp2.intersected(pp1) ps = pp2.intersected(ps) p.addPath(ps) p.addPath(pp1)
def __init__(self, session): QtGui.QWidget.__init__(self) lab = QtGui.QLabel('Profile:') tt = '''The chosen profile influences the visibility of tool bars. Changes are only effective after restarting the program.''' lab.setToolTip(tt) cb = QtGui.QComboBox() cb.setToolTip(tt) items = ('simple', 'advanced') cb.addItems(items) try: cb.setCurrentIndex(items.index(session.app_opts['profile'])) except KeyError: session.app_opts['profile'] = 'simple' pass cb.currentIndexChanged.connect(lambda i: session.app_opts.__setitem__( 'profile', str(cb.currentText()))) l = QtGui.QHBoxLayout() self.setLayout(l) l.addWidget(lab) l.addWidget(cb)
def __init__(self, session): FirstStart.__init__(self, session) self.layout().insertWidget(3, ChooseProfile(session)) #TEMPORARY CONTENT TO BE REMOVED AFTER CODE RELEASE self.resize(300, 310) lab = QtGui.QLabel('<b>Software License Agreement</b>') ed = QtGui.QTextBrowser() ed.setReadOnly(True) ed.setOpenExternalLinks(True) ed.setCurrentFont(QtGui.QFont("Courier New", 8)) ed.setHtml('''<font size="3" face="Courier New"> This free software 'dataArtist' is licensed under GPLv3. By using this software the user agrees to the thereby associated terms. More information can be found <a href = "http://www.gnu.org/licenses/quick-guide-gplv3.en.html">here </a> </font>''') btn = QtGui.QCheckBox('I accept the terms') self.btn_done.setEnabled(False) btn.clicked.connect(lambda checked: self.btn_done.setEnabled(checked)) self.layout().insertWidget(4, lab) self.layout().insertWidget(5, ed) self.layout().insertWidget(6, btn)
def __init__(self, display): QtGui.QWidget.__init__(self) l = QtGui.QVBoxLayout() self.setLayout(l) #PAREMETERTREE pref = ParameterTree(display.p, showHeader=False) h = pref.header() h.setResizeMode(0, QtGui.QHeaderView.Stretch) h.setStretchLastSection(False) #TITLE l.addWidget(QtGui.QLabel('<b>Preferences</b')) l.addWidget(pref)
def __init__(self): QtGui.QStatusBar.__init__(self) #do not resize mainWindow when a longer message is displayed: self.setMinimumWidth(2) self.setFixedHeight(self.sizeHint().height() + 5) l = self.layout() l.setSpacing(0) l.setContentsMargins(0, 0, 0, 0) self._pMsg = QtGui.QPalette() self._pMsg.setColor(QtGui.QPalette.Foreground, QtCore.Qt.black) self._pErr = QtGui.QPalette() self._pErr.setColor(QtGui.QPalette.Foreground, QtCore.Qt.red)
def _openContextMenu(self, pos): #show toolbar name and action[remove] on right click m = QtGui.QMenu() #title: a = QtGui.QAction('Toolbar: %s' % self.name, self) a.setSoftKeyRole(QtGui.QAction.NoSoftKey) f = a.font() f.setBold(True) a.setFont(f) m.addAction(a) m.addSeparator() m.addAction("Remove").triggered.connect(self.actionSelect.trigger) m.exec_(self.mapToGlobal(pos))
def __init__(self, fnPrevious, fnNext): QtGui.QWidget.__init__(self) #make frameles: self.setWindowFlags(QtCore.Qt.FramelessWindowHint | QtCore.Qt.WindowStaysOnTopHint) layout = QtGui.QHBoxLayout() self.setLayout(layout) btn_previous = QtGui.QPushButton('Previous') btn_previous.clicked.connect(fnPrevious) btn_next = QtGui.QPushButton('Next') btn_next.clicked.connect(fnNext) layout.addWidget(btn_previous) layout.addWidget(btn_next)
def addLayerControl(self, item, name, tip=''): ''' add color button in parameter menu if an overlay is added ''' aExport = QtGui.QAction('Export to new display', self._menu.p) aExport.triggered.connect( lambda c, n=name: self._exportLayerToNewDisplay(n)) p = self._menu.p.addChild({ 'name': name, 'highlight': True, 'type': 'color', 'tip': tip, 'removable': True, 'autoIncrementName': True, 'addToContextMenu': [aExport], #TODO: # 'sliding':True 'item': item }) p.setValue(item.getQColor()) p.sigValueChanged.connect( lambda param, val: param.opts['item'].setQColor(val)) self.setChecked(True)
def __init__(self, display): QtGui.QToolButton.__init__(self) self.display = display self.view = display.widget.view.vb #SET ICON icon = getattr(self, 'icon', None) if icon: if not os.path.exists(icon): icon = ICONFOLDER.join(icon) self.setIcon (QtGui.QIcon(icon)) #SET TOOLTIP if self.__doc__: #USING THE CLASS DOC t = '%s\n\t%s' %(self.__class__.__name__, self.__doc__) else: #USING THE CLASS NAME t =self.__class__.__name__ self.setToolTip(t) #SETUP CHECKABILITY: if hasattr(self, 'activate'): try: #if a tool has a method deactivate it should be checkable self.deactivate self.setCheckable(True) except AttributeError: self.deactivate = self._deactivate self.setCheckable(False) else: self.setPopupMode(QtGui.QToolButton.InstantPopup) self.clicked.connect(self.toggle)
def _changeColor(self, param, val): c = param.opts['curve'] pen = c.opts['pen'] if not isinstance(pen, QtGui.QPen): pen = QtGui.QPen() pen.setColor(val) c.setPen(pen)
def __init__(self): QtGui.QWidget.__init__(self) l = QtGui.QHBoxLayout() self.setLayout(l) l.setContentsMargins(0, 0, 0, 0) l.setSpacing(0) l.setDirection(QtGui.QBoxLayout.RightToLeft)
def __init__(self, MEDIA_FOLDER): QtGui.QWidget.__init__(self) self.is_active = True self.max_hist_len = 5 self._c = 0#count all added backups self.reset() self.setContentsMargins (0, 0, 0, 0) #HISTORY MENU self.menu = QtGui.QMenu() self.menu.aboutToShow.connect(self._showMenu) hl = QtGui.QHBoxLayout() hl.setContentsMargins (0, 0, 0, 0) self.setLayout(hl) icon_path = MEDIA_FOLDER.join("icons") #UNDO BUTTON self.btn_undo = QtGui.QToolButton() self.btn_undo.setAutoRaise(True) self.btn_undo.setToolTip('Undo') self.btn_undo.setIcon(QtGui.QIcon(icon_path.join('undo.svg'))) self.btn_undo.setShortcut (QtGui.QKeySequence.Undo) self.btn_undo.clicked.connect(self.undo) self.btn_undo.setEnabled(False) #MENU BUTTON self.btn_menu = QtGui.QToolButton() self.btn_menu.setAutoRaise(True) self.btn_menu.setFixedWidth(9) self.btn_menu.setToolTip('Undo/Redo options') self.btn_menu.setMenu(self.menu) self.btn_menu.setPopupMode(QtGui.QToolButton.InstantPopup) self.menu_options = _MenuOptions() self.menu_options.activate.stateChanged.connect(self.setActive) action = QtGui.QWidgetAction(self) action.setDefaultWidget(self.menu_options) self.menu.addAction(action) #REDO BUTTON self.btn_redo = QtGui.QToolButton() self.btn_redo.setAutoRaise(True) self.btn_redo.setToolTip('Redo') self.btn_redo.setIcon(QtGui.QIcon(icon_path.join('redo.svg'))) self.btn_redo.clicked.connect(self.redo) self.btn_redo.setShortcut (QtGui.QKeySequence.Redo) self.btn_redo.setEnabled(False) hl.addWidget(self.btn_undo) hl.addWidget(self.btn_menu) hl.addWidget(self.btn_redo)
def __init__(self, statusbar): QtGui.QWidget.__init__(self) self.statusbar = statusbar layout = QtGui.QHBoxLayout() layout.setContentsMargins(0, 0, 0, 0) self.setLayout(layout) self.bar = QtGui.QProgressBar() self.cancel = QtGui.QPushButton('Cancel') self.label = QtGui.QLabel() layout.addWidget(self.label) layout.addWidget(self.bar) layout.addWidget(self.cancel) self.statusbar.addPermanentWidget(self, stretch=1) self.hide()
def __init__(self, display): Tool.__init__(self, display) self._linked_display = None self._menu = QtGui.QMenu() self.setMenu(self._menu) self._menu.aboutToShow.connect(self._buildMenu)
def _fillMenuDuplicateToOtherWS(self): c = self.centralWidget() self._m_duplDisp.clear() for i in range(c.count()): if i != c.currentIndex(): t = '[%s]' % str(i + 1) a = QtGui.QAction(t, self._m_duplDisp) a.triggered.connect(lambda clicked, i=i, self=self: self. _moveCurrentDiplayToWorkspace(i)) self._m_duplDisp.addAction(a)
def _buildMenu(self): ''' Add an action for all other displays and connect it to self._linkView ''' self._menu.clear() ag = QtGui.QActionGroup(self._menu, exclusive=True) for d in self.display.workspace.displays(): if d != self.display: a = ag.addAction(QtGui.QAction(d.name(),self._menu, checkable=True)) self._menu.addAction(a) a.triggered.connect(lambda checked, d=d, self=self: self._linkView(d, checked)) if d == self._linked_display: a.setChecked(True)
def _newCurve(self): w = self.display.widget pen = mkPen(10, len(self.paths) + 2) self.curIndex = -1 p = self.pa.addChild({ 'name': str(len(self.paths) + 1), 'type': 'empty', 'highlight': True, 'removable': True, 'renamable': True, 'autoIncrementName': True }) path = FreehandItem(w.imageItem, pen) pAdd = p.addChild({ 'name': 'Add', 'type': 'action', }) pAdd.sigActivated.connect(self._appendToPath) pAdd.sigActivated.connect(self._menu.hide) pMod = p.addChild({'name': 'Modify', 'type': 'action'}) pMod.sigActivated.connect(self._modifyPath) pMod.sigActivated.connect(self._menu.hide) self._initDraw() self.paths.append(path) color = pen.color() pLineColor = p.addChild({ 'name': 'Line color', 'type': 'color', 'value': color, 'path': path }) pLineColor.sigValueChanged.connect(self._changeLineColor) br = QtGui.QColor(color) br.setAlpha(0) path.setBrush(br) pFillColor = p.addChild({ 'name': 'Fill color', 'type': 'color', 'value': br, 'path': path }) pFillColor.sigValueChanged.connect(self._changeFillColor) self.setChecked(True)
def __init__(self, gui): QtGui.QWidget.__init__(self) self.gui = gui self._last_active_display = None self._import_display = None self._n_displays = 0 #number of opened displays #BUILD MAIN DOCKAREAS: self.console = Console(self.gui.app.session.streamOut.message, self.gui.app.session.streamErr.message) self.console.setMinimumHeight(25) self.displayPrefTabs = DisplayPrefTabs() self.displayPrefTabs.currentChanged.connect(self.tabChanged) self.area_middle = MiddleDockArea() #LAYOUT: layout = QtGui.QHBoxLayout() #remove space between statusbar and console: m = layout.contentsMargins() m.setBottom(0) layout.setContentsMargins(m) self.setLayout(layout) #middle - displays and message self.middle_splitter = QtGui.QSplitter( QtCore.Qt.Orientation(0)) #0=horiz, 1=vert self.middle_splitter.addWidget(self.area_middle) self.middle_splitter.addWidget(self.console) #hide console by default self.middle_splitter.moveSplitter(0, 0) # (410, 1) #add areas to centralWidget self.vert_splitter = QtGui.QSplitter( QtCore.Qt.Orientation(1)) #0=horiz, 1=vert layout.addWidget(self.vert_splitter) self.vert_splitter.addWidget(self.displayPrefTabs) self.vert_splitter.addWidget(self.middle_splitter) #display pref tabs with fixed size: self.vert_splitter.setStretchFactor(1, 1) self.setActive()
def __init__(self, parent, scales, **kwargs): pgTextItem.__init__(self, **kwargs) self._parent = parent self.editor = QtGui.QLineEdit(parent) self.editor.setWindowFlags(QtCore.Qt.Popup) self.editor.setFocusProxy(parent) self.editor.editingFinished.connect(self.editingFinished) self.editor.installEventFilter(parent) self.editor.setText(self.textItem.toPlainText()) self.setFlag(self.ItemIgnoresTransformations, scales)
def paint(self, p, opt, widget): pen = QtGui.QPen(self.currentPen) pen.setWidth(pen.width() // 2) c = pen.color() r, g, b, a = c.getRgb() c.setRgb(255 - r, 255 - g, 255 - b) # invert pen.setColor(c) p.setPen(pen) p.setRenderHint(QtGui.QPainter.Antialiasing) p.drawPath(self.painterPath())
def __init__(self, display): Tool.__init__(self, display) self.n_slices = 0 self._ROIs = [] a_show = QtGui.QAction('show', self) a_show.setCheckable(True) a_show.setChecked(True) a_show.toggled.connect(self.toggleShow) self.addAction(a_show)
def __init__(self, imageDisplay): Tool.__init__(self, imageDisplay) self.scene = self.view.scene() #MENU: self.a_newDisplay = QtGui.QAction('result in new display', self) self.a_newDisplay.setCheckable(True) self.addAction(self.a_newDisplay) a_show = QtGui.QAction('show', self) a_show.setCheckable(True) a_show.setChecked(True) a_show.toggled.connect(self.toggleShow) self.addAction(a_show) self.n_slices = 0 self.slave = None self._POIS = []
def __init__(self, display): Tool.__init__(self, display) self.poiTextList = [] self.scene = self.view.scene() self._first_time = True self.actionHide = QtGui.QAction('show', self) self.actionHide.setCheckable(True) self.actionHide.setChecked(True) self.actionHide.triggered.connect(self.toggleShow) self.addAction(self.actionHide) areset = QtGui.QAction('reset', self) areset.triggered.connect(self.reset) self.addAction(areset) self.actionShowCoord = QtGui.QAction('show coordinates', self) self.actionShowCoord.setCheckable(True) self.actionShowCoord.setChecked(True) self.addAction(self.actionShowCoord)
def start(self, filenames): self.filenames = filenames if self.preferences and self.forceSetup and self._firstTime: d = QtGui.QDialog() d.setWindowTitle('Import preferences') l = QtGui.QVBoxLayout() t = ParameterTree(self.preferences) b = QtGui.QPushButton('OK') b.clicked.connect(d.accept) l.addWidget(t) l.addWidget(b) d.setLayout(l) d.accepted.connect(self._start) d.exec_() else: self._start()
def _allowRabbitMQchanged(self, checked): if checked: try: self.rabbitMQServer.start() except Exception, err: #maybe rabbitMQ is not installed self._errm = QtGui.QErrorMessage( ) #needs to assign to self, otherwise garbage collected self._errm.showMessage(str(err)) self.cb_allowRabbit.setChecked(False) self.cb_allowRabbit.setEnabled(False) return
def __init__(self, import_pref, fnames): QtGui.QDialog.__init__(self) l = QtGui.QVBoxLayout() self.setLayout(l) p = self.pref = import_pref self.dial_pref = p.__class__(p.gui) p.updateSettings(self.dial_pref) l.addWidget(self.dial_pref) if len(fnames) > 1: self.setWindowTitle('Import %s File(s)' % len(fnames)) else: self.setWindowTitle('Import File') self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint) self.btn_done = QtGui.QPushButton('Done') self.btn_done.clicked.connect(self.accept) l.addWidget(self.btn_done)
def _add(self, typ, name, state): self.curIndex = -1 p = self.pa.addChild({ 'name': '[%i] %s' % (len(self.paths) + 1, name), 'type': 'empty', 'highlight': True, 'removable': True, 'renamable': True, 'autoIncrementName': True }) if typ == 'Freehand': path = self._addFreehand(p, state) if path.isEmpty(): self._initFreehand() elif typ == 'Grid': path = self._addGrid(p, state) elif typ == 'Isolines': path = self._addIso(p, state) elif typ == 'Rectangle': path = self._addROI(_Rect, p, state) elif typ == 'Ellipse': path = self._addROI(_Ellipse, p, state) self.paths.append(path) color = state['pen'].color() pLineColor = p.addChild({ 'name': 'Line color', 'type': 'color', 'value': color, 'path': path }) pLineColor.sigValueChanged.connect(self._changeLineColor) if 'brush' in state: br = state['brush'].color() else: br = QtGui.QColor(color) br.setAlpha(25) path.setBrush(br) pFillColor = p.addChild({ 'name': 'Fill color', 'type': 'color', 'value': br, 'path': path }) pFillColor.sigValueChanged.connect(self._changeFillColor) self.setChecked(True)
def __init__(self): QtGui.QWidget.__init__(self) l = QtGui.QVBoxLayout() self.setLayout(l) title = QtGui.QLabel('<b>Undo / Redo</b>') self.activate = QtGui.QCheckBox('Activate') self.activate.setChecked(True) self.activate.stateChanged.connect(self._enableLenHistory) self._label_lenHist = QtGui.QLabel('History Length') self.lenHistory = QtGui.QSpinBox() self.lenHistory.setRange(1, 100) self.lenHistory.setValue(5) l_history = QtGui.QHBoxLayout() l_history.addWidget(self._label_lenHist) l_history.addWidget(self.lenHistory) l.addWidget(title) l.addWidget(self.activate) l.addLayout(l_history)
def _setColorViaHistogram(self): #get boundaries from the histogram mn,mx = self.histogram.getLevels() if mn <= self.histogramPos <= mx: #calc x as relative position (0-1) between the boundaries if self.histogramPos == mn: x = 0 else: x = (self.histogramPos-mn) / (mx-mn) self.color = self.histogram.gradient.getColor(x).rgb() self.updateLayer() else: self.qimage.fill(QtGui.QColor(0,0,0,0).rgba()) self.vb.updateViewRange()