-
-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathpwmdriver_ui.py
56 lines (44 loc) · 2.11 KB
/
pwmdriver_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
from PyQt6.QtWidgets import QMainWindow
from PyQt6.QtWidgets import QDialog
from PyQt6.QtWidgets import QWidget
from PyQt6.QtWidgets import QMessageBox,QVBoxLayout,QCheckBox,QButtonGroup
from PyQt6 import uic
from helper import res_path,classlistToIds
from PyQt6.QtCore import QTimer
import main
from base_ui import WidgetUI
from base_ui import CommunicationHandler
class PwmDriverUI(WidgetUI,CommunicationHandler):
def __init__(self, main=None, unique=1):
WidgetUI.__init__(self, main,'pwmdriver_ui.ui')
CommunicationHandler.__init__(self)
self.main = main #type: main.MainUi
self.pushButton_apply.clicked.connect(self.apply)
self.register_callback("pwmdrv","freq",self.freq_cb,0,str,typechar='!')
self.register_callback("pwmdrv","freq",self.comboBox_freq.setCurrentIndex,0,int,typechar='?')
self.register_callback("pwmdrv","mode",self.pwmmode_cb,0,str,typechar='!')
self.register_callback("pwmdrv","mode",self.comboBox_mode.setCurrentIndex,0,int,typechar='?')
self.register_callback("pwmdrv","dir",self.checkBox_invert.setChecked,0,int,typechar='?')
self.init_ui()
def init_ui(self):
# Fill menus
self.send_command("pwmdrv","freq",0,'!')
self.send_command("pwmdrv","mode",0,'!')
self.send_command("pwmdrv","dir",0,'?')
def freq_cb(self,modes):
self.comboBox_freq.clear()
modes = [m.split(":") for m in modes.split("\n") if m]
for m in modes:
self.comboBox_freq.addItem(m[0],m[1])
self.send_command("pwmdrv","freq",0,'?')
def pwmmode_cb(self,modes):
self.comboBox_mode.clear()
modes = [m.split(":") for m in modes.split("\n") if m]
for m in modes:
self.comboBox_mode.addItem(m[0],m[1])
self.send_command("pwmdrv","mode",0,'?')
def apply(self):
self.send_value("pwmdrv","mode",self.comboBox_mode.currentData())
self.send_value("pwmdrv","freq",self.comboBox_freq.currentData())
self.send_value("pwmdrv","dir",1 if self.checkBox_invert.isChecked() else 0)
self.init_ui() # Update UI