add tab icon

This commit is contained in:
2025-10-23 19:02:28 +08:00
parent 47f7f32f42
commit 62a4de2bad
8 changed files with 49 additions and 7 deletions

View File

@@ -47,8 +47,9 @@ class CtrlGuiNode(Node):
def build_ui(node: CtrlGuiNode) -> None:
"""Build the NiceGUI UI."""
# Add background image using custom CSS
# Add favicon and background image using custom HTML
ui.add_head_html('''
<link rel="icon" href="/static/favicon.ico" type="image/x-icon">
<style>
body {
background-image: url("/static/background.png");
@@ -166,16 +167,16 @@ def main() -> None:
spin_thread = threading.Thread(target=rclpy.spin, args=(node,), daemon=True)
spin_thread.start()
# Build UI for the default page
@ui.page('/')
def main_page():
build_ui(node)
# Add static file serving for background image
from nicegui import app
static_path = os.path.join(os.path.dirname(__file__), '..', 'static')
app.mount('/static', StaticFiles(directory=static_path), name='static')
# Build UI for the default page
@ui.page('/')
def main_page():
build_ui(node)
# Ensure clean shutdown when the process exits
def shutdown() -> None:
try:

View File

@@ -14,7 +14,8 @@ setup(
('share/' + package_name, ['package.xml']),
('share/' + package_name + '/launch', ['launch/ctrlgui.launch.py']),
('share/' + package_name + '/static',
[os.path.join('static', 'background.png')]),
[os.path.join('static', 'background.png'),
os.path.join('static', 'favicon.ico')]),
],
install_requires=['setuptools', 'nicegui>=1.4.0'],
zip_safe=True,

16
static/convert_to_ico.py Normal file
View File

@@ -0,0 +1,16 @@
from PIL import Image
import os
# Open the jpg image
img_path = "/root/workspace/hivecore_ws/hivecore_robot_ctrlgui/static/favicon.jpg"
ico_path = "/root/workspace/hivecore_ws/hivecore_robot_ctrlgui/static/favicon.ico"
# Open and convert the image
img = Image.open(img_path)
# Resize to standard favicon size
img = img.resize((32, 32))
# Save as ico
img.save(ico_path, format='ICO')
print(f"Successfully converted {img_path} to {ico_path}")

24
static/create_favicon.py Normal file
View File

@@ -0,0 +1,24 @@
from PIL import Image, ImageDraw
# Create a simple robot-themed favicon
size = 32
image = Image.new('RGB', (size, size), '#4a86e8') # Blue background
# Draw a simple robot face
draw = ImageDraw.Draw(image)
# Eyes
draw.rectangle([8, 10, 12, 14], fill='white') # Left eye
draw.rectangle([20, 10, 24, 14], fill='white') # Right eye
draw.rectangle([10, 12, 12, 14], fill='black') # Left pupil
draw.rectangle([22, 12, 24, 14], fill='black') # Right pupil
# Mouth - smile
draw.arc([8, 16, 24, 26], 0, 180, fill='white', width=2)
# Antenna
draw.line([16, 2, 16, 6], fill='white', width=2)
# Save as favicon.ico
image.save('/root/workspace/hivecore_ws/hivecore_robot_ctrlgui/static/favicon.ico')
print("Favicon created successfully.")

BIN
static/favicon.backup.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

BIN
static/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

BIN
static/favicon.jpg Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 144 KiB

BIN
static/favicon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 102 B