forked from mi8882255/3dprinteros-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
virtual_printer.py
59 lines (43 loc) · 1.39 KB
/
virtual_printer.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
import time
import threading
from base_sender import BaseSender
class Sender(BaseSender):
def __init__(self, profile, usb_info):
BaseSender.__init__(self, profile, usb_info)
self.printing_flag = False
self.total_gcodes = 0
self.lines = 0
self.pause_flag = False
def is_operational(self):
return not self.stop_flag
def is_printing(self):
return self.printing_flag
def is_paused(self):
return self.pause_flag
def load_gcodes(self, gcodes):
self.lines = len(self.preprocess_gcodes(gcodes))
self.total_gcodes = self.lines
self.print_thread = threading.Thread(target=self.printing)
def printing(self):
self.printing_flag = True
while self.lines > 0 and not self.stop_flag:
if not self.pause_flag:
self.lines -= 10
time.sleep(1)
self.printing_flag = False
def cancel(self):
self.lines = 0
def pause(self):
self.pause_flag = True
def unpause(self):
self.pause_flag = False
def get_percent(self):
if not self.total_gcodes:
percent = 0
else:
percent = int(self.get_current_line_number() / float(self.total_gcodes) * 100)
return percent
def get_current_line_number(self):
return self.total_gcodes - self.lines
def reset(self):
pass