Skip to content

Commit

Permalink
retain compatibility with older Cura versions because the Ultimaker M…
Browse files Browse the repository at this point in the history
…arketplace only supports one plugin version globally for all Cura's
  • Loading branch information
Kriechi committed Aug 3, 2022
1 parent b8d39a3 commit 04d8d25
Show file tree
Hide file tree
Showing 10 changed files with 218 additions and 14 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog of Cura-DuetRRFPlugin

## v1.2.7: 2022-04-26
* bump compatibility for Cura 5.0 / API 8.0, while retaining compatibility with Cura 4.11 / 7.7 and up

## v1.2.6: 2022-04-23
* bump compatibility for Cura 5.0 / API 8.0, for older Cura versions, please use plugin v1.2.5 or older
* fixed simulation progress reports
Expand Down
11 changes: 9 additions & 2 deletions DuetRRFAction.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import os
import re
import sys
from typing import Optional

from PyQt6.QtCore import QObject, pyqtSlot, pyqtProperty, pyqtSignal
try: # Cura 5
from PyQt6.QtCore import QObject, pyqtSlot, pyqtProperty, pyqtSignal
except: # Cura 4
from PyQt5.QtCore import QObject, pyqtSlot, pyqtProperty, pyqtSignal

from cura.CuraApplication import CuraApplication
from cura.MachineAction import MachineAction
Expand All @@ -20,7 +24,10 @@ class DuetRRFAction(MachineAction):
def __init__(self, parent: QObject = None) -> None:
super().__init__("DuetRRFAction", catalog.i18nc("@action", "Connect Duet RepRapFirmware"))

self._qml_url = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'resources', 'qml', 'DuetRRFAction.qml')
extra_path = ""
if "PyQt5" in sys.modules: # Cura 4
extra_path = "legacy"
self._qml_url = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'resources', 'qml', extra_path, 'DuetRRFAction.qml')

self._application = CuraApplication.getInstance()
self._application.globalContainerStackChanged.connect(self._onGlobalContainerStackChanged)
Expand Down
18 changes: 14 additions & 4 deletions DuetRRFOutputDevice.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
import os.path
import datetime
import urllib
Expand All @@ -7,9 +8,14 @@
from typing import cast
from enum import Enum

from PyQt6.QtNetwork import QNetworkReply
from PyQt6.QtCore import QUrl, QObject, QByteArray, QTimer
from PyQt6.QtGui import QDesktopServices
try: # Cura 5
from PyQt6.QtNetwork import QNetworkReply
from PyQt6.QtCore import QUrl, QObject, QByteArray, QTimer
from PyQt6.QtGui import QDesktopServices
except: # Cura 4
from PyQt5.QtNetwork import QNetworkReply
from PyQt5.QtCore import QUrl, QObject, QByteArray, QTimer
from PyQt5.QtGui import QDesktopServices

from cura.CuraApplication import CuraApplication

Expand Down Expand Up @@ -171,7 +177,11 @@ def requestWrite(self, node, fileName=None, *args, **kwargs):
fileName = "%s.gcode" % Application.getInstance().getPrintInformation().jobName
self._fileName = fileName

path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'resources', 'qml', 'UploadFilename.qml')
extra_path = ""
if "PyQt5" in sys.modules: # Cura 4
extra_path = "legacy"
path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'resources', 'qml', extra_path, 'UploadFilename.qml')

self._dialog = CuraApplication.getInstance().createQmlComponent(path, {"manager": self})
self._dialog.textChanged.connect(self._onFilenameChanged)
self._dialog.accepted.connect(self._onFilenameAccepted)
Expand Down
5 changes: 4 additions & 1 deletion DuetRRFPlugin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import json

from PyQt6.QtCore import QTimer
try: # Cura 5
from PyQt6.QtCore import QTimer
except: # Cura 4
from PyQt5.QtCore import QTimer

from cura.CuraApplication import CuraApplication
from cura.Settings.CuraContainerRegistry import CuraContainerRegistry
Expand Down
4 changes: 2 additions & 2 deletions plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"name": "DuetRRF",
"author": "Thomas Kriechbaumer",
"description": "Upload and Print to Duet 2 Wifi / Duet 2 Ethernet / Duet 2 Maestro / Duet 3 with RepRapFirmware.",
"version": "1.2.6",
"supported_sdk_versions": ["8.0.0"]
"version": "1.2.7",
"supported_sdk_versions": ["7.7.0", "7.8.0", "7.9.0", "8.0.0"]
}
1 change: 0 additions & 1 deletion resources/qml/DuetRRFAction.qml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import QtQuick.Window 2.2
import UM 1.5 as UM
import Cura 1.1 as Cura


Cura.MachineAction
{
id: base;
Expand Down
1 change: 0 additions & 1 deletion resources/qml/UploadFilename.qml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import QtQuick 2.10
import QtQuick.Controls 2.3
import QtQuick.Window 2.2
import QtQuick.Dialogs

import UM 1.5 as UM
import Cura 1.1 as Cura
Expand Down
113 changes: 113 additions & 0 deletions resources/qml/legacy/DuetRRFAction.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import QtQuick 2.2
import QtQuick.Controls 1.1
import QtQuick.Layouts 1.1
import QtQuick.Window 2.1

import UM 1.2 as UM
import Cura 1.0 as Cura


Cura.MachineAction
{
id: base;

property var finished: manager.finished
onFinishedChanged: if(manager.finished) {completed()}

function reset()
{
manager.reset()
}

anchors.fill: parent;
property var selectedInstance: null

property bool validUrl: true;

Component.onCompleted: {
actionDialog.minimumWidth = screenScaleFactor * 500;
actionDialog.minimumHeight = screenScaleFactor * 255;
actionDialog.maximumWidth = screenScaleFactor * 500;
actionDialog.maximumHeight = screenScaleFactor * 255;
}

Column {
anchors.fill: parent;

Item { width: parent.width; }
Label { text: catalog.i18nc("@label", "Duet Address (URL)"); }
TextField {
id: urlField;
text: manager.printerSettingUrl;
maximumLength: 1024;
anchors.left: parent.left;
anchors.right: parent.right;
onTextChanged: {
base.validUrl = manager.validUrl(urlField.text);
}
}

Item { width: parent.width; }
Label { text: catalog.i18nc("@label", "Duet Password (if you used M551)"); }
TextField {
id: duet_passwordField;
text: manager.printerSettingDuetPassword;
maximumLength: 1024;
anchors.left: parent.left;
anchors.right: parent.right;
}

Item { width: parent.width; }
Label { text: catalog.i18nc("@label", "HTTP Basic Auth: user (if you run a reverse proxy)"); }
TextField {
id: http_userField;
text: manager.printerSettingHTTPUser;
maximumLength: 1024;
anchors.left: parent.left;
anchors.right: parent.right;
}

Item { width: parent.width; }
Label { text: catalog.i18nc("@label", "HTTP Basic Auth: password (if you run a reverse proxy)"); }
TextField {
id: http_passwordField;
text: manager.printerSettingHTTPPassword;
maximumLength: 1024;
anchors.left: parent.left;
anchors.right: parent.right;
}

Item { width: parent.width; }
Label {
visible: !base.validUrl;
text: catalog.i18nc("@error", "URL not valid. Example: http://192.168.1.42/");
color: "red";
}

Item {
width: saveButton.implicitWidth
height: saveButton.implicitHeight
}

Button {
id: saveButton;
text: catalog.i18nc("@action:button", "Save Config");
width: screenScaleFactor * 100;
onClicked: {
manager.saveConfig(urlField.text, duet_passwordField.text, http_userField.text, http_passwordField.text);
actionDialog.reject();
}
enabled: base.validUrl;
}

Button {
id: deleteButton;
text: catalog.i18nc("@action:button", "Delete Config");
width: screenScaleFactor * 100;
onClicked: {
manager.deleteConfig();
actionDialog.reject();
}
}
}
}
65 changes: 65 additions & 0 deletions resources/qml/legacy/UploadFilename.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import QtQuick 2.1
import QtQuick.Controls 1.1
import QtQuick.Dialogs 1.2
import QtQuick.Window 2.1

import UM 1.1 as UM

UM.Dialog
{
id: base;
property string object: "";

property alias newName: nameField.text;
property bool validName: true;
property string validationError;
property string dialogTitle: "Upload Filename";

title: dialogTitle;

minimumWidth: screenScaleFactor * 400
minimumHeight: screenScaleFactor * 120

property variant catalog: UM.I18nCatalog { name: "uranium"; }

signal textChanged(string text);
signal selectText()
onSelectText: {
nameField.selectAll();
nameField.focus = true;
}

Column {
anchors.fill: parent;

TextField {
objectName: "nameField";
id: nameField;
width: parent.width;
text: base.object;
maximumLength: 100;
onTextChanged: base.textChanged(text);
Keys.onReturnPressed: { if (base.validName) base.accept(); }
Keys.onEnterPressed: { if (base.validName) base.accept(); }
Keys.onEscapePressed: base.reject();
}

Label {
visible: !base.validName;
text: base.validationError;
}
}

rightButtons: [
Button {
text: catalog.i18nc("@action:button", "Cancel");
onClicked: base.reject();
},
Button {
text: catalog.i18nc("@action:button", "OK");
onClicked: base.accept();
enabled: base.validName;
isDefault: true;
}
]
}
11 changes: 8 additions & 3 deletions thumbnails.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@
import traceback
from io import StringIO

from PyQt6 import QtCore
from PyQt6.QtCore import QCoreApplication, QBuffer
from PyQt6.QtGui import QImage
try: # Cura 5
from PyQt6 import QtCore
from PyQt6.QtCore import QCoreApplication, QBuffer
from PyQt6.QtGui import QImage
except: # Cura 4
from PyQt5 import QtCore
from PyQt5.QtCore import QCoreApplication, QBuffer
from PyQt5.QtGui import QImage

from UM.Application import Application
from UM.Logger import Logger
Expand Down

0 comments on commit 04d8d25

Please sign in to comment.