class StandaloneHistoryApp(CacheClient): parameters = { 'views': Param('Strings specifying views (from command line)', type=listof(str)), } def doInit(self, mode): self._qtapp = QApplication(sys.argv) self._qtapp.setOrganizationName('nicos') self._qtapp.setApplicationName('history') self._window = StandaloneHistoryWindow(self) # if no cache was given on the command line... if not self._config['cache']: dlg = SettingsDialog(self._window) dlg.exec_() self._setROParam('cache', dlg.cacheBox.currentText()) self._setROParam('prefix', dlg.prefixEdit.text()) CacheClient.doInit(self, mode) def getDeviceList(self, only_explicit=True, special_clause=None): devlist = [ key[:-6] for (key, _) in self.query_db('') if key.endswith('/value') ] if special_clause: devlist = [ dn for dn in devlist if eval(special_clause, {'dn': dn}) ] return sorted(devlist) def getDeviceParam(self, devname, parname): return self.get(devname, parname) def getDeviceParams(self, devname): ldevname = devname.lower() index = len(ldevname) + 1 return { key[index:]: value for (key, value) in self.query_db('') if key.startswith(ldevname + '/') } def getDeviceParamInfo(self, _): return {} # we can't deliver this info from the cache alone def start(self): self._startup_done.wait(2) self._window.openViews(self.views) self._window.show() try: self._qtapp.exec_() except KeyboardInterrupt: pass self._stoprequest = True def _propagate(self, data): self._window.newValue.emit(data)
class CacheInspector(CICacheClient): def doInit(self, mode): CICacheClient.doInit(self, self._mode) self._qtapp = QApplication(sys.argv) self._qtapp.setOrganizationName('nicos') self._qtapp.setApplicationName('cacheinspector') self._window = MainWindow(self) self._window.setWindowIcon(QIcon(':/inspector')) session._qthandler.setStatusbar(self._window.statusBar()) def start(self): self._window.show() if self.cache: self.connect(self.cache) try: self._qtapp.exec_() except KeyboardInterrupt: pass self._stoprequest = True
def main(): app = QApplication(sys.argv) myWindow = MainWindow() myWindow.resize(800, 600) myWindow.show() sys.exit(app.exec_())
return self._setStart(v) elif index == self._SPLIT_END: _lockWidth(self._head) if v <= self.start(): return self._setEnd(v) _unlockWidth(self._tail) _unlockWidth(self._head) _unlockWidth(self._handle) #------------------------------------------------------------------------------- # MAIN #------------------------------------------------------------------------------- if __name__ == '__main__': app = QApplication(sys.argv) rs = QRangeSlider() rs.show() rs.setRange(15, 35) rs.setBackgroundStyle( 'background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 #222, stop:1 #333);' ) rs.handle.setStyleSheet( 'background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 #282, stop:1 #393);' ) app.exec_()
def main(argv): global log # pylint: disable=global-statement userpath = path.join(path.expanduser('~'), '.config', 'nicos') # Set up logging for the GUI instance. initLoggers() log = NicosLogger('gui') log.parent = None log.setLevel(logging.INFO) log.addHandler(ColoredConsoleHandler()) log.addHandler( NicosLogfileHandler(path.join(userpath, 'log'), 'gui', use_subdir=False)) # set up logging for unhandled exceptions in Qt callbacks def log_unhandled(*exc_info): traceback.print_exception(*exc_info) log.exception('unhandled exception in QT callback', exc_info=exc_info) sys.excepthook = log_unhandled app = QApplication(argv, organizationName='nicos', applicationName='gui') opts = parseargs() if opts.configfile is None: try: config.apply() except RuntimeError: pass # If "demo" is detected automatically, let the user choose their # instrument configuration. need_dialog = config.instrument is None or \ (config.setup_package == 'nicos_demo' and config.instrument == 'demo' and 'INSTRUMENT' not in os.environ) if need_dialog: opts.configfile = InstrSelectDialog.select( 'Your instrument could not be automatically detected.') if opts.configfile is None: return else: opts.configfile = path.join(config.setup_package_path, config.instrument, 'guiconfig.py') with open(opts.configfile, 'rb') as fp: configcode = fp.read() gui_conf = processGuiConfig(configcode) gui_conf.stylefile = '' if gui_conf.options.get('facility') in ['ess', 'sinq']: gui_conf.stylefile = f"{config.nicos_root}" \ f"/nicos/clients/flowui/guiconfig.qss" stylefiles = [ path.join(userpath, 'style-%s.qss' % sys.platform), path.join(userpath, 'style.qss'), path.splitext(opts.configfile)[0] + '-%s.qss' % sys.platform, path.splitext(opts.configfile)[0] + '.qss', ] for stylefile in [gui_conf.stylefile] or stylefiles: if path.isfile(stylefile): try: with open(stylefile, 'r', encoding='utf-8') as fd: app.setStyleSheet(fd.read()) gui_conf.stylefile = stylefile break except Exception: log.warning('Error setting user style sheet from %s', stylefile, exc=1) mainwindow_cls = _mainwindow_cls.get( gui_conf.options.get('facility', 'default')) mainwindow = mainwindow_cls(log, gui_conf, opts.viewonly, opts.tunnel) log.addHandler(DebugHandler(mainwindow)) if opts.connect: parsed = parseConnectionString(opts.connect, DEFAULT_PORT) if parsed: cdata = ConnectionData(**parsed) cdata.viewonly = opts.viewonly mainwindow.setConnData(cdata) if cdata.password is not None: # we have a password, connect right away mainwindow.client.connect(mainwindow.conndata) else: # we need to ask for password, override last preset (uses given # connection data) and force showing connect window mainwindow.lastpreset = '' mainwindow.autoconnect = True mainwindow.startup() return app.exec_()