Skip to content

Commit

Permalink
envvars-dialog: Center text entry vertically
Browse files Browse the repository at this point in the history
Traverse AdwEntryRow's widget tree to remove visibility of the title labels and change alignment of the text entry to center.

This implementation is tightly coupled with the internal representation of AdwEntryRow. Checks were added to prevent crashing if that representation changes, but in such case the layout may get askew.
  • Loading branch information
jntesteves committed Jan 8, 2025
1 parent 8bba5d0 commit 704fc2b
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions bottles/frontend/windows/envvars.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@

from gi.repository import Gtk, GLib, Adw

from bottles.backend.logger import Logger
from bottles.frontend.utils.gtk import GtkUtils
from bottles.frontend.utils.sh import ShUtils

logging = Logger()


@Gtk.Template(resource_path="/com/usebottles/bottles/env-var-entry.ui")
class EnvVarEntry(Adw.EntryRow):
Expand All @@ -44,6 +47,21 @@ def __init__(self, parent, env, **kwargs):
self.connect("apply", self.__save)
self.btn_remove.connect("clicked", self.__remove)

try:
widget = self.get_child().get_first_child().get_next_sibling().get_first_child()
while isinstance(widget, Gtk.Label):
widget.set_visible(False)
widget = widget.get_next_sibling()

if isinstance(widget, Gtk.Text):
widget.set_valign(Gtk.Align.CENTER)
else:
raise RuntimeError("Could not find widget Gtk.Text")
except Exception as e:
logging.error(
f"{type(e)}: {e}\nEnvVarEntry could not find text widget. Did AdwEntryRow change it's widget tree?"
)

def __save(self, *_args):
"""
Change the env var value according to the
Expand Down

0 comments on commit 704fc2b

Please sign in to comment.