Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

In PyGI (GTK3), how can I make a GtkEntry widget appear against the same background applied (by the user's theme) to the primary toolbar. I tried adding the same style class like this:

entry.get_style_context().add_class(Gtk.STYLE_CLASS_PRIMARY_TOOLBAR)

but that class doesn't seem to be observed on a widget that isn't a GtkToolbar. So how can I cue the user's theme to apply the same styles behind a GtkEntry widget?

(If it matters, I have the GtkEntry in the first cell of a GtkHBox container. But even when I apply a fixed gradient to that HBox the whole cell holding the GtkEntry seems to mask out the background of the HBox with a flat background colour.)

Thanks.

share|improve this question
    
You would need to add the class to the style context of the container of the entry, and not the entry itself. –  dobey Aug 9 '12 at 21:27
    
Yes, but unfortunately the class doesn't do anything on non-toolbar widgets (e.g., an HBox or VBox). –  monotasker Aug 12 '12 at 19:35
add comment

2 Answers

up vote 1 down vote accepted

It is called primary-toolbar style because it should be applied only to primary toolbar.

In Gtk, toolbars by default can hold only ToolButtons, but there is the ToolItem class, which does not have a visual represntation.

That is created because it can embed other widgets. ToolItem has add method which you can use like :

my_tool_item.add(my_box) where my_box contains your entry

Then you can add your tool item to toolbar my_toolbar.insert(my_tool_item,index)

Your toolbar of course has called : get_style_context().add_class(Gtk.STYLE_CLASS_PRIMARY_TOOLBAR)

The reason why you cannot use "primary-toolbar" with non Toolbar widgets is most probably because in .css files it is defined like :

GtkToolbar.primary-toolbar 

{

    /* style info*/

}
share|improve this answer
    
Thanks @Aleksandar. I didn't realize that I would embed other widgets (aside from buttons) in a toolbar like this. It's kind of hidden in glade (which I'm using for ui design), but I finally realized that when I edit the widget hierarchy in glade for a GtkToolbar I can add a new item of the type "custom." That "custom" item type is the generic GtkToolItem. Then I was able to add my GtkEntry widget normally with glade's interface. –  monotasker Aug 10 '12 at 23:06
    
No problem. I am glad to help. –  Aleksandar Aug 11 '12 at 7:07
add comment

You did not say, why you can't use a toolbar, so I will suggest exactly that:

replace the HBox by a toolbar, give that toolbar the Gtk.STYLE_CLASS_PRIMARY_TOOLBAR style and you should be done...

share|improve this answer
    
Thanks for the suggestion, xubuntix. The trick was that I didn't know how to embed a GtkEntry widget in a toolbar. I've figured that out now, so I was able to use a toolbar after all. –  monotasker Aug 10 '12 at 23:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.