Make the tab for the laptop tied so that its position cannot be changed

I have a GtkNotebook that will contain at least one persistent tab called Search. The widget on this page allows you to create more pages, and on these pages there is a tab containing a close button.

How to make tabs reorderable, but also keep tab β€œSearch” in position 0? The current behavior of gtk.Notebook.set_tab_reorderable () is that it allows you to physically drag a tab to reorder it ... it does not stop this tab from having to reorder when a relabeled tab passes it.

Example:

This first image is the default position:

enter image description here

This image is the result of dragging row # 6 (where row # 6 is reordered, but Search is not): enter image description here

How do I keep Search from reordering with rewritable tabs?

+4
source share
1 answer

It seems to me that a possible solution would be to connect to the 'page-reordered' signal as follows:

 import gtk def on_reorder(notebook, child, number, user_data): if number == 0: notebook.reorder_child(user_data, 0) def main(): mainwin = gtk.Window() notebook = gtk.Notebook() mainwin.add(notebook) mainwin.set_default_size(200,200) for label in ['Search', 'Row#6', 'Row#9']: child = gtk.VBox() notebook.append_page(child, gtk.Label(label)) if label != 'Search': notebook.set_tab_reorderable(child, True) else: notebook.set_tab_reorderable(child, False) searchtab = notebook.get_nth_page(0) notebook.connect('page-reordered', on_reorder, searchtab) mainwin.show_all() mainwin.connect('destroy', gtk.main_quit) gtk.main() if __name__ == "__main__": main() 

Hope this helps.

+7
source

Source: https://habr.com/ru/post/1397513/


All Articles