-
-
Notifications
You must be signed in to change notification settings - Fork 70
/
UploadOptions.py
113 lines (84 loc) · 3.31 KB
/
UploadOptions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# Copyright (c) 2022 Aldo Hoeben / fieldOfView
# OctoPrintPlugin is released under the terms of the AGPLv3 or higher.
from UM.Application import Application
from UM.Version import Version
from UM.Util import parseBool
try:
from cura.ApplicationMetadata import CuraSDKVersion
except ImportError: # Cura <= 3.6
CuraSDKVersion = "6.0.0"
USE_QT5 = False
if CuraSDKVersion >= "8.0.0":
from PyQt6.QtCore import QObject, pyqtSignal, pyqtProperty, pyqtSlot
else:
from PyQt5.QtCore import QObject, pyqtSignal, pyqtProperty, pyqtSlot
USE_QT5 = True
import os.path
from typing import Any, Tuple, List, Dict, Callable, Optional
class UploadOptions(QObject):
def __init__(self) -> None:
super().__init__()
self._application = Application.getInstance()
self._proceed_callback = None # type: Optional[Callable]
self._file_name = ""
self._file_path = ""
self._auto_select = False
self._auto_print = False
self._qml_folder = "qml" if not USE_QT5 else "qml_qt5"
def configure(self, global_container_stack, file_name) -> None:
self.setAutoPrint(
parseBool(
global_container_stack.getMetaDataEntry("octoprint_auto_print", True)
)
)
self.setAutoSelect(
parseBool(
global_container_stack.getMetaDataEntry("octoprint_auto_select", False)
)
)
file_name_segments = file_name.split("/")
self.setFileName(file_name_segments.pop())
self.setFilePath("/".join(file_name_segments))
def setProceedCallback(self, callback: Callable) -> None:
self._proceed_callback = callback
def showOptionsDialog(self) -> None:
path = os.path.join(
os.path.dirname(os.path.abspath(__file__)), self._qml_folder, "UploadOptions.qml"
)
self._settings_dialog = self._application.createQmlComponent(
path, {"manager": self}
)
if self._settings_dialog:
self._settings_dialog.show()
@pyqtSlot()
def acceptOptionsDialog(self) -> None:
if self._proceed_callback:
self._proceed_callback()
fileNameChanged = pyqtSignal()
def setFileName(self, file_name: str) -> None:
self._file_name = file_name
self.fileNameChanged.emit()
@pyqtProperty(str, notify=fileNameChanged, fset=setFileName)
def fileName(self) -> str:
return self._file_name
filePathChanged = pyqtSignal()
def setFilePath(self, file_path: str) -> None:
self._file_path = file_path
self.filePathChanged.emit()
@pyqtProperty(str, notify=filePathChanged, fset=setFilePath)
def filePath(self) -> str:
return self._file_path
autoSelectChanged = pyqtSignal()
def setAutoSelect(self, auto_select: bool) -> None:
self._auto_select = auto_select
self.autoSelectChanged.emit()
@pyqtProperty(bool, notify=autoSelectChanged, fset=setAutoSelect)
def autoSelect(self) -> bool:
return self._auto_select
autoPrintChanged = pyqtSignal()
def setAutoPrint(self, auto_print: bool) -> None:
self._auto_print = auto_print
self.autoPrintChanged.emit()
@pyqtProperty(bool, notify=autoPrintChanged, fset=setAutoPrint)
def autoPrint(self) -> bool:
return self._auto_print