More Myriad Table Questions

I feel I’m very close to adding an accessory view field to a table, but it’s not working. I’m getting a blank space.

What am I missing?

use AppleScript version "2.4"
use framework "Foundation"
use framework "AppKit"
use script "Myriad Tables Lib" version "1.0.9"
use scripting additions

property theAccessoryView : missing value
property theField : missing value

if current application's NSThread's isMainThread() as boolean then
   my createFieldMainThread:{"entered Text", "place holder text", 20, 20, 200, 200, true}
   my buildAccessoryViewMainThread:{theField}
else
   my performSelectorOnMainThread:"createFieldMainThread:" withObject:{"enteredText", "placeholder", 0, 0, 200, 20, true} waitUntilDone:true
   my performSelectorOnMainThread:"buildAccessoryViewMainThread:" withObject:{theField} waitUntilDone:true
   
end if

set theTable to make new table with data {"One", "Two", "Three", "Four", "Five"}
modify table theTable accessory view theAccessoryView
set theAccessoryView to missing value -- to avoid error messages when saving
display table theTable


on createFieldMainThread:theArg
   set {enteredText, placeholder, theLeft, theBottom, theWidth, extraHeight, acceptsTabs} to theArg as list
   set theTop to theBottom + 22 + extraHeight
   set theField to (NSTextField's alloc()'s initWithFrame:{{theLeft, theBottom}, {theWidth, theTop - theBottom}})
   tell theField
      (its setEditable:true)
      (its setBezeled:true)
      its (cell()'s setPlaceholderString:placeholder)
      if extraHeight > 0 then its (cell()'s setWraps:true)
      its setStringValue:enteredText
      if acceptsTabs then its setDelegate:me
   end tell
   -- return theField, the top of the field
   set my handlerResult to {theField, theTop}
end createFieldMainThread:

on buildAccessoryViewMainThread:theControls
   set my theAccessoryView to current application's NSView's alloc()'s initWithFrame:{{0, 0}, {160, 60}}
   repeat with aControl in theControls
      (theAccessoryView's addSubview:aControl)
   end repeat
end buildAccessoryViewMainThread:



I think I figured out what I was missing: Dialog Toolkit Plus!

use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AppKit"
use framework "Carbon" -- AEInteractWithUser() is in Carbon 
use script "Myriad Tables Lib" version "1.0.12"
use script "Dialog Toolkit Plus" version "1.1.2"

property theAccessoryView : missing value

--accView variables
set accViewControls to {}
set AccViewLeft to 0
set AccViewBottom to 0
set AccViewWidth to 200
set AccViewTop to 250

set theBottom to AccViewBottom
set theLeft to AccViewLeft

set spacer to 20

--Label variables
set maxWidth to 200
set alignment to center aligned
-- alignments: left aligned, right aligned or center aligned
set wrapsBool to true
set controlSize to regular size
--control sizes:regular size,  mini size, small size,large size 
set boldType to true
set labelString to "The Label Text"

--Field variables
set enteredText to "Entered Text"
set defaultText to "Place holder text"
set theWidth to 200
set extraHeight to spacer
set acceptsTabs to true

--View variables
set iconPath to choose file with prompt ("Select the image to display") ¬
   of type ("jpg") with showing package contents
set posixPath to POSIX path of iconPath
--set posixPath to "/Users/edstockly/AppleScript/Handlers and Snippets/MyriadTableAccessoryView/seachSafariIcon.jpg"

set viewWidth to 40
set viewHeight to 40
set imageScale to scale to fit
--{scale down proportionally, scale to fit, scale none, scale proportionally}
set imageAlignment to bottom aligned
--imageAlignments:center aligned, top aligned, top left aligned, top right aligned
----left aligned, bottom left aligned, bottom right aligned, right aligned, bottom aligned

set {theField, theTop} to create field enteredText ¬
   placeholder text defaultText ¬
   left inset theLeft ¬
   bottom theBottom ¬
   field width theWidth ¬
   extra height extraHeight ¬
   with accepts linebreak and tab

set the end of accViewControls to theField

set theBottom to theTop

set {theLabel, theTop} to create label labelString ¬
   left inset theLeft ¬
   bottom theBottom ¬
   max width maxWidth ¬
   aligns alignment ¬
   multiline wrapsBool ¬
   control size controlSize ¬
   bold type boldType

set the end of accViewControls to theLabel
set theBottom to theTop + spacer

set {theImage, theTop} to create image view posixPath ¬
   left inset theLeft ¬
   bottom theBottom ¬
   view width viewWidth ¬
   view height viewHeight ¬
   scale image imageScale ¬
   align image imageAlignment

set the end of accViewControls to theImage
set theTop to theTop - AccViewBottom
if theTop < AccViewTop then set AccViewTop to theTop

my buildAccessoryViewMainThread:{accViewControls, AccViewLeft, AccViewBottom, AccViewWidth, AccViewTop}

on create label labelString left inset theLeft : 0 bottom theBottom max width maxWidth aligns alignment : left aligned multiline wrapsBool : true control size controlSize : regular size bold type boldType : false
   if NSThread's isMainThread() as boolean then
      my createLabelMainThread:{labelString, theLeft, theBottom, maxWidth, alignment, wrapsBool, controlSize, boldType}
   else
      my performSelectorOnMainThread:"createLabelMainThread:" withObject:{labelString, theLeft, theBottom, maxWidth, alignment, wrapsBool, controlSize, boldType} waitUntilDone:true
   end if
   return handlerResult
end create label

on create field enteredText placeholder text placeholder left inset theLeft : 0 bottom theBottom field width theWidth extra height extraHeight : 0 accepts linebreak and tab acceptsTabs : false
   if NSThread's isMainThread() as boolean then
      my createFieldMainThread:{enteredText, placeholder, theLeft, theBottom, theWidth, extraHeight, acceptsTabs}
   else
      my performSelectorOnMainThread:"createFieldMainThread:" withObject:{enteredText, placeholder, theLeft, theBottom, theWidth, extraHeight, acceptsTabs} waitUntilDone:true
   end if
   return handlerResult
end create field

on create top labeled field enteredText placeholder text placeholder : "" left inset theLeft : 0 bottom theBottom field width theWidth extra height extraHeight : 0 label text theLabel accepts linebreak and tab acceptsTabs : false
   set {theField, theTop} to create field enteredText placeholder text placeholder left inset theLeft bottom theBottom field width theWidth extra height extraHeight accepts linebreak and tab acceptsTabs
   set {theLabel, theTop, newWidth} to create label theLabel left inset theLeft bottom (theTop + 8) max width theWidth aligns left aligned without multiline
   return {theField, theLabel, theTop}
end create top labeled field

on create image view posixPath left inset theLeft bottom theBottom view width viewWidth view height viewHeight scale image imageScale : scale down proportionally align image imageAlignment : center aligned
   if NSThread's isMainThread() as boolean then
      my createImageViewMainThread:{posixPath, theLeft, theBottom, viewWidth, viewHeight, imageScale, imageAlignment}
   else
      my performSelectorOnMainThread:"createImageViewMainThread:" withObject:{posixPath, theLeft, theBottom, viewWidth, viewHeight, imageScale, imageAlignment} waitUntilDone:true
   end if
   return handlerResult
end create image view

on buildAccessoryViewMainThread:theArg
   set {accViewControls, theLeft, theBottom, theWidth, theTop} to theArg
   set my theAccessoryView to current application's NSView's alloc()'s initWithFrame:{{theLeft, theBottom}, {theWidth, theTop - theBottom}}
   repeat with aControl in accViewControls
      (theAccessoryView's addSubview:aControl)
   end repeat
end buildAccessoryViewMainThread:

set theTable to make new table with data {"One", "Two", "Three", "Four", "Five"} with empty selection allowed
modify table theTable ¬
   accessory view theAccessoryView
set theAccessoryView to missing value -- to avoid error messages when saving
display table theTable ¬
   with extended results
set theState to theField's stringValue()





Nevermind…
→ Script Debugger 8.0.5 (8A61)
→ MacOS 12.6.4
→ Myriad Tables 1.0.12