staticfx 2.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of staticfx might be problematic. Click here for more details.
- staticfx/__init__.py +3 -0
- staticfx/__main__.py +5 -0
- staticfx/app/__init__.py +1 -0
- staticfx/app/app.py +335 -0
- staticfx/app/keymap.py +163 -0
- staticfx/app/player.py +143 -0
- staticfx/app/session.py +97 -0
- staticfx/cli/__init__.py +20 -0
- staticfx/cli/commands.py +293 -0
- staticfx/cli/parser.py +185 -0
- staticfx/core/__init__.py +1 -0
- staticfx/core/clock.py +30 -0
- staticfx/core/color.py +89 -0
- staticfx/core/frame.py +85 -0
- staticfx/core/glyphs.py +15 -0
- staticfx/core/keys.py +116 -0
- staticfx/core/renderer.py +84 -0
- staticfx/core/terminal.py +148 -0
- staticfx/effects/__init__.py +1 -0
- staticfx/effects/base.py +88 -0
- staticfx/effects/builtin/__init__.py +203 -0
- staticfx/effects/builtin/fields.py +404 -0
- staticfx/effects/builtin/geometry.py +77 -0
- staticfx/effects/builtin/particles.py +623 -0
- staticfx/effects/builtin/shapes.py +255 -0
- staticfx/effects/builtin/signals.py +298 -0
- staticfx/effects/builtin/simulations.py +439 -0
- staticfx/effects/builtin/terminal.py +362 -0
- staticfx/effects/curated.py +16 -0
- staticfx/effects/engine/__init__.py +11 -0
- staticfx/effects/engine/effect.py +267 -0
- staticfx/effects/engine/filters.py +115 -0
- staticfx/effects/engine/generate.py +203 -0
- staticfx/effects/engine/layers.py +396 -0
- staticfx/effects/engine/recipe.py +215 -0
- staticfx/effects/engine/schema.py +87 -0
- staticfx/effects/engine/warps.py +203 -0
- staticfx/effects/registry.py +103 -0
- staticfx/effects/spec.py +51 -0
- staticfx/integrations.py +48 -0
- staticfx/library/__init__.py +1 -0
- staticfx/library/config.py +122 -0
- staticfx/library/effects.py +159 -0
- staticfx/library/files.py +44 -0
- staticfx/library/legacy.py +180 -0
- staticfx/library/looks.py +134 -0
- staticfx/postfx.py +78 -0
- staticfx/py.typed +0 -0
- staticfx/themes.py +162 -0
- staticfx/ui/__init__.py +1 -0
- staticfx/ui/browser.py +269 -0
- staticfx/ui/dialogs.py +95 -0
- staticfx/ui/help.py +99 -0
- staticfx/ui/pickers.py +221 -0
- staticfx/ui/play.py +213 -0
- staticfx/ui/screen.py +39 -0
- staticfx/ui/settings.py +262 -0
- staticfx/ui/studio.py +433 -0
- staticfx/ui/widgets.py +196 -0
- staticfx-2.0.0.dist-info/METADATA +164 -0
- staticfx-2.0.0.dist-info/RECORD +65 -0
- staticfx-2.0.0.dist-info/WHEEL +5 -0
- staticfx-2.0.0.dist-info/entry_points.txt +2 -0
- staticfx-2.0.0.dist-info/licenses/LICENSE +21 -0
- staticfx-2.0.0.dist-info/top_level.txt +1 -0
staticfx/ui/play.py
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
"""The main view: the effect, full screen, driven by the key map."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from collections.abc import Callable
|
|
6
|
+
from typing import TYPE_CHECKING
|
|
7
|
+
|
|
8
|
+
from staticfx.app.keymap import key_label
|
|
9
|
+
from staticfx.ui.browser import Browser
|
|
10
|
+
from staticfx.ui.dialogs import ask_look_name
|
|
11
|
+
from staticfx.ui.help import HelpScreen
|
|
12
|
+
from staticfx.ui.pickers import LookPicker, ThemePicker
|
|
13
|
+
from staticfx.ui.screen import Screen
|
|
14
|
+
from staticfx.ui.settings import SettingsScreen
|
|
15
|
+
from staticfx.ui.studio import open_studio
|
|
16
|
+
from staticfx.ui.widgets import Canvas, fit
|
|
17
|
+
|
|
18
|
+
if TYPE_CHECKING:
|
|
19
|
+
from staticfx.app.app import App
|
|
20
|
+
|
|
21
|
+
HINT_SECONDS = 6.0
|
|
22
|
+
QUIT_WINDOW = 2.0 # seconds within which a second Esc quits
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class PlayScreen(Screen):
|
|
26
|
+
def __init__(self, app: App) -> None:
|
|
27
|
+
super().__init__(app)
|
|
28
|
+
self.hint_time = HINT_SECONDS
|
|
29
|
+
self.quit_armed = 0.0
|
|
30
|
+
self.actions: dict[str, Callable[[], None]] = {
|
|
31
|
+
"next": lambda: app.step(1),
|
|
32
|
+
"previous": lambda: app.step(-1),
|
|
33
|
+
"random": app.play_random,
|
|
34
|
+
"back": app.play_previous,
|
|
35
|
+
"auto": app.toggle_auto,
|
|
36
|
+
"browse": self.open_browser,
|
|
37
|
+
"themes": self.open_themes,
|
|
38
|
+
"looks": self.open_looks,
|
|
39
|
+
"settings": self.open_settings,
|
|
40
|
+
"help": self.open_help,
|
|
41
|
+
"new_effect": lambda: self.open_studio(None),
|
|
42
|
+
"edit_effect": lambda: self.open_studio(app.player.key),
|
|
43
|
+
"favorite": self.favorite,
|
|
44
|
+
"save_look": self.save_look,
|
|
45
|
+
"next_theme": self.next_theme,
|
|
46
|
+
"crt": lambda: self.toggle_filter("crt", "CRT scanlines"),
|
|
47
|
+
"glitch": lambda: self.toggle_filter("glitch", "Glitch"),
|
|
48
|
+
"recolour": lambda: self.toggle_filter("recolour", "Rainbow recolour"),
|
|
49
|
+
"pause": self.pause,
|
|
50
|
+
"restart": self.restart,
|
|
51
|
+
"faster": lambda: self.change_speed(app.player.faster),
|
|
52
|
+
"slower": lambda: self.change_speed(app.player.slower),
|
|
53
|
+
"status": self.toggle_status,
|
|
54
|
+
"quit": self.quit,
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
def handle(self, key: str) -> None:
|
|
58
|
+
app = self.app
|
|
59
|
+
self.hint_time = 0.0
|
|
60
|
+
if not app.settings.seen_welcome:
|
|
61
|
+
app.settings.seen_welcome = True # any key dismisses the welcome card
|
|
62
|
+
app.dirty = True
|
|
63
|
+
return
|
|
64
|
+
if key == "ctrl-c":
|
|
65
|
+
self.quit()
|
|
66
|
+
elif key == "escape":
|
|
67
|
+
if self.quit_armed > 0:
|
|
68
|
+
self.quit()
|
|
69
|
+
else:
|
|
70
|
+
self.quit_armed = QUIT_WINDOW
|
|
71
|
+
app.toast(f"Press Esc again to quit ({app.keymap.label('quit')} quits at once)")
|
|
72
|
+
else:
|
|
73
|
+
action = app.keymap.action(key)
|
|
74
|
+
if action is not None:
|
|
75
|
+
self.actions[action]()
|
|
76
|
+
|
|
77
|
+
def update(self, dt: float) -> None:
|
|
78
|
+
self.hint_time = max(0.0, self.hint_time - dt)
|
|
79
|
+
self.quit_armed = max(0.0, self.quit_armed - dt)
|
|
80
|
+
|
|
81
|
+
def quit(self) -> None:
|
|
82
|
+
self.app.running = False
|
|
83
|
+
|
|
84
|
+
def open_browser(self) -> None:
|
|
85
|
+
self.app.push(Browser(self.app))
|
|
86
|
+
|
|
87
|
+
def open_themes(self) -> None:
|
|
88
|
+
self.app.push(ThemePicker(self.app))
|
|
89
|
+
|
|
90
|
+
def open_looks(self) -> None:
|
|
91
|
+
self.app.push(LookPicker(self.app))
|
|
92
|
+
|
|
93
|
+
def open_settings(self) -> None:
|
|
94
|
+
self.app.push(SettingsScreen(self.app))
|
|
95
|
+
|
|
96
|
+
def open_help(self) -> None:
|
|
97
|
+
self.app.push(HelpScreen(self.app))
|
|
98
|
+
|
|
99
|
+
def open_studio(self, key: str | None) -> None:
|
|
100
|
+
open_studio(self.app, key)
|
|
101
|
+
|
|
102
|
+
def favorite(self) -> None:
|
|
103
|
+
app = self.app
|
|
104
|
+
key = app.player.key
|
|
105
|
+
added = app.toggle_favorite(key)
|
|
106
|
+
label = app.registry[key].label
|
|
107
|
+
app.toast(f"Added {label} to favourites" if added else f"Removed {label} from favourites")
|
|
108
|
+
|
|
109
|
+
def save_look(self) -> None:
|
|
110
|
+
ask_look_name(self.app)
|
|
111
|
+
|
|
112
|
+
def next_theme(self) -> None:
|
|
113
|
+
app = self.app
|
|
114
|
+
names = app.theme_names()
|
|
115
|
+
current = app.player.theme_name
|
|
116
|
+
index = names.index(current) if current in names else -1
|
|
117
|
+
app.set_theme(names[(index + 1) % len(names)])
|
|
118
|
+
app.toast(f"Theme: {app.player.theme().label}")
|
|
119
|
+
|
|
120
|
+
def toggle_filter(self, name: str, label: str) -> None:
|
|
121
|
+
post = self.app.player.post
|
|
122
|
+
setattr(post, name, not getattr(post, name))
|
|
123
|
+
self.app.dirty = True
|
|
124
|
+
self.app.toast(f"{label} {'on' if getattr(post, name) else 'off'}")
|
|
125
|
+
|
|
126
|
+
def restart(self) -> None:
|
|
127
|
+
self.app.player.restart()
|
|
128
|
+
self.app.toast("Restarted")
|
|
129
|
+
|
|
130
|
+
def pause(self) -> None:
|
|
131
|
+
player = self.app.player
|
|
132
|
+
player.paused = not player.paused
|
|
133
|
+
self.app.toast("Paused" if player.paused else "Playing")
|
|
134
|
+
|
|
135
|
+
def change_speed(self, change: Callable[[], None]) -> None:
|
|
136
|
+
change()
|
|
137
|
+
self.app.dirty = True
|
|
138
|
+
self.app.toast(f"Speed ×{self.app.player.speed:.2f}")
|
|
139
|
+
|
|
140
|
+
def toggle_status(self) -> None:
|
|
141
|
+
self.app.show_status = not self.app.show_status
|
|
142
|
+
|
|
143
|
+
def draw(self, canvas: Canvas) -> None:
|
|
144
|
+
if len(self.app.screens) > 1 and self.app.screens[-1] is not self:
|
|
145
|
+
return
|
|
146
|
+
if not self.app.settings.seen_welcome:
|
|
147
|
+
self.draw_welcome(canvas)
|
|
148
|
+
elif self.app.show_status:
|
|
149
|
+
self.draw_status(canvas)
|
|
150
|
+
elif self.hint_time > 0:
|
|
151
|
+
self.draw_hint(canvas)
|
|
152
|
+
|
|
153
|
+
def _key(self, action: str) -> str:
|
|
154
|
+
return self.app.keymap.label(action, self.app.ascii_only)
|
|
155
|
+
|
|
156
|
+
def draw_status(self, canvas: Canvas) -> None:
|
|
157
|
+
app, c, s = self.app, canvas.chrome, canvas.style
|
|
158
|
+
spec = app.registry[app.player.key]
|
|
159
|
+
star = f"{c.star} " if app.is_favorite(spec.key) else ""
|
|
160
|
+
flags = [*app.player.post.active()]
|
|
161
|
+
if app.auto:
|
|
162
|
+
flags.append("auto")
|
|
163
|
+
if app.player.paused:
|
|
164
|
+
flags.append("paused")
|
|
165
|
+
parts = [spec.category, app.player.theme().label, f"×{app.player.speed:.1f}", *flags]
|
|
166
|
+
left = f" {star}{spec.label} {f' {c.dot} '.join(parts)}"
|
|
167
|
+
right = f"{self._key('help')} help "
|
|
168
|
+
y = canvas.height - 1
|
|
169
|
+
canvas.frame.fill(0, y, canvas.width, 1)
|
|
170
|
+
canvas.text(0, y, fit(left, canvas.width - len(right) - 1, c.ellipsis), s.text)
|
|
171
|
+
canvas.text(canvas.width - len(right), y, right, s.dim)
|
|
172
|
+
|
|
173
|
+
def draw_hint(self, canvas: Canvas) -> None:
|
|
174
|
+
dot = f" {canvas.chrome.dot} "
|
|
175
|
+
browse = (
|
|
176
|
+
f"{key_label('left', self.app.ascii_only)}{key_label('right', self.app.ascii_only)}"
|
|
177
|
+
)
|
|
178
|
+
hint = dot.join(
|
|
179
|
+
[
|
|
180
|
+
f"{browse} next",
|
|
181
|
+
f"{self._key('browse')} browse",
|
|
182
|
+
f"{self._key('themes')} themes",
|
|
183
|
+
f"{self._key('new_effect')} create",
|
|
184
|
+
f"{self._key('help')} help",
|
|
185
|
+
f"{self._key('quit')} quit",
|
|
186
|
+
]
|
|
187
|
+
)
|
|
188
|
+
hint = fit(hint, canvas.width - 2, canvas.chrome.ellipsis)
|
|
189
|
+
canvas.text((canvas.width - len(hint)) // 2, canvas.height - 1, hint, canvas.style.dim)
|
|
190
|
+
|
|
191
|
+
def draw_welcome(self, canvas: Canvas) -> None:
|
|
192
|
+
app = self.app
|
|
193
|
+
count = f"{len(app.registry):,}"
|
|
194
|
+
arrows = f"{key_label('left', app.ascii_only)} {key_label('right', app.ascii_only)}"
|
|
195
|
+
rows = [
|
|
196
|
+
(arrows, "previous / next effect"),
|
|
197
|
+
(self._key("browse"), f"browse and search all {count} effects"),
|
|
198
|
+
(self._key("themes"), "change the colour theme"),
|
|
199
|
+
(self._key("looks"), "ready-made looks"),
|
|
200
|
+
(self._key("new_effect"), "make your own effect in the Studio"),
|
|
201
|
+
(self._key("status"), "show what's playing"),
|
|
202
|
+
(self._key("help"), "every key"),
|
|
203
|
+
]
|
|
204
|
+
width = min(canvas.width - 4, 52)
|
|
205
|
+
height = len(rows) + 6
|
|
206
|
+
x, y = (canvas.width - width) // 2, max(0, (canvas.height - height) // 2)
|
|
207
|
+
canvas.box(x, y, width, height, "Welcome to StaticFX")
|
|
208
|
+
s = canvas.style
|
|
209
|
+
canvas.text(x + 3, y + 2, "Animated effects for your terminal.", s.text, width - 6)
|
|
210
|
+
for i, (keys, what) in enumerate(rows):
|
|
211
|
+
canvas.text(x + 3, y + 3 + i, keys, s.selected, 9)
|
|
212
|
+
canvas.text(x + 12, y + 3 + i, what, s.text, width - 15)
|
|
213
|
+
canvas.text(x + 3, y + height - 2, "Press any key to start", s.accent, width - 6)
|
staticfx/ui/screen.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"""The base class for everything that takes over the keyboard."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import TYPE_CHECKING
|
|
6
|
+
|
|
7
|
+
from staticfx.ui.widgets import Canvas
|
|
8
|
+
|
|
9
|
+
if TYPE_CHECKING:
|
|
10
|
+
from staticfx.app.app import App
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class Screen:
|
|
14
|
+
"""One layer of the UI. The app keeps a stack; the top screen gets every key.
|
|
15
|
+
|
|
16
|
+
``help`` lists ``(keys, what they do)`` for the help screen, so each
|
|
17
|
+
screen documents its own controls next to the code that handles them.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
help: tuple[tuple[str, str], ...] = ()
|
|
21
|
+
|
|
22
|
+
def __init__(self, app: App) -> None:
|
|
23
|
+
self.app = app
|
|
24
|
+
|
|
25
|
+
def handle(self, key: str) -> None:
|
|
26
|
+
"""React to one key press."""
|
|
27
|
+
|
|
28
|
+
def update(self, dt: float) -> None:
|
|
29
|
+
"""Advance any animation the screen owns."""
|
|
30
|
+
|
|
31
|
+
def draw(self, canvas: Canvas) -> None:
|
|
32
|
+
"""Draw on top of the effect (and of the screens below)."""
|
|
33
|
+
|
|
34
|
+
def close(self) -> None:
|
|
35
|
+
"""Remove this screen from the stack."""
|
|
36
|
+
self.app.pop(self)
|
|
37
|
+
|
|
38
|
+
def on_close(self) -> None:
|
|
39
|
+
"""Called after the screen is removed; undo any previews here."""
|
staticfx/ui/settings.py
ADDED
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
"""Settings and key bindings, changed in place and saved straight away."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from collections.abc import Callable, Sequence
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from typing import TYPE_CHECKING, TypeVar
|
|
9
|
+
|
|
10
|
+
from staticfx import themes
|
|
11
|
+
from staticfx.app.keymap import ACTIONS, RESERVED, key_label
|
|
12
|
+
from staticfx.library.config import CHARACTERS, COLOURS
|
|
13
|
+
from staticfx.ui.dialogs import Confirm
|
|
14
|
+
from staticfx.ui.screen import Screen
|
|
15
|
+
from staticfx.ui.widgets import Canvas, Cursor
|
|
16
|
+
|
|
17
|
+
if TYPE_CHECKING:
|
|
18
|
+
from staticfx.app.app import App
|
|
19
|
+
|
|
20
|
+
N = TypeVar("N", int, float)
|
|
21
|
+
|
|
22
|
+
FPS_CHOICES = [10, 15, 20, 24, 30, 45, 60]
|
|
23
|
+
AUTO_CHOICES = [5.0, 8.0, 12.0, 20.0, 30.0, 60.0, 120.0, 300.0]
|
|
24
|
+
FLASH_WARNING = [
|
|
25
|
+
"The Strobe theme flashes rapidly and can",
|
|
26
|
+
"trigger seizures in people with photosensitive",
|
|
27
|
+
"epilepsy. Unlock it anyway?",
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@dataclass
|
|
32
|
+
class Row:
|
|
33
|
+
label: str
|
|
34
|
+
value: Callable[[], str] = str
|
|
35
|
+
change: Callable[[int], None] | None = None
|
|
36
|
+
on_enter: Callable[[], None] | None = None
|
|
37
|
+
hint: str = ""
|
|
38
|
+
heading: bool = False
|
|
39
|
+
action: str | None = None # set on key-binding rows
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def step_choice(options: Sequence[N], current: float, step: int) -> N:
|
|
43
|
+
"""The option after (or before) ``current``, stopping at the ends."""
|
|
44
|
+
nearest = min(range(len(options)), key=lambda i: abs(options[i] - current))
|
|
45
|
+
return options[max(0, min(len(options) - 1, nearest + step))]
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class SettingsScreen(Screen):
|
|
49
|
+
help = (
|
|
50
|
+
("↑ ↓", "choose a setting"),
|
|
51
|
+
("← →", "change it"),
|
|
52
|
+
("Enter", "on a key binding: press the new key"),
|
|
53
|
+
("Backspace", "on a key binding: unbind it"),
|
|
54
|
+
("Esc", "close"),
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
def __init__(self, app: App) -> None:
|
|
58
|
+
super().__init__(app)
|
|
59
|
+
self.cursor = Cursor()
|
|
60
|
+
self.view = Cursor()
|
|
61
|
+
self.capturing: str | None = None # the action waiting for a new key
|
|
62
|
+
self.rows: list[Row] = []
|
|
63
|
+
self.visible_rows = 10
|
|
64
|
+
self.rebuild()
|
|
65
|
+
|
|
66
|
+
def rebuild(self) -> None:
|
|
67
|
+
app, s = self.app, self.app.settings
|
|
68
|
+
rows = [
|
|
69
|
+
Row("Display", heading=True),
|
|
70
|
+
Row(
|
|
71
|
+
"Frame rate",
|
|
72
|
+
lambda: f"{s.fps} fps",
|
|
73
|
+
self.change_fps,
|
|
74
|
+
hint="lower it if your terminal can't keep up",
|
|
75
|
+
),
|
|
76
|
+
Row(
|
|
77
|
+
"Characters",
|
|
78
|
+
lambda: s.characters,
|
|
79
|
+
self.change_characters,
|
|
80
|
+
hint="auto, katakana in rain effects, or plain ASCII",
|
|
81
|
+
),
|
|
82
|
+
Row(
|
|
83
|
+
"Colours",
|
|
84
|
+
lambda: s.colour,
|
|
85
|
+
self.change_colour,
|
|
86
|
+
hint="use 256 if colours look wrong in your terminal",
|
|
87
|
+
),
|
|
88
|
+
Row(
|
|
89
|
+
"Auto-cycle every",
|
|
90
|
+
lambda: f"{s.auto_seconds:g}s",
|
|
91
|
+
self.change_auto,
|
|
92
|
+
hint=f"{app.keymap.label('auto', app.ascii_only)} turns auto-cycle on",
|
|
93
|
+
),
|
|
94
|
+
Row(
|
|
95
|
+
"Allow flashing",
|
|
96
|
+
lambda: "yes" if s.allow_flashing else "no",
|
|
97
|
+
self.toggle_flashing,
|
|
98
|
+
hint="unlocks the Strobe theme (photosensitivity warning)",
|
|
99
|
+
),
|
|
100
|
+
Row("Keys", heading=True),
|
|
101
|
+
]
|
|
102
|
+
rows += [self.key_row(action, description) for action, (_, description) in ACTIONS.items()]
|
|
103
|
+
rows.append(Row("Reset all keys", lambda: "", on_enter=self.confirm_reset))
|
|
104
|
+
if app.data_dir is not None:
|
|
105
|
+
rows += [
|
|
106
|
+
Row("Files", heading=True),
|
|
107
|
+
Row(
|
|
108
|
+
"Data folder",
|
|
109
|
+
lambda: self.short_path(app.data_dir),
|
|
110
|
+
hint="effects/, looks.json, config.json",
|
|
111
|
+
),
|
|
112
|
+
]
|
|
113
|
+
self.rows = rows
|
|
114
|
+
|
|
115
|
+
def key_row(self, action: str, description: str) -> Row:
|
|
116
|
+
return Row(
|
|
117
|
+
description,
|
|
118
|
+
lambda: self.keys_text(action),
|
|
119
|
+
on_enter=lambda: self.start_capture(action),
|
|
120
|
+
hint="Enter to set a key, Backspace to unbind",
|
|
121
|
+
action=action,
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
@staticmethod
|
|
125
|
+
def short_path(path: Path | None) -> str:
|
|
126
|
+
if path is None:
|
|
127
|
+
return "(none)"
|
|
128
|
+
home = str(Path.home())
|
|
129
|
+
text = str(path)
|
|
130
|
+
return "~" + text[len(home) :] if text.startswith(home) else text
|
|
131
|
+
|
|
132
|
+
def keys_text(self, action: str) -> str:
|
|
133
|
+
if self.capturing == action:
|
|
134
|
+
return "press a key..."
|
|
135
|
+
keys = self.app.keymap.keys_for(action)
|
|
136
|
+
return " / ".join(key_label(k, self.app.ascii_only) for k in keys) or "(unbound)"
|
|
137
|
+
|
|
138
|
+
def selectable(self) -> list[Row]:
|
|
139
|
+
return [row for row in self.rows if not row.heading]
|
|
140
|
+
|
|
141
|
+
@property
|
|
142
|
+
def current(self) -> Row:
|
|
143
|
+
return self.selectable()[self.cursor.index]
|
|
144
|
+
|
|
145
|
+
def changed(self, setting: str = "") -> None:
|
|
146
|
+
"""Mark settings for saving; a setting changed here outlives command-line overrides."""
|
|
147
|
+
if setting:
|
|
148
|
+
self.app.keep(setting)
|
|
149
|
+
self.app.dirty = True
|
|
150
|
+
|
|
151
|
+
def change_fps(self, step: int) -> None:
|
|
152
|
+
self.app.settings.fps = step_choice(FPS_CHOICES, self.app.settings.fps, step)
|
|
153
|
+
self.changed("fps")
|
|
154
|
+
|
|
155
|
+
def change_auto(self, step: int) -> None:
|
|
156
|
+
s = self.app.settings
|
|
157
|
+
s.auto_seconds = step_choice(AUTO_CHOICES, s.auto_seconds, step)
|
|
158
|
+
self.changed("auto_seconds")
|
|
159
|
+
|
|
160
|
+
def change_characters(self, step: int) -> None:
|
|
161
|
+
s = self.app.settings
|
|
162
|
+
s.characters = CHARACTERS[(CHARACTERS.index(s.characters) + step) % len(CHARACTERS)]
|
|
163
|
+
self.app.apply_characters()
|
|
164
|
+
self.changed("characters")
|
|
165
|
+
|
|
166
|
+
def change_colour(self, step: int) -> None:
|
|
167
|
+
s = self.app.settings
|
|
168
|
+
s.colour = COLOURS[(COLOURS.index(s.colour) + step) % len(COLOURS)]
|
|
169
|
+
self.changed("colour")
|
|
170
|
+
|
|
171
|
+
def toggle_flashing(self, _step: int = 0) -> None:
|
|
172
|
+
app = self.app
|
|
173
|
+
if app.settings.allow_flashing:
|
|
174
|
+
app.settings.allow_flashing = False
|
|
175
|
+
if app.player.theme_name == "strobe":
|
|
176
|
+
app.set_theme(themes.DEFAULT)
|
|
177
|
+
self.changed()
|
|
178
|
+
return
|
|
179
|
+
|
|
180
|
+
def unlock() -> None:
|
|
181
|
+
app.settings.allow_flashing = True
|
|
182
|
+
app.toast("Strobe unlocked: find it in the theme menu")
|
|
183
|
+
self.changed()
|
|
184
|
+
|
|
185
|
+
app.push(Confirm(app, "Photosensitivity warning", FLASH_WARNING, unlock))
|
|
186
|
+
|
|
187
|
+
def start_capture(self, action: str) -> None:
|
|
188
|
+
self.capturing = action
|
|
189
|
+
|
|
190
|
+
def capture(self, key: str) -> None:
|
|
191
|
+
action, self.capturing = self.capturing, None
|
|
192
|
+
if action is None or key == "escape":
|
|
193
|
+
return
|
|
194
|
+
if key in RESERVED:
|
|
195
|
+
self.app.toast(f"{key_label(key)} is reserved and can't be bound")
|
|
196
|
+
return
|
|
197
|
+
keymap = self.app.keymap
|
|
198
|
+
keymap.unbind(action) # the new key replaces the old ones
|
|
199
|
+
lost = keymap.bind(key, action)
|
|
200
|
+
if lost:
|
|
201
|
+
self.app.toast(f"{key_label(key)} no longer does: {ACTIONS[lost][1]}")
|
|
202
|
+
self.changed()
|
|
203
|
+
|
|
204
|
+
def confirm_reset(self) -> None:
|
|
205
|
+
def reset() -> None:
|
|
206
|
+
self.app.keymap.reset()
|
|
207
|
+
self.app.toast("Keys reset to the defaults")
|
|
208
|
+
self.changed()
|
|
209
|
+
|
|
210
|
+
self.app.push(
|
|
211
|
+
Confirm(self.app, "Reset keys", ["Put every key back to its default?"], reset)
|
|
212
|
+
)
|
|
213
|
+
|
|
214
|
+
def handle(self, key: str) -> None:
|
|
215
|
+
if self.capturing is not None:
|
|
216
|
+
self.capture(key)
|
|
217
|
+
return
|
|
218
|
+
row = self.current
|
|
219
|
+
if key in ("escape", "ctrl-c", "q"):
|
|
220
|
+
self.close()
|
|
221
|
+
elif self.cursor.handle(key, len(self.selectable()), self.visible_rows):
|
|
222
|
+
pass
|
|
223
|
+
elif key in ("left", "right") and row.change is not None:
|
|
224
|
+
row.change(-1 if key == "left" else 1)
|
|
225
|
+
elif key == "enter" and row.on_enter is not None:
|
|
226
|
+
row.on_enter()
|
|
227
|
+
elif key in ("enter", "space") and row.change is not None:
|
|
228
|
+
row.change(1)
|
|
229
|
+
elif key in ("backspace", "delete") and row.action is not None:
|
|
230
|
+
self.app.keymap.unbind(row.action)
|
|
231
|
+
self.changed()
|
|
232
|
+
|
|
233
|
+
def draw(self, canvas: Canvas) -> None:
|
|
234
|
+
c, s = canvas.chrome, canvas.style
|
|
235
|
+
w, h = min(canvas.width - 2, 64), canvas.height - 2
|
|
236
|
+
x, y = 1, 1
|
|
237
|
+
canvas.box(x, y, w, h, "Settings")
|
|
238
|
+
self.visible_rows = h - 5
|
|
239
|
+
current = self.current
|
|
240
|
+
self.view.index = self.rows.index(current)
|
|
241
|
+
for line, i in enumerate(self.view.window(self.visible_rows, len(self.rows)), y + 1):
|
|
242
|
+
row = self.rows[i]
|
|
243
|
+
if row.heading:
|
|
244
|
+
canvas.text(x + 2, line, f"{c.h * 2} {row.label} ", s.dim, w - 4)
|
|
245
|
+
continue
|
|
246
|
+
selected = row is current
|
|
247
|
+
value = row.value()
|
|
248
|
+
if selected and row.change is not None:
|
|
249
|
+
value = f"{c.arrow_left} {value} {c.arrow_right}"
|
|
250
|
+
colour = s.selected if selected else s.text
|
|
251
|
+
value_width = min(len(value), w // 2)
|
|
252
|
+
label = f"{c.cursor if selected else ' '} {row.label}"
|
|
253
|
+
canvas.text(x + 2, line, label, colour, w - 6 - value_width)
|
|
254
|
+
value_colour = (
|
|
255
|
+
s.accent if self.capturing and selected else colour if selected else s.dim
|
|
256
|
+
)
|
|
257
|
+
canvas.text(x + w - 3 - value_width, line, value, value_colour, value_width)
|
|
258
|
+
canvas.scrollbar(x + w - 2, y + 1, self.visible_rows, self.view.first, len(self.rows))
|
|
259
|
+
canvas.rule(x, y + h - 4, w)
|
|
260
|
+
hint = "Press the new key (Esc cancels)" if self.capturing else current.hint
|
|
261
|
+
canvas.text(x + 2, y + h - 3, hint, s.text, w - 4)
|
|
262
|
+
canvas.text(x + 2, y + h - 2, "← → change Enter select Esc close", s.dim, w - 4)
|