Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

wxPython wx.Frame Get/Set Position doesn't work under Wayland?

$
0
0

I have a wxPython application that remembers its windows positions and sizes by writing them down into a configuration file upon closing, and restoring them from the config file upon launch. Worked without a problem on Windows for many years. Recently I had to use that on Linux. I've tried on the following two configurations:

#1 MX Linux KDEPython 3.11.2wx.__version__'4.2.0'KDE Plasma 5.27.5Kernel 6.1.0-17-amd64X11#2 Fedora 40 KDEPython 3.12.3wx.__version__4.2.1KDE Plasma 6.0.5Kernel 6.8.10-300.fc40.x86_64Wayland

On MX Linux it worked more or less the same as on Windows. On Fedora, however, I could only get or set the width and height of the window, but not its top left corner position: GetPosition() and GetScreenPosition() always return (0, 0), GetRect() always return (0, 0, width, height). SetPosition() or SetRect() have no visible effect regarding the window position, although SetRect() sets the width and height correctly. What gives? Some applications on Fedora 40 seem to be able to remember and restore their position (Skype, for example), so it's probably not a system limitation. But how do I do that for my own wxPython application?

Here's the minimal example to reproduce the behavior I'm talking about. I've also noticed that EVT_MOVE message is not handled on Fedora, which may be related to the issue (not included into this example).

#!/usr/bin/env python3import wxclass MainWindow(wx.Frame):    def __init__(self, parent, window_id, title):               wx.Frame.__init__(self, parent, window_id, title)        self.Bind(wx.EVT_CLOSE, self.OnClose)               self.Show(True)    def ReadSettings(self):        rect = [0, 0, 100, 100]        try:            with open("settings.txt", "r") as f:                rect = [int(s) for s in f.read().split(",")]        except:            pass        self.SetSize(*rect)    def WriteSettings(self):        with open("settings.txt", "w") as f:            f.write(",".join((str(s) for s in self.GetRect())))    def OnClose(self, evt):        self.WriteSettings()        self.Destroy()app = wx.App(0)frame = MainWindow(None, -1, "Test")frame.ReadSettings()frame.Show(1)app.MainLoop()

Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>