Kivy: Moving mouse freeze main loop - python

I have a video player application, with a graph display below it. My video player is fetching frames periodically, but when I move the mouse it freezes, and by printing what's happening I can see that the main loop didn't call anything
I've tried printing some text for every widget on_mouse_pos event but none of them is triggered, so I really don't know where should I look. Using the recorder module, I can see that there is no mouse event, so I'm not even sure the mouse event is recorder
I have several widgets now so I'm not sure posting them here would be useful, but I'd love to hear feeedback or any idea about this problem
Thanks a lot

So I was able to fix this, my frame pulling function was in a separate thread, moving it to a periodically triggered Clock event fixed this.
I'm still not sure why this bug happened, my 2 cents is that opencv block the GIL while reading a frame, and this somehow interfered with how kivy manages its events

Related

OpenCV: control video playback with both keyboard and mouse

I'd like to be able to play a video (that automatically stops at some fixed frames), and I want to be able to play/stop either using keyboard or mouse. However, it seems that opencv does not provide a function to wait both a keyboard event or a mouse event. I saw there exists a function setMouseCallback but I'm not sure how to use it to make sure that I don't have any conflicts between the keyboard and the mouse. Am I supposed to create a thread that receive messages from both the mouse and the keyboard, or is there something simpler? Otherwise, is there any more suited library to play/seek/stop a video precisely on a given frame?
EDIT
I tried to implement a solution based on threads, and I do action = self.queue.get() instead of cv2.waitKey(...), but then nothing is displayed on screen. Also, if I do cv2.waitKey(1) before, I get an empty frame, and the cv2.waitKey located in other threads does not detect any keypress...

how to handle pygame VideoExpose event

I was experimenting with pygame and noticed it raised a VideoExpose event when I press alt+tab and the window is fullscreen. when I switch press alt+tab again, everything on the screen is moved to the bottom left.
I know that this is supposed to mean that 'portions of the window must be redrawn', but how am I supposed to redraw them and what why does pygame even have this event in the first place?
If you are writing a program to use the windowing Event Model, the windowing environment sends the program events to notify it of environmental changes - window resize, mouse move, need to re-paint, etc.
Not handling these events will cause your application to be considered "non responsive" by the environment. Here on SO, there's about one question a week with PyGame and exactly this issue.
When working with PyGame re-drawing event handling may seem superfluous as the majority of PyGame games redraw the entire screen every frame, e.g.: 60 FPS. But if unnecessary, this method is a complete waste of resources (CPU-time, electricity, etc.) It is quite simple though, so good for beginners.
Say you were writing a card game like Solitaire... the screen updates only when interacting with the user. In terms of CPU, it's doing nothing 99.9% of the time while the user contemplates their next move. In this case, the program could be written to only re-draw the screen when necessary. When is it necessary? When the player gives input, or the program receives a pygame.VIDEOEXPOSE event from the widowing environment.
If your program is redrawing the window constantly, you can simply ignore the message. If not, when receiving the message call whatever block of code is normally used to render the window. The expose message may come with the region of the screen that needs to be re-drawn, in this case a really good application would only update that section of the display.

Functions acting strange when run as thread in Kivy/Python

I am building an app that, when the user hits a 'run' button, generates a table of buttons.
Because this process takes a while, I want to add a popup or progress bar to alert the user that the function is running and not frozen. To do this I decided to create a popup and call my function using threading so that the screen will be updated when the function starts (as opposed to once it is done).
mythread = threading.Thread(target=run_function)
mythread.start()
The trouble is that when I call my function from the above code it works very strangely: the columns of my table are the wrong width, some of my buttons are arbitrarily empty, and others have the wrong fill color. To fix this, all I need to do is to remove the threading operation and simply call run_function()
Any idea why this is happening?
I am new to Python, so it is likely some dumb mistake, but I have no idea. What is different between a process running as a thread and its default operation?
Disclaimer: I haven't worked with Kivy.
Not every framework works well with multithreading.
But most of the GUI frameworks have an event loop which is responsible for managing user events (mouse clicks, keyboard) and queued drawing operations (widgets).
In your case if don't want the UI to be freezed, you should regularly give control to your framework's event loop.
I guess kivy.base.EventLoopBase.dispatch_input is what you need to call to show an added widget or to handle user events.

Loading Images and music Leads to not responding state for few seconds - kivy python

I am writing a code which loads some images and music files for their usage in the code .
Problem is that it goes to not responding state for few seconds when i run program for the first time in windows , I know it should take some time to load images and music however i want to do that without going to not responding state but at a time when i can show a screen named loading and on background all stuff gets loaded and once stuff is loaded program should go further .
Any ideas ?
You should be able to make the splash screen visible, although I am new to kivy so I don't know how. In some SDK you can control when the screen disappears, you could make it disappear after your media are loaded. But sometimes this will mean too long a wait for UI to appear, in that case you are better off doing as #inclement suggests in Remove or replace the kivy splash screen on startup:
make sure your build method doesn't do much, and try to construct as much state as possible only after that.
You would typically load the media in a separate thread that you start from the GUI build method, and you have your thread signal load complete via a callback where you update GUI accordingly. I don't know yet if that is how one is meant to do it in kivy.

wxPython Whole Window Focus Event

With wxPython, how does one trigger an event whenever the whole window goes into/out of focus?
To elaborate, I'm building a serial terminal GUI and would like to close down the connection whenever the user doesn't have my application selected, and re-open the connection whenever the user brings my app back into the foreground. My application is just a single window derived from wx.Frame.
The correct answer for this case is to use an EVT_ACTIVATE handler bound to the frame. There will be an event whenever the frame is activated (brought into the foreground relative to other windows currently open) or deactivated. You can use the event object's GetActive method to tell which just happened.
as WxPerl programmer i know there is
EVT_SET_FOCUS(
EVT_KILL_FOCUS(
if you initialize this event by listening to the frame as first parameter it should work as in Perl since the API is almost the same
Interesting article at http://www.blog.pythonlibrary.org/2009/08/27/wxpython-learning-to-focus/
Gist of it: wx.EVT_KILL_FOCUS works fine, but wx.EVT_SET_FOCUS behaves a little oddly for any panel containing widgets (the child's set-focus prevents the panel's set-focus event from firing as expected?)
In addition to what these fellows are saying, you might also want to try EVT_ENTER_WINDOW and EVT_LEAVE_WINDOW. I think these are fired when you move the mouse into and out of the frame widget, although I don't think the frame has to be in focus for those events to fire.
# Hugh - thanks for the readership!

Categories

Resources