Updating image using Shane's Dialog Toolkit without reopening a new dialog

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

Hello Nicolas (@NT83) :wave:

Its interesting what you want to accomplish with Shane’s Dialog Toolkit Plus.

But you’ll have no luck writing dynamically changing Dialogs with it - unless you roll your own version of it and change the Codebase completely like Tom (@t.spoon) did it for Dialog Toolkit at the time this version of the library existed.

Or you build the code from the ground up as a new Library.

This is what I can say about it … maybe I am totally wrong but that’s what I know and can remember from a talk with Shane about writing dynamic Dialogs using this Library a very long time ago - and unless I’ve missed a huge update to DTP where Shane made this possible - this will not be.

Maybe there is a chance that Tom (@t.spoon) shares his modified version for dynamic Dialogs with the community ?!

I am sorry to give you an answer like this …

Greetings from Germany :de:

Tobias

Hey Tobias (@Nr.5-need_input)

Thanks for your contribution to my topic, really appreciated.

Yes I am pretty sure too, that I need to modify the core of Shane’s toolkit.

I also already modified several parts to build a custom version, so the handlers return specific informations that I need in my project, for exemple. Nothing too “hardcore” though, and maybe the kind of modification that I seek here is out of my league, but if some hints or pointers can be handed to me, I will welcome them and try as hard as I can, because I find it really entertaining.

So the correct words for my project are “Dynamic Dialogs”. And I hear from you that another member did just that. Wow maybe there’s some hope after all !

Greetings from France !
Nicolas

1 Like

Hey Nicolas👋

Great that I could give you at least some information about DTP.

You’ve linked the thread in your post:

Maybe you forgot about that ?! - The code in that post you’ve linked to was from Tom - he also created the whole Thread / Topic.

I’ve never revisited this topic since my first time I was originally thinking about dynamic Dialogs and nearly one week after I got the info from Shane I gave to you above.

After that time I had so much other stuff going on that I totally forgot about the existence of that topic and the fact that there is a person that could potentially help me with this.

Thanks for bringing this whole thing back into my life :pray:

Greetings back to France :fr:

Tobias

Hey Tobias :slightly_smiling_face:

Wow I didn’t realize the Thread’s creator and Tom you were referring to, were actually the same person !! Thanks for pointing that out. But that means my research on Macscripter was done right I guess… :sweat_smile:

I have good news, I made significant progress. My first intuition was correct :

theImage's setImage:newImage

This is exactly what does the trick, in addition to Tom’s handler (2nd script of the first post). But, since I was building the path of the new image, with an out of scope variable, inside the method to be triggered by the the popup’s setAction, the Path of the image couldn’t be built, as a result the image didn’t refresh.

Because it didn’t trigger any error in Script Debugger, I wrongly thought my code was error free and that the image couldn’t refresh because I was missing another step.

This is the right way to do it but I had to set global variables (or properties) so they can be accessed by the handler.

I wonder why it didn’t trigger any error ? :thinking:

Here is a gif for the demonstration of the behaviour with the buttons (flashing) and dynamically triggered by the popup (without flash).

changeimage

Anyway, my conclusion is that it is almost completely doable to build Dynamic Dialogs with Shane’s toolkit, with ZERO core modification needed. We can interconnect (without any modification of the toolkit) all of the controls except for the buttons. Pushing a button triggers the dialog’s closure by design so as it is, we can’t use their state to trigger actions dynamically. In order to do that, we need a type of dynamic button which would be interconnectable with other controls, and we would have to modify the toolkit by adding a new type of control, and implement it correctly in the rest of the handlers.

In my opinion, this kind of spring loaded button can be useful, for instance to trigger asynchronous scripts, clear some cache by user prompt, reset elements of the dialog etc… endless possibilities)

This toolkit is so powerful !

I think I might work on creating a dynamic version for those who like me and you, think it would be a good improvement/addition. The most challenging part of this work will be to make those “links” between controls, easy to implement for the user.

There is also the fact that the handlers triggered by setAction can’t take parameters if I am not mistaking.

Thanks Tobias for stepping by on my Topic and your kind words. thanks to Tom for his topic wich was necessary for me to understand the problem. And Thanks to Shane for the amazing toolkit he created. :smiley:

Hey Nicolas :wave:

Great to see you making progress …

Yes as long as you set everything you want to display dynamically as properties there is a lot of room for updating maybe even changing the count of the buttons, adding or removing other controls, making the dialog bigger or smaller …

Buttons will never work dynamically because every one you have in a dialog is intended to always close the dialog - what ever each button is used to do after the Dialog was closed.

If you want to do the work to build a Version vor Dynamic Dialogs - I have to say that I for my part can not help you out - if I would be able to write code the way it is needed - you would of course have a development partner.

But since my knowledge is far away from that you’re on your own - sorry for that …

My day will now end … have to get some sleep.

Greetings from Germany :de:

Tobias

One thing you could do is place both images at the same location. Then set them as Hidden.
In your buttons handler Hide/Unhide each image based on the button.

You could also take it further and create two global variables image1State, image2State.
Then bind each image’s hidden state to the variable.

Then on the buttons handler, change the Boolean value of each imageState appropriately.