Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d99a94b

Browse filesBrowse files
committed
fix hlut
1 parent 87c8d9d commit d99a94b
Copy full SHA for d99a94b

File tree

Expand file treeCollapse file tree

4 files changed

+53
-36
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+53
-36
lines changed

‎examples/desktop/image/image_widget.py

Copy file name to clipboardExpand all lines: examples/desktop/image/image_widget.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111

1212
a = iio.imread("imageio:camera.png")
13-
iw = fpl.ImageWidget(data=a, cmap="viridis", histogram_widget=False)
13+
iw = fpl.ImageWidget(data=a, cmap="viridis")
1414
iw.show()
1515

1616

‎fastplotlib/graphics/_base.py

Copy file name to clipboardExpand all lines: fastplotlib/graphics/_base.py
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,15 @@ def deleted(self) -> bool:
9898
def deleted(self, value: bool):
9999
self._deleted.set_value(self, value)
100100

101+
@property
102+
def block_events(self) -> bool:
103+
"""Used to block events for a graphic and prevent recursion."""
104+
return self._block_events
105+
106+
@block_events.setter
107+
def block_events(self, value: bool):
108+
self._block_events = value
109+
101110
def __init_subclass__(cls, **kwargs):
102111
# set the type of the graphic in lower case like "image", "line_collection", etc.
103112
cls.type = (
@@ -165,6 +174,7 @@ def __init__(
165174
self._rotation = Rotation(rotation)
166175
self._offset = Offset(offset)
167176
self._visible = Visible(True)
177+
self._block_events = False
168178

169179
@property
170180
def world_object(self) -> pygfx.WorldObject:
@@ -269,6 +279,9 @@ def _handle_event(self, callback, event: pygfx.Event):
269279
"""Wrap pygfx event to add graphic to pick_info"""
270280
event.graphic = self
271281

282+
if self.block_events:
283+
return
284+
272285
if event.type in self.features:
273286
# for feature events
274287
event._target = self.world_object

‎fastplotlib/graphics/selectors/_linear_region.py

Copy file name to clipboardExpand all lines: fastplotlib/graphics/selectors/_linear_region.py
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ def __init__(
208208
group.add(edge)
209209

210210
# TODO: if parent offset changes, we should set the selector offset too
211+
# TODO: add check if parent is `None`, will throw error otherwise
211212
if axis == "x":
212213
offset = (parent.offset[0], center, 0)
213214
elif axis == "y":

‎fastplotlib/widgets/histogram_lut.py

Copy file name to clipboardExpand all lines: fastplotlib/widgets/histogram_lut.py
+38-35Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,23 @@ def __init__(
5252
origin = (hist_scaled.max() / 2, 0)
5353

5454
self._linear_region_selector = LinearRegionSelector(
55-
bounds=bounds,
55+
selection=bounds,
5656
limits=limits,
5757
size=size,
58-
origin=origin,
58+
center=origin[0],
5959
axis="y",
6060
edge_thickness=8,
61+
parent=self._histogram_line
6162
)
6263

63-
# there will be a small difference with the histogram edges so this makes them both line up exactly
64+
#there will be a small difference with the histogram edges so this makes them both line up exactly
6465
self._linear_region_selector.selection = (
65-
image_graphic.cmap.vmin,
66-
image_graphic.cmap.vmax,
66+
self._image_graphic.vmin,
67+
self._image_graphic.vmax,
6768
)
6869

69-
self._vmin = self.image_graphic.cmap.vmin
70-
self._vmax = self.image_graphic.cmap.vmax
70+
self._vmin = self.image_graphic.vmin
71+
self._vmax = self.image_graphic.vmax
7172

7273
vmin_str, vmax_str = self._get_vmin_vmax_str()
7374

@@ -105,17 +106,15 @@ def __init__(
105106

106107
self.world_object.local.scale_x *= -1
107108

108-
self._text_vmin.position_x = -120
109-
self._text_vmin.position_y = self._linear_region_selector.selection()[0]
109+
self._text_vmin.offset = (-120, self._linear_region_selector.selection[0], 0)
110110

111-
self._text_vmax.position_x = -120
112-
self._text_vmax.position_y = self._linear_region_selector.selection()[1]
111+
self._text_vmax.offset = (-120, self._linear_region_selector.selection[1], 0)
113112

114-
self._linear_region_selector.selection.add_event_handler(
115-
self._linear_region_handler
113+
self._linear_region_selector.add_event_handler(
114+
self._linear_region_handler, "selection"
116115
)
117116

118-
self.image_graphic.cmap.add_event_handler(self._image_cmap_handler)
117+
self.image_graphic.add_event_handler(self._image_cmap_handler, "vmin", "vmax")
119118

120119
def _get_vmin_vmax_str(self) -> tuple[str, str]:
121120
if self.vmin < 0.001 or self.vmin > 99_999:
@@ -198,39 +197,38 @@ def _calculate_histogram(self, data):
198197
def _linear_region_handler(self, ev):
199198
# must use world coordinate values directly from selection()
200199
# otherwise the linear region bounds jump to the closest bin edges
201-
vmin, vmax = self._linear_region_selector.selection()
200+
selected_ixs = self._linear_region_selector.selection
201+
vmin, vmax = selected_ixs[0], selected_ixs[1]
202202
vmin, vmax = vmin / self._scale_factor, vmax / self._scale_factor
203203
self.vmin, self.vmax = vmin, vmax
204204

205205
def _image_cmap_handler(self, ev):
206-
self.vmin, self.vmax = ev.pick_info["vmin"], ev.pick_info["vmax"]
207-
208-
def _block_events(self, b: bool):
209-
self.image_graphic.cmap.block_events(b)
210-
self._linear_region_selector.selection.block_events(b)
206+
setattr(self, ev.type, ev.info["value"])
211207

212208
@property
213209
def vmin(self) -> float:
214210
return self._vmin
215211

216212
@vmin.setter
217213
def vmin(self, value: float):
218-
self._block_events(True)
214+
self.image_graphic.block_events = True
215+
self._linear_region_selector.block_events = True
219216

220217
# must use world coordinate values directly from selection()
221218
# otherwise the linear region bounds jump to the closest bin edges
222219
self._linear_region_selector.selection = (
223220
value * self._scale_factor,
224-
self._linear_region_selector.selection()[1],
221+
self._linear_region_selector.selection[1],
225222
)
226-
self.image_graphic.cmap.vmin = value
223+
self.image_graphic.vmin = value
227224

228-
self._block_events(False)
225+
self.image_graphic.block_events = False
226+
self._linear_region_selector.block_events = False
229227

230228
self._vmin = value
231229

232230
vmin_str, vmax_str = self._get_vmin_vmax_str()
233-
self._text_vmin.position_y = self._linear_region_selector.selection()[0]
231+
self._text_vmin.offset = (-120, self._linear_region_selector.selection[0], 0)
234232
self._text_vmin.text = vmin_str
235233

236234
@property
@@ -239,22 +237,25 @@ def vmax(self) -> float:
239237

240238
@vmax.setter
241239
def vmax(self, value: float):
242-
self._block_events(True)
240+
self.image_graphic.block_events = True
241+
self._linear_region_selector.block_events = True
243242

244243
# must use world coordinate values directly from selection()
245244
# otherwise the linear region bounds jump to the closest bin edges
246245
self._linear_region_selector.selection = (
247-
self._linear_region_selector.selection()[0],
246+
self._linear_region_selector.selection[0],
248247
value * self._scale_factor,
249248
)
250-
self.image_graphic.cmap.vmax = value
251249

252-
self._block_events(False)
250+
self.image_graphic.vmax = value
251+
252+
self.image_graphic.block_events = False
253+
self._linear_region_selector.block_events = False
253254

254255
self._vmax = value
255256

256257
vmin_str, vmax_str = self._get_vmin_vmax_str()
257-
self._text_vmax.position_y = self._linear_region_selector.selection()[1]
258+
self._text_vmax.offset = (-120, self._linear_region_selector.selection[1], 0)
258259
self._text_vmax.text = vmax_str
259260

260261
def set_data(self, data, reset_vmin_vmax: bool = True):
@@ -275,9 +276,11 @@ def set_data(self, data, reset_vmin_vmax: bool = True):
275276
self._linear_region_selector.selection = bounds
276277
else:
277278
# don't change the current selection
278-
self._block_events(True)
279+
self.image_graphic.block_events = True
280+
self._linear_region_selector.block_events = True
279281
self._linear_region_selector.limits = limits
280-
self._block_events(False)
282+
self.image_graphic.block_events = False
283+
self._linear_region_selector.block_events = False
281284

282285
self._data = weakref.proxy(data)
283286

@@ -297,14 +300,14 @@ def image_graphic(self, graphic):
297300

298301
if self._image_graphic is not None:
299302
# cleanup events from current image graphic
300-
self._image_graphic.cmap.remove_event_handler(self._image_cmap_handler)
303+
self._image_graphic.remove_event_handler(self._image_cmap_handler)
301304

302305
self._image_graphic = graphic
303306

304-
self.image_graphic.cmap.add_event_handler(self._image_cmap_handler)
307+
self.image_graphic.add_event_handler(self._image_cmap_handler)
305308

306309
def disconnect_image_graphic(self):
307-
self._image_graphic.cmap.remove_event_handler(self._image_cmap_handler)
310+
self._image_graphic.remove_event_handler(self._image_cmap_handler)
308311
del self._image_graphic
309312
# self._image_graphic = None
310313

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.