[pygtk] gtk.Notebook

johnthawk at excite.com johnthawk at excite.com
Mon Jan 7 10:47:55 WST 2008


In gtk notebook page_num(child) being a widget
Returns :	the index of the page containing child, or -1

So here is the problem:

Added button to tab for close so I need the page the button is on since the
button grabs focus rather than the tab. I tried emit back to parent and that 
failed to produce anything.

The code segements:

Creation:
   #--------------------------------------------------------------------------
   def new_page(self, arg, filename):
      self.z = self.z + 1
      # create  scroller, gtksourceview, buffer and set mime
      scroller = gtk.ScrolledWindow()
      scroller.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
      bufferS = gtksourceview.SourceBuffer()
      manager = gtksourceview.SourceLanguagesManager()
      if arg:
         type = gnomevfs.get_mime_type(arg)
         language = manager.get_language_from_mime_type(type)
      else:
         language = manager.get_language_from_mime_type('text')
      bufferS.set_language(language)
      view = gtksourceview.SourceView(bufferS)
      scroller.add(view)
      # set defaults for gtksourceview and buffer
      bufferS.set_highlight(self.HIGHLIGHT)
      bufferS.set_check_brackets(self.CHECK_BRACKETS)
      view.set_show_line_numbers(self.SHOW_LINE_NUMBERS)
      view.set_show_margin(self.SHOW_MARGIN)
      view.set_auto_indent(self.AUTO_INDENT)
      view.set_tabs_width(int(self.TABS_WIDTH))
      view.set_insert_spaces_instead_of_tabs(self.INSERT_SPACES_INSTEAD_OF_TABS)
      view.set_margin(int(self.MARGIN))
      # add close button
      image = gtk.Image()
      image.set_from_file("data/images/close.png")
      btn = gtk.Button()
      btn.add(image)
      btn.connect('clicked',self.on_close_btn)
      #btn.set_size_request(16,16)
      # add label
      hbox = gtk.HBox(False,3)
      if not arg:
         self.key[self.z] = gtk.Label(filename)
      else:
         self.key[self.z] = gtk.Label(filename.rsplit('/',1)[1])
      hbox.add(self.key[self.z])
      hbox.add(btn)
      hbox.show_all()
      # load and set text
      if arg:
         try:
            bufferS.begin_not_undoable_action()
            f = open(arg, 'r')
            bufferS.set_text(f.read())
            f.close()
            bufferS.end_not_undoable_action()  
         except:
            print 'File Error: '+arg
      else:
         bufferS.set_text('')
      # populate tree
      iter = None
      iter = self.mod.append(iter)
      if arg:
         self.mod.set(iter,0, arg)
      else:
         self.mod.set(iter,0, filename)
      self.mod.set(iter,1, self.key[self.z].get_text())
      self.mod.set(iter,2, view)
      self.mod.set(iter,3, bufferS)
      self.mod.set(iter,4, self.key[self.z])
      self.view = view
      self.bufferS = bufferS
      # add page
      page = self.mdi_book.append_page(scroller,hbox)
      self.mdi_book.show_all()
      # switch to page
      self.mdi_book.set_current_page(page)
 
 Callbacks:
    #--------------------------------------------------------------------------
   def on_close_btn(self, widget):
      p = self.mdi_book.page_num(widget)
      self.on_update_tree('delete')
      self.mdi_book.remove_page(p)   
   #--------------------------------------------------------------------------
   def on_close(self, widget):
      p = self.mdi_book.get_current_page()
      self.on_update_tree('delete')
      self.mdi_book.remove_page(p)   

 




_______________________________________________
Join Excite! - http://www.excite.com
The most personalized portal on the Web!




More information about the pygtk mailing list