zlee
zlee

Reputation: 1

PyGTK: Is there a method to calculate the best size for a window?

Most of my GUI programming was done in Java, where you could use a .pack() method that would set the preferred size the window should have. I'm learning PyGTK now and wondering if such a thing exists in it.

Upvotes: 0

Views: 310

Answers (2)

pmoleri
pmoleri

Reputation: 4451

You don't need a pack method. if you don't set a size, the window will adjust to its minimum size. You can use window.set_size_request(-1,-1) to unset any previous size.

Upvotes: 1

detly
detly

Reputation: 30332

Unfortunately... not that I know of. I use the following trick that uses a variety of GTK and GDK methods to work out the screen size of the current monitor at app startup and resizes the root window to have a certain proportion of fill.

Note that root is a GtkWindow. You could, of course, have two values for SCREEN_FILL for horizontal and vertical fill.

SCREEN_FILL = 0.7

class MainApp(object):

    def set_initial_size(self):        
        screen = self.root.get_screen()
        monitor = screen.get_monitor_at_window(self.root.get_window())
        geom = screen.get_monitor_geometry(monitor)
        self.root.set_resize_mode(gtk.RESIZE_QUEUE)
        self.root.resize(
                         int(geom.width * SCREEN_FILL),
                         int(geom.height * SCREEN_FILL))

Upvotes: 0

Related Questions