Question

I need help in figuring how to rebuild an element of a gtk.stack.

Assuming that the child is a gtk.box containing information which it may have to be rebuilt in many ways, as the reconstruction should be done?

def refresh_take(self):
    self.take_container.destroy()
    #Reconstructed container
    self.take_container = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
    #Reconstructed Top label
    hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
    label = Gtk.Label("For take:", xalign=0)
    self.take_container.pack_start(label, False, False, 10)

    get_ready = self.database.get_tomas_ready()
    listbox = Gtk.ListBox()
    listbox.set_selection_mode(Gtk.SelectionMode.NONE)
    #Reconstructed First list
    counter = 0
    for list_element in get_ready[0]:
        self.create_med_dialog(list_element[0])
        row = Gtk.ListBoxRow()
        hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=50)
        row.add(hbox)
        vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        hbox.pack_start(vbox, True, True, 0)
        if list_element[4] in range(10):
            minutes = '0' + str(list_element[4])
        else:
            minutes = list_element[4]
        tempo = (str(get_ready[1][counter]) + ":" + str(minutes) + "H")

        Pill = Gtk.Label(tempo + "\t" + list_element[0] , xalign=0)
        vbox.pack_start(Pill, True, True, 0)
        if counter == 0:
            button = Gtk.Button(label="Take")
            self.demanded_pill = list_element[0]
            button.connect("clicked", self.demand_pill)
            hbox.pack_start(button, False, True, 0)

        listbox.add(row)

        self.take_container.pack_start(listbox, False, False, 0)
        counter = counter + 1

    #The second label is reconstructed
    hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
    info_label = Gtk.Label("Next Pill:", xalign=0)
    self.take_container.pack_start(info_label, False, False, 10)

    get_next = self.database.get_tomas_next()
    listbox = Gtk.ListBox()
    listbox.set_selection_mode(Gtk.SelectionMode.NONE)
    #The second list is reconstructed
    counter = 0
    for list_element in get_next[0]:
        row = Gtk.ListBoxRow()
        hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=50)
        row.add(hbox)
        vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        hbox.pack_start(vbox, True, True, 0)

        if list_element[4] in range(10):
            minutes = '0' + str(list_element[4])
        else:
            minutes = list_element[4]
        Pill = Gtk.Label(list_element[0], xalign=0)
        vbox.pack_start(Pill, True, True, 0)
        label = Gtk.Label(str(get_next[1][counter])
        + ":" + str(minutes) + "H")
        hbox.pack_start(label, False, True, 0)
        listbox.add(row)
        counter = counter + 1

    self.take_container.pack_start(listbox, False, False, 0)
    self.take_container.set_visible(True)
    self.stack.add_named(self.take_container, "Takes")

When my stack refreshes, all disappear, but I want that they create the labels again, after destroy.

Was it helpful?

Solution

From the code snippet, it looks like you are not adding the widgets you create into any containers. Unless you do that somewhere else listbox and self.take_container are created but never added to any containers.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top