Hi Luke,

First of all thanks for your work on pyjamas.

I tried to login to the mailing list, but when I provide my OpenID (anthon) I get a message this is invalid, and when I try to 'contact owner to join' on the old mailing list I am told I have insufficient permissions. However also on that page it is written that I have to write to the address '[email protected]', so that is what I am trying now. I must say I find it a bit of hurdle to contact the group ;-)

Two years ago I looked at pyjamas and did not 'get it' thinking there were not enough widgets. So I went with web2py/jQuery for an application that I did need to write. In the mean time I changed web2py to allow partial updates of the pages (ie. submit via javascript) as I could not afford complete redraws of the pages.

Recently I looked at a better way to create my of client side widgets and rediscovered Pyjamas. I did however not want to throw away everything done in jQuery right away. That meant trying to integrate the button form Hello World in one of my current web2py applications, which was relatively easy using the wiki page
http://pyjs.org/wiki/integratingwithexistingprojects/

This is the code that I added to web2py_ajax_init():
  app = __pygwt_modController._get('apps', 'test00');
  if (app) {
    var t = app.reference.$pyjs.loaded_modules['test00'];
    t['main']()
  }
As you might guess test00.py is the program for the button which has a function main() that does the work it gets compiled into test00.html which is loaded from the directory with static files under the web2py application. The main function gets the DOM element based on an ID and then changes that element.

This works fine on the first load of the page, but not on the partial redraws by jQuery (although web2py_ajax_init is called after such an event).

After some digging I found that in rootPanels in library/gwt/ui/RootPanel.py caches the IDs are cached to be able to do an onDetach() on closing the windows (onWindowsClosed()). However this does not clear out rootPanels (so things are still cached) and anyway onWindowsClosed() is not called if there element goes away without closing the window.

With the attached patch and the following test in test00.py at the beginning of main():
    if panelManager.has_key('fun'):
        panelManager['fun'].onWindowClosed()
things work fine ( I tried to make panelManager a global variable inited to None, instead of a dict, but that did not work).

So now I finally can start to gradually transform everything to Pyjamas!

Anthon

diff -r 6301769a29de library/gwt/ui/RootPanel.py
--- a/library/gwt/ui/RootPanel.py	Tue Nov 15 10:52:12 2011 +0100
+++ b/library/gwt/ui/RootPanel.py	Mon Dec 12 10:34:18 2011 +0100
@@ -22,12 +22,15 @@
 from pyjamas.ui.AbsolutePanel import AbsolutePanel
 
 rootPanels = {}
+panelManager = {}
+
 class RootPanelManager(object):
 
     def onWindowClosed(self):
         global rootPanels
         for panel in rootPanels.itervalues():
             panel.onDetach()
+        rootPanels = {}
 
     def onWindowClosing(self):
         return None
@@ -50,8 +53,8 @@
 def manageRootPanel(panel, id=None):
 
     if len(rootPanels) < 1:
-        panelManager = RootPanelManager()
-        Window.addWindowCloseListener(panelManager)
+        panelManager['fun'] = RootPanelManager()
+        Window.addWindowCloseListener(panelManager['fun'])
 
     rootPanels[id] = panel
     return panel
diff -r 6301769a29de library/pyjamas/ui/RootPanel.py
--- a/library/pyjamas/ui/RootPanel.py	Tue Nov 15 10:52:12 2011 +0100
+++ b/library/pyjamas/ui/RootPanel.py	Mon Dec 12 10:34:18 2011 +0100
@@ -9,5 +9,6 @@
     get,
     manageRootPanel,
     rootPanels,
+    panelManager,
     sys,
 )


Reply via email to