File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed
Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python3
2+ # -*- coding: utf-8 -*-
3+
4+ import threading
5+ import sys
6+ import time
7+
8+
9+ class SearchingProgressBar (threading .Thread ):
10+ __LEN__ = 10
11+
12+ def __init__ (self ):
13+ super (SearchingProgressBar , self ).__init__ ()
14+ self .daemon = True
15+ self ._stop_event = threading .Event ()
16+
17+ def stop (self ):
18+ self ._stop_event .set ()
19+
20+ def stopped (self ):
21+ return self ._stop_event .is_set ()
22+
23+ def __clear (self ):
24+ sys .stdout .write ("\r " )
25+ sys .stdout .write (" " * self .__LEN__ )
26+ sys .stdout .write ("\r " )
27+ sys .stdout .flush ()
28+
29+ def run (self ):
30+ while True :
31+ progress = "searching "
32+ for i in range (self .__LEN__ ):
33+ if self .stopped ():
34+ self .__clear ()
35+ return
36+ time .sleep (0.1 )
37+ sys .stdout .write ("\r " )
38+ progress += " ."
39+ sys .stdout .write (progress )
40+ sys .stdout .flush ()
41+ sys .stdout .write ("\r " )
42+ sys .stdout .write ("\r " )
43+ sys .stdout .write ("searching " + " " * self .__LEN__ )
44+ sys .stdout .write ("\r " )
45+ sys .stdout .flush ()
You can’t perform that action at this time.
0 commit comments