action buttons and input field

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

action buttons and input field

asdfghjkl123456789
Hi,
I am doing a calculator.

I'v done a one input field and 9 action button for number.
I want click on action button and see a result in input field.
I was trying do something like that with label and ido this like that(for example for number eight)
 
putEight
 
        (self widgetAt: #ILabel1) labelString: ('8').

^self


and for a label it is working. How do it for input field?
Reply | Threaded
Open this post in threaded view
|

Re: action buttons and input field

Steven Kelly
asdfghjkl123456789 [[hidden email]] wrote Nov 19, 2012 3:42 PM:

> I am doing a calculator.
>
> I'v done a one input field and 9 action button for number.
> I want click on action button and see a result in input field.
> I was trying do something like that with label and ido this like
> that(for example for number eight)
>
> putEight
>
> (self widgetAt: #ILabel1) labelString: ('8').
>
> ^self

You don't need ^self - if there's no explicit return, self is returned
implicitly.

> and for a label it is working. How do it for input field?

When you add the input field in the UI Painter, you set its aspect, e.g.
#screenNumber. Edit | Define will create a method for you like this
(assuming you set the InputField Type to Number):

screenNumber
        ^screenNumber isNil
                ifTrue: [screenNumber := 0 asValue]
                ifFalse: [screenNumber]

You write the value to the screenNumber input field by sending
screenNumber the value: message, with the number as an argument:

putEight
        self screenNumber value: 8

Obviously you'll actually need to have more logic in there, so that
pressing 8 twice results in 88 and so on, but this should get you
started. See doc\GUIDevGuide.pdf for more info.

All the best,
Steve
--
Please send replies to the vwnc list

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: action buttons and input field

Dave & Vicki Stevenson
The original example is confusing because #ILabel1 is referenced as the id of a button:
     (self widgetAt: #ILabel1)...
Don't let yourself become confused by the names (or ids) of widgets vs their models. #Label1 is the kind of id that gets automatically assigned when you add a label widget from the pallette to the spec. You should always replace automatically generated ids with something more sensible. For example, if I have the following label:
    Foo
I might give it the id:
    #Foo
or:
    #labelFoo
or something like that, to distinguish it from other labels in the spec.
 
Likewise, the button widget should have a sensible id:
    #button8
The button label is displayed on the button, and should probably represent what the button does, like '8'. When editing the windowSpec, I would select button8 and set these properties:
            Action Button
    Label:    _ Supplied by Application (check this if you want to send a message to answer the label instead of hard-coding it in the spec - probably not necessary for this button) 
    String:    8
    Lookup key:      (leave this blank unless you want the label to be retrieved from a localized catalog)
    Catalog:      (leave this blank unless you want the label to be retrieved from a localized catalog)
    Action:    #putEight    (or simply #put8, if you prefer)
    ID:    #button8
 
Steven properly showed that you don't want to directly modify the input field widget, but rather the model (aValueHolder) with which it is associated. I'll suggest that 'screenNumber' is not a good name for your value holder, because a value holder is not a number, and I like to name things by what they are to avoid confusion later. For example, suppose I want to modify a method in an application I wrote a long time ago, or maybe that someone else wrote. If I see a send to #number in the existing code, I might expect aNumber to be answerd, and I would be surprised if it instead answered aValueHolder. So I might name my aspect #numberHolder, which is clear. I can also add an accessor to answer the number if I want:
    number
        ^self numberHolder value
which is also clearly named. So now if I want the number I know how to get it, and if I want the model (value holder) I can get that as well.
 
If you're emulating a calculator, then the calculator display sometimes shows an input value, and sometimes a result. So inputHolder or resultHolder might be too specific a name. Maybe just numberHolder if you're thinking in terms of modelling a number. But perhaps you want more flexibility in modelling the calculator's display. For example, I have a carpenter's calculator that converts between imperial and metric measurements. For that calculator, you'd need to display the physical unit (ft, in, m, cm, etc) as well. So maybe displayHolder would better suit your needs. So you might set these widget properties in the painter:
            Input Field
    Aspect:    numberHolder
    Menu:   
    ID:    numberInputField
    Type:    Number
    Format:   
 
or for more flexibility:
            Input Field
    Aspect:    displayHolder
    Menu:   
    ID:    displayInputField
    Type:    String
    Format:   
 
Now that my input field has a proper id, I can access it if needed:
    self widgetAt: #numberInputField
if I want to update the widget state, like disable it or change its background color. But for merely changing the number value, follow Steven's advice about updating the value holder.
 
Labels are rarely changed, so they are designed to be static widgets. They can be changed, but that is not typical and they do not support the same ease of update that an input field does. If I want a label that changes dynamically (which you don't in this case, you want your input field), I'll use an input field and set it to read-only (so the user cannot click and change it) and remove its border (so it looks more like a label than an input field - see Details tab in the painter tool).
 

Dave Stevenson
[hidden email]

 


From: Steven Kelly <[hidden email]>
To: [hidden email]
Sent: Fri, November 30, 2012 10:47:26 AM
Subject: Re: [vwnc] action buttons and input field

asdfghjkl123456789 [[hidden email]] wrote Nov 19, 2012 3:42 PM:

> I am doing a calculator.
>
> I'v done a one input field and 9 action button for number.
> I want click on action button and see a result in input field.
> I was trying do something like that with label and ido this like
> that(for example for number eight)
>
> putEight
>
>     (self widgetAt: #ILabel1) labelString: ('8').
>
> ^self

You don't need ^self - if there's no explicit return, self is returned
implicitly.

> and for a label it is working. How do it for input field?

When you add the input field in the UI Painter, you set its aspect, e.g.
#screenNumber. Edit | Define will create a method for you like this
(assuming you set the InputField Type to Number):

screenNumber
    ^screenNumber isNil
        ifTrue:    [screenNumber := 0 asValue]
        ifFalse:    [screenNumber]

You write the value to the screenNumber input field by sending
screenNumber the value: message, with the number as an argument:

putEight
    self screenNumber value: 8

Obviously you'll actually need to have more logic in there, so that
pressing 8 twice results in 88 and so on, but this should get you
started. See doc\GUIDevGuide.pdf for more info.

All the best,
Steve
--
Please send replies to the vwnc list

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc