-
Notifications
You must be signed in to change notification settings - Fork 1
/
ayatool_qt.py
executable file
·183 lines (141 loc) · 5.29 KB
/
ayatool_qt.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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/usr/bin/env python
# Copyright (C) 2017 Ricky K. Thomson
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# u should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# VERSION : 0.3
#
# Vendor ID : 3938
# Product ID : 1101
from PyQt4 import QtCore, QtGui
import sys, os
import ayatoolgui
import blackweb_aya
class config():
def __init__(self):
global rgb, profile, ledmode, polling, smartkey
class AyaTool(QtGui.QMainWindow, ayatoolgui.Ui_MainWindow):
def __init__(self):
super(self.__class__, self).__init__()
self.setupUi(self)
# set up connect signals
self.btnUpdateMouse.activated.connect(self.UpdateMouse)
self.btnFactoryReset.activated.connect(self.FactoryReset)
self.btnExit.activated.connect(self.Exit)
self.btnGithub.activated.connect(self.Github)
self.btnAbout.activated.connect(self.About)
self.comboMousePolling.currentIndexChanged.connect(self.PollingRate)
self.comboProfile.currentIndexChanged.connect(self.Profile)
self.comboSmartKey.currentIndexChanged.connect(self.SmartKey)
self.btnApply.clicked.connect(self.UpdateMouse)
self.radioLedOff.clicked.connect(self.LedMode)
self.radioLedOn.clicked.connect(self.LedMode)
self.radioLedBreathe.clicked.connect(self.LedMode)
self.radioLedCycle.clicked.connect(self.LedMode)
self.hboxLedColor.addWidget(ColorBox())
# open the USB device
blackweb_aya.open_usb()
# get the current profile
config.profile = blackweb_aya.get_profile()
self.comboProfile.setCurrentIndex(config.profile -1)
# get the smartkey
config.smartkey = 1 # find out how to get this value
self.comboSmartKey.setCurrentIndex(config.smartkey -1)
# get the current color
config.rgb = blackweb_aya.get_color(config.profile)
ColorBox.setStyleSheet(self, "QWidget#ColorBox { background-color: rgb(%d,%d,%d) }" % (config.rgb[0],config.rgb[1],config.rgb[2]))
# get the current LED mode
config.ledmode = blackweb_aya.get_ledmode(config.profile)
print config.ledmode
if config.ledmode == 0:
self.radioLedOn.setChecked(1)
elif config.ledmode == 1:
self.radioLedOff.setChecked(1)
elif config.ledmode == 2:
self.radioLedBreathe.setChecked(1)
elif config.ledmode == 3:
self.radioLedCycle.setChecked(1)
config.polling = blackweb_aya.get_polling(config.profile)
self.comboMousePolling.setCurrentIndex(config.polling)
# todo:
# implement reading current values for:
# * polling rate
# * smart key
#close the USB device
blackweb_aya.close_usb()
def UpdateMouse(self):
blackweb_aya.open_usb()
blackweb_aya.set_profile(config.profile)
blackweb_aya.set_ledmode(config.profile,config.ledmode)
blackweb_aya.set_color(config.profile, config.rgb[0],config.rgb[1],config.rgb[2])
blackweb_aya.set_polling(config.profile,config.polling)
blackweb_aya.set_smartkey(config.smartkey)
blackweb_aya.store_settings(config.profile)
blackweb_aya.close_usb()
def PollingRate(self,i):
config.polling = i
def LedMode(self):
if self.radioLedOff.isChecked():
config.ledmode = 0
if self.radioLedOn.isChecked():
config.ledmode = 1
if self.radioLedBreathe.isChecked():
config.ledmode = 2
if self.radioLedCycle.isChecked():
config.ledmode = 3
#print config.ledmode
def Profile(self,i):
config.profile = i +1
def SmartKey(self,i):
config.smartkey = i +1
def FactoryReset(self):
blackweb_aya.open_usb()
blackweb_aya.factory_reset()
#blackweb_aya.store_settings(config.profile)
blackweb_aya.close_usb()
def Exit(self):
sys.exit()
def Github(self):
# maybe a better way to do this?
os.system("xdg-open " + "http://github.com/Jigoku/blackweb_aya")
def About(self):
# TODO About dialog
print ("test")
class ColorBox(QtGui.QFrame):
def __init__(self,parent=None):
super(ColorBox,self).__init__(parent)
# setup ColorBox widget
self.color = QtCore.Qt.white
self.setFixedHeight(20)
self.setFrameStyle(1)
self.setObjectName("ColorBox");
self.setStyleSheet("QWidget { border-color: rgba(0,0,0,0)}")
def mousePressEvent(self, e):
if e.buttons() == QtCore.Qt.LeftButton:
# spawn the color dialog
col = QtGui.QColorDialog.getColor(self.color, self)
if col.isValid():
config.rgb = [col.red(), col.green(), col.blue()]
# update ColorButton background color
self.setStyleSheet("QWidget#ColorBox { background-color: rgb(%d,%d,%d) }" % (config.rgb[0],config.rgb[1],config.rgb[2]))
#Possibly preview the LED color, by setting it, without storing the setting here?
#blackweb_aya.open_usb()
#blackweb_aya.set_ledmode(config.profile,config.ledmode)
#blackweb_aya.set_color(config.profile, config.rgb[0],config.rgb[1],config.rgb[2])
#blackweb_aya.close_usb()
def main():
app = QtGui.QApplication(sys.argv)
form = AyaTool()
form.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()