Toggle the color palette with Ctrl+W

Doesn't work in VS Code's terminal, but that's OK.
It works in Ubuntu's Terminal app.
This commit is contained in:
Isaiah Odhner 2023-04-11 11:48:08 -04:00
parent 4d2b667ecb
commit a66df997bb
2 changed files with 16 additions and 1 deletions

View File

@ -6,7 +6,7 @@ Screen {
layout: grid;
grid-size: 1;
grid-columns: 1fr;
grid-rows: 1fr 6;
grid-rows: 1fr 0;
}
#main-horizontal-split {
@ -22,6 +22,10 @@ Screen {
grid-columns: 18 1fr;
}
.show_colors_box #paint {
grid-rows: 1fr 6;
}
#editing-area {
background: $surface-lighten-3;
}

View File

@ -261,6 +261,7 @@ class PaintApp(App):
CSS_PATH = "paint.css"
show_tools_box = var(True)
show_colors_box = var(True)
selected_tool = var(Tool.pencil)
selected_color = var(palette[0])
selected_char = var(" ")
@ -277,6 +278,14 @@ class PaintApp(App):
else:
self.add_class("show_tools_box")
def watch_show_colors_box(self, show_colors_box: bool) -> None:
"""Called when show_colors_box changes."""
self.query_one("#colors_box").display = show_colors_box
if self.has_class("show_colors_box"):
self.remove_class("show_colors_box")
else:
self.add_class("show_colors_box")
def watch_selected_tool(self, old_selected_tool: Tool, selected_tool: Tool) -> None:
"""Called when selected_tool changes."""
self.query_one("#tool_button_" + old_selected_tool.name).classes = "tool_button"
@ -341,6 +350,8 @@ class PaintApp(App):
self.exit()
elif key == "ctrl+t":
self.show_tools_box = not self.show_tools_box
elif key == "ctrl+w":
self.show_colors_box = not self.show_colors_box
def on_button_pressed(self, event: Button.Pressed) -> None:
"""Called when a button is pressed."""