3

I'd like to be able to dynamically change the background color a notebook page in ruby-gnome2 after the program has run. I've only found ONE way of setting the background color:

# Some page contents, for the sake of example
box1 = Gtk::HBox.new(false, 2)
box1.pack_start(Gtk::Label.new("Page 1"))
box2 = Gtk::HBox.new(false, 2)
box2.pack_start(Gtk::Label.new("Page 2"))

notebook = Gtk::Notebook.new      # Create a notebook object
notebook.append_page(box1)        # Create a page with box1 as contents
notebook.append_page(box2)        # Create a page with box2 as contents
style = notebook.style            # Copy the currently applied style
style.set_bg(Gtk::STATE_NORMAL, bg.red, bg.green, bg.blue) # Update the bg color
notebook.style = style            # Set notebook's style to the updated object

This is fine if it's applied before Gtk.main is kicked off. But it has no effect after the window has already launched. I've tried combinations of modify_bg and modify_base on both the notebook object and the page contents, to no effect.

Is there a proper way to set the color of a notebook page that isn't so hackish, and can be applied after the main loop is run?

KChaloux
  • 3,918
  • 6
  • 37
  • 52

1 Answers1

2

Your question is from 5 years ago but I'll give you an example of how I did it with the newest version of the Ruby-GNOME2 bindings. If not to you, maybe it could still come handy to someone else:

color = Gdk::Color.parse("#003366")

button1.signal_connect("clicked") {
   textview1.override_background_color(Gtk::StateFlags::NORMAL, Gdk::RGBA.new(color.red, color.green, color.blue))
}

Gtk.main

The button is able to change the textview widget color afterwards the main Gtk loop has started, if that's what you meant. Of course it should also work with a notebook widget.

I have to say I just started using Ruby-GNOME2 bindings and I am not sure this is the currently recommended way of modifying the UI appearance, but it works.

Redoman
  • 3,059
  • 3
  • 34
  • 62