def setupUi(self, Form): Form.setObjectName("QRangeSlider") Form.resize(300, 30) Form.setStyleSheet(DEFAULT_CSS) self.gridLayout = QGridLayout(Form) self.gridLayout.setContentsMargins(0, 0, 0, 0) self.gridLayout.setSpacing(0) self.gridLayout.setObjectName("gridLayout") self._splitter = QSplitter(Form) self._splitter.setMinimumSize(QSize(0, 0)) self._splitter.setMaximumSize(QSize(16777215, 16777215)) self._splitter.setOrientation(Qt.Horizontal) self._splitter.setObjectName("splitter") self._head = QGroupBox(self._splitter) self._head.setTitle("") self._head.setObjectName("Head") self._handle = QGroupBox(self._splitter) self._handle.setTitle("") self._handle.setObjectName("Span") self._tail = QGroupBox(self._splitter) self._tail.setTitle("") self._tail.setObjectName("Tail") self.gridLayout.addWidget(self._splitter, 0, 0, 1, 1) self.retranslateUi(Form) QMetaObject.connectSlotsByName(Form)
def __init__(self, parent, connpresets, lastpreset, lastdata, tunnel=''): QDialog.__init__(self, parent) loadUi(self, 'dialogs/auth.ui') self.connpresets = connpresets if isinstance(lastpreset, QPyNullVariant): lastpreset = None pal = self.quickList.palette() pal.setColor(QPalette.Window, pal.color(QPalette.Base)) self.quickList.setPalette(pal) if len(connpresets) < 3: self.quickList.hide() else: self.quickList.setStyleSheet('padding: 10px 5px;') self.quickList.clear() maxw = 64 icon = QIcon(':/appicon') metric = QFontMetrics(self.quickList.font()) for preset in sorted(connpresets): item = QListWidgetItem(preset, self.quickList) item.setIcon(icon) maxw = max(maxw, metric.width(preset)) self.quickList.setGridSize(QSize(maxw + 8, 72)) # the automatic sizing still leads to a vertical scrollbar hint = self.quickList.sizeHint() hint.setHeight(hint.height() + 50) hint.setWidth(max(4.7 * maxw, 330)) self.quickList.setMinimumSize(hint) self.resize(self.sizeHint()) self.presetOrAddr.addItems(sorted(connpresets)) self.presetOrAddr.setEditText(lastpreset) if not lastpreset and lastdata: # if we have no stored last preset connection, put in the raw data self.presetOrAddr.setEditText('%s:%s' % (lastdata.host, lastdata.port)) self.viewonly.setChecked(lastdata.viewonly) self.userName.setText(lastdata.user) self.password.setFocus() self.viaFrame.setHidden(not tunnel) if tunnel: host, username, password = splitTunnelString(tunnel) self.remotePassword.setText(password) if not password: self.remotePassword.setFocus() self.remoteUserName.setText(username) if not username: self.remoteUserName.setFocus() self.remoteHost.setText(host) if not host: self.remoteHost.setFocus() self.presetFrame.hide() self.resize(QSize(self.width(), self.minimumSize().height()))
def propertyUpdated(self, pname, value): if pname == 'dev': if value: self.key = value + '.value' self.statuskey = value + '.status' elif pname == 'width': if value < 0: self.reinitLayout() else: onechar = QFontMetrics(self.valueFont).width('0') self.valuelabel.setMinimumSize(QSize(onechar * (value + .5), 0)) elif pname == 'istext': self.valuelabel.setFont(value and self.font() or self.valueFont) self.width = self.width elif pname == 'valueFont': self.valuelabel.setFont(self.valueFont) self.width = self.width # update char width calculation elif pname == 'showName': self.namelabel.setVisible(value) elif pname == 'showStatus': if not value: setBothColors(self.valuelabel, (self._colorscheme['fore'][UNKNOWN], self._colorscheme['back'][UNKNOWN])) elif pname == 'horizontal': self.reinitLayout() if pname in ('dev', 'name', 'unit'): self.update_namelabel() NicosWidget.propertyUpdated(self, pname, value)
def setCornerLabel(self, text): self._cornerText = text opt = QStyleOptionHeader() opt.text = text size = self._cornerButton.style().sizeFromContents( QStyle.CT_HeaderSection, opt, QSize(), self._cornerButton) self.verticalHeader().setMinimumWidth(size.width())
def _init_toolbar(self): self.statusLabel = QLabel('', self, pixmap=QPixmap(':/disconnected'), margin=5, minimumSize=QSize(30, 10)) self.toolbar = self.toolBarMain self.toolbar.addWidget(self.statusLabel) self.setStatus('disconnected')
def _init_toolbar(self): self.statusLabel = QLabel('', self, pixmap=QPixmap(':/disconnected'), margin=5, minimumSize=QSize(30, 10)) self.statusLabel.setStyleSheet('color: white') self.toolbar = self.toolBarRight self.toolbar.addWidget(self.statusLabel) self.setStatus('disconnected')
def propertyUpdated(self, pname, value): if pname == 'plotwindow': self._showdate = value > 24 * 3600 self._showsecs = value < 300 elif pname in ('width', 'height'): self.setMinimumSize( QSize(self._scale * (self.props['width'] + .5), self._scale * (self.props['height'] + .5))) elif pname == 'legend': self.plot.setLegend(value) NicosWidget.propertyUpdated(self, pname, value)
def __init__(self, parent): QMainWindow.__init__(self, parent) DlgUtils.__init__(self, 'Live data') self.panel = parent layout1 = QVBoxLayout() self.plot = QwtPlot(self) layout1.addWidget(self.plot) self.curve = QwtPlotCurve() self.curve.setRenderHint(QwtPlotCurve.RenderAntialiased) self.curve.attach(self.plot) self.marker = QwtPlotMarker() self.marker.attach(self.plot) self.markerpen = QPen(Qt.red) self.marker.setSymbol( QwtSymbol(QwtSymbol.Ellipse, QBrush(), self.markerpen, QSize(7, 7))) self.zoomer = QwtPlotZoomer(self.plot.canvas()) self.zoomer.setMousePattern(QwtPlotZoomer.MouseSelect3, Qt.NoButton) self.picker = QwtPlotPicker(self.plot.canvas()) self.picker.setSelectionFlags(QwtPlotPicker.PointSelection | QwtPlotPicker.ClickSelection) self.picker.setMousePattern(QwtPlotPicker.MouseSelect1, Qt.MidButton) self.picker.selected.connect(self.pickerSelected) layout2 = QHBoxLayout() layout2.addWidget(QLabel('Scale:', self)) self.scale = QComboBox(self) self.scale.addItems([ 'Single detectors, sorted by angle', 'Scattering angle 2theta (deg)', 'Q value (A-1)' ]) self.scale.currentIndexChanged[int].connect(self.scaleChanged) layout2.addWidget(self.scale) layout2.addStretch() self.scaleframe = QFrame(self) self.scaleframe.setLayout(layout2) self.scaleframe.setVisible(False) layout1.addWidget(self.scaleframe) mainframe = QFrame(self) mainframe.setLayout(layout1) self.setCentralWidget(mainframe) self.setContentsMargins(6, 6, 6, 6) plotfont = scaledFont(self.font(), 0.7) self.plot.setAxisFont(QwtPlot.xBottom, plotfont) self.plot.setAxisFont(QwtPlot.yLeft, plotfont) self.plot.setCanvasBackground(Qt.white) self.resize(800, 200) self._detinfo = None self._anglemap = None self._infowindow = None self._infolabel = None self._xs = self._ys = None self._type = None
def setPicture(self): size = QSize(self.props['width'] * self._scale, self.props['height'] * self._scale) if isfile(self._filePath): pixmap = QPixmap(self._filePath) else: pixmap = QPixmap(size) pixmap.fill() if size.isEmpty(): self.piclabel.setPixmap(pixmap) else: self.piclabel.setPixmap(pixmap.scaled(size)) self.piclabel.resize(self.piclabel.sizeHint())
def setScript(self, script): self.traceView.clear() lines = script.splitlines() longest = len(str(len(lines))) padding = ' ' * (longest + 3) height = QFontMetrics(self.traceView.font()).height() for (i, line) in enumerate(lines): item = QListWidgetItem(self.otherlineicon, padding + line, self.traceView) item.setSizeHint(QSize(-1, height)) item.setData(Qt.UserRole, '%*d |' % (longest, i+1)) self.traceView.addItem(item) self.current_line = -1
def recalculateBackgroundArea(self): if self._background_image is None: return # recalculate the rect to draw the background image into size = self._background_image.size() # scale to viewport size and add some margin size.scale(self.viewport().size() - QSize(30, 30), Qt.KeepAspectRatio) # center background image p = (self.viewport().size() - size) / 2 self._background_image_area = QRect(p.width(), p.height(), size.width(), size.height())
def setScript(self, script): self.traceView.clear() lines = script.splitlines() longest = len(str(len(lines))) padding = ' ' * (longest + 3) metrics = QFontMetrics(self.traceView.font()) height = metrics.height() lineno_width = metrics.size(0, ' ' * (longest + 2)).width() self.traceView.itemDelegate()._margin_offset = lineno_width for (i, line) in enumerate(lines): item = QListWidgetItem(self.otherlineicon, padding + line, self.traceView) item.setSizeHint(QSize(-1, height)) item.setData(Qt.UserRole, '%*d' % (longest, i + 1)) self.traceView.addItem(item) self.current_line = -1
def viewTextFile(self, fname): with open(fname) as f: contents = f.read() qd = QDialog(self, 'PreviewDlg', True) qd.setCaption('File preview') qd.resize(QSize(500, 500)) lay = QVBoxLayout(qd, 11, 6, 'playout') lb = QLabel(qd, 'label') lb.setText('Viewing %s:' % fname) lay.addWidget(lb) tx = QTextEdit(qd, 'preview') tx.setReadOnly(1) tx.setText(contents) font = QFont(tx.font()) font.setFamily('monospace') tx.setFont(font) lay.addWidget(tx) btn = QPushButton(qd, 'ok') btn.setAutoDefault(1) btn.setDefault(1) btn.setText('Close') btn.clicked.connect(qd.accept) lay.addWidget(btn, 0, QWidget.AlignRight) qd.show()
def sizeHint(self): return QSize(self._scale * self.props['width'], self._scale * self.props['height'])
def __init__(self, log, gui_conf, viewonly=False, tunnel=''): QMainWindow.__init__(self) DlgUtils.__init__(self, 'NICOS') loadUi(self, self.ui) # set app icon in multiple sizes icon = QIcon() icon.addFile(':/appicon') icon.addFile(':/appicon-16') icon.addFile(':/appicon-48') self.setWindowIcon(icon) if tunnel and SSHTunnelForwarder is None: self.showError('You want to establish a connection to NICOS via ' "a SSH tunnel, but the 'sshtunnel' module is not " 'installed. The tunneling feature will disabled.') self.tunnel = tunnel if SSHTunnelForwarder is not None else '' self.tunnelServer = None # hide admin label until we are connected as admin self.adminLabel.hide() # our logger instance self.log = log # window for displaying errors self.errorWindow = None # window for "prompt" event confirmation self.promptWindow = None # debug console window, if opened self.debugConsole = None # log messages sent by the server self.messages = [] # are we in expert mode? (always false on startup) self.expertmode = False # no wrapping at startup self.allowoutputlinewrap = False # set-up the initial connection data self.conndata = ConnectionData(host='localhost', port=1301, user='******', password=None, viewonly=viewonly) # state members self.current_status = None # connect the client's events self.client = NicosGuiClient(self, self.log) self.client.error.connect(self.on_client_error) self.client.broken.connect(self.on_client_broken) self.client.failed.connect(self.on_client_failed) self.client.connected.connect(self.on_client_connected) self.client.disconnected.connect(self.on_client_disconnected) self.client.status.connect(self.on_client_status) self.client.showhelp.connect(self.on_client_showhelp) self.client.clientexec.connect(self.on_client_clientexec) self.client.plugplay.connect(self.on_client_plugplay) self.client.watchdog.connect(self.on_client_watchdog) self.client.prompt.connect(self.on_client_prompt) # data handling setup self.data = DataHandler(self.client) # panel configuration self.gui_conf = gui_conf self.initDataReaders() self.mainwindow = self # determine if there is an editor window type, because we would like to # have a way to open files from a console panel later self.editor_wintype = self.gui_conf.find_panel( ('editor.EditorPanel', 'nicos.clients.gui.panels.editor.EditorPanel')) self.history_wintype = self.gui_conf.find_panel( ('history.HistoryPanel', 'nicos.clients.gui.panels.history.HistoryPanel')) # additional panels self.panels = [] self.splitters = [] self.windowtypes = [] self.windows = {} # setting presets self.instrument = self.gui_conf.name self.createWindowContent() # timer for reconnecting self.reconnectTimer = QTimer(singleShot=True, timeout=self._reconnect) self._reconnect_count = 0 self._reconnect_time = 0 # setup tray icon self.trayIcon = QSystemTrayIcon(self) self.trayIcon.activated.connect(self.on_trayIcon_activated) self.trayMenu = QMenu(self) nameAction = self.trayMenu.addAction(self.instrument) nameAction.setEnabled(False) self.trayMenu.addSeparator() toggleAction = self.trayMenu.addAction('Hide main window') toggleAction.setCheckable(True) toggleAction.triggered[bool].connect( lambda hide: self.setVisible(not hide)) self.trayIcon.setContextMenu(self.trayMenu) self.statusLabel = QLabel('', self, pixmap=QPixmap(':/disconnected'), margin=5, minimumSize=QSize(30, 10)) self.toolBarMain.addWidget(self.statusLabel) # help window self.helpWindow = None # watchdog window self.watchdogWindow = None # plug-n-play notification windows self.pnpWindows = {} # create initial state self.setStatus('disconnected')
def __init__(self, icon, parent=None): QAbstractButton.__init__(self, parent) self.icon = icon self._size = QSize(100, 100)
def __init__(self, icon, parent=None): super(PicButton, self).__init__(parent) self.icon = icon self._size = QSize(100, 100)
def sizeHint(self): return QSize(120, 120)
def tabSizeHint(self, index): fm = self.fontMetrics() tabSize = fm.boundingRect(self.tabText(index) or 'Ag').size() + QSize( 20, 10) return tabSize
def sizeHint(self): return QSize( self._scale * self.props['width'], self._scale * 2.5 * self.props['height'] + (self.props['name'] and 2.5 * self._scale or 0))
def sizeHint(self): return QSize( self.props['width'] * self._scale + 10, self.props['height'] * self._scale + (self.props['smalldet'] and 50 or 0) + (self.props['name'] and self._scale * 2.5 or 0) + 40)
def resizeEvent(self, event): # Maintain aspect ratio when resizing new_size = QSize(event.size().width(), event.size().width()) self.resize(new_size)
def sizeHint(self): if self.layout() is None: return QSize(24, 24) return QLabel.sizeHint(self)
def minimumSizeHint(self): return QSize(8, 8)
def sizeHint(self): return QSize(self.codeEditor.lineNumberAreaWidth(), 0)
def sizeHint(self): return QSize( self.props['width'] * self._scale, self.props['height'] * self._scale + (self.props['name'] and self._scale * 2.5 or 0))
def on_expandBtn_clicked(self): self.table.setMinimumSize(QSize(0, self.table.height() + 100))
def sizeHint(self, option, index): html = index.data(Qt.UserRole + 1) document = QTextDocument() document.setDefaultFont(option.font) document.setHtml(html) return QSize(document.idealWidth(), int(document.size().height()))