Polling from a ui.View (built in timers in ui.Views)
@omz, did you ever go further with the idea of a ui.View having its own timer that you could hook into to do updates etc. ? Personally, I think I would be a great advance for ui.View or Custom ui.Views. I realise there are different ways to do it already. But it's so easy to get it wrong, well at least for me. I am sure you could implement it many ways. For me, I think the best would be a callback same as draw in subclassed ui.Views. Like the draw method, if a timer method is not defined then no additional overhead or speed issues would impact the class. Also some way to set the interval of the callback as well as a way to able to suspend/activate the timer callbacks. I think it could be more flexible if it did not automatically suspend if it's not the foremost view. Eg, you may have a view/s as an overlay/s with the alpha set so it's transparent, but you want to still want it to execute the code in the timer callback method.
Anyway, I think this would be super helpful. Not sure what others think.
@mikael , lol. But it's stress testing :)
Have to say, you can click around, drag around etc.. everything keeps working which is great
@omz - Hi. I also found using update_interval and update very straightforward and it worked without a hitch.
Sorry I did not give any feedback before now. I didn't know where to give feedback. Now, I see that this is the place to do that.
I had no issues with programming the beta version at all.
There is a bug in an example program, which also exist in the release (non-beta) version. The Calculator.py example in the "Widget" folder gives "v is not defined" - "v" should be "widget_view". When that change is made, the program works. (The other Calculator.py program in the "User Interface" folder has no issues).
I noticed the download in the App store has been changed to be named, "Pythonista 3", I presume to match the version of Python used. The main application screen still has "Pythonista 2 Documents".
Thanks for creating such a great App.
@technoway Thanks for your feedback.
Pythonista 3 is the current version. The folder "Pythonista 2 Documents" exists to access files from the old version. It only shows up if you had version 2 installed at some point, and you can turn it off in the settings.
If not running the Pythonista 3 beta, someone can also have an update method be periodically called as shown below.
This is not my idea, I just simplified an idea in the TimedRefreshView.py example program that I found at:
This program below, named say_random_digit.py, says a random digit from 0 to 9 every 5 seconds.
I had to change the data member "self.update_interval" to "self.updatex_interval" and the method "update" to "updatex" so as not to conflict with the names in the Pythonista 3 beta, which I am running.
I like having this functionality built into the class much more than having to implement it, so I look forward to the beta becoming the released product.
import ui import threading import speech from random import randint class TimedUpdateView(ui.View): def __init__(self): self.updatex_interval = 5 self.update_after_delay() def updatex(self): """ Say a random digit from 0 to 9 every 5 seconds. """ speech.say('%s' % (randint(0, 9))) def update_after_delay(self): """ This just method calls the updatex method periodically """ self.updatex() update_thread = threading.Timer(self.updatex_interval, self.update_after_delay).run() if __name__ == "__main__": v = TimedUpdateView() v.present('sheet')
I just updated my iPhone 6s to IOS 12.0.1, and the 'update' method is not longer called in my ui.View derived class.
I wonder if anyone else has encountered this?
@technoway, 12.0.1 on iPhone X, still works as previously.
You sure you have update_interval set?
Thank you mikael and JonB for the help.
You sure you have update_interval set?
Yes. I have:
self.update_interval = 1.0
in my derived class's
It likely I did something to break code that was working, but I don't see anything wrong. I'll debug my application - if this works for others, then I'm sure I introduced a bug somewhere. It's odd though, because I only made two very small changes and then updated the OS.
Next time, before I upgrade the OS, I'll test before to make sure it's the OS that breaks code, and not my code changes.