Skip to content

Commit

Permalink
feat: gtk记住窗口大小
Browse files Browse the repository at this point in the history
  • Loading branch information
yuhldr committed Dec 9, 2024
1 parent 28becd0 commit 7190e39
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
8 changes: 8 additions & 0 deletions data/gtk/cool.ldr.lfy.in.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@
<default>3</default>
<description>The currently selected translation language</description>
</key>
<key type="i" name="window-width">
<default>500</default>
<description>Translation windows width</description>
</key>
<key type="i" name="window-height">
<default>400</default>
<description>Translation windows height</description>
</key>
<key type="s" name="server-sk-baidu">
<default>""</default>
<description>Baidu app_id and secret_key, used in the middle | split</description>
Expand Down
15 changes: 12 additions & 3 deletions lfy/gtk/translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,18 @@ class TranslateWindow(Adw.ApplicationWindow):
gp_translate: Gtk.Paned = Gtk.Template.Child()
header_bar: Adw.HeaderBar = Gtk.Template.Child()

def __init__(self, **kwargs):
super().__init__(**kwargs)
def __init__(self, application):

self.app = self.get_application()
self.app = application

self.sg = Settings()

super().__init__(
application=application,
default_height=self.sg.g("window-width"),
default_width=self.sg.g("window-height")
)

# 翻译的key
self.lang_t = None

Expand Down Expand Up @@ -101,6 +106,10 @@ def save_settings(self, _a):
Args:
_a (TranslateWindow): _description_
"""
if not self.is_maximized():
size = self.get_default_size()
self.sg.s("window-width", size.width)
self.sg.s("window-height", size.height)

self.sg.s("server-selected-key", self.tra_server.key)
self.sg.s("lang-selected-n", self.lang_t.n)
Expand Down

0 comments on commit 7190e39

Please sign in to comment.