-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWidget_niddle.py
352 lines (286 loc) · 10.6 KB
/
Widget_niddle.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
import kivy
from kivy.uix.widget import Widget
from kivy.core.text import Label as textLabel
from kivy.uix.label import Label as KiLabel
from kivy.uix.textinput import TextInput
from kivy.lang import Builder
from kivy.uix.scatter import Scatter
from kivy.graphics.opengl import *
from kivy.graphics import *
from kivy.properties import ObjectProperty
import sys
import math
from kivy.uix.boxlayout import BoxLayout
from kivy.metrics import cm
from WidgetValFunctionHandler import WidgetValFunctionHandler
from kivy_garden.speedmeter import SpeedMeter
from kivy.uix.spinner import Spinner
from WidgetHelper import WidgetHelper
from MyLabel import MyLabel
from kivy.animation import Animation
class MySpeedMeter(SpeedMeter):
pass
class Widget_niddle(WidgetHelper):
def __init__(self, **kwargs):
self.updateCount = 0
self.screen = 0
self.size = [200,200]
self.pos = [0,0]
self.scale = 1.0
self.rotation = 0.0
self.x = 0
self.y = 0
self.myValue = None
self.stat = {
'skip': 0,
'update': 0
}
self.subPix = 1.25
self.mtitle = ""
self.mcallback = None
self.mvalk = ""
self.munit = 1
self.mround = 1
self.maxnum = 4
self.valueToDisplay = 0.0
self.smSettings = {
'title': '',
'name': '-170 to 170',
'thumb': 'widget_niddle_170_170.png',
'min': -175,
'max': 175,
'tick': 25,
'subtick':6,
'start_angle': -170,
'end_angle': 170,
'value_font_size': 23,
'label_font_size': 50,
}
self.sm = MySpeedMeter()
self.sm.size_hint = [None,None]
self.sm.size = self.size
self.sm.pos = self.pos
self.defSettings = [
{
'name': '-170 to 170',
'title': '',
'thumb': 'widget_niddle_170_170.png',
'min': -175,
'max': 175,
'tick': 25,
'subtick':6,
'start_angle': -170,
'end_angle': 170,
'value_font_size': 23,
'label_font_size': 50,
},
{
'name': '-170 to 170 small numbers',
'title': '',
'thumb': 'widget_niddle_170_170.png',
'min': -3,
'max': 3,
'tick': 1,
'subtick':11,
'start_angle': -170,
'end_angle': 170,
'value_font_size': 23,
'label_font_size': 50,
},
{
'name': '-90 to 90 ',
'thumb': 'widget_niddle_90_90.png',
'min': -175,
'max': 175,
'tick': 50,
'subtick':3,
'start_angle': -85,
'end_angle': 85,
'value_font_size': 14,
'label_font_size': 50,
},
{
'name': '-90 to 90 small numbers',
'title': '',
'thumb': 'widget_niddle_90_90.png',
'min': -3,
'max': 3,
'tick': 1,
'subtick':11,
'start_angle': -85,
'end_angle': 85,
'value_font_size': 14,
'label_font_size': 50,
},
{
'name': '0 to 90 small numbers',
'title': '',
'thumb': 'widget_niddle_corner.png',
'min': 0,
'max': 5,
'tick': 1,
'subtick':6,
'start_angle': 90,
'end_angle': 0,
'value_font_size': 14,
'label_font_size': 35,
},
]
self.wvfh = WidgetValFunctionHandler()
self.wvfh.setParameters()
def setValues(self,
screen, title, unit, round_ ,maxnum ):
self.screen = str(screen)
self.mtitle = title
self.munit = unit
self.mround = round_
self.maxnum = maxnum
def settingsDoneStore(self):
pass
def settingsNeedIt(self):
return True
def setValuesFromDic(self,dic):
print("setValuesFromDic",dic)
self.wvfh.setParametersFromDict(dic['valHandler'])
self.screen = str(dic['screen'])
for k in self.smSettings.keys():
#print("key ",k," in dic is ",dic[k])
try:
try:
self.smSettings[k] = int(dic[k])
except:
self.smSettings[k] = str(dic[k])
#print("set self.sm")
exec("self.sm.{0} = {1}".format(k,self.smSettings[k]))
#print(" sm set")
except:
pass
#print(" pass ???")
#print("so niddle pos",self.pos," size",self.size)
def getAttrFromDialog(self):
self.updateSmSettings()
return self.smSettings
def addSettingsDialogPart(self,bl, inWConf = None):
presetVals = []
for s in self.defSettings:
presetVals.append(s['name'])
presetDef = presetVals[0]
#bl = BoxLayout(orientation="vertical")
bh = self.getDialogRow()
bh.add_widget(MyLabel(text="Preset:"))
self.spPreset = Spinner(
text = presetDef,
values = presetVals,
height = cm(1)
)
bh.add_widget( self.spPreset )
bl.add_widget(bh)
self.spPreset.bind(text=self.on_presetChange)
if inWConf:
self.spPreset.text = inWConf['atr']['name']
bl,self.ti_title = self.addDialogRow(bl, "Title",
"" if inWConf == None else inWConf['atr']['title'] )
bl,self.ti_min = self.addDialogRow(bl, "Min value",
-175 if inWConf == None else str(inWConf['atr']['min']) )
bl,self.ti_max = self.addDialogRow(bl, "Max value",
175 if inWConf == None else str(inWConf['atr']['max']) )
bl,self.ti_tick = self.addDialogRow(bl, "Tick",
25 if inWConf == None else str(inWConf['atr']['tick']) )
bl,self.ti_subtick = self.addDialogRow(bl, "Sub ticks",
6 if inWConf == None else str(inWConf['atr']['subtick']) )
bl,self.ti_start_angle = self.addDialogRow(bl, "Start angle",
-170 if inWConf == None else str(inWConf['atr']['start_angle']))
bl,self.ti_end_angle = self.addDialogRow(bl, "End angle",
170 if inWConf == None else str(inWConf['atr']['end_angle']) )
bl,self.ti_value_font_size = self.addDialogRow(bl, "Value size",
23 if inWConf == None else str(inWConf['atr']['value_font_size']) )
bl,self.ti_label_font_size = self.addDialogRow(bl, "Labels size",
50 if inWConf == None else str(inWConf['atr']['label_font_size']) )
return bl
def updateSmSettings(self):
print("updateSmSettings")
for k in self.smSettings.keys():
#print("value ",k)
try:
exec("self.smSettings['{0}'] = str(self.ti_{0}.text)".format(k))
#print(" -> ",self.smSettings[k])
except:
print(" not pressent")
pass
def on_presetChange(self,a='',b=''):
print("on_presetChange")
sp = self.spPreset.text
for s in self.defSettings:
if s['name']==sp:
spO = s
break
for k in spO.keys():
print("setting to gui",k)
try:
exec("self.ti_%s.text = str(%s)"%(k,spO[k]))
#print("set")
except:
#print('skipp')
pass
try:
self.smSettings[k] = spO[k]
except:
pass
print("affter change smSettings is ",self.smSettings)
def getWidget(self):
'''print("getWidget () o ",self.mtitle,
"pos:",int(self.pos[0]),"x",int(self.pos[1]),
"size:",int(self.size[0]),"x",int(self.size[1]))
'''
return self.sm
def updateIt(self, fromWho = '',vals = ''):
self.update(fromWho, vals)
self.setPos(self.pos)
self.setScale(self.scale)
self.setRot(self.rotation)
def update(self, fromWho, vals):
if( self.gui.rl.current[:7] != 'Widgets' or
self.screen != self.gui.rl.current[7:]
):
return 0
if 0:
print('''update from widget_n[{}]
from:{}
gotvals:{}'''.format(
self.mtitle, fromWho, vals
))
v = self.wvfh.updateVal(fromWho, vals)
if v != None:
vAsInt = True
try:
vi = int(v)
except:
vAsInt = False
if vAsInt:
self.valueToDisplay = round( v, self.mround ) if self.mround > 0 else int( v )
else:
self.valueToDisplay = v
if self.smSettings['title'] != '':
self.sm.label = "{}\n{}".format(
self.smSettings['title'], self.valueToDisplay)
else:
self.sm.label = str(self.valueToDisplay)
if self.valueToDisplay > self.smSettings['max']:
self.valueToDisplay = self.smSettings['max']
if self.valueToDisplay < self.smSettings['min']:
self.valueToDisplay = self.smSettings['min']
if self.gui.animation:
Animation.cancel_all(self.sm,'angle')
anim = Animation(value=self.valueToDisplay, t='out_quad' )
anim.start( self.sm )
else:
self.sm.value = self.valueToDisplay
def setGui(self, gui):
self.gui = gui
self.size = [
200,
200
]
self.pos = [self.x,self.y]
def getSize(self):
return [self.size[0],self.size[1], 0.5, -1.0 ]