-
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?
Conversation
| self.init_gui(uri) | ||
|
|
||
| # Window properties | ||
| self.setFixedWidth(400) |
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.
| 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}") | ||
|
|
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 user prefs are used for more than just this widget or even hab-gui. The top level pref name
geometryis too vague. Also I think we should assume that there will be other prefs required in the future, so we should put all of this widgets preferences under a container dictionary. Something like"alias_launcher": {"geometry": [641, 376, 286, 234]}. Then other plugins or future features can add to its dictionary. - There is a simpler hab_gui interface for working with user_prefs that currently is only used in one place. We might as well make this use the new simpler interface that takes care of the boilerplate code you had to replicate.
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 prefs.filename logging messages as I would have to resolve the prefs object just to log it. If we decide we actually want that verbosity of logging we should probably put it into Settings, or the hab package itself.
|
With this remembering geometry positions, it should have the safety feature to prevent it being restored off-screen if the monitor geometry changes. You can copy the code from PrEditor. |


Checklist
Types of Changes
Proposed Changes
Allow adjusting width of window, and saving / restoring window geometry.
If Windows text scale is not 100%, ui may be too small


This change allows user to adjust size, and keep that adjustment