Skip to content

Commit

Permalink
added option to remember last window size
Browse files Browse the repository at this point in the history
  • Loading branch information
jiri-one committed Nov 18, 2021
1 parent f44db5b commit dc463fa
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
1 change: 1 addition & 0 deletions easydict_gtk/easydict.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def __init__(self):

# settings objects
self.checkbutton_scan = gui("checkbutton_scan")
self.checkbutton_size = gui("checkbutton_size")
self.combobox_language = gui("combobox_language")

# connect signals from builder
Expand Down
8 changes: 6 additions & 2 deletions easydict_gtk/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ def onTrashPress(self, *args):
self.entry_search.set_text("")

def onWindowSizeChange(self, widget, event):
window_width, window_height = self.window.get_size()
self.write_setting("window_size", [window_width, window_height])
if self.checkbutton_size.get_active():
window_width, window_height = self.window.get_size()
self.write_setting("window_size", [window_width, window_height])

# handlers for dialogs
def onAboutClicked(self, *args):
Expand All @@ -87,6 +88,9 @@ def onSettingsClicked(self, *args):
# settings handlers
def onCheckbuttonScanToggled(self, check_button):
self.write_setting("clipboard_scan", check_button.get_active())

def onCheckbuttonSizeToggled(self, check_button):
self.write_setting("win_size_remember", check_button.get_active())

def onComboboxLanguageChanged(self, combo):
self.write_setting("search_language", combo.get_active_id())
Expand Down
11 changes: 8 additions & 3 deletions easydict_gtk/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@ def initiate_settings(self):
# get setting of clippboard scan from db and set it
pref_clipboard_scan = prefdb.search(query["settings"] == "clipboard_scan")[0]["value"]
self.checkbutton_scan.props.active = pref_clipboard_scan
# get setting of window size remembering from db and set it
pref_win_size_remember = prefdb.search(query["settings"] == "win_size_remember")[0]["value"]
self.checkbutton_size.props.active = pref_win_size_remember
# get the window size from db and set it
window_width, window_height = prefdb.search(query["settings"] == "window_size")[0]["value"]
self.window.set_default_size(window_width, window_height)
# get setting of search language from db and set it
pref_search_language = prefdb.search(query["settings"] == "search_language")[0]["value"]
self.image_language.props.file = str(self.cwd_images / f"flag_{pref_search_language}.svg")
self.language = pref_search_language
self.combobox_language.set_active_id(pref_search_language)
window_width, window_height = prefdb.search(query["settings"] == "window_size")[0]["value"]
self.window.set_default_size(window_width, window_height)
except IndexError:
self.create_default_settings()
# set the version from poetry pyproject.toml file
Expand All @@ -43,10 +47,11 @@ def write_setting(self, name, value):
prefdb.update({'value': value}, where("settings") == name)

def create_default_settings(self):
# default language settings and turn the clipboard scanning on
# set default settings
prefdb.upsert({'settings': 'search_language', 'value': "eng"}, query["settings"] == "search_language")
prefdb.upsert({'settings': 'clipboard_scan', 'value': True}, query["settings"] == "clipboard_scan")
prefdb.upsert({'settings': 'window_size', 'value': [360,640]}, query["settings"] == "window_size")
prefdb.upsert({'settings': 'win_size_remember', 'value': True}, query["settings"] == "win_size_remember")
# after default values are set, call initiate_settings again
self.initiate_settings()

Expand Down
18 changes: 17 additions & 1 deletion easydict_gtk/ui/easydict.glade
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,23 @@
</packing>
</child>
<child>
<placeholder/>
<object class="GtkCheckButton" id="checkbutton_size">
<property name="label" translatable="yes">Remember last main window size</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">False</property>
<property name="tooltip-text" translatable="yes">If is enabled, EasyDict will remember last window size</property>
<property name="halign">start</property>
<property name="image-position">right</property>
<property name="draw-indicator">True</property>
<signal name="toggled" handler="onCheckbuttonSizeToggled" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="padding">7</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkBox">
Expand Down

0 comments on commit dc463fa

Please sign in to comment.