Skip to content

Conversation

@macevhicz
Copy link
Contributor

@macevhicz macevhicz commented Oct 15, 2025

Checklist

  • I have read the CONTRIBUTING.md document
  • I formatted my changes with black
  • I linted my changes with flake8
  • I have added documentation regarding my changes where necessary
  • Any pre-existing tests continue to pass
  • Additional tests were made covering my changes

Types of Changes

  • Bugfix (change that fixes an issue)
  • New Feature (change that adds functionality)
  • Documentation Update (if none of the other choices apply)

Proposed Changes

Allow adjusting width of window, and saving / restoring window geometry.

If Windows text scale is not 100%, ui may be too small
2025-10-15_11h06_58
This change allows user to adjust size, and keep that adjustment
2025-10-15_12h03_14

self.init_gui(uri)

# Window properties
self.setFixedWidth(400)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image image

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 of self.setFixedWidth(400)?

Comment on lines +232 to +266
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}")

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. The user prefs are used for more than just this widget or even hab-gui. The top level pref name geometry is 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.
  2. 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.

@MHendricks MHendricks changed the title Markm/prefs geometry Adjustable launcher width with prefs Oct 16, 2025
@MHendricks
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants