Skip to content

Commit

Permalink
Do not allow disabled forms to be focused
Browse files Browse the repository at this point in the history
  • Loading branch information
joouha committed Nov 7, 2023
1 parent ed2b396 commit 11263f5
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Added
Fixed
=====

- Prevent disabled forms being focused
- Prevent rare error when closing a tab
- Prevent error dialog collapsing at small terminal sizes
- Correct error in escape code for querying terminal dimensions
Expand Down
25 changes: 16 additions & 9 deletions euporie/core/widgets/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def __init__(
FormattedTextControl(
self.get_text_fragments,
key_bindings=self.key_bindings,
focusable=True,
focusable=~self.disabled,
show_cursor=False,
style="class:face",
),
Expand Down Expand Up @@ -464,7 +464,7 @@ def __init__(
FormattedTextControl(
self._get_text_fragments,
key_bindings=self._get_key_bindings(),
focusable=True,
focusable=~self.disabled,
show_cursor=False,
),
style=lambda: f"class:checkbox {style}"
Expand Down Expand Up @@ -586,8 +586,8 @@ def __init__(
multiline=multiline,
height=Dimension(min=min_height, max=height, preferred=height),
width=width,
focusable=True,
focus_on_click=True,
focusable=~self.disabled,
focus_on_click=~self.disabled,
read_only=self.disabled,
style=f"{style} class:text,text-area",
validator=Validator.from_callable(validation) if validation else None,
Expand Down Expand Up @@ -1305,7 +1305,7 @@ def load_container(self) -> AnyContainer:
window := Window(
FormattedTextControl(
self.text_fragments,
focusable=True,
focusable=~self.disabled,
show_cursor=False,
key_bindings=self.key_bindings(),
),
Expand Down Expand Up @@ -1379,7 +1379,7 @@ def __init__(
Shadow(
Window(
FormattedTextControl(
self.menu_fragments,
self.menu_fragments, focusable=self.disabled
),
style=f"class:dropdown,dropdown.menu {self.style}",
)
Expand Down Expand Up @@ -1689,6 +1689,7 @@ def __init__(
track_char: str | None = None,
selected_track_char: str | None = None,
style: str = "class:input",
disabled: FilterOrBool = False,
) -> None:
"""Create a new slider control instance.
Expand All @@ -1701,13 +1702,17 @@ def __init__(
selected_track_char: The character to use for the selected section of the
slider track
style: A style string to apply to the slider
disabled: A filter which when evaluated to :py:const:`True` causes the
widget to be disabled
"""
self.slider = slider

self.track_char = track_char
self.selected_track_char = selected_track_char
self.show_arrows = to_filter(show_arrows)
self.handle_char = handle_char
self.style = style
self.disabled = to_filter(disabled)

self.selected_handle = 0
self.track_len = 0
Expand Down Expand Up @@ -1736,7 +1741,7 @@ def preferred_height(

def is_focusable(self) -> bool:
"""Tell whether this user control is focusable."""
return True
return not self.disabled()

def create_content(self, width: int, height: int) -> UIContent:
"""Create an cache the rendered control fragments."""
Expand Down Expand Up @@ -2134,7 +2139,9 @@ def __init__(

def load_container(self) -> AnyContainer:
"""Build the slider's container."""
self.control = SliderControl(slider=self, show_arrows=self.show_arrows)
self.control = SliderControl(
slider=self, show_arrows=self.show_arrows, disabled=self.disabled
)
window = Window(self.control, style=lambda: f"class:slider {self.style}")
self.control.window = window
self.readout = Text(
Expand Down Expand Up @@ -2177,7 +2184,7 @@ def accept_handler(self, buffer: Buffer) -> bool:

def validate_readout(self, text: str) -> list[Any] | None:
"""Confirm the value entered in the readout is value."""
values = [value.strip() for value in text.split("-")]
values = [value.strip() for value in text.split("- ")]
valid_values = []
for value in values:
for option in self.options:
Expand Down
2 changes: 1 addition & 1 deletion euporie/core/widgets/graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ def get_graphic_float(self, key: str) -> Float | None:

GraphicControl = select_graphic_control(format_=datum.format)
if GraphicControl is None:
log.debug("Terminal graphics not supported")
log.debug("Terminal graphics not supported or format not graphical")
return None

bg_color = datum.bg
Expand Down
2 changes: 1 addition & 1 deletion euporie/web/tabs/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def _status() -> StatusBarFields:
button_prev = Button(
"◀",
show_borders=DiBool(top=True, right=False, bottom=True, left=True),
disabled=Condition(lambda: not self.webview.prev_stack),
disabled=Condition(lambda: not self.webview.prev_stack[:-1]),
on_click=lambda x: self.webview.nav_prev(),
)
button_next = Button(
Expand Down

0 comments on commit 11263f5

Please sign in to comment.