1414import base64
1515from queue import Queue
1616import platform
17- import objc
18- from Foundation import NSObject , NSRunLoop , NSDefaultRunLoopMode , NSDistributedNotificationCenter
19- import AppKit
2017from aprspy import APRS
2118
2219IS_DARK_MODE = True
20+ IS_MAC = platform .system () == "Darwin"
21+ IS_WINDOWS = platform .system () == "Windows"
2322
2423symbol_map = {
2524 # Primary Table ('/')
320319 ,"CMD:Settings:Display:Scroll Speed:<0 to 65,535>"
321320 ,"CMD:Settings:Display:Invert:<True/False>" ]
322321
322+ if IS_MAC :
323+ import objc
324+ from Foundation import NSObject , NSDistributedNotificationCenter
325+ import AppKit
323326
324- class AppearanceObserver (NSObject ):
325- def darkModeChanged_ (self , notification ):
326- appearance = AppKit .NSApplication .sharedApplication ().effectiveAppearance ().name ()
327- is_dark = "Dark" in appearance
328- print ("Dark mode is now" , "enabled" if is_dark else "disabled" )
329- global IS_DARK_MODE
330- if is_dark :
331- IS_DARK_MODE = True
332- print ("Dark mode is now" , "enabled" )
333- else :
334- IS_DARK_MODE = False
335- print ("Dark mode is now" , "disabled" )
336- global window
337- window .change_text_colors ()
327+ class AppearanceObserver (NSObject ):
328+ def getDarkMode (self ):
329+ appearance = AppKit .NSApplication .sharedApplication ().effectiveAppearance ().name ()
330+ is_dark = "Dark" in appearance
331+ return is_dark
332+
333+ def darkModeChanged_ (self , notification ):
334+ global IS_DARK_MODE
335+ IS_DARK_MODE = self .getDarkMode ()
336+ global window
337+ window .change_text_colors ()
338338
339339class SerialThread (QThread ):
340340 message_received = Signal (str )
@@ -407,11 +407,11 @@ def __init__(self):
407407 }
408408
409409 self .tag_colors_light_mode = {
410- "Sent" : "blue" ,
411- "Received" : "green" ,
412- "Modem" : "orange" ,
413- "SD" : "red" ,
414- "Message" : "purple" ,
410+ "Sent" : "#005EA2" , # deep azure blue
411+ "Received" : "#2E8B57" , # medium sea green
412+ "Modem" : "#D99000" , # warm mustard gold
413+ "SD" : "#C14444" , # muted brick red
414+ "Message" : "#A64CA6" , # rich orchid purple
415415 }
416416
417417 def toggle_auto_scroll (self , state ):
@@ -659,7 +659,6 @@ def filter_log_entries(self, selected_tag):
659659 self .render_log_entry (entry )
660660
661661 def change_text_colors (self ):
662- print ("changing colors" )
663662 self .log_output .clear ()
664663 for entry in self .log_entries :
665664 self .render_log_entry (entry )
@@ -965,10 +964,8 @@ def render_msg_entry(self, entry):
965964 tag = entry .get ("tag" , "Message" )
966965 global IS_DARK_MODE
967966 if IS_DARK_MODE :
968- print ("using dark mode colors" )
969967 color = self .tag_colors_dark_mode .get (tag , "white" )
970968 else :
971- print ("using light mode colors" )
972969 color = self .tag_colors_light_mode .get (tag , "black" )
973970
974971 fmt = QTextCharFormat ()
@@ -993,10 +990,10 @@ def render_log_entry(self, entry):
993990 tag = entry .get ("tag" , "Received" )
994991 global IS_DARK_MODE
995992 if IS_DARK_MODE :
996- print ("using dark mode colors " )
993+ print ("dark mode color " )
997994 color = self .tag_colors_dark_mode .get (tag , "white" )
998995 else :
999- print ("using light mode colors " )
996+ print ("light mode color " )
1000997 color = self .tag_colors_light_mode .get (tag , "black" )
1001998
1002999 fmt = QTextCharFormat ()
@@ -1018,9 +1015,7 @@ def render_log_entry(self, entry):
10181015 app = QApplication (sys .argv )
10191016 window = HamMessengerGUI ()
10201017
1021- system = platform .system ()
1022-
1023- if system == "Darwin" : # macOS
1018+ if IS_MAC : # macOS
10241019 try :
10251020 # set up dark mode monitoring
10261021 AppKit .NSApplication .sharedApplication ()
@@ -1033,13 +1028,13 @@ def render_log_entry(self, entry):
10331028 "AppleInterfaceThemeChangedNotification" ,
10341029 None
10351030 )
1036- # Print current dark mode
1037- IS_DARK_MODE = AppKit . NSApplication . sharedApplication (). effectiveAppearance (). name ()
1038- print ( "Initial mode:" , "Dark" if "Dark" in IS_DARK_MODE else "Light" )
1031+ # get current dark mode
1032+ IS_DARK_MODE = observer . getDarkMode ()
1033+
10391034 except Exception :
10401035 pass
10411036
1042- elif system == "Windows" :
1037+ elif IS_WINDOWS :
10431038 try :
10441039 pass
10451040 except Exception :
0 commit comments