timers and multiple notebook pages

Help needed with best use of timers. I've got an application in mind that will have quite a few wxNotebooks and quite a few pages in each notebook. Only on page will be visable at a time (ie. I have notebooks within notebooks). Each page will periodically get some information. I only want the active page to go fetch the information to update. What would be the best use of timers in this scenario ??

My first thoughts are that I only need one timer that is global to application. How do I get the timer to call the appropriate method/function of the active notebook page ?

Another method would be to have timers for each page, then activate them when the page is active and deactive the timer when another page is selected. I can see this working but seems like a waste of resources. Is this adequate or elegant solution to my timer scenario ???

Any other ideas that would be more suitable or elegant ???

Is there any examples that demonstrate something like the scenario I described ???

Thanks for any advice or suggestions,
Brendan Simon.

Help needed with best use of timers. I've got an application in mind
that will have quite a few wxNotebooks and quite a few pages in each
notebook. Only on page will be visable at a time (ie. I have notebooks
within notebooks). Each page will periodically get some information.

Do you mean that you have only one main notebook, and you want to periodically update its pages? if so, maybe this works:

class MyNotebookPage(wxPanel):
    # ...
    def on_timer(self, event):
        # do stuff
        pass

class MainNotebook(wxNotebook):
    def __init__(self, *args, **kwds):
        # ...
        self.timer = wxTimer(...)
        EVT_TIMER(self, self.timer.GetId(), self.on_timer)

    def on_timer(self, event):
        self.GetPage(self.GetSelection()).on_timer(event)

Another method would be to have timers for each page, then activate them
when the page is active and deactive the timer when another page is
selected. I can see this working but seems like a waste of resources.

I think this is more complex than the previous solution, if all the pages will be notified at the same rate.

Is this adequate or elegant solution to my timer scenario ???

Any other ideas that would be more suitable or elegant ???

I think the first solution is ok, but it's just my 2 EuroCents...

Bye,
Alberto

Alberto Griggio wrote:

Help needed with best use of timers. I've got an application in mind that will have quite a few wxNotebooks and quite a few pages in each notebook. Only on page will be visable at a time (ie. I have notebooks
within notebooks). Each page will periodically get some information.

Do you mean that you have only one main notebook, and you want to periodically update its pages? if so, maybe this works:

class MyNotebookPage(wxPanel):
    # ...
    def on_timer(self, event):
        # do stuff
        pass
class MainNotebook(wxNotebook):
    def __init__(self, *args, **kwds):
        # ...
        self.timer = wxTimer(...)
        EVT_TIMER(self, self.timer.GetId(), self.on_timer)

    def on_timer(self, event):
        self.GetPage(self.GetSelection()).on_timer(event)

It sounded like Brendan wanted to go up one meta-level, and have multiple notebooks as well. But maybe the above idea can be extended by creating a multi-notebook control and doing the same kind of thing?

If you put all the wxNotebooks in a single container (wxFrame, wxPanel, ..), and attach the timer in the same way Alberto suggested to that container, for each wxNotebook, in the event handler for EVT_NOTEBOOK_PAGE_CHANGED, you could call parent.ObserveTimer(event.GetSelection() or self.GetSelection() it looks like either should work)

parent.ObserveTimer would just set a member variable with the selected page (I'm assuming that the GetSelection() does indeed return a wxNotebookPage object so we don't need to care which notebook it came from), and parent's timer handler would then call the timer handler for that page.

Shi.

Brendan Simon wrote:

Help needed with best use of timers. I've got an application in mind
that will have quite a few wxNotebooks and quite a few pages in each
notebook. Only on page will be visable at a time (ie. I have notebooks
within notebooks). Each page will periodically get some information.
I only want the active page to go fetch the information to update.
What would be the best use of timers in this scenario ??

I have a similar situation with a master notebook that I call the
workbook, containing other notebooks, one per workbook page, and these
notebooks each have similar pages containing various wxWindow controls.
The user can make menu and toolbar selections that carry out actions on
the currently visible page, so the workbook and its notebooks all contain
information to keep track of the current page and the object instance
associated with that page. Maybe you could have something similar for
your, single, timer event to use when it goes off, so that the right page
is updated. I can send you the relevant code as an example if you like.

Two other things occur to me. Would it be better for the source of the new
information to initiate the updating when new data is ready, rather than
polling for a possible change with a timer? Also, when new information
*is* available, won't every page need to check for new information
whenever it, the page, becomes visible, or will you automatically update
every page before displaying it?

Regards,

David Hughes
Forestfield Software Ltd
www.forestfield.co.uk