Skip to content
Snippets Groups Projects
Commit 6dfa5eb8 authored by Kasper Seweryn's avatar Kasper Seweryn :pancakes:
Browse files

Preserve window position and state when reloaded

parent 1fe5ac80
No related branches found
No related tags found
No related merge requests found
import sys import sys
import os import os
import inotify.adapters import inotify.adapters
from PySide6.QtCore import QThread, QObject, Signal, Slot from PySide6.QtCore import QThread, QObject, Signal, Slot
...@@ -12,23 +13,36 @@ main = os.path.join(os.path.dirname(__file__), 'qml', "main.qml") ...@@ -12,23 +13,36 @@ main = os.path.join(os.path.dirname(__file__), 'qml', "main.qml")
class Master(QObject): class Master(QObject):
command = Signal() command = Signal()
def __init__(self):
QObject.__init__(self)
@Slot() @Slot()
def reload(self): def reload(self):
print("Loading UI") print("Loading UI")
for window in engine.rootObjects(): windows = engine.rootObjects()
window.destroy() if len(windows) > 0:
pos = windows[-1].position()
width = windows[-1].width()
height = windows[-1].height()
state = windows[-1].windowState()
for window in windows:
window.close()
window.destroy()
engine.clearComponentCache()
engine.load(main)
engine.clearComponentCache() if not engine.rootObjects():
engine.load(main) sys.exit(-1)
if not engine.rootObjects(): # NOTE: Every load creates new rootObject
sys.exit(-1) window = engine.rootObjects()[-1]
window.setPosition(pos); window.setWindowState(state)
window.resize(width, height)
else:
engine.load(main)
# TODO: Move new window to old window position if not engine.rootObjects():
sys.exit(-1)
class Worker(QObject): class Worker(QObject):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment