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

@ -44,6 +44,7 @@ from invokeai.frontend.install.widgets import (
CenteredButtonPress, CenteredButtonPress,
IntTitleSlider, IntTitleSlider,
set_min_terminal_size, set_min_terminal_size,
CyclingForm,
MIN_COLS, MIN_COLS,
MIN_LINES, MIN_LINES,
) )
@ -310,7 +311,7 @@ def get_root(root: str = None) -> str:
return str(config.root_path) return str(config.root_path)
# ------------------------------------- # -------------------------------------
class editOptsForm(npyscreen.FormMultiPage): class editOptsForm(CyclingForm, npyscreen.FormMultiPage):
# for responsive resizing - disabled # for responsive resizing - disabled
# FIX_MINIMUM_SIZE_WHEN_CREATED = False # FIX_MINIMUM_SIZE_WHEN_CREATED = False
@ -612,6 +613,7 @@ class EditOptApplication(npyscreen.NPSAppManaged):
"MAIN", "MAIN",
editOptsForm, editOptsForm,
name="InvokeAI Startup Options", name="InvokeAI Startup Options",
cycle_widgets=True,
) )
if not (self.program_opts.skip_sd_weights or self.program_opts.default_only): if not (self.program_opts.skip_sd_weights or self.program_opts.default_only):
self.model_select = self.addForm( self.model_select = self.addForm(

View File

@ -50,6 +50,7 @@ from invokeai.frontend.install.widgets import (
FileBox, FileBox,
set_min_terminal_size, set_min_terminal_size,
select_stable_diffusion_config_file, select_stable_diffusion_config_file,
CyclingForm,
MIN_COLS, MIN_COLS,
MIN_LINES, MIN_LINES,
) )
@ -68,7 +69,7 @@ def make_printable(s:str)->str:
'''Replace non-printable characters in a string''' '''Replace non-printable characters in a string'''
return s.translate(NOPRINT_TRANS_TABLE) return s.translate(NOPRINT_TRANS_TABLE)
class addModelsForm(npyscreen.FormMultiPage): class addModelsForm(CyclingForm, npyscreen.FormMultiPage):
# for responsive resizing - disabled # for responsive resizing - disabled
# FIX_MINIMUM_SIZE_WHEN_CREATED = False # 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): def set_min_terminal_size(min_cols: int, min_lines: int, launch_command: str=None):
# make sure there's enough room for the ui # make sure there's enough room for the ui
term_cols, term_lines = get_terminal_size() term_cols, term_lines = get_terminal_size()
if term_cols >= min_cols and term_lines >= min_lines:
return
cols = max(term_cols, min_cols) cols = max(term_cols, min_cols)
lines = max(term_lines, min_lines) lines = max(term_lines, min_lines)
set_terminal_size(cols, lines, launch_command) set_terminal_size(cols, lines, launch_command)
class IntSlider(npyscreen.Slider): class IntSlider(npyscreen.Slider):
def translate_value(self): def translate_value(self):
stri = "%2d / %2d" % (self.value, self.out_of) stri = "%2d / %2d" % (self.value, self.out_of)
@ -81,6 +82,22 @@ class IntSlider(npyscreen.Slider):
stri = stri.rjust(l) stri = stri.rjust(l)
return stri 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): class CenteredTitleText(npyscreen.TitleText):