[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

constrained gtk radio buttons

prubel

4/6/2005 7:19:00 PM

Hello,

I've been trying out gtk and gtk2 for the first time over the past few
days. Overall it has been a good experience. At the moment however,
I'm stumped and was hoping someone might be able to enlighten me.

At a hight level I have two sets of radio buttons and want to change
the selection of one set of buttons when a button in the other set is
clicked.

More specifically, the buttons represent a mouse. One side is button
(Left, Right, Center,...) and the other is type of click (single,
double, and drag). When L is selected any of the click
types should be available. However, if R is selected
and a user clicks on double I'd like to change from R to L as a
double right doesn't seem very useful.

On a click on double I'm able to call @left_button.set_state(true) and
this changes from R to L as I'd expect. However, when I do this double
doesn't get selected, single is still selected. The code below is my
attempt to get this working. If you start it and click on right and
then double you'll see what I described above.

One interesting thing I do notice is that the first click on double
prints out "clicked double" twice, which is odd. I suspect there is
something in the event dispatching that I'm missing. Is there a better
way to set the state of the button? Any help would be appreciated.

thank you,
Paul



require 'gtk'

class DwellWindow < Gtk::Window

def initialize()
super
@single_button = Gtk::RadioButton.new(nil, "Single")
@double_button = Gtk::RadioButton.new(@single_button,"Double")
@double_button.signal_connect("clicked") {@left_button.set_state(true);puts " clicked double"}

@left_button = Gtk::RadioButton.new(nil, "Left")
@right_button = Gtk::RadioButton.new(@left_button, "Right")
@right_button.signal_connect("clicked") {@single_button.set_state(true)}


type_box = Gtk::VBox.new
type_box.add(@single_button)
type_box.add(@double_button)

button_box = Gtk::VBox.new
button_box.add(@left_button)
button_box.add(@right_button)

top_box = Gtk::HBox.new
top_box.add(button_box)
top_box.add(type_box)

add(top_box)
show_all
end

end


dwell = DwellWindow.new
Gtk::main


2 Answers

Joao Pedrosa

4/6/2005 8:01:00 PM

0

Hi,

On Apr 6, 2005 4:18 PM, Paul Rubel <prubel@bbn.com> wrote:
> Hello,
>
> I've been trying out gtk and gtk2 for the first time over the past few
> days. Overall it has been a good experience. At the moment however,
> I'm stumped and was hoping someone might be able to enlighten me.

I've created a sample that works with Ruby-GNOME2. When a Radiobutton
is activated, it triggers the "clicked" event, even when the
activation is thru code, so I created a method to handle that. I've
never used GTK 1.x so I can't test your version. :-) Follows:

require 'gtk2'

class DwellWindow < Gtk::Window

def initialize()
super
@single_button = Gtk::RadioButton.new("Single")
@double_button = Gtk::RadioButton.new(@single_button,"Double")
@double_button.signal_connect("clicked") {activate_button(@left_button)}

@left_button = Gtk::RadioButton.new("Left")
@right_button = Gtk::RadioButton.new(@left_button, "Right")
@right_button.signal_connect("clicked") {activate_button(@single_button)}

type_box = Gtk::VBox.new
type_box.pack_start @single_button, true, true, 0
type_box.pack_start @double_button, true, true, 0

button_box = Gtk::VBox.new
button_box.pack_start @left_button, true, true, 0
button_box.pack_start @right_button, true, true, 0

top_box = Gtk::HBox.new
top_box.pack_start button_box, true, true, 0
top_box.pack_start type_box, true, true, 0

add(top_box)
show_all
end

def activate_button b
if not @activating
@activating = true
b.active = true
@activating = nil
end
end

end

Gtk.init
dwell = DwellWindow.new
dwell.show_all
Gtk::main

-------------

Cheers,
Joao


prubel

4/7/2005 1:32:00 PM

0

Joao Pedrosa writes:
> Hi,
>
> On Apr 6, 2005 4:18 PM, Paul Rubel <prubel@bbn.com> wrote:
> > Hello,
> >
> > I've been trying out gtk and gtk2 for the first time over the past few
> > days. Overall it has been a good experience. At the moment however,
> > I'm stumped and was hoping someone might be able to enlighten me.
>
> I've created a sample that works with Ruby-GNOME2. When a Radiobutton
> is activated, it triggers the "clicked" event, even when the
> activation is thru code, so I created a method to handle that. I've
> never used GTK 1.x so I can't test your version. :-) Follows:

Thanks for both of the responses. I appreciate your help. It looks
like using the toggled action combined with watching whether I'm in
the midst of dealing with a click, as you suggested, will do the job.

thanks again,
Paul