forked from leidawt/resistor_calculator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrol.py
61 lines (54 loc) · 2.34 KB
/
control.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
"""
本代码由[Tkinter布局助手]生成
官网:https://www.pytk.net
QQ交流群:905019785
在线反馈:https://support.qq.com/product/618914
"""
# 示例下载 https://www.pytk.net/blog/1702564569.html
import utils
from res_calculator import ResCalculator
class Controller:
# 导入UI类后,替换以下的 object 类型,将获得 IDE 属性提示功能
ui: object
def __init__(self):
self.calculator = ResCalculator()
def init(self, ui):
"""
得到UI实例,对组件进行初始化配置
"""
self.ui = ui
# TODO 组件初始化 赋值操作
def handle_divider_cal(self, evt):
e_type = int(self.ui.res_e_series.get())
self.calculator.set_res_table(e_type)
vin = utils.get_float_input(self, "lhbmtn25")
vout = utils.get_float_input(self, "lhbmurrf")
r_min = utils.get_float_input(self, "lhbmwkar") * 1000
r_max = utils.get_float_input(self, "lhbmwujp") * 1000
# print(vin, vout, r_min, r_max)
self.calculator.voltage_divider_cal(vin, vout, r_min, r_max, r_min, r_max)
results = self.calculator.get_results(len=100)
table = self.ui.tk_table_lhbn5jnk
table.delete(*table.get_children())
for li in results:
table.insert("", "end", values=li)
def handle_res_cal(self, evt):
e_type = int(self.ui.res_e_series.get())
self.calculator.set_res_table(e_type)
cal_type = int(self.ui.res_compose_type.get())
desired = utils.get_float_input(self, "lhbn7or6") * 1000
r1_min = utils.get_float_input(self, "lhbnc1sa") * 1000
r1_max = utils.get_float_input(self, "lhbncnhk") * 1000
r2_min = utils.get_float_input(self, "lhbnoq64") * 1000
r2_max = utils.get_float_input(self, "lhbnohw1") * 1000
r3_min = utils.get_float_input(self, "lhbnoypr") * 1000
r3_max = utils.get_float_input(self, "lhbnp1be") * 1000
# print((desired, cal_type, r1_min, r1_max, r2_min, r2_max, r3_min, r3_max))
self.calculator.res_compose_cal(
desired, cal_type, r1_min, r1_max, r2_min, r2_max, r3_min, r3_max
)
results = self.calculator.get_results(len=100)
table = self.ui.tk_table_lhbnewl1
table.delete(*table.get_children())
for li in results:
table.insert("", "end", values=li)