Skip to content

Commit

Permalink
use Cura printer metadata for storing config
Browse files Browse the repository at this point in the history
fixes #8
  • Loading branch information
Kriechi committed Aug 29, 2020
1 parent 33c4ce4 commit ca03f69
Show file tree
Hide file tree
Showing 11 changed files with 452 additions and 518 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ A clear and concise description of what you expected to happen.
- Cura-DuetRRFPlugin Version and Installation: [e.g. 1.0.6 installed via Marketplace, or git-master]
- Duet RepRapFirmware Version: [e.g. 3.1.1, check with `M122`]

** Cura Log**
**Cura Log**
Based on your Cura version, please drag&drop the log file into the issue, or copy&paste all lines with `DuetRRFPlugin`:
Windows: C:\Users\<username>\AppData\Roaming\cura\4.6\cura.log
macOS: ~/Library/Application Support/Cura/4.6/cura.log
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog of Cura-DuetRRFPlugin

## v1.1.0: 2020-XX-XX
* BREAKING CHANGE: migrate settings to be printer-specific
* auto-migrate legacy settings for active printers if printer name matches

## v1.0.11: 2020-08-29
* bump compatibility for Cura 4.7 / API 7.3
* fix Cura crashes with non-latin strings in Message boxes
Expand Down
106 changes: 106 additions & 0 deletions DuetRRFAction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import os
import json
import re

from PyQt5.QtCore import QObject, pyqtSlot

from cura.CuraApplication import CuraApplication
from cura.MachineAction import MachineAction

from UM.Logger import Logger
from UM.Settings.ContainerRegistry import ContainerRegistry
from UM.Settings.DefinitionContainer import DefinitionContainer
from UM.i18n import i18nCatalog
catalog = i18nCatalog("cura")


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')
self._application = CuraApplication.getInstance()

ContainerRegistry.getInstance().containerAdded.connect(self._onContainerAdded)

def _onContainerAdded(self, container: "ContainerInterface") -> None:
# Add this action as a supported action to all machine definitions
if (
isinstance(container, DefinitionContainer) and
container.getMetaDataEntry("type") == "machine" and
container.getMetaDataEntry("supports_usb_connection")
):
self._application.getMachineActionManager().addSupportedAction(container.getId(), self.getKey())

@pyqtSlot(result=str)
def printerSettingUrl(self):
global_container_stack = self._application.getGlobalContainerStack()
if global_container_stack:
return global_container_stack.getMetaDataEntry("duetrrf_url", "")
return ""

@pyqtSlot(result=str)
def printerSettingDuetPassword(self):
global_container_stack = self._application.getGlobalContainerStack()
if global_container_stack:
return global_container_stack.getMetaDataEntry("duetrrf_duet_password", "")
return ""

@pyqtSlot(result=str)
def printerSettingHTTPUser(self):
global_container_stack = self._application.getGlobalContainerStack()
if global_container_stack:
return global_container_stack.getMetaDataEntry("duetrrf_http_user", "")
return ""

@pyqtSlot(result=str)
def printerSettingHTTPPassword(self):
global_container_stack = self._application.getGlobalContainerStack()
if global_container_stack:
return global_container_stack.getMetaDataEntry("duetrrf_http_password", "")
return ""

@pyqtSlot(str, str, str, str)
def testAndSave(self, url, duet_password, http_user, http_password):
if not url.endswith('/'):
url += '/'

global_container_stack = self._application.getGlobalContainerStack()
if not global_container_stack:
Logger.log("e", "failed to save config: global_container_stack is missing")
return

global_container_stack.setMetaDataEntry("duetrrf", True)
global_container_stack.setMetaDataEntry("duetrrf_url", url)
global_container_stack.setMetaDataEntry("duetrrf_duet_password", duet_password)
global_container_stack.setMetaDataEntry("duetrrf_http_user", http_user)
global_container_stack.setMetaDataEntry("duetrrf_http_password", http_password)
Logger.log("d", "config saved: " + global_container_stack.getName())

@pyqtSlot()
def deleteConfig(self):
global_container_stack = self._application.getGlobalContainerStack()
if not global_container_stack:
Logger.log("e", "failed to delete config: global_container_stack is missing")
return

global_container_stack.removeMetaDataEntry("duetrrf")
global_container_stack.removeMetaDataEntry("duetrrf_url")
global_container_stack.removeMetaDataEntry("duetrrf_duet_password")
global_container_stack.removeMetaDataEntry("duetrrf_http_user")
global_container_stack.removeMetaDataEntry("duetrrf_http_password")
Logger.log("d", "config deleted: " + global_container_stack.getName())

@pyqtSlot(str, result=bool)
def validUrl(self, newUrl):
if newUrl.startswith('\\\\'):
# no UNC paths
return False
if not re.match('^https?://.', newUrl):
# missing https?://
return False
if '@' in newUrl:
# @ is probably HTTP basic auth, which is a separate setting
return False

return True
Loading

0 comments on commit ca03f69

Please sign in to comment.