Skip to content

Commit

Permalink
added system theme color icon
Browse files Browse the repository at this point in the history
  • Loading branch information
Odizinne authored and Flora committed Jun 22, 2024
1 parent 067e156 commit 4fc54f0
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 38 deletions.
67 changes: 47 additions & 20 deletions bigpicture-external.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import threading
import pygetwindow as gw
from enum import Enum
from PIL import Image, ImageDraw
from PIL import Image
from pystray import Icon, MenuItem, Menu
from PyQt5.QtWidgets import QApplication, QMainWindow, QMessageBox
from PyQt5.QtGui import QIcon
Expand All @@ -21,16 +21,6 @@ class Mode(Enum):
current_mode = None
constants = None

def generate_default_icon():
icon_size = (256, 256)
icon_color = (255, 255, 255, 0)
icon_image = Image.new('RGBA', icon_size, icon_color)
draw = ImageDraw.Draw(icon_image)
draw.ellipse([(50, 50), (200, 200)], fill=(0, 128, 255, 255))
temp_icon_path = "steamos-logo.png"
icon_image.save(temp_icon_path)
return temp_icon_path

def load_constants():
appdata_path = os.path.join(os.environ['APPDATA'], "bigpicture-eternal")
constants_path = os.path.join(appdata_path, 'settings.json')
Expand All @@ -48,7 +38,8 @@ def create_default_settings(constants_path):
settings_template = {
"BIG_PICTURE_KEYWORDS": ["Steam", "mode", "Big", "Picture"],
"GAMEMODE_AUDIO": "TV",
"DESKTOP_AUDIO": "Headset"
"DESKTOP_AUDIO": "Headset",
"UseSystemTheme": False # Added setting for system theme
}
with open(constants_path, 'w') as f:
json.dump(settings_template, f, indent=4)
Expand Down Expand Up @@ -160,14 +151,32 @@ def exit_action(icon, item):
def create_tray_icon(current_mode):
global tray_icon

icon_path = os.path.join(os.path.dirname(__file__), 'steamos-logo.png')
icon_image = Image.open(icon_path)
# Load constants and check for UseSystemTheme setting
constants = load_constants()
use_system_theme = constants.get('UseSystemTheme', False)

menu = create_menu(current_mode)
# Determine icon path based on system theme
if use_system_theme:
# Check Windows theme using winreg
try:
import winreg
reg_path = r'SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize'
with winreg.OpenKey(winreg.HKEY_CURRENT_USER, reg_path) as key:
theme_type = winreg.QueryValueEx(key, 'AppsUseLightTheme')[0]
if theme_type == 1:
icon_path = os.path.join(os.path.dirname(__file__), 'steamos-logo-dark.png')
else:
icon_path = os.path.join(os.path.dirname(__file__), 'steamos-logo-light.png')
except Exception as e:
print(f"Failed to read Windows theme: {e}")
icon_path = os.path.join(os.path.dirname(__file__), 'steamos-logo.png')
else:
icon_path = os.path.join(os.path.dirname(__file__), 'steamos-logo.png')

# Create menu and tray icon
menu = create_menu(current_mode)
icon_image = Image.open(icon_path)
tray_icon = Icon('BigPictureTV', icon=icon_image, menu=menu)
tray_icon.tooltip = 'BigPictureTV'

return tray_icon

def run_tray_icon():
Expand Down Expand Up @@ -226,6 +235,10 @@ def __init__(self):
# Apply stylesheet for grey background and widget styling
self.set_darkmode()

# Connect systemThemeBox to toggle_system_theme function
self.systemThemeBox.setChecked(self.constants.get('UseSystemTheme', False))
self.systemThemeBox.stateChanged.connect(self.toggle_system_theme)

def load_settings(self):
self.constants = load_constants()

Expand All @@ -250,9 +263,9 @@ def save_settings(self):
def set_darkmode(self):
# Define a stylesheet for rounded corners and other widget styles
stylesheet = """
QMainWindow {
background-color: #171d25;
}
QPushButton {
background-color: #32363d;
color: white;
Expand All @@ -261,10 +274,12 @@ def set_darkmode(self):
padding: 5px;
margin: 8px;
}
QLabel {
color: white;
margin: 8px;
}
QLineEdit {
background-color: #24282f;
color: white;
Expand All @@ -273,6 +288,7 @@ def set_darkmode(self):
padding: 3px;
margin: 8px;
}
QTextEdit {
background-color: #24282f;
color: white;
Expand All @@ -281,11 +297,22 @@ def set_darkmode(self):
padding: 5px;
margin: 8px;
}
QCheckBox {
margin: 8px;
}
"""

# Apply the stylesheet to the window
self.setStyleSheet(stylesheet)

def toggle_system_theme(self, state):
if state == 2: # Qt.Checked
self.constants['UseSystemTheme'] = True
else:
self.constants['UseSystemTheme'] = False

def restart_main():
python = sys.executable
os.execl(python, python, *sys.argv)
Expand All @@ -294,10 +321,10 @@ def restart_main():
GAMEMODE_SCREEN = "/external"
DESKTOP_SCREEN = "/internal"
constants = load_constants()
current_mode = Mode.DESKTOP
current_mode = read_current_mode()
SLEEP_TIME = 1

if read_current_mode() != Mode.DESKTOP:
if current_mode != Mode.DESKTOP:
switch_mode(Mode.DESKTOP)

tray_thread = threading.Thread(target=run_tray_icon, daemon=True)
Expand Down
56 changes: 38 additions & 18 deletions design.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>491</width>
<height>372</height>
<height>407</height>
</rect>
</property>
<property name="sizePolicy">
Expand All @@ -24,40 +24,33 @@
<item row="0" column="0">
<widget class="QFrame" name="gridFrame">
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="0">
<item row="3" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>DESKTOP audio device</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>GAMEMODE audio device</string>
</property>
</widget>
</item>
<item row="2" column="1">
<item row="3" column="1">
<widget class="QLineEdit" name="desktopEntry"/>
</item>
<item row="1" column="0">
<item row="2" column="0">
<widget class="QLabel" name="label">
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="text">
<string>Steam Big Picture keywords</string>
</property>
</widget>
</item>
<item row="1" column="1">
<item row="2" column="1">
<widget class="QLineEdit" name="steamEntry"/>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="gamemodeEntry"/>
</item>
<item row="4" column="0" colspan="2">
<widget class="QPushButton" name="saveButton">
<item row="4" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Save and restart</string>
<string>GAMEMODE audio device</string>
</property>
</widget>
</item>
Expand All @@ -81,6 +74,33 @@ p, li { white-space: pre-wrap; }
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLineEdit" name="gamemodeEntry"/>
</item>
<item row="5" column="0" colspan="2">
<widget class="QPushButton" name="saveButton">
<property name="text">
<string>Save and restart</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="systemThemeBox">
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Use system theme for icon</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down
Binary file added steamos-logo-dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added steamos-logo-light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4fc54f0

Please sign in to comment.