• curious

    I have solved it with the following code. I'd be happy to share the whole script if anyone is interested.

    def run_countdown(self):
        self.setup_view_main()
        self.countdown()
            
    def countdown(self):
        if self.time > 0:
            if self.time <= 3: 
                speech.say(str(self.time), "en-US", 0)
            view_main["lbl_time"].text = str(self.time)
            self.time -= 1
            ui.delay(self.countdown, 1)
        elif self.round < self.data["rounds"]:
            self.switch_states()
            self.run_countdown()
    
    • list item

    posted in Pythonista read more
  • curious

    Thank you Jon. I thought the problem might be the same kind as before. So I will have to think through properly. Hope there are no further questions coming up.

    posted in Pythonista read more
  • curious

    I have adjusted the code a little bit. The button now calls run_countdown. Now the delay function does not work any more. Why is it like this? How can I make the sport time work?

    def run_countdown(self):
        while self.round <= self.rounds:
            self.time = self.seconds_active
            self.countdown()
            self.time = self.seconds_break
            self.countdown()
            self.round += 1
            
    def countdown(self):
        if self.time > 0:
            self.time -= 1
            view_main["lbl_time"].text = str(self.time)
            ui.delay(self.countdown, 1)

    posted in Pythonista read more
  • curious

    Tanks. There is only one process at a time on each thread. In this case it is the process triggered by either of the buttons. pressing b2 halts the process of b1. Or in other words uses/ reserves the threat. But not vice versa. Pressing b1 still allows for b2 which then again blocks the thread. Eventually, b2 decorated with your run_async allows for parallel use. Funnily, if I put a @ui.in_background infront of b2action b1 behaves as b2.

    posted in Pythonista read more
  • curious

    Thanks a lot for the quick answers.
    @Webmaster4o
    a) Is there a way to export the pyui file somehow and then to upload it to GitHub? Is it maybe done "manually" with the ftp server Ole posted some time ago? Or with any of the shells created for pythonista?
    b) do you know why there are compatibility issues between time and ui? I am quite curious about such things...

    @JonB
    Right now I am not familiar with asynchronous programming. But I think the take away is to skip the decorator in my case.

    posted in Pythonista read more
  • curious

    Hello,

    I want to create something like a timer with the UI. For testing there should be a button which triggers a label to display a count down etc. This is my code. Unfortunately, it only displays the last value (0) of the count down. Why is it like this? Is there anything I can do to directly display the other values (here 3, 2, 1) as well?

    import ui, time

    class Main(ui.View):

    def __init__(self):
        self.view_main = ui.load_view()
        self.lbl = self.view_main["lbl_time"]
        self.view_main.present("sheet")
        self.time = 4
            
    def did_load(self):
        self["btn_start"].action = self.change_label_time
        
    def change_label_time(self, sender):
        while self.time > 0:
            self.time -= 1
            time.sleep(1)
            self.view_main["lbl_time"].text = str(self.time)    
    

    Main()

    posted in Pythonista read more

Internal error.

Oops! Looks like something went wrong!