-
Notifications
You must be signed in to change notification settings - Fork 2
Adjustable launcher width with prefs #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,10 +49,6 @@ def __init__( | |
| self.process_entry_points() | ||
| self.init_gui(uri) | ||
|
|
||
| # Window properties | ||
| self.setFixedWidth(400) | ||
| self.center_window_position() | ||
|
|
||
| # Create a auto-refresh timer by default that forces a refresh of hab. | ||
| # This can be disabled by setting the site config setting to an empty string. | ||
| self.refresh_timer = QtCore.QTimer(self) | ||
|
|
@@ -104,6 +100,11 @@ def apply_layout(self): | |
| else: | ||
| self.setTabOrder(self.uri_widget, self.pinned_uris) | ||
|
|
||
| def closeEvent(self, event): # noqa: N802 | ||
| """Saves the prefs on close if prefs are enabled.""" | ||
| self.record_prefs() | ||
| super().closeEvent(event) | ||
|
|
||
| def process_entry_points(self): | ||
| """Loads the classes defined by the site entry_point system. | ||
| These are later initialized by init_gui to create the UI. | ||
|
|
@@ -192,6 +193,12 @@ def init_gui(self, uri=None): | |
| # Ensure the window title always shows the currently selected URI | ||
| self.settings.uri_changed.connect(self._update_window_title) | ||
|
|
||
| # Window properties | ||
| self.center_window_position() | ||
|
|
||
| # Restore prefs | ||
| self.restore_prefs() | ||
|
|
||
| @utils.cursor_override() | ||
| def refresh_cache(self, reset_timer=True): | ||
| """Refresh the resolved hab and re-display. | ||
|
|
@@ -222,6 +229,41 @@ def center_window_position(self): | |
| qt_rectangle.moveCenter(center_point) | ||
| self.move(qt_rectangle.topLeft()) | ||
|
|
||
| def restore_prefs(self): | ||
| """Restore various saved prefs. It will only do that if prefs are | ||
| enabled. This will call load to ensure the preference file has been | ||
| loaded. | ||
| """ | ||
| prefs = self.settings.resolver.user_prefs() | ||
| if not prefs.enabled: | ||
| return | ||
| # Ensure the preferences are loaded. | ||
| prefs.load() | ||
|
|
||
| # Restore previous geometry | ||
| geom = prefs.get("geometry", None) | ||
| if geom: | ||
| self.setGeometry(*geom) | ||
|
|
||
| logger.debug(f"Prefs restored {prefs.filename}") | ||
|
|
||
| def record_prefs(self): | ||
| """Save various prefs. It will only do that if prefs are enabled. This | ||
| will call load to ensure the preference file has been loaded. | ||
| """ | ||
| prefs = self.settings.resolver.user_prefs() | ||
| if not prefs.enabled: | ||
| return | ||
| # Ensure the preferences are loaded. | ||
| prefs.load() | ||
|
|
||
| # Save window geometry | ||
| prefs["geometry"] = self.geometry().getRect() | ||
|
|
||
| # Save the prefs | ||
| prefs.save() | ||
| logger.debug(f"Prefs saved {prefs.filename}") | ||
|
|
||
|
Comment on lines
+232
to
+266
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This code addresses both of these notes. def restore_prefs(self):
"""Restore various saved prefs. It will only do that if prefs are
enabled. This will call load to ensure the preference file has been
loaded.
"""
prefs = self.settings.user_pref("alias_launcher", {})
# Restore previous geometry
geom = prefs.get("geometry", None)
if geom:
self.setGeometry(*geom)
def record_prefs(self):
"""Save various prefs. It will only do that if prefs are enabled. This
will call load to ensure the preference file has been loaded.
"""
# Use the namespace alias_launcher to store this and any future UI prefs.
prefs = self.settings.user_pref("alias_launcher", {})
# Save window geometry
prefs["geometry"] = self.geometry().getRect()
self.settings.set_user_pref("alias_launcher", prefs)This code no longer needs to get the prefs so I removed the |
||
|
|
||
| def main(): | ||
| app = QtWidgets.QApplication([]) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default minimum size is a bit small even if there are aliases to show. Should we keep the 400 but use
self.setMinimumWidth(400)instead ofself.setFixedWidth(400)?