Re: EXTERNAL: Re: Pharo Checkbox and Radio Button Questions

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: EXTERNAL: Re: Pharo Checkbox and Radio Button Questions

Benjamin Van Ryseghem (Pharo)
<base href="x-msg://753/">
On Mar 30, 2012, at 5:17 PM, Pingitore, Nelson wrote:

Hi,
 
Regarding the use of the following statement:  dialog := (builder newPluggableDialogWindow: 'Example basic controls') useDefaultOKCancelButton.
 
How do I detect if the user selected the OK or Cancel button?
 
Your option provided below and listed here, puts an additional Ok button on the form.  I am hoping to get instruction on capturing the user selection of the choices from the useDefaultOKCancelButton
 
For defining your button, you use something like 
'Ok'->(dialog newButtonFor: nil action: nil label: 'A Button' help: 'This is a button').
if instead you specify something like
'Ok'->(dialog newButtonFor: model action: #okAction label: 'Ok' help: 'This is a button').
Then when the button is clicked, the method okAction will be performed by model.
Then it's up to you to implement the wanted behavior in this method.
 
 
Thank you
 
 
 
Nelson V. Pingitore Jr.
Lockheed Martin Corporation
Information Systems & Global Services
Program Surveillance
410-279-2780
 
From: Benjamin [mailto:[hidden email]] 
Sent: Friday, March 30, 2012 9:27 AM
To: Pingitore, Nelson
Subject: Re: EXTERNAL: Re: Pharo Checkbox and Radio Button Questions
 
 
On Mar 30, 2012, at 3:06 PM, Pingitore, Nelson wrote:


Hi,
 
Thank you for your reply.  I Pharo is very exciting!
 
I develop applications in Microsoft’s Visual Studio tools, using Visual Basic.  For my example in Pharo, I am attempting to re-create a User Settings form via a Usersettings class in Pharo. 
 
 
Here is my code:
 
 
 
                |dialog builder radioModel treeModel|
                builder := UITheme exampleBuilder.
                dialog := (builder newPluggableDialogWindow: 'Example basic controls') useDefaultOKCancelButton.
                radioModel := ExampleRadioButtonModel new.
                treeModel := ValueHolder new contents: TextStyle actualTextStyles explorerContents.
                dialog contentMorph: ((dialog newRow:
                {
                                dialog newLabelGroup:
                                {
                                                'Normal Label'->(dialog newLabel: 'A Label').
                                                'Normal Button'->(dialog newButtonFor: nil action: nil label: 'A Button' help: 'This is a button').
                                                'Default Button'->((dialog newButtonFor: nil action: nil label: 'Default Button' help: 'This is a default button') isDefault: true).
                                                'Selected Button'->(dialog newButtonFor: (ValueHolder new contents: true) getState: #contents
                                                                                                                action: nil arguments: #() getEnabled: nil label: 'A Button' help: 'This is a selected button').
 
                                                'Checkbox A'->(dialog newCheckboxFor: (ValueHolder new contents: true)
                                                                                                                getSelected: #contents setSelected: #contents: label: 'A Checkbox' help: 'This is a checkbox').
                                                'Checkbox B'->(dialog newCheckboxFor: (ValueHolder new contents: true)
                                                                                                                getSelected: #contents setSelected: #contents: label: 'A Checkbox' help: 'This is a checkbox').
                                                'Checkbox C'->(dialog newCheckboxFor: (ValueHolder new contents: true)
                                                                                                                getSelected: #contents setSelected: #contents: label: 'A Checkbox' help: 'This is a checkbox').
                                                'Radio Buttons'->((dialog newColumn: {
                                                                                                                                (dialog newRadioButtonFor: radioModel
                                                                                                                                                getSelected: #isLeft setSelected: #beLeft label: 'Left' help: 'This is a radio buton').
                                                                                                                                                                                                                                                                                                                                                                                                        ^^^^^^^^^
                                                                                                                                                                                                                                                                                                                                                                              Here is the selector of the method performed when this radio button.
Then, in this method, you can store the state wanted :)
Something like
 
beLeft
 
          currentState = #left.
          blablabla....
 
 
 
                                                                                                                                (dialog newRadioButtonFor: radioModel
                                                                                                                                                getSelected: #isCenter setSelected: #beCenter label: 'Center' help: 'This is a radio buton').
                                                                                                                                (dialog newRadioButtonFor: radioModel
                                                                                                                                                getSelected: #isRight setSelected: #beRight label: 'Right' help: 'This is a radio buton')})
                                                                                                                                vResizing: #shrinkWrap).                                             
                                                'Text Entry'->(dialog newTextEntryFor: (ValueHolder new contents: 'Hello')
                                                                                                                getText: #contents setText: #contents: help: 'This is a text entry').
 
                                                'Slider'->(dialog newSliderFor: (ValueHolder new contents: 0.5)
                                                                                                                getValue: #contents setValue: #contents: help: 'This is a slider').
                                }.
                                dialog newVerticalSeparator.
                                dialog newLabelGroup:
                                {
                                                'Drop List'->(dialog newDropListFor: (ListModel new list: #('One' 'Two' 'Three' 'Four'))
                                                                                                                list: #list getSelected: #selectionIndex setSelected: #selectionIndex: help: 'This is a drop list').
                                                'Normal List'->((dialog newListFor: (ListModel new list: #('One' 'Two' 'Three' 'Four'); selectionIndex: 3)
                                                                                                                list: #list selected: #selectionIndex changeSelected: #selectionIndex:
                                                                                                                help: 'This is a list') minWidth: 120).
                                               
                                }.
                })
                vResizing: #spaceFill);
                model: nil.
                builder openModal: dialog
“---------------------------------------------------------------------------------------------------“
This is an extract from the UITheme exampleBasicControls class
 
My questions are related to capturing user selections:
 
1) How do I detect if the user selected “Ok” where I would want to save all of the user choices, or “Cancel” where the user choices are discarded?
 
For defining your button, you use something like 
'Ok'->(dialog newButtonFor: nil action: nil label: 'A Button' help: 'This is a button').
if instead you specify something like
'Ok'->(dialog newButtonFor: model action: #okAction label: 'Ok' help: 'This is a button').
Then when the button is clicked, the method okAction will be performed by model.
Then it's up to you to implement the wanted behavior in this method.
 
2) How do I detect which Checkboxes are checked or unchecked?
see the next point

3) How do I detect which Radio buttons are selected?
see the comment I let in your code above
 
Another solution is to store in an inst var all your widgets (radio buttons/checkboxes) and then when you press ok, iterate over those inst vars and see which ones are selected or not
 
4) How do I capture the Text Entry content? 
 
If you have a pointer to the text entry, just do 
myTextEntry text (or if it doesn't work, try getText instead)


Do I need to add instance variables to store user selections?  If so, how do I capture the user selections into those variables.
 
I think you will have to.
 
 
You're welcome,
 
Ben


 
 
Thanks
 
 
 
 
 
 
 
 
 
 
Nelson V. Pingitore Jr.
Lockheed Martin Corporation
Information Systems & Global Services
Program Surveillance
410-279-2780
 
From: Benjamin [[hidden email]] 
Sent: Friday, March 30, 2012 3:34 AM
To: The Pingitore Family
Cc: Pingitore, Nelson
Subject: EXTERNAL: Re: Pharo Checkbox and Radio Button Questions
 
Welcome among us :)
 
I hope you will have a great time using Pharo :)
 
 
Can you give me the code you are using as an example please ?
 
There are at least two different ways to create such widgets, so if you want a better answer, I need more info :)
 
 
Ben
 
On Mar 30, 2012, at 6:28 AM, The Pingitore Family wrote:



Hi,
 
I am new to Pharo.  Am looking at the UITheme exampleBasicControls.  I can see how the Checkboxes and Radio buttons are displayed,  But, how do I capture if the Checkbox has been checked and what its state is?  Same for the Radio buttons - How do I discover which radio button is selected?
 
Thank you for your time and advice
 
 
 
 

Reply | Threaded
Open this post in threaded view
|

Re: EXTERNAL: Re: Pharo Checkbox and Radio Button Questions

Sean P. DeNigris
Administrator
Benjamin Van Ryseghem-2 wrote
> How do I detect if the user selected the OK or Cancel button?
It's not very intuitive. You set an object as the model and then specify a callback like so:
        dialog
                model: self;
                applyChangesSelector: #ok.

HTH,
Sean
Cheers,
Sean