Skip to content

Instantly share code, notes, and snippets.

@achadwick
Last active May 19, 2016 11:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save achadwick/1b3505beb47d65fedfd6 to your computer and use it in GitHub Desktop.
Save achadwick/1b3505beb47d65fedfd6 to your computer and use it in GitHub Desktop.
GtkNotebook minimal code, for debugging
#!python
# Tester for reorderable tabs. Sure are a lot of GTK regressions here.
# Script is good for either Python2 or Python3.
#
# Copyright waived: http://creativecommons.org/publicdomain/zero/1.0/
# Andrew Chadwick, 2016-05-19.
#
# GTK 3.20.4 terminates the drag as soon as the pointer goes outside the
# notebook whose tab is being dragged. Reordering of tabs within a
# notebook is still possible. https://github.com/mypaint/mypaint/issues/682
#
# GTK 3.16.3 dumps core when trying to drag a tab into an empty
# notebook. The following is seen when you try:
# Gtk:ERROR:[...]/gtk/gtknotebook.c:3832:gtk_notebook_drag_motion: \
# assertion failed: (priv->cur_page != NULL)
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
def _main():
# Window with a grid of notebooks
win = Gtk.Window()
win.set_title("test notebook drag")
grid = Gtk.Grid()
# Pack a populated notebook
nb = Gtk.Notebook()
nb.set_group_name("test1")
nb.set_size_request(40, 40)
nb.set_hexpand(True)
nb.set_vexpand(True)
for i in range(3):
s = (
"Tab %d\n\n"
"Try dragging me to the\n"
"empty notebook below."
) % (i,)
w = Gtk.Label(s)
w.set_size_request(200, 200)
nb.append_page(w, Gtk.Label("t%d" % (i,)))
nb.set_tab_reorderable(w, True)
nb.set_tab_detachable(w, True)
grid.attach(nb, 0, 1, 1, 1)
# Pack an empty notebook too
nb = Gtk.Notebook()
nb.set_group_name("test1")
nb.set_size_request(40, 40)
nb.set_hexpand(True)
nb.set_vexpand(True)
grid.attach(nb, 0, 2, 1, 1)
# Run it...
win.add(grid)
win.connect("destroy", Gtk.main_quit)
win.show_all()
Gtk.main()
if __name__ == "__main__":
_main()
@achadwick
Copy link
Author

Related MyPaint bug: mypaint/mypaint#322

@achadwick
Copy link
Author

@achadwick
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment