• ZinoSama

    @cvp the 361 one is the value I forget to change for testing.
    I wrote a simple while loop to test button action. The result is the label will only show 10 after 10 seconds, but not get from 1 to 10 by each second. it just didn't show 1 to 9

    def start2(sender):
        label = sender.superview['label1']
        num = 0
        while num != 10:
            time.sleep(1)
            num += 1
            label.text = str(num)
    

    posted in Pythonista read more
  • ZinoSama

    it seems like I can’t put a whole loop into button action, but I want to do a counter by time function.

    posted in Pythonista read more
  • ZinoSama

    I tried debug this code, and it worked correctly, but after I running this one, the whole app crushed.

    def start(sender):
        def ani_pause():
            sender.image = ui.Image.named('iob:pause_32')
    
        def ani_play():
            sender.image = ui.Image.named('iob:play_32')
    
        global is_playing
    
        if is_playing is False:
            ui.animate(ani_pause)
            is_playing = True
            start_time = time.time()
            label = sender.superview['label1']
            label2 = sender.superview['label2']
            time_left = 0
            while int(label.text) != 131:
                time.sleep(0.01)
                time_now = time.time()
                duration = time_now - start_time
                time_left += 1
                label2.text = str(10 - time_left)
                if label2.text is '0':
                    label.text = str(int(label.text) + 1)
                    time_left = 361
            ui.animate(ani_play)
            is_playing = False
        else:
            is_playing = False
            ui.animate(ani_play)
    

    posted in Pythonista read more
  • ZinoSama

    @cvp oops, didn’t notice that. Let me try it.

    posted in Pythonista read more
  • ZinoSama

    @ccc you are right, I already changed it. It is still stuck though

    posted in Pythonista read more
  • ZinoSama

    Thank you, guys, just by adding 'iob:' makes it working.
    Now I get another problem, I have a button action link to this function, and every time I press this button, the whole Pythonista will stuck.

    state = False
    def start(sender):
        def ani_pause():
            sender.image = ui.Image('iob:pause_32')
    
        def ani_play():
            sender.image = ui.Image('iob:play_32')
    
        global state
        if state is False:
            ui.animate(ani_pause)
            state = True
            start_time = round(time.time())
            label = sender.superview['label1']
            label2 = sender.superview['label2']
            while int(label.text) != '131':
                time_now = round(time.time())
                duration = time_now - start_time
                time_left = divmod(duration, 360)[1]
                label2.text = str(time_left)
                if time_left == 0:
                    label.text = str(int(label.text) + 1)
                else:
                    continue
            ui.animate(ani_play)
            state = False
        else:
            state = False
            ui.animate(ani_play)
    

    posted in Pythonista read more
  • ZinoSama

    How do I change the button image from 'play' to 'pause'?
    Something like press button once, the image change to 'pause', then press it again, the image change back to 'play'.
    What I did is

    sender. Image = ui.Image.named('pause_32')
    

    This will make the button blank, totally white

    posted in Pythonista read more

Internal error.

Oops! Looks like something went wrong!