mirror of
https://github.com/1j01/textual-paint.git
synced 2024-09-11 15:56:03 +03:00
Move ToolsBox to a new file
This commit is contained in:
parent
88b1de94ed
commit
072f8327c0
@ -62,6 +62,7 @@ from textual_paint.menus import Menu, MenuBar, MenuItem, Separator
|
||||
from textual_paint.palette_data import DEFAULT_PALETTE, IRC_PALETTE
|
||||
from textual_paint.rasterize_ansi_art import rasterize
|
||||
from textual_paint.tool import Tool
|
||||
from textual_paint.toolbox import ToolsBox
|
||||
from textual_paint.wallpaper import get_config_dir, set_wallpaper
|
||||
from textual_paint.windows import DialogWindow, MessageBox, Window
|
||||
|
||||
@ -76,36 +77,6 @@ load_language(args.language)
|
||||
|
||||
palette = list(DEFAULT_PALETTE)
|
||||
|
||||
class ToolsBox(Container):
|
||||
"""Widget containing tool buttons"""
|
||||
|
||||
class ToolSelected(Message):
|
||||
"""Message sent when a tool is selected."""
|
||||
def __init__(self, tool: Tool) -> None:
|
||||
self.tool = tool
|
||||
super().__init__()
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
"""Add our buttons."""
|
||||
self.tool_by_button: dict[Button, Tool] = {}
|
||||
for tool in Tool:
|
||||
button = Button(tool.get_icon(), classes="tool_button")
|
||||
button.can_focus = False
|
||||
# TODO: ideally, position tooltip centered under the tool button,
|
||||
# so that it never obscures the tool icon you're hovering over,
|
||||
# and make it appear immediately if a tooltip was already visible
|
||||
# (tooltip should hide and delay should return if moving to a button below,
|
||||
# to allow for easy scanning of the buttons, but not if moving above or to the side)
|
||||
button.tooltip = tool.get_name()
|
||||
self.tool_by_button[button] = tool
|
||||
yield button
|
||||
|
||||
def on_button_pressed(self, event: Button.Pressed) -> None:
|
||||
"""Called when a button is clicked."""
|
||||
|
||||
if "tool_button" in event.button.classes:
|
||||
self.post_message(self.ToolSelected(self.tool_by_button[event.button]))
|
||||
|
||||
class CharInput(Input, inherit_bindings=False):
|
||||
"""Widget for entering a single character."""
|
||||
|
||||
|
39
src/textual_paint/toolbox.py
Normal file
39
src/textual_paint/toolbox.py
Normal file
@ -0,0 +1,39 @@
|
||||
"""Container for tool buttons."""
|
||||
|
||||
from textual.app import ComposeResult
|
||||
from textual.containers import Container
|
||||
from textual.message import Message
|
||||
from textual.widgets import Button
|
||||
|
||||
from textual_paint.tool import Tool
|
||||
|
||||
|
||||
class ToolsBox(Container):
|
||||
"""Widget containing tool buttons"""
|
||||
|
||||
class ToolSelected(Message):
|
||||
"""Message sent when a tool is selected."""
|
||||
def __init__(self, tool: Tool) -> None:
|
||||
self.tool = tool
|
||||
super().__init__()
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
"""Add our buttons."""
|
||||
self.tool_by_button: dict[Button, Tool] = {}
|
||||
for tool in Tool:
|
||||
button = Button(tool.get_icon(), classes="tool_button")
|
||||
button.can_focus = False
|
||||
# TODO: ideally, position tooltip centered under the tool button,
|
||||
# so that it never obscures the tool icon you're hovering over,
|
||||
# and make it appear immediately if a tooltip was already visible
|
||||
# (tooltip should hide and delay should return if moving to a button below,
|
||||
# to allow for easy scanning of the buttons, but not if moving above or to the side)
|
||||
button.tooltip = tool.get_name()
|
||||
self.tool_by_button[button] = tool
|
||||
yield button
|
||||
|
||||
def on_button_pressed(self, event: Button.Pressed) -> None:
|
||||
"""Called when a button is clicked."""
|
||||
|
||||
if "tool_button" in event.button.classes:
|
||||
self.post_message(self.ToolSelected(self.tool_by_button[event.button]))
|
Loading…
Reference in New Issue
Block a user