-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStates.py
87 lines (61 loc) · 2 KB
/
States.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
import graph
from GraphObjects import Line, Resistance, Power
import tkpanel
import Types
class State():
def __init__(self, graph, panel = None):
"""
:param graph:
:type graph: graph.Graph
:param panel:
:type panel: tkpanel.Panel
"""
self.graph = graph
self.panel = panel
def toLine(self):
self.cleanState()
self.graph.selectedObject = Line(self.graph, self.graph.selectedNode)
def toRes(self):
self.cleanState()
self.graph.selectedObject = Resistance(self.graph)
inVal = self.panel.valueTB.get()
if str.isnumeric(inVal):
self.graph.selectedObject.setVal(int(inVal))
def toVoltage(self):
self.cleanState()
self.graph.selectedObject = Power(self.graph)
inVal = self.panel.valueVoltTB.get()
if str.isnumeric(inVal):
self.graph.selectedObject.setVal(int(inVal))
def toGround(self):
self.cleanState()
pass
def delete(self):
self.cleanState()
pass
def cleanState(self):
if self.panel.cableState.get() == 1:
self.toggleCableStateButton()
if self.graph.selectedObject:
self.graph.selectedObject.delete()
del self.graph.selectedObject
def toggleCableStateButton(self):
print("state", self.panel.cableState.get())
if self.panel.cableState.get() == 0:
self.panel.cableState.set(1)
self.graph.state = "s"
else:
self.panel.cableState.set(0)
self.graph.state = "a"
self.panel.cableCheckBox.toggle()
def changeSelectedObject(self, type):
if self.graph.selectedObject:
self.graph.selectedObject.delete()
if type == Types.res:
self.toRes()
elif type == Types.volt:
self.toVoltage()
elif type == Types.line:
self.toLine()
elif type == Types.ground:
self.toGround()