• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to specify cocoa bindings options?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to specify cocoa bindings options?


  • Subject: Re: How to specify cocoa bindings options?
  • From: email@hidden
  • Date: Wed, 02 Sep 2015 03:26:30 -0400

Many, many thanks Shane! I even added a slider control and plan to hook up the bindings to show the values change continuously. Great tip!

Thanks,
-N



-----Original Message-----
From: Shane Stanley <email@hidden>
To: ASObjC <email@hidden>
Sent: Sat, Aug 29, 2015 8:35 pm
Subject: Re: How to specify cocoa bindings options?

On 30 Aug 2015, at 1:20 am, email@hidden wrote:

I'm using Shane Stanley's "Dialog Toolkit" and as an experiment wanted to set up cocoa bindings between a text field and a label. I would like to setup continuous updates from the text field so it would show any keystroke changes but am having some difficulty using the right terminology for it.

I didn't like your chances of getting this to work, to be honest, but it looks like it does. The options parameter requires a dictionary, so you could add something like this:

set theOptions to current application's NSDictionary's dictionaryWithObject : true forKey :( current application's NSContinuouslyUpdatesValueBindingOption )

And your bind parameter is also problematic -- you need current application's NSValueBinding. Throw in a placeholder for when the label is empty and your script becomes:

use AppleScript version "2.3.1"
use scripting additions
use framework "Foundation"
use framework "AppKit"

property textFieldOutlet : missing value
property labelOutlet : missing value
property boundProperty : "Initial state"

tell script "Dialog Toolkit"
check for main -- make sure we are in foreground when testing
set theLabelStrings to {"Random Text", "Random Text", "Even more randome text"}
set maxLabelWidth to max width for labels theLabelStrings
set controlLeft to maxLabelWidth + 6

set { labelOutlet, theTop, newWidth} to create label " total per queue." left inset 0 bottom (0 + 8) max width 250 aligns "left" without multiline
end tell
set theOptions to current application's NSDictionary's dictionaryWithObjects :{ true , "No entry"} forKeys :{ current application's NSContinuouslyUpdatesValueBindingOption , current application's NSNullPlaceholderBindingOption }
labelOutlet's bind :( current application's NSValueBinding ) toObject :me withKeyPath :"boundProperty" options :theOptions

tell script "Dialog Toolkit"
set { textFieldOutlet , textFieldLabel , theTop , fieldLeft } to create side labeled field "the field" placeholder text "Stop ID" left inset 0 bottom ( theTop + 8) total width 250 label text "textFieldOutlet" field left controlLeft
end tell

textFieldOutlet's bind :( current application's NSValueBinding ) toObject :me withKeyPath :"boundProperty" options :theOptions

tell script "Dialog Toolkit"
set allControls to {labelOutlet , textFieldLabel , textFieldOutlet }
-- controlResults will in the same order as allControls
set { buttonName , suppressedState , controlResults } to display enhanced alert "The main title." message "some other stuff" as informational buttons {"Cancel", "OK"} giving up after 120 acc view width 250 acc view height theTop acc view controls allControls without suppression
log controlResults
set {statusMessage , textFieldLabel , textFieldOutlet } to controlResults

end tell

Nice...

-- 
Shane Stanley <email@hidden>
<www.macosxautomation.com/applescript/apps/>

_______________________________________________
Do not post admin requests to
the list. They will be ignored.
applescriptobjc-dev mailing list
(email@hidden)
Help/Unsubscribe/Update your
Subscription:

This
email sent to email@hidden
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
applescriptobjc-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Next by Date: NSImage Resize
  • Next by thread: NSImage Resize
  • Index(es):
    • Date
    • Thread