Форум сайта python.su
Код должен добавлять объекты на вкладки gtk.Notebook “по клику мыши”. Добавляет только на первую вкладку. Подскажите, где не прав?
#coding:utf8
import gtk, gtk.glade
tabs=[gtk.EventBox()]
labels=[]
buttons=[]
efields=[]
fTabs=gtk.Notebook()
toplace="null"
def press_event(widget,event,key):
global toplace
if key=="tab":
tabs.append(gtk.EventBox())
tabs[-1].add(gtk.Fixed())
tabs[-1].show()
tabs[-1].connect("button_press_event",press_event,"on_fTabs")
tabs[-1].set_events(gtk.gdk.BUTTON_PRESS_MASK)
tabs[-1].set_visible_window(False)
fTabs.append_page(tabs[-1],tab_label=gtk.Label(u"Вкладка%s"%(len(tabs))))
if key=="label":
toplace="label"
if key=="button":
toplace="button"
if key=="efield":
toplace="efield"
if key=="on_fTabs": #здесь происходит добавление объектов
if toplace=="label":
labels.append(gtk.Label(u"Метка%s"%(len(labels))))
event_box=gtk.EventBox()
event_box.add(labels[-1])
event_box.connect("button_press_event",press_event,"elabel")
event_box.set_events(gtk.gdk.BUTTON_PRESS_MASK)
curFixed=fTabs.get_nth_page(fTabs.get_current_page()).get_child()
curFixed.put(event_box,int(event.x),int(event.y))
event_box.show()
labels[-1].show()
toplace="null"
if toplace=="button":
buttons.append(gtk.Button(u"Кнопка%s"%(len(buttons))))
curFixed=fTabs.get_nth_page(fTabs.get_current_page()).get_child()
curFixed.put(buttons[-1],int(event.x),int(event.y))
buttons[-1].connect("button_press_event",press_event,"ebutton")
buttons[-1].show()
toplace="null"
if toplace=="efield":
efields.append(gtk.Entry())
efields[-1].set_max_length(25)
efields[-1].set_text("Поле ввода%s"%(len(efields)))
efields[-1].connect("button_press_event",press_event,"eefield")
curFixed=fTabs.get_nth_page(fTabs.get_current_page()).get_child()
curFixed.put(efields[-1],int(event.x),int(event.y))
efields[-1].show()
toplace="null"
def editor_buttons(main):
efieldBtn=main.get_widget("efieldBtn")
buttonBtn=main.get_widget("buttonBtn")
labelBtn=main.get_widget("labelBtn")
tabBtn=main.get_widget("tabBtn")
efieldBtn.connect("button_press_event",press_event,"efield")
buttonBtn.connect("button_press_event",press_event,"button")
labelBtn.connect("button_press_event",press_event,"label")
tabBtn.connect("button_press_event",press_event,"tab")
def cons(main):
tabs[0].connect("button_press_event",press_event,"on_fTabs")
tabs[0].set_events(gtk.gdk.BUTTON_PRESS_MASK)
tabs[0].add(gtk.Fixed())
tabs[0].set_visible_window(False)
mFrame=main.get_widget("viewport1")
tabs[0].show()
fTabs.append_page(tabs[0], tab_label=gtk.Label(u"Главная"))
mFrame.add(fTabs)
editor_buttons(main)
Офлайн