1
0
Fork 0
mirror of https://github.com/shlomif/PySolFC.git synced 2025-04-05 00:02:29 -04:00

Kivy/Android

- refactoring, hardening, flake8
This commit is contained in:
lufebe16 2023-11-30 11:40:13 +01:00
parent 10c6b5c61d
commit 224d21a2d2
5 changed files with 48 additions and 41 deletions

View file

@ -1455,7 +1455,7 @@ class Game(object):
c0 = cards[0]
dx, dy = (x - c0.x), (y - c0.y)
base = float(self.app.opt.animations)
duration = base*base/25.0 + 0.05
duration = base*base/30.0 + 0.05
for card in cards:
card.animatedMove(dx, dy, duration)
# self.top.waitAnimation(swallow=True, pickup=True)

View file

@ -135,30 +135,28 @@ class LAnimationTask(LTask, LBase):
class LAnimationMgr(object):
def __init__(self, **kw):
super(LAnimationMgr, self).__init__()
self.animations = []
self.widgets = {}
self.tasks = []
self.callbacks = []
self.taskQ = LTaskQ()
def checkRunning(self):
return len(self.animations) > 0
return len(self.tasks) > 0
def addEndCallback(self, cb):
self.callbacks.append(cb)
# print('len of callbacks', len(self.callbacks))
def animEnd(self, anim, widget):
# print('LAnimationMgr: animEnd = %s.%s' % (anim, widget))
def taskEnd(self, task, value):
if value:
print('LAnimationMgr: taskEnd = %s %s' % (task, value))
self.tasks.remove(task)
if not self.checkRunning():
# print('LAnimationMgr: taskEnd ->', len(self.callbacks), 'callbacks') # noqa
for cb in self.callbacks:
cb()
# print('LAnimationMgr: taskEnd -> callbacks done')
self.callbacks = []
self.animations.remove(anim)
if not self.checkRunning():
# print('LAnimationMgr: animEnd ->', len(self.callbacks), 'callbacks') # noqa
for cb in self.callbacks:
cb()
# print('LAnimationMgr: animEnd -> callbacks done')
self.callbacks = []
print('Clock.get_fps() ->', Clock.get_fps())
print('Clock.get_fps() ->', Clock.get_fps())
def create(self, spos, widget, **kw):
x = 0.0
@ -175,16 +173,17 @@ class LAnimationMgr(object):
transition = kw['transition']
anim = Animation(x=x, y=y, duration=duration, transition=transition)
anim.bind(on_complete=self.animEnd)
if 'bindE' in kw:
anim.bind(on_complete=kw['bindE'])
if 'bindS' in kw:
anim.bind(on_start=kw['bindS'])
self.animations.append(anim)
offset = duration / 3.0
animTask = LAnimationTask(anim, spos, widget, offset)
Clock.schedule_once(lambda dt: self.taskQ.taskInsert(animTask), 0.016)
task = LAnimationTask(anim, spos, widget, offset)
self.tasks.append(task)
task.bind(done=self.taskEnd)
Clock.schedule_once(lambda dt: self.taskQ.taskInsert(task), 0.016)
LAnimationManager = LAnimationMgr()

View file

@ -21,11 +21,10 @@ from kivy.properties import BooleanProperty, ListProperty
class LTask(EventDispatcher):
done = BooleanProperty(False)
done = BooleanProperty(True)
def __init__(self, name):
super(LTask, self).__init__()
self.done = False
self.name = name
self.delay = 0.01
@ -37,10 +36,6 @@ class LTask(EventDispatcher):
# print('stop of ',self.name)
self.done = True
def on_done(self, instance, value):
# print ('on_done',instance,value)
pass
class LTaskQ(EventDispatcher):
waitQ = ListProperty([])

View file

@ -23,6 +23,7 @@
from pysollib.acard import AbstractCard
from pysollib.kivy.LApp import LImageItem
# from pysollib.kivy.LApp import LAnimationManager
from pysollib.kivy.LImage import LImage
from pysollib.kivy.tkcanvas import MfxCanvasImage
@ -89,18 +90,24 @@ class _OneImageCard(_HideableCard):
def showFace(self, unhide=1):
# print ('card: showFace = %s' % self._face_image.source)
if not self.face_up:
def flip():
self._setImage(image=self._face_image)
self.tkraise(unhide)
self.face_up = 1
if not self.face_up:
flip()
def showBack(self, unhide=1):
# print ('card: showBack = %s' % self._back_image.source)
if self.face_up:
def flip():
self._setImage(image=self._back_image)
self.tkraise(unhide)
self.face_up = 0
if self.face_up:
flip()
def updateCardBackground(self, image):
print('card: updateCardBackground = %s' % image.source)
self._back_image = LImage(texture=image.texture)

View file

@ -276,8 +276,8 @@ class MfxCanvasImage(object):
super(MfxCanvasImage, self).__init__()
self.canvas = canvas
# animation support:
self.animation = None
# animation mode support:
self.animation = 0
self.deferred_raises = []
self.deferred_pos = []
@ -337,9 +337,10 @@ class MfxCanvasImage(object):
# print('stack[2] = ', inspect.stack()[2].frame)
# print('stack[3] = ', inspect.stack()[3].frame)
if self.animation:
if self.animation > 0:
# print('defer tkraise to animation', abitm)
self.deferred_raises.append(self.makeDeferredRaise(abitm))
if len(self.deferred_raises) < self.animation:
self.deferred_raises.append(self.makeDeferredRaise(abitm))
return
# print('direct tkraise', abitm)
@ -368,11 +369,12 @@ class MfxCanvasImage(object):
dsize = image.coreSize
dpos = (image.corePos[0] + dx, image.corePos[1] + dy)
image.corePos = dpos
if not self.animation:
if self.animation == 0:
image.pos, image.size = self.canvas.CoreToKivy(dpos, dsize)
else:
pos, size = self.canvas.CoreToKivy(dpos, dsize)
self.deferred_pos.append(pos)
if len(self.deferred_pos) < self.animation:
pos, size = self.canvas.CoreToKivy(dpos, dsize)
self.deferred_pos.append(pos)
def makeAnimStart(self):
def animStart(anim, widget):
@ -399,7 +401,13 @@ class MfxCanvasImage(object):
def makeAnimEnd(self, dpos, dsize):
def animEnd(anim, widget):
# print('MfxCanvasImage: animEnd %s' % self)
self.animation = False
if self.animation > 0:
self.animation -= 1
if self.animation == 0:
# just for the case, keep in sync:
self.deferred_raises = []
self.deferred_pos = []
# print('MfxCanvasImage: animEnd moved to %s, %s' % (dpos[0], dpos[1])) # noqa
return animEnd
@ -422,7 +430,7 @@ class MfxCanvasImage(object):
if self.canvas.wmain.app.game.demo:
transition = transition1
self.animation = True
self.animation += 1
ssize = image.coreSize
spos = (image.corePos[0], image.corePos[1])
spos, ssize = self.canvas.CoreToKivy(spos, ssize)
@ -776,16 +784,14 @@ class MfxCanvas(LImage):
# print('MfxCanvas: tag_lower: to bottom')
self.remove_widget(itm)
k = len(self.children.index)
self.add_widget(itm,index=k)
self.add_widget(itm, index=k)
else:
# print('MfxCanvas: tag_lower: to specified position')
self.remove_widget(itm)
k = self.children.index(belowThis)
k += 1
self.add_widget(itm, index=k)
#
#
#
def setInitialSize(self, width, height):
self.r_width = width
self.r_height = height