Skip to content

Commit

Permalink
Merge branch 'animations'
Browse files Browse the repository at this point in the history
  • Loading branch information
AustL committed Sep 1, 2020
2 parents 15a296d + 1f048ee commit ed5ef25
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
25 changes: 20 additions & 5 deletions pygame_widgets/animations/animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


class AnimationBase:
def __init__(self, widget, timeout, **kwargs):
def __init__(self, widget, timeout, allowMultiple=False, **kwargs):
"""Base for animations
:param widget: The widget that the animation targets
Expand All @@ -15,13 +15,21 @@ def __init__(self, widget, timeout, **kwargs):
"""
self.widget = widget
self.timeout = timeout
self.allowMultiple = allowMultiple
self.params = kwargs
self.thread = Thread(target=self.loop)
self.thread = Thread()

self.started = False
self.runOnce = False

def start(self):
self.thread.start()
if not self.started and not (self.runOnce and not self.allowMultiple):
self.thread = Thread(target=self.loop)
self.thread.start()

def loop(self):
self.started = self.runOnce = True

start = time.time()

initialParams = {}
Expand All @@ -39,6 +47,8 @@ def loop(self):
for param, target in self.params.items():
self.widget.set(param, target)

self.started = False


class Translate(AnimationBase):
def __init__(self, widget, timeout, x, y):
Expand All @@ -51,13 +61,18 @@ def __init__(self, widget, timeout, width, height):


if __name__ == '__main__':
def animate():
resize.start()
translate.start()

pygame.init()
win = pygame.display.set_mode((600, 600))

button = Button(win, 100, 100, 300, 150)

animation = Resize(button, 3, 200, 200)
animation.start()
resize = Resize(button, 3, 200, 200)
translate = Translate(button, 3, 200, 200)
button.setOnClick(animate)

run = True
while run:
Expand Down
4 changes: 2 additions & 2 deletions pygame_widgets/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,11 @@ def setImage(self, image):
self.imageRect = self.image.get_rect()
self.alignImageRect()

def setOnClick(self, onClick, params):
def setOnClick(self, onClick, params=()):
self.onClick = onClick
self.onClickParams = params

def setOnRelease(self, onRelease, params):
def setOnRelease(self, onRelease, params=()):
self.onRelease = onRelease
self.onReleaseParams = params

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name='pygame-widgets',
version='0.2.0',
version='0.2.1',
author='AustL',
author_email='21chydra@gmail.com',
description='Widgets for use with Pygame',
Expand Down

0 comments on commit ed5ef25

Please sign in to comment.