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