Tobi
Tobi

Reputation: 1313

Python GTK 3 Table: Buttons should not expand

Using following code, I have the problems, that the buttons "Log Leeren" and "Auto Scroll" change their height, when I resize the window. They should be exactly one text-line high and the rest of the viewport should be used by the scrolledWindow

What do I need to change:

class ConsoleLogWindow(Gtk.Window):
    def __init__(self, server):
        self.log = server["log"];
        Gtk.Window.__init__(self, title="Meteor Log von %s" % server["name"])

        # self.set_icon_from_file("filename")

        self.set_size_request(800,500)

        table = Gtk.Table(3, 2, False)

        self.add(table)

        # Should be only one line of thext high
        self.button_clear = Gtk.Button(label="Log Leeren")
        self.button_scroll = Gtk.Button(label="Auto Scroll")

        table.attach(self.button_clear, 2, 3, 1, 2)
        table.attach(self.button_scroll, 0, 1, 1, 2)

        # should take as much space as is available.
        scrollWindow = Gtk.ScrolledWindow()
        scrollWindow.set_hexpand(False)
        scrollWindow.set_vexpand(True)

        self.content_table = Gtk.Table(len(self.log)+1, 4, False)
        # self.content_table is filled here.

        scrollWindow.add(self.content_table)

        table.attach(scrollWindow, 0, 3, 0, 1)

the window class is called in a function like:

def show_errors_menu(self, widget):
    print ("Showing Error Menu")
    win = ConsoleLogWindow(widget.get_node());
    win.connect("delete-event", Gtk.main_quit)
    win.show_all()
    Gtk.main()

Upvotes: 2

Views: 1505

Answers (2)

ptomato
ptomato

Reputation: 57850

Don't use Gtk.Table; it does not always respect the expand and align properties of its child widgets. Its replacement since GTK 3.0 has been Gtk.Grid. Using that, you only have to make sure that expand is set to true on the scrolled window and false on the buttons.

Upvotes: 3

SonicARG
SonicARG

Reputation: 517

In the Qt side, at least, the frameworks consider for every widget a size attribute, a minimumSize attribute and a maximumSize attribute. Setting these three attributes to the same value for height and width makes them unresizable. Java's widgets have a explicit resizable attribute. I don't know how GTK3 prevents resizing, but doing some web search I came across this recipe which makes unresizable windows by extending and adding self.set_resizable(False) which is said to work. Give it a try and let me know!

Upvotes: 0

Related Questions