Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
hidra
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
steinbac
hidra
Commits
dd2de9cc
Commit
dd2de9cc
authored
9 years ago
by
Manuela Kuhn
Browse files
Options
Downloads
Patches
Plain Diff
Added original LiveViewer
parent
7a3e4335
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
LiveViewer.py
+118
-0
118 additions, 0 deletions
LiveViewer.py
with
118 additions
and
0 deletions
LiveViewer.py
0 → 100644
+
118
−
0
View file @
dd2de9cc
# -*- coding: utf-8 -*-
import
os
import
time
from
dectris
import
albula
from
PyQt4
import
QtCore
from
PyQt4.QtCore
import
SIGNAL
,
QThread
,
QMutex
class
LiveView
(
QThread
):
FILETYPE_CBF
=
0
FILETYPE_TIF
=
1
FILETYPE_HDF5
=
2
alive
=
False
path
=
""
filetype
=
0
interval
=
0.5
#s
stoptimer
=
-
1.0
viewer
=
None
subframe
=
None
mutex
=
None
def
__init__
(
self
,
path
=
None
,
filetype
=
None
,
interval
=
None
,
parent
=
None
):
QThread
.
__init__
(
self
,
parent
)
if
path
is
not
None
:
self
.
path
=
path
if
filetype
is
not
None
:
self
.
filetype
=
filetype
if
interval
is
not
None
:
self
.
interval
=
interval
self
.
mutex
=
QMutex
()
def
start
(
self
,
path
=
None
,
filetype
=
None
,
interval
=
None
):
if
path
is
not
None
:
self
.
path
=
path
if
filetype
is
not
None
:
self
.
filetype
=
filetype
if
interval
is
not
None
:
self
.
interval
=
interval
QThread
.
start
(
self
)
def
stop
(
self
,
interval
=
0.0
):
if
self
.
stoptimer
<
0.0
and
interval
>
0.0
:
print
"
Live view thread: Stopping in %d seconds
"
%
interval
self
.
stoptimer
=
interval
return
print
"
Live view thread: Stopping thread
"
self
.
alive
=
False
self
.
wait
()
# waits until run stops on his own
def
run
(
self
):
self
.
alive
=
True
print
"
Live view thread: started
"
suffix
=
[
"
.cbf
"
,
"
.tif
"
,
"
.hdf5
"
]
if
self
.
filetype
in
[
LiveView
.
FILETYPE_CBF
,
LiveView
.
FILETYPE_TIF
]:
# open viewer
while
self
.
alive
:
# find latest image
self
.
mutex
.
lock
()
files
=
[(
os
.
path
.
getmtime
(
self
.
path
+
"
/
"
+
fn
),
fn
)
for
fn
in
os
.
listdir
(
self
.
path
)
if
fn
.
lower
().
endswith
(
suffix
[
self
.
filetype
])]
files
.
sort
()
files
.
reverse
()
if
len
(
files
)
>
0
:
# display image
# wait to make sure the image is copied completely before displaying it
time
.
sleep
(
0.1
)
try
:
self
.
subframe
.
loadFile
(
self
.
path
+
"
/
"
+
files
[
0
][
1
])
# viewer or subframe has been closed by the user
except
:
self
.
mutex
.
unlock
()
time
.
sleep
(
0.1
)
try
:
self
.
subframe
=
self
.
viewer
.
openSubFrame
()
except
:
self
.
viewer
=
albula
.
openMainFrame
()
self
.
subframe
=
self
.
viewer
.
openSubFrame
()
continue
self
.
mutex
.
unlock
()
# wait interval
interval
=
0.0
while
interval
<
self
.
interval
and
self
.
alive
:
if
self
.
stoptimer
>
0.0
:
self
.
stoptimer
-=
0.05
if
self
.
stoptimer
<
0.0
:
self
.
stoptimer
=
-
1.0
self
.
alive
=
False
time
.
sleep
(
0.05
)
interval
+=
0.05
elif
self
.
filetype
==
LiveView
.
FILETYPE_HDF5
:
print
"
Live view thread: HDF5 not supported yet
"
print
"
Live view thread: Thread for Live view died
"
self
.
alive
=
False
def
setPath
(
self
,
path
=
None
):
self
.
mutex
.
lock
()
if
path
is
not
None
:
self
.
path
=
path
self
.
mutex
.
unlock
()
def
setFiletype
(
self
,
filetype
=
None
):
restart
=
False
if
self
.
alive
:
restart
=
True
self
.
stop
()
if
filetype
is
not
None
:
self
.
filetype
=
filetype
if
restart
:
self
.
start
()
def
setInterval
(
self
,
interval
=
None
):
if
interval
is
not
None
:
self
.
interval
=
interval
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment