Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
taste-setup
Commits
259fa5a7
Commit
259fa5a7
authored
Sep 20, 2017
by
Thanassis Tsiodras
Browse files
Merge branch 'master' of
https://gitrepos.estec.esa.int/taste/taste-setup
parents
f25c9f59
dd437829
Changes
1
Hide whitespace changes
Inline
Side-by-side
misc/helper-scripts/taste-progress-dialog.py
View file @
259fa5a7
#!/usr/bin/env python
#!/usr/bin/env python
import
sys
import
sys
import
PySide
import
time
import
time
import
signal
import
signal
from
collections
import
deque
import
PySide
from
PySide.QtCore
import
QThread
,
Signal
,
QObject
from
PySide.QtCore
import
QThread
,
Signal
,
QObject
from
PySide.QtGui
import
(
QApplication
,
from
PySide.QtGui
import
(
QApplication
,
...
@@ -12,46 +13,77 @@ from PySide.QtGui import (QApplication,
...
@@ -12,46 +13,77 @@ from PySide.QtGui import (QApplication,
QProgressDialog
)
QProgressDialog
)
class
MyThread
(
QThread
,
QObject
):
class
MyThread
(
QThread
,
QObject
):
signal
=
Signal
(
str
)
''' Thread waiting for data on stdin and sending signals to the prgress
progress
=
Signal
(
int
)
bar in case something came in.
quit
=
Signal
()
Text can be formatted:
* if the line starts with a number, it will use the value (range 0..100)
to update the progress bar, and it will display the text above the bar.
* if the line starts with @ERROR@ the process will stop and all the
history will be dispayed in a log dialog.
* in all other cases, the line is appended to the log
'''
text
=
Signal
(
str
)
progress
=
Signal
(
int
)
end
=
Signal
()
error
=
Signal
()
log
=
deque
()
force_quit
=
False
def
run
(
self
):
def
run
(
self
):
value
=
10
value
=
10
while
True
:
while
True
:
# read from stdin without any buffering
# read from stdin without any buffering
if
self
.
force_quit
:
return
line
=
sys
.
stdin
.
readline
()
line
=
sys
.
stdin
.
readline
()
if
len
(
line
)
==
0
:
if
len
(
line
)
==
0
:
print
(
"Bye"
)
print
(
"Bye"
)
self
.
quit
.
emit
()
self
.
end
.
emit
()
return
elif
line
[
0
]
==
'q'
:
print
(
"Quit"
)
self
.
quit
.
emit
()
return
return
else
:
else
:
split
=
line
.
split
()
try
:
try
:
split
=
line
.
split
()
# check for format "NUMBER text"
possible_val
=
split
[
0
]
possible_val
=
split
[
0
]
value
=
int
(
possible_val
)
value
=
int
(
possible_val
)
if
100
<
value
<
0
:
raise
ValueError
text
=
' '
.
join
(
split
[
1
:])
text
=
' '
.
join
(
split
[
1
:])
self
.
progress
.
emit
(
value
)
self
.
progress
.
emit
(
value
)
self
.
text
.
emit
(
text
)
if
value
==
100
:
self
.
end
.
emit
()
return
except
(
ValueError
,
IndexError
):
except
(
ValueError
,
IndexError
):
text
=
line
text
=
line
self
.
signal
.
emit
(
text
)
self
.
log
.
append
(
text
)
time
.
sleep
(
0.1
)
try
:
if
split
[
0
]
==
'@ERROR@'
:
self
.
error
.
emit
()
except
IndexError
:
pass
def
run_gui
():
def
run_gui
():
app
=
QApplication
(
sys
.
argv
)
app
=
QApplication
(
sys
.
argv
)
thread
=
MyThread
()
thread
=
MyThread
()
progress
=
QProgressDialog
()
progress
=
QProgressDialog
()
progress
.
setValue
(
0
)
progress
.
setValue
(
0
)
thread
.
signal
.
connect
(
progress
.
setLabelText
)
progress
.
setAutoClose
(
True
)
thread
.
quit
.
connect
(
progress
.
cancel
)
thread
.
progress
.
connect
(
progress
.
setValue
)
thread
.
text
.
connect
(
progress
.
setLabelText
)
thread
.
start
()
thread
.
end
.
connect
(
progress
.
cancel
)
progress
.
exec_
()
thread
.
progress
.
connect
(
progress
.
setValue
)
thread
.
setTerminationEnabled
(
True
)
thread
.
start
()
progress
.
exec_
()
if
progress
.
wasCanceled
:
print
'Cancel was pressed'
thread
.
force_quit
=
True
thread
.
wait
()
print
"end"
def
main
():
def
main
():
signal
.
signal
(
signal
.
SIGINT
,
signal
.
SIG_DFL
)
signal
.
signal
(
signal
.
SIGINT
,
signal
.
SIG_DFL
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment