is on the screen event

Hallo,
I need to know when a widget becomes visible on screen, and when it is
no more visible.
I have tried the EVT_SHOW, but this does not work for panel (they are
always shown).
I need this because i want the widget to be subscirbed to a publisher
that sends refresh messages only when the wiget is on screen.

wxWindow::IsShown

virtual bool IsShown() const

Returns true if the window is shown, false if
it has been hidden.

See also

wxWindow::IsShownOnScreen

···

On 01/02/2011 5:11 PM, tinauser wrote:

Hallo,
I need to know when a widget becomes visible on screen, and when it is
no more visible.
I have tried the EVT_SHOW, but this does not work for panel (they are
always shown).
I need this because i want the widget to be subscirbed to a publisher
that sends refresh messages only when the wiget is on screen.

wxWindow::IsShownOnScreen
virtual bool IsShownOnScreen() const

Returns true if the window is physically visible
on the screen, i.e. it is shown and all its parents up to the
toplevel window are shown as well.

See also

wxWindow::IsShown

Thanks for the reply.
However what you are indicating me are flags that belong to wxWindows.
I do not need to know the state, I need to catch the change of the
state.
Regarding IsShown moreover, it is not good to be used for the
purpouse, as it is set to true by default for many wxWindows (wxPanel,
for instance).

···

On 1 Feb, 19:01, Gadget/Steve <GadgetSt...@live.co.uk> wrote:

On 01/02/2011 5:11 PM, tinauser wrote:

> Hallo,
> I need to know when a widget becomes visible on screen, and when it is
> no more visible.
> I have tried the EVT_SHOW, but this does not work for panel (they are
> always shown).
> I need this because i want the widget to be subscirbed to a publisher
> that sends refresh messages only when the wiget is on screen.

  wxWindow::IsShown

*virtual bool* *IsShown*() *const*

Returns true if the window is shown, false if it has been hidden.

*See also*

wxWindow::IsShownOnScreen

------------------------------------------------------------------------
wxWindow::IsShownOnScreen

*virtual bool* *IsShownOnScreen*() *const*

Returns true if the window is physically visible on the screen, i.e. it
is shown and all its parents up to the toplevel window are shown as well.

*See also*

wxWindow::IsShown

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

···

On 01/02/2011 6:08 PM, tinauser wrote:

On 1 Feb, 19:01, Gadget/Steve <GadgetSt...@live.co.uk> wrote:

On 01/02/2011 5:11 PM, tinauser wrote:

Hallo,
I need to know when a widget becomes visible on screen, and when it is
no more visible.
I have tried the EVT_SHOW, but this does not work for panel (they are
always shown).
I need this because i want the widget to be subscirbed to a publisher
that sends refresh messages only when the wiget is on screen.

wxWindow::IsShown

*virtual bool* *IsShown*() *const*

Returns true if the window is shown, false if it has been hidden.

*See also*

wxWindow::IsShownOnScreen

------------------------------------------------------------------------
wxWindow::IsShownOnScreen

*virtual bool* *IsShownOnScreen*() *const*

Returns true if the window is physically visible on the screen, i.e. it
is shown and all its parents up to the toplevel window are shown as well.

*See also*

wxWindow::IsShown

Thanks for the reply.
However what you are indicating me are flags that belong to wxWindows.
I do not need to know the state, I need to catch the change of the
state.
Regarding IsShown moreover, it is not good to be used for the
purpouse, as it is set to true by default for many wxWindows (wxPanel,
for instance).

Surely your wxPanel is in/child of a wxWindow? How about
wxIconizeEvent or wxActivateEvent - or you could always use a timer
to poll your applications state.

both events you suggest relates with wxFrame,not with wxPanel, that's
what I'm more likely to need. The frame will be aways on screen, but
according to user selection there might be different widgets on the
screen. Polling could do the job, but with quite an high consumption
of resource,that is not worth if I'm trying to catch this event in
order not to deal with not shown widgets.
If i needed only to catch when the widget is presented on the
screen ,I could have used simply the EVT_PAINT, but I also need to
catch when the widget is not on screen anymore.

···

On 1 Feb, 21:32, Gadget/Steve <GadgetSt...@live.co.uk> wrote:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 01/02/2011 6:08 PM, tinauser wrote:

> On 1 Feb, 19:01, Gadget/Steve <GadgetSt...@live.co.uk> wrote:
>> On 01/02/2011 5:11 PM, tinauser wrote:

>>> Hallo,
>>> I need to know when a widget becomes visible on screen, and when it is
>>> no more visible.
>>> I have tried the EVT_SHOW, but this does not work for panel (they are
>>> always shown).
>>> I need this because i want the widget to be subscirbed to a publisher
>>> that sends refresh messages only when the wiget is on screen.

>> wxWindow::IsShown

>> *virtual bool* *IsShown*() *const*

>> Returns true if the window is shown, false if it has been hidden.

>> *See also*

>> wxWindow::IsShownOnScreen

>> ------------------------------------------------------------------------
>> wxWindow::IsShownOnScreen

>> *virtual bool* *IsShownOnScreen*() *const*

>> Returns true if the window is physically visible on the screen, i.e. it
>> is shown and all its parents up to the toplevel window are shown as well.

>> *See also*

>> wxWindow::IsShown

> Thanks for the reply.
> However what you are indicating me are flags that belong to wxWindows.
> I do not need to know the state, I need to catch the change of the
> state.
> Regarding IsShown moreover, it is not good to be used for the
> purpouse, as it is set to true by default for many wxWindows (wxPanel,
> for instance).

Surely your wxPanel is in/child of a wxWindow? How about
wxIconizeEvent or wxActivateEvent - or you could always use a timer
to poll your applications state.

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1

Hallo, I need to know when a widget becomes visible on
screen, and when it is no more visible. I have tried the
EVT_SHOW, but this does not work for panel (they are always
shown). I need this because i want the widget to be
subscirbed to a publisher that sends refresh messages only
when the wiget is on screen.

wxWindow::IsShown

*virtual bool* *IsShown*() *const*

Returns true if the window is shown, false if it has been
hidden.

*See also*

wxWindow::IsShownOnScreen

------------------------------------------------------------------------

wxWindow::IsShownOnScreen

*virtual bool* *IsShownOnScreen*() *const*

Returns true if the window is physically visible on the
screen, i.e. it is shown and all its parents up to the
toplevel window are shown as well.

*See also*

wxWindow::IsShown

Thanks for the reply. However what you are indicating me are
flags that belong to wxWindows. I do not need to know the
state, I need to catch the change of the state. Regarding
IsShown moreover, it is not good to be used for the purpouse,
as it is set to true by default for many wxWindows (wxPanel,
for instance).

Surely your wxPanel is in/child of a wxWindow? How about
wxIconizeEvent or wxActivateEvent - or you could always use a
timer to poll your applications state.

both events you suggest relates with wxFrame,not with wxPanel,
that's what I'm more likely to need. The frame will be aways on
screen, but according to user selection there might be different
widgets on the screen. Polling could do the job, but with quite an
high consumption of resource,that is not worth if I'm trying to
catch this event in order not to deal with not shown widgets. If i
needed only to catch when the widget is presented on the screen ,I
could have used simply the EVT_PAINT, but I also need to catch when
the widget is not on screen anymore.

But since a wxPanel must have a parent and does not have a hide/show
button of it's own you have one of 2 cases, the parent is hidden, in
which case the above method should do the job or you have a hide/show
widget/panel button/menu item - in the latter case the same function
that does the show/hide can do the subscribe/un-subcribe actions.

···

On 01/02/2011 10:27 PM, tinauser wrote:

On 1 Feb, 21:32, Gadget/Steve <GadgetSt...@live.co.uk> wrote:

On 01/02/2011 6:08 PM, tinauser wrote:

On 1 Feb, 19:01, Gadget/Steve <GadgetSt...@live.co.uk> wrote:

On 01/02/2011 5:11 PM, tinauser wrote:

El 01/02/2011 19:08, tinauser escribi�:

...

I do not need to know the state, I need to catch the change of the
state.

See:

<http://docs.wxwidgets.org/trunk/classwx_show_event.html&gt;

···

--
Oswaldo Hern�ndez

I have tried the EVT_SHOW, but this does not work for panel (they are
always shown). As steve suggested, I have to bind the first parent
that actually is hided and re-displayed by user actions: for instance,
if the panel is the page of a notebook, the notebook will hide-show
it. Another example, if the panel is hide/shown with a button control.
To have a more general widget, I have to pass as variable the parent
that get actually hidden/shown (might be self)

···

On 2 Feb, 13:35, Oswaldo Hernández <lis...@soft-com.es> wrote:

El 01/02/2011 19:08, tinauser escribi :

...
> I do not need to know the state, I need to catch the change of the
> state.

See:

<http://docs.wxwidgets.org/trunk/classwx_show_event.html&gt;

--
Oswaldo Hern ndez

El 02/02/2011 13:58, tinauser escribi�:

El 01/02/2011 19:08, tinauser escribi :

...

I do not need to know the state, I need to catch the change of the
state.

See:

<http://docs.wxwidgets.org/trunk/classwx_show_event.html&gt;

--
Oswaldo Hern ndez

I have tried the EVT_SHOW, but this does not work for panel (they are
always shown). As steve suggested, I have to bind the first parent
that actually is hided and re-displayed by user actions: for instance,
if the panel is the page of a notebook, the notebook will hide-show
it. Another example, if the panel is hide/shown with a button control.
To have a more general widget, I have to pass as variable the parent
that get actually hidden/shown (might be self)

If you do "panel.Bind(wx.EVT_SHOW,...)", it is triggered when you make panel.Show(True/False). but no when you do parentpanel.Show() or frame.Show().

For catching the event in any of the parents, included the frame, you must do:

class myPanel(wx.Panel):
     def __init__(...
     ...
     s = self
     while s:
         s.Bind.(wx.EVT_SHOW, self._OnShow)
         s = s.GetParent()

     def _OnShow(self, evt):
         print "Show %s in:%s" %(evt.Show, evt.GetEventObject())

···

On 2 Feb, 13:35, Oswaldo Hern�ndez<lis...@soft-com.es> wrote:

--
Oswaldo Hern�ndez

Thank you very much for the hint. Here is how I made my panel that
subscribe/unsubscribe himeself from a publishlist when he is on
screen. With respect of your hint, I just added an evt.Skip() command,
so that if ore of these panels are instantiated, they all get the
event show. The only problem I'm having is that when I destroy the
frame, I also get an evt_show, and I get an error because in the
OnShow function I use the panel that has been destroyed. A possible
workaround would be the try-condition.Do anyone have a bettere idea?

class CountingCtrlTxtPanel(wx.Panel):
    def __init__(self, parent, name, divider = 1):
        print "CountingCtrlTxtPanel:",name
        wx.Panel.__init__(self,parent)
        assert divider>0
        self.c = wx.TextCtrl(self, wx.ID_ANY,'0')
        msizer=wx.BoxSizer(wx.HORIZONTAL)
        msizer.Add(self.c)
        self.SetSizer(msizer)
        self.Layout()
        self.div=divider
        self.name=name
        s = self
        while s:
            s.Bind(wx.EVT_SHOW, self.OnShow)#bind the EVT_SHOW of all
the parent of the widget
            s = s.GetParent()

    def OnShow(self,evt):
        print "Show %s in:%s" %(evt.Show, evt.GetEventObject())
        print self.name,"is show on screen:",self.IsShownOnScreen()
        if self.IsShownOnScreen():
            pub.subscribe(self.OnRefresh,'refreshTimer')#a timer is
always publishing,sending as data a count
        else:
            pub.unsubscribe(self.OnRefresh,'refreshTimer')#don't want
to do job if I'm not seen
        evt.Skip()

    def OnRefresh(self,msg):
        print self.name,'refresh:',msg.data,' self.div:',self.div
        if msg.data%self.div == 0:
            print 'in f'
            self.c.SetLabel(str(msg.data/self.div))

···

On 2 Feb, 15:49, Oswaldo Hernández <lis...@soft-com.es> wrote:

El 02/02/2011 13:58, tinauser escribi :

> On 2 Feb, 13:35, Oswaldo Hern ndez<lis...@soft-com.es> wrote:
>> El 01/02/2011 19:08, tinauser escribi :

>> ...
>>> I do not need to know the state, I need to catch the change of the
>>> state.

>> See:

>> <http://docs.wxwidgets.org/trunk/classwx_show_event.html&gt;

>> --
>> Oswaldo Hern ndez

> I have tried the EVT_SHOW, but this does not work for panel (they are
> always shown). As steve suggested, I have to bind the first parent
> that actually is hided and re-displayed by user actions: for instance,
> if the panel is the page of a notebook, the notebook will hide-show
> it. Another example, if the panel is hide/shown with a button control.
> To have a more general widget, I have to pass as variable the parent
> that get actually hidden/shown (might be self)

If you do "panel.Bind(wx.EVT_SHOW,...)", it is triggered when you make
panel.Show(True/False). but no when you do parentpanel.Show() or
frame.Show().

For catching the event in any of the parents, included the frame, you
must do:

class myPanel(wx.Panel):
def __init__(...
...
s = self
while s:
s.Bind.(wx.EVT_SHOW, self._OnShow)
s = s.GetParent()

 def \_OnShow\(self, evt\):
     print &quot;Show %s in:%s&quot; %\(evt\.Show, evt\.GetEventObject\(\)\)

--
Oswaldo Hern ndez

El 03/02/2011 11:57, tinauser escribi�:
...

The only problem I'm having is that when I destroy the
frame, I also get an evt_show, and I get an error because in the
OnShow function I use the panel that has been destroyed. A possible
workaround would be the try-condition.Do anyone have a bettere idea?

if self.IsBeingDeleted()
or
if self.GetTopLevelParent().IsBeingDeleted()

<wxPython API Documentation — wxPython Phoenix 4.2.2 documentation;

···

--
Oswaldo Hern�ndez

Thanks again for the hint. The correct solution was:
if not evt.GetEventObject().IsBeingDeleted():
Now everyting works!

···

On 3 Feb, 13:29, Oswaldo Hernández <lis...@soft-com.es> wrote:

El 03/02/2011 11:57, tinauser escribi :
...

>The only problem I'm having is that when I destroy the
> frame, I also get an evt_show, and I get an error because in the
> OnShow function I use the panel that has been destroyed. A possible
> workaround would be the try-condition.Do anyone have a bettere idea?

if self.IsBeingDeleted()
or
if self.GetTopLevelParent().IsBeingDeleted()

<wxPython API Documentation — wxPython Phoenix 4.2.2 documentation;

--
Oswaldo Hern ndez