-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgressOps.py
44 lines (31 loc) · 1.1 KB
/
ProgressOps.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
import socket
import os
class ExternalProgressBar():
def __enter__(self):
path = os.path.join(
os.path.dirname(__file__),
'progressbar.bat'
)
os.startfile(path)
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.socket.connect(('localhost', 10000))
self._percentage = b""
def set_percentage(self, inPercentage):
if self._percentage != inPercentage:
self._percentage = inPercentage
#In case the connection dropped, wrap in try
try:
if self._percentage < 10:
message = b'00{prc}'.format(prc=self._percentage)
elif self._percentage < 100:
message = b'0{prc}'.format(prc=self._percentage)
else:
message = b'{prc}'.format(prc=self._percentage)
self.socket.sendall(message)
except:
pass
def __exit__(self, inType, inValue, inTraceback):
try:
self.socket.close()
except:
pass