-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWidgetBubble.py
149 lines (115 loc) · 3.38 KB
/
WidgetBubble.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
from kivy.uix.widget import Widget
from kivy.core.text import Label
from kivy.graphics.opengl import *
from kivy.graphics import *
from kivy.properties import ObjectProperty
from kivy.core.image import Image as KImage
from kivy.animation import Animation, AnimationTransition
from WidgetValFunctionHandler import WidgetValFunctionHandler
class WidgetBubble(Widget):
def __init__(self, **kwargs):
super(WidgetBubble, self).__init__(**kwargs)
self.pos = [0.0,0.0]
self.orgSize = [512.0, 160.0]
self.size = [self.orgSize[0],self.orgSize[1]]
self.scale = 1.0
self.rotation = 0.0
self.iLevelBg = KImage("icons/ico_level_bg_512_512.png")
self.iLevelBubble = KImage("icons/ico_level_bubble_256_256.png")
self.drawIt()
self.myValue = None
self.stat = {
'skip': 0,
'update': 0
}
self.wvfh = WidgetValFunctionHandler()
#self.wvfh.setParameters()
def setValuesFromDic(self,dic):
print("setValuesFromDic",dic)
self.ImOnScreen = str(dic['screen'])
self.wvfh.setParametersFromDict(dic['valHandler'])
def settingsNeedIt(self):
return True
def getAttrFromDialog(self):
return {}
def addSettingsDialogPart(self,bl,inWConf=None):
return bl
def setLevel(self,level):
#print("setLevel",level)
if self.gui.animation:
Animation.cancel_all(self.bubRot,'angle')
anim = Animation(angle=-level,t='out_quad' )
anim.start( self.bubRot )
else:
self.bubRot.angle = -level
def getSize(self):
return [self.orgSize[0],self.orgSize[1], 1.0, -1.0 ]
#return self.orgSize
def setGui(self, gui):
self.gui = gui
def getWidget(self):
return self
def setColor(self,t):
if t == "w":
Color(1,1,1,1)
elif t == "b":
Color(1,1,1,1)
elif t == "cog":
Color(0,1,0,1)
elif t == "hdg":
Color(1,0,0,1)
def drawIt(self):
print("drawIt")
with self.canvas:
self.setColor('w')
PushMatrix()
self.centPos = Translate(self.size[0]*.5, self.size[1]*.5,0)
self.comScale = Scale(1,1,1)
self.comRot = Rotate(0,0,0,1)
self.r = Rotate(0,0,0,1)
Translate(-self.orgSize[0]*.5,-110.0,0)
Rectangle(
pos = (0,0),
texture = self.iLevelBg.texture,
size = self.iLevelBg.texture.size,
)
PushMatrix()
poi = 450.0
Translate(self.orgSize[0]*.5,poi,0)
self.bubRot = Rotate(0,0,0,-1)
Translate(0,-poi+20,0)
Rectangle(
pos = (0,0),
texture = self.iLevelBubble.texture,
size = [self.iLevelBubble.texture.size[0]*.3,self.iLevelBubble.texture.size[1]*.3]
)
PopMatrix()
PopMatrix()
self.bind(pos = self.updateIt)
def updateOfSize(self,a='',b=''):
print("bubble.update of size",self.size,"\na",a,"\nb",b)
def update(self, fromWho, vals):
if( self.gui.rl.current[:7] != 'Widgets' or
self.ImOnScreen != self.gui.rl.current[7:]
):
return 0
v = self.wvfh.updateVal(fromWho, vals)
if v != None:
if self.myValue == None or self.myValue != v:
self.myValue = v
self.setLevel( v )
self.stat['update']+=1
else:
self.stat['skip']+=1
if (self.stat['skip']%50)==0:
print("widget stat bubble level -> ",self.stat)
def updateIt(self, *args):
#print("bubble.updateIt")
try:
aoeuobc = self.gui
except:
return 0
if self.gui.rl.current[:7] in ["Widgets"]:
pass
else:
return 0