Gif Animation not playing in Kivy App - python

I am writing a kivy application, a game, which has an animated gif at the top which should play on a loop, as it does in finder etc. When it loads into the kivy gui it only shows one frame. I am new to kivy and would appreciate some help with this issue. I am using the .kv file to load the image:
Image:
source: 'spaceshipgif.gif'
allow_stretch: True
I have studied the documentation on the kivy website and searched around but to no avail.

I don't remember exactly what the gif playing status is - they should work in principle, but some of our providers are better than others at it. As I remember it might work better if you compile kivy with PIL as the image provider. I think some of these problems can be caused by technically incorrect gif files, which aren't handled well by the default provider, but I'm not sure about this.
A better solution is to instead put the frames of the .gif as images in a zip file, and set the path to this zip as the image path in your widget. Kivy will automatically animate them for you, including making it easy to change the animation rate (or pause it), without being limited by problems with gif files.

Related

How to play MP4 with Ursina in Python

I am new to game development. I am trying to start high and make a 3D RPG. I know the road is not gonna be easy. That is why i decided to use Ursina and python to make my game.
However i wanna add a cutscene showing a Backstory. I have the video in mp4 format but i cannot seem to know how to play it inside the game with Ursina.
Anyhelp will be much appreciated.
(Side question : do you think Ursina is good for a beginner in 3D gaming? If i want to publish my game on my website, isn't it better for me to learn javascript ? I read about Unity but it is too big to download for a little side project)
You can set the video as a texture of any element. You'll want to fix it to the UI using its parent attribute and you have to load the sound separately from the same file (as described in the Panda3D documentation).
from ursina import *
app = Ursina()
video = 'video.mp4'
video_player = Entity(model='quad', parent=camera.ui, scale=(1.5, 1), texture=video)
video_sound = loader.loadSfx(video)
video_player.texture.synchronizeTo(video_sound)
video_sound.play()
app.run()
The above code assumes that the video file is in the same folder as the Python script.
Well, I don't think there is a way to do that. the closest thing you can do to that is having a folder filled with all the frames of your video in .png or .jpg files, then adding a quad to the world and changing the texture of it to the next frame every fraction of a second depending on the framerate. this, however would make your computer l a g. trust me, I've tried it. it would probably be better to have a separate window with some sort of module that plays .mp4 files for playing the file.
In other words, there is no feasible way to do that.
From Entity Basics in the documentation:
e4 = Entity(model='cube', texture='movie_name.mp4') # set video texture

Is it possible to save in a file an animation created with Tkinter?

I wanted to use Python to create animations (video) containing text and simple moving geometric objects (lines, rectangles, circles and so on).
In the book titled "Python 2.6 Graphics Cookbook" I found examples using Tkinter library. First, it looked like what I need. I was able to create simple animation but then I realized that in the end I want to have a file containing my animation (in gif or mp4 format). However, what I have, is an application with GUI running on my computer and showing me my animation.
Is there a simple way to save the animation that I see in my GUI in a file?
There is no simple way.
The question Programmatically generate video or animated GIF in Python? has answers related strictly to creating these files with python (ie: it doesn't mention tkinter).
The question How can I convert canvas content to an image? has answers related to saving the canvas as an image
You might be able to take the best answers from those two questions and combine them into a single program.
I've accomplished this before, but not in a particularly pretty way.
Tl;dr save your canvas as an image at each step of the iteration, use external tools to convert from image to gif
This won't require any external dependencies or new packages except having imagemagick already installed on your machine
Save the image
I assume that you're using a Tkinter canvas object. If you're posting actual images to the tk widgets, it will probably be much easier to save them; the tk canvas doesn't have a built-in save function except as postcript. Postscript might actually be fine for making the animation, but otherwise you can
Concurrently draw in PIL and save the PIL image https://www.daniweb.com/software-development/python/code/216929/saving-a-tkinter-canvas-drawing-python
Take a screenshot at every step, maybe using imagegrab http://effbot.org/imagingbook/imagegrab.htm
Converting the images to to an animation
Once the images are saved, I used imagemagick to dump them into either a gif, or into a mpg. You can run the command right from python using How to run imagemagick in the background from python or something similar. It also means that the process is implictely run on a separate thread, so it won't halt your program while it happens. You can query the file to find out when the process is done.
The command
convert ../location/*.ps -quality 100 ../location/animation.gif
should do the trick.
Quirks:
There are some small details, and the process isn't perfect. Imagemagick reads files in order, so you'll need to save the files so that alphabetical and chronological line up. Beware that the name
name9.ps
Is alphabetically greater than
name10.ps
From imagemagick's point of view.
If you don't have imagemagick, you can download it easily (its a super useful command-line tool to have) on linux and mac, and cygwin comes with it on windows. If you're worried about portability... well... PIL isn't standard either
There is a way of doing that, with the "recording screen method", this was explained in other question: "how can you record your screen in a gif?".
Click the link -->LICEcap : https://github.com/lepht/licecap
They say that it's free software for Mac (OS X) and Windows
You could look at Panda3D, but it could be a little over killed for what you need.
I would say you can use Blender3d too but i'm not really sure of how it works. Someone more experimented then me could tell you more about this.

PyQt4 - QPushbutton.setIcon doesn't set the icon

I am writing an open configurable taskbar using PyQt4, and I want to add a start orb. I want the orb to support the common image format of start orbs, which is usually three 54x54 squares for a 54x162 image.
My program takes those images, cuts them in thirds using PIL, and I try to load them using .setIcon(QIcon(icon)). Unfortunately, this isn't working. The image is loaded, calling .show() displays the image perfectly.
For various reasons, I did not choose style sheets, including that I would have trouble loading the cut images. Instead, (as the code shows) I had the QPushButton change icons on hover, press, and release. None of them work. Not even the default image.
My code is on this github. Note the warning in the readme! The program quite literally replaces (and removes) the taskbar (but you can get it back).
tl;dr
I have the code (see link below). It won't load using .setIcon(), and I don't know why. I thought it would work, used ImageQt, but no.
EDIT:Unfortunately, going from a PIL object to a Imagqt object to a QImage didn't solve the problem.
EDIT2: as #Trilarion requeted here is a link to a gist of the slimmed down code: https://gist.github.com/IronManMark20/85b00104c9bb52b78add

wxPython how to play once or disable loop in GIFAnimationCtrl

I have an animated GIF played by GIFAnimationCtrl() on my Python code. Since my GIF is triggered by user events I need to just play it once.
I tried just exporting the GIF without the looping attribute and trying if the function Play() has any options, but it doesn't. Any other function or libary I could use with wxPython is also wellcomed.
Here is the image i'm trying to use.
After more research i just found a workaround, wich is to put on the last frame of the animated GIF, a 240 seconds delay (the maximum I can put on Photoshop) wich does the trick,
Still looking for better aproaches.

Phonon: how to clear screen after video plays

I am writing a program for audio-visual experiments, which will present a pre-generated list of audio-only and video-with-audio stimuli to experiment subjects. I have decided to use PyQT and Phonon for this, despite the fact that I'm fairly new to writing QT-based programs (and GUI programming in general).
The issue I'm having is that, when the previous file played was video (.mov in this case), and the current file is audio-only (.wav file), the image from the last frame of the video file remains on the screen while the audio file is playing. The video image remains until the next .mov file rolls around in the stimulus list.
Is there a way to clear the Phonon screen, in order to show just an empty black screen while the audio-only files are playing? I've done a fair bit of poking around with Google, and though this question has been asked by a number of people on different forums, it seems to have gone unanswered.
Any suggestions will be greatly appreciated!
This seems to be a bug, or missing feature, and it's hard to come up with a good workaround.
One somewhat hacky solution is to force a resize of the video widget:
size = self.video.size()
self.video.resize(0, 0)
self.video.resize(size)
but I wouldn't bet on this working on all platforms.
A more reliable workaround would be to put the video-widget inside a container widget with a black background, and then simply hide/show the video-widget when stopping/starting the media.

Categories