Hello,
I am currently experimenting with Shane’s Dialog Toolkit Plus.
Would it be possible to change an image without having to reopen a new dialog window causing the “flash” ?
The first code below works but causes a flash since the dialog has to be recreated each time to trigger the change, by clicking the “image 1” / “image 2” buttons, or by clicking the “Ok” button after having selected the image I want in the popup.
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
use script "Dialog Toolkit Plus" version "1.1.2"
set folder_path to (path to home folder as text) & "Documents:scripting:Script Debugger:test_folder:"
set images_paths to {¬
folder_path & "image1.jpg", ¬
folder_path & "image2.jpg"}
set accViewWidth to 400
set viewWidth to 50
set viewHeight to 50
set {theButtons, minWidth} to create buttons {"Cancel", "image 1", "image 2", "OK"} default button 1 given «class btns»:2
if minWidth > accViewWidth then set accViewWidth to minWidth -- make sure buttons fit
set {imPopUp, popupLabel, theTop} to create labeled popup {"image 1", "image 2"} ¬
bottom (20) popup width 100 max width accViewWidth label text ¬
"Select the image" popup left 150 initial choice 1
set buttonName to ""
set controlsResults to {{}}
set im_bottom to theTop + 20
repeat while buttonName is not "Cancel"
if buttonName is "image 2" or item 1 of controlsResults is "image 2" then
set viewPath to item 2 of images_paths
else
set viewPath to item 1 of images_paths
end if
set posixPath to POSIX path of viewPath
set {theImage, theTop} to create image view posixPath ¬
bottom im_bottom ¬
view width viewWidth ¬
view height viewHeight ¬
set allControls to {imPopUp, popupLabel, theImage}
set {buttonName, controlsResults} to display enhanced window ¬
"Change image" acc view width accViewWidth acc view height theTop acc view controls allControls buttons ¬
theButtons with align cancel button
end repeat
My understanding of imageView is :
1/ load the image specifying the path.
2/ create the view specifying the frame dimensions,
3/ set the image to the view
4/ do alignement, scaling stuff…
after having a closer look at the doc and dialog toolkit handlers, I intuitively think of this
theImage’s setImage:newImage
Tried to implement it without success (image doesn’t update)
Here is a script I found in another topic
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions
use script "Dialog Toolkit plus"
property ordersNmethods : {}
set ordersNmethods to {theOrders:{"Please Make a Selection", "Order Number 1, Production Method 2", "Order Number 2, Production Method 5"}, theMethods:{missing value, 2, 5}}
set {methodPopup, methodPopupLabel, theTop, matrixLeft} to create labeled popup {"1 - Some Method", "2 - Another Method", "3 - Still More Methods", "4 - The Rhythm Method", "5 - Methodical"} left inset 0 bottom 0 popup width 200 max width 400 label text "Override Method" popup left 0
set {orderPopup, orderPopupLabel, theTop, matrixLeft} to create labeled popup (theOrders of ordersNmethods) left inset 0 bottom (theTop + 20) popup width 200 max width 400 label text "Choose an Order" popup left 0
orderPopup's setTarget:me
orderPopup's setAction:"setMethod:"
set {buttonName, suppressedState, controlsResults} to display enhanced alert "Test" message "" as informational alert buttons {"Cancel", "OK"} giving up after 120 acc view width 700 acc view height (theTop + 10) acc view controls {methodPopup, orderPopup} without suppression
on setMethod:sender
set selectedOrderIndex to (my orderPopup's indexOfSelectedItem() as integer) + 1
set orderMethod to item selectedOrderIndex of theMethods of ordersNmethods
my (methodPopup's selectItemAtIndex:(orderMethod - 1))
end setMethod:
the behavior is close to what I seek (minus the image part) because it does not trigger a complete reopening of the dialog.
I would appreciate any hint you could give me.
Thank you