Use radio buttons in Custom Zoom window

This commit is contained in:
Isaiah Odhner 2023-05-04 23:32:26 -04:00
parent 4f08072a75
commit ef0eb6a42b
2 changed files with 50 additions and 17 deletions

View File

@ -263,6 +263,27 @@ CharacterSelectorDialogWindow .cancel {
height: auto; height: auto;
width: 1fr; width: 1fr;
} }
RadioSet {
layout: grid;
width: 35;
grid-size: 3;
grid-gutter: 0 1;
grid-columns: 10;
grid-rows: 2;
padding: 1 1;
height: auto;
/* Why is border-title-color not recognized? */
/* https://textual.textualize.io/styles/border_title_color/ */
/* It's documented, maybe it was removed from the library? */
/* border-title-color: $text; */
/* Also this isn't accepting $text */
/* border: round $text; */
border: round black;
}
.-dark-mode RadioSet {
border: round white;
}
DialogWindow .buttons { DialogWindow .buttons {
layout: horizontal; layout: horizontal;
height: auto; height: auto;

View File

@ -29,7 +29,7 @@ from textual.reactive import var, reactive
from textual.strip import Strip from textual.strip import Strip
from textual.dom import DOMNode from textual.dom import DOMNode
from textual.widget import Widget from textual.widget import Widget
from textual.widgets import Button, Static, Input, Header from textual.widgets import Button, Static, Input, Header, RadioSet, RadioButton
from textual.binding import Binding from textual.binding import Binding
from textual.color import Color from textual.color import Color
@ -2348,16 +2348,19 @@ class PaintApp(App[None]):
self.close_windows("#zoom_dialog") self.close_windows("#zoom_dialog")
def handle_button(button: Button) -> None: def handle_button(button: Button) -> None:
if button.has_class("ok"): if button.has_class("ok"):
min_zoom = 1 # min_zoom = 1
max_zoom = 16 # max_zoom = 16
try: # try:
n = int(window.content.query_one("#zoom_input", Input).value) # n = int(window.content.query_one("#zoom_input", Input).value)
if n < min_zoom or n > max_zoom: # if n < min_zoom or n > max_zoom:
raise ValueError # raise ValueError
self.magnification = n # self.magnification = n
window.close() # window.close()
except ValueError: # except ValueError:
self.warning_message_box(_("Zoom"), _("Please enter an integer between %1 and %2.", str(min_zoom), str(max_zoom)), "ok") # self.warning_message_box(_("Zoom"), _("Please enter an integer between %1 and %2.", str(min_zoom), str(max_zoom)), "ok")
radio_button = window.content.query_one(RadioSet).pressed_button
self.magnification = int(radio_button.id.split("_")[1])
window.close()
else: else:
window.close() window.close()
window = DialogWindow( window = DialogWindow(
@ -2366,16 +2369,23 @@ class PaintApp(App[None]):
handle_button=handle_button, handle_button=handle_button,
) )
window.content.mount( window.content.mount(
# TODO: radio button group, and show as percentage
Vertical( Vertical(
Horizontal( Horizontal(
Static(_("Current zoom:")), Static(_("Current zoom:")),
Static(str(self.magnification) + "x"), # Static(str(self.magnification) + "x"),
Static(str(self.magnification * 100) + "%"),
), ),
# Horizontal( # # Horizontal(
Static(_("Zoom to")), # Static(_("Zoom to")),
Input(id="zoom_input", value=str(self.magnification)), # Input(id="zoom_input", value=str(self.magnification)),
# ), # # ),
RadioSet(
RadioButton(_("100%"), id="value_1"),
RadioButton(_("200%"), id="value_2"),
RadioButton(_("400%"), id="value_4"),
RadioButton(_("600%"), id="value_6"),
RadioButton(_("800%"), id="value_8"),
)
), ),
Container( Container(
Button(_("OK"), classes="ok submit", variant="primary"), Button(_("OK"), classes="ok submit", variant="primary"),
@ -2383,6 +2393,8 @@ class PaintApp(App[None]):
classes="buttons", classes="buttons",
) )
) )
window.content.query_one("#value_" + str(self.magnification), RadioButton).value = True
window.content.query_one(RadioSet).border_title = _("Zoom to")
self.mount(window) self.mount(window)
def action_show_grid(self) -> None: def action_show_grid(self) -> None:
self.warning_message_box(_("Paint"), "Not implemented.", "ok") self.warning_message_box(_("Paint"), "Not implemented.", "ok")