Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
tomwer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Jira
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
tomotools
tomwer
Commits
3629c6db
Commit
3629c6db
authored
4 years ago
by
payno
Browse files
Options
Downloads
Patches
Plain Diff
[gui][viewer] add cache for the data viewer.
parent
95040941
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tomwer/gui/visualization/dataviewer.py
+41
-0
41 additions, 0 deletions
tomwer/gui/visualization/dataviewer.py
with
41 additions
and
0 deletions
tomwer/gui/visualization/dataviewer.py
+
41
−
0
View file @
3629c6db
...
...
@@ -30,6 +30,7 @@ __date__ = "21/07/2020"
import
silx
from
silx.gui
import
qt
from
silx.utils.enum
import
Enum
as
_Enum
from
collections
import
OrderedDict
try
:
from
silx.gui.utils.signal
import
SignalProxy
except
ImportError
:
...
...
@@ -305,7 +306,43 @@ class DisplayControl(qt.QWidget):
self
.
_scanQLE
.
setText
(
scan_name
)
class
_CachedOrderedDict
(
object
):
def
__init__
(
self
,
max_size
=
4
):
if
max_size
<=
0
:
raise
ValueError
self
.
max_size
=
max_size
self
.
_items
=
OrderedDict
()
def
_move_latest
(
self
,
key
):
# Order is in descending priority, i.e. first element
# is latest.
self
.
_items
.
move_to_end
(
key
,
last
=
False
)
def
__getitem__
(
self
,
key
,
default
=
None
):
if
key
not
in
self
.
_items
:
return
default
value
=
self
.
_items
[
key
]
self
.
_move_latest
(
key
)
return
value
def
__setitem__
(
self
,
key
,
value
):
if
len
(
self
.
_items
)
>=
self
.
max_size
:
keys
=
list
(
self
.
_items
.
keys
())
key_to_evict
=
keys
[
-
1
]
self
.
_items
.
pop
(
key_to_evict
)
self
.
_items
[
key
]
=
value
self
.
_move_latest
(
key
)
def
__contains__
(
self
,
item
):
return
item
in
self
.
_items
class
ImageStack
(
_ImageStack
):
CACHE_SIZE
=
15
def
__init__
(
self
,
parent
):
self
.
_normFct
=
None
self
.
_url_indexes
=
None
...
...
@@ -315,6 +352,10 @@ class ImageStack(_ImageStack):
self
.
_normFct
=
fct
self
.
_url_indexes
=
url_indexes
def
reset
(
self
)
->
None
:
super
().
reset
()
self
.
_urlData
=
_CachedOrderedDict
(
max_size
=
ImageStack
.
CACHE_SIZE
)
def
_urlLoaded
(
self
)
->
None
:
"""
...
...
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