Hi all,
My application so far consists of a single window with a Gtk Paned in it. I am trying to follow the developer guide to use gsettings
to restore the window state. My problem is that I can’t get the paned position right when the window starts in a maximized state: so far, I have all the initial setup in __init__
, but I guess maximization happens after I set the pane’s position, so if the window starts maximized, only the left pane is visible. What is the correct approach here? The current code is (I am using python, gtk3):
from gi.repository import Gtk, Gio, Gdk
from .editor import TexwriterEditor
from .pdfviewer import TexwriterPdfviewer
@Gtk.Template(resource_path='/com/github/molnarandris/TeXWriter/window.ui')
class TexwriterWindow(Gtk.ApplicationWindow):
__gtype_name__ = 'TexwriterWindow'
paned = Gtk.Template.Child()
editor = Gtk.Template.Child()
viewer = Gtk.Template.Child()
def __init__(self, **kwargs):
super().__init__(**kwargs)
settings = Gio.Settings.new("com.github.molnarandris.TeXWriter")
self.current_width = settings.get_int("window-width")
self.current_height = settings.get_int("window-height")
self.current_maximized = settings.get_boolean("window-maximized")
self.current_fullscreen = settings.get_boolean("window-fullscreen")
self.paned_position = settings.get_int("paned-position")
self.set_default_size(self.current_width, self.current_height)
if self.current_maximized:
self.maximize()
if self.current_fullscreen:
self.fullscreen()
self.paned.set_position(self.paned_position) # Where should this go?
self.connect("size-allocate", self.on_size_allocate)
self.connect("window-state-event", self.on_window_state_event)
self.connect("destroy", self.on_destroy)
self.paned.connect("size-allocate", self.on_paned_resize)
def on_size_allocate(self, widget, allocation):
if not (self.current_maximized or self.current_fullscreen):
self.current_width, self.current_height = widget.get_size()
def on_window_state_event(self, widget, event):
is_maximized = bool(event.new_window_state & Gdk.WindowState.MAXIMIZED)
is_fullscreen = bool(event.new_window_state & Gdk.WindowState.FULLSCREEN)
if self.current_maximized and not is_maximized:
self.set_default_size(self.current_width, self.current_height)
self.current_maximized = is_maximized
self.current_fullscreen = is_fullscreen
return False
def on_paned_resize(self,widget,allocation):
self.paned_position = self.paned.get_position()
def on_destroy(self,widget):
settings = Gio.Settings.new("com.github.molnarandris.TeXWriter")
settings.set_int("window-width", self.current_width)
settings.set_int("window-height", self.current_height)
settings.set_boolean("window-maximized", self.current_maximized)
settings.set_boolean("window-fullscreen", self.current_fullscreen)
settings.set_int("paned-position", self.paned_position)
Thanks,
Andras