Ruby GTK modify widget colors

Hello,

I want to modify the widget colors in GTK3. I only found an example with GTK2.

With GTK3 it doesn't work.

Has someone a solution?

Regards

UH

require 'gtk2'

window= Gtk::Window.new
window.set_size_request(300,200)

button= Gtk::Button.new('Button')
button.set_size_request(100,-1)

font= Pango::FontDescription.new('28')
button.child.modify_font(font)

yellow= Gdk::Color.new(65535,65535,0)
cyan= Gdk::Color.new(0,65535,65535)
green= Gdk::Color.new(0,65535,0)
magenta= Gdk::Color.new(65535,0,65535)
white= Gdk::Color.new(65535,65535,65535)
blue= Gdk::Color.new(0,0,65535)

# background color of the button
button.modify_bg(Gtk::STATE_NORMAL , yellow)
button.modify_bg(Gtk::STATE_PRELIGHT, cyan)
button.modify_bg(Gtk::STATE_ACTIVE , green)

# label color of the button
button.child.modify_fg(Gtk::STATE_NORMAL , magenta)
button.child.modify_fg(Gtk::STATE_PRELIGHT, blue)
button.child.modify_fg(Gtk::STATE_ACTIVE , white)

fixed= Gtk::Fixed.new
fixed.put(button,10,10)
window.add(fixed)

window.show_all
window.signal_connect("destroy") {Gtk.main_quit }
Gtk.main

Hi,

In <f339fabb-6ed1-6830-ffe0-01599a65a85e@unitybox.de>
  "Ruby GTK modify widget colors" on Thu, 10 Jan 2019 23:38:55 +0100,

I want to modify the widget colors in GTK3. I only found an example
with GTK2.

With GTK3 it doesn't work.

Has someone a solution?

You can use CSS in GTK+ 3:

require "gtk3"

application = Gtk::Application.new
application.signal_connect(:activate) do
  provider = Gtk::CssProvider.new
  provider.load(data: <<-CSS)
button {
  background-image: none;
  background-color: yellow;
}

label {
  font-size: 28px;
  color: magenta;
}

button:hover {
  background-color: cyan;
}

button:hover label {
  color: blue;
}

button:active {
  background-color: green;
}

button:active label {
  color: white;
}
  CSS
  Gtk::StyleContext.add_provider_for_screen(Gdk::Screen.default,
                                            provider,
                                            Gtk::StyleProvider::PRIORITY_APPLICATION)

  window = Gtk::ApplicationWindow.new(application)
  window.set_size_request(300, 200)

  button = Gtk::Button.new(label: "Button")
  button.set_size_request(100, -1)

  fixed = Gtk::Fixed.new
  fixed.put(button, 10, 10)

  window << fixed
  window.show_all
end
application.run

···

ulli bei Unity <upahermann@unitybox.de> wrote:

Hi,

(You should send your e-mail to ruby-talk@ instead of me.)

It works on my Debian GNU/Linux sid machine.
And I also confirmed with fresh install Linux Mint 19.1
Cinnamon edition.

Newly created GTK+ 3 applications should use Gtk::Application.
If you still have problem, please submit an issue to
Issues · ruby-gnome/ruby-gnome · GitHub with full
error message.

Thanks,

···

--
kou

In <97cc9e26-fd4a-1409-6425-a5693a9e0e7f@unitybox.de>
  "Re: Ruby GTK modify widget colors" on Sat, 12 Jan 2019 08:41:26 +0100,
  ulli bei Unity <upahermann@unitybox.de> wrote:

Hi,
this sample doesn't work under Linux.

Gtk::Application.new wants two parameter. Basically I have to say, I
only know the start of application with GTK.init and GTK.main. All
samples I find wit application.run doesn't work under Linux (Mint
19.1).
Regards
UH

Hi,

yes it works on fresh installed mint 19.1. Convincing Method.

Thanks
Ulrich Hermann

···

Am 13.01.19 um 03:24 schrieb Kouhei Sutou:

Hi,

(You should send your e-mail to ruby-talk@ instead of me.)

It works on my Debian GNU/Linux sid machine.
And I also confirmed with fresh install Linux Mint 19.1
Cinnamon edition.

Newly created GTK+ 3 applications should use Gtk::Application.
If you still have problem, please submit an issue to
Issues · ruby-gnome/ruby-gnome · GitHub with full
error message.

Thanks,
--
kou

In <97cc9e26-fd4a-1409-6425-a5693a9e0e7f@unitybox.de>
   "Re: Ruby GTK modify widget colors" on Sat, 12 Jan 2019 08:41:26 +0100,
   ulli bei Unity <upahermann@unitybox.de> wrote:

Hi,
this sample doesn't work under Linux.

Gtk::Application.new wants two parameter. Basically I have to say, I
only know the start of application with GTK.init and GTK.main. All
samples I find wit application.run doesn't work under Linux (Mint
19.1).
Regards
UH

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;