Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>After a lot of digging, the answer turned out to be somewhat obscure. </p> <ul> <li><code>background-color</code> does not work. I had to use <code>background</code></li> <li>I also had to use <code>-unico-inner-stroke-width</code></li> </ul> <p>I ended up at a GTK3 CSS file for the Ubuntu theme itself to see what was happening, located here:</p> <pre><code>/usr/share/themes/Ambiance/gtk-3.0/gtk-widgets.css </code></pre> <p>I got the <code>-unico-inner-stroke-width</code> property from the CSS file above. I cannot determine why <code>background-color</code> in my script is being ignored, but it is, at least on Ubuntu 12.04. </p> <p>I was also forced to 're-set' the background and border colors of the elements I was changing as they would otherwise appear strange. This is the minimum CSS I had to use</p> <pre><code> GtkMenuItem { border:@bg_color; background:@bg_color; } GtkMenuItem:hover { background:@selected_bg_color; } GtkWidget { border: @bg_color; } #mymenu:hover { color:@fg_color; background: @bg_color; -unico-inner-stroke-width: 0; } </code></pre> <p>In this example, I am setting the hover color of a single GtkMenuItem to be the same as the background color, but if you want to set the color to something else, you'd have to change the <code>background</code> property as per your needs.</p> <p>Result, a working MenuItem without a hover color</p> <p><img src="https://i.stack.imgur.com/aJ3ZA.png" alt="enter image description here"></p> <p>Here is the full Python code:</p> <pre><code>from gi.repository import Gtk, Gdk import sys class TrayIcon: def __init__(self): self.statusicon = Gtk.StatusIcon() self.statusicon.set_from_stock(Gtk.STOCK_MEDIA_PLAY) self.statusicon.connect("popup-menu", self.OnShowPopupMenu) self.statusicon.set_tooltip_text("HELLO") window = Gtk.Window() def OnShowPopupMenu(self, icon, button, time): display = Gdk.Display.get_default() screen = display.get_default_screen() css_provider = Gtk.CssProvider() gtk3Css = """GtkMenuItem { border:@bg_color; background:@bg_color; } GtkMenuItem:hover { background:@selected_bg_color; } GtkWidget { border: @bg_color; } #mymenu:hover { color:@fg_color; background: @bg_color; -unico-inner-stroke-width: 0; }""" css_provider.load_from_data(gtk3Css) context = Gtk.StyleContext() context.add_provider_for_screen(screen, css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION) menu = Gtk.Menu() #menu.set_name('mymenu') first = self.GetMenuItem("First") first.set_name('mymenu') second = self.GetMenuItem("Second") menu.append(first) menu.append(second) menu.show_all() menu.popup(None, None, lambda w,x: self.statusicon.position_menu(menu, self.statusicon), self.statusicon, 3, time) def GetMenuItem(self, txt): menuItem = Gtk.MenuItem() menuItem.set_label(txt) menuItem.connect("button_press_event", self.exit) return menuItem def exit(self, a,b): sys.exit() TrayIcon() Gtk.main() </code></pre> <p>If you wanted to set another background color, you could do this in the CSS above</p> <pre><code> GtkMenuItem:hover { background:purple; -unico-inner-stroke-width: 0; } </code></pre> <p>(or do it in #mymenu:hover)</p> <p><img src="https://i.stack.imgur.com/b2cH9.png" alt="enter image description here"></p> <p>In conclusion, I think this may have been a problem limited to Ubuntu 12.04 or GTK 3.4.2 which I determined by running, </p> <pre><code>pkg-config --modversion gtk+-3.0 </code></pre> <p>But I do not have the expertise to determine the origin of this problem.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload