Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update event model #120

Open
jarvisteach opened this issue Mar 19, 2017 · 5 comments
Open

Update event model #120

jarvisteach opened this issue Mar 19, 2017 · 5 comments
Assignees
Milestone

Comments

@jarvisteach
Copy link
Owner

jarvisteach commented Mar 19, 2017

Improve the way users register events

At the moment, it's only possible to have one event loop, and the user has to manage how many times it gets called.

Would be nice to offer a better model:

  • Each event in its own loop
  • Each loop has its own delay
  • Each loop has its own number of repeats
  • Each loop repeats until the function returns True

So, .registerEvent(function) could have additional parameters:

  • count - how many times to repeat the function (defaults to infinite - None)
  • sleep - how long to sleep between function calls (defaults to 1 second)
  • checkResult - keep repeating until the function returns True (default to off)

Becoming: .registerEvent(function, sleep=1, repeat=None. checkResult=False)

.setPollTime() then becomes deprecated - but will adjust the default delay time above.

Also, some way to sleep for x amount of time. This could be provided as: .sleep(time). It would wait the specified amount of time before returning control back to the calling function. But it won't block the main loop, so the UI will remain responsive.

@jarvisteach
Copy link
Owner Author

Interesting way of running loops: https://gist.github.com/niccokunzmann/8673951

@jarvisteach
Copy link
Owner Author

@jarvisteach
Copy link
Owner Author

An additional function .callEvent(function) that wraps around the above to call a function once - sets repeat to 1.

@jarvisteach
Copy link
Owner Author

NB. The docs are VERY misleading - .after() doesn't kick off processes in new threads, and will cause the event loop to hang...

jarvisteach added a commit that referenced this issue Aug 26, 2017
jarvisteach added a commit that referenced this issue Aug 28, 2017
Slight rework of threading #120
* provided function queue - so threads can safely call gui functions
including a monitor to run functions
* changed thread imports

Updates to maps - to use threading #174

Started work on a ttknotebook container #230
jarvisteach added a commit that referenced this issue Aug 28, 2017
#120 - make sure afters/threads are cleared up. Cancel the processQueue
after, loop through maps and stop their threads/afters. Remove priority
queue.

Big change to sub-classing, changed all supers to use different syntax.

Updated maps #174 - removed location loop, gets location once at start,
causes some delay. Only map downloads are in threads. Also added some
code for geoLocating.

Updated testing to try threads.
@jarvisteach
Copy link
Owner Author

We now have a few new features.

  • A function queue - users can queue function calls, that get processed in the GUI loop, ensuring no thread conflicts.
  • As the Queue is threadsafe, these function calls can be queued from external threads.
  • A thread function, that can be passed a function to run in a thread, so that the GUI doesn't hang. Any GUI updates should be passed to the function queue.

This is a fairly complex model, but should allow for a reliable process.

The threads are set as Daemon threads - so if the GUI is quit, the threads will be terminated.

In an attempt to support as many versions of Python as possible, the threading is fairly basic - there's no limit on thread numbers, and each time the thread function is called a new thread is instantiated. Both of these could be improved.

There's also currently no thread monitoring - it would be nice to subclass Thread, and have threads store a running time and call something on completion...

jarvisteach added a commit that referenced this issue Aug 29, 2017
Tidied up some broken references

Added defaults for Queue size & processing speed #120
@jarvisteach jarvisteach modified the milestones: 0.08, 0.09 Sep 16, 2017
jarvisteach added a commit that referenced this issue Oct 24, 2017
#120 & #281 - the parameters are strange, I think it’s working now…
@jarvisteach jarvisteach modified the milestones: 0.90, 1.0 Dec 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant