Forum: Ruby-Gnome 2 keep CSS style while state change

4913bcb685792f601ae9813b4713abb9?d=identicon&s=25 Detlef Reichl (Guest)
on 2013-10-24 18:36
(Received via mailing list)
Hi,

I have some buttons with images, where I have changed the style with
CSS. When I now change the state of the button from sensitive to
insensitive, the image in the button get the default theme style. That
is obvious, cause this image is a newly created widget, that has not the
CSS style attached. How can I get around this? One way would be, to
create a special "insensitive"-image and change this every time the
button state changes on my own. But this is ugly, cause it would revoke
split from code to style. Has anyone a better idea?

Cheers, detlef
Ee6ffca720cc428d70247dcd7377dd48?d=identicon&s=25 Kouhei Sutou (Guest)
on 2013-10-27 11:29
(Received via mailing list)
Hi,

Could you show us a sample script that reproduces your
problem? If you show it, someone may help you. :-)

Thanks,
--
kou

In <5269492E.6040309@gmx.org>
  "[ruby-gnome2-devel-en] keep CSS style while state change" on Thu, 24
Oct 2013 18:22:06 +0200,
4913bcb685792f601ae9813b4713abb9?d=identicon&s=25 Detlef Reichl (Guest)
on 2013-10-27 14:46
(Received via mailing list)
Hi,

sure, here we go:

You can adjust the value from 0 to 4. If the limits are reached, the
button for this direction will get insensitive and "loses" it style

Cheers, detlef


#!/usr/bin/env ruby

require 'gtk3'


class Win < Gtk::Window
     def initialize
         super
         box = Gtk::Box.new :horizontal
         self.add box

         img = Gtk::Image.new :stock => Gtk::Stock::REMOVE, :size =>
:small_toolbar
         @downButton = Gtk::Button.new
         @downButton << img
         @downButton.signal_connect(:clicked){clicked :down}
         @downButton.set_name 'numeric_controll'

         @value = 1
         @label = Gtk::Label.new
         set_label

         img = Gtk::Image.new :stock => Gtk::Stock::ADD, :size =>
:small_toolbar
         @upButton   = Gtk::Button.new
         @upButton << img
         @upButton.signal_connect(:clicked){clicked :up}
         @upButton.set_name 'numeric_controll'

         box.pack_start @downButton
         box.pack_start @label
         box.pack_start @upButton

         provider = Gtk::CssProvider.new
         provider.load :data => '#numeric_controll {
             color: white;
             background-color: #223;
             border-style: solid;
             border-width: 2px;
             border-color: #2528a4;
         }'

         styleContext = Gtk::StyleContext.new
         styleContext.add_provider provider, GLib::MAXUINT

         apply_css(self, provider)
         show_all
     end


     def apply_css(widget, provider)
         widget.style_context.add_provider(provider, GLib::MAXUINT)
         if widget.is_a?(Gtk::Container)
             widget.each_forall do |child|
                 apply_css(child, provider)
             end
         end
     end

     def clicked dir
         if dir == :down
             if @value >= 0
                 @value -=1
                 @downButton.sensitive = @value > 0
                 @upButton.sensitive = true
             end
         else
             if @value <= 4
                 @value +=1
                 @upButton.sensitive = @value < 4
                 @downButton.sensitive = true
             end
         end
         set_label
     end


     def set_label
         text = @value.to_s
         @label.markup = "<span size=\"#{20 * 1024}\"
font_weight=\"bold\">#{text}</span>"
     end
end


win = Win.new
Gtk.main


Am 27.10.2013 11:28, schrieb Kouhei Sutou:
394f372e936f867e4e43bfd1315a0a4e?d=identicon&s=25 Masafumi Yokoyama (masafumi_y)
on 2013-10-28 04:08
(Received via mailing list)
Hello,

Please tell us your environment?
I want to see the results of the following commands:

    $ ruby -v

and

    $ ruby -r gtk3 -e "p Gtk::VERSION"


Regards,
--
Masafumi Yokoyama
GitHub: myokoym



2013/10/27 Detlef Reichl <detlef.reichl@gmx.org>:
4913bcb685792f601ae9813b4713abb9?d=identicon&s=25 Detlef Reichl (Guest)
on 2013-10-28 16:28
(Received via mailing list)
Hi,

ruby -v

ruby 1.9.3p448 (2013-06-27 revision 41675) [x86_64-linux]


ruby -r gtk3 -e "p Gtk::VERSION"

[3, 8, 4]


Cheers, detlef


Am 28.10.2013 04:07, schrieb Masafumi Yokoyama:
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.