-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathg710tool.py
More file actions
157 lines (122 loc) · 4.53 KB
/
g710tool.py
File metadata and controls
157 lines (122 loc) · 4.53 KB
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
#!/usr/bin/env python2
import sys
import threading
from PyQt4 import QtCore, QtGui
import Xlib.display
import Xlib.ext.xtest
import Xlib.X
import g710
class HotkeyObserver(g710.G710Observer):
keymap = {
'G1': 0x1008FF41,
'G2': 0x1008FF42,
'G3': 0x1008FF43,
'G4': 0x1008FF44,
'G5': 0x1008FF45,
'G6': 0x1008FF46,
'M1': 0x1008FF47,
'M2': 0x1008FF48,
'M3': 0x1008FF49,
'M4': 0x1008FF4A,
'Next track': 0x1008FF17,
'Previous track': 0x1008FF16,
'Stop': 0x1008FF15,
'Play': 0x1008FF14,
'Vol. up': 0x1008FF13,
'Vol. down': 0x1008FF11,
'Mute': 0x1008FF12
}
def __init__(self, display=None):
self.display = display if display else Xlib.display.Display()
def fake_input(self, event, keysym):
Xlib.ext.xtest.fake_input(self.display, event, self.display.keysym_to_keycode(keysym))
self.display.sync()
def fake_press(self, keysym):
self.fake_input(Xlib.X.KeyPress, keysym)
def fake_release(self, keysym):
self.fake_input(Xlib.X.KeyRelease, keysym)
def key_down(self, key):
self.fake_press(self.keymap[key])
def key_up(self, key):
self.fake_release(self.keymap[key])
def status_change(self, game_mode, wasd_light, key_light):
pass
class G710Control(QtGui.QWidget):
_closing = False
# noinspection PyUnresolvedReferences,PyCallByClass,PyTypeChecker,PyArgumentList
def __init__(self):
QtGui.QWidget.__init__(self)
self.g710 = g710.G710()
self.reader = g710.G710Reader(self.g710)
self.reader.add_observer(HotkeyObserver())
self.hotkey_thread = threading.Thread(target=self.reader.loop)
self.hotkey_thread.setDaemon(True)
self.hotkey_thread.start()
self.m1 = QtGui.QCheckBox('M1')
self.m1.stateChanged.connect(self.backlight_changed)
self.m2 = QtGui.QCheckBox('M2')
self.m2.stateChanged.connect(self.backlight_changed)
self.m3 = QtGui.QCheckBox('M3')
self.m3.stateChanged.connect(self.backlight_changed)
self.mr = QtGui.QCheckBox('MR')
self.mr.stateChanged.connect(self.backlight_changed)
hbox = QtGui.QHBoxLayout()
hbox.addWidget(self.m1)
hbox.addWidget(self.m2)
hbox.addWidget(self.m3)
hbox.addWidget(self.mr)
vbox = QtGui.QVBoxLayout(self)
vbox.addLayout(hbox)
vbox.addWidget(QtGui.QLabel('WASD backlight'))
self.wasd = QtGui.QSlider()
self.wasd.setMinimum(0)
self.wasd.setMaximum(4)
self.wasd.setValue(self.g710.backlight['WASD'])
self.wasd.setOrientation(QtCore.Qt.Horizontal)
self.wasd.valueChanged.connect(self.backlight_changed)
vbox.addWidget(self.wasd)
vbox.addWidget(QtGui.QLabel('Keys backlight'))
self.light = QtGui.QSlider()
self.light.setMinimum(0)
self.light.setMaximum(4)
self.light.setValue(self.g710.backlight['keys'])
self.light.setOrientation(QtCore.Qt.Horizontal)
self.light.valueChanged.connect(self.backlight_changed)
vbox.addWidget(self.light)
self.icon = QtGui.QSystemTrayIcon()
self.icon.setIcon(QtGui.QIcon.fromTheme("input-keyboard"))
self.icon.setToolTip("G710Tool")
menu = QtGui.QMenu()
exit_action = menu.addAction("Exit")
exit_action.setIcon(QtGui.QIcon.fromTheme("application-exit"))
exit_action.activated.connect(self.close_right)
self.icon.setContextMenu(menu)
self.icon.activated.connect(self.tray_clicked)
self.icon.show()
self.setWindowTitle('G710Tool v0.1')
def close_right(self):
self._closing = True
self.close()
def closeEvent(self, event):
if self._closing:
event.accept()
else:
self.hide()
event.ignore()
def tray_clicked(self, reason):
if reason == QtGui.QSystemTrayIcon.Trigger:
if self.isVisible():
self.hide()
else:
self.show()
def backlight_changed(self):
self.g710.backlight['M1'] = self.m1.isChecked()
self.g710.backlight['M2'] = self.m2.isChecked()
self.g710.backlight['M3'] = self.m3.isChecked()
self.g710.backlight['MR'] = self.mr.isChecked()
self.g710.backlight['WASD'] = self.wasd.value()
self.g710.backlight['keys'] = self.light.value()
app = QtGui.QApplication(sys.argv)
window = G710Control()
window.show()
sys.exit(app.exec_())