[wxPython] Change to another App and get Back to my App on W98

hi,

this problem is to difficult to me, so i have to
ask yours another newbie question...
i think that robin answer me, so i say thx for
all of your advices. Also thx to all others of ya

Basics:
I have a TextCtrl with an Polygon like a triangle
drawed with ClientDc in an upper corner.
if the user moves the mouse over this triangle a
little Dialog without a caption appears and show
a comment. Like an Excel comment.
Because its difficult to close the commentwindow
without any button or a caption i decide to use
EVT_ENTER_WINDOW and LEAVE_WINDOW
to determine the closefunc. It's all for test. Later
there should be more ways to let disappear the win
if i enter the cwindow(resp. the panel). with my
mousecursor the EVT_LEAVE_Handler be
initialized and if i leave the commentwindow
it disappears.
Fine.
But after the commentwindow disappears another
open app (z.B. IE or any other open) gets active
for one second - change to foreground on my
desktop and then my app gets active again and
change to foreground… (???)
if the commentwindow was lying over the statusbar
(which was owned by the TopWindow) of my app
this will also happen, but my App übernimmt capture
immediatly the active status back. the other app will
only get for a ms the activestate…
Its very confuse to me…

i tried to refresh my window (better only one pixel) after
the closing of the commentwin to get my App showing and
not hiding, but that doesnt work...

=(

Thanx, reen

Rene Freund
rene@meder.de

Here's the code...
class CommentTextCtrl(wxTextCtrl):
    def __init__(self, parent, ID, value, pos, size, style):
        wxTextCtrl.__init__(self, parent, ID, value, pos, size, style)
        if style == 32:
            self.multiline=1
        else:
            self.multiline=0
        self.window=storedata.GetTopWindow()

self.rect=wxRect(self.window.GetPosition().x,self.window.GetPosition().y,se
lf.window.GetSize().GetWidth(),self.window.GetSize().GetHeight())
        self.comment=''
        self.modal=None
        self.parent=parent
        self.doDraw = false
        self.commentwin=None
        EVT_PAINT(self, self.OnPaint)
        self.SetHotspotArea()
        EVT_IDLE(self, self.OnCheckDraw)
        EVT_MOTION(self, self.CheckMousePos)

    def CheckMousePos(self,event):
        self.SetHotspotArea()
        if self.checkhotspot(event.GetPosition()):
            if not self.commentwin:
                # init
                # Size ist fest vorgegeben, muss variabel
                #sein und an SetCommentwinPosition() weitergegeben werden.
                self.commentwin = frametools.MyMiniFrame(self.parent,
                                  -1, "Kommentar",
                                  self.SetCommentwinPos(), wxSize(100, 100),
                                                         wxSIMPLE_BORDER)
                self.panel=wxPanel(self.commentwin,-1)

self.panel.SetBackgroundColour(wxNamedColour(dbuser.GetbgFarbe()))

self.panel.SetForegroundColour(wxNamedColour(dbuser.GetTextFarbe()))

                #inhalt
                item1 = wxStaticBox( self.panel, -1, "Kommentar" )
                self.item0 = wxStaticBoxSizer( item1, wxVERTICAL )
                self.text=wxStaticText(self.panel,
                                       -1, "standard comment.",
wxDefaultPosition )
                EVT_ENTER_WINDOW(self.panel, self.InitOnExitEvent )
# i've tried another solutions to close the cwin, but i don'T
#now what panel or area i have to choose for the evt_handler.
#My target is to close the window if the user clicks on any place
# but not in the commentwin to close the cwin
                EVT_LEFT_UP(self.panel, self.DelThisOnClick)
                EVT_LEFT_UP(self, self.DelThisOnClick)
                EVT_LEFT_UP(self.window, self.DelThisOnClick)

···

#---
                self.item0.AddWindow(self.text, 15,
                                     wxALIGN_CENTRE|wxALL, 20 )

                #anzeige und ausrichtung des inhalts
                self.panel.SetAutoLayout( true )
                self.panel.SetSizer( self.item0 )
                self.item0.Fit( self.panel )
                self.commentwin.SetSize(self.panel.GetSize())

                self.modal=self.commentwin.ShowModal()
                self.commentwin.Destroy()
                self.commentwin=None
                self.doDraw=true
                self.DrawNew()
                self.window.Refresh(rect=(30,30,1,1))
            else:
                pass

    def InitOnExitEvent(self,event):
        EVT_LEAVE_WINDOW(self.panel,self.DelThis)

    def DelThis(self,event):
        if self.checkifoutside(event.GetPosition()):
            self.commentwin.EndModal(self.commentwin.GetReturnCode())
        else:
            pass

    def DelThisOnClick(self,event):
        if self.checkifoutside(event.GetPosition()):
            self.commentwin.EndModal(self.commentwin.GetReturnCode())

    def checkifoutside(self,pos):
        if pos.x >self.commentwin.GetPosition().x:
            if pos.x <
self.commentwin.GetPosition().x+self.commentwin.GetSize().GetWidth():
                if pos.y >self.commentwin.GetPosition().y:
                    if pos.y <
self.commentwin.GetPosition().y+self.commentwin.GetSize().GetHeight():
                        return 0
        return 1

    def wait(self,sek):
        time.sleep(sek)

    def SetCommentwinPos(self):
         #Positionsbestimmung
        windowSize=self.window.GetSize()
        windowPos=self.window.GetPosition()
        pos=self.GetPosition()
        pos=self.ClientToScreen(pos)

position=wxPoint(pos.x+self.GetSize().GetWidth(),pos.y-50)-self.GetPosition
()
        if position.y < windowPos.y:
            position.y=windowPos.y
        elif position.y > windowPos.y+windowSize.GetHeight():
            position.y=windowPos.y+windowSize.GetHeight()-130
        if position.x < windowPos.x:
            position.x=windowPos.x
        elif position.x > windowPos.x+windowSize.GetWidth()-100:
            position.x=windowPos.x+windowSize.GetWidth()-160
        return position

    def OnPaint(self, evt):
        # just set a flag so the drawing is done later after
        # CommentTextCtrl is done
        self.doDraw = true
        evt.Skip()

    def OnCheckDraw(self, evt):
        if self.doDraw:
            self.doDraw = false
            self.DrawNew()

    def DrawNew(self):
        dc = wxClientDC(self)
        dc.BeginDrawing()
        dc.SetPen(wxRED_PEN)
        dc.SetBrush(wxRED_BRUSH)
# is this needed??
        dc.SetBackground(wxRED_BRUSH)
#----

dc.DrawPolygon([self.upperleft,self.rightdown,self.corner],0,0,wxODDEVEN_RU
LE)
        dc.EndDrawing()
        ## Now draw your triangle hotspot in the corner using dc
        #dc.DrawRectangle(1, 1, 10, 10)

    def checkhotspot(self,pos):
        if (pos.x > self.upperleft.x):
            if (pos.y <self.rightdown.y):
                return 1
        return 0

    def SetHotspotArea(self):
        boxSize=self.GetSize()
        if boxSize.GetHeight()>50:
            boxSize.SetHeight(50)
        if self.multiline:
            boxSize.SetWidth(boxSize.GetWidth()-17)
        self.corner=wxPoint(boxSize.GetWidth()-7,0)
        self.rightdown=wxPoint(boxSize.GetWidth()-7,(boxSize.GetHeight()/3))

self.upperleft=wxPoint(boxSize.GetWidth()-7-(boxSize.GetHeight()/3),0)

System:
Win98 II all (required) Updates
Python 2.0
win32extensions for Python
wxpython 2.2

thx

Hi Rene,

Sorry to hear that you're having problems -- I'm not enough of a wxPython expert to be able to see what's wrong by glancing through your code, but I thought I'd suggest pulling your code into a small, standalone program that demonstrates the problem. Several times, I've found that by going through the process of pulling a misbehaving piece of code out of the application it's in and putting it into a (small!) standalone program, it's much easier to figure out what's going wrong and a lot of the time I figure it out myself, rather than having to wait for replies from the mailing list. It's also a *lot* easier for others to reproduce your problem if they can run the example code you send out to the mailing list -- I tried pasting your code into a small test application to see if I could show up the problem, but I quickly realised that your code isn't complete -- your CommentTextCtrl makes use of another class, frametools.MyMiniFrame, which you haven't supplied the source code to. This makes it rather hard to duplicate your problems!

If you could send out a simplified version of your CommentTextCtrl class wrapped up in a simple testing wxPython app, I'd be happy to run the example and see if I can't figure out what's wrong. That is, of course, if someone else with more experience doesn't point out something obvious in the meantime...

Cheers,

  - Erik.

···

At 10:52 18/05/2001 +0200, Rene Freund wrote:

hi,

this problem is to difficult to me, so i have to
ask yours another newbie question...
i think that robin answer me, so i say thx for
all of your advices. Also thx to all others of ya

Basics:
I have a TextCtrl with an Polygon like a triangle
drawed with ClientDc in an upper corner.
if the user moves the mouse over this triangle a
little Dialog without a caption appears and show
a comment. Like an Excel comment.
Because its difficult to close the commentwindow
without any button or a caption i decide to use
EVT_ENTER_WINDOW and LEAVE_WINDOW
to determine the closefunc. It's all for test. Later
there should be more ways to let disappear the win
if i enter the cwindow(resp. the panel). with my
mousecursor the EVT_LEAVE_Handler be
initialized and if i leave the commentwindow
it disappears.
Fine.
But after the commentwindow disappears another
open app (z.B. IE or any other open) gets active
for one second - change to foreground on my
desktop and then my app gets active again and
change to foreground... (???)
if the commentwindow was lying over the statusbar
(which was owned by the TopWindow) of my app
this will also happen, but my App übernimmt capture
immediatly the active status back. the other app will
only get for a ms the activestate...
Its very confuse to me..

i tried to refresh my window (better only one pixel) after
the closing of the commentwin to get my App showing and
not hiding, but that doesnt work...

=(

Thanx, reen

Rene Freund
rene@meder.de

Here's the code...
class CommentTextCtrl(wxTextCtrl):
   def __init__(self, parent, ID, value, pos, size, style):
       wxTextCtrl.__init__(self, parent, ID, value, pos, size, style)
       if style == 32:
           self.multiline=1
       else:
           self.multiline=0
       self.window=storedata.GetTopWindow()
self.rect=wxRect(self.window.GetPosition().x,self.window.GetPosition().y,se
lf.window.GetSize().GetWidth(),self.window.GetSize().GetHeight())
       self.comment=''
       self.modal=None
       self.parent=parent
       self.doDraw = false
       self.commentwin=None
       EVT_PAINT(self, self.OnPaint)
       self.SetHotspotArea()
       EVT_IDLE(self, self.OnCheckDraw)
       EVT_MOTION(self, self.CheckMousePos)

   def CheckMousePos(self,event):
       self.SetHotspotArea()
       if self.checkhotspot(event.GetPosition()):
           if not self.commentwin:
               # init
               # Size ist fest vorgegeben, muss variabel
               #sein und an SetCommentwinPosition() weitergegeben werden.
               self.commentwin = frametools.MyMiniFrame(self.parent,
                                 -1, "Kommentar",
                                 self.SetCommentwinPos(), wxSize(100, 100),
                                                        wxSIMPLE_BORDER)
               self.panel=wxPanel(self.commentwin,-1)
self.panel.SetBackgroundColour(wxNamedColour(dbuser.GetbgFarbe()))
self.panel.SetForegroundColour(wxNamedColour(dbuser.GetTextFarbe()))

               #inhalt
               item1 = wxStaticBox( self.panel, -1, "Kommentar" )
               self.item0 = wxStaticBoxSizer( item1, wxVERTICAL )
               self.text=wxStaticText(self.panel,
                                      -1, "standard comment.", wxDefaultPosition )
               EVT_ENTER_WINDOW(self.panel, self.InitOnExitEvent )
# i've tried another solutions to close the cwin, but i don'T
#now what panel or area i have to choose for the evt_handler.
#My target is to close the window if the user clicks on any place
# but not in the commentwin to close the cwin
               EVT_LEFT_UP(self.panel, self.DelThisOnClick)
               EVT_LEFT_UP(self, self.DelThisOnClick)
               EVT_LEFT_UP(self.window, self.DelThisOnClick)
#---
               self.item0.AddWindow(self.text, 15,
                                    wxALIGN_CENTRE|wxALL, 20 )

               #anzeige und ausrichtung des inhalts
               self.panel.SetAutoLayout( true )
               self.panel.SetSizer( self.item0 )
               self.item0.Fit( self.panel )
               self.commentwin.SetSize(self.panel.GetSize())
               self.modal=self.commentwin.ShowModal()
               self.commentwin.Destroy()
               self.commentwin=None
               self.doDraw=true
               self.DrawNew()
               self.window.Refresh(rect=(30,30,1,1))
           else:
               pass

   def InitOnExitEvent(self,event):
       EVT_LEAVE_WINDOW(self.panel,self.DelThis)

   def DelThis(self,event):
       if self.checkifoutside(event.GetPosition()):
           self.commentwin.EndModal(self.commentwin.GetReturnCode())
       else:
           pass

   def DelThisOnClick(self,event):
       if self.checkifoutside(event.GetPosition()):
           self.commentwin.EndModal(self.commentwin.GetReturnCode())

   def checkifoutside(self,pos):
       if pos.x >self.commentwin.GetPosition().x:
           if pos.x < self.commentwin.GetPosition().x+self.commentwin.GetSize().GetWidth():
               if pos.y >self.commentwin.GetPosition().y:
                   if pos.y < self.commentwin.GetPosition().y+self.commentwin.GetSize().GetHeight():
                       return 0
       return 1

   def wait(self,sek):
       time.sleep(sek)

   def SetCommentwinPos(self):
        #Positionsbestimmung
       windowSize=self.window.GetSize()
       windowPos=self.window.GetPosition()
       pos=self.GetPosition()
       pos=self.ClientToScreen(pos)
position=wxPoint(pos.x+self.GetSize().GetWidth(),pos.y-50)-self.GetPosition
()
       if position.y < windowPos.y:
           position.y=windowPos.y
       elif position.y > windowPos.y+windowSize.GetHeight():
           position.y=windowPos.y+windowSize.GetHeight()-130
       if position.x < windowPos.x:
           position.x=windowPos.x
       elif position.x > windowPos.x+windowSize.GetWidth()-100:
           position.x=windowPos.x+windowSize.GetWidth()-160
       return position

   def OnPaint(self, evt):
       # just set a flag so the drawing is done later after
       # CommentTextCtrl is done
       self.doDraw = true
       evt.Skip()

   def OnCheckDraw(self, evt):
       if self.doDraw:
           self.doDraw = false
           self.DrawNew()

   def DrawNew(self):
       dc = wxClientDC(self)
       dc.BeginDrawing()
       dc.SetPen(wxRED_PEN)
       dc.SetBrush(wxRED_BRUSH)
# is this needed??
       dc.SetBackground(wxRED_BRUSH)
#----
dc.DrawPolygon([self.upperleft,self.rightdown,self.corner],0,0,wxODDEVEN_RU
LE)
       dc.EndDrawing()
       ## Now draw your triangle hotspot in the corner using dc
       #dc.DrawRectangle(1, 1, 10, 10)

   def checkhotspot(self,pos):
       if (pos.x > self.upperleft.x):
           if (pos.y <self.rightdown.y):
               return 1
       return 0

   def SetHotspotArea(self):
       boxSize=self.GetSize()
       if boxSize.GetHeight()>50:
           boxSize.SetHeight(50)
       if self.multiline:
           boxSize.SetWidth(boxSize.GetWidth()-17)
       self.corner=wxPoint(boxSize.GetWidth()-7,0)
       self.rightdown=wxPoint(boxSize.GetWidth()-7,(boxSize.GetHeight()/3))
self.upperleft=wxPoint(boxSize.GetWidth()-7-(boxSize.GetHeight()/3),0)

System:
Win98 II all (required) Updates
Python 2.0
win32extensions for Python
wxpython 2.2

thx

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwindows.org
http://lists.wxwindows.org/mailman/listinfo/wxpython-users

But after the commentwindow disappears another
open app (z.B. IE or any other open) gets active
for one second - change to foreground on my
desktop and then my app gets active again and
change to foreground... (???)

This may be fixed in 2.3. I remember discussion about some issue with focus
not returning to the right place in certain situations, maybe this is the
same thing.

                EVT_ENTER_WINDOW(self.panel, self.InitOnExitEvent )
# i've tried another solutions to close the cwin, but i don'T
#now what panel or area i have to choose for the evt_handler.
#My target is to close the window if the user clicks on any place
# but not in the commentwin to close the cwin

Call commentwin.CaptureMouse() and then give the commentwin mouse event
handlers that check for clicks outside of its boundaries.

···

--
Robin Dunn
Software Craftsman
robin@AllDunn.com Java give you jitters?
http://wxPython.org Relax with wxPython!