Multiple-notebook timer issues

I have a main-frame splitter with a notebook on the left side, and one of
multiple notebooks on the right side. More specifically, there is a
separate right-side notebook for each left-side notebook =page=.
Whenever the user chooses a different left-side notebook page, the
notebook that was displayed on the right side is hidden, and the
right-side notebook corresponding to the left-side notebook page is
displayed instead. I.e., I’m using notebooks to support a major
left-to-right one-to-many relationship.
Each right-side notebook, whether or not it’s displayed, contains a
statistics page. When that page is changed to, I create and start a
notebook-bound timer that updates that page’s statistics twice a
second. When that page is changed from, I stop and destroy the
timer. (The statistics summarize what the user is currently doing
on the left-side notebook page.)
This is all working now. But I have two concerns: (1)
is there a better way? (2) How do I avoid having multiple timers
running simultaneously?
**(1) Is there a better way?**I use main-frame-bound EVT_NOTEBOOK_PAGE_CHANGED and
EVT_NOTEBOOK_PAGE_CHANGING events with page names to know when a
statistics page has been selected/deselected. It’d be much more
appropriate to use page-just-made-partially-or-fully-visible and
page-just-hidden events to manage what is basically a “display
timer,” but I have yet to encounter any such hooks.
Note that this is NOT a focus issue. Focus is always on the
left-side notebook. So EVT_SET_FOCUS and EVT_LEAVE_WINDOW are
irrelevant here.
**(2) How do I avoid having multiple timers running
simultaneously?**When the user has selected a right-side statistics page, and then
selects a different left-side page, the right-side notebook is hidden …
but its timer continues on, updating now-hidden statistics twice a
second. That’s a complete waste of time! And if the user now
selects the statistics page of the just-displayed notebook, TWO timers
will be running at once. Many timers could eventually be running at
once, as more and more left-side notebook pages are brought into
play. Not good.

BTW, the user should definitely not have to switch away from a statistics
page before its notebook is hidden.

Advice, please1

Bob

[deletia]

(2) How do I avoid having multiple timers running simultaneously?

When the user has selected a right-side statistics page, and then selects a
different left-side page, the right-side notebook is hidden ... but its
timer continues on, updating now-hidden statistics twice a second. That's a
complete waste of time! And if the user now selects the statistics page of
the just-displayed notebook, TWO timers will be running at once. Many
timers could eventually be running at once, as more and more left-side
notebook pages are brought into play. Not good.

BTW, the user should definitely not have to switch away from a statistics
page before its notebook is hidden.

How about one global timer that fires on two-second interviews, and
then uses PubSub to send a message. The notebooks that subscribe to
the message do a check to see if they're visible. If they're not they
ignore the message. If they are they process it.

Alternatively you could only subscribe to the message when the
notebook was visible, and then unsubscribe when it is not. This way
you wouldn't even have to do the "Am I Visible" check.

···

On Wed, Aug 6, 2008 at 8:09 AM, Bob Klahn <bobstones@comcast.net> wrote:

--
Stand Fast,
tjg. [Timothy Grant]

Hmmm. I haven't used pubsub before; clearly I should learn more about it.

In the meantime ... Re your "Alternatively" comment, after unsubscribing to the global timer when the notebook was not visible, how would I then resubscribe? Where would the resubscribe code live, and what would fire it? I will be developing a number of other right-side pages that will need timer updates when they're displayed, and I don't think I want all those checks going on every half-second.

Ideally, I should only have a timer running when it's truly needed.

Bob

P.S. Thanks for the quick response!

···

At 11:49 AM 8/6/2008, Timothy Grant wrote:

On Wed, Aug 6, 2008 at 8:09 AM, Bob Klahn <bobstones@comcast.net> wrote:
[deletia]
> (2) How do I avoid having multiple timers running simultaneously?
>
> When the user has selected a right-side statistics page, and then selects a
> different left-side page, the right-side notebook is hidden ... but its
> timer continues on, updating now-hidden statistics twice a second. That's a
> complete waste of time! And if the user now selects the statistics page of
> the just-displayed notebook, TWO timers will be running at once. Many
> timers could eventually be running at once, as more and more left-side
> notebook pages are brought into play. Not good.
>
> BTW, the user should definitely not have to switch away from a statistics
> page before its notebook is hidden.

How about one global timer that fires on two-second interviews, and
then uses PubSub to send a message. The notebooks that subscribe to
the message do a check to see if they're visible. If they're not they
ignore the message. If they are they process it.

Alternatively you could only subscribe to the message when the
notebook was visible, and then unsubscribe when it is not. This way
you wouldn't even have to do the "Am I Visible" check.

--
Stand Fast,
tjg. [Timothy Grant]

I initially didn't use pubsub because I didn't want to learn something
new. But it's so very simple that it was well worth the effort.

To answer your question, I think I would have a
my_notebook.subscribe() and a my_notebook.unsubscribe() method that
was called in whichever event handler you're using to change
notebooks.

Please remember this is completely untested, it's just where I would
start if I was attempting to accomplish what you're attempting to
accomplish.

···

On Wed, Aug 6, 2008 at 12:24 PM, Bob Klahn <bobstones@comcast.net> wrote:

At 11:49 AM 8/6/2008, Timothy Grant wrote:

On Wed, Aug 6, 2008 at 8:09 AM, Bob Klahn <bobstones@comcast.net> wrote:
[deletia]
> (2) How do I avoid having multiple timers running simultaneously?
>
> When the user has selected a right-side statistics page, and then
> selects a
> different left-side page, the right-side notebook is hidden ... but its
> timer continues on, updating now-hidden statistics twice a second.
> That's a
> complete waste of time! And if the user now selects the statistics page
> of
> the just-displayed notebook, TWO timers will be running at once. Many
> timers could eventually be running at once, as more and more left-side
> notebook pages are brought into play. Not good.
>
> BTW, the user should definitely not have to switch away from a
> statistics
> page before its notebook is hidden.

How about one global timer that fires on two-second interviews, and
then uses PubSub to send a message. The notebooks that subscribe to
the message do a check to see if they're visible. If they're not they
ignore the message. If they are they process it.

Alternatively you could only subscribe to the message when the
notebook was visible, and then unsubscribe when it is not. This way
you wouldn't even have to do the "Am I Visible" check.

--
Stand Fast,
tjg. [Timothy Grant]

Hmmm. I haven't used pubsub before; clearly I should learn more about it.

In the meantime ... Re your "Alternatively" comment, after unsubscribing to
the global timer when the notebook was not visible, how would I then
resubscribe? Where would the resubscribe code live, and what would fire it?
I will be developing a number of other right-side pages that will need
timer updates when they're displayed, and I don't think I want all those
checks going on every half-second.

Ideally, I should only have a timer running when it's truly needed.

Bob

P.S. Thanks for the quick response!

--
Stand Fast,
tjg. [Timothy Grant]