Skip to content

Commit 3a0dc2f

Browse files
committed
fix icon that was broken by resizable
1 parent 43ec63d commit 3a0dc2f

File tree

5 files changed

+18
-30
lines changed

5 files changed

+18
-30
lines changed

src/keyboard_event/keyboard_event/keyboard.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ def scancode_to_color(scancode):
2727
if scancode == 0:
2828
return 255, 0, 0
2929
brightness = 255
30-
r, g, b = colorsys.hsv_to_rgb(
31-
(scancode % 30) / 30, 0.5, 1
32-
)
30+
r, g, b = colorsys.hsv_to_rgb((scancode % 30) / 30, 0.5, 1)
3331
return int(r * brightness), int(g * brightness), int(b * brightness)
3432

3533

@@ -57,21 +55,26 @@ def sdl_thread(
5755
stop_event: threading.Event,
5856
sub_input: Callable[[Key], None] = lambda *_: None,
5957
):
60-
r, g, b = colorsys.hsv_to_rgb(
61-
random.random(), (random.random() + 1) / 2, 1
62-
)
58+
r, g, b = colorsys.hsv_to_rgb(random.random(), (random.random() + 1) / 2, 1)
6359
back_color = int(r * 255), int(g * 255), int(b * 255)
6460

6561
sdl2.ext.init()
66-
window = sdl2.ext.Window("Input", size=(100, 100), flags=sdl2.SDL_WINDOW_RESIZABLE)
67-
renderer = sdl2.ext.Renderer(window)
62+
sdl2.SDL_SetHint(sdl2.SDL_HINT_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR, b"0")
63+
window = sdl2.ext.Window(
64+
"Input",
65+
size=(150, 150),
66+
# flags=sdl2.SDL_WINDOW_RESIZABLE, # icon disapears if used
67+
)
6868

6969
pkg_share = get_package_share_directory("keyboard_event")
7070
surface_icon = sdl2.ext.load_img(
7171
os.path.join(pkg_share, "icons", "gogo.png")
7272
# "/home/elian/Motion-Stack/src/keyboard_event/icons/gogo.png"
7373
)
74+
sdl2.SDL_SetWindowIcon(window.window, surface_icon)
75+
renderer = sdl2.ext.Renderer(window)
7476
window.show()
77+
7578
surface_gogo_calm = sdl2.ext.load_img(
7679
os.path.join(pkg_share, "icons", "gogo.png"),
7780
# "/home/elian/Motion-Stack/src/keyboard_event/icons/gogo.png"
@@ -84,8 +87,6 @@ def sdl_thread(
8487
os.path.join(pkg_share, "icons", "gogo_happy2.png")
8588
# "/home/elian/Motion-Stack/src/keyboard_event/icons/gogo_happy2.png"
8689
)
87-
sdl2.SDL_SetWindowIcon(window.window, surface_icon)
88-
8990
texture_gogo_calm = sdl2.SDL_CreateTextureFromSurface(
9091
renderer.sdlrenderer, surface_gogo_calm
9192
)
@@ -95,7 +96,7 @@ def sdl_thread(
9596
texture_gogo_happy2 = sdl2.SDL_CreateTextureFromSurface(
9697
renderer.sdlrenderer, surface_gogo_happy2
9798
)
98-
dst_rect = sdl2.SDL_Rect(0, 0, 100, 100) # x, y, width, height
99+
dst_rect = sdl2.SDL_Rect(0, 0, 150, 150) # x, y, width, height
99100

100101
renderer.color = back_color
101102
renderer.clear()
@@ -138,15 +139,17 @@ def finish():
138139
elif e.type in [
139140
sdl2.SDL_WINDOWEVENT,
140141
]:
142+
sdl2.SDL_SetWindowIcon(window.window, surface_icon)
143+
window.show()
141144
if e.window.event in [
142145
sdl2.SDL_WINDOWEVENT_SIZE_CHANGED,
143146
sdl2.SDL_WINDOWEVENT_RESIZED,
144147
]:
145-
pass # continues to update the window to new size
148+
pass # continues to update the window to new size
146149
else:
147-
continue # does nothing
150+
continue # does nothing
148151
else:
149-
continue # does nothing
152+
continue # does nothing
150153

151154
renderer.color = (
152155
scancode_to_color(list(pressed.keys())[-1])

src/keyboard_event/package.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
33
<package format="3">
44
<name>keyboard_event</name>
5-
<version>1.1.2</version>
5+
<version>1.1.3</version>
66
<description>ROS 2 keyboard event node in the style of sdl</description>
77
<maintainer email="elian.neppel@posteo.eu">elian</maintainer>
88
<license>MIT</license>

src/keyboard_event/pixi-humble.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,8 @@ platforms = [
1212
preview = ["pixi-build"]
1313

1414
[dependencies]
15-
sdl2 = "*"
16-
sdl2_image = "*"
17-
pysdl2 = "*"
1815
ros-humble-keyboard-event = { path = "." }
1916
ros-humble-ros2run = "*"
20-
ros-humble-keyboard-event-msgs = "*"
21-
asyncio_for_robotics = "*"
2217
ros-humble-rmw-cyclonedds-cpp = "*"
2318
ros-humble-rmw-fastrtps-cpp = "*"
2419
ros-humble-rmw-zenoh-cpp = "*"

src/keyboard_event/pixi-jazzy.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,8 @@ platforms = [
1212
preview = ["pixi-build"]
1313

1414
[dependencies]
15-
# sdl2 = "*"
16-
# sdl2_image = "*"
17-
# pysdl2 = "*"
1815
ros-jazzy-keyboard-event = { path = "." }
1916
ros-jazzy-ros2run = "*"
20-
# ros-jazzy-keyboard-event-msgs = "*"
21-
# asyncio_for_robotics = "*"
2217
ros-jazzy-rmw-cyclonedds-cpp = "*"
2318
ros-jazzy-rmw-fastrtps-cpp = "*"
2419
ros-jazzy-rmw-zenoh-cpp = "*"

src/keyboard_event/pixi-kilted.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,8 @@ platforms = [
1212
preview = ["pixi-build"]
1313

1414
[dependencies]
15-
sdl2 = "*"
16-
sdl2_image = "*"
17-
pysdl2 = "*"
1815
ros-kilted-keyboard-event = { path = "." }
1916
ros-kilted-ros2run = "*"
20-
ros-kilted-keyboard-event-msgs = "*"
21-
asyncio_for_robotics = "*"
2217
ros-kilted-rmw-cyclonedds-cpp = "*"
2318
ros-kilted-rmw-fastrtps-cpp = "*"
2419
ros-kilted-rmw-zenoh-cpp = "*"

0 commit comments

Comments
 (0)