11import atexit
22import signal
3+ from pathlib import Path
34from threading import Thread
45
56import rclpy .utilities
7+ from ament_index_python import get_package_share_directory
68from PyQt6 .QtWidgets import QApplication , QWidget
9+ from qt_material import apply_stylesheet
710from rclpy .executors import MultiThreadedExecutor
811
912from gui .gui_node import GUINode
@@ -29,18 +32,27 @@ def run_gui(self) -> None:
2932 # Kills with Control + C
3033 signal .signal (signal .SIGINT , signal .SIG_DFL )
3134
32- # TODO: New method of dark mode
35+ extra_blue = {'success' : '#040444' , 'danger' : '#040444' , 'warning' : '#040444' }
36+ extra_watermelon = {'success' : '#341616' , 'danger' : '#341616' , 'warning' : '#341616' }
3337 # Apply theme
34- # theme_param = self.theme_param.get_parameter_value().string_value
35- # theme_path = Path(get_package_share_directory('gui')) / 'styles' / (theme_param + '.qss')
36-
37- # base_theme = 'dark' if theme_param == 'dark' else 'light'
38- # custom_styles = '\n'
39- # if theme_path.exists():
40- # with theme_path.open(encoding='utf-8') as theme_file:
41- # custom_styles += theme_file.read()
42-
43- # qdarktheme.setup_theme(base_theme, additional_qss=custom_styles)
38+ theme_param = self .theme_param .get_parameter_value ().string_value
39+
40+ match theme_param :
41+ case 'dark' :
42+ base_theme = 'dark_blue.xml'
43+ case 'light' :
44+ base_theme = 'light_blue.xml'
45+ case 'watermelon' :
46+ base_path = Path (get_package_share_directory ('gui' )) / 'styles' / ('watermelon.xml' )
47+ base_theme = base_path .as_posix ()
48+ case _:
49+ base_theme = 'dark_blue.xml'
50+ self .node .get_logger ().info (
51+ 'Theme ' + theme_param + ' not found, defaulting to dark.'
52+ )
53+
54+ extra = extra_watermelon if theme_param == 'watermelon' else extra_blue
55+ apply_stylesheet (self , theme = base_theme , style = '' , extra = extra )
4456
4557 executor = MultiThreadedExecutor ()
4658 executor .add_node (self .node )
0 commit comments