Esempio n. 1
0
def show_message_box(text, info_text="", buttons=QMessageBox.Ok):
    """
    Shows a message box
    :param text:
    :param info_text:
    :param buttons:
    :return:
    """
    message_box = QMessageBox()
    try:
        message_box.setIconPixmap(QPixmap(
            ":/res/ui/guiscrcpy_logo.png").scaledToHeight(100))
    except Exception as e:
        print("WARN: {e}: loading guiscrcpy "
              "message box pixmap failed. "
              "Ignoring".format(e=e))
    message_box.setText("<b>{}</b>".format(text))
    message_box.setTextFormat(QtCore.Qt.RichText)
    message_box.setInformativeText(info_text)
    message_box.setStandardButtons(buttons)
    return message_box
Esempio n. 2
0
 def __on_ws_message(self, msg):
     '''
     Handles messages from the device.
     :param msg: the message.
     '''
     if msg.startswith('mso '):
         logger.debug(f"Processing mso {msg}")
         self.__on_mso(json.loads(msg[4:]))
     elif msg.startswith('msoupdate '):
         logger.debug(f"Processing msoupdate {msg}")
         self.__on_msoupdate(json.loads(msg[10:]))
     else:
         logger.warning(f"Unknown message {msg}")
         msg_box = QMessageBox(QMessageBox.Critical, 'Unknown Message',
                               f"Received unexpected message from {self.ipAddress.text()}")
         msg_box.setDetailedText(f"<code>{msg}</code>")
         msg_box.setTextFormat(Qt.RichText)
         msg_box.exec()
         if self.__spinner is not None:
             stop_spinner(self.__spinner, self.syncStatus)
             self.__spinner = None
             self.syncStatus.setIcon(qta.icon('fa5s.times', color='red'))
Esempio n. 3
0
    def __init__(self):
        super(XicamMainWindow, self).__init__()

        # Set icon
        self.setWindowIcon(QIcon(QPixmap(str(path("icons/xicam.gif")))))

        # Set size and position
        self.setGeometry(0, 0, 1000, 600)
        frameGm = self.frameGeometry()
        screen = QApplication.desktop().screenNumber(
            QApplication.desktop().cursor().pos())
        centerPoint = QApplication.desktop().screenGeometry(screen).center()
        frameGm.moveCenter(centerPoint)
        self.move(frameGm.topLeft())

        # Init child widgets to None
        self.topwidget = (self.leftwidget) = (self.rightwidget) = (
            self.bottomwidget
        ) = self.lefttopwidget = self.righttopwidget = self.leftbottomwidget = self.rightbottomwidget = None

        # Setup appearance
        self.setWindowTitle("Xi-cam")
        self.load_style()

        # Attach an object to restore config when loaded
        self._config_restorer = ConfigRestorer()

        # Load plugins
        pluginmanager.qt_is_safe = True
        pluginmanager.initialize_types()
        pluginmanager.collect_plugins()
        pluginmanager.collect_user_plugins()

        # Setup center/toolbar/statusbar/progressbar
        self.pluginmodewidget = pluginModeWidget()
        self.pluginmodewidget.sigSetStage.connect(self.setStage)
        self.pluginmodewidget.sigSetGUIPlugin.connect(self.setGUIPlugin)
        self.addToolBar(self.pluginmodewidget)
        self.setStatusBar(QStatusBar(self))
        msg.progressbar = QProgressBar(self)
        msg.progressbar.hide()
        msg.statusbar = self.statusBar()
        self.statusBar().addPermanentWidget(msg.progressbar)
        self.setCentralWidget(QStackedWidget())
        # NOTE: CentralWidgets are force-deleted when replaced, even if the object is still referenced;
        # To avoid this, a QStackedWidget is used for the central widget.

        # Setup menubar
        menubar = DebuggableMenuBar()
        self.setMenuBar(menubar)
        file = QMenu("&File", parent=menubar)
        plugins = QMenu("&Plugins", parent=menubar)
        menubar.addMenu(file)
        file.addAction("Se&ttings",
                       self.showSettings,
                       shortcut=QKeySequence(Qt.CTRL + Qt.ALT + Qt.Key_S))
        file.addAction("E&xit", self.close)
        menubar.addMenu(plugins)
        plugins.addAction("Open User &Plugin Directory",
                          self.openUserPluginDir,
                          shortcut=QKeySequence(Qt.CTRL + Qt.ALT + Qt.Key_P))

        # Set up help
        help = QMenu("&Help", parent=menubar)
        documentation_link = QUrl("https://xi-cam.readthedocs.io/en/latest/")
        help.addAction("Xi-CAM &Help",
                       lambda: QDesktopServices.openUrl(documentation_link))
        slack_link = QUrl("https://nikea.slack.com")
        help.addAction("Chat on &Slack",
                       lambda: QDesktopServices.openUrl(slack_link))
        help.addSeparator()

        about_title = "About Xi-CAM"
        version_text = f"""Version: <strong>{version.get_versions()['version']}</strong>"""
        copyright_text = f"""<small>Copyright (c) 2016, The Regents of the University of California, \
            through Lawrence Berkeley National Laboratory \
            (subject to receipt of any required approvals from the U.S. Dept. of Energy). \
            All rights reserved.</small>"""
        funding_text = f"""Funding for this research was provided by: \
            Lawrence Berkeley National Laboratory (grant No. TReXS LDRD to AH); \
            US Department of Energy (award No. Early Career Award to AH; \
            contract No. DE-SC0012704; contract No. DE-AC02-06CH11357; \
            contract No. DE-AC02-76SF00515; contract No. DE-AC02-05CH11231); \
            Center for Advanced Mathematics in Energy Research Applications; \
            Light Source Directors Data Solution Task Force Pilot Project."""
        about_text = version_text + "<br><br>" + funding_text + "<br><hr>" + copyright_text
        about_box = QMessageBox(QMessageBox.NoIcon, about_title, about_text)
        about_box.setTextFormat(Qt.RichText)
        about_box.setWindowModality(Qt.NonModal)
        help.addAction("&About Xi-CAM", lambda: about_box.show())
        help.addSeparator()

        help.addAction(QWhatsThis.createAction(help))

        menubar.addMenu(help)

        # Initialize layout with first plugin
        self._currentGUIPlugin = None
        self.build_layout()

        # self._currentGUIPlugin = pluginmanager.getPluginsOfCategory("GUIPlugin")[0]
        self.populate_layout()

        # Make F key bindings
        fkeys = [
            Qt.Key_F1,
            Qt.Key_F2,
            Qt.Key_F3,
            Qt.Key_F4,
            Qt.Key_F5,
            Qt.Key_F6,
            Qt.Key_F7,
            Qt.Key_F8,
            Qt.Key_F9,
            Qt.Key_F10,
            Qt.Key_F11,
            Qt.Key_F12,
        ]
        self.Fshortcuts = [QShortcut(QKeySequence(key), self) for key in fkeys]
        for i in range(12):
            self.Fshortcuts[i].activated.connect(partial(self.setStage, i))

        self.readSettings()
        # Wireup default widgets
        get_default_stage()["left"].sigOpen.connect(self.open)
        get_default_stage()["left"].sigOpen.connect(print)
        get_default_stage()["left"].sigPreview.connect(
            get_default_stage()["lefttop"].preview)