4
votes

I am designing a python program using GTK3 and Glade. It requires changing the interface depending on what the user is needing to build.

The first interface is something like:

____________________________________________________
| Label one | Text entry one |  Save object button |
| Label two | Text entry two |                     |
____________________________________________________

which is in a top level window inside a Gtk.Box() set to vertical with a Gtk.Grid() as the labels and text entries in one side of the box and the save Save object button on the section of the box. (my interface in reality is much more complicated that this with many more labels, text entries, toggle buttons, comboboxes, etc within the table). If you want to see it, it is at http://sourceforge.net/projects/createlauncher.

If the user needs to build another object, it would look like:

________________________________________________________
| Label three | Text entry three |  Save object button |
| Label four  | Text entry four  |                     |
________________________________________________________

What are some suggestions on how to implement the change?

I've thought of keeping track of label one-two and entry one-two, and hiding them and showing the others but it messes with the formating. I have messed around with deleting each widget and rebuilding if needing to switch back. It is a lot of work. Since I'm using Glade, it is hard to create a separate "area" as I thought about deleting the Gtk.Box() and remaking it for the other interface needs, but that seems prohibitive using Glade.

I'm open to any and all options.

3

3 Answers

1
votes

Composite custom widgets?

class ObjectOneSettings(Gtk.Grid):
    def __init__(self):
        Gtk.Grid.__init__(self)
        self.label_one = Gtk.Label('Label One')
        self.label_two = Gtk.Label('Label Two')
        self.entry_one = Gtk.Entry()
        self.entry_two = Gtk.Entry()
        self.attach(self.label_one, 0, 0, 1, 1)
        self.attach(self.label_two, 0, 1, 1, 1)
        self.attach(self.entry_one, 1, 0, 1, 1)
        self.attach(self.entry_two, 1, 1, 1, 1)

Then you can destroy your ObjectOneSettings widget and replace it with an ObjectTwoSettings widget when you need to change the window.

1
votes

Perhaps a bit of a hack, but you could use a notebook with hidden tabs and border.

1
votes

If you use Glade, I can think of two approaches.

The first one is to change the label of the Gtk.Label and the Gtk.Entry dynamically in your python code depending on what you need.

The second one is to create a separate Gtk.Box in Glade that is not inside the main window and add it when you need it (first remove the other one from the window). This would look like this:

glade with separate box