Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ authors = [
{ name = "Dave Pearson", email = "davep@davep.org" }
]
dependencies = [
"textual>=3.1.0",
"textual>=3.7.0",
"textual-enhanced>=0.13.0",
"textual-canvas>=0.3.0",
"xdg-base-dirs>=6.0.2",
Expand Down
30 changes: 16 additions & 14 deletions src/complexitty/screens/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# Textual imports.
from textual import on, work
from textual.app import ComposeResult
from textual.getters import query_one
from textual.widgets import Footer, Header

##############################################################################
Expand Down Expand Up @@ -136,6 +137,9 @@ class Main(EnhancedScreen[None]):
COMMANDS = {MainCommands}
HELP = "## Commands and keys"

mandelbrot = query_one(Mandelbrot)
"""The plot of the Mandelbrot set."""

def __init__(self, arguments: Namespace) -> None:
"""Initialise the screen object.

Expand All @@ -156,7 +160,7 @@ def compose(self) -> ComposeResult:

def on_mount(self) -> None:
"""Configure the Mandelbrot once the DOM is ready."""
self.query_one(Mandelbrot).set(
self.mandelbrot.set(
max_iteration=self._arguments.max_iteration,
multibrot=self._arguments.multibrot,
zoom=self._arguments.zoom,
Expand Down Expand Up @@ -218,7 +222,7 @@ def _update_situation(self, message: Mandelbrot.Plotted) -> None:

def _remember(self) -> None:
"""Remember the current situation."""
plot = self.query_one(Mandelbrot)
plot = self.mandelbrot
self._history.append(
Situation(
plot.x_position,
Expand All @@ -237,7 +241,7 @@ def action_zoom(self, change: float) -> None:
change: The amount to change the zoom by.
"""
self._remember()
self.query_one(Mandelbrot).zoom *= change
self.mandelbrot.zoom *= change

def action_move(self, x: int, y: int) -> None:
"""Move the plot in the indicated direction.
Expand All @@ -247,7 +251,7 @@ def action_move(self, x: int, y: int) -> None:
y: The number of pixels to move in the Y direction.
"""
self._remember()
self.query_one(Mandelbrot).move(x, y)
self.mandelbrot.move(x, y)

def action_iterate(self, change: int) -> None:
"""Change the maximum iteration.
Expand All @@ -256,15 +260,15 @@ def action_iterate(self, change: int) -> None:
change: The change to make to the maximum iterations.
"""
self._remember()
self.query_one(Mandelbrot).max_iteration += change
self.mandelbrot.max_iteration += change

def action_set_colour(self, colour_map: str) -> None:
"""Set the colour map for the plot.

Args:
colour_map: The name of the colour map to use.
"""
self.query_one(Mandelbrot).colour_map = get_colour_map(colour_map)
self.mandelbrot.colour_map = get_colour_map(colour_map)

def action_multibrot(self, change: int) -> None:
"""Change the 'multibrot' value.
Expand All @@ -273,7 +277,7 @@ def action_multibrot(self, change: int) -> None:
change: The change to make to the 'multibrot' value.
"""
self._remember()
self.query_one(Mandelbrot).multibrot += change
self.mandelbrot.multibrot += change

def action_goto(self, x: int, y: int) -> None:
"""Go to a specific location.
Expand All @@ -282,13 +286,13 @@ def action_goto(self, x: int, y: int) -> None:
x: The X location to go to.
y: The Y location to go to.
"""
self.query_one(Mandelbrot).goto(x, y)
self.mandelbrot.goto(x, y)
self._remember()

def action_reset_command(self) -> None:
"""Reset the plot to its default values."""
self._remember()
self.query_one(Mandelbrot).reset()
self.mandelbrot.reset()

_VALID_LOCATION: Final[Pattern[str]] = compile(
r"(?P<x>[^, ]+) *[, ] *(?P<y>[^, ]+)"
Expand All @@ -311,9 +315,7 @@ async def action_go_to_command(self) -> None:
severity="error",
)
if "x" in target and "y" in target:
self.query_one(Mandelbrot).goto(
float(parsed["x"]), float(parsed["y"])
)
self.mandelbrot.goto(float(parsed["x"]), float(parsed["y"]))
else:
self.notify(
"Please provide both the [i]x[/] and [i]y[/] coordinates "
Expand All @@ -326,7 +328,7 @@ async def action_go_to_command(self) -> None:

def action_copy_command_line_to_clipboard_command(self) -> None:
"""Copy the current view as a command, to the clipboard."""
plot = self.query_one(Mandelbrot)
plot = self.mandelbrot
command = (
f"complexitty "
f"--x-position={plot.x_position} "
Expand All @@ -346,7 +348,7 @@ def action_undo_command(self) -> None:
except IndexError:
return
self.refresh_bindings()
self.query_one(Mandelbrot).set(
self.mandelbrot.set(
x_position=situation.x_position,
y_position=situation.y_position,
zoom=situation.zoom,
Expand Down