Skip to content

Commit

Permalink
UI tweak to column select
Browse files Browse the repository at this point in the history
  • Loading branch information
Lincoln Stein authored and hipsterusername committed Aug 25, 2023
1 parent 3af7aeb commit 3d2a5b2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
9 changes: 5 additions & 4 deletions invokeai/backend/install/invokeai_configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
# TO DO - Move all the frontend code into invokeai.frontend.install
from invokeai.frontend.install.widgets import (
SingleSelectColumns,
SingleSelectColumnsSimple,
MultiSelectColumns,
CenteredButtonPress,
FileBox,
Expand Down Expand Up @@ -384,7 +385,7 @@ def create(self):
)
self.nextrely -= 2
self.precision = self.add_widget_intelligent(
SingleSelectColumns,
SingleSelectColumnsSimple,
columns=len(PRECISION_CHOICES),
name="Precision",
values=PRECISION_CHOICES,
Expand All @@ -405,7 +406,7 @@ def create(self):
)
self.nextrely -= 2
self.device = self.add_widget_intelligent(
SingleSelectColumns,
SingleSelectColumnsSimple,
columns=len(DEVICE_CHOICES),
values=DEVICE_CHOICES,
value=DEVICE_CHOICES.index(device),
Expand All @@ -425,7 +426,7 @@ def create(self):
)
self.nextrely -= 2
self.attention_type = self.add_widget_intelligent(
SingleSelectColumns,
SingleSelectColumnsSimple,
columns=len(ATTENTION_CHOICES),
values=ATTENTION_CHOICES,
value=ATTENTION_CHOICES.index(attention_type),
Expand All @@ -447,7 +448,7 @@ def create(self):
)
self.nextrely -= 2
self.attention_slice_size = self.add_widget_intelligent(
SingleSelectColumns,
SingleSelectColumnsSimple,
columns=len(ATTENTION_SLICE_CHOICES),
values=ATTENTION_SLICE_CHOICES,
value=ATTENTION_SLICE_CHOICES.index(attention_slice_size),
Expand Down
13 changes: 9 additions & 4 deletions invokeai/frontend/install/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ class FloatTitleSlider(npyscreen.TitleText):


class SelectColumnBase:
"""Base class for selection widget arranged in columns."""

def make_contained_widgets(self):
self._my_widgets = []
column_width = self.width // self.columns
Expand Down Expand Up @@ -253,14 +255,15 @@ def on_mouse_double_click(self, cursor_line):
class SingleSelectWithChanged(npyscreen.SelectOne):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.on_changed = None

def h_select(self, ch):
super().h_select(ch)
if self.on_changed:
self.on_changed(self.value)


class SingleSelectColumns(SelectColumnBase, SingleSelectWithChanged):
class SingleSelectColumnsSimple(SelectColumnBase, SingleSelectWithChanged):
def __init__(self, screen, columns: int = 1, values: list = [], **keywords):
self.columns = columns
self.value_cnt = len(values)
Expand All @@ -271,16 +274,18 @@ def __init__(self, screen, columns: int = 1, values: list = [], **keywords):
def when_value_edited(self):
self.h_select(self.cursor_line)

def when_cursor_moved(self):
self.h_select(self.cursor_line)

def h_cursor_line_right(self, ch):
self.h_exit_down("bye bye")

def h_cursor_line_left(self, ch):
self.h_exit_up("bye bye")


class SingleSelectColumns(SingleSelectColumnsSimple):
def when_cursor_moved(self):
self.h_select(self.cursor_line)


class TextBoxInner(npyscreen.MultiLineEdit):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand Down

0 comments on commit 3d2a5b2

Please sign in to comment.