Button in view disabled

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

Button in view disabled

Chapa_Eye
Hello!

I'm a beginer and I'm trying to make a simple GUI with buttons. But all I'm getting
is an disabled Button, when I'm evaulating the code.

Does anybody know what is wrong, what should I do.


Reply | Threaded
Open this post in threaded view
|

Re: Button in view disabled

Ian Bartholomew-18
Hi,

> I'm a beginer

Welcome

>          and I'm trying to make a simple GUI with buttons. But all
> I'm getting is an disabled Button, when I'm evaulating the code.
>
> Does anybody know what is wrong, what should I do.

When you add the button to the Shell (in the ViewComposer) you should set
the 'command' aspect for the button to a Symbol.  This is the Symbol that is
"sent" when the button in pressed.

In your Shell (or one of it's superclasses) you should add an instance
method with a selector which _must be_ the same as the Symbol you use above.

Until the method is present the button will be disabled.  Try this -

Add the following to a workspace, select it all and evaluate it.  You should
see a shell with a single button, but the button is disabled as there is no
method in the image with the selector #buttonPushed

s := Shell show.
s view addSubView: (p := PushButton new).
p position: 100@100.
p command: #buttonPressed.
p text: 'Press Me'

If you now add the following instance method to the Shell class and then
re-evaluate the code above the button should now be enabled (because there
now is a method available with the correct selector) and when it is pressed
the message box should be displayed.

buttonPressed
    MessageBox notify: 'Pressed'

Note
 - I'm not suggesting you should normally add methods to Shell like this,
using inheritance just makes the above example easier
 - There are ways of enabling/disabling buttons dynamically, but that is
probably better as lesson 2

Ask again if you need help in translating the above to your own class.

Regards
    Ian


Reply | Threaded
Open this post in threaded view
|

Re: Button in view disabled

Chapa_Eye
"Ian Bartholomew" <[hidden email]> wrote in message news:<ZDDr9.3483$Lm1.282952@stones>...

> Hi,
>
> > I'm a beginer
>
> Welcome
>
> >          and I'm trying to make a simple GUI with buttons. But all
> > I'm getting is an disabled Button, when I'm evaulating the code.
> >
> > Does anybody know what is wrong, what should I do.
>
> When you add the button to the Shell (in the ViewComposer) you should set
> the 'command' aspect for the button to a Symbol.  This is the Symbol that is
> "sent" when the button in pressed.
>
> In your Shell (or one of it's superclasses) you should add an instance
> method with a selector which _must be_ the same as the Symbol you use above.
>
> Until the method is present the button will be disabled.  Try this -
>
> Add the following to a workspace, select it all and evaluate it.  You should
> see a shell with a single button, but the button is disabled as there is no
> method in the image with the selector #buttonPushed
>
> s := Shell show.

> s view addSubView: (p := PushButton new).
> p position: 100@100.
> p command: #buttonPressed.
> p text: 'Press Me'
>
> If you now add the following instance method to the Shell class and then
> re-evaluate the code above the button should now be enabled (because there
> now is a method available with the correct selector) and when it is pressed
> the message box should be displayed.
>
> buttonPressed
>     MessageBox notify: 'Pressed'
>
> Note
>  - I'm not suggesting you should normally add methods to Shell like this,
> using inheritance just makes the above example easier
>  - There are ways of enabling/disabling buttons dynamically, but that is
> probably better as lesson 2
>
> Ask again if you need help in translating the above to your own class.
>
> Regards
>     Ian


Thanky you very much for this example.

If it's not a problem, I would like to see how that works in my own
class.
If you could show me a simple example, to see how it works. I will be
really greatful.

Rok


Reply | Threaded
Open this post in threaded view
|

Re: Button in view disabled

Ian Bartholomew-18
> If it's not a problem, I would like to see how that works in my own
> class.
> If you could show me a simple example, to see how it works. I will be
> really greatful.

Sure. To avoid cluttering up the group it's probably best to take it to mail
so if you let me know (on [hidden email]) an e-mail address where I can
contact you, and which version of Dolphin you are using, I'll sort something
out.

Ian


Reply | Threaded
Open this post in threaded view
|

Re: Button in view disabled

Chapa_Eye
In reply to this post by Ian Bartholomew-18
"Ian Bartholomew" <[hidden email]> wrote in message news:<ZDDr9.3483$Lm1.282952@stones>...

> Hi,
>
> > I'm a beginer
>
> Welcome
>
> >          and I'm trying to make a simple GUI with buttons. But all
> > I'm getting is an disabled Button, when I'm evaulating the code.
> >
> > Does anybody know what is wrong, what should I do.
>
> When you add the button to the Shell (in the ViewComposer) you should set
> the 'command' aspect for the button to a Symbol.  This is the Symbol that is
> "sent" when the button in pressed.
>
> In your Shell (or one of it's superclasses) you should add an instance
> method with a selector which _must be_ the same as the Symbol you use above.
>
> Until the method is present the button will be disabled.  Try this -
>
> Add the following to a workspace, select it all and evaluate it.  You should
> see a shell with a single button, but the button is disabled as there is no
> method in the image with the selector #buttonPushed
>
> s := Shell show.
> s view addSubView: (p := PushButton new).
> p position: 100@100.
> p command: #buttonPressed.
> p text: 'Press Me'
>
> If you now add the following instance method to the Shell class and then
> re-evaluate the code above the button should now be enabled (because there
> now is a method available with the correct selector) and when it is pressed
> the message box should be displayed.
>
> buttonPressed
>     MessageBox notify: 'Pressed'
>
> Note
>  - I'm not suggesting you should normally add methods to Shell like this,
> using inheritance just makes the above example easier
>  - There are ways of enabling/disabling buttons dynamically, but that is
> probably better as lesson 2
>
> Ask again if you need help in translating the above to your own class.
>
> Regards
>     Ian



Thank you for that informations.
If it's not a problem, I am also intrested in translating to my own class.
Can you write me an example of "BClick" class, which is a window with one
button. When you click a button, text changes from "Click" to "Clicked".
Thanks.
Rok.