Skip to content

Commit 68dbdaa

Browse files
committed
Added logging statements and timeout to ensure processing is complete
1 parent b1f90ea commit 68dbdaa

File tree

3 files changed

+211
-50
lines changed

3 files changed

+211
-50
lines changed

jupyterlab_polus_render/examples/intro.ipynb

+167-22
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"execution_count": null,
6-
"id": "8913ae6f-16cd-4c33-878d-b5e0d0cb279b",
5+
"execution_count": 1,
6+
"id": "58a52b59-65f1-4876-aa1e-f5d823fe996d",
77
"metadata": {},
88
"outputs": [],
99
"source": [
@@ -12,12 +12,40 @@
1212
},
1313
{
1414
"cell_type": "code",
15-
"execution_count": null,
15+
"execution_count": 2,
1616
"id": "1ef25860-fb82-4d99-917a-6da0c3366767",
1717
"metadata": {
1818
"scrolled": true
1919
},
20-
"outputs": [],
20+
"outputs": [
21+
{
22+
"name": "stdout",
23+
"output_type": "stream",
24+
"text": [
25+
"Path is a local file: /Users/sainia2/Documents/pj/forks/jupyterlab-extensions/jupyterlab_polus_render/examples/../images/LuCa-7color_3x3component_data.ome.tif\n",
26+
"Image path changed: /Users/sainia2/Documents/pj/forks/jupyterlab-extensions/jupyterlab_polus_render/examples/../images/LuCa-7color_3x3component_data.ome.tif\n",
27+
"Path is a local file: /Users/sainia2/Documents/pj/forks/jupyterlab-extensions/jupyterlab_polus_render/examples/../images/LuCa-7color_3x3component_data.ome.tif\n",
28+
"Updated imagePath: /Users/sainia2/Documents/pj/forks/jupyterlab-extensions/jupyterlab_polus_render/examples/../images/LuCa-7color_3x3component_data.ome.tif, is_imagePath_url: False\n",
29+
"Path is a local file: /Users/sainia2/Documents/pj/forks/jupyterlab-extensions/jupyterlab_polus_render/examples\n",
30+
"Path is a local file: /Users/sainia2/Documents/pj/forks/jupyterlab-extensions/jupyterlab_polus_render/examples\n"
31+
]
32+
},
33+
{
34+
"data": {
35+
"application/vnd.jupyter.widget-view+json": {
36+
"model_id": "73ea462ca38f4438aab886edd8102c28",
37+
"version_major": 2,
38+
"version_minor": 0
39+
},
40+
"text/plain": [
41+
"Render(imagePath='/Users/sainia2/Documents/pj/forks/jupyterlab-extensions/jupyterlab_polus_render/examples/../…"
42+
]
43+
},
44+
"execution_count": 2,
45+
"metadata": {},
46+
"output_type": "execute_result"
47+
}
48+
],
2149
"source": [
2250
"Render(imagePath = '../images/LuCa-7color_3x3component_data.ome.tif')"
2351
]
@@ -26,75 +54,174 @@
2654
"cell_type": "code",
2755
"execution_count": null,
2856
"id": "e2e879af",
29-
"metadata": {},
57+
"metadata": {
58+
"scrolled": true
59+
},
3060
"outputs": [],
3161
"source": [
3262
"Render(imagePath = 'https://viv-demo.storage.googleapis.com/idr0106.pyramid.ome.tif')"
3363
]
3464
},
3565
{
3666
"cell_type": "code",
37-
"execution_count": null,
67+
"execution_count": 3,
3868
"id": "520ef52e-2f81-4c52-9c2f-c858e82d59e4",
3969
"metadata": {},
40-
"outputs": [],
70+
"outputs": [
71+
{
72+
"name": "stdout",
73+
"output_type": "stream",
74+
"text": [
75+
"Path is a local file: /Users/sainia2/Documents/pj/forks/jupyterlab-extensions/jupyterlab_polus_render/examples/../images/LuCa-7color_3x3component_data.ome.tif\n",
76+
"Image path changed: /Users/sainia2/Documents/pj/forks/jupyterlab-extensions/jupyterlab_polus_render/examples/../images/LuCa-7color_3x3component_data.ome.tif\n",
77+
"Path is a local file: /Users/sainia2/Documents/pj/forks/jupyterlab-extensions/jupyterlab_polus_render/examples/../images/LuCa-7color_3x3component_data.ome.tif\n",
78+
"Updated imagePath: /Users/sainia2/Documents/pj/forks/jupyterlab-extensions/jupyterlab_polus_render/examples/../images/LuCa-7color_3x3component_data.ome.tif, is_imagePath_url: False\n",
79+
"Path is a local file: /Users/sainia2/Documents/pj/forks/jupyterlab-extensions/jupyterlab_polus_render/examples\n",
80+
"Path is a local file: /Users/sainia2/Documents/pj/forks/jupyterlab-extensions/jupyterlab_polus_render/examples\n"
81+
]
82+
}
83+
],
4184
"source": [
4285
"r = Render(imagePath = '../images/LuCa-7color_3x3component_data.ome.tif')"
4386
]
4487
},
4588
{
4689
"cell_type": "code",
47-
"execution_count": null,
90+
"execution_count": 4,
4891
"id": "a3eaa802-f2ed-4ee4-8191-7c0befb89ca8",
4992
"metadata": {},
50-
"outputs": [],
93+
"outputs": [
94+
{
95+
"data": {
96+
"text/plain": [
97+
"False"
98+
]
99+
},
100+
"execution_count": 4,
101+
"metadata": {},
102+
"output_type": "execute_result"
103+
}
104+
],
51105
"source": [
52106
"r.is_imagePath_url"
53107
]
54108
},
55109
{
56110
"cell_type": "code",
57-
"execution_count": null,
111+
"execution_count": 5,
58112
"id": "a8f1218a-a189-4542-9ee4-4fca5b0c86bd",
59-
"metadata": {},
60-
"outputs": [],
113+
"metadata": {
114+
"scrolled": true
115+
},
116+
"outputs": [
117+
{
118+
"data": {
119+
"application/vnd.jupyter.widget-view+json": {
120+
"model_id": "4c6d4246e4464cd28c307cf66471f605",
121+
"version_major": 2,
122+
"version_minor": 0
123+
},
124+
"text/plain": [
125+
"Render(imagePath='/Users/sainia2/Documents/pj/forks/jupyterlab-extensions/jupyterlab_polus_render/examples/../…"
126+
]
127+
},
128+
"execution_count": 5,
129+
"metadata": {},
130+
"output_type": "execute_result"
131+
}
132+
],
61133
"source": [
62134
"r"
63135
]
64136
},
65137
{
66138
"cell_type": "code",
67-
"execution_count": null,
139+
"execution_count": 6,
68140
"id": "2f6aaf29-5a4f-4b2f-ac5a-4912097de53d",
69141
"metadata": {},
70-
"outputs": [],
142+
"outputs": [
143+
{
144+
"name": "stdout",
145+
"output_type": "stream",
146+
"text": [
147+
"Image path changed: https://viv-demo.storage.googleapis.com/idr0106.pyramid.ome.tif\n",
148+
"Path is a URL: https://viv-demo.storage.googleapis.com/idr0106.pyramid.ome.tif\n",
149+
"Updated imagePath: https://viv-demo.storage.googleapis.com/idr0106.pyramid.ome.tif, is_imagePath_url: True\n"
150+
]
151+
}
152+
],
71153
"source": [
72154
"r.imagePath = 'https://viv-demo.storage.googleapis.com/idr0106.pyramid.ome.tif'"
73155
]
74156
},
75157
{
76158
"cell_type": "code",
77-
"execution_count": null,
159+
"execution_count": 7,
78160
"id": "7c6e6fe4-0133-4281-a1b6-f94227dceb1a",
79161
"metadata": {},
80-
"outputs": [],
162+
"outputs": [
163+
{
164+
"name": "stdout",
165+
"output_type": "stream",
166+
"text": [
167+
"https://viv-demo.storage.googleapis.com/idr0106.pyramid.ome.tif\n"
168+
]
169+
}
170+
],
81171
"source": [
82172
"print(r.imagePath)"
83173
]
84174
},
85175
{
86176
"cell_type": "code",
87-
"execution_count": null,
177+
"execution_count": 7,
178+
"id": "3fd3e203-23c5-4feb-ae08-0084e58c3567",
179+
"metadata": {},
180+
"outputs": [
181+
{
182+
"data": {
183+
"application/vnd.jupyter.widget-view+json": {
184+
"model_id": "a8992b381a57481ba866a87db9d5e4ad",
185+
"version_major": 2,
186+
"version_minor": 0
187+
},
188+
"text/plain": [
189+
"Render(imagePath='https://viv-demo.storage.googleapis.com/idr0106.pyramid.ome.tif', is_imagePath_url=True, not…"
190+
]
191+
},
192+
"execution_count": 7,
193+
"metadata": {},
194+
"output_type": "execute_result"
195+
}
196+
],
197+
"source": [
198+
"r"
199+
]
200+
},
201+
{
202+
"cell_type": "code",
203+
"execution_count": 8,
88204
"id": "0f72b629-e855-4484-ae82-c4b5aaa73412",
89205
"metadata": {},
90-
"outputs": [],
206+
"outputs": [
207+
{
208+
"data": {
209+
"text/plain": [
210+
"True"
211+
]
212+
},
213+
"execution_count": 8,
214+
"metadata": {},
215+
"output_type": "execute_result"
216+
}
217+
],
91218
"source": [
92219
"r.is_imagePath_url"
93220
]
94221
},
95222
{
96223
"cell_type": "code",
97-
"execution_count": null,
224+
"execution_count": 9,
98225
"id": "53735950-b176-47c5-835b-b18f084c46ca",
99226
"metadata": {},
100227
"outputs": [],
@@ -104,10 +231,28 @@
104231
},
105232
{
106233
"cell_type": "code",
107-
"execution_count": null,
234+
"execution_count": 9,
108235
"id": "71badd13-5989-4a4a-a1ec-5e2a3c54eb89",
109-
"metadata": {},
110-
"outputs": [],
236+
"metadata": {
237+
"scrolled": true
238+
},
239+
"outputs": [
240+
{
241+
"data": {
242+
"application/vnd.jupyter.widget-view+json": {
243+
"model_id": "93846c323cea4b17b5d800123c821a62",
244+
"version_major": 2,
245+
"version_minor": 0
246+
},
247+
"text/plain": [
248+
"Render(base_url='/', imagePath='https://viv-demo.storage.googleapis.com/idr0106.pyramid.ome.tif', imageUrl='/j…"
249+
]
250+
},
251+
"execution_count": 9,
252+
"metadata": {},
253+
"output_type": "execute_result"
254+
}
255+
],
111256
"source": [
112257
"r"
113258
]

jupyterlab_polus_render/jupyterlab_polus_render/render.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ def __init__(self, imagePath='', overlayPath='', **kwargs):
4949
def create_full_path(self, path):
5050
# If the path starts with 'http', return path value and set True for URL flag
5151
if path.startswith('http'):
52-
return path, True
52+
print(f"Path is a URL: {path}")
53+
return str(path), True
5354
else:
5455
full_path = Path(path) # Convert path to a Path object
5556
if not full_path.is_absolute():
@@ -60,14 +61,17 @@ def create_full_path(self, path):
6061
if not full_path.exists():
6162
raise FileNotFoundError(f"The file '{full_path}' does not exist.")
6263

64+
print(f"Path is a local file: {full_path}")
6365
return str(full_path), False
6466

6567

6668
# Decorator to observe when a trait attribute is changed
6769
@observe('imagePath')
6870
def _image_path_change(self, change): # Handler - change
71+
print("Image path changed:", change['new'])
6972
new_value = change['new']
7073
self.imagePath, self.is_imagePath_url = self.create_full_path(new_value)
74+
print(f"Updated imagePath: {self.imagePath}, is_imagePath_url: {self.is_imagePath_url}")
7175

7276
@observe('overlayPath')
7377
def _overlay_path_change(self, change):

jupyterlab_polus_render/src/plugin.ts

+39-27
Original file line numberDiff line numberDiff line change
@@ -51,38 +51,42 @@ function activateWidgetExtension(
5151
let overlayPath = this.model.get('overlayPath');
5252
let isImagePathUrl = this.model.get('is_imagePath_url');
5353
let isOverlayPathUrl = this.model.get('is_overlayPath_url');
54-
let imageUrl = isImagePathUrl ? imagePath : `${baseUrl}${renderFilePrefix}${imagePath}`; // T/F condition ? valueIfTrue : valueIfFalse
55-
let overlayUrl = isOverlayPathUrl ? overlayPath : `${baseUrl}${renderFilePrefix}${overlayPath}`;
56-
57-
// [ Not needed anymore since traitlet sync takes cares ]
58-
// Updates the state based on current value
59-
// this.model.set('is_imagePath_url', imagePath.startsWith('http'));
60-
// this.model.set('is_overlayPath_url', overlayPath.startsWith('http'));
61-
// this.model.save_changes();
6254

63-
// Set the image url
55+
console.log(`isImagePathUrl: ${isImagePathUrl}, imagePath: ${imagePath}`);
56+
// console.log(`isOverlayPathUrl: ${isOverlayPathUrl}, overlayPath: ${overlayPath}`);
57+
58+
59+
// T/F condition ? valueIfTrue : valueIfFalse
60+
let imageUrl = isImagePathUrl ? imagePath : `${baseUrl}${renderFilePrefix}${imagePath}`;
61+
let overlayUrl = isOverlayPathUrl ? overlayPath : `${baseUrl}${renderFilePrefix}${overlayPath}`;
62+
63+
console.log(`imageUrl: ${imageUrl}`);
64+
// console.log(`overlayUrl: ${overlayUrl}`);
65+
66+
// Set the image URL in the store
6467
store.setState({
6568
urls: [
66-
imageUrl,
69+
imageUrl,
6770
],
68-
});
71+
});
6972

70-
// Set the overlay url
71-
fetch(overlayUrl).then((response) => {
73+
// Set the overlay url
74+
fetch(overlayUrl).then((response) => {
7275
response.json().then((overlayData) => {
73-
store.setState({
74-
overlayData,
75-
});
76-
const heatmapIds = Object.keys(overlayData.value_range)
77-
.map((d: any) => ({ label: d, value: d }))
78-
.concat({ label: 'None', value: null });
76+
store.setState({
77+
overlayData,
78+
});
79+
const heatmapIds = Object.keys(overlayData.value_range)
80+
.map((d: any) => ({ label: d, value: d }))
81+
.concat({ label: 'None', value: null });
7982

80-
store.setState({
81-
heatmapIds,
82-
});
83+
store.setState({
84+
heatmapIds,
85+
});
8386
});
84-
});
85-
}
87+
});
88+
}
89+
8690

8791
protected showUnsupportedFileTypePopup() {
8892
showDialog({
@@ -243,9 +247,17 @@ function activateWidgetExtension(
243247

244248
// Observe any changes to imagePath and rerun the widget when it changes
245249
this.model.on('change:imagePath', () => {
246-
console.log('imagePath change detected')
247-
this.loadsetState(); // Updates the value of imagePath
248-
this.updateView(); // Re-render widgets view with new state
250+
console.log('imagePath change detected in frontend');
251+
console.log('New imagePath:', this.model.get('imagePath'));
252+
253+
// Check if is_imagePath_url is updated correctly
254+
console.log('New is_imagePath_url:', this.model.get('is_imagePath_url'));
255+
256+
// Add a small delay before calling loadsetState - Helps to ensure the backend processing is complete
257+
setTimeout(() => {
258+
this.loadsetState();
259+
this.updateView();
260+
}, 100); // 100 milliseconds delay
249261
}, this);
250262

251263
// Observe any changes to overlayPath and rerun the widget when it changes

0 commit comments

Comments
 (0)