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 a711a4f
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 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,19 @@ def __init__(self, parent, env, **kwargs):
self.connect("apply", self.__save)
self.btn_remove.connect("clicked", self.__remove)

row_wg = self.get_child().get_first_child().get_next_sibling()
child_wg = row_wg.get_first_child() if row_wg else None
while isinstance(child_wg, Gtk.Label):
child_wg.set_visible(False)
child_wg = child_wg.get_next_sibling()

if isinstance(child_wg, Gtk.Text):
child_wg.set_valign(Gtk.Align.CENTER)
else:
logging.error(
"EnvVarEntry 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 a711a4f

Please sign in to comment.