Пример #1
0
    def __init__(self, parent=None):
        super(Console, self).__init__(parent)
        self.json_decode_warning = None

        self.widget = QWidget(self)
        self.console_layout = QVBoxLayout(self.widget)
        self.widget.setLayout(self.console_layout)

        self.output_label = QLabel(self.widget)
        self.output_label.setText("Output")
        self.output_edit = QTextEdit(self.widget)
        self.output_edit.setReadOnly(True)
        self.highlighter = Highlighter(self.output_edit.document())
        self.output_edit.setStyleSheet("background-color: rgb(0, 0, 0);")
        self.output_edit.setTextColor(QColor(0, 255, 0))
        self.output_edit.setFont(QFont(self.output_edit.currentFont().family(), 10))

        self.input_label = QLabel(self.widget)
        self.input_label.setText("Command")
        self.input_edit = QLineEdit(self.widget)
        self.input_edit.setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(0, 255, 0)")
        self.input_edit.setFont(QFont(self.output_edit.currentFont().family(), 10))

        self.send_button = QPushButton(self.widget)
        self.send_button.setObjectName("send_button")
        self.send_button.setText("Send command")

        self.console_layout.addWidget(self.output_label)
        self.console_layout.addWidget(self.output_edit)
        self.console_layout.addWidget(self.input_label)
        self.console_layout.addWidget(self.input_edit)
        self.console_layout.addWidget(self.send_button)

        self.addContentWidget(self.widget)
        QMetaObject.connectSlotsByName(self)
Пример #2
0
    def __init__(self, parent=None):
        super(FramesWidget, self).__init__(parent)
        self.config_frames = []
        self.frames_instances = []
        self.current_frame = 0

        self.widget_layout = QVBoxLayout(self)
        self.setLayout(self.widget_layout)

        self.frames_widget = QWidget(self)
        self.frames_widget.setContentsMargins(0, 0, 0, 0)
        self.frames_widget_layout = QGridLayout(self.frames_widget)
        self.frames_widget_layout.setContentsMargins(0, 0, 0, 0)
        self.widget_layout.addWidget(self.frames_widget)

        self.btn_box = QDialogButtonBox(self)
        self.btn_box.setObjectName("btn_box")
        self.btn_box.setStandardButtons(QDialogButtonBox.Reset
                                        | QDialogButtonBox.Cancel
                                        | QDialogButtonBox.Ok)
        self.btn_box.button(QDialogButtonBox.Reset).setText("Back")
        self.btn_box.button(QDialogButtonBox.Ok).setText("Next")
        self.widget_layout.addWidget(self.btn_box)

        self.btn_box.button(QDialogButtonBox.Reset).clicked.connect(
            self.on_btn_box_resetted)
        QMetaObject.connectSlotsByName(self)
Пример #3
0
    def start(self):
        if self.logger_name:
            self.logger = logging.getLogger(self.logger_name)  # noqa
        else:
            self.logger = logging.getLogger(self.__class__.__name__)  # noqa
        self.data = {"size_left": 0, "data": b""}  # noqa
        self.tcpSocket = QTcpSocket(self)  # noqa

        self.tcpSocket.setObjectName("qclient_socket")
        QMetaObject.connectSlotsByName(self)
        self.tcpSocket.setSocketOption(QAbstractSocket.KeepAliveOption, 1)
        self.tcpSocket.connectToHost(QHostAddress(self.ip), self.port,
                                     QIODevice.ReadWrite)
        if not self.tcpSocket.waitForConnected(3000):
            self.failed_to_connect.emit(self.ip, self.port)
            self.tcpSocket.disconnectFromHost()
            self.tcpSocket.close()
            self.logger.error("Failed to connect to {}:{}".format(
                self.ip, self.port))
            return

        self.close_signal.connect(self.close, Qt.BlockingQueuedConnection)
        self.write_signal.connect(self._write)
        self.connect_signal.connect(self._connectTo)
        self.disconnect_signal.connect(self._disconnect)
        self.reconnect_signal.connect(self._reconnect)
Пример #4
0
        def exception_hook(exception):
            from qtpy.QtCore import QMetaObject
            from qtpy.QtWidgets import QApplication

            instance = QApplication.instance()
            if isinstance(exception, ValueError) and exception.args[0] == "Incompatible shape of mask and image":
                instance.warning = (
                    "Open error",
                    "Most probably you try to load mask from other image. " "Check selected files",
                )
                QMetaObject.invokeMethod(instance, "show_warning", Qt.QueuedConnection)
            elif isinstance(exception, MemoryError):
                instance.warning = "Open error", f"Not enough memory to read this image: {exception}"
                QMetaObject.invokeMethod(instance, "show_warning", Qt.QueuedConnection)
            elif isinstance(exception, IOError):
                instance.warning = "Open error", f"Some problem with reading from disc: {exception}"
                QMetaObject.invokeMethod(instance, "show_warning", Qt.QueuedConnection)
            elif isinstance(exception, KeyError):
                instance.warning = "Open error", f"Some problem project file: {exception}"
                QMetaObject.invokeMethod(instance, "show_warning", Qt.QueuedConnection)
                print(exception, file=sys.stderr)
            elif isinstance(exception, WrongFileTypeException):
                instance.warning = (
                    "Open error",
                    "No needed files inside archive. Most probably you choose file from segmentation mask",
                )
                QMetaObject.invokeMethod(instance, "show_warning", Qt.QueuedConnection)
            else:
                raise exception
Пример #5
0
    def __init__(self, parent=None):
        super(TermsFrame, self).__init__(parent)
        self.setObjectName("botnet_termsframe_start")
        self.disable_next_on_enter = True

        self.widget_layout = QVBoxLayout(self)
        self.setLayout(self.widget_layout)

        self.terms = QTextEdit(self)
        self.terms.setReadOnly(True)
        self.terms.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
        self.terms.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.terms.setLineWrapMode(QTextEdit.WidgetWidth)
        self.terms.setWordWrapMode(QTextOption.WrapAnywhere)
        with open(os.path.join(sys.path[0], "../LICENSE")) as f:
            self.terms.setText(f.read())
        self.widget_layout.addWidget(self.terms)

        self.accept = QCheckBox(self)
        self.accept.setChecked(False)
        self.accept.setText("Accept license")
        self.accept.setObjectName("license_checkbox")
        self.widget_layout.addWidget(self.accept)

        QMetaObject.connectSlotsByName(self)
Пример #6
0
    def __init__(self, parent=None):
        super(SetupDialog, self).__init__(parent)
        self.logger = logging.getLogger(self.__class__.__name__)

        self.message_box = None

        self.start_button = QPushButton("Start", self)
        self.start_button.setObjectName("start_button")
        self.start_button.setMinimumHeight(35)
        self.start_button.setVisible(True)
        self.addSubContentWidget(self.start_button)

        self.config_frame = FramesWidget(self)
        self.config_frame.add_frames([
            TermsFrame, GUIConfigFrame, C2ConfigFrame, InfoFrame, FinishFrame
        ])

        self.config_frame.setObjectName("config_frame")
        self.config_frame.setVisible(False)
        self.addSubContentWidget(self.config_frame)

        QMetaObject.connectSlotsByName(self)
        try:
            self.closeClicked.disconnect()
        except Exception:
            pass
        self.closeClicked.connect(self.on_config_frame_rejected)
Пример #7
0
def my_excepthook(type_, value, trace_back):
    """
    Custom excepthook. base on base on :py:data:`state_store.show_error_dialog` decide if shown error dialog.

    """

    # log the exception here
    if state_store.show_error_dialog and not isinstance(value, KeyboardInterrupt):
        if state_store.report_errors and parsed_version.is_devrelease:
            with sentry_sdk.push_scope() as scope:
                scope.set_tag("auto_report", "true")
                sentry_sdk.capture_exception(value)
        try:
            # noinspection PyUnresolvedReferences
            from qtpy.QtWidgets import QApplication

            if QApplication.instance():
                from qtpy.QtCore import QMetaObject, Qt, QThread

                QApplication.instance().error = value
                if QThread.currentThread() != QApplication.instance().thread():
                    QMetaObject.invokeMethod(QApplication.instance(), "show_error", Qt.QueuedConnection)
                else:
                    QApplication.instance().show_error()
        except ImportError:
            sys.__excepthook__(type_, value, trace_back)
    elif isinstance(value, KeyboardInterrupt):
        print("KeyboardInterrupt close", file=sys.stderr)
        sys.exit(1)
    else:
        # then call the default handler
        sys.__excepthook__(type_, value, trace_back)
    def __init__(self):
        super(BaseWindow, self).__init__(None)
        self.win = None
        self.warning = None
        self.askClose = None

        self.subwindowButton = QPushButton("Create new subwindow", self)
        self.subwindowButton.setObjectName("subwindowButton")

        self.warningButton = QPushButton("Create new warning message box",
                                         self)
        self.warningButton.setObjectName("warningButton")

        self.idButton = QPushButton("Print ID", self)
        self.idButton.setObjectName("idButton")

        self.closeButton = QPushButton("Close application", self)
        self.closeButton.setObjectName("closeButton")

        self.addContentWidget(self.subwindowButton)
        self.addContentWidget(self.warningButton)
        self.addContentWidget(self.idButton)
        self.addContentWidget(self.closeButton)

        QMetaObject.connectSlotsByName(self)
Пример #9
0
    def setupUi(self, MainWindow):
        MainWindow.setObjectName(_fromUtf8("MainWindow"))
        MainWindow.resize(1155, 853)
        self.centralwidget = QWidget(MainWindow)
        self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
        self.verticalLayout = QVBoxLayout(self.centralwidget)
        self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
        self.tabWidget = QTabWidget(self.centralwidget)
        self.tabWidget.setObjectName(_fromUtf8("tabWidget"))
        self.tab = QWidget()
        self.tab.setObjectName(_fromUtf8("tab"))
        self.tabWidget.addTab(self.tab, _fromUtf8(""))
        self.tab_2 = QWidget()
        self.tab_2.setObjectName(_fromUtf8("tab_2"))
        self.tabWidget.addTab(self.tab_2, _fromUtf8(""))
        self.verticalLayout.addWidget(self.tabWidget)
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QMenuBar(MainWindow)
        self.menubar.setGeometry(QRect(0, 0, 1155, 20))
        self.menubar.setObjectName(_fromUtf8("menubar"))
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QStatusBar(MainWindow)
        self.statusbar.setObjectName(_fromUtf8("statusbar"))
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)
        self.tabWidget.setCurrentIndex(0)
        QMetaObject.connectSlotsByName(MainWindow)
Пример #10
0
    def __init__(self, parent):
        super(FramelessWindowBase, self).__init__(parent)
        self.__rect = QApplication.instance().desktop().availableGeometry(self)

        self.__resizingEnabled = True
        self.__contentWidgets = []

        self.setMouseTracking(True)
        self.setAttribute(Qt.WA_NoSystemBackground)
        super().setContentsMargins(0, 0, 0, 0)
        super().setWindowFlags(Qt.Window
                               | Qt.FramelessWindowHint
                               | Qt.WindowSystemMenuHint
                               | Qt.WindowMinimizeButtonHint
                               | Qt.WindowMaximizeButtonHint
                               | Qt.WindowCloseButtonHint)

        self.__centralWidget = QWidget(self)
        self.__centralWidget.setObjectName("__centralWidget")
        self.__centralWidget.setContentsMargins(0, 0, 0, 0)
        self.__centralWidget.setMouseTracking(True)

        self.__centralLayout = QVBoxLayout(self.__centralWidget)
        self.__centralLayout.setAlignment(Qt.AlignBottom)
        self.__centralLayout.setContentsMargins(0, 0, 0, 0)
        self.__centralLayout.setSpacing(0)

        self.__bar = Titlebar(self)
        self.__bar.showRestoreButton(False)
        self.__bar.showMinimizeButton(False)
        self.__bar.showMaximizeButton(False)
        self.__centralLayout.addWidget(self.__bar)
        self.__centralLayout.setAlignment(self.__bar, Qt.AlignVCenter)

        self.__contentWidget = QWidget(self)
        self.__contentWidget.setObjectName("__contentWidget")
        self.__contentWidget.setSizePolicy(QSizePolicy.Expanding,
                                           QSizePolicy.Expanding)
        self.__contentWidget.setContentsMargins(2, 0, 2, 2)
        self.__contentWidgetLayout = QVBoxLayout(self.__contentWidget)
        self.__contentWidgetLayout.setContentsMargins(0, 0, 0, 0)
        self.__centralLayout.addWidget(self.__contentWidget)

        self.__centralWidget.setLayout(self.__centralLayout)
        self.__contentWidget.setAutoFillBackground(True)

        self.__bar.closeClicked.connect(self.closeClicked.emit)
        self.closeClicked.connect(self.close)

        self.__main_layout = QVBoxLayout(self)
        self.__main_layout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(self.__main_layout)
        self.__main_layout.addWidget(self.__centralWidget)

        QMetaObject.connectSlotsByName(self)
        self.showSizeControl(True)
        self.resize(
            QSize(int(self.__rect.width() / 2), int(self.__rect.height() / 2)))
Пример #11
0
 def on_new_fit_performed(self):
     """React to a new fit created in the fitting tab"""
     # It's possible that this call can come in on a thread that
     # is different to the one that the view lives on.
     # In order to update the GUI we use invokeMethod with the assumption
     # that 'self' lives on the same thread as the view and Qt forces
     # the call to the chose method to be done on the thread the
     # view lives on. This avoids errors from painting on non-gui threads.
     QMetaObject.invokeMethod(self, "_on_new_fit_performed_impl")
Пример #12
0
    def setup_ui(self):
        # create title bar, content
        self.vboxWindow.setContentsMargins(0, 0, 0, 0)

        self.windowFrame.setObjectName('windowFrame')

        self.vboxFrame.setContentsMargins(0, 0, 0, 0)

        self.titleBar.setObjectName('titleBar')
        self.titleBar.setSizePolicy(
            QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed))

        self.hboxTitle.setContentsMargins(0, 0, 0, 0)
        self.hboxTitle.setSpacing(0)

        self.lblTitle.setObjectName('lblTitle')
        self.lblTitle.setAlignment(Qt.AlignCenter)
        self.hboxTitle.addWidget(self.lblTitle)

        sp_buttons = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)

        self.btnMinimize.setObjectName('btnMinimize')
        self.btnMinimize.setSizePolicy(sp_buttons)
        self.hboxTitle.addWidget(self.btnMinimize)

        self.btnRestore.setObjectName('btnRestore')
        self.btnRestore.setSizePolicy(sp_buttons)
        self.btnRestore.setVisible(False)
        self.hboxTitle.addWidget(self.btnRestore)

        self.btnMaximize.setObjectName('btnMaximize')
        self.btnMaximize.setSizePolicy(sp_buttons)
        self.hboxTitle.addWidget(self.btnMaximize)

        self.btnClose.setObjectName('btnClose')
        self.btnClose.setSizePolicy(sp_buttons)
        self.hboxTitle.addWidget(self.btnClose)

        self.vboxFrame.addWidget(self.titleBar)

        self.vboxFrame.addWidget(self.windowContent)

        self.vboxWindow.addWidget(self.windowFrame)

        # set window flags
        self.setWindowFlags(Qt.Window | Qt.FramelessWindowHint
                            | Qt.WindowSystemMenuHint)

        if self._window.app.qt_version >= (5, ):
            self.setAttribute(Qt.WA_TranslucentBackground)

        # set stylesheet
        stylesheet = self.app.ui.get_stylesheet('frameless.qss')
        self.setStyleSheet(stylesheet)

        # automatically connect slots
        QMetaObject.connectSlotsByName(self)
Пример #13
0
 def run(self):
     ret = run_script(self.script, self.widget)
     if isinstance(ret, Exception):
         raise ret
     self.script_iter = [iter(ret) if inspect.isgenerator(ret) else None]
     if self.pause != 0:
         self.script_timer.setInterval(self.pause * 1000)
     # Zero-timeout timer runs script_runner() between Qt events
     self.script_timer.timeout.connect(self, Qt.QueuedConnection)
     QMetaObject.invokeMethod(self.script_timer, 'start', Qt.QueuedConnection)
Пример #14
0
            def exception_hook(exception):
                from qtpy.QtCore import QMetaObject
                from qtpy.QtWidgets import QApplication

                instance = QApplication.instance()
                if isinstance(exception, ValueError):
                    instance.warning = "Save error", f"Error during saving\n{exception}"
                    QMetaObject.invokeMethod(instance, "show_warning", Qt.QueuedConnection)
                else:
                    raise exception
Пример #15
0
 def on_output_results_request(self):
     """React to the output results table request"""
     results_selection = self.view.selected_result_workspaces()
     if not results_selection:
         return
     log_selection = self.view.selected_log_values()
     try:
         self.model.create_results_table(log_selection, results_selection)
         QMetaObject.invokeMethod(self, "_notify_results_table_created")
     except Exception as exc:
         self.view.show_warning(str(exc))
Пример #16
0
    def setupUi(self, Form):
        if Form.objectName():
            Form.setObjectName(u"Form")
        Form.resize(400, 300)
        Form.setMinimumSize(QSize(400, 300))
        Form.setMaximumSize(QSize(400, 300))
        self.textBrowser = QTextBrowser(Form)
        self.textBrowser.setObjectName(u"textBrowser")
        self.textBrowser.setGeometry(QRect(0, 0, 400, 300))

        self.retranslateUi(Form)

        QMetaObject.connectSlotsByName(Form)
    def __init__(self, parent=None):
        super(FramelessWindow, self).__init__(parent)
        self.__rect = QApplication.instance().desktop().availableGeometry(self)

        self.__titlebarHeight = 45
        self.__borderWidth = 3

        self.hwnd = None

        if QtWin.isCompositionEnabled():
            QtWin.extendFrameIntoClientArea(self, -1, -1, -1, -1)
        else:
            QtWin.resetExtendedFrame(self)
        QMetaObject.connectSlotsByName(self)
Пример #18
0
 def send(self, block=True, func=None, *args, **kwargs):
     """
     :param block: wait on the func to return
     :param func: the reference to the function to be called by the eventloop
     :param ``*args``: unnamed arguments for the function
     :param ``**kwargs``: key word arguments for the function
     """
     returnlock = ReturnLock()
     self.signal_call_queue.put((returnlock, func, args, kwargs))
     QMetaObject.invokeMethod(self, "receive", Qt.QueuedConnection)
     if block:
         returnlock.waitOnReturn()
         return returnlock.value
     else:
         return returnlock
Пример #19
0
 def __call__(self, *args, **kwargs):
     """
     If the current thread is the qApp thread then this
     performs a straight call to the wrapped callable_obj. Otherwise
     it invokes the do_call method as a slot via a
     BlockingQueuedConnection.
     """
     if QThread.currentThread() == self.qApp.thread():
         return self.callee(*args, **kwargs)
     else:
         self._store_function_args(*args, **kwargs)
         QMetaObject.invokeMethod(self, "on_call",
                                  Qt.BlockingQueuedConnection)
         if self._exc_info is not None:
             reraise(*self._exc_info)
         return self._result
Пример #20
0
 def setup_ui(self, dialog):
     dialog.setObjectName("Dialog")
     dialog.resize(600, 200)
     dialog.setModal(True)
     self.layout = QHBoxLayout(dialog)
     self.layout.setObjectName("hbox_layout")
     self.waiting = QtWaitingSpinner(dialog, centerOnParent=False)
     self.waiting.setObjectName("waiting")
     self.label = QLabel('Loading model result...')
     font = self.label.font()
     font.setPointSize(16)
     self.label.setFont(font)
     self.label.setStyleSheet("QLabel { color : black; }")
     self.layout.addWidget(self.waiting)
     self.layout.addWidget(self.label)
     QMetaObject.connectSlotsByName(dialog)
Пример #21
0
 def __call__(self, *args, **kwargs):
     """
     If the current thread is the qApp thread then this
     performs a straight call to the wrapped callable_obj. Otherwise
     it invokes the do_call method as a slot via a
     BlockingQueuedConnection.
     """
     if QThread.currentThread() == qApp.thread():
         return self.callee(*args, **kwargs)
     else:
         self._store_function_args(*args, **kwargs)
         QMetaObject.invokeMethod(self, "on_call",
                                  Qt.BlockingQueuedConnection)
         if self._exc_info is not None:
             reraise(*self._exc_info)
         return self._result
Пример #22
0
 def __call__(self, *args, **kwargs):
     """
     If the current thread is the qApp thread then this
     performs a straight call to the wrapped callable_obj. Otherwise
     it invokes the do_call method as a slot via a
     BlockingQueuedConnection.
     """
     if self.is_qapp_thread():
         return self.callee(*args, **kwargs)
     else:
         self._ensure_self_on_qapp_thread()
         self._store_function_args(args, kwargs)
         QMetaObject.invokeMethod(self, "on_call", Qt.BlockingQueuedConnection)
         if self._exc_info is not None:
             raise self._exc_info[1].with_traceback(self._exc_info[2])
         return self._result
Пример #23
0
    def on_new_fit_performed(self, fit_info=None):
        """React to a new fit created in the fitting tab"""
        # It's possible that this call can come in on a thread that
        # is different to the one that the view lives on.
        # In order to update the GUI we use invokeMethod with the assumption
        # that 'self' lives on the same thread as the view and Qt forces
        # the call to the chose method to be done on the thread the
        # view lives on. This avoids errors from painting on non-gui threads.

        new_fit_name = ";"
        if fit_info:
            new_fit_list = fit_info.output_workspace_names()
            if new_fit_list and len(new_fit_list) > 0:
                new_fit_name = new_fit_list[0]
        QMetaObject.invokeMethod(self, "_on_new_fit_performed_impl",
                                 Q_ARG(str, new_fit_name))
Пример #24
0
    def setupUi(self, Form):
        if not Form.objectName():
            Form.setObjectName(u"Form")
        Form.resize(400, 300)
        sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(Form.sizePolicy().hasHeightForWidth())
        Form.setSizePolicy(sizePolicy)
        Form.setMinimumSize(QSize(400, 300))
        Form.setMaximumSize(QSize(400, 300))
        self.textBrowser = QTextBrowser(Form)
        self.textBrowser.setObjectName(u"textBrowser")
        self.textBrowser.setGeometry(QRect(0, 0, 401, 301))

        self.retranslateUi(Form)

        QMetaObject.connectSlotsByName(Form)
Пример #25
0
    def __init__(self, parent=None):
        super(Titlebar, self).__init__(parent)
        self.setObjectName("titlebar")
        self.setMouseTracking(True)

        self.menus = []

        self.setAutoFillBackground(True)
        self.setFixedHeight(30)
        self.setContentsMargins(0, 0, 0, 0)
        self.setBackgroundRole(QPalette.Highlight)

        self.layout = QHBoxLayout(self)
        self.layout.setAlignment(Qt.AlignVCenter)
        self.layout.setAlignment(Qt.AlignLeft)
        self.layout.setContentsMargins(8, 0, 0, 0)
        self.layout.setSpacing(0)
        self.setLayout(self.layout)

        self.appLogoLabel = AppLogo(self)
        if qrainbowstyle.APP_ICON_PATH:
            self.appLogoLabel.setPixmap(QPixmap(qrainbowstyle.APP_ICON_PATH))
            self.layout.setContentsMargins(2, 0, 0, 0)
        self.layout.addWidget(self.appLogoLabel)
        if qrainbowstyle.ALIGN_BUTTONS_LEFT:
            self.appLogoLabel.setVisible(False)
            self.layout.setContentsMargins(8, 0, 0, 0)

        self.layout.insertStretch(50)
        self.buttonsWidget = ButtonsWidget(self)
        if qrainbowstyle.ALIGN_BUTTONS_LEFT:
            self.layout.insertWidget(0, self.buttonsWidget)
        else:
            self.layout.addWidget(self.buttonsWidget)

        # auto connect signals
        QMetaObject.connectSlotsByName(self)
        if self.window().parent() is not None:
            self.buttonsWidget.btnRestore.setVisible(False)
            self.buttonsWidget.btnMaximize.setVisible(False)
            self.buttonsWidget.btnMinimize.setVisible(False)
Пример #26
0
    def on_gui_client_config(self, config: dict):
        if config:
            self.content_widget.bot_double_clicked.connect(
                self.on_bot_double_clicked)
            self.content_widget.task_button_clicked.connect(
                self.on_task_button_clicked)
            self.content_widget.payload_button_clicked.connect(
                self.on_payload_button_clicked)
            self.content_widget.setupUi(config)
            self.addContentWidget(self.content_widget)

            self.console_window = Console(self)
            self.client.message.connect(self.console_window.write)
            self.client.shell_error.connect(self.on_gui_client_shell_error)
            self.client.shell_output.connect(self.on_gui_client_shell_output)
            self.console_window.message.connect(self.client.write)
            self.console_window.setVisible(False)

            self.spinner = WaitingSpinner(self,
                                          modality=Qt.WindowModal,
                                          disableParentWhenSpinning=True,
                                          roundness=70.0,
                                          fade=70.0,
                                          radius=15.0,
                                          lines=6,
                                          line_length=25.0,
                                          line_width=4.0,
                                          speed=1.0)
            self.content_widget.load_finished.connect(self.spinner.stop)
            self.spinner.start()

            self.menu = MainWindowMenu(self)
            self.addMenu(self.menu)

            self.tray = SystemTrayWidget(self)
            self.tray.exit_action_triggered.connect(self.on_close_requested)
            self.tray.hide_action_triggered.connect(self.hide)
            self.tray.show_action_triggered.connect(self.show)
            self.tray.show()
            QMetaObject.connectSlotsByName(self)
Пример #27
0
        def exception_hook(exception):
            from qtpy.QtCore import QMetaObject

            instance = QApplication.instance()
            if isinstance(exception, MemoryError):
                instance.warning = "Open error", f"Not enough memory to read this image: {exception}"
                QMetaObject.invokeMethod(instance, "show_warning", Qt.QueuedConnection)
            elif isinstance(exception, IOError):
                instance.warning = "Open error", f"Some problem with reading from disc: {exception}"
                QMetaObject.invokeMethod(instance, "show_warning", Qt.QueuedConnection)
            elif isinstance(exception, KeyError):
                instance.warning = "Open error", f"Some problem project file: {exception}"
                QMetaObject.invokeMethod(instance, "show_warning", Qt.QueuedConnection)
                print(exception, file=sys.stderr)
            else:
                raise exception
 def set_function_string(self, text):
     box = self.get_active_modal_widget()
     box.setTextValue(text)
     QMetaObject.invokeMethod(box, 'accept', Qt.QueuedConnection)
Пример #29
0
    def setupUi(self, MainWindow, title):
        MainWindow.setWindowTitle(title)
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(600, 850)
        MainWindow.setMinimumSize(QSize(300, 350))
        self.centralWidget = QWidget(MainWindow)
        self.centralWidget.setObjectName("centralWidget")
        self.gridLayout = QGridLayout(self.centralWidget)
        self.gridLayout.setContentsMargins(11, 11, 11, 11)
        self.gridLayout.setSpacing(6)
        self.gridLayout.setObjectName("gridLayout")
        self.horizontalLayout_5 = QHBoxLayout()
        self.horizontalLayout_5.setContentsMargins(11, 11, 11, 11)
        self.horizontalLayout_5.setSpacing(6)
        self.horizontalLayout_5.setObjectName("horizontalLayout_5")
        self.lines_selected_label = QLabel(self.centralWidget)
        self.lines_selected_label.setObjectName("lines_selected_label")
        self.horizontalLayout_5.addWidget(self.lines_selected_label)
        self.label = QLabel(self.centralWidget)
        self.label.setObjectName("label")
        self.horizontalLayout_5.addWidget(self.label)
        spacerItem = QSpacerItem(40, 20, QSizePolicy.Expanding,
                                 QSizePolicy.Minimum)
        self.horizontalLayout_5.addItem(spacerItem)
        self.draw_button = QPushButton(self.centralWidget)
        self.draw_button.setObjectName("draw_button")
        self.horizontalLayout_5.addWidget(self.draw_button)
        self.erase_button = QPushButton(self.centralWidget)
        self.erase_button.setObjectName("erase_button")
        self.horizontalLayout_5.addWidget(self.erase_button)
        self.dismiss_button = QPushButton(self.centralWidget)
        self.dismiss_button.setObjectName("dismiss_button")
        self.horizontalLayout_5.addWidget(self.dismiss_button)
        self.gridLayout.addLayout(self.horizontalLayout_5, 4, 0, 1, 1)
        self.verticalLayout_11 = QVBoxLayout()
        self.verticalLayout_11.setContentsMargins(11, 11, 11, 11)
        self.verticalLayout_11.setSpacing(6)
        self.verticalLayout_11.setObjectName("verticalLayout_11")
        self.tabWidget = QTabWidget(self.centralWidget)
        self.tabWidget.setObjectName("tabWidget")
        self.tabWidget.setTabsClosable(True)
        self.verticalLayout_11.addWidget(self.tabWidget)
        self.gridLayout.addLayout(self.verticalLayout_11, 0, 0, 1, 1)
        self.horizontalLayout_7 = QHBoxLayout()
        self.horizontalLayout_7.setContentsMargins(11, 11, 11, 11)
        self.horizontalLayout_7.setSpacing(6)
        spacerItem = QSpacerItem(40, 20, QSizePolicy.Expanding,
                                 QSizePolicy.Minimum)
        self.horizontalLayout_7.addItem(spacerItem)
        self.horizontalLayout_7.setObjectName("horizontalLayout_7")
        self.gridLayout.addLayout(self.horizontalLayout_7, 2, 0, 2, 1)
        MainWindow.setCentralWidget(self.centralWidget)

        # self.menuBar = QMenuBar(MainWindow)
        # self.menuBar.setGeometry(QRect(0, 0, 767, 22))
        # self.menuBar.setObjectName("menuBar")
        #
        # self.menuFile = QMenu(self.menuBar)
        # self.menuFile.setObjectName("menuFile")
        #
        # MainWindow.setMenuBar(self.menuBar)

        self.mainToolBar = QToolBar(MainWindow)
        self.mainToolBar.setMovable(False)
        self.mainToolBar.setFloatable(False)
        self.mainToolBar.setObjectName("mainToolBar")
        MainWindow.addToolBar(Qt.TopToolBarArea, self.mainToolBar)

        # self.statusBar = QStatusBar(MainWindow)
        # self.statusBar.setObjectName("statusBar")
        # MainWindow.setStatusBar(self.statusBar)

        self.actionOpen = QAction(MainWindow)
        icon = QIcon(os.path.join(ICON_PATH, "Open Folder-48.png"))
        self.actionOpen.setIcon(icon)
        self.actionOpen.setObjectName("actionOpen")

        self.actionExport = QAction(MainWindow)
        icon = QIcon(os.path.join(ICON_PATH, "Export-48.png"))
        self.actionExport.setIcon(icon)
        self.actionExport.setObjectName("actionExport")

        self.line_list_selector = QComboBox()
        self.line_list_selector.setToolTip(
            "Select line list from internal library")

        self.actionExit = QAction(MainWindow)
        self.actionExit.setObjectName("actionExit")
        self.actionRemove = QAction(MainWindow)
        self.actionRemove.setObjectName("actionRemove")
        self.actionChange_Color = QAction(MainWindow)
        self.actionChange_Color.setObjectName("actionChange_Color")
        # self.menuFile.addAction(self.actionOpen)
        # self.menuFile.addSeparator()
        # self.menuFile.addAction(self.actionExit)
        # self.menuBar.addAction(self.menuFile.menuAction())
        self.mainToolBar.addAction(self.actionOpen)
        self.mainToolBar.addAction(self.actionExport)
        self.mainToolBar.addSeparator()
        self.mainToolBar.addWidget(self.line_list_selector)
        self.retranslateUi(MainWindow)
        QMetaObject.connectSlotsByName(MainWindow)
Пример #30
0
 def callback(x):
     QMetaObject.invokeMethod(calc, "accept", Qt.QueuedConnection)
Пример #31
0
def trigger_action(action):
    QMetaObject.invokeMethod(action, 'trigger', Qt.QueuedConnection)
Пример #32
0
 def click_button(self, name):
     button = self.get_button(name)
     QMetaObject.invokeMethod(button, 'click', Qt.QueuedConnection)
Пример #33
0
 def hover_action(self, name):
     action, menu = self.get_action(name, get_menu=True)
     if not menu.isVisible():
         raise RuntimeError("Action {} isn't visible.".format(name))
     QMetaObject.invokeMethod(action, 'hover', Qt.QueuedConnection)
Пример #34
0
    def setupUi(self):
        # create title bar, content
        self.vboxWindow = QVBoxLayout(self)
        self.vboxWindow.setContentsMargins(0, 0, 0, 0)

        self.windowFrame = QWidget(self)
        self.windowFrame.setObjectName('windowFrame')

        self.vboxFrame = QVBoxLayout(self.windowFrame)
        self.vboxFrame.setContentsMargins(0, 0, 0, 0)

        self.titleBar = WindowDragger(self, self.windowFrame)
        self.titleBar.setObjectName('titleBar')
        self.titleBar.setSizePolicy(
            QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed))

        self.hboxTitle = QHBoxLayout(self.titleBar)
        self.hboxTitle.setContentsMargins(0, 0, 0, 0)
        self.hboxTitle.setSpacing(0)

        self.lblTitle = QLabel('Title')
        self.lblTitle.setObjectName('lblTitle')
        self.lblTitle.setAlignment(Qt.AlignCenter)

        spButtons = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)

        self.btnMinimize = QToolButton(self.titleBar)
        self.btnMinimize.setObjectName('btnMinimize')
        self.btnMinimize.setSizePolicy(spButtons)

        self.btnRestore = QToolButton(self.titleBar)
        self.btnRestore.setObjectName('btnRestore')
        self.btnRestore.setSizePolicy(spButtons)
        self.btnRestore.setVisible(False)

        self.btnMaximize = QToolButton(self.titleBar)
        self.btnMaximize.setObjectName('btnMaximize')
        self.btnMaximize.setSizePolicy(spButtons)

        self.btnClose = QToolButton(self.titleBar)
        self.btnClose.setObjectName('btnClose')
        self.btnClose.setSizePolicy(spButtons)

        self.vboxFrame.addWidget(self.titleBar)

        self.windowContent = QWidget(self.windowFrame)
        self.vboxFrame.addWidget(self.windowContent)

        self.vboxWindow.addWidget(self.windowFrame)

        if PLATFORM == "Darwin":
            self.hboxTitle.addWidget(self.btnClose)
            self.hboxTitle.addWidget(self.btnMinimize)
            self.hboxTitle.addWidget(self.btnRestore)
            self.hboxTitle.addWidget(self.btnMaximize)
            self.hboxTitle.addWidget(self.lblTitle)
        else:
            self.hboxTitle.addWidget(self.lblTitle)
            self.hboxTitle.addWidget(self.btnMinimize)
            self.hboxTitle.addWidget(self.btnRestore)
            self.hboxTitle.addWidget(self.btnMaximize)
            self.hboxTitle.addWidget(self.btnClose)

        # set window flags
        self.setWindowFlags(Qt.Window | Qt.FramelessWindowHint
                            | Qt.WindowSystemMenuHint)

        if QT_VERSION >= (5, ):
            self.setAttribute(Qt.WA_TranslucentBackground)

        # set stylesheet
        with open(_FL_STYLESHEET) as stylesheet:
            self.setStyleSheet(stylesheet.read())

        # automatically connect slots
        QMetaObject.connectSlotsByName(self)
Пример #35
0
    def __init__(self, parent=None):
        super().__init__(parent)

        # Create viewer widget
        self._viewer = micro_view.MicroViewWidget()
        self._viewer.setObjectName("viewer")
        self._viewer.showLocalizationsChanged.connect(self.setShowPreview)

        # Create dock widgets
        fileChooser = file_chooser.FileChooser()
        fileChooser.selected.connect(self.open)
        self._fileModel = fileChooser.model()
        self._fileModel.rowsRemoved.connect(self._checkFileList)
        self._fileDock = QDockWidget(self.tr("File selection"), self)
        self._fileDock.setObjectName("fileDock")
        self._fileDock.setWidget(fileChooser)

        self._locOptionsWidget = locate_options.Container()
        self._locOptionsWidget.setObjectName("locOptionsWidget")
        self._locOptionsDock = QDockWidget(self.tr("Localization options"),
                                           self)
        self._locOptionsDock.setObjectName("locOptionsDock")
        self._locOptionsDock.setWidget(self._locOptionsWidget)

        self._locFilterWidget = locate_filter.FilterWidget()
        self._locFilterWidget.filterChanged.connect(self._filterLocalizations)
        self._locFilterDock = QDockWidget(self.tr("Localization filter"), self)
        self._locFilterDock.setObjectName("locFilterDock")
        self._locFilterDock.setWidget(self._locFilterWidget)

        locSaveWidget = locate_saver.SaveWidget()
        self._locSaveDock = QDockWidget(self.tr("Save localizations"), self)
        self._locSaveDock.setObjectName("locSaveDock")
        self._locSaveDock.setWidget(locSaveWidget)

        for d in (self._fileDock, self._locOptionsDock, self._locFilterDock,
                  self._locSaveDock):
            d.setFeatures(d.features() & ~QDockWidget.DockWidgetClosable)
            self.addDockWidget(Qt.LeftDockWidgetArea, d)
        self.setDockOptions(self.dockOptions() | QMainWindow.VerticalTabs)

        self.setCentralWidget(self._viewer)

        # set up the preview worker
        self._previewWorker = workers.PreviewWorker(self)
        self._locOptionsWidget.optionsChanged.connect(
            self._makePreviewWorkerWork)
        self._viewer.currentFrameChanged.connect(self._makePreviewWorkerWork)
        self._previewWorker.finished.connect(self._previewFinished)
        self._previewWorker.error.connect(self._previewError)
        self._previewWorker.enabled = True
        self._previewWorker.busyChanged.connect(self._setBusyCursor)

        # set up the batch worker
        self._batchWorker = workers.BatchWorker(self)
        self._batchWorker.fileFinished.connect(self._locateRunnerFinished)
        self._batchWorker.fileError.connect(self._locateRunnerError)

        # batch progress dialog
        self._progressDialog = batch_progress.BatchProgressDialog(self)

        self._batchWorker.fileFinished.connect(
            self._progressDialog.increaseValue)
        self._batchWorker.fileError.connect(self._progressDialog.increaseValue)
        self._progressDialog.canceled.connect(self._batchWorker.stop)

        # Some things to keep track of
        self._currentFile = QPersistentModelIndex()
        self._currentLocData = pd.DataFrame(columns=["x", "y"])
        self._roiPolygon = QPolygonF()

        # load settings and restore window geometry
        settings = QSettings("sdt", "locator")
        v = settings.value("MainWindow/geometry")
        if v is not None:
            self.restoreGeometry(v)
        v = settings.value("MainWindow/state")
        if v is not None:
            self.restoreState(v)

        # restore enable/disable preview
        show = settings.value("Viewer/showPreview", True, type=bool)
        self._viewer.showLocalizations = show

        QMetaObject.connectSlotsByName(self)