Exemple #1
0
    def emit(self, *args, **kwargs):
        try:
            if self.__type == Signal.Queued:
                Signal._app.functionEvent(CallFunctionEvent(self.emit, args, kwargs))
                return

            if self.__type == Signal.Auto:
                if threading.current_thread() is not Signal._app.getMainThread():
                    Signal._app.functionEvent(CallFunctionEvent(self.emit, args, kwargs))
                    return
        except AttributeError: # If Signal._app is not set
            return

        # Quickly make some private references to the collections we need to process.
        # Although the these fields are always safe to use read and use with regards to threading,
        # we want to operate on a consistent snapshot of the whole set of fields.
        with self.__lock:
            functions = self.__functions
            methods = self.__methods
            signals = self.__signals

        # Call handler functions
        for func in functions:
            func(*args, **kwargs)

        # Call handler methods
        for dest, func in methods:
            func(dest, *args, **kwargs)

        # Emit connected signals
        for signal in signals:
            signal.emit(*args, **kwargs)
Exemple #2
0
    def emit(self, *args: Any, **kwargs: Any) -> None:
        # Check to see if we need to postpone emits
        if self._postpone_emit:
            if threading.current_thread() != self._postpone_thread:
                Logger.log("w", "Tried to emit signal from thread %s while emits are being postponed by %s. Traceback:", threading.current_thread(), self._postpone_thread)
                tb = traceback.format_stack()
                for line in tb:
                    Logger.log("w", line)

            if self._compress_postpone:
                # If emits should be compressed, we only emit the last emit that was called
                self._postponed_emits = (args, kwargs)
            else:
                # If emits should not be compressed, we catch all calls to emit and put them in a list to be called later.
                if not self._postponed_emits:
                    self._postponed_emits = []
                self._postponed_emits.append((args, kwargs))
            return

        try:
            if self.__type == Signal.Queued:
                Signal._app.functionEvent(CallFunctionEvent(self.__performEmit, args, kwargs))
                return
            if self.__type == Signal.Auto:
                if threading.current_thread() is not Signal._app.getMainThread():
                    Signal._app.functionEvent(CallFunctionEvent(self.__performEmit, args, kwargs))
                    return
        except AttributeError: # If Signal._app is not set
            return

        self.__performEmit(*args, **kwargs)
Exemple #3
0
    def emit(self, *args, **kargs):
        try:
            if self.__type == Signal.Queued:
                Signal._app.functionEvent(CallFunctionEvent(self.emit, args, kargs))
                return

            if self.__type == Signal.Auto:
                if threading.current_thread() is not Signal._app.getMainThread():
                    Signal._app.functionEvent(CallFunctionEvent(self.emit, args, kargs))
                    return
        except AttributeError: # If Signal._app is not set
            return

        self.__emitting = True

        # Call handler functions
        for func in self.__functions:
            func(*args, **kargs)

        # Call handler methods
        for dest, funcs in self.__methods.items():
            for func in funcs:
                func(dest, *args, **kargs)

        # Emit connected signals
        for signal in self.__signals:
            signal.emit(*args, **kargs)

        self.__emitting = False
        for connector in self.__connect_queue:
            self.connect(connector)
        self.__connect_queue.clear()
        for connector in self.__disconnect_queue:
            self.disconnect(connector)
        self.__connect_queue.clear()
Exemple #4
0
    def emit(self, *args, **kwargs):
        try:
            if self.__type == Signal.Queued:
                Signal._app.functionEvent(
                    CallFunctionEvent(self.__performEmit, args, kwargs))
                return
            if self.__type == Signal.Auto:
                if threading.current_thread() is not Signal._app.getMainThread(
                ):
                    Signal._app.functionEvent(
                        CallFunctionEvent(self.__performEmit, args, kwargs))
                    return
        except AttributeError:  # If Signal._app is not set
            return

        self.__performEmit(*args, **kwargs)
Exemple #5
0
    def emit(self, *args: Any, **kwargs: Any) -> None:
        """Emit the signal which indirectly calls all of the connected slots.

        :param args: The positional arguments to pass along.
        :param kwargs: The keyword arguments to pass along.

        :note If the Signal type is Queued and this is not called from the application thread
        the call will be posted as an event to the application main thread, which means the
        function will be called on the next application event loop tick.
        """

        # Check to see if we need to postpone emits
        if self._postpone_emit:
            if threading.current_thread() != self._postpone_thread:
                Logger.log(
                    "w",
                    "Tried to emit signal from thread %s while emits are being postponed by %s. Traceback:",
                    threading.current_thread(), self._postpone_thread)
                tb = traceback.format_stack()
                for line in tb:
                    Logger.log("w", line)

            if self._compress_postpone == CompressTechnique.CompressSingle:
                # If emits should be compressed, we only emit the last emit that was called
                self._postponed_emits = (args, kwargs)
            else:
                # If emits should not be compressed or compressed per parameter value, we catch all calls to emit and put them in a list to be called later.
                if not self._postponed_emits:
                    self._postponed_emits = []
                self._postponed_emits.append((args, kwargs))
            return

        try:
            if self.__type == Signal.Queued:
                Signal._app.functionEvent(
                    CallFunctionEvent(self.__performEmit, args, kwargs))
                return
            if self.__type == Signal.Auto:
                if threading.current_thread() is not Signal._app.getMainThread(
                ):
                    Signal._app.functionEvent(
                        CallFunctionEvent(self.__performEmit, args, kwargs))
                    return
        except AttributeError:  # If Signal._app is not set
            return

        self.__performEmit(*args, **kwargs)
Exemple #6
0
 def openDocumentation(self) -> None:
     # Starting a web browser from a signal handler connected to a menu will crash on windows.
     # So instead, defer the call to the next run of the event loop, since that does work.
     # Note that weirdly enough, only signal handlers that open a web browser fail like that.
     event = CallFunctionEvent(
         self._openUrl, [QUrl("http://ultimaker.com/en/support/software")],
         {})
     cura.CuraApplication.CuraApplication.getInstance().functionEvent(event)
Exemple #7
0
 def openDocumentation(self):
     # Starting a web browser from a signal handler connected to a menu will crash on windows.
     # So instead, defer the call to the next run of the event loop, since that does work.
     # Note that weirdly enough, only signal handlers that open a web browser fail like that.
     event = CallFunctionEvent(self._openUrl, [
         QUrl("http://www.bcn3dtechnologies.com/en/3d-printer/bcn3d-cura/")
     ], {})
     Application.getInstance().functionEvent(event)
Exemple #8
0
 def requestWriteToDevice(self, device_id, file_name):
     # On Windows, calling requestWrite() on LocalFileOutputDevice crashes when called from a signal
     # handler attached to a QML MenuItem. So instead, defer the call to the next run of the event
     # loop, since that does work.
     event = CallFunctionEvent(self._writeToDevice, [
         Application.getInstance().getController().getScene().getRoot(),
         device_id, file_name
     ], {})
     Application.getInstance().functionEvent(event)
 def openDocumentation(self) -> None:
     # Starting a web browser from a signal handler connected to a menu will crash on windows.
     # So instead, defer the call to the next run of the event loop, since that does work.
     # Note that weirdly enough, only signal handlers that open a web browser fail like that.
     event = CallFunctionEvent(
         self._openUrl, [QUrl("https://stereotech.org/manuals/steslicer")],
         {})
     steslicer.SteSlicerApplication.SteSlicerApplication.getInstance(
     ).functionEvent(event)
Exemple #10
0
 def __handleEmitIndirect(self, *args, **kwargs) -> None:
     # Handle any indirect emits of signals (eg; type is "Auto" or "Queued"
     try:
         if self.__type == Signal.Queued:
             Signal._app.functionEvent(
                 CallFunctionEvent(self.__performEmitIndirect, args,
                                   kwargs))
         if self.__type == Signal.Auto:
             if threading.current_thread() is not Signal._app.getMainThread(
             ):
                 Signal._app.functionEvent(
                     CallFunctionEvent(self.__performEmitIndirect, args,
                                       kwargs))
             else:
                 # Signal is emitted from the main thread, so call it directly!
                 self.__performEmit(*args, **kwargs)
     except AttributeError:  # If Signal._app is not set
         pass
Exemple #11
0
 def openDocumentation(self) -> None:
     # Starting a web browser from a signal handler connected to a menu will crash on windows.
     # So instead, defer the call to the next run of the event loop, since that does work.
     # Note that weirdly enough, only signal handlers that open a web browser fail like that.
     event = CallFunctionEvent(self._openUrl, [
         QUrl(
             "https://ultimaker.com/en/resources/manuals/software?utm_source=cura&utm_medium=software&utm_campaign=dropdown-documentation"
         )
     ], {})
     cura.CuraApplication.CuraApplication.getInstance().functionEvent(event)
    def createInstance(self, name, definition_id):
        definition = self._manager.findMachineDefinition(definition_id)

        instance = MachineInstance(self._manager, name = name, definition = definition)
        self._manager.addMachineInstance(instance)

        # Workaround for an issue on OSX where directly calling setActiveMachineInstance would
        # crash in the QML garbage collector.
        event = CallFunctionEvent(self._manager.setActiveMachineInstance, [instance], {})
        Application.getInstance().functionEvent(event)
Exemple #13
0
    def callLater(self, func: Callable[..., Any], *args, **kwargs) -> None:
        """Call a function the next time the event loop runs.
        
        You can't get the result of this function directly. It won't block.
        :param func: The function to call.
        :param args: The positional arguments to pass to the function.
        :param kwargs: The keyword arguments to pass to the function.
        """

        event = CallFunctionEvent(func, args, kwargs)
        self.functionEvent(event)
Exemple #14
0
    def requestWriteSelectionToDevice(self, device_id, file_name):
        if not Selection.hasSelection():
            return

        # On Windows, calling requestWrite() on LocalFileOutputDevice crashes when called from a signal
        # handler attached to a QML MenuItem. So instead, defer the call to the next run of the event
        # loop, since that does work.
        event = CallFunctionEvent(
            self._writeToDevice,
            [Selection.getSelectedObject(0), device_id, file_name], {})
        Application.getInstance().functionEvent(event)
Exemple #15
0
 def openBugReportPage(self):
     event = CallFunctionEvent(
         self._openUrl, [QUrl("http://github.com/BCN3D/Cura/issues")], {})
     Application.getInstance().functionEvent(event)
 def openBugReportPage(self) -> None:
     event = CallFunctionEvent(self._openUrl, [
         QUrl("https://gitlab.com/stereotech/steslicer/ste-slicer/issues")
     ], {})
     steslicer.SteSlicerApplication.SteSlicerApplication.getInstance(
     ).functionEvent(event)
Exemple #17
0
 def openWebsitePage(self):
     event = CallFunctionEvent(self._openUrl, [QUrl("http://intamsys.com")],
                               {})
     Application.getInstance().functionEvent(event)
Exemple #18
0
 def callLater(self, function, *args, **kwargs):
     event = CallFunctionEvent(function, args, kwargs)
     self.functionEvent(event)
Exemple #19
0
 def openLink(self, link):
     event = CallFunctionEvent(self._openUrl, [QUrl(link)], {})
     Application.getInstance().functionEvent(event)
Exemple #20
0
 def openBugReportPage(self):
     event = CallFunctionEvent(
         self._openUrl,
         [QUrl("https://code.alephobjects.com/project/board/10/")], {})
     Application.getInstance().functionEvent(event)
 def openBugReportPage(self) -> None:
     event = CallFunctionEvent(self._openUrl, [QUrl("https://github.com/Ultimaker/Cura/issues")], {})
     cura.CuraApplication.CuraApplication.getInstance().functionEvent(event)
Exemple #22
0
 def openPartsPage(self):
     event = CallFunctionEvent(
         self._openUrl, [QUrl("https://www.lulzbot.com/store/parts")], {})
     Application.getInstance().functionEvent(event)
Exemple #23
0
 def callLater(self, func: Callable[..., Any], *args, **kwargs) -> None:
     event = CallFunctionEvent(func, args, kwargs)
     self.functionEvent(event)
Exemple #24
0
 def openMerchandisePage(self):
     event = CallFunctionEvent(
         self._openUrl, [QUrl("https://www.lulzbot.com/store/merchandise")],
         {})
     Application.getInstance().functionEvent(event)