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

Work in progress on highlighter tickets #259

Closed

Conversation

tangledhelix
Copy link
Collaborator

This is not ready to merge, by a long shot, but creating a PR for review purposes.

I'm working on #43 and #42, both of which share a couple of characteristics:

  • When choosing the menu item you toggle an on/off state for the feature
  • Code needs to run on some interval so that the highlight changes as the text or cursor position changes

I have the fundamentals working (tested at least on Mac, so far - testing on Win/Linux is pending):

  • The menu item's on/off state works
  • Saving that state to the preferences works
  • That setting persists across restarts
  • The callback runs when the pref is True, and does not run when it's False

My observations so far:

On startup, the preference is read; if it's False, then the callback is run only one time (due to the fact all callbacks are run on startup) but it doesn't do anything and it doesn't run again. But if True on startup, it will do exactly what it should: it runs, and it runs again every 2000ms (as designed).

If I change the preference, it turns the callback on and off like it should.

So far so good - all of this seems proper. The one thing is that, if the app starts with the pref as False, and I then turn it on, it starts to call the callback twice per interval, not once. This is in contrast to when the pref is True on startup. In that case, it calls the callback only once per interval (which is the desired behavior).

Any advice is appreciated. And for @windymilla specifically I'd like to hear if any of this works at all on Windows, as it's not tested there. (I will test on Ubuntu at some point myself, but I haven't yet.)

For now I am just trying to get the infrastructure in place for a repeating callback to run, controlled by a boolean preference. Obviously later this will be calling real code to do real work.

@tangledhelix
Copy link
Collaborator Author

I figured this out in the interim. I needed to separate the concerns, having one function with the sole job of setting the preference to a new value, separate from the callback function, whose job is to decide whether or not to call the function that starts the loop going, when the preference is changed. Previously, the combined function was being called twice (once by the callback handler, and once by the event handler when the menu item is selected). This resulted in two nearly-concurrent loops beginning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant