Skip to content

Commit 7beada5

Browse files
committed
Encode/decode window state into/from base64
1 parent 59872d0 commit 7beada5

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

cdl/core/gui/main.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from __future__ import annotations
1313

1414
import abc
15+
import base64
1516
import functools
1617
import os
1718
import os.path as osp
@@ -621,6 +622,7 @@ def __restore_state(self) -> None:
621622
"""Restore main window state from configuration"""
622623
state = Conf.main.window_state.get(None)
623624
if state is not None:
625+
state = base64.b64decode(state)
624626
self.restoreState(QC.QByteArray(state))
625627
for widget in self.children():
626628
if isinstance(widget, QW.QDockWidget):
@@ -635,7 +637,10 @@ def __save_pos_size_and_state(self) -> None:
635637
Conf.main.window_size.set((size.width(), size.height()))
636638
pos = self.pos()
637639
Conf.main.window_position.set((pos.x(), pos.y()))
638-
Conf.main.window_state.set(self.saveState().data())
640+
# Encoding window state into base64 string to avoid sending binary data
641+
# to the configuration file:
642+
state = base64.b64encode(self.saveState().data()).decode("ascii")
643+
Conf.main.window_state.set(state)
639644

640645
def setup(self, console: bool = False) -> None:
641646
"""Setup main window

0 commit comments

Comments
 (0)