Keep CSS style while state change

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

Hi,

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

Thanks,

kou

In [email protected]
“[ruby-gnome2-devel-en] keep CSS style while state change” on Thu, 24
Oct 2013 18:22:06 +0200,

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}"
end
end

win = Win.new
Gtk.main

Am 27.10.2013 11:28, schrieb Kouhei S.:

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 Y.
GitHub: myokoym

2013/10/27 Detlef R. [email protected]:

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 Y.:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs