Skip to content

Commit cd82704

Browse files
committed
Allow cmap scaling changes when image not ready
Previously, error messages would appear if the cmap scaling was changed while the image was still being generated (such as the polar view being generated). Now, error messages are not generated, and the cmap scaling change is handled gracefully. Signed-off-by: Patrick Avery <[email protected]>
1 parent 690751f commit cd82704

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

hexrdgui/color_map_editor.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import copy
22

3+
from PySide6.QtCore import QTimer
34
from PySide6.QtGui import QColor
45
from PySide6.QtWidgets import QColorDialog
56

@@ -24,6 +25,9 @@ def __init__(self, image_object, parent=None):
2425
# 2. set_norm: a function to set the norm on the image
2526
# 3. set_scaling: a function to set the scaling on the image
2627
# 4. scaled_image_data: a property to get the scaled image data
28+
# 5. image_ready: an optional boolean property indicating if the image
29+
# is ready. If not present, the image is assumed to
30+
# be ready.
2731

2832
self.image_object = image_object
2933

@@ -268,4 +272,14 @@ def update_scaling(self):
268272

269273
# Reset the bounds, as the histogram could potentially have moved.
270274
# This will update the data too.
271-
self.update_bounds(self.image_object.scaled_image_data)
275+
# Wait until the image is ready to do the update.
276+
277+
def do_bound_update_if_ready():
278+
if not getattr(self.image_object, 'image_ready', True):
279+
# If the image is not ready, try again in 250 milliseconds
280+
QTimer.singleShot(250, do_bound_update_if_ready)
281+
return
282+
283+
self.update_bounds(self.image_object.scaled_image_data)
284+
285+
do_bound_update_if_ready()

hexrdgui/image_canvas.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,10 @@ def scaled_images(self):
412412
def scaled_display_images(self):
413413
return list(self.scaled_display_image_dict.values())
414414

415+
@property
416+
def image_ready(self) -> bool:
417+
return self.iviewer is not None
418+
415419
@property
416420
def blit_artists(self):
417421
return self.blit_manager.artists
@@ -1692,11 +1696,13 @@ def set_scaling(self, transform):
16921696
image_names = list(self.raw_axes)
16931697
self.load_images(image_names)
16941698
else:
1695-
for axes_img, img in zip(
1696-
self.axes_images,
1697-
self.scaled_display_images,
1698-
):
1699-
axes_img.set_data(img)
1699+
# If the image is not ready, these will be set later
1700+
if self.image_ready:
1701+
for axes_img, img in zip(
1702+
self.axes_images,
1703+
self.scaled_display_images,
1704+
):
1705+
axes_img.set_data(img)
17001706

17011707
self.update_azimuthal_integral_plot()
17021708
self.draw_idle()

hexrdgui/image_tab_widget.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,10 @@ def scaled_image_data(self):
323323
# return the whole image data dict.
324324
return self.image_canvases[0].scaled_display_image_dict
325325

326+
@property
327+
def image_ready(self) -> bool:
328+
return self.image_canvases[0].image_ready
329+
326330
def on_motion_notify_event(self, event):
327331
# Clear the info if the mouse leaves a plot
328332
if event.inaxes is None:

0 commit comments

Comments
 (0)