コード例 #1
0
ファイル: TestMessage.py プロジェクト: Ultimaker/Uranium
def test_gettersAndSetters():
    message = Message(text = "OMG", title="YAY", image_caption="DERP", image_source= "HERP", option_text="FOO", option_state= False)
    message.setMaxProgress(200)
    assert message.getText() == "OMG"
    assert message.getTitle() == "YAY"
    assert message.getImageCaption() == "DERP"
    assert message.getImageSource() == "HERP"
    assert message.getOptionText() == "FOO"
    assert message.getMaxProgress() == 200
    assert message.getOptionState() == False

    message.setTitle("whoo")
    assert message.getTitle() == "whoo"
コード例 #2
0
def test_gettersAndSetters():
    message = Message(text="OMG",
                      title="YAY",
                      image_caption="DERP",
                      image_source="HERP",
                      option_text="FOO",
                      option_state=False,
                      message_type=Message.MessageType.POSITIVE)
    message.setMaxProgress(200)
    assert message.getText() == "OMG"
    assert message.getTitle() == "YAY"
    assert message.getImageCaption() == "DERP"
    assert message.getImageSource() == "HERP"
    assert message.getOptionText() == "FOO"
    assert message.getMaxProgress() == 200
    assert message.getOptionState() == False

    message.setTitle("whoo")
    assert message.getTitle() == "whoo"
コード例 #3
0
class CuraSnapmakerSenderOutputDevice(
        OutputDevice):  #We need an actual device to do the writing.
    def __init__(self, uri: str, name: str, token=''):
        super().__init__(
            "CuraSnapmakerSenderOutputDevice"
        )  #Give an ID which is used to refer to the output device.
        self._nameofSnapmaker = name
        self._uri = uri
        self._id = uri
        #Optionally set some metadata.
        self.setName("CuraSnapmakerSender")
        self.setShortDescription(
            i18n_catalog.i18nc("@message", "Send To ") +
            self._nameofSnapmaker)  #This is put on the save button.
        self.setDescription(
            i18n_catalog.i18nc("@message", "Send To ") + self._nameofSnapmaker)
        self.setIconName("save")

        self._token = token
        self._printer = SnapmakerApiV1.SnapmakerApiV1(self._uri, self._token)
        self._authrequired_message = Message(i18n_catalog.i18nc(
            "@message",
            "Awaiting Authorization.\r\nPlease allow the connection on your Snapmaker."
        ),
                                             dismissable=False)
        self._authrequired_message.addAction(
            "abort",
            i18n_catalog.i18nc("@button", "Abort"),
            icon="abort",
            description=i18n_catalog.i18nc("@message:description",
                                           "Abort Sending..."))
        self._authrequired_message.actionTriggered.connect(self.abortSend)
        self._connect_failed_message = Message(i18n_catalog.i18nc(
            "@message",
            "Could not connect to your machine. It is either off, the given address is wrong or not reachable or your Snapmaker refused the connection."
        ),
                                               lifetime=30,
                                               dismissable=True,
                                               title='Error')
        self._prepare_send_message = Message(i18n_catalog.i18nc(
            "@message", "Preparing Gcode for sending, please wait."),
                                             dismissable=True,
                                             title='Info')
        self._progress_message = Message(
            i18n_catalog.i18nc("@message", "Sending file to ") +
            self._nameofSnapmaker)

    def requestWrite(self,
                     nodes,
                     file_name=None,
                     limit_mimetypes=None,
                     file_handler=None,
                     **kwargs):
        #Logger.log("d","Firing Timer")
        self._writeHandleTimer = QTimer()
        self._writeHandleTimer.timeout.connect(lambda: self.handleWrite(
            nodes, file_name, limit_mimetypes, file_handler))
        self._writeHandleTimer.setInterval(1)
        self._writeHandleTimer.setSingleShot(True)
        self._writeHandleTimer.start()

    def abortSend(self, message, action):
        message.hide()
        if (self._printer.state !=
                SnapmakerApiV1.SnapmakerApiState.NOTCONNECTED or
                self._printer.state != SnapmakerApiV1.SnapmakerApiState.FATAL):
            self._printer.disconnect()
        self._writeHandleTimer.stop()

    def handleWrite(self,
                    nodes,
                    file_name=None,
                    limit_mimetypes=None,
                    file_handler=None,
                    **kwargs):
        #Logger.log("d","In handleWrite")
        self._writeHandleTimer.setInterval(1000)
        result = None
        if not self._printer.state == SnapmakerApiV1.SnapmakerApiState.IDLE:
            if (self._printer.state ==
                    SnapmakerApiV1.SnapmakerApiState.NOTCONNECTED):
                result = self._printer.connect()
                if result == False:
                    self.writeError.emit()
                    self._connect_failed_message.show()
                    return
            elif (self._printer.state == SnapmakerApiV1.SnapmakerApiState.FATAL
                  ):
                #Logger.log("d",self._printer.state)
                self._printer = SnapmakerApiV1.SnapmakerApiV1(
                    self._uri, self._printer.token)
                result = self._printer.connect()
                if result == False:
                    self.writeError.emit()
                    self._connect_failed_message.show()
                    return
            elif (self._printer.state ==
                  SnapmakerApiV1.SnapmakerApiState.AWAITING_AUTHORIZATION):
                #Logger.log("d",self._printer.state)
                self._authrequired_message.show()
            else:
                #Logger.log("d",self._printer.state)
                self.writeError.emit()
                message = Message(i18n_catalog.i18nc(
                    "@message", "Sending failed, try again later"),
                                  lifetime=30,
                                  dismissable=True,
                                  title='Error')
                message.show()
                return

            self._writeHandleTimer.start()
            return
        #Logger.log("d","Ready to send")
        self._authrequired_message.hide()
        self._prepare_send_message.show()
        self._token = self._printer.token
        self.writeStarted.emit(self)
        print_info = CuraApplication.getInstance().getPrintInformation()
        gcode_writer = MeshWriter()
        self._gcode_stream = StringIO()
        #In case the Plugin Gcodewriter is a separate Plugin
        #try:
        #gcode_writer = cast(MeshWriter, PluginRegistry.getInstance().getPluginObject("CuraSnapmakerSender"))
        #except UM.PluginError.PluginNotFoundError:
        #gcode_writer = cast(MeshWriter, PluginRegistry.getInstance().getPluginObject("GCodeWriter"))
        gcode_writer = SnapmakerGCodeWriter.SnapmakerGCodeWriter()
        if not gcode_writer.write(self._gcode_stream, None):
            #Logger.log("e", "GCodeWrite failed: %s" % gcode_writer.getInformation())
            return
        self.content_length = self._gcode_stream.tell()
        self._gcode_stream.seek(0)
        self._byteStream = BytesIOWrapper(self._gcode_stream)
        self._printer.setBlocking(False)
        self.active_sending_future = self._printer.send_gcode_file(
            print_info.jobName.strip() + ".gcode",
            self._byteStream,
            callback=self.updateProgress)
        self.active_sending_future.add_done_callback(self.transmitDone)
        self._printer.setBlocking(True)
        self._progress_message.setMaxProgress(100)
        self._progress_message.setProgress(0)
        self._progress_message.show()
        #Logger.log("d","WriteRequested")

    def updateProgress(self, monitor):
        ##Logger.log("d",str(monitor.bytes_read) +" of " + str(self.content_length))
        self._prepare_send_message.hide()
        self._progress_message.setProgress(
            (monitor.bytes_read / self.content_length) * 100)
        self.writeProgress.emit()

    def transmitDone(self, future):
        #Logger.log("d","WriteDone")
        self._progress_message.hide()
        if self.active_sending_future.result():
            self.writeFinished.emit()
            self.writeSuccess.emit()
        else:
            self.writeError.emit()

    def tearDown(self):
        self._printer.disconnect()