kivy -- event for when guis is loaded - python

How can I register a callback for when a Kivy gui is loaded?
In my Kivy app, as soon as the GUI is loaded (aka the window pops up with the initial view), I need to kick off a function that loads expensive data and updates the UI.
So far i've been using the on_start method in App but this runs before the GUI is loaded.
essentially, i want something like $( document ).ready() (from jquery) but for ivy

You could Clock.schedule(some_function, 0) in your build method, I think that would run after everything is initialised but before the next frame.

Related

Initializing popup outside of the kivy main app class in Python

I am trying to write a function that launches a popup in a kivy gui based on a conditional. The method is outside of the main app because I am using multithreading to have both run at the same time. Every time I try to initialize a new popup in the method which is outside of the main app, it crashes. If I don't initialize it, it runs fine. Any ideas?
You must perform GUI related operations (like opening or dismissing a Popup) on the kivy thread.
In your code, where you would call sm.open_unrecognized() do Clock.schedule_once(sm.open_unrecognized, 0). This will schedule the call to open_unrecognized on the kivy thread after the next frame is displayed.
Dismissing the Popup can be done automatically (any click outside the Popup) or explicitly using something like a Button in the Popup. Note that any code called by a Button event is performed on the kivy thread.
See the Clock documentation for more information

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.

How to imbricate a QApplication inside a main QApplication

I'm currently working on a GUI interface that runs a GNU Radio script rendering some Qt windows (plotting real time histogramm, waterfall graph, or other nice gui...). I control its parameters and launch it from my first main windows. I'd like to integrate the QApp created by launching the GNU Radio script inside a widget of my first main windows (which is another QApp).
I already tried to run a second QApp in the same time of my first one, for some reasons, I get errors like QCoreApplication::sendPostedEvents: Cannot send posted events for objects in another thread.
I did not work around this error because a nicer idea would be to have a kind of container whom I would give a PyQt4.QtGui.QApplication object to make him execute and display it without creating a second windows.
Does that kind of container exist ?
Thanks a lot !

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.

How can I add a simple non-interactive gui to my python application?

I have written a little python utility that monitors my typing speed, using pyxhook to hook keyboard events, and a thread timer to update my words per minute number.
Right now it just prints to the terminal every 2 seconds.
How can I make this appear in a little always-on-top gui box?
I tried playing around with tkinter, but the mainloop() function doesn't like my key listener and timer. It seems I can only run the gui OR my event handlers, but not both.
Unfortunately I don't think I can use the keyhandler in tkinter, since I am wanting to capture events from other windows.
Any suggestions?
I don't know how to go about doing this in tk, but I've been using PySide lately and I know you could use that.
One way to do it in pyside would be with two classes running in separate threads that communicate using the Qt signal & slot mechanism available in pyside. One class would subclass QThread & get methods that run your existing code & pass the data via signals to the Ui class. The 2nd class would be the one for your gui elements. it would call for an instance of the first class, connect the signals & slots, then start it & begin drawing the display.
resources if you go the pyside route:
http://www.matteomattei.com/pyside-signals-and-slots-with-qthread-example/
search 'pyside dock widget' on this site
search for github's pyside examples
https://pyside.github.io/docs/pyside/PySide/QtCore/QThread.html?highlight=qthread

Categories

Resources