Newer
Older
import sys
from PySide2 import QtCore, QtWidgets, QtGui
import subprocess
class MainWindow(QtWidgets.QWidget):
def __init__(self):
super().__init__()
self.label_head = QtWidgets.QLabel("Alien Head")
self.label_head_color = QtWidgets.QLabel()
self.label_logo = QtWidgets.QLabel("Side Logo")
self.label_logo_color = QtWidgets.QLabel()
self.button_head = QtWidgets.QPushButton("Change Head Color")
self.button_logo = QtWidgets.QPushButton("Change Logo Color")
self.set_labels_to_current_color()
self.layout_head = QtWidgets.QVBoxLayout()
self.layout_logo = QtWidgets.QVBoxLayout()
self.layout_head.addWidget(self.label_head)
self.layout_head.addWidget(self.label_head_color)
self.layout_head.addWidget(self.button_head)
self.layout_logo.addWidget(self.label_logo)
self.layout_logo.addWidget(self.label_logo_color)
self.layout_logo.addWidget(self.button_logo)
self.layout = QtWidgets.QHBoxLayout()
self.layout.addLayout(self.layout_head)
self.layout.addLayout(self.layout_logo)
self.setLayout(self.layout)
self.button_head.clicked.connect(self.select_new_head_color)
self.button_logo.clicked.connect(self.select_new_logo_color)
def set_labels_to_current_color(self):
#find colors from system
#headOutput = subprocess.run(["cat", "/sys/devices/platform/alienware-wmi/rgb_zones/"+"zone00"], text=True)
#logoOutput = subprocess.run(["cat", "/sys/devices/platform/alienware-wmi/rgb_zones/"+"zone01"], text=True)
#Turn output into rgb
#head = QtGui.QColor(int(headOutput.stdout[:2],16),int(headOutput.stdout[2:2],16),int(headOutput.stdout[4:2],16))
#logo = QtGui.QColor(int(logoOutput.stdout[:2],16),int(logoOutput.stdout[2:2],16),int(logoOutput.stdout[4:2],16))
#self.label_head_color.setStyleSheet("QLabel {background:rgb("+str(head.red())+","+str(head.green())+","+str(head.blue())+");}")
#self.label_logo_color.setStyleSheet("QLabel {background:rgb("+str(logo.red())+","+str(logo.green())+","+str(logo.blue())+");}")
pass
@QtCore.Slot()
def select_new_head_color(self):
new_color = QtWidgets.QColorDialog.getColor(title="Select New Head Color")
self.change_head_color(new_color)
self.set_labels_to_current_color()
@QtCore.Slot()
def select_new_logo_color(self):
new_color = QtWidgets.QColorDialog.getColor(title="Select New Logo Color")
self.change_logo_color(new_color)
self.set_labels_to_current_color()
@QtCore.Slot()
def change_head_color(self, new_color):
color = "{0:0{1}x}".format(new_color.red(),2) + "{0:0{1}x}".format(new_color.green(),2) + "{0:0{1}x}".format(new_color.blue(),2)
subprocess.run(["pkexec", "echo", color, ">", "/sys/devices/platform/alienware-wmi/rgb_zones/"+"zone00"])
@QtCore.Slot()
def change_logo_color(self, new_color):
color = "{0:0{1}x}".format(new_color.red(),2) + "{0:0{1}x}".format(new_color.green(),2) + "{0:0{1}x}".format(new_color.blue(),2)
subprocess.run(["pkexec", "echo", color, ">", "/sys/devices/platform/alienware-wmi/rgb_zones/"+"zone01"])
if __name__ == "__main__":
app = QtWidgets.QApplication([])
window = MainWindow()
window.show()
sys.exit(app.exec_())