-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
165 lines (125 loc) · 5.22 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# https://www.youtube.com/watch?v=li7esLMuFhE
# https://www.pythonguis.com/pyqt5/
# https://build-system.fman.io/pyqt5-tutorial
# https://github.com/altendky/pyqt-tools/issues/98#issuecomment-968296553
# https://realpython.com/qt-designer-python/
import sys
import subprocess
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.uic import loadUi
from PyQt5 import QtGui
from main_macropad import Ui_MainWindow
from configparser import ConfigParser
from pynput.keyboard import Key, Controller
import pywinctl as pwc
from qt_material import apply_stylesheet
config_object = ConfigParser()
config_object.read("config.ini")
#windowTitles = pwc.getWindowsWithTitle('0 A.D.')
#appWindow = windowTitles[0]
def run_button(button_name):
try:
subprocess.run(button_name)
except:
msg = QMessageBox()
msg.setWindowTitle("Error")
msg.setText("Couldn't execute requested command. Please revise chosen action's code.")
msg.exec_()
class Window(QMainWindow, Ui_MainWindow):
def __init__(self, parent=None):
super().__init__(parent)
self.setupUi(self)
# window stuff
# self.setWindowFlag(Qt.FramelessWindowHint)
self.setWindowTitle('alpha-0.0.2')
self.setWindowIcon(QtGui.QIcon('assets/swmp.ico'))
# self.keyboard = Controller()
# setup buttons
self.buttonGridSetup()
# self.verticalSlider_4.valueChanged.connect(self.onSliderChanged)
# clock timer
timer = QTimer(self)
timer.timeout.connect(self.showTime)
timer.start(1000)
# def onSliderChanged(self, value):
# param = 'https://www.google.com/search?q=' + str(value)
# subprocess.run(['C:\Program Files (x86)\Google\Chrome\Application\chrome.exe',param])
def showTime(self):
current_time = QTime.currentTime()
label_time = current_time.toString('hh:mm')
self.lcdNumber.setDigitCount(5)
self.lcdNumber.display(label_time)
def buttonGridSetup(self):
# row 0 (top)
self.pushButton_00.setText(config_object["button00"]["text"])
self.pushButton_00.clicked.connect(self.onButton00Clicked)
self.pushButton_01.setText(config_object["button01"]["text"])
self.pushButton_01.clicked.connect(self.onButton01Clicked)
self.pushButton_02.setText(config_object["button02"]["text"])
self.pushButton_02.clicked.connect(self.onButton02Clicked)
# row 1 (middle)
self.pushButton_10.setText(config_object["button10"]["text"])
self.pushButton_10.clicked.connect(self.onButton10Clicked)
self.pushButton_11.setText(config_object["button11"]["text"])
self.pushButton_11.clicked.connect(self.onButton11Clicked)
self.pushButton_12.setText(config_object["button12"]["text"])
self.pushButton_12.clicked.connect(self.onButton12Clicked)
# row 2 (bottom)
self.pushButton_20.setText(config_object["button20"]["text"])
self.pushButton_20.clicked.connect(self.onButton20Clicked)
self.pushButton_212.setText(config_object["button212"]["text"])
self.pushButton_212.clicked.connect(self.onButton212Clicked)
def onButton00Clicked(self):
button00config = config_object["button00"]
button00CMD = button00config["cmd"].split(",")
run_button(button00CMD)
def onButton01Clicked(self):
button01config = config_object["button01"]
button01CMD = button01config["cmd"].split(",")
run_button(button01CMD)
def onButton02Clicked(self):
button02config = config_object["button02"]
button02CMD = button02config["cmd"].split(",")
run_button(button02CMD)
# testing some pynput stuff here. Nothing to see.
# button02Key = button02config["key"]
# kc=keyboard.KeyCode.from_char('cmd')
# print(kc)
# print(type(kc))
# print(kc.char)
# print(type(Key.cmd))
# print(button02Key)
# self.keyboard.press(Key.cmd)
# self.keyboard.press('1')
# self.keyboard.release('1')
# self.keyboard.release(Key.cmd)
def onButton10Clicked(self):
button10config = config_object["button10"]
button10CMD = button10config["cmd"].split(",")
run_button(button10CMD)
def onButton11Clicked(self):
button11config = config_object["button11"]
button11CMD = button11config["cmd"].split(",")
run_button(button11CMD)
def onButton12Clicked(self):
button12config = config_object["button12"]
button12CMD = button12config["cmd"].split(",")
run_button(button12CMD)
def onButton20Clicked(self):
button20config = config_object["button20"]
button20CMD = button20config["cmd"].split(",")
run_button(button20CMD)
def onButton212Clicked(self):
button212config = config_object["button212"]
button212CMD = button212config["cmd"].split(",")
run_button(button212CMD)
def main():
app = QApplication(sys.argv)
appConfig = config_object["appConfig"]
apply_stylesheet(app, theme=appConfig["theme"])
win = Window()
win.show()
sys.exit(app.exec())
if __name__ == "__main__":
main()