List Info

Thread: how are events handled when using splash screen- some odd behavior




how are events handled when using splash screen- some odd behavior
user name
2006-05-30 03:37:08
Hi,

I've been giving wxpython a test drive and have been
playing around with 
some of the demo code. During this, I've found that under
some 
circumstances I can cause,  an exception in doodle.py demo
script if I 
include a splash screen. When I modify the doodle.py script
so it reads as 
follows


class DoodleFrame(wx.Frame):
     def __init__(self, parent):
         wx.Frame.__init__(self, parent, -1, "Doodle
Frame", size=(800,600),
                          style=wx.DEFAULT_FRAME_STYLE | 
wx.NO_FULL_REPAINT_ON_RESIZE)

         #addition starts here#
        
image=wx.Image(".\\images\\splashscreen.bmp"
, wx.BITMAP_TYPE_BMP)
         bmp=image.ConvertToBitmap()
         wx.SplashScreen(bmp, 
wx.SPLASH_CENTRE_ON_SCREEN|wx.SPLASH_TIMEOUT,3000,None,-1)
         wx.Yield()
         #addition ends here#

         doodle = DoodleWindow(self, -1)

Running this code everything is fine provided I don't click
on the splash 
screen - in which case the doodle code causes and exception
in OnMotion 
when it tries to access self.curLine - which is not
available. If I 
understand the code correctly its as though the initial
click on the 
splashscreen generates a call to OnMoition()

def OnMotion(self, event):
         """
         Called when the mouse is in motion.  If the left
button is
         dragging then draw a line from the last event
position to the
         current one.  Save the coordinants for redraws.
         """
         event
         if event.Dragging() and event.LeftIsDown():

             dc = wx.BufferedDC(wx.ClientDC(self),
self.buffer)
             dc.BeginDrawing()
             dc.SetPen(self.pen)
             pos = event.GetPosition()
             coords = (self.pos.x, self.pos.y, pos.x, pos.y)
             self.curLine.append(coords)
             dc.DrawLine(*coords)
             self.pos = pos
             dc.EndDrawing()


additional background
I'm running python
'2.3.4 (#53, May 25 2004, 21:17:02) [MSC v.1200 32 bit
(Intel)]'
under win2k
with
wxPython2.6-win32-ansi-2.6.3.2-py23.exe

Now after this long preamble my question is
Is this problem due to my ignorance about how to handle
events in wxpython, 
or a bug. If as I suspect it is the former ihow can I handle
them better so 
I don't have this problem?


Thankyou
Dominic


------------------------------------------------------------
---------
To unsubscribe, e-mail: wxPython-users-unsubscribelists.wxwidgets.org
For additional commands, e-mail: wxPython-users-helplists.wxwidgets.org

how are events handled when using splash screen- some odd behavior
user name
2006-05-30 05:21:54
At 08:37 PM 5/29/2006, you wrote:
>Hi,
>
>I've been giving wxpython a test drive and have been
playing around with 
>some of the demo code. During this, I've found that
under some 
>circumstances I can cause,  an exception in doodle.py
demo script if I 
>include a splash screen. When I modify the doodle.py
script so it reads as 
>follows
>
>
>class DoodleFrame(wx.Frame):
>     def __init__(self, parent):
>         wx.Frame.__init__(self, parent, -1,
"Doodle Frame", size=(800,600),
>                          style=wx.DEFAULT_FRAME_STYLE |

> wx.NO_FULL_REPAINT_ON_RESIZE)
>
>         #addition starts here#
>        
image=wx.Image(".\\images\\splashscreen.bmp"
, wx.BITMAP_TYPE_BMP)
>         bmp=image.ConvertToBitmap()
>         wx.SplashScreen(bmp, 
>
wx.SPLASH_CENTRE_ON_SCREEN|wx.SPLASH_TIMEOUT,3000,None,-1)
>         wx.Yield()
>         #addition ends here#
>
>         doodle = DoodleWindow(self, -1)
>
>Running this code everything is fine provided I don't
click on the splash 
>screen - in which case the doodle code causes and
exception in OnMotion 
>when it tries to access self.curLine - which is not
available. If I 
>understand the code correctly its as though the initial
click on the 
>splashscreen generates a call to OnMoition()
>
>def OnMotion(self, event):
>         """
>         Called when the mouse is in motion.  If the
left button is
>         dragging then draw a line from the last event
position to the
>         current one.  Save the coordinants for redraws.
>         """
>         event
>         if event.Dragging() and event.LeftIsDown():
>
>             dc = wx.BufferedDC(wx.ClientDC(self),
self.buffer)
>             dc.BeginDrawing()
>             dc.SetPen(self.pen)
>             pos = event.GetPosition()
>             coords = (self.pos.x, self.pos.y, pos.x,
pos.y)
>             self.curLine.append(coords)
>             dc.DrawLine(*coords)
>             self.pos = pos
>             dc.EndDrawing()
>
>
>additional background
>I'm running python
>'2.3.4 (#53, May 25 2004, 21:17:02) [MSC v.1200 32 bit
(Intel)]'
>under win2k
>with
>wxPython2.6-win32-ansi-2.6.3.2-py23.exe
>
>Now after this long preamble my question is
>Is this problem due to my ignorance about how to handle
events in 
>wxpython, or a bug. If as I suspect it is the former
ihow can I handle 
>them better so I don't have this problem?
>
>
>Thankyou
>Dominic

I'm not quite a beginner, so I can offer not quite an
answer.

The short answer is to add
     self.curLine = []
in your frame initialisation before creating the splash
screen.

The longer answer is that I'm guessing that the splash
screen captures 
mouse down events but not motion, so that OnLeftDown in the
DoodleWindow 
instance is never called, hence curLine is never created.

Here's where my wxPython knowledge breaks down.  I
understood that mouse 
events do not propagate up the window hierarchy if they are
not handled, so 
I don't know why the DoodleWindow sees the motion event. 
Doubtless some 
more knowledgeable person will explain everything, but this
should get you 
going in the meantime.

Phil Mayes 



------------------------------------------------------------
---------
To unsubscribe, e-mail: wxPython-users-unsubscribelists.wxwidgets.org
For additional commands, e-mail: wxPython-users-helplists.wxwidgets.org

how are events handled when using splash screen- some odd behavior
user name
2006-05-30 13:17:09
At 01:21 AM 5/30/2006, you wrote:
>At 08:37 PM 5/29/2006, you wrote:
>>Hi,
>>
>>I've been giving wxpython a test drive and have
been playing around with 
>>some of the demo code. During this, I've found that
under some 
>>circumstances I can cause,  an exception in
doodle.py demo script if I 
>>include a splash screen. When I modify the doodle.py
script so it reads 
>>as follows
>>
>>
>>class DoodleFrame(wx.Frame):
>>     def __init__(self, parent):
>>         wx.Frame.__init__(self, parent, -1,
"Doodle Frame", size=(800,600),
>>                         
style=wx.DEFAULT_FRAME_STYLE | 
>> wx.NO_FULL_REPAINT_ON_RESIZE)
>>
>>         #addition starts here#
>>        
image=wx.Image(".\\images\\splashscreen.bmp"
, wx.BITMAP_TYPE_BMP)
>>         bmp=image.ConvertToBitmap()
>>         wx.SplashScreen(bmp, 
>>
wx.SPLASH_CENTRE_ON_SCREEN|wx.SPLASH_TIMEOUT,3000,None,-1)
>>         wx.Yield()
>>         #addition ends here#
>>
>>         doodle = DoodleWindow(self, -1)
>>
>>Running this code everything is fine provided I
don't click on the splash 
>>screen - in which case the doodle code causes and
exception in OnMotion 
>>when it tries to access self.curLine - which is not
available. If I 
>>understand the code correctly its as though the
initial click on the 
>>splashscreen generates a call to OnMoition()

snip


>>Now after this long preamble my question is
>>Is this problem due to my ignorance about how to
handle events in 
>>wxpython, or a bug. If as I suspect it is the former
ihow can I handle 
>>them better so I don't have this problem?
>>
>>
>>Thankyou
>>Dominic

snip


Hi Phil,

Thank you for the feed back-

>I'm not quite a beginner, so I can offer not quite an
answer.
>
>The short answer is to add
>     self.curLine = []
>in your frame initialisation before creating the splash
screen.

This seems reasonable but it, sadly,  won't make my feeling
of ignorance 
about wxpython events go away 

>The longer answer is that I'm guessing that the splash
screen captures 
>mouse down events but not motion, so that OnLeftDown in
the DoodleWindow 
>instance is never called, hence curLine is never
created.
>
>Here's where my wxPython knowledge breaks down.  I
understood that mouse 
>events do not propagate up the window hierarchy if they
are not handled, 
>so I don't know why the DoodleWindow sees the motion
event.  Doubtless 
>some more knowledgeable person will explain everything,
but this should 
>get you going in the meantime.

Thank you for the in sigh about the not propagation of mouse
events - I 
wonder if you can force propagation of the left mouse click
event- I had 
though that wx.Skip() might do this but it does not seem to
solve the problem.


>Phil Mayes
>
>
>--------------------------------------------------------
-------------
>To unsubscribe, e-mail: wxPython-users-unsubscribelists.wxwidgets.org
>For additional commands, e-mail: wxPython-users-helplists.wxwidgets.org




Dominic Barraclough, PhD


Center for Visual Science
University of Rochester
274 Meliora Hall - River Campus
Rochester
New York 14627


Tel. (585) 275 1812
Fax.(585) 271-3043
email dominicbcvs.rochester.edu
group home web page http://www.bcs.roc
hester.edu/~dlee 


------------------------------------------------------------
---------
To unsubscribe, e-mail: wxPython-users-unsubscribelists.wxwidgets.org
For additional commands, e-mail: wxPython-users-helplists.wxwidgets.org

how are events handled when using splash screen- some odd behavior
user name
2006-05-30 15:50:10
At 06:17 AM 5/30/2006, Dominic wrote:
>At 01:21 AM 5/30/2006, I replied:
>>At 08:37 PM 5/29/2006, Dominic wrote:
>>>Hi,
>>>
>>>I've been giving wxpython a test drive and have
been playing around with 
>>>some of the demo code. During this, I've found
that under some 
>>>circumstances I can cause,  an exception in
doodle.py demo script if I 
>>>include a splash screen.

heavily snipped


>Thank you for the in sigh about the not propagation of
mouse events - I 
>wonder if you can force propagation of the left mouse
click event- I had 
>though that wx.Skip() might do this but it does not seem
to solve the problem.

Dominic -- I looked at this a little more, and the
SplashScreen code simply 
does:
     EVT_MOUSE_EVENTS(wxSplashScreenWindow::OnMouseEvent)
...
void wxSplashScreenWindow::OnMouseEvent(wxMouseEvent&
event)
{
     if (event.LeftDown() || event.RightDown())
         GetParent()->Close(true);
}

so it looks like the window closes, the OS sets focus to the
doodle window, 
and the left mouse button is still down.  OnMotion then
performs the test:
         if event.Dragging() and event.LeftIsDown():
but of course, self.curLine and self.pos have not been set
up.  Better is 
to test:
         if self.HasCapture():

[Or should the splash screen wait for mouse up?  This would
avoid every 
program having to defend itself against Mouse Up with no
preceding Mouse Down.]

Phil Mayes 



------------------------------------------------------------
---------
To unsubscribe, e-mail: wxPython-users-unsubscribelists.wxwidgets.org
For additional commands, e-mail: wxPython-users-helplists.wxwidgets.org

how are events handled when using splash screen- some odd behavior
user name
2006-05-30 17:03:33
At 11:50 AM 5/30/2006, you wrote:
>At 06:17 AM 5/30/2006, Dominic wrote:
>>At 01:21 AM 5/30/2006, I replied:
>>>At 08:37 PM 5/29/2006, Dominic wrote:
>>>>Hi,
>>>>
>>>>I've been giving wxpython a test drive and
have been playing around 
>>>>with some of the demo code. During this,
I've found that under some 
>>>>circumstances I can cause,  an exception in
doodle.py demo script if I 
>>>>include a splash screen.
>
>heavily snipped
>
>
>>Thank you for the in sigh about the not propagation
of mouse events - I 
>>wonder if you can force propagation of the left
mouse click event- I had 
>>though that wx.Skip() might do this but it does not
seem to solve the problem.

Hi Phil,
Thank you so much for going the extra mile - I will explore
using the 
HasCapture() method.
Incidentally, It looks like it may pay to get familiar with
the wxwindows 
c++ source - how often to you find you need to check it out?
Dominic

>Dominic -- I looked at this a little more, and the
SplashScreen code 
>simply does:
>    
EVT_MOUSE_EVENTS(wxSplashScreenWindow::OnMouseEvent)
>...
>void
wxSplashScreenWindow::OnMouseEvent(wxMouseEvent& event)
>{
>     if (event.LeftDown() || event.RightDown())
>         GetParent()->Close(true);
>}
>
>so it looks like the window closes, the OS sets focus to
the doodle 
>window, and the left mouse button is still down. 
OnMotion then performs 
>the test:
>         if event.Dragging() and event.LeftIsDown():
>but of course, self.curLine and self.pos have not been
set up.  Better is 
>to test:
>         if self.HasCapture():
>
>[Or should the splash screen wait for mouse up?  This
would avoid every 
>program having to defend itself against Mouse Up with no
preceding Mouse Down.]
>
>Phil Mayes
>
>
>--------------------------------------------------------
-------------
>To unsubscribe, e-mail: wxPython-users-unsubscribelists.wxwidgets.org
>For additional commands, e-mail: wxPython-users-helplists.wxwidgets.org




Dominic Barraclough, PhD


Center for Visual Science
University of Rochester
274 Meliora Hall - River Campus
Rochester
New York 14627


Tel. (585) 275 1812
Fax.(585) 271-3043
email dominicbcvs.rochester.edu
group home web page http://www.bcs.roc
hester.edu/~dlee 


------------------------------------------------------------
---------
To unsubscribe, e-mail: wxPython-users-unsubscribelists.wxwidgets.org
For additional commands, e-mail: wxPython-users-helplists.wxwidgets.org

[1-5]

about | contact  Other archives ( Real Estate discussion Medical topics )