forked from mi8882255/3dprinteros-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
virtual_printer.py
88 lines (65 loc) · 2.5 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
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
#Copyright (c) 2015 3D Control Systems LTD
#3DPrinterOS client is free software: you can redistribute it and/or modify
#it under the terms of the GNU Affero General Public License as published by
#the Free Software Foundation, either version 3 of the License, or
#(at your option) any later version.
#3DPrinterOS client is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU Affero General Public License for more details.
#You should have received a copy of the GNU Affero General Public License
#along with 3DPrinterOS client. If not, see <http://www.gnu.org/licenses/>.
# Author: Vladimir Avdeev <another.vic@yandex.ru>
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.print_thread = None
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)
self.print_thread.start()
def unbuffered_gcodes(self, gcodes):
self.logger.info("Unbuffered gcode: " + str(gcodes))
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
def close(self):
self.logger.info('Closing Virtual printer sender')
self.stop_flag = True
if self.print_thread:
self.print_thread.join()
self.is_running = False