2014-01-10 3 views
0

저는 pygtk를 처음 사용하는 사용자입니다. 탭 드래깅 기능을 추가하기 위해 gtk 문서의 일부 기존 코드를 수정했지만 드래그시 레이블이 다시 그려지지 않고 대신 흰색으로 표시됩니다. 어떻게 다시 그릴 수 있습니까?Gtk set_tab_reorderable 다시 그리기 레이블

#!/usr/bin/env python 

# example notebook.py 

import gtk 

class NotebookExample: 
    # This method rotates the position of the tabs 
    def rotate_book(self, button, notebook): 
     notebook.set_tab_pos((notebook.get_tab_pos()+1) %4) 

    # Add/Remove the page tabs and the borders 
    def tabsborder_book(self, button, notebook): 
     tval = gtk.FALSE 
     bval = gtk.FALSE 
     if self.show_tabs == gtk.FALSE: 
      tval = gtk.TRUE 
     if self.show_border == gtk.FALSE: 
      bval = gtk.TRUE 

     notebook.set_show_tabs(tval) 
     self.show_tabs = tval 
     notebook.set_show_border(bval) 
     self.show_border = bval 

    # Remove a page from the notebook 
    def remove_book(self, button, notebook): 
     page = notebook.get_current_page() 
     notebook.remove_page(page) 
     # Need to refresh the widget -- 
     # This forces the widget to redraw itself. 
     notebook.draw((0,0,-1,-1)) 

    def delete(self, widget, event=None): 
     gtk.mainquit() 
     return gtk.FALSE 

    def __init__(self): 
     window = gtk.Window(gtk.WINDOW_TOPLEVEL) 
     window.connect("delete_event", self.delete) 
     window.set_border_width(10) 

     table = gtk.Table(3,6,gtk.FALSE) 
     window.add(table) 

     # Create a new notebook, place the position of the tabs 
     notebook = gtk.Notebook() 
     notebook.set_tab_pos(gtk.POS_TOP) 
     table.attach(notebook, 0,6,0,1) 
     notebook.show() 
     self.show_tabs = gtk.TRUE 
     self.show_border = gtk.TRUE 

     # Let's append a bunch of pages to the notebook 
     for i in range(5): 
      bufferf = "Append Frame %d" % (i+1) 
      bufferl = "Page %d" % (i+1) 

      frame = gtk.Frame(bufferf) 
      frame.set_border_width(10) 
      frame.set_usize(100, 75) 
      frame.show() 

      label = gtk.Label(bufferf) 
      frame.add(label) 
      label.show() 

      label = gtk.Label(bufferl) 
      notebook.append_page(frame, label) 
      notebook.set_tab_reorderable(frame, True) 

     # Now let's add a page to a specific spot 
     checkbutton = gtk.CheckButton("Check me please!") 
     checkbutton.set_usize(100, 75) 
     checkbutton.show() 

     label = gtk.Label("Add page") 
     notebook.insert_page(checkbutton, label, 2) 

     # Now finally let's prepend pages to the notebook 
     for i in range(5): 
      bufferf = "Prepend Frame %d" % (i+1) 
      bufferl = "PPage %d" % (i+1) 

      frame = gtk.Frame(bufferf) 
      frame.set_border_width(10) 
      frame.set_usize(100, 75) 
      frame.show() 

      label = gtk.Label(bufferf) 
      frame.add(label) 
      label.show() 

      label = gtk.Label(bufferl) 
      notebook.prepend_page(frame, label) 

     # Set what page to start at (page 4) 
     notebook.set_page(3) 

     # Create a bunch of buttons 
     button = gtk.Button("close") 
     button.connect("clicked", self.delete) 
     table.attach(button, 0,1,1,2) 
     button.show() 

     button = gtk.Button("next page") 
     button.connect("clicked", notebook.next_page) 
     table.attach(button, 1,2,1,2) 
     button.show() 

     button = gtk.Button("prev page") 
     button.connect("clicked", notebook.prev_page) 
     table.attach(button, 2,3,1,2) 
     button.show() 

     button = gtk.Button("tab position") 
     button.connect("clicked", self.rotate_book, notebook) 
     table.attach(button, 3,4,1,2) 
     button.show() 

     button = gtk.Button("tabs/border on/off") 
     button.connect("clicked", self.tabsborder_book, notebook) 
     table.attach(button, 4,5,1,2) 
     button.show() 

     button = gtk.Button("remove page") 
     button.connect("clicked", self.remove_book, notebook) 
     table.attach(button, 5,6,1,2) 
     button.show() 

     table.show() 
     window.show() 

def main(): 
    gtk.mainloop() 
    return 0 

if __name__ == "__main__": 
    NotebookExample() 
    main() 
+0

원본 코드에 대한 링크를 추가해 주시겠습니까? 그것은 당신이 만든 수정에만 집중하는 데 도움이됩니다. – liberforce

+0

내가 추가 한 행은'notebook.set_tab_reorderable (frame, True)'입니다. 이것을 재현 할 수 있습니까? – simonzack

+0

사용중인 GTK 버전을 알려주세요. – liberforce

답변

1

샘플은 약간의 버그가있는 "페이지 x"를 이동, 그렇지 않으면 (다음 및 이전 버튼 콜백에게 주어진 많은 인자에 있기 때문에 나를 위해 작동하지 않습니다)하지만, (아니 "PPage입니다 x ") 페이지가 예상대로 작동합니다. GNU/Linux (Mageia 3)에서 GTK 2.24.17을 사용하고 있습니다.

+0

저는 아치에 GTK 2.24.22를 사용하고 있습니다 만, 이후 pygobject로 gtk 3으로 전환했는데 문제가 사라진 것 같습니다. 아마도 gtk 버그 일 겁니다. 코드를 테스트 해 주셔서 감사합니다. – simonzack