forked from battulasaivinesh/OM_GUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUnitOP.py
154 lines (140 loc) · 6.22 KB
/
UnitOP.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
150
151
152
153
154
from kivy.app import App
from kivy.clock import Clock
from kivy.uix.widget import Widget
from kivy.uix.button import Button
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import ListProperty
from kivy.properties import NumericProperty
from kivy.graphics.vertex_instructions import Rectangle
from kivy.graphics.vertex_instructions import Line
from kivy.uix.bubble import Bubble
from kivy.uix.popup import Popup
from functools import partial
from kivy.uix.scrollview import ScrollView
from kivy.uix.slider import Slider
from kivy.uix.gridlayout import GridLayout
from kivy.uix.stacklayout import StackLayout
from kivy.uix.label import Label
from kivy.uix.textinput import TextInput
from kivy.uix.floatlayout import FloatLayout
from kivy.graphics.context_instructions import Color
from kivy.graphics.instructions import InstructionGroup
from kivy.lang import Builder
from kivy.uix.dropdown import DropDown
from url import OmWidget
from kivy.factory import Factory
Builder.load_file('popup.kv')
class cPopUp(Popup):
pass
class dDown(DropDown):
DrNumber = NumericProperty(0)
class butt(Button):
DrNumber = NumericProperty(0)
class UnitOPM(Factory.CustButton):
def __init__(self, **kwargs):
super(UnitOPM, self).__init__(**kwargs)
self.child = Button()
def on_touch_down(self, touch):
if self.child.collide_point(*touch.pos):
if touch.is_double_tap:
# touch.multitouch_sim = True
self.child.multi_touch = self.child.multi_touch + 1
else:
touch.grab(self)
return False
def on_touch_up(self, touch):
if touch.grab_current is self:
# self.unpressed = touch.pos
touch.ungrab(self)
return True
def on_touch_move(self, touch):
if touch.grab_current is self:
self.center_x = touch.x
self.center_y = touch.y
if self.child.connected == True:
self.child.line_move = self.child.line_move + 1
return False
return super(UnitOPM, self).on_touch_move(touch)
class UnitOP(Button):
Operators = []
drop_connections = {}
size_limit = [100, 100]
unpressed = ListProperty([0, 0])
double_tap = NumericProperty(0)
multi_touch = NumericProperty(0)
current_touch = None
line_move = NumericProperty(0)
connect = NumericProperty(0)
def __init__(self, **kwargs):
super(UnitOP, self).__init__(**kwargs)
self.size_hint = None, None
self.size = (40, 15)
self.connected = False
self.PropertyList = []
self.PropertyObj = []
self.PropertyVal = ['50','101.325','100']
self.OM_Model = ''
self.name = ''
self.PropInput = [TextInput(size_hint_y=None, height=25, valign='middle', font_size=12, multiline=False),TextInput(size_hint_y=None, height=25, valign='middle', font_size=12, multiline=False),TextInput(size_hint_y=None, height=25, valign='middle', font_size=12, multiline=False)]
self.conn_point = 0
self.check_stm = 1
self.DropDowns =[]
self.MainButton = []
self.name_ob = TextInput()
self.bef_name = ''
self.text_label = Label()
def on_multi_touch(self, instance, value):
c = cPopUp()
i = 0
self.PropertyObj = []
self.PropInput = []
self.DropDowns = []
self.MainButton = []
c.ids.name_label.text_size = c.ids.name.size
self.bef_name = self.name
c.ids.name.text = self.name
self.name_ob = c.ids.name
for Property in self.PropertyList:
PropLabel = Label(text=Property, size_hint_y=None, height=25, halign='left', valign='middle', font_size=14)
PropLabel.text_size = PropLabel.size
self.PropInput.append(TextInput(text = str(self.PropertyVal[i]),size_hint_y=None, height=25, valign='middle', font_size=12, multiline=False))
self.PropertyObj.append(self.PropInput[i])
c.ids.first_tab.add_widget(PropLabel)
if self.check_stm == 0:
c.ids.first_tab.add_widget(self.PropInput[i])
else:
self.MainButton.append(Button(text='Select', size_hint_y=None, height=25))
self.DropDowns.append(dDown(DrNumber=i))
for item in self.Operators:
btn = butt(text=item.name, size_hint_y=None, height=25, DrNumber=i,background_normal='',background_color=(0.4,0.4,0.4,1))
btn.bind(on_release=lambda btn: self.DropDowns[btn.DrNumber].select(btn.text))
self.DropDowns[i].add_widget(btn)
self.MainButton[i].bind(on_release=self.DropDowns[i].open)
self.DropDowns[i].bind(on_select=lambda instance, x: setattr(self.MainButton[instance.DrNumber], 'text', x))
c.ids.first_tab.add_widget(self.MainButton[i])
i = i+1
c.ids.submit.bind(on_press=self.on_submit)
c.open()
def open_prop(self,instance):
self.PropInput = []
print 'yes'
i = 0
for p in self.PropertyVal:
self.PropInput.append(TextInput(text = str(p),size_hint_y=None, height=25, valign='middle', font_size=12, multiline=False))
print p
i = i + 1
def scroll_change(self, scrlv, instance, value):
scrlv.scroll_y = value
def slider_change(self, s, instance, value):
if value >= 0:
# this to avoid 'maximum recursion depth exceeded' error
s.value = value
def on_submit(self, instance):
self.PropertyVal = []
self.PropertyObj = self.PropInput
self.name = self.name_ob.text
UnitOP.UnitOP.drop_connections[self.name] = UnitOP.UnitOP.drop_connections[self.bef_name]
for Property in self.PropertyObj:
self.PropertyVal.append(Property.text)
if self.connected == False:
self.connect = self.connect + 1