Page 1 of 1

Adding checkbox buttons from script

Posted: Tue Oct 17, 2017 1:32 pm
by PoLyGLoT
Hi,

I want to add checkbox buttons based on the numbers of columns in a file. I have a button to import a file, and based on the contents of that file, I want to be able to create, say, 15 checkbox buttons with the titles reflecting information from the file. Note that the # of buttons I need and the titles of those buttons will change with each new file I import.

Can you add checkbox buttons from the script? Or do you have to put them there in developer mode?

If you cannot add them from the script, is it possible to add a bunch of buttons at the beginning and then change the titles later from the script?

Re: Adding checkbox buttons from script

Posted: Tue Oct 17, 2017 2:05 pm
by dunbarx
Hi.

LC can do anything you can think of. Check out the "create" command in the dictionary.

In your script, you would (pseudo)

Code: Select all

create button
set the style of last button to "checkBox"
set the loc of last button to wherever
set all other properties you are interested in
Craig Newman

Re: Adding checkbox buttons from script

Posted: Tue Oct 17, 2017 2:11 pm
by Mikey
Yes, you can.
Things to check in the dictionary:
  • "button" for all the button properties that you can set
  • "style" is the property that controls the type of button (rectangle, checkbox, etc.)
  • "templateButton". You can preset all the properties that you want all your checkboxes to share, before you create them

Re: Adding checkbox buttons from script

Posted: Tue Oct 17, 2017 3:14 pm
by PoLyGLoT
Thank you both.

I can create the buttons now, but I am trying to have them appear in a column within a text field.

Is it possible to take a set of text lines, and using a repeat function, transform a text line into a checkbox button? This would work better for my purposes.

Basically, I have this in a text field:

Code: Select all

Username
ID
ExperimentName
Session
Trial
Date
It's organized the way I want. I want to first populate the text field with all the info I want, and then transform those text lines into checkbox buttons. Is that possible?

Re: Adding checkbox buttons from script

Posted: Tue Oct 17, 2017 3:18 pm
by Mikey
You could with a datagrid. That would also give you a scroller, without having to build everything.

Re: Adding checkbox buttons from script

Posted: Tue Oct 17, 2017 3:23 pm
by PoLyGLoT
Just looking at a data grid and it seems like exactly what I want! Thank you!

Once I import the data into the grid, is there anything special to turn the row into a checkbox? Or can you make just the first column a checkbox, and the other columns pure data. That might be good for my purposes, actually.

Anyways, thank you!

Re: Adding checkbox buttons from script

Posted: Tue Oct 17, 2017 3:25 pm
by Mikey
I would go even simpler than that and just use the first column as a text field and control it so that it either has an “X” or is blank.

Re: Adding checkbox buttons from script

Posted: Tue Oct 17, 2017 4:11 pm
by PoLyGLoT
I have created a data grid with two columns, but I cannot figure out how to make the first column a text column (or a checkbox):

Image

Re: Adding checkbox buttons from script

Posted: Tue Oct 17, 2017 4:20 pm
by Mikey
It should already be a text column. Now refer to the DataGrid manual. You can either respond to a click on a row, or a click in the "Selected" column on a row (I prefer to respond to a click anywhere on a row, but that's just my preference). When someone clicks on a row in that column, the value of the cell should toggle between "X" and empty.

Re: Adding checkbox buttons from script

Posted: Wed Oct 18, 2017 4:31 am
by dunbarx
If you use a DG for your purposes , you will likely need to use the "form" variant, as opposed to the more basic "table" type.

DG's, especially forms, require a learning and practicing curve. They work right out of the box, but to customize them takes time.

It is time well spent, as they are powerful tools once you become even moderately proficient.Check out the lessons and the DG manual, as Mikey suggested.

Craig Newman

Re: Adding checkbox buttons from script

Posted: Wed Oct 18, 2017 11:53 am
by Mikey
I don't think in this case form is necessary since you can fake checkbox behavior, but if it isn't good enough, then I agree, form