[AG-TECH] Shared app callback problem

Rob King r5king at ryerson.ca
Tue Jun 22 12:43:43 CDT 2004


	Thanks again Susanne,

	After looking at the shared question tool code it made much more
sense.  I finally got the console apps up and running and it has been a
great help in debugging so far.
	 I've finally narrowed down the problem I've been having.  It would
seem as though there is some problem with creating an instance of a wxPython
widget from within a shared app event call-back.  Even when using the same
code for object creation, when instantiated from within a call-back the
object locks up (even though traces in the __init__ seem to indicate it
initializes fine).  I think it might be some sort of funky threading
conflict between AGTK, and wxPython...

	Below I have included the code of a really small shared app that
exhibits this behaviour.  To try it, simply paste the code into a .py file,
replace appUrl with an application session (though I'll keep the current one
up, so it *should* work as is), and run it from the command line.
	If running one instance, pressing the new note button should pop up
a yellow tooltip that can be moved with the mouse.  To see the problem run
two instances (on the same or different computers...shouldn't matter).
Pressing the new note button will work as it should in the app where the
button was pressed.  A yellow tooltip will also pop up on the receiving end,
but the widget will lock up, so when mousing over you get an hour glass, and
you cannot move the tooltip anymore.

	Hopefully someone will be able to help me figure this one out, as
this same problem has been plaguing me over the past month+.  

	Thanks in advance!

	-rob king
	



###########################Start code##################################


from wxPython.wx import *
import AccessGrid.SharedAppClient
from AccessGrid.Toolkit import CmdlineApplication

class StickyBoard(wxApp):
    def __init__( self, appUrl, debugMode = 1, logFile = None):
        self.appURL = appUrl
        

        # Create shared application client
        self.sharedAppClient =
AccessGrid.SharedAppClient.SharedAppClient("StickyBoard")
        self.log = self.sharedAppClient.InitLogging(debugMode, logFile)

        self.app = CmdlineApplication.instance()
        self.app.Initialize("Sticky Board")

        # Connect to shared application service.
        self.sharedAppClient.Join(appUrl)

        wxApp.__init__(self, False)


    def OnInit(self):
        self.Control = StickyBoardControl(self)
        self.SetTopWindow(self.Control)
        self.Control.Show(1)
        self.sharedAppClient.RegisterEventCallback("note",
self.Control.noteCB )
        return 1



class StickyBoardControl(wxFrame):
    def __init__(self, parent):
        kwds =
{"style":wxCAPTION|wxMINIMIZE_BOX|wxCLOSE_BOX|wxSYSTEM_MENU|wxRESIZE_BORDER,
"size":(120, 120), "pos":(0,0)}

        wxFrame.__init__(self, *(None, -1, ""), **kwds)

        self.parent = parent
        self.notes = []

        self.button = wxButton(self, -1, "New Note")
        self.Bind(EVT_BUTTON, self.newSticky, self.button)

        box = wxBoxSizer(wxVERTICAL)
        box.Add((0, 0))
        box.Add(self.button, 0, wxALIGN_CENTER|wxALL, 15)
        self.SetAutoLayout(True)
        self.SetSizer(box)

    def noteCB(self, event):
        senderId = event.data
        if senderId == self.parent.sharedAppClient.GetPublicId():
            self.parent.log.debug("Ignoring edit message from myself ")
        else:
            self.parent.log.debug( "adding note" )
            self.note = Note(self, wxSIMPLE_BORDER)

    def newSticky(self, event=None):
        self.note = Note(self, wxSIMPLE_BORDER)
        publicID = self.parent.sharedAppClient.GetPublicId()
        self.parent.sharedAppClient.SendEvent("note", (publicID))




class Note(wxPopupWindow):
    def __init__(self, parent, style, text = None, pos = None):

        self.parent = parent

        wxPopupWindow.__init__(self, parent, style)

        self.SetBackgroundColour("GOLDENROD")

        self.SetSize((50,50))

        self.Bind(EVT_LEFT_DOWN, self.OnMouseLeftDown)
        self.Bind(EVT_MOTION, self.OnMouseMotion)
        self.Bind(EVT_LEFT_UP, self.OnMouseLeftUp)

        self.Show(1)

    def OnMouseLeftDown(self, evt):
        self.ldPos = evt.GetEventObject().ClientToScreen(evt.GetPosition())
        self.wPos = self.ClientToScreen((0,0))
        self.CaptureMouse()

    def OnMouseMotion(self, evt):
        if evt.Dragging() and evt.LeftIsDown():
            dPos = evt.GetEventObject().ClientToScreen(evt.GetPosition())
            nPos = (self.wPos.x + (dPos.x - self.ldPos.x),
                    self.wPos.y + (dPos.y - self.ldPos.y))
            self.Move(nPos)

    def OnMouseLeftUp(self, evt):
        self.ReleaseMouse()



if __name__ == "__main__":

    from AccessGrid.Toolkit import CmdlineApplication
    app = CmdlineApplication.instance()
    app.Initialize("Sticky Board")

    # Url from app properties dialog in venue client.  Change these!
    appUrl = 'https://vv2.mcs.anl.gov:9000/119'
    debugMode = 1

    stickyBoard = StickyBoard(appUrl, debugMode, None)
    stickyBoard.MainLoop()


#############################end code####################################









-----Original Message-----
From: Susanne Lefvert [mailto:lefvert at mcs.anl.gov] 
Sent: June 21, 2004 3:12 PM
To: Rob King
Subject: RE: [AG-TECH] Errors silenced?


Hello Rob,

I have tried to answer your questions below. 

Regards,

Susanne

On Mon, 21 Jun 2004, Rob King wrote:

> 	Hmmm... I think I must be missing something here...
> 
> 	I tried putting this in a file (test.py):
> 
> from AccessGrid.Toolkit import CmdlineApplication
> app = CmdlineApplication.instance()
> app.Initialize("Sticky Board") 
> appUrl = 'https://vv2.mcs.anl.gov:9000/208'	
> 
> And ran it, but nothing happened.  It just ran through and ended.
> I also tried with app.Initialize("StickyBoard.py"), and that did nothing
as
> well.
> 
> So a few questions:
> Should <appName> be the name registered in the venue client, or the
> filename?


You can set <appName> to whatever you want, I used "SharedQuestionTool".


> Should the code above be a standalone app run from a command prompt, or
> should the code be incorporated into my shared app code somehow?
> I looked in the toolkit.py sourcecode, and I can't find where it actually
> runs the app, or takes in the appURL... am I looking at this wrong?


You can see an example of how I am using the code in
/AccessGrid/sharedapps/SharedQuestionTool/SharedQuestionTool.py


> 
> I also took a look at the AccessGrid/tools/VenueApp.py file, and from what
I
> could interpret, it seems to create an application session on the server
but
> doesn't run the application locally.  Again I may be mistaken though.


That's correct. You can use that code if you want to get access to an 
application url without having to open the application session properties 
dialog in the Venue Client. 


> 
> 	Hopefully you can help me with this!
> 
> 	Thanks a lot,
> 
> 	Rob king
> 
> -----Original Message-----
> From: owner-ag-tech at mcs.anl.gov [mailto:owner-ag-tech at mcs.anl.gov] On
Behalf
> Of Susanne Lefvert
> Sent: June 17, 2004 4:06 PM
> To: Rob King
> Cc: ag-tech at mcs.anl.gov
> Subject: Re: [AG-TECH] Errors silenced?
> 
> 
> Hello Rob,
> 
> I am glad to hear that you are working on a shared application for the AG 
> and would like to help you with your logging issue.  Apparently, log files

> for shared apps are not created properly and we are working to get that 
> fixed.  In the mean time, you can use following code to test your app 
> outside of the venue client:
> 
> from AccessGrid.Toolkit import CmdlineApplication
> app = CmdlineApplication.instance()
> app.Initialize("<appName>") 
> 
> # Url from app properties dialog in venue client (the 'Location 
> # URL' field in the dialog that shows up when you right click the 
> # application session you want to use and select 'Properties').
> appUrl = 'https://<host>:<port>/....'
> 
> This will print errors to the console and create a log <appName>.log file 
> where you are running your application.  Also, 
> AccessGrid/tools/VenueApp.py in cvs shows you how to create an 
> application session in the venue without using the venue client.         
> 
> Hope this helps,
> 
> Susanne
> 
>   
> 
> 
> 
> On Thu, 17 Jun 2004, Rob King wrote:
> 
> >             Hello Everyone,
> > 
> >  
> > 
> >             I am working on developing a shared application right now,
but
> > have been having some problems.  I could probably figure them out, but
it
> > seems as though the errors are being suppressed somewhere.  It's
happened
> in
> > a couple of places so far, and problems become difficult to debug.  I
have
> > debug logging mode on, but when it gets to an error, it doesn't log it,
it
> > just stops.  Is there some way to coax the error messages into a log or
> even
> > the debug console?  My current method of putting a debug log statement
> every
> > couple lines of code has only met with limited success ;)
> > 
> >             Hope someone can help!
> > 
> >  
> > 
> >             -rob king
> > 
> > 
> 
> 
> __________ NOD32 1.772 (20040524) Information __________
> 
> This message was checked by NOD32 Antivirus System.
> http://www.nod32.com
> 
> 
> 

__________ NOD32 1.772 (20040524) Information __________

This message was checked by NOD32 Antivirus System.
http://www.nod32.com





More information about the ag-tech mailing list