Skip to content

Commit 43ec63d

Browse files
committed
fixed gogo display and icon
1 parent fd51d4d commit 43ec63d

File tree

13 files changed

+1112
-22588
lines changed

13 files changed

+1112
-22588
lines changed

pixi.lock

Lines changed: 1053 additions & 22555 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pixi.toml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[workspace]
22
name = "motion_stack"
33
description = "From modular robots with distributed computation, to a simple robotic arm, the motion stack provides control for (multi-)limbed systems."
4-
channels = ["https://prefix.dev/conda-forge"]
5-
platforms = ["linux-64", "linux-aarch64", "win-64"]
4+
channels = [ "https://prefix.dev/conda-forge", "https://prefix.dev/motion-stack"]
5+
platforms = ["linux-64", "linux-aarch64"]
66

77
# Dependencies used by all environments
88
[dependencies]
@@ -25,11 +25,17 @@ ninja = ">=1.13.1,<2"
2525
# ROS specific tools
2626
rosdep = "*"
2727
colcon-common-extensions = ">=0.3.0,<0.4"
28-
29-
[pypi-dependencies]
28+
sdl2 = "*"
3029
pysdl2 = "*"
30+
sdl2_image = "*"
31+
sdl2_ttf = "*"
32+
sdl2_mixer = "*"
33+
sdl2_gfx = "*"
3134
asyncio_for_robotics = "*"
32-
pysdl2-dll = "*"
35+
36+
# [pypi-dependencies]
37+
# pysdl2 = "*"
38+
# pysdl2-dll = "*"
3339

3440
[target.linux.dependencies]
3541
libgl-devel = "*"

src/keyboard_event/icons/NotoGorilla.svg

Lines changed: 1 addition & 0 deletions
Loading

src/keyboard_event/icons/gogo.bmp

-2.13 KB
Binary file not shown.

src/keyboard_event/icons/gogo.png

918 Bytes
Loading
-2.13 KB
Binary file not shown.
940 Bytes
Loading
-2.13 KB
Binary file not shown.
1.09 KB
Loading

src/keyboard_event/keyboard_event/keyboard.py

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
import colorsys
33
import dataclasses
44
import os
5+
import random
56
import threading
7+
import time
68
from typing import Any, Callable, Dict, KeysView, List, Self, Tuple
79

810
import asyncio_for_robotics.ros2 as afor
@@ -27,8 +29,7 @@ def scancode_to_color(scancode):
2729
brightness = 255
2830
r, g, b = colorsys.hsv_to_rgb(
2931
(scancode % 30) / 30, 0.5, 1
30-
) # HSV: full saturation, full value
31-
32+
)
3233
return int(r * brightness), int(g * brightness), int(b * brightness)
3334

3435

@@ -56,23 +57,35 @@ def sdl_thread(
5657
stop_event: threading.Event,
5758
sub_input: Callable[[Key], None] = lambda *_: None,
5859
):
60+
r, g, b = colorsys.hsv_to_rgb(
61+
random.random(), (random.random() + 1) / 2, 1
62+
)
63+
back_color = int(r * 255), int(g * 255), int(b * 255)
64+
5965
sdl2.ext.init()
60-
window = sdl2.ext.Window("Input", size=(100, 100))
66+
window = sdl2.ext.Window("Input", size=(100, 100), flags=sdl2.SDL_WINDOW_RESIZABLE)
67+
renderer = sdl2.ext.Renderer(window)
6168

6269
pkg_share = get_package_share_directory("keyboard_event")
70+
surface_icon = sdl2.ext.load_img(
71+
os.path.join(pkg_share, "icons", "gogo.png")
72+
# "/home/elian/Motion-Stack/src/keyboard_event/icons/gogo.png"
73+
)
74+
window.show()
6375
surface_gogo_calm = sdl2.ext.load_img(
64-
os.path.join(pkg_share, "icons", "gogo.bmp")
76+
os.path.join(pkg_share, "icons", "gogo.png"),
77+
# "/home/elian/Motion-Stack/src/keyboard_event/icons/gogo.png"
6578
)
6679
surface_gogo_happy = sdl2.ext.load_img(
67-
os.path.join(pkg_share, "icons", "gogo_happy.bmp")
80+
os.path.join(pkg_share, "icons", "gogo_happy.png")
81+
# "/home/elian/Motion-Stack/src/keyboard_event/icons/gogo_happy.png"
6882
)
6983
surface_gogo_happy2 = sdl2.ext.load_img(
70-
os.path.join(pkg_share, "icons", "gogo_happy2.bmp")
84+
os.path.join(pkg_share, "icons", "gogo_happy2.png")
85+
# "/home/elian/Motion-Stack/src/keyboard_event/icons/gogo_happy2.png"
7186
)
72-
sdl2.SDL_SetWindowIcon(window.window, surface_gogo_calm)
73-
window.show()
87+
sdl2.SDL_SetWindowIcon(window.window, surface_icon)
7488

75-
renderer = sdl2.ext.Renderer(window)
7689
texture_gogo_calm = sdl2.SDL_CreateTextureFromSurface(
7790
renderer.sdlrenderer, surface_gogo_calm
7891
)
@@ -82,16 +95,12 @@ def sdl_thread(
8295
texture_gogo_happy2 = sdl2.SDL_CreateTextureFromSurface(
8396
renderer.sdlrenderer, surface_gogo_happy2
8497
)
85-
sdl2.SDL_FreeSurface(surface_gogo_calm)
86-
sdl2.SDL_FreeSurface(surface_gogo_happy)
87-
sdl2.SDL_FreeSurface(surface_gogo_happy2)
8898
dst_rect = sdl2.SDL_Rect(0, 0, 100, 100) # x, y, width, height
8999

90-
renderer.color = scancode_to_color(0)
100+
renderer.color = back_color
91101
renderer.clear()
92102
sdl2.SDL_RenderCopy(renderer.sdlrenderer, texture_gogo_calm, None, dst_rect)
93103
renderer.present()
94-
window.refresh()
95104

96105
running = True
97106
pressed: Dict[int, Key] = dict()
@@ -125,17 +134,28 @@ def finish():
125134
k = Key.from_sdl(e.key)
126135
asyncio_loop.call_soon_threadsafe(sub_input, k)
127136
del pressed[k.code]
137+
138+
elif e.type in [
139+
sdl2.SDL_WINDOWEVENT,
140+
]:
141+
if e.window.event in [
142+
sdl2.SDL_WINDOWEVENT_SIZE_CHANGED,
143+
sdl2.SDL_WINDOWEVENT_RESIZED,
144+
]:
145+
pass # continues to update the window to new size
146+
else:
147+
continue # does nothing
128148
else:
129-
continue
149+
continue # does nothing
130150

131151
renderer.color = (
132152
scancode_to_color(list(pressed.keys())[-1])
133153
if len(pressed) > 0
134-
else scancode_to_color(0)
154+
else back_color
135155
)
136156
renderer.clear()
137157
if len(pressed) > 0:
138-
cycle = (cycle + 1)%len(texture_cycle)
158+
cycle = (cycle + 1) % len(texture_cycle)
139159
sdl2.SDL_RenderCopy(
140160
renderer.sdlrenderer, texture_cycle[cycle], None, dst_rect
141161
)
@@ -145,7 +165,6 @@ def finish():
145165
)
146166
renderer.present()
147167

148-
window.refresh()
149168
return 0
150169

151170

0 commit comments

Comments
 (0)