Skip to content

Commit 682b4cf

Browse files
committed
Merge pull request JuliaImages#22 from moehabib/documentation_fix
Documentation add section about calling display() within julia script file
2 parents 2a5da26 + 96b3682 commit 682b4cf

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

README.md

+42
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ display(img, pixelspacing = [1,1])
3737
The basic command to view the image is `display`.
3838
The optional `pixelspacing` input tells `display` that this image has a fixed aspect ratio, and that this needs to be honored when displaying the image. (Alternatively, you could set `img["pixelspacing"] = [1,1]` and then you wouldn't have to tell this to the `display` function.)
3939

40+
**Note:** If you are running Julia from a script file, the julia process will terminate towards the end of the program. This will cause any windows opened with `display()` to terminate (Which is probably not what you intend). Refer to [calling display from a script file](#calling-display-from-a-script-file) section for more information on how to avoid this behavior.
41+
4042
You should get a window with your image:
4143

4244
![photo](readme_images/photo1.jpg)
@@ -105,6 +107,7 @@ You can change the playback speed by right-clicking in an empty space within the
105107

106108
![GUI snapshot](readme_images/popup.jpg)
107109

110+
108111
<br />
109112
<br />
110113

@@ -164,3 +167,42 @@ display(c[2,1], testimage("moonsurface"); ops...)
164167
display(c[2,2], testimage("mandrill"); ops...)
165168
```
166169
![canvasgrid snapshot](readme_images/canvasgrid.jpg)
170+
171+
172+
## Additional notes
173+
174+
### Calling display from a script file
175+
176+
If you call Julia from a script file, the julia process will terminate towards the end of the program. This will cause any windows opened with `display()` to terminate (Which is probably not what you intend). We want to make it only terminate the process when the image window changes. Bellow is some example code to do this:
177+
178+
```
179+
using Tk
180+
using Images
181+
using ImageView
182+
183+
img = imread()
184+
imgc, imgslice = display(img);
185+
186+
#If we are not in a REPL
187+
if (!isinteractive())
188+
189+
# Create a condition object
190+
c = Condition()
191+
192+
# Get the main window (A Tk toplevel object)
193+
win = toplevel(imgc)
194+
195+
# Notify the condition object when the window closes
196+
bind(win, "<Destroy>", e->notify(c))
197+
198+
# Wait for the notification before proceeding ...
199+
wait(c)
200+
end
201+
```
202+
203+
This will stop the julia process from terminating immediately. Note that if we did not add the `bind` function, the process will keep waiting even after the image window has closed, and you will have to manually close it with `CTRL + C`.
204+
205+
If you are opening more than one window you may need to create more than one `Condition` object.
206+
207+
<br>
208+
<br>

0 commit comments

Comments
 (0)