def qapp(pytestconfig): global application application = QtWidgets.QApplication.instance() if application is None: application = PyDMApplication(use_main_window=False) typhos.use_stylesheet(pytestconfig.getoption('--dark')) return application
def qapp(pytestconfig): global application if application: pass else: application = PyDMApplication(use_main_window=False) typhos.use_stylesheet(pytestconfig.getoption('--dark')) return application
def main(project, *, plcs=None, include=None, exclude=None, macro=None, flat=False): macros = util.split_macros(macro or []) include = include or [] exclude = exclude or [] solution_path, projects = util.get_tsprojects_from_filename(project.name) devices = [] for tsproj_project in projects: parsed_tsproj = pytmc.parser.parse(tsproj_project) for plc_name, plc_project in parsed_tsproj.plcs_by_name.items(): logger.debug('Project: %s PLC: %s', tsproj_project, plc_name) if plcs and plc_name not in plcs: logger.debug('Skipping; not in valid list: %s', plcs) continue try: device = ophyd_device_from_plc(plc_name, plc_project, macros, includes=include, excludes=exclude, flat=flat) except Exception: logger.exception('Failed to create device for plc %s', plc_name) raise for sig in typhos.utils.get_all_signals_from_device(device): logger.debug("Signal: %s", sig) devices.append(device) typhos.cli.get_qapp() typhos.use_stylesheet() suite = typhos.TyphosSuite.from_devices(devices) return typhos.cli.launch_suite(suite)
def typhos_cli_setup(args): """Setup logging and style.""" # Logging Level handling logging.getLogger().addHandler(logging.NullHandler()) shown_logger = logging.getLogger('typhos') if args.verbose: level = "DEBUG" log_fmt = ('[%(asctime)s] - %(levelname)s - Thread (%(thread)d - ' '%(threadName)s ) - %(name)s -> %(message)s') else: level = "INFO" log_fmt = '[%(asctime)s] - %(levelname)s - %(message)s' coloredlogs.install(level=level, logger=shown_logger, fmt=log_fmt) logger.debug("Set logging level of %r to %r", shown_logger.name, level) # Deal with stylesheet qapp = get_qapp() logger.debug("Applying stylesheet ...") typhos.use_stylesheet(dark=args.dark) if args.stylesheet: logger.info("Loading QSS file %r ...", args.stylesheet) with open(args.stylesheet, 'r') as handle: qapp.setStyleSheet(handle.read())
def launch(beamline, *, toolbar=None, row_group_key="location_group", col_group_key="functional_group", log_level="INFO", dark=False): # Re-enable sigint (usually blocked by pyqt) signal.signal(signal.SIGINT, signal.SIG_DFL) # Silence the logger from pyPDB.dbd.yacc logging.getLogger("pyPDB.dbd.yacc").setLevel(logging.WARNING) logging.getLogger("ophyd").setLevel(logging.WARNING) lucid_logger = logging.getLogger('') handler = logging.StreamHandler() formatter = logging.Formatter( '[%(asctime)s] [%(levelname)-8s] - %(message)s') handler.setFormatter(formatter) lucid_logger.addHandler(handler) lucid_logger.setLevel(log_level) handler.setLevel(log_level) app = QtWidgets.QApplication([]) app.setOrganizationName("SLAC National Accelerator Laboratory") app.setOrganizationDomain("slac.stanford.edu") app.setApplicationName("LUCID") typhos.use_stylesheet(dark=dark) splash = lucid.splash.Splash() splash.show() splash.update_status("Creating Main Window") window = lucid.main_window.LucidMainWindow(dark=dark) window.setWindowTitle(f"LUCID - {beamline}") # Install exception hook handler with dialog popup exception.install(use_default_handler=False) # Use custom exception handler exception.ExceptionDispatcher().newException.connect(window.handle_error) grid = lucid.overview.IndicatorGridWithOverlay(toolbar_file=toolbar) splash.update_status(f"Loading {beamline} devices") # callback list for Happi Loader cbs = [grid.add_from_dict] loader = HappiLoader(beamline=beamline, group_keys=(row_group_key, col_group_key), callbacks=cbs) def grid_to_dock(): dock_widget = QtAds.CDockWidget('Grid') dock_widget.setToggleViewActionMode(QtAds.CDockWidget.ActionModeShow) dock_widget.setFeature(dock_widget.DockWidgetClosable, False) dock_widget.setFeature(dock_widget.DockWidgetFloatable, False) dock_widget.setFeature(dock_widget.DockWidgetMovable, False) dock_widget.setMinimumSizeHintMode( QtAds.CDockWidget.MinimumSizeHintFromContent) dock_widget.setWidget(grid.frame, QtAds.CDockWidget.eInsertMode.ForceNoScrollArea) window.dock_manager.addDockWidget(QtAds.LeftDockWidgetArea, dock_widget) loader.finished.connect(splash.accept) loader.finished.connect(grid_to_dock) loader.finished.connect(window.show) loader.start() app.exec_()
import numpy as np from qtpy.QtWidgets import QApplication import typhos from ophyd import Component as Cpt from ophyd import Device, Signal from typhos.utils import SignalRO class Sample(Device): """Simulated Device""" readback = Cpt(SignalRO, value=1) setpoint = Cpt(Signal, value=2) waveform = Cpt(SignalRO, value=np.random.randn(100, )) image = Cpt(SignalRO, value=np.abs(np.random.randn(100, 100)) * 455) # Create my device without a prefix sample = Sample('', name='sample') if __name__ == '__main__': # Create my application app = QApplication(sys.argv) typhos.use_stylesheet() # Create my panel panel = typhos.TyphosSignalPanel.from_device(sample) panel.sortBy = panel.byName # Execute panel.show() app.exec_()
def __init__(self, controller, beamline=None, parent=None, dark=True): super().__init__(parent=parent) # Store Lightpath information self.light = controller self.path = None self.detail_screen = None self.device_buttons = dict() self._lock = threading.Lock() # Create empty layout self.lightLayout = QHBoxLayout() self.lightLayout.setSpacing(1) self.widget_rows.setLayout(self.lightLayout) self.device_types.setLayout(QGridLayout()) self.overview.setLayout(QHBoxLayout()) self.overview.layout().setSpacing(2) self.overview.layout().setContentsMargins(2, 2, 2, 2) # Setup the fancy overview slider slide_scroll = self.scroll.horizontalScrollBar() self.slide.setRange(slide_scroll.minimum(), slide_scroll.maximum()) self.slide.sliderMoved.connect(slide_scroll.setSliderPosition) slide_scroll.rangeChanged.connect(self.slide.setRange) slide_scroll.valueChanged.connect(self.slide.setSliderPosition) # Add destinations for line in self.destinations(): self.destination_combo.addItem(line) # Connect signals to slots self.destination_combo.currentIndexChanged.connect( self.change_path_display) self.device_combo.activated[str].connect(self.focus_on_device) self.impediment_button.pressed.connect(self.focus_on_device) self.remove_check.toggled.connect(self.filter) self.upstream_check.toggled.connect(self.filter) self.detail_hide.clicked.connect(self.hide_detailed) # Store LightRow objects to manage subscriptions self.rows = list() # Select the beamline to begin with beamline = beamline or self.destinations()[0] try: idx = self.destinations().index(beamline.upper()) except ValueError: logger.error("%s is not a valid beamline", beamline) idx = 0 # Move the ComboBox self.destination_combo.setCurrentIndex(idx) # Add all of our device type options max_columns = 3 for i, row in enumerate(np.array_split(self.shown_types, max_columns)): for j, device_type in enumerate(row): # Add box to layout box = QCheckBox(device_type.__name__) box.setChecked(True) self.device_types.layout().addWidget(box, j, i) # Hook up box to hide function self.device_buttons[box] = device_type box.toggled.connect(self.filter) # Setup the UI self.change_path_display() self.resizeSlider() # Change the stylesheet if dark: typhos.use_stylesheet(dark=True)