Skip to content

Commit 82d3582

Browse files
committed
Mark KMOD_ names as deprecated
1 parent 233e4a7 commit 82d3582

File tree

5 files changed

+26
-39
lines changed

5 files changed

+26
-39
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ This project adheres to [Semantic Versioning](https://semver.org/) since version
66

77
## [Unreleased]
88

9+
### Deprecated
10+
11+
- Keyboard bitmask modifiers `tcod.event.KMOD_*` have been replaced by `tcod.event.Modifier`.
12+
913
## [16.2.3] - 2024-07-16
1014

1115
### Fixed

examples/samples_tcod.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import tcod.sdl.mouse
2828
import tcod.sdl.render
2929
from tcod import libtcodpy
30+
from tcod.sdl.video import WindowFlags
3031

3132
# ruff: noqa: S311
3233

@@ -82,11 +83,13 @@ def ev_keydown(self, event: tcod.event.KeyDown) -> None:
8283
cur_sample = (cur_sample - 1) % len(SAMPLES)
8384
SAMPLES[cur_sample].on_enter()
8485
draw_samples_menu()
85-
elif event.sym == tcod.event.KeySym.RETURN and event.mod & tcod.event.KMOD_LALT:
86-
libtcodpy.console_set_fullscreen(not libtcodpy.console_is_fullscreen())
87-
elif event.sym == tcod.event.KeySym.PRINTSCREEN or event.sym == tcod.event.KeySym.p:
86+
elif event.sym == tcod.event.KeySym.RETURN and event.mod & tcod.event.Modifier.ALT:
87+
sdl_window = context.sdl_window
88+
if sdl_window:
89+
sdl_window.fullscreen = False if sdl_window.fullscreen else WindowFlags.FULLSCREEN_DESKTOP
90+
elif event.sym in (tcod.event.KeySym.PRINTSCREEN, tcod.event.KeySym.p):
8891
print("screenshot")
89-
if event.mod & tcod.event.KMOD_LALT:
92+
if event.mod & tcod.event.Modifier.ALT:
9093
libtcodpy.console_save_apf(root_console, "samples.apf")
9194
print("apf")
9295
else:

tcod/event.py

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@
9595
import tcod.sdl.sys
9696
from tcod.cffi import ffi, lib
9797
from tcod.event_constants import * # noqa: F403
98-
from tcod.event_constants import KMOD_ALT, KMOD_CTRL, KMOD_GUI, KMOD_SHIFT
9998
from tcod.sdl.joystick import _HAT_DIRECTIONS
10099

101100
T = TypeVar("T")
@@ -2807,6 +2806,14 @@ def __getattr__(name: str) -> int:
28072806
FutureWarning,
28082807
stacklevel=2,
28092808
)
2809+
elif name.startswith("KMOD_"):
2810+
modifier = name[5:]
2811+
warnings.warn(
2812+
"Key modifiers have been replaced with the Modifier IntFlag.\n"
2813+
f"`tcod.event.{modifier}` should be replaced with `tcod.event.Modifier.{modifier}`",
2814+
FutureWarning,
2815+
stacklevel=2,
2816+
)
28102817
return value
28112818

28122819

@@ -2859,23 +2866,6 @@ def __getattr__(name: str) -> int:
28592866
"Scancode",
28602867
"KeySym",
28612868
# --- From event_constants.py ---
2862-
"KMOD_NONE",
2863-
"KMOD_LSHIFT",
2864-
"KMOD_RSHIFT",
2865-
"KMOD_SHIFT",
2866-
"KMOD_LCTRL",
2867-
"KMOD_RCTRL",
2868-
"KMOD_CTRL",
2869-
"KMOD_LALT",
2870-
"KMOD_RALT",
2871-
"KMOD_ALT",
2872-
"KMOD_LGUI",
2873-
"KMOD_RGUI",
2874-
"KMOD_GUI",
2875-
"KMOD_NUM",
2876-
"KMOD_CAPS",
2877-
"KMOD_MODE",
2878-
"KMOD_RESERVED",
28792869
"MOUSEWHEEL_NORMAL",
28802870
"MOUSEWHEEL_FLIPPED",
28812871
"MOUSEWHEEL",

tcod/event_constants.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -540,23 +540,6 @@
540540
}
541541

542542
__all__ = [
543-
"KMOD_NONE",
544-
"KMOD_LSHIFT",
545-
"KMOD_RSHIFT",
546-
"KMOD_SHIFT",
547-
"KMOD_LCTRL",
548-
"KMOD_RCTRL",
549-
"KMOD_CTRL",
550-
"KMOD_LALT",
551-
"KMOD_RALT",
552-
"KMOD_ALT",
553-
"KMOD_LGUI",
554-
"KMOD_RGUI",
555-
"KMOD_GUI",
556-
"KMOD_NUM",
557-
"KMOD_CAPS",
558-
"KMOD_MODE",
559-
"KMOD_SCROLL",
560543
"MOUSEWHEEL_NORMAL",
561544
"MOUSEWHEEL_FLIPPED",
562545
"MOUSEWHEEL",

tests/test_deprecated.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ def test_deprecate_mouse_constants() -> None:
5151
_ = tcod.event.BUTTON_LMASK
5252

5353

54+
def test_deprecate_kmod_constants() -> None:
55+
with pytest.warns(FutureWarning, match=r"Modifier.LSHIFT"):
56+
_ = tcod.event.KMOD_LSHIFT
57+
with pytest.warns(FutureWarning, match=r"Modifier.GUI"):
58+
_ = tcod.event.KMOD_GUI
59+
60+
5461
def test_line_where() -> None:
5562
with pytest.warns():
5663
where = tcod.libtcodpy.line_where(1, 0, 3, 4)

0 commit comments

Comments
 (0)