These are chat archives for pybee/general

8th
Jun 2018
Alistair Buxton
@ali1234
Jun 08 20:32
can i write an android app and compile it with VOC without using toga? how do i declare my activities/servers/broadcast listeners? where is the manifest?
Charles
@misua
Jun 08 23:10
hello @freakboy3742 I followed a tutorial done by you on youtube, I am using linuxmint and installed anaconda for my python needs, and it gave errors,when I did a python -m beeliza, somthn about gi not installed, tried to pip install it, but failed. can you please recommend a distribution or the one you used to run those demo you have like in youtube ?
Serge Beaumont
@sbeaumont
Jun 08 23:38
Hi, I'm trying to have a Toga label update during some processing with label.text = "my update"; label.refresh(), but that does not seem to work. Can't find any other way to force a refresh. Am I missing something?
Dan Yeaw
@danyeaw
Jun 08 23:41
@misua Welcome! Did you install the required dependencies in the README?
@sbeaumont It is my understanding that refresh() is to refresh the layout of a widget, I wouldn't think you would need that to set a new label value. Which platform are you trying to get this working in?
Serge Beaumont
@sbeaumont
Jun 08 23:45
macos.
I have a desktop app that is doing some batch processing, and I want to use that label that updates a label text as it progresses.
Problem is that the UI seems to freeze during the processing. I programmed Delphi in Ye Olden Days, and there you had to make sure that you put all the UI changes on the main thread or you got weirdness like the UI locking up during longer processing inside your application. Something similar going on here?
Dan Yeaw
@danyeaw
Jun 08 23:48

@sbeaumont I opened Tutorial 1 and added a new line in the build function right before the return

c_label.text = "Update"

It works fine for me in Gtk+. I don't have a MacOS box on me at the moment.

Russell Keith-Magee
@freakboy3742
Jun 08 23:48
@sbeaumont Right - so the issue is exactly the same as in Ye Olden Days. There’s a single GUI loop; if you block in your handler, the gui loop can’t update.
However - Toga event handlers can be generators or asyncio coroutines - both of which will yield control back to the GUI event loop.
So - if you have a long-lived handler, you need to make it periodically yield:
def myhandler(widget, **kwargs):
    while not finished():
        new_label = do_update()
        c_label.text = new_label
        yield 1
the value of the yield is a “sleep” between iterations, during which control will be given back to the GUI loop.
Dan Yeaw
@danyeaw
Jun 08 23:52
Cool, I learned something new today too :clap:
Russell Keith-Magee
@freakboy3742
Jun 08 23:53
@danyeaw Weren’t you in my PyCon talk? :-)
danyeaw @danyeaw ducks who me?
Dan Yeaw
@danyeaw
Jun 08 23:54
You talked about yielding to the event loop in your PyCon talk? I guess I need to go rewatch it :smile:
Russell Keith-Magee
@freakboy3742
Jun 08 23:54
Yup - that was the whole thing about making the chatbot wait before responding.
Dan Yeaw
@danyeaw
Jun 08 23:55
@freakboy3742 Ohhh, right, I remember that. Well not the first thing that I had to learn twice.
Serge Beaumont
@sbeaumont
Jun 08 23:58
Hokay... I'm not too hot on async stuff in Python. In Delphi I would start a long process in its own thread, and in that thread notify the main thread when I needed to update the UI. Would a strategy like that make sense in Python?
hemicurtis
@hemicurtis
Jun 08 23:59
Yes, but you will have the less-busy thread in a state of busy-wait while it is looking for the change.