Use Qt saveGeometry and restoreGeometry
This commit is contained in:
parent
c9e4f2417d
commit
234d171483
@ -25,6 +25,7 @@ import subprocess
|
|||||||
import configparser
|
import configparser
|
||||||
from signal import signal, SIGINT
|
from signal import signal, SIGINT
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
|
from base64 import b64encode
|
||||||
|
|
||||||
# Print a nice traceback on segfault -- only available on Python 3.3+, but if
|
# Print a nice traceback on segfault -- only available on Python 3.3+, but if
|
||||||
# it's unavailable, it doesn't matter much.
|
# it's unavailable, it doesn't matter much.
|
||||||
@ -342,15 +343,12 @@ class QuteBrowser(QApplication):
|
|||||||
|
|
||||||
def _save_geometry(self):
|
def _save_geometry(self):
|
||||||
"""Save the window geometry to the state config."""
|
"""Save the window geometry to the state config."""
|
||||||
rect = self.mainwindow.geometry()
|
geom = b64encode(bytes(self.mainwindow.saveGeometry())).decode('ASCII')
|
||||||
try:
|
try:
|
||||||
config.state.add_section('mainwindow')
|
config.state.add_section('geometry')
|
||||||
except configparser.DuplicateSectionError:
|
except configparser.DuplicateSectionError:
|
||||||
pass
|
pass
|
||||||
config.state['mainwindow']['x'] = str(rect.x())
|
config.state['geometry']['mainwindow'] = geom
|
||||||
config.state['mainwindow']['y'] = str(rect.y())
|
|
||||||
config.state['mainwindow']['w'] = str(rect.width())
|
|
||||||
config.state['mainwindow']['h'] = str(rect.height())
|
|
||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def _on_tab_shutdown_complete(self):
|
def _on_tab_shutdown_complete(self):
|
||||||
|
@ -17,6 +17,9 @@
|
|||||||
|
|
||||||
"""The main window of QuteBrowser."""
|
"""The main window of QuteBrowser."""
|
||||||
|
|
||||||
|
import binascii
|
||||||
|
from base64 import b64decode
|
||||||
|
|
||||||
from PyQt5.QtCore import QRect
|
from PyQt5.QtCore import QRect
|
||||||
from PyQt5.QtWidgets import QWidget, QVBoxLayout
|
from PyQt5.QtWidgets import QWidget, QVBoxLayout
|
||||||
|
|
||||||
@ -43,19 +46,17 @@ class MainWindow(QWidget):
|
|||||||
|
|
||||||
self.setWindowTitle('qutebrowser')
|
self.setWindowTitle('qutebrowser')
|
||||||
try:
|
try:
|
||||||
x = int(config.state['mainwindow']['x'])
|
geom = b64decode(config.state['geometry']['mainwindow'],
|
||||||
y = int(config.state['mainwindow']['y'])
|
validate=True)
|
||||||
w = int(config.state['mainwindow']['w'])
|
except binascii.Error:
|
||||||
h = int(config.state['mainwindow']['h'])
|
self._set_default_geometry()
|
||||||
except KeyError:
|
|
||||||
rect = QRect()
|
|
||||||
else:
|
else:
|
||||||
rect = QRect(x, y, w, h)
|
try:
|
||||||
if not rect.isValid():
|
ok = self.restoreGeometry(geom)
|
||||||
rect = QRect(50, 50, 800, 600)
|
except KeyError:
|
||||||
# FIXME there is no setFrameGeometry, but this seems to do the wrong
|
self._set_default_geometry()
|
||||||
# thing.
|
if not ok:
|
||||||
self.setGeometry(rect)
|
self._set_default_geometry()
|
||||||
|
|
||||||
self.vbox = QVBoxLayout(self)
|
self.vbox = QVBoxLayout(self)
|
||||||
self.vbox.setContentsMargins(0, 0, 0, 0)
|
self.vbox.setContentsMargins(0, 0, 0, 0)
|
||||||
@ -93,3 +94,7 @@ class MainWindow(QWidget):
|
|||||||
#self.retranslateUi(MainWindow)
|
#self.retranslateUi(MainWindow)
|
||||||
#self.tabWidget.setCurrentIndex(0)
|
#self.tabWidget.setCurrentIndex(0)
|
||||||
#QtCore.QMetaObject.connectSlotsByName(MainWindow)
|
#QtCore.QMetaObject.connectSlotsByName(MainWindow)
|
||||||
|
|
||||||
|
def _set_default_geometry(self):
|
||||||
|
"""Set some sensible default geometry."""
|
||||||
|
self.setGeometry(QRect(50, 50, 800, 600))
|
||||||
|
Loading…
Reference in New Issue
Block a user