SHARE
TWEET

Untitled

a guest Jun 16th, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python
  2.  
  3. import gi
  4. gi.require_version('Gtk', '3.0')
  5. from gi.repository import Gtk
  6.  
  7. class GUI:
  8.     def __init__(self):
  9.  
  10.         self.window = Gtk.Window()
  11.         self.window.set_size_request(400, 400)
  12.         notebook = Gtk.Notebook()
  13.         self.window.add(notebook)
  14.         notebook.connect('create-window', self.notebook_create_window)
  15.         notebook.set_group_name('0') # very important for DND
  16.         for i in range (4):
  17.             label = Gtk.Label('label in page number ' + str(i))
  18.             tab_label = Gtk.Label('page ' + str(i))
  19.             notebook.append_page(label, tab_label)
  20.             notebook.set_tab_detachable(label, True)
  21.         self.window.show_all()
  22.         self.window.connect('destroy', Gtk.main_quit)
  23.  
  24.     def notebook_create_window (self, notebook, widget, x, y):
  25.         # handler for dropping outside of current window
  26.         window = Gtk.Window()
  27.         new_notebook = Gtk.Notebook()
  28.         window.add(new_notebook)
  29.         new_notebook.set_group_name('0') # very important for DND
  30.         new_notebook.connect('page-removed', self.notebook_page_removed, window)
  31.         window.connect('destroy', self.sub_window_destroyed, new_notebook, notebook)
  32.         window.set_transient_for(self.window)
  33.         window.set_destroy_with_parent(True)
  34.         window.set_size_request(400, 400)
  35.         window.move(x, y)
  36.         window.show_all()
  37.         return new_notebook
  38.  
  39.     def notebook_page_removed (self, notebook, child, page, window):
  40.         #destroy the sub window after the notebook is empty
  41.         if notebook.get_n_pages() == 0:
  42.             window.destroy()
  43.  
  44.     def sub_window_destroyed (self, window, cur_notebook, dest_notebook):
  45.         # if the sub window gets destroyed, push pages back to the main window
  46.         # detach the notebook pages in reverse sequence to avoid index errors
  47.         for page_num in reversed(range(cur_notebook.get_n_pages())):
  48.             widget = cur_notebook.get_nth_page(page_num)
  49.             tab_label = cur_notebook.get_tab_label(widget)
  50.             cur_notebook.detach_tab(widget)
  51.             dest_notebook.append_page(widget, tab_label)
  52.             dest_notebook.set_tab_detachable(widget, True)
  53.  
  54. app = GUI()
  55. Gtk.main()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top