[APBeta] Script help
Paul Rodman
paul at ilanga.com
Sat Jul 9 08:12:08 PDT 2011
On Jul 8, 2011, at 5:12 PM, Jeff Young wrote:
> I’ve written the following script to allow editing of user image descriptions (and some of the flags). The first dialog shows a list of user images. Double-clicking one of them brings up an edit dialog which allows you to edit the description and two of the flags.
>
> The first dialog list is doing a string-sort instead of an ID-sort, though. Is there a way to return ID for the MultiFieldObject’s ColumnType so the list will sort correctly?
I don't think so, but it would be easy enough to add it, since I already use it in the main application.
Paul R.
>
> Thanks,
> Jeff.
>
> function EditImage(img as Image) as boolean
> dim editor as Dialog, imgCanvas as Canvas
> editor = new Dialog
> imgCanvas = Dialog.NewCanvas(500, 500)
> imgCanvas.DrawImage(img, 0, 0, 500)
>
> editor.CanvasParameter(imgCanvas)
> editor.StringParameter("Description", img.Description)
> editor.BooleanParameter("Color", img.IsColor)
> editor.BooleanParameter("Black on White", img.IsBlackOnWhite)
>
> if editor.show("Edit User Image for " + img.ID) then
> img.Description = editor.StringParameter("Description")
> img.IsColor = editor.BooleanParameter("Color")
> img.IsBlackOnWhite = editor.BooleanParameter("Black on White")
> return true
> end if
>
> return false
> end function
> function toStr(b as boolean) as string
> if b then
> return "true"
> else
> return "false"
> end if
> end function
> class ImageMetaData
> implements MultiFieldObject
> ID as string
> Desc as string
> isColor as boolean
> isBlackOnWhite as boolean
> index as integer
> function ColumnName(idx as integer) as string
> if idx = 1 then
> return "ID"
> elseif idx = 2 then
> return "Description"
> elseif idx = 3 then
> return "Color"
> elseif idx = 4 then
> return "Black on White"
> elseif idx = 5 then
> return "Index"
> end if
> end function
> function ColumnType(idx as integer) as integer
> if idx = 1 then
> return vtype_String
> elseif idx = 2 then
> return vtype_String
> elseif idx = 3 then
> return vtype_Boolean
> elseif idx = 4 then
> return vtype_Boolean
> elseif idx = 5 then
> return vtype_Integer
> end if
> end function
> function ColumnValue(idx as integer) as string
> if idx = 1 then
> return ID
> elseif idx = 2 then
> return Desc
> elseif idx = 3 then
> return toStr(isColor)
> elseif idx = 4 then
> return toStr(isBlackOnWhite)
> elseif idx = 5 then
> return Str(index)
> end if
> return "undefined column (" + Str(idx) + ")"
> end function
> function nColumns() as integer
> return 5
> end function
> end class
> function getImageMetaData(img as Image, idx as integer) as ImageMetaData
> dim metadata as ImageMetaData
> metadata = new ImageMetaData
>
> metadata.ID = img.ID
> metadata.Desc = img.Description
> metadata.isColor = img.IsColor
> metadata.isBlackOnWhite = img.IsBlackOnWhite
> metadata.index = idx
>
> return metadata
> end function
> sub main()
> try
> dim imageData(1000) as ImageMetaData
>
> dim i, idx as integer, img as Image
> i = 0
> for idx = 1 to Image.Count
> img = Image.Get(idx)
> if img.IsUser then
> imageData(i) = getImageMetaData(img, idx)
> i = i + 1
> end if
> next
> redim imageData(i-1)
>
> dim browser as Dialog
> while true
> browser = new Dialog
> browser.ListChoiceParameter("User Images", 0, imageData, true, 50, true)
> browser.ParameterWindowNoCancel()
> browser.ParameterWindowOKCaption("Done")
>
> if browser.show("User Image Browser") then
> if browser.DoubleClickedList() = "User Images" then
> i = browser.ListChoiceParameter("User Images")
> idx = imageData(i).index
> img = Image.Get(idx)
> if EditImage(img) then
> imageData(i) = getImageMetaData(img, idx)
> end if
> else
> return
> end if
> else
> return
> end if
> wend
> catch
> print "My bad. Image Browser script generated an exception."
> end try
> end sub
> _______________________________________________
> APBeta mailing list
> APBeta at lists.astroplanner.net
> http://lists.astroplanner.net/listinfo.cgi/apbeta-astroplanner.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.astroplanner.net/pipermail/apbeta-astroplanner.net/attachments/20110709/c6414e98/attachment-0003.htm>
More information about the APBeta
mailing list