make widget selection wrap around

This commit is contained in:
Lincoln Stein
2023-06-06 13:53:11 -07:00
parent 294f086857
commit 1b43276e5d
3 changed files with 25 additions and 5 deletions

View File

@ -50,6 +50,7 @@ from invokeai.frontend.install.widgets import (
FileBox,
set_min_terminal_size,
select_stable_diffusion_config_file,
CyclingForm,
MIN_COLS,
MIN_LINES,
)
@ -68,7 +69,7 @@ def make_printable(s:str)->str:
'''Replace non-printable characters in a string'''
return s.translate(NOPRINT_TRANS_TABLE)
class addModelsForm(npyscreen.FormMultiPage):
class addModelsForm(CyclingForm, npyscreen.FormMultiPage):
# for responsive resizing - disabled
# FIX_MINIMUM_SIZE_WHEN_CREATED = False

View File

@ -69,11 +69,12 @@ def _set_terminal_size_unix(width: int, height: int):
def set_min_terminal_size(min_cols: int, min_lines: int, launch_command: str=None):
# make sure there's enough room for the ui
term_cols, term_lines = get_terminal_size()
if term_cols >= min_cols and term_lines >= min_lines:
return
cols = max(term_cols, min_cols)
lines = max(term_lines, min_lines)
set_terminal_size(cols, lines, launch_command)
class IntSlider(npyscreen.Slider):
def translate_value(self):
stri = "%2d / %2d" % (self.value, self.out_of)
@ -81,7 +82,23 @@ class IntSlider(npyscreen.Slider):
stri = stri.rjust(l)
return stri
# -------------------------------------
# fix npyscreen form so that cursor wraps both forward and backward
class CyclingForm(object):
def find_previous_editable(self, *args):
done = False
n = self.editw-1
while not done:
if self._widgets__[n].editable and not self._widgets__[n].hidden:
self.editw = n
done = True
n -= 1
if n<0:
if self.cycle_widgets:
n = len(self._widgets__)-1
else:
done = True
# -------------------------------------
class CenteredTitleText(npyscreen.TitleText):
def __init__(self, *args, **keywords):