Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add global hotkeys to change Gmode&&add plot widget #38

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
**/.mypy_cache
dist
build
*.spec
*.spec
.idea
62 changes: 53 additions & 9 deletions src/GUI/AppGUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
from GUI.AppColors import Colors
from GUI.ThermalUnitWidget import ThermalUnitWidget
from GUI.QGaugeTrayIcon import QGaugeTrayIcon
from PySide6.QtCore import Qt, Signal
from windows_toasts import WindowsToaster, Toast, ToastDuration, ToastDisplayImage, ToastImage, ToastImagePosition, \
InteractableWindowsToaster
from GUI import Hotkey
from GUI.plot import Plot_Tem_Speed,InteractiveTemperatureFanCurve

GUI_ICON = 'icons/gaugeIcon.png'

Expand Down Expand Up @@ -83,6 +88,8 @@ class SettingsKey(Enum):
GPUThresholdTemp = "app/fan/gpu/threshold_temp"
FailSafeIsOnFlag = "app/failsafe_is_on_flag"
MinimizeOnCloseFlag = "app/minimize_on_close_flag"
Plot_Tem_Speed_data = "app/plot_data"


def errorExit(message: str, message2: Optional[str] = None) -> None:
if not QtWidgets.QApplication.instance():
Expand Down Expand Up @@ -112,6 +119,8 @@ class TCC_GUI(QtWidgets.QWidget):
_failsafeOn = True
_prevSavedSettingsValues: list = []

Change_Mode = Signal(int)

def __init__(self, awcc: AWCCThermal):
super().__init__()
self._awcc = awcc
Expand Down Expand Up @@ -169,6 +178,8 @@ def onTrayIconActivated(trigger):
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))

self.Plot_Tem_Speed =InteractiveTemperatureFanCurve()

lTherm = QtWidgets.QHBoxLayout()
lTherm.addWidget(self._thermalGPU)
lTherm.addWidget(self._thermalCPU)
Expand Down Expand Up @@ -197,10 +208,10 @@ def updFailsafeIndicator() -> None:

# Fail-safe temp limits
self._limitTempGPU = QtWidgets.QComboBox()
self._limitTempGPU.addItems(list(map(lambda v: str(v), range(50, 91))))
self._limitTempGPU.addItems(list(map(lambda v: str(v), range(30, 91))))
self._limitTempGPU.setToolTip("Threshold GPU temp")
self._limitTempCPU = QtWidgets.QComboBox()
self._limitTempCPU.addItems(list(map(lambda v: str(v), range(50, 101))))
self._limitTempCPU.addItems(list(map(lambda v: str(v), range(30, 101))))
self._limitTempCPU.setToolTip("Threshold CPU temp")
def onLimitGPUChange():
val = self._limitTempGPU.currentText()
Expand All @@ -213,23 +224,25 @@ def onLimitCPUChange():


# Fail-safe checkbox
self._failsafeCB = QtWidgets.QCheckBox("Fail-safe")
self._failsafeCB.setToolTip(f"Switch to G-mode (fans on max) when GPU temp reaches {self.FAILSAFE_GPU_TEMP}°C or CPU reaches {self.FAILSAFE_CPU_TEMP}°C")
_failsafeCB = QtWidgets.QCheckBox("Fail-safe")
_failsafeCB.setToolTip(f"Switch to G-mode (fans on max) when GPU temp reaches {self.FAILSAFE_GPU_TEMP}°C or CPU reaches {self.FAILSAFE_CPU_TEMP}°C")
def onFailsafeCB():
self._failsafeOn = self._failsafeCB.isChecked()
self._failsafeOn = _failsafeCB.isChecked()
self._failsafeTempIsHighTs = 0
self._failsafeTrippedPrevModeStr = None
self._failsafeTempIsHighStartTs = None
updFailsafeIndicator()
self._failsafeCB.toggled.connect(onFailsafeCB)
self._failsafeCB.setChecked(self._failsafeOn)
_failsafeCB.toggled.connect(onFailsafeCB)
_failsafeCB.setChecked(True)

failsafeBox = QtWidgets.QHBoxLayout()
failsafeBox.addWidget(self._failsafeCB)
failsafeBox.addWidget(_failsafeCB)
failsafeBox.addWidget(self._limitTempGPU)
failsafeBox.addWidget(self._limitTempCPU)
failsafeBox.addWidget(failsafeIndicator)

plotBox = QtWidgets.QHBoxLayout()
plotBox.addWidget(self.Plot_Tem_Speed,alignment=QtCore.Qt.AlignCenter)

modeBox = QtWidgets.QHBoxLayout()
modeBox.addWidget(self._modeSwitch, alignment= QtCore.Qt.AlignLeft)
modeBox.addWidget(QtWidgets.QWidget(), alignment= QtCore.Qt.AlignRight) # Insert dummy Widget in order to move the following 'failsafeBox' to the right side
Expand All @@ -238,6 +251,7 @@ def onFailsafeCB():
mainLayout = QtWidgets.QVBoxLayout(self)
mainLayout.addLayout(lTherm)
mainLayout.addLayout(modeBox)
mainLayout.addLayout(plotBox)
mainLayout.setAlignment(QtCore.Qt.AlignTop)
mainLayout.setContentsMargins(10, 0, 10, 0)

Expand Down Expand Up @@ -324,6 +338,11 @@ def updateAppState():
self._updateGaugesTask = QPeriodic(self, self.TEMP_UPD_PERIOD_MS, updateAppState)
updateAppState()
self._updateGaugesTask.start()

self._thermalGPU.speedSliderChanged(updateFanSpeed)
self._thermalCPU.speedSliderChanged(updateFanSpeed)

self._loadAppSettings()

def closeEvent(self, event):
minimizeOnClose = self.settings.value(SettingsKey.MinimizeOnCloseFlag.value)
Expand All @@ -344,6 +363,7 @@ def closeEvent(self, event):
# onExit() connected to systray_Exit
def onExit(self):
print("exit")
self._saveAppSettings()
# Set mode to Balanced before exit
self._updateGaugesTask.stop()
prevMode = self._modeSwitch.getChecked()
Expand Down Expand Up @@ -371,6 +391,7 @@ def _saveAppSettings(self):
self.settings.setValue(SettingsKey.CPUThresholdTemp.value, self.FAILSAFE_CPU_TEMP)
self.settings.setValue(SettingsKey.GPUThresholdTemp.value, self.FAILSAFE_GPU_TEMP)
self.settings.setValue(SettingsKey.FailSafeIsOnFlag.value, self._failsafeOn)
self.settings.setValue(SettingsKey.Plot_Tem_Speed_data.value,self.Plot_Tem_Speed.get_plot_data())

def _loadAppSettings(self):
savedMode = self.settings.value(SettingsKey.Mode.value) or ThermalMode.Balanced.value
Expand All @@ -385,13 +406,32 @@ def _loadAppSettings(self):
self._limitTempGPU.setCurrentText(str(savedTemp))
savedFailsafe = self.settings.value(SettingsKey.FailSafeIsOnFlag.value) or 'True'
self._failsafeCB.setChecked(not (savedFailsafe == 'False'))
savedPlot_Tem_Speed_data = self.settings.value(SettingsKey.Plot_Tem_Speed_data.value)
self.Plot_Tem_Speed.set_plot_data(savedPlot_Tem_Speed_data)


def clearAppSettings(self):
(isYes, _) = confirm("Reset to Default", "Do you want to reset all settings to default?", ("Reset", "Cancel"))
if not isYes: return
self.settings.clear()
self._loadAppSettings()

def G_Mode_key_Pressed(self):

interacttaoster = InteractableWindowsToaster('Questionnaire','432890')
toaster = WindowsToaster('TCC-G15')
newToast = Toast(duration=ToastDuration.Short)
#newToast = Toast(['How are you?'])
# newToast.AddImage(ToastDisplayImage(ToastImage(resourcePath(GUI_ICON))))
if(self._modeSwitch.getChecked() == ThermalMode.G_Mode.value):
self._modeSwitch.setChecked(ThermalMode.Balanced.value)
newToast.text_fields = {'ModeChanged','Thermal mode has been set to Balanced'}
interacttaoster.show_toast(newToast)
else:
self._modeSwitch.setChecked(ThermalMode.G_Mode.value)
newToast.text_fields = {'ModeChanged','Thermal mode has been set to G_Mode'}
interacttaoster.show_toast(newToast)


def runApp(startMinimized = False) -> int:
app = QtWidgets.QApplication([])
Expand Down Expand Up @@ -434,6 +474,10 @@ def runApp(startMinimized = False) -> int:
}}
""")

Gmode_key = Hotkey.HotKey()
Gmode_key.Change_Mode.connect(mainWindow.G_Mode_key_Pressed)
Gmode_key.start()

if startMinimized:
mainWindow.showMinimized()
mainWindow.hide()
Expand Down
24 changes: 24 additions & 0 deletions src/GUI/Hotkey.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import win32con
from ctypes import *
from ctypes.wintypes import *
from PySide6.QtCore import *

class HotKey(QThread):

Change_Mode = Signal(int)
def __init__(self):
super(HotKey, self).__init__()
def run(self):
user32 = windll.user32
while True:
if not user32.RegisterHotKey(None, 1, 0, 128):# G_Mode_key
print("Hotkey registration failed")
try:
msg = MSG()
if user32.GetMessageA(byref(msg), None, 0, 0) != 0:
if msg.message == win32con.WM_HOTKEY:
if msg.wParam == 1:
self.Change_Mode.emit(msg.lParam)
finally:
user32.UnregisterHotKey(None, 1)

Loading