update
Ich habe mir jetzt auch den table Container aus dem Code zusammengepflückt. Wozu ich dann Glade brauchen soll (ausser um die Namen der Boxen, Felder, etc rauszufinden), erschliesst sich mir immer weniger, schliesslich kann ich die gesamte Oberfläche auch in python coden...
Dieses Makro ist nicht verfügbar
Nun startet das Programm, Dropdown Menu hat bereits die gewünschten Einträge, wenn ich einen Button clicke wird das entsprechende signal geprinted und activate1 checkbox prüft ob sie aktiv ist oder nicht und gibt dann den jeweiligen status aus.
"Activate1" is on "Activate1" is off
Die Funktionen sind also da. Allerdings bekomme ich beim Starten folgende Fehlermeldung:
Gtk-CRITICAL **: gtk_table_attach: assertion 'gtk_widget_get_parent (child) == NULL' failed
Hat jemand eine Idee, wie ich das beheben kann?
Hier der Gesamtcode:
from gi.repository import Gtk, Gio class HeaderBarWindow(Gtk.Window): def __init__(self): Gtk.Window.__init__(self, title="Testprogramm1") self.set_border_width(10) self.set_default_size(500, 300) ## defines gtk header bar and what it includes hb = Gtk.HeaderBar() hb.props.show_close_button = True hb.props.title = "Testprogramm1" self.set_titlebar(hb) buttonback = Gtk.Button() buttonback.add(Gtk.Arrow(Gtk.ArrowType.LEFT, Gtk.ShadowType.NONE)) buttonback.add hb.pack_start(buttonback) buttonforward = Gtk.Button() buttonforward.add(Gtk.Arrow(Gtk.ArrowType.RIGHT, Gtk.ShadowType.NONE)) buttonforward.add hb.pack_start(buttonforward) button = Gtk.Button() icon = Gio.ThemedIcon(name="mail-send-receive-symbolic") image = Gtk.Image.new_from_gicon(icon, Gtk.IconSize.BUTTON) button.add(image) hb.pack_end(button) #Gtk.ComboBox.__init__(self, title="combobox1") table = Gtk.Table(3, 3, True) self.add(table) button1 = Gtk.Button(label="Firefox") button1.connect("clicked", self.on_firefox_clicked) button2 = Gtk.Button(label="App2") button2.connect("clicked", self.on_app2_clicked) button3 = Gtk.Button(label="App3") button3.connect("clicked", self.on_app3_clicked) #button4 = Gtk.Button(label="Button 4") #button5 = Gtk.Button(label="Button 5") label1 = Gtk.Label("Chose Kernel I/O Scheduler") combobox1 = Gtk.ComboBox() ### ### creates the list entries ### name_store = Gtk.ListStore(int, str) name_store.append([1, "noop"]) name_store.append([2, "deadline"]) name_store.append([3, "cfq"]) ### creates the box place vbox1 = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) name_combo = Gtk.ComboBox.new_with_model_and_entry(name_store) name_combo.set_entry_text_column(1) vbox1.pack_start(name_combo, False, False, 0) checkbutton1 = Gtk.CheckButton(label="Activate1") checkbutton1.connect("toggled", self.on_activate1_toggled) vbox1.pack_start(checkbutton1, True, True, 0) ### shows you where the buttons, boxes and list stores are placed in the table layout table.attach(button1, 0, 1, 0, 1) table.attach(button2, 1, 3, 0, 1) table.attach(button3, 0, 1, 1, 3) table.attach(label1, 1, 2, 3, 4) table.attach(vbox1, 1, 2, 2, 3) table.attach(checkbutton1, 2, 3, 2, 3) ### defines the function and prints output def on_firefox_clicked(self, button): print("\"Firefox\" button was clicked") def on_app2_clicked(self, button): print("\"App2\" button was clicked") def on_app3_clicked(self, button): print("\"App3\" button was clicked") def on_activate1_toggled(self, checkbutton1): self.activate1 = checkbutton1.get_active() if self.activate1: print("\"Activate1\" is on") else: print("\"Activate1\" is off") win = HeaderBarWindow() win.connect("delete-event", Gtk.main_quit) win.show_all() Gtk.main()
Was ich noch überhaupt nicht durchschaut habe, trotz über 1 Stunde herumprobieren, ist das Table-Layout...
So wie ich das sehe, habe ich eine 3x3 Tabelle, aber was machen: z.B.
table.attach(button1, 0, 1, 0, 1) table.attach(button2, 1, 3, 0, 1) table.attach(button3, 0, 1, 1, 3)
jetzt genau?
Ändere ich 3x3 in 5x5 und probiere mit den EInträgen herum, verreisst es mir das ganze Layout (buttons liegen übereinander, etc..)
Allerdings: der Lernfaktor ist schon auf jeden Fall da, und Spaß macht das ganze auch langsam. 😬