forked from Ultrawipf/OpenFFBoard-configurator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuttonconf_ui.py
149 lines (116 loc) · 5.01 KB
/
buttonconf_ui.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
from PyQt5.QtWidgets import QMainWindow
from PyQt5.QtWidgets import QDialog
from PyQt5.QtWidgets import QWidget,QGroupBox
from PyQt5.QtWidgets import QMessageBox,QVBoxLayout,QCheckBox,QButtonGroup,QPushButton,QLabel,QSpinBox,QComboBox
from PyQt5 import uic
import main
from optionsdialog import OptionsDialog,OptionsDialogGroupBox
from helper import res_path,classlistToIds
class ButtonOptionsDialog(OptionsDialog):
def __init__(self,name,id, main):
self.main = main
self.dialog = OptionsDialogGroupBox(name,main)
if(id == 0): # local buttons
self.dialog = (LocalButtonsConf(name,self.main))
elif(id == 1):
self.dialog = (SPIButtonsConf(name,self.main))
elif(id == 2):
self.dialog = (ShifterButtonsConf(name,self.main))
OptionsDialog.__init__(self, self.dialog,main)
class LocalButtonsConf(OptionsDialogGroupBox):
def __init__(self,name,main):
self.main = main
OptionsDialogGroupBox.__init__(self,name,main)
self.buttonBox = QGroupBox("Pins")
self.buttonBoxLayout = QVBoxLayout()
self.buttonBox.setLayout(self.buttonBoxLayout)
def initUI(self):
vbox = QVBoxLayout()
self.polBox = QCheckBox("Invert")
vbox.addWidget(self.polBox)
self.buttongroup = QButtonGroup()
self.buttongroup.setExclusive(False)
vbox.addWidget(self.buttonBox)
self.setLayout(vbox)
def initButtons(self,num):
#delete buttons
self.num = num
# Remove buttons
for i in range(self.buttonBoxLayout.count()):
b = self.buttonBoxLayout.takeAt(0)
self.buttonBoxLayout.removeItem(b)
b.widget().deleteLater()
for b in self.buttongroup.buttons():
self.buttongroup.removeButton(b)
self.buttonBox.update()
for i in range(self.num):
cb = QCheckBox(str(i+1))
self.buttongroup.addButton(cb,i)
self.buttonBoxLayout.addWidget(cb)
def localcb(mask):
for i in range(self.num):
self.buttongroup.button(i).setChecked(mask & (1 << i))
self.main.comms.serialGetAsync("local_btnmask?",localcb,int)
def apply(self):
mask = 0
for i in range(self.num):
if(self.buttongroup.button(i).isChecked()):
mask |= 1 << i
self.main.comms.serialWrite("local_btnmask="+str(mask))
self.main.comms.serialWrite("local_btnpol="+("1" if self.polBox.isChecked() else "0"))
def readValues(self):
self.main.comms.serialGetAsync("local_btnpins?",self.initButtons,int)
self.main.comms.serialGetAsync("local_btnpol?",self.polBox.setChecked,int)
class SPIButtonsConf(OptionsDialogGroupBox):
def __init__(self,name,main):
self.main = main
OptionsDialogGroupBox.__init__(self,name,main)
def initUI(self):
vbox = QVBoxLayout()
vbox.addWidget(QLabel("Buttons"))
self.numBtnBox = QSpinBox()
self.numBtnBox.setMinimum(0)
self.numBtnBox.setMaximum(32)
vbox.addWidget(self.numBtnBox)
vbox.addWidget(QLabel("Mode"))
self.modeBox = QComboBox()
vbox.addWidget(self.modeBox)
self.polBox = QCheckBox("Invert")
vbox.addWidget(self.polBox)
self.setLayout(vbox)
def apply(self):
self.main.comms.serialWrite("spibtn_mode="+str(self.modeBox.currentData()))
self.main.comms.serialWrite("spi_btnnum="+str(self.numBtnBox.value()))
self.main.comms.serialWrite("spi_btnpol="+("1" if self.polBox.isChecked() else "0"))
def readValues(self):
self.main.comms.serialGetAsync("spi_btnnum?",self.numBtnBox.setValue,int)
self.modeBox.clear()
def modecb(mode):
modes = mode.split("\n")
modes = [m.split(":") for m in modes if m]
for m in modes:
self.modeBox.addItem(m[0],m[1])
self.main.comms.serialGetAsync("spibtn_mode?",self.modeBox.setCurrentIndex,int)
self.main.comms.serialGetAsync("spibtn_mode!",modecb)
self.main.comms.serialGetAsync("spi_btnpol?",self.polBox.setChecked,int)
class ShifterButtonsConf(OptionsDialogGroupBox):
def __init__(self,name,main):
self.main = main
OptionsDialogGroupBox.__init__(self,name,main)
def initUI(self):
vbox = QVBoxLayout()
vbox.addWidget(QLabel("Mode"))
self.modeBox = QComboBox()
vbox.addWidget(self.modeBox)
self.setLayout(vbox)
def apply(self):
self.main.comms.serialWrite("shifter_mode="+str(self.modeBox.currentData()))
def readValues(self):
self.modeBox.clear()
def modecb(mode):
modes = mode.split("\n")
modes = [m.split(":") for m in modes if m]
for m in modes:
self.modeBox.addItem(m[0],m[1])
self.main.comms.serialGetAsync("shifter_mode?",self.modeBox.setCurrentIndex,int)
self.main.comms.serialGetAsync("shifter_mode!",modecb)