views:

286

answers:

3

Basically, what I want to do is put some buttons before the tabs in a gtk.Notebook. I tried making my own notebook type widget and it worked well, but it would have required lots more work to make it as flexible as I would like, also it wasn't as efficient.

Here is a mock-up of what I'm trying to achieve: http://imagebin.ca/view/84SC0d.html

Any ideas would be much appreciated, thanks.

Ben.

A: 

It's a hack, but you can put your widgets on a separate tab, and then prevent the tab from being clicked by registering the following switch-page event for the notebook:

def onTabsSwitchPage(self, notebook, page_notUsableInPython, pageNumber):
    # Don't allow to switch to the dummy tab containing widgets
    if pageNumber == <put correct tab number here>:
        notebook.stop_emission("switch-page")

Note that this doesn't look good with all GTK themes, but it works...

AndiDog
Thanks for the suggestion. I've already tried it and like you said it doesn't look the best... I think I'm either going to stick with my own widget and make it better, or try and make a widget that inherits for gtk.Notebook like ptomato suggested. Thanks anyway :)
Ben Ashton
A: 

I don't think there's any way to do it without making your own notebook widget. There are a couple of hacks. One was posted by AndiDog. Another is to hide the tabs altogether (notebook.set_show_tabs(False)) and make a toolbar with buttons above the widget, with your buttons on the left, plus one button for each tab in the notebook that switches to that page.

Instead of making your own notebook-type widget from scratch, you could inherit from gtk.Notebook, overriding some of the methods like expose_event, size_request, and size_allocate, in order to deal with two types of container children: pages and buttons. I don't know how to do this in PyGTK though, only in C.

You might also consider whether the buttons in the tab space are really what you want. What if the user resizes your notebook small enough that some of the tabs disappear? Where do the previous tab/next tab arrows go? What happens to the buttons?

ptomato
Thanks for the quick response, I've already tried the hack that Andi suggested and the problem arises when you have more tabs than will fit in the available space and then the buttons will disappear when you are on the end tabs.I was looking into inheriting from gtk.Notebook earlier but couldn't find much good documentation for PyGTK. I'll have another look tomorrow because this is definitely the best option.If I can't work out how to implement the second solution then I'll just go back to creating my own widget.Thanks for the suggestions :)
Ben Ashton
+2  A: 

You might be interested to know that this functionality has been added in GTK 2.20, see "Changes in GtkNotebook" in the following announcement: http://mail.gnome.org/archives/gtk-devel-list/2010-March/msg00132.html

ptomato