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 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
Beispiel #3
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")
Beispiel #4
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)
            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
 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))
Beispiel #7
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
Beispiel #8
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
Beispiel #9
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))
 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
Beispiel #11
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
Beispiel #12
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
Beispiel #13
0
def trigger_action(action):
    QMetaObject.invokeMethod(action, 'trigger', Qt.QueuedConnection)
Beispiel #14
0
 def click_button(self, name):
     button = self.get_button(name)
     QMetaObject.invokeMethod(button, 'click', Qt.QueuedConnection)
Beispiel #15
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)
Beispiel #16
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)
 def set_function_string(self, text):
     box = self.get_active_modal_widget()
     box.setTextValue(text)
     QMetaObject.invokeMethod(box, 'accept', Qt.QueuedConnection)
Beispiel #18
0
 def click_button(self, name):
     button = self.get_button(name)
     QMetaObject.invokeMethod(button, 'click', Qt.QueuedConnection)
Beispiel #19
0
 def handle_runs_loaded(self) -> None:
     """Handles when new run numbers are loaded. QMetaObject is required so its executed on the GUI thread."""
     QMetaObject.invokeMethod(self, "_handle_runs_loaded")
Beispiel #20
0
def trigger_action(action):
    QMetaObject.invokeMethod(action, 'trigger', Qt.QueuedConnection)
Beispiel #21
0
 def callback(x):
     QMetaObject.invokeMethod(calc, "accept", Qt.QueuedConnection)
 def set_function_string(self, text):
     box = self.get_active_modal_widget()
     box.setTextValue(text)
     QMetaObject.invokeMethod(box, 'accept', Qt.QueuedConnection)
Beispiel #23
0
 def handle_instrument_changed(self) -> None:
     """User changes the selected instrument."""
     QMetaObject.invokeMethod(self, "_handle_instrument_changed")
Beispiel #24
0
 def notify_subscribers(self, arg=None, **kwargs):
     self.arg = arg
     self.kwargs = kwargs
     QMetaObject.invokeMethod(self, '_notify_subscribers_impl')