开发者

get num-page of notebook

I have one notebook with some tabs in my form and in this tabs i have label-button for closing tab. I have code for this:

def new_tab(self,label): self.scrolled_window = gtk.ScrolledWindow()

  self.add(self.scrolled_window)
  self.scrolled_window.add_with_viewport(self.editor_access())

  self.scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)

  la开发者_如何学Gobel = self.create_tab_label(label,self.editor_access)

  self.set_tab_label_packing(self.scrolled_window,False,False,2)
  self.set_tab_label(self.scrolled_window,label)

  self.saving = False
  self.already_save.insert(0,self.get_n_pages() - 1) 

  label.show_all()
  self.show_all()
  return self.editor

def create_tab_label(self, title, tab_child): box = gtk.HBox() label = gtk.Label(title) closebtn = gtk.Button()

  image = gtk.Image()
  image.set_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_MENU)

  closebtn.set_image(image)
  closebtn.set_relief(gtk.RELIEF_NONE)

  box.pack_start(label, True, True)
  box.pack_end(closebtn, False, False)

  self.show_all()

  closebtn.connect("clicked",self.close_tab)

  return box 

How can i get page_num of tab which I closed with this button?

Thank you.


If your page widgets never change, you can just pass them to your close_tab callback as the user data:

# In create_tab_label
    closebtn.connect("clicked", self.close_tab, tab_child)

def close_tab(self, button, tab_child):
    # Do something with self.page_num(tab_child)

Update: The "page_num first argument must be gtk.Widget, not instacemethod" error you mentioned is because of this:

label = self.create_tab_label(label,self.editor_access)

It seems that you are passing a method as tab_widget. Note that you previously you ran editor_access to create the tab child widget:

self.scrolled_window.add_with_viewport(self.editor_access())

You need to store this widget so you can pass it as tab_widget, i.e.:

editor_access = self.editor_access()
self.scrolled_window.add_with_viewport(editor_access)

# ...

label = self.create_tab_label(label, editor_access)


# Do something with self.page_num(tab_child)

But page_num first argument must be gtk.Widget, not instacemethod

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜