def _find_default_screen(self):
        """Screen: loads the screen ID for the screen where the application window should appear by default

        NOTE: this helper method assumes that the caller has already changed the active context of
        the self.settings object to point to the window we need to process
        """
        groups = self._settings.childGroups()
        default_group_id = self._settings.value("LastScreen")

        all_screens = dict()
        for cur_screen in QApplication.screens():
            all_screens[generate_screen_id(cur_screen)] = cur_screen

        # Favor the last used screen if it is still available
        if default_group_id in all_screens.keys():
            self._log.debug(
                f"Loading layout for previously used screen {default_group_id}"
            )
            return all_screens[default_group_id]

        # if last used screen is not found, see if we have any cached screen details
        # that map to one of our available screen
        cached_screen_ids = set(all_screens.keys()).intersection(set(groups))

        # If so, return the first match
        if cached_screen_ids:
            return all_screens[cached_screen_ids[0]]

        # If all else fails and there are no defaults to be found, return the default screen
        default_screen_id = generate_screen_id(QApplication.screens()[0])
        self._log.debug("Loading a default screen layout")
        return all_screens[default_screen_id]
Esempio n. 2
0
    def main(args):
        """ Runs the XSpecGui on an input file
        """
        import sys
        import numpy as np

        from qtpy.QtWidgets import QApplication

        from linetools.guis.xspecgui import XSpecGui

        from pypeit import specobjs
        from pypeit import msgs

        sobjs = specobjs.SpecObjs.from_fitsfile(args.file, chk_version=False)

        # List only?
        if args.list:
            print("Showing object names for input file...")
            for ii in range(len(sobjs)):
                line = "EXT{:07d} = {}".format(ii + 1, sobjs[ii].NAME)
                if sobjs[ii].RA is not None:
                    line += " {:0.5f} {:0.5f} {:s}".format(
                        sobjs[ii].RA, sobjs[ii].DEC, sobjs[ii].MASKDEF_OBJNAME)
                if sobjs[ii].MASKDEF_EXTRACT is not None and sobjs[
                        ii].MASKDEF_EXTRACT is True:
                    line += " maskdef_extract"
                if sobjs[ii].hand_extract_flag is True:
                    line += " manual_extract"
                #
                print(line)
            return

        if args.obj is not None:
            exten = np.where(sobjs.NAME == args.obj)[0][0]
            if exten < 0:
                msgs.error("Bad input object name: {:s}".format(args.obj))
        else:
            exten = args.exten - 1  # 1-index in FITS file

        # Check Extraction
        if args.extract == 'OPT':
            if sobjs[exten][
                    'OPT_WAVE'] is None:  #not in sobjs[exten]._data.keys():
                msgs.error(
                    "Spectrum not extracted with OPT.  Try --extract BOX")

        spec = sobjs[exten].to_xspec1d(extraction=args.extract,
                                       fluxed=args.flux)

        # Setup
        app = QApplication(sys.argv)
        # Screen dimensions
        width = app.screens()[0].geometry().width()
        scale = 2. * (width / 3200.)

        # Launch
        gui = XSpecGui(spec)  #, screen_scale=scale)
        gui.show()
        app.exec_()
Esempio n. 3
0
    def __init__(self, parent=None, prefix=VACA_PREFIX):
        """Init."""
        super().__init__(parent)
        self._prefix = prefix

        # window settings
        self.setObjectName('ASApp')
        self.setWindowTitle('Sirius Launcher')
        self.setWindowIcon(
            qta.icon('mdi.rocket', color=get_appropriate_color('AS')))

        screens = QApplication.screens()
        screen_idx = 3 if len(screens) == 8 else 0
        topleft = screens[screen_idx].geometry().topLeft()
        self.move(topleft.x(), topleft.y() + 20)
        self.setWindowFlags(Qt.WindowStaysOnTopHint)

        # menubar
        menubar = get_object(ismenubar=True)
        menubar.setNativeMenuBar(False)
        self.setMenuBar(menubar)
        self._setupUi()

        # connect window signals
        connect_newprocess(self,
                           'sirius-hla-as-ap-monitor.py',
                           parent=self,
                           signal=self.showMonitor)
        connect_newprocess(self,
                           'sirius-hla-si-ap-genstatus.py',
                           parent=self,
                           signal=self.showStatus)
        connect_newprocess(self,
                           'sirius-hla-li-eg-control.py',
                           parent=self,
                           signal=self.showEgun)

        # set focus policy
        self.setFocus(True)
        self.setFocusPolicy(Qt.StrongFocus)
Esempio n. 4
0
    def __init__(self, model):
        """Initialize MNELAB main window.

        Parameters
        ----------
        model : mnelab.model.Model instance
            The main window needs to connect to a model containing all data
            sets. This decouples the GUI from the data (model/view).
        """
        super().__init__()
        self.model = model  # data model
        self.setWindowTitle("MNELAB")

        # restore settings
        settings = read_settings()
        self.recent = settings["recent"]  # list of recent files
        if settings["geometry"]:
            self.restoreGeometry(settings["geometry"])
        else:
            self.setGeometry(300, 300, 1000, 750)  # default window size
            self.move(QApplication.screens()[0].geometry().center() -
                      self.rect().center())
        if settings["state"]:
            self.restoreState(settings["state"])

        self.actions = {}  # contains all actions

        # initialize menus
        file_menu = self.menuBar().addMenu("&File")
        icon = QIcon(image_path("open_file.svg"))
        self.actions["open_file"] = file_menu.addAction(
            icon, "&Open...", self.open_data, QKeySequence.Open)
        self.recent_menu = file_menu.addMenu("Open recent")
        self.recent_menu.aboutToShow.connect(self._update_recent_menu)
        self.recent_menu.triggered.connect(self._load_recent)
        if not self.recent:
            self.recent_menu.setEnabled(False)
        self.actions["close_file"] = file_menu.addAction(
            "&Close",
            self.model.remove_data,
            QKeySequence.Close)
        self.actions["close_all"] = file_menu.addAction(
            "Close all",
            self.close_all)
        file_menu.addSeparator()
        icon = QIcon(image_path("meta_info.svg"))
        self.actions["meta_info"] = file_menu.addAction(icon,
                                                        "Show information...",
                                                        self.meta_info)
        file_menu.addSeparator()
        self.actions["import_bads"] = file_menu.addAction(
            "Import bad channels...",
            lambda: self.import_file(model.import_bads, "Import bad channels",
                                     "*.csv"))
        self.actions["import_events"] = file_menu.addAction(
            "Import events...",
            lambda: self.import_file(model.import_events, "Import events",
                                     "*.csv"))
        self.actions["import_annotations"] = file_menu.addAction(
            "Import annotations...",
            lambda: self.import_file(model.import_annotations,
                                     "Import annotations", "*.csv"))
        self.actions["import_ica"] = file_menu.addAction(
            "Import &ICA...",
            lambda: self.open_file(model.import_ica, "Import ICA",
                                   "*.fif *.fif.gz"))
        file_menu.addSeparator()
        self.export_menu = file_menu.addMenu("Export data")
        for name, ext in EXPORT_FORMATS.items():
            self.actions["export_data_" + ext] = self.export_menu.addAction(
                f"{name} ({ext[1:].upper()})...",
                partial(self.export_file, model.export_data, "Export data",
                        ext))
        self.actions["export_bads"] = file_menu.addAction(
            "Export &bad channels...",
            lambda: self.export_file(model.export_bads, "Export bad channels",
                                     "*.csv"))
        self.actions["export_events"] = file_menu.addAction(
            "Export &events...",
            lambda: self.export_file(model.export_events, "Export events",
                                     "*.csv"))
        self.actions["export_annotations"] = file_menu.addAction(
            "Export &annotations...",
            lambda: self.export_file(model.export_annotations,
                                     "Export annotations", "*.csv"))
        self.actions["export_ica"] = file_menu.addAction(
            "Export ICA...",
            lambda: self.export_file(model.export_ica,
                                     "Export ICA", "*.fif *.fif.gz"))
        file_menu.addSeparator()
        self.actions["quit"] = file_menu.addAction("&Quit", self.close,
                                                   QKeySequence.Quit)

        edit_menu = self.menuBar().addMenu("&Edit")
        self.actions["pick_chans"] = edit_menu.addAction(
            "P&ick channels...",
            self.pick_channels)
        icon = QIcon(image_path("chan_props.svg"))
        self.actions["chan_props"] = edit_menu.addAction(
            icon, "Channel &properties...", self.channel_properties)
        self.actions["set_montage"] = edit_menu.addAction("Set &montage...",
                                                          self.set_montage)
        edit_menu.addSeparator()
        self.actions["set_ref"] = edit_menu.addAction("Set &reference...",
                                                      self.set_reference)
        edit_menu.addSeparator()
        self.actions["annotations"] = edit_menu.addAction(
            "&Annotations...",
            self.edit_annotations)
        self.actions["events"] = edit_menu.addAction("&Events...",
                                                     self.edit_events)

        edit_menu.addSeparator()
        self.actions["crop"] = edit_menu.addAction("&Crop data...", self.crop)
        self.actions["append_data"] = edit_menu.addAction(
            "Appen&d data...",
            self.append_data)

        plot_menu = self.menuBar().addMenu("&Plot")
        icon = QIcon(image_path("plot_data.svg"))
        self.actions["plot_data"] = plot_menu.addAction(icon, "&Data...",
                                                        self.plot_data)
        icon = QIcon(image_path("plot_psd.svg"))
        self.actions["plot_psd"] = plot_menu.addAction(
            icon, "&Power spectral density...", self.plot_psd)
        icon = QIcon(image_path("plot_montage.svg"))
        self.actions["plot_montage"] = plot_menu.addAction(icon, "&Montage...",
                                                           self.plot_montage)
        plot_menu.addSeparator()
        self.actions["plot_ica_components"] = plot_menu.addAction(
            "ICA &components...", self.plot_ica_components)
        self.actions["plot_ica_sources"] = plot_menu.addAction(
            "ICA &sources...", self.plot_ica_sources)

        tools_menu = self.menuBar().addMenu("&Tools")
        icon = QIcon(image_path("filter.svg"))
        self.actions["filter"] = tools_menu.addAction(icon, "&Filter data...",
                                                      self.filter_data)
        icon = QIcon(image_path("find_events.svg"))
        self.actions["find_events"] = tools_menu.addAction(icon,
                                                           "Find &events...",
                                                           self.find_events)
        self.actions["events_from_annotations"] = tools_menu.addAction(
            "Create events from annotations", self.events_from_annotations
        )
        tools_menu.addSeparator()
        icon = QIcon(image_path("run_ica.svg"))
        self.actions["run_ica"] = tools_menu.addAction(icon, "Run &ICA...",
                                                       self.run_ica)
        self.actions["apply_ica"] = tools_menu.addAction("Apply &ICA",
                                                         self.apply_ica)
        tools_menu.addSeparator()
        self.actions["interpolate_bads"] = tools_menu.addAction(
                                                "Interpolate bad channels...",
                                                self.interpolate_bads)
        tools_menu.addSeparator()
        icon = QIcon(image_path("epoch_data.svg"))
        self.actions["epoch_data"] = tools_menu.addAction(
            icon, "Create Epochs...", self.epoch_data)

        view_menu = self.menuBar().addMenu("&View")
        self.actions["history"] = view_menu.addAction("&History...",
                                                      self.show_history)
        self.actions["toolbar"] = view_menu.addAction("&Toolbar",
                                                      self._toggle_toolbar)
        self.actions["toolbar"].setCheckable(True)
        self.actions["statusbar"] = view_menu.addAction("&Statusbar",
                                                        self._toggle_statusbar)
        self.actions["statusbar"].setCheckable(True)

        help_menu = self.menuBar().addMenu("&Help")
        self.actions["about"] = help_menu.addAction("&About", self.show_about)
        self.actions["about_qt"] = help_menu.addAction("About &Qt",
                                                       self.show_about_qt)

        # actions that are always enabled
        self.always_enabled = ["open_file", "about", "about_qt", "quit",
                               "toolbar", "statusbar"]

        # set up toolbar
        self.toolbar = self.addToolBar("toolbar")
        self.toolbar.setObjectName("toolbar")
        self.toolbar.addAction(self.actions["open_file"])
        self.toolbar.addAction(self.actions["meta_info"])
        self.toolbar.addSeparator()
        self.toolbar.addAction(self.actions["chan_props"])
        self.toolbar.addSeparator()
        self.toolbar.addAction(self.actions["plot_data"])
        self.toolbar.addAction(self.actions["plot_psd"])
        self.toolbar.addAction(self.actions["plot_montage"])
        self.toolbar.addSeparator()
        self.toolbar.addAction(self.actions["filter"])
        self.toolbar.addAction(self.actions["find_events"])
        self.toolbar.addAction(self.actions["epoch_data"])
        self.toolbar.addAction(self.actions["run_ica"])

        self.setUnifiedTitleAndToolBarOnMac(True)
        if settings["toolbar"]:
            self.toolbar.show()
            self.actions["toolbar"].setChecked(True)
        else:
            self.toolbar.hide()
            self.actions["toolbar"].setChecked(False)

        # set up data model for sidebar (list of open files)
        self.names = QStringListModel()
        self.names.dataChanged.connect(self._update_names)
        splitter = QSplitter()
        self.sidebar = QListView()
        self.sidebar.setFrameStyle(QFrame.NoFrame)
        self.sidebar.setFocusPolicy(Qt.NoFocus)
        self.sidebar.setModel(self.names)
        self.sidebar.clicked.connect(self._update_data)
        splitter.addWidget(self.sidebar)
        self.infowidget = InfoWidget()
        splitter.addWidget(self.infowidget)
        width = splitter.size().width()
        splitter.setSizes((int(width * 0.3), int(width * 0.7)))
        self.setCentralWidget(splitter)

        self.status_label = QLabel()
        self.statusBar().addPermanentWidget(self.status_label)
        if settings["statusbar"]:
            self.statusBar().show()
            self.actions["statusbar"].setChecked(True)
        else:
            self.statusBar().hide()
            self.actions["statusbar"].setChecked(False)

        self.setAcceptDrops(True)
        self.data_changed()