Skip to content

Commit

Permalink
Add minimize to tray feature
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexIII committed Jan 15, 2023
1 parent b2f6f00 commit 30aab48
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 8 deletions.
6 changes: 5 additions & 1 deletion GUI/AppColors.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from enum import Enum
from typing import *

class Colors(Enum):
DARK_GREY = '#202020'
Expand All @@ -8,4 +9,7 @@ class Colors(Enum):
YELLOW = '#f1c232'
RED = '#f44336'
BLUE = '#1A6497'


def rgb(self) -> Tuple[int, int, int]:
color = self.value.lstrip('#')
return tuple(int(color[i:i+2], 16) for i in (0, 2, 4))
45 changes: 40 additions & 5 deletions GUI/AppGUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from GUI.QRadioButtonSet import QRadioButtonSet
from GUI.AppColors import Colors
from GUI.ThermalUnitWidget import ThermalUnitWidget
from GUI.QGageTrayIcon import QGageTrayIcon

GUI_ICON = 'icons/gaugeIcon.png'

Expand Down Expand Up @@ -47,10 +48,13 @@ class TCC_GUI(QtWidgets.QWidget):
FAILSAFE_CPU_TEMP = 95
FAILSAFE_GPU_TEMP = 85
APP_NAME = "Thermal Control Center for Dell G15 5515"
APP_VERSION = "1.0.0"
APP_VERSION = "1.1.0"
APP_DESCRIPTION = "This app is an open-source replacement for Alienware Control Center "
APP_URL = "github.com/AlexIII/tcc-g15"

GPU_COLOR_LIMITS = (72, 85)
CPU_COLOR_LIMITS = (85, 95)

def __init__(self, awcc: AWCCThermal):
super().__init__()
self._awcc = awcc
Expand All @@ -64,12 +68,30 @@ def __init__(self, awcc: AWCCThermal):
alert("About", f"{self.APP_NAME} v{self.APP_VERSION}", f"{self.APP_DESCRIPTION}\n{self.APP_URL}")
)

# Set up tray icon
trayIcon = QGageTrayIcon((self.GPU_COLOR_LIMITS, self.CPU_COLOR_LIMITS))
menu = QtWidgets.QMenu()
showAction = menu.addAction("Show")
showAction.triggered.connect(self.showNormal)
exitAction = menu.addAction("Exit")
exitAction.triggered.connect(self.close)
tray = QtWidgets.QSystemTrayIcon(self)
tray.setIcon(trayIcon)
tray.setContextMenu(menu)
tray.show()

def onTrayIconActivated(trigger):
if trigger == QtWidgets.QSystemTrayIcon.ActivationReason.DoubleClick:
self.showNormal()
self.activateWindow()
self.connect(tray, QtCore.SIGNAL("activated(QSystemTrayIcon::ActivationReason)"), onTrayIconActivated)

# Set up GUI
self.setObjectName('QMainWindow')
self.setWindowTitle(self.APP_NAME)

self._thermalGPU = ThermalUnitWidget(self, 'GPU', tempMinMax= (0, 95), tempColorLimits= (72, 85), fanMinMax= (0, 5500), sliderMaxAndTick= (120, 20))
self._thermalCPU = ThermalUnitWidget(self, 'CPU', tempMinMax= (0, 110), tempColorLimits= (85, 95), fanMinMax= (0, 5500), sliderMaxAndTick= (120, 20))
self._thermalGPU = ThermalUnitWidget(self, 'GPU', tempMinMax= (0, 95), tempColorLimits= self.GPU_COLOR_LIMITS, fanMinMax= (0, 5500), sliderMaxAndTick= (120, 20))
self._thermalCPU = ThermalUnitWidget(self, 'CPU', tempMinMax= (0, 110), tempColorLimits= self.CPU_COLOR_LIMITS, fanMinMax= (0, 5500), sliderMaxAndTick= (120, 20))

lTherm = QtWidgets.QHBoxLayout()
lTherm.addWidget(self._thermalGPU)
Expand Down Expand Up @@ -148,6 +170,9 @@ def updateOutput():
self._modeSwitch.setChecked(ThermalMode.G_Mode.value)
print('Fail-safe tripped!')

# Update tray icon
trayIcon.update((gpuTemp, cpuTemp))
tray.setIcon(trayIcon)

self._periodicTask = QPeriodic(self, self.TEMP_UPD_PERIOS_MS, updateOutput)
updateOutput()
Expand All @@ -158,17 +183,27 @@ def updateOutput():

def closeEvent(self, event):
self._periodicTask.stop()
prevMode = self._modeSwitch.getChecked()
self._modeSwitch.setChecked(ThermalMode.Balanced.value)
alert("Mode changed", "Thermal mode has been reset to Balanced")
if prevMode != ThermalMode.Balanced.value:
alert("Mode changed", "Thermal mode has been reset to Balanced")
event.accept()

def changeEvent(self, event):
# Intercept minimize event, hide window instead
if event.type() == QtCore.QEvent.WindowStateChange and self.windowState() & QtCore.Qt.WindowMinimized:
event.ignore()
self.hide()
return
super().changeEvent(event)

def testWMIsupport(self):
try:
pass
except:
pass

def runApp():
def runApp() -> int:
app = QtWidgets.QApplication([])

# Setup backend
Expand Down
31 changes: 31 additions & 0 deletions GUI/QGageTrayIcon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from typing import *
from PySide6 import QtCore, QtGui
from GUI.AppColors import Colors

class QGageTrayIcon(QtGui.QPixmap):
_SIZE = (16, 16)

def __init__(self, tempColorLimits: Optional[Tuple[Tuple[int,int], Tuple[int,int]]]) -> None:
super().__init__(*self._SIZE)
self.fill(QtCore.Qt.transparent)
self._tempColorLimits = tempColorLimits

def update(self, temps: Tuple[int, int]) -> None:
self.fill(QtCore.Qt.transparent)
painter = QtGui.QPainter(self)
font = QtGui.QFont("Consolas", self._SIZE[1] // 2)
painter.setFont(font)

def drawVal(y: int, val: int, limits: Optional[Tuple[int,int]]):
color = Colors.GREEN
if limits:
if val >= limits[1]: color = Colors.RED
elif val >= limits[0]: color = Colors.YELLOW
painter.setPen(QtGui.QColor.fromRgb(*color.rgb()))
x = 2 if val < 100 else -1
painter.drawText(x, y, str(val))

drawVal(self._SIZE[1] // 2 - 1, temps[0], self._tempColorLimits[0] if self._tempColorLimits else None)
drawVal(self._SIZE[1], temps[1], self._tempColorLimits[1] if self._tempColorLimits else None)

painter.end()
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

Open-source alternative to AWCC*

[Download link](https://github.com/AlexIII/tcc-g15/releases/download/1.0.0/Thermal.Control.Center.v1.0.0.exe) *(Note: requires to be run as administrator)*
[Download link](https://github.com/AlexIII/tcc-g15/releases/download/1.0.0/Thermal.Control.Center.v1.0.0.exe) *(Note: the app requires to be run as administrator)*

<img width=600 src="./screen-1.png" />

<img src="./screen-2.png" />

Tested only for Dell G15 5515. May also work on other Dell G15 notebooks.

Please report if it worked / didn't work for you. Your feedback is highly appreciated.
Expand Down Expand Up @@ -42,7 +44,7 @@ If this alternative works out for you, you can safely remove from your PC:

I'll implement these things if the project receives sufficient number of stars*

- Minimize to tray (10x ⭐)
- ✔️ Minimize to tray (10x ⭐)
- Save settings between restarts (20x ⭐)
- Autorun on system startup option (30x ⭐)
- "Target temperature mode" - automatically control the fans to maintain user-specified GPU/CPU temperature (40x ⭐)
Expand Down
Binary file modified screen-1.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 screen-2.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 30aab48

Please sign in to comment.