|
@@ -6,13 +6,7 @@
|
6
|
6
|
#
|
7
|
7
|
# Main application logic.
|
8
|
8
|
|
9
|
|
-import json
|
10
|
9
|
import sys
|
11
|
|
-import time
|
12
|
|
-import urllib.parse
|
13
|
|
-import urllib.request
|
14
|
|
-import operator
|
15
|
|
-import socket
|
16
|
10
|
from os import path
|
17
|
11
|
from PyQt5 import QtNetwork
|
18
|
12
|
from PyQt5.QtWidgets import QSystemTrayIcon, QAction, QMenu, QMessageBox, QDesktopWidget
|
|
@@ -21,11 +15,17 @@ from PyQt5.QtCore import QCoreApplication, QSettings, QUrl
|
21
|
15
|
from CamWindow import CamWindow
|
22
|
16
|
from SettingsWindow import SettingsWindow
|
23
|
17
|
from MainWindow import MainWindow
|
|
18
|
+from APIOctoprint import APIOctoprint
|
|
19
|
+
|
|
20
|
+class Printer(object):
|
|
21
|
+ # field 'api' for actual I/O
|
|
22
|
+ # field 'host' and 'key' for credentials
|
|
23
|
+ pass
|
24
|
24
|
|
25
|
25
|
class OctoTray():
|
26
|
26
|
name = "OctoTray"
|
27
|
27
|
vendor = "xythobuz"
|
28
|
|
- version = "0.4"
|
|
28
|
+ version = "0.5"
|
29
|
29
|
|
30
|
30
|
iconName = "octotray_icon.png"
|
31
|
31
|
iconPaths = [
|
|
@@ -39,16 +39,9 @@ class OctoTray():
|
39
|
39
|
|
40
|
40
|
networkTimeout = 2.0 # in s
|
41
|
41
|
|
42
|
|
- # list of lists, inner lists contain printer data:
|
43
|
|
- # first elements as in SettingsWindow.columns
|
44
|
|
- # 0=host 1=key 2=tool-preheat 3=bed-preheat
|
45
|
|
- # rest used for system-commands, menu, actions
|
|
42
|
+ # list of Printer objects
|
46
|
43
|
printers = []
|
47
|
44
|
|
48
|
|
- statesWithWarning = [
|
49
|
|
- "Printing", "Pausing", "Paused"
|
50
|
|
- ]
|
51
|
|
-
|
52
|
45
|
camWindows = []
|
53
|
46
|
settingsWindow = None
|
54
|
47
|
|
|
@@ -67,90 +60,81 @@ class OctoTray():
|
67
|
60
|
|
68
|
61
|
unknownCount = 0
|
69
|
62
|
for p in self.printers:
|
70
|
|
- method = self.getMethod(p[0], p[1])
|
71
|
|
- print("Printer " + p[0] + " has method " + method)
|
72
|
|
- if method == "unknown":
|
73
|
|
- unknownCount += 1
|
|
63
|
+ p.api = APIOctoprint(self, p.host, p.key)
|
|
64
|
+ p.menus = []
|
|
65
|
+
|
|
66
|
+ commands = p.api.getAvailableCommands()
|
74
|
67
|
|
75
|
|
- action = QAction(p[0])
|
|
68
|
+ # don't populate menu when no methods are available
|
|
69
|
+ if len(commands) == 0:
|
|
70
|
+ unknownCount += 1
|
|
71
|
+ action = QAction(p.host)
|
76
|
72
|
action.setEnabled(False)
|
77
|
|
- p.append(action)
|
|
73
|
+ p.menus.append(action)
|
78
|
74
|
self.menu.addAction(action)
|
79
|
|
-
|
80
|
75
|
continue
|
81
|
76
|
|
82
|
|
- commands = self.getSystemCommands(p[0], p[1])
|
83
|
|
- p.append(commands)
|
84
|
|
-
|
85
|
|
- menu = QMenu(self.getName(p[0], p[1]))
|
86
|
|
- p.append(menu)
|
|
77
|
+ # top level menu for this printer
|
|
78
|
+ menu = QMenu(p.api.getName())
|
|
79
|
+ p.menus.append(menu)
|
87
|
80
|
self.menu.addMenu(menu)
|
88
|
81
|
|
89
|
|
- if method == "psucontrol":
|
90
|
|
- action = QAction("Turn On PSU")
|
91
|
|
- action.triggered.connect(lambda chk, x=p: self.printerOnAction(x))
|
92
|
|
- p.append(action)
|
93
|
|
- menu.addAction(action)
|
94
|
|
-
|
95
|
|
- action = QAction("Turn Off PSU")
|
96
|
|
- action.triggered.connect(lambda chk, x=p: self.printerOffAction(x))
|
97
|
|
- p.append(action)
|
98
|
|
- menu.addAction(action)
|
99
|
|
-
|
100
|
|
- for i in range(0, len(commands)):
|
101
|
|
- action = QAction(commands[i].title())
|
102
|
|
- action.triggered.connect(lambda chk, x=p, y=i: self.printerSystemCommandAction(x, y))
|
103
|
|
- p.append(action)
|
|
82
|
+ # create action for all available commands
|
|
83
|
+ for cmd in commands:
|
|
84
|
+ name, func = cmd
|
|
85
|
+ action = QAction(name)
|
|
86
|
+ action.triggered.connect(lambda chk, p=p, n=name, f=func: p.api.f(n))
|
|
87
|
+ p.menus.append(action)
|
104
|
88
|
menu.addAction(action)
|
105
|
89
|
|
106
|
|
- if (p[2] != None) or (p[3] != None):
|
|
90
|
+ if (p.tempTool != None) or (p.tempBed != None):
|
107
|
91
|
menu.addSeparator()
|
108
|
92
|
|
109
|
|
- if p[2] != None:
|
|
93
|
+ if p.tempTool != None:
|
110
|
94
|
action = QAction("Preheat Tool")
|
111
|
|
- action.triggered.connect(lambda chk, x=p: self.printerHeatTool(x))
|
112
|
|
- p.append(action)
|
|
95
|
+ action.triggered.connect(lambda chk, p=p: p.api.printerHeatTool(p.tempTool))
|
|
96
|
+ p.menus.append(action)
|
113
|
97
|
menu.addAction(action)
|
114
|
98
|
|
115
|
|
- if p[3] != None:
|
|
99
|
+ if p.tempBed != None:
|
116
|
100
|
action = QAction("Preheat Bed")
|
117
|
|
- action.triggered.connect(lambda chk, x=p: self.printerHeatBed(x))
|
118
|
|
- p.append(action)
|
|
101
|
+ action.triggered.connect(lambda chk, p=p: p.api.printerHeatBed(p.tempBed))
|
|
102
|
+ p.menus.append(action)
|
119
|
103
|
menu.addAction(action)
|
120
|
104
|
|
121
|
|
- if (p[2] != None) or (p[3] != None):
|
|
105
|
+ if (p.tempTool != None) or (p.tempBed != None):
|
122
|
106
|
action = QAction("Cooldown")
|
123
|
|
- action.triggered.connect(lambda chk, x=p: self.printerCooldown(x))
|
124
|
|
- p.append(action)
|
|
107
|
+ action.triggered.connect(lambda chk, p=p: p.api.printerCooldown())
|
|
108
|
+ p.menus.append(action)
|
125
|
109
|
menu.addAction(action)
|
126
|
110
|
|
127
|
111
|
menu.addSeparator()
|
128
|
112
|
|
129
|
113
|
fileMenu = QMenu("Recent Files")
|
130
|
|
- p.append(fileMenu)
|
|
114
|
+ p.menus.append(fileMenu)
|
131
|
115
|
menu.addMenu(fileMenu)
|
132
|
116
|
|
133
|
|
- files = self.getRecentFiles(p[0], p[1], 10)
|
|
117
|
+ files = p.api.getRecentFiles(10)
|
134
|
118
|
for f in files:
|
135
|
119
|
fileName, filePath = f
|
136
|
120
|
action = QAction(fileName)
|
137
|
|
- action.triggered.connect(lambda chk, x=p, y=filePath: self.printerFilePrint(x, y))
|
138
|
|
- p.append(action)
|
|
121
|
+ action.triggered.connect(lambda chk, p=p, f=filePath: p.api.printFile(f))
|
|
122
|
+ p.menus.append(action)
|
139
|
123
|
fileMenu.addAction(action)
|
140
|
124
|
|
141
|
125
|
action = QAction("Get Status")
|
142
|
|
- action.triggered.connect(lambda chk, x=p: self.printerStatusAction(x))
|
143
|
|
- p.append(action)
|
|
126
|
+ action.triggered.connect(lambda chk, p=p: p.api.statusDialog())
|
|
127
|
+ p.menus.append(action)
|
144
|
128
|
menu.addAction(action)
|
145
|
129
|
|
146
|
130
|
action = QAction("Show Webcam")
|
147
|
131
|
action.triggered.connect(lambda chk, x=p: self.printerWebcamAction(x))
|
148
|
|
- p.append(action)
|
|
132
|
+ p.menus.append(action)
|
149
|
133
|
menu.addAction(action)
|
150
|
134
|
|
151
|
135
|
action = QAction("Open Web UI")
|
152
|
136
|
action.triggered.connect(lambda chk, x=p: self.printerWebAction(x))
|
153
|
|
- p.append(action)
|
|
137
|
+ p.menus.append(action)
|
154
|
138
|
menu.addAction(action)
|
155
|
139
|
|
156
|
140
|
self.menu.addSeparator()
|
|
@@ -220,11 +204,11 @@ class OctoTray():
|
220
|
204
|
l = settings.beginReadArray("printers")
|
221
|
205
|
for i in range(0, l):
|
222
|
206
|
settings.setArrayIndex(i)
|
223
|
|
- p = []
|
224
|
|
- p.append(settings.value("host"))
|
225
|
|
- p.append(settings.value("key"))
|
226
|
|
- p.append(settings.value("tool_preheat"))
|
227
|
|
- p.append(settings.value("bed_preheat"))
|
|
207
|
+ p = Printer()
|
|
208
|
+ p.host = settings.value("host")
|
|
209
|
+ p.key = settings.value("key")
|
|
210
|
+ p.tempTool = settings.value("tool_preheat")
|
|
211
|
+ p.tempBed = settings.value("bed_preheat")
|
228
|
212
|
printers.append(p)
|
229
|
213
|
settings.endArray()
|
230
|
214
|
return printers
|
|
@@ -240,10 +224,10 @@ class OctoTray():
|
240
|
224
|
for i in range(0, len(printers)):
|
241
|
225
|
p = printers[i]
|
242
|
226
|
settings.setArrayIndex(i)
|
243
|
|
- settings.setValue("host", p[0])
|
244
|
|
- settings.setValue("key", p[1])
|
245
|
|
- settings.setValue("tool_preheat", p[2])
|
246
|
|
- settings.setValue("bed_preheat", p[3])
|
|
227
|
+ settings.setValue("host", p.host)
|
|
228
|
+ settings.setValue("key", p.key)
|
|
229
|
+ settings.setValue("tool_preheat", p.tempTool)
|
|
230
|
+ settings.setValue("bed_preheat", p.tempBed)
|
247
|
231
|
settings.endArray()
|
248
|
232
|
del settings
|
249
|
233
|
|
|
@@ -279,327 +263,15 @@ class OctoTray():
|
279
|
263
|
else:
|
280
|
264
|
return False
|
281
|
265
|
|
282
|
|
- def sendRequest(self, host, headers, path, content = None):
|
283
|
|
- url = "http://" + host + "/api/" + path
|
284
|
|
- if content == None:
|
285
|
|
- request = urllib.request.Request(url, None, headers)
|
286
|
|
- else:
|
287
|
|
- data = content.encode('ascii')
|
288
|
|
- request = urllib.request.Request(url, data, headers)
|
289
|
|
-
|
290
|
|
- try:
|
291
|
|
- with urllib.request.urlopen(request, None, self.networkTimeout) as response:
|
292
|
|
- text = response.read()
|
293
|
|
- return text
|
294
|
|
- except (urllib.error.URLError, urllib.error.HTTPError) as error:
|
295
|
|
- print("Error requesting URL \"" + url + "\": \"" + str(error) + "\"")
|
296
|
|
- return "error"
|
297
|
|
- except socket.timeout:
|
298
|
|
- print("Timeout waiting for response to \"" + url + "\"")
|
299
|
|
- return "timeout"
|
300
|
|
-
|
301
|
|
- def sendPostRequest(self, host, key, path, content):
|
302
|
|
- headers = {
|
303
|
|
- "Content-Type": "application/json",
|
304
|
|
- "X-Api-Key": key
|
305
|
|
- }
|
306
|
|
- return self.sendRequest(host, headers, path, content)
|
307
|
|
-
|
308
|
|
- def sendGetRequest(self, host, key, path):
|
309
|
|
- headers = {
|
310
|
|
- "X-Api-Key": key
|
311
|
|
- }
|
312
|
|
- return self.sendRequest(host, headers, path)
|
313
|
|
-
|
314
|
|
- def getTemperatureIsSafe(self, host, key):
|
315
|
|
- r = self.sendGetRequest(host, key, "printer")
|
316
|
|
- try:
|
317
|
|
- rd = json.loads(r)
|
318
|
|
-
|
319
|
|
- if "temperature" in rd:
|
320
|
|
- if ("tool0" in rd["temperature"]) and ("actual" in rd["temperature"]["tool0"]):
|
321
|
|
- if rd["temperature"]["tool0"]["actual"] > 50.0:
|
322
|
|
- return False
|
323
|
|
-
|
324
|
|
- if ("tool1" in rd["temperature"]) and ("actual" in rd["temperature"]["tool1"]):
|
325
|
|
- if rd["temperature"]["tool1"]["actual"] > 50.0:
|
326
|
|
- return False
|
327
|
|
- except json.JSONDecodeError:
|
328
|
|
- pass
|
329
|
|
- return True
|
330
|
|
-
|
331
|
|
- def getTemperatureString(self, host, key):
|
332
|
|
- r = self.sendGetRequest(host, key, "printer")
|
333
|
|
- s = ""
|
334
|
|
- try:
|
335
|
|
- rd = json.loads(r)
|
336
|
|
-
|
337
|
|
- if ("state" in rd) and ("text" in rd["state"]):
|
338
|
|
- s += rd["state"]["text"]
|
339
|
|
- if "temperature" in rd:
|
340
|
|
- s += " - "
|
341
|
|
-
|
342
|
|
- if "temperature" in rd:
|
343
|
|
- if "bed" in rd["temperature"]:
|
344
|
|
- if "actual" in rd["temperature"]["bed"]:
|
345
|
|
- s += "B"
|
346
|
|
- s += "%.1f" % rd["temperature"]["bed"]["actual"]
|
347
|
|
- if "target" in rd["temperature"]["bed"]:
|
348
|
|
- s += "/"
|
349
|
|
- s += "%.1f" % rd["temperature"]["bed"]["target"]
|
350
|
|
- s += " "
|
351
|
|
-
|
352
|
|
- if "tool0" in rd["temperature"]:
|
353
|
|
- if "actual" in rd["temperature"]["tool0"]:
|
354
|
|
- s += "T"
|
355
|
|
- s += "%.1f" % rd["temperature"]["tool0"]["actual"]
|
356
|
|
- if "target" in rd["temperature"]["tool0"]:
|
357
|
|
- s += "/"
|
358
|
|
- s += "%.1f" % rd["temperature"]["tool0"]["target"]
|
359
|
|
- s += " "
|
360
|
|
-
|
361
|
|
- if "tool1" in rd["temperature"]:
|
362
|
|
- if "actual" in rd["temperature"]["tool1"]:
|
363
|
|
- s += "T"
|
364
|
|
- s += "%.1f" % rd["temperature"]["tool1"]["actual"]
|
365
|
|
- if "target" in rd["temperature"]["tool1"]:
|
366
|
|
- s += "/"
|
367
|
|
- s += "%.1f" % rd["temperature"]["tool1"]["target"]
|
368
|
|
- s += " "
|
369
|
|
- except json.JSONDecodeError:
|
370
|
|
- pass
|
371
|
|
- return s.strip()
|
372
|
|
-
|
373
|
|
- def getState(self, host, key):
|
374
|
|
- r = self.sendGetRequest(host, key, "job")
|
375
|
|
- try:
|
376
|
|
- rd = json.loads(r)
|
377
|
|
- if "state" in rd:
|
378
|
|
- return rd["state"]
|
379
|
|
- except json.JSONDecodeError:
|
380
|
|
- pass
|
381
|
|
- return "Unknown"
|
382
|
|
-
|
383
|
|
- def getProgress(self, host, key):
|
384
|
|
- r = self.sendGetRequest(host, key, "job")
|
385
|
|
- try:
|
386
|
|
- rd = json.loads(r)
|
387
|
|
- if "progress" in rd:
|
388
|
|
- return rd["progress"]
|
389
|
|
- except json.JSONDecodeError:
|
390
|
|
- pass
|
391
|
|
- return "Unknown"
|
392
|
|
-
|
393
|
|
- def getName(self, host, key):
|
394
|
|
- r = self.sendGetRequest(host, key, "printerprofiles")
|
395
|
|
- try:
|
396
|
|
- rd = json.loads(r)
|
397
|
|
- if "profiles" in rd:
|
398
|
|
- p = next(iter(rd["profiles"]))
|
399
|
|
- if "name" in rd["profiles"][p]:
|
400
|
|
- return rd["profiles"][p]["name"]
|
401
|
|
- except json.JSONDecodeError:
|
402
|
|
- pass
|
403
|
|
- return host
|
404
|
|
-
|
405
|
|
- def getRecentFiles(self, host, key, count):
|
406
|
|
- r = self.sendGetRequest(host, key, "files?recursive=true")
|
407
|
|
- files = []
|
408
|
|
- try:
|
409
|
|
- rd = json.loads(r)
|
410
|
|
- if "files" in rd:
|
411
|
|
- t = [f for f in rd["files"] if "date" in f]
|
412
|
|
- fs = sorted(t, key=operator.itemgetter("date"), reverse=True)
|
413
|
|
- for f in fs[:count]:
|
414
|
|
- files.append((f["name"], f["origin"] + "/" + f["path"]))
|
415
|
|
- except json.JSONDecodeError:
|
416
|
|
- pass
|
417
|
|
- return files
|
418
|
|
-
|
419
|
|
- def getMethod(self, host, key):
|
420
|
|
- r = self.sendGetRequest(host, key, "plugin/psucontrol")
|
421
|
|
- if r == "timeout":
|
422
|
|
- return "unknown"
|
423
|
|
-
|
424
|
|
- try:
|
425
|
|
- rd = json.loads(r)
|
426
|
|
- if "isPSUOn" in rd:
|
427
|
|
- return "psucontrol"
|
428
|
|
- except json.JSONDecodeError:
|
429
|
|
- pass
|
430
|
|
-
|
431
|
|
- r = self.sendGetRequest(host, key, "system/commands/custom")
|
432
|
|
- if r == "timeout":
|
433
|
|
- return "unknown"
|
434
|
|
-
|
435
|
|
- try:
|
436
|
|
- rd = json.loads(r)
|
437
|
|
- for c in rd:
|
438
|
|
- if "action" in c:
|
439
|
|
- # we have some custom commands and no psucontrol
|
440
|
|
- # so lets try to use that instead of skipping
|
441
|
|
- # the printer completely with 'unknown'
|
442
|
|
- return "system"
|
443
|
|
- except json.JSONDecodeError:
|
444
|
|
- pass
|
445
|
|
-
|
446
|
|
- return "unknown"
|
447
|
|
-
|
448
|
|
- def getSystemCommands(self, host, key):
|
449
|
|
- l = []
|
450
|
|
- r = self.sendGetRequest(host, key, "system/commands/custom")
|
451
|
|
- try:
|
452
|
|
- rd = json.loads(r)
|
453
|
|
-
|
454
|
|
- if len(rd) > 0:
|
455
|
|
- print("system commands available for " + host + ":")
|
456
|
|
-
|
457
|
|
- for c in rd:
|
458
|
|
- if "action" in c:
|
459
|
|
- print(" - " + c["action"])
|
460
|
|
- l.append(c["action"])
|
461
|
|
- except json.JSONDecodeError:
|
462
|
|
- pass
|
463
|
|
- return l
|
464
|
|
-
|
465
|
|
- def setPSUControl(self, host, key, state):
|
466
|
|
- cmd = "turnPSUOff"
|
467
|
|
- if state:
|
468
|
|
- cmd = "turnPSUOn"
|
469
|
|
- return self.sendPostRequest(host, key, "plugin/psucontrol", '{ "command":"' + cmd + '" }')
|
470
|
|
-
|
471
|
|
- def setSystemCommand(self, host, key, cmd):
|
472
|
|
- cmd = urllib.parse.quote(cmd)
|
473
|
|
- return self.sendPostRequest(host, key, "system/commands/custom/" + cmd, '')
|
474
|
|
-
|
475
|
266
|
def exit(self):
|
476
|
267
|
QCoreApplication.quit()
|
477
|
268
|
|
478
|
|
- def printerSystemCommandAction(self, item, index):
|
479
|
|
- if "off" in item[2][index].lower():
|
480
|
|
- state = self.getState(item[0], item[1])
|
481
|
|
- if state in self.statesWithWarning:
|
482
|
|
- if self.showDialog("OctoTray Warning", "The printer seems to be running currently!", "Do you really want to run '" + item[2][index] + "'?", True, True) == False:
|
483
|
|
- return
|
484
|
|
-
|
485
|
|
- safe = self.getTemperatureIsSafe(item[0], item[1])
|
486
|
|
- if safe == False:
|
487
|
|
- if self.showDialog("OctoTray Warning", "The printer seems to still be hot!", "Do you really want to turn it off?", True, True) == False:
|
488
|
|
- return
|
489
|
|
-
|
490
|
|
- self.setSystemCommand(item[0], item[1], item[2][index])
|
491
|
|
-
|
492
|
|
- def printerOnAction(self, item):
|
493
|
|
- self.setPSUControl(item[0], item[1], True)
|
494
|
|
-
|
495
|
|
- def printerOffAction(self, item):
|
496
|
|
- state = self.getState(item[0], item[1])
|
497
|
|
- if state in self.statesWithWarning:
|
498
|
|
- if self.showDialog("OctoTray Warning", "The printer seems to be running currently!", "Do you really want to turn it off?", True, True) == False:
|
499
|
|
- return
|
500
|
|
-
|
501
|
|
- safe = self.getTemperatureIsSafe(item[0], item[1])
|
502
|
|
- if safe == False:
|
503
|
|
- if self.showDialog("OctoTray Warning", "The printer seems to still be hot!", "Do you really want to turn it off?", True, True) == False:
|
504
|
|
- return
|
505
|
|
-
|
506
|
|
- self.setPSUControl(item[0], item[1], False)
|
507
|
|
-
|
508
|
|
- def printerHomingAction(self, item, axes = "xyz"):
|
509
|
|
- state = self.getState(item[0], item[1])
|
510
|
|
- if state in self.statesWithWarning:
|
511
|
|
- if self.showDialog("OctoTray Warning", "The printer seems to be running currently!", "Do you really want to home it?", True, True) == False:
|
512
|
|
- return
|
513
|
|
-
|
514
|
|
- axes_string = ''
|
515
|
|
- for i in range(0, len(axes)):
|
516
|
|
- axes_string += '"' + str(axes[i]) + '"'
|
517
|
|
- if i < (len(axes) - 1):
|
518
|
|
- axes_string += ', '
|
519
|
|
-
|
520
|
|
- self.sendPostRequest(item[0], item[1], "printer/printhead", '{ "command": "home", "axes": [' + axes_string + '] }')
|
521
|
|
-
|
522
|
|
- def printerMoveAction(self, printer, axis, dist, relative = True):
|
523
|
|
- state = self.getState(printer[0], printer[1])
|
524
|
|
- if state in self.statesWithWarning:
|
525
|
|
- if self.showDialog("OctoTray Warning", "The printer seems to be running currently!", "Do you really want to move it?", True, True) == False:
|
526
|
|
- return
|
527
|
|
-
|
528
|
|
- absolute = ''
|
529
|
|
- if relative == False:
|
530
|
|
- absolute = ', "absolute": true'
|
531
|
|
-
|
532
|
|
- self.sendPostRequest(printer[0], printer[1], "printer/printhead", '{ "command": "jog", "' + str(axis) + '": ' + str(dist) + ', "speed": ' + str(self.jogMoveSpeed) + absolute + ' }')
|
533
|
|
-
|
534
|
|
- def printerPauseResume(self, printer):
|
535
|
|
- state = self.getState(printer[0], printer[1])
|
536
|
|
- if state in self.statesWithWarning:
|
537
|
|
- if self.showDialog("OctoTray Warning", "The printer seems to be running currently!", "Do you really want to pause/resume?", True, True) == False:
|
538
|
|
- return
|
539
|
|
- self.sendPostRequest(printer[0], printer[1], "job", '{ "command": "pause", "action": "toggle" }')
|
540
|
|
-
|
541
|
|
- def printerJobCancel(self, printer):
|
542
|
|
- state = self.getState(printer[0], printer[1])
|
543
|
|
- if state in self.statesWithWarning:
|
544
|
|
- if self.showDialog("OctoTray Warning", "The printer seems to be running currently!", "Do you really want to cancel?", True, True) == False:
|
545
|
|
- return
|
546
|
|
- self.sendPostRequest(printer[0], printer[1], "job", '{ "command": "cancel" }')
|
547
|
|
-
|
548
|
269
|
def printerWebAction(self, item):
|
549
|
|
- self.openBrowser(item[0])
|
550
|
|
-
|
551
|
|
- def printerStatusAction(self, item):
|
552
|
|
- progress = self.getProgress(item[0], item[1])
|
553
|
|
- s = item[0] + "\n"
|
554
|
|
- warning = False
|
555
|
|
- if ("completion" in progress) and ("printTime" in progress) and ("printTimeLeft" in progress) and (progress["completion"] != None) and (progress["printTime"] != None) and (progress["printTimeLeft"] != None):
|
556
|
|
- s += "%.1f%% Completion\n" % progress["completion"]
|
557
|
|
- s += "Printing since " + time.strftime("%H:%M:%S", time.gmtime(progress["printTime"])) + "\n"
|
558
|
|
- s += time.strftime("%H:%M:%S", time.gmtime(progress["printTimeLeft"])) + " left"
|
559
|
|
- elif ("completion" in progress) and ("printTime" in progress) and ("printTimeLeft" in progress):
|
560
|
|
- s += "No job is currently running"
|
561
|
|
- else:
|
562
|
|
- s += "Could not read printer status!"
|
563
|
|
- warning = True
|
564
|
|
- t = self.getTemperatureString(item[0], item[1])
|
565
|
|
- if len(t) > 0:
|
566
|
|
- s += "\n" + t
|
567
|
|
- self.showDialog("OctoTray Status", s, None, False, warning)
|
568
|
|
-
|
569
|
|
- def printerFilePrint(self, item, path):
|
570
|
|
- self.sendPostRequest(item[0], item[1], "files/" + path, '{ "command": "select", "print": true }')
|
571
|
|
-
|
572
|
|
- def setTemperature(self, host, key, what, temp):
|
573
|
|
- path = "printer/bed"
|
574
|
|
- s = "{\"command\": \"target\", \"target\": " + temp + "}"
|
575
|
|
-
|
576
|
|
- if "tool" in what:
|
577
|
|
- path = "printer/tool"
|
578
|
|
- s = "{\"command\": \"target\", \"targets\": {\"" + what + "\": " + temp + "}}"
|
579
|
|
-
|
580
|
|
- if temp == None:
|
581
|
|
- temp = 0
|
582
|
|
-
|
583
|
|
- self.sendPostRequest(host, key, path, s)
|
584
|
|
-
|
585
|
|
- def printerHeatTool(self, p):
|
586
|
|
- self.setTemperature(p[0], p[1], "tool0", p[2])
|
587
|
|
-
|
588
|
|
- def printerHeatBed(self, p):
|
589
|
|
- self.setTemperature(p[0], p[1], "bed", p[3])
|
590
|
|
-
|
591
|
|
- def printerCooldown(self, p):
|
592
|
|
- state = self.getState(p[0], p[1])
|
593
|
|
- if state in self.statesWithWarning:
|
594
|
|
- if self.showDialog("OctoTray Warning", "The printer seems to be running currently!", "Do you really want to turn it off?", True, True) == False:
|
595
|
|
- return
|
596
|
|
-
|
597
|
|
- self.setTemperature(p[0], p[1], "tool0", 0)
|
598
|
|
- self.setTemperature(p[0], p[1], "bed", 0)
|
|
270
|
+ self.openBrowser(item.host)
|
599
|
271
|
|
600
|
272
|
def printerWebcamAction(self, item):
|
601
|
273
|
for cw in self.camWindows:
|
602
|
|
- if cw.getHost() == item[0]:
|
|
274
|
+ if cw.getHost() == item.host:
|
603
|
275
|
cw.show()
|
604
|
276
|
cw.activateWindow()
|
605
|
277
|
return
|