PageRenderTime 59ms CodeModel.GetById 50ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/library/Window.py

http://pyjamas.googlecode.com/
Python | 145 lines | 142 code | 3 blank | 0 comment | 0 complexity | 1ad78391dafad45e4461b6c4d306056b MD5 | raw file
  1import Location
  2closingListeners = []
  3resizeListeners = []
  4
  5def addWindowCloseListener(listener):
  6    global closingListeners
  7    closingListeners.append(listener)
  8
  9def addWindowResizeListener(listener):
 10    global resizeListeners
 11    resizeListeners.append(listener)
 12
 13def alert(msg):
 14    JS("""
 15    $wnd.alert(msg);
 16    """)
 17
 18def confirm(msg):
 19    JS("""
 20    return $wnd.confirm(msg);
 21    """)
 22
 23def enableScrolling(enable):
 24    JS("""
 25    $doc.body.style.overflow = enable ? 'auto' : 'hidden';
 26    """)
 27
 28def getClientHeight():
 29    JS("""
 30    if ($wnd.innerHeight)
 31        return $wnd.innerHeight;
 32    return $doc.body.clientHeight;
 33    """)
 34
 35def getClientWidth():
 36    JS("""
 37    if ($wnd.innerWidth)
 38        return $wnd.innerWidth;
 39    return $doc.body.clientWidth;
 40    """)
 41
 42JS("var Window_location = null")
 43def getLocation():
 44    global location
 45    JS("""
 46    if(!Window_location)
 47       Window_location = Location_Location($wnd.location);
 48    return Window_location;
 49    """)
 50 
 51 
 52def getTitle():
 53    JS("""
 54    return $doc.title;
 55    """)
 56
 57def open(url, name, features):
 58    JS("""
 59    $wnd.open(url, name, features);
 60    """)
 61
 62def removeWindowCloseListener(listener):
 63    global closingListeners
 64    closingListeners.remove(listener)
 65
 66def removeWindowResizeListener(listener):
 67    global resizeListeners
 68    resizeListeners.remove(listener)
 69
 70def setMargin(size):
 71    JS("""
 72    $doc.body.style.margin = size;
 73    """)
 74
 75def setTitle(title):
 76    JS("""
 77    $doc.title = title;
 78    """)
 79
 80# TODO: call fireClosedAndCatch
 81def onClosed():
 82    fireClosedImpl()
 83
 84# TODO: call fireClosingAndCatch
 85def onClosing():
 86    fireClosingImpl()
 87
 88# TODO: call fireResizedAndCatch
 89def onResize():
 90    fireResizedImpl()
 91
 92def fireClosedAndCatch(handler):
 93    # FIXME - need implementation
 94    pass
 95
 96def fireClosedImpl():
 97    global closingListeners
 98    
 99    for listener in closingListeners:
100        listener.onWindowClosed()
101
102def fireClosingAndCatch(handler):
103    # FIXME - need implementation
104    pass
105
106def fireClosingImpl():
107    global closingListeners
108    
109    ret = None
110    for listener in closingListeners:
111        msg = listener.onWindowClosing()
112        if ret == None:
113            ret = msg
114    return ret
115
116def fireResizedAndCatch(handler):
117    # FIXME - need implementation
118    pass
119
120def fireResizedImpl():
121    global resizeListeners
122
123    for listener in resizeListeners:
124        listener.onWindowResized(getClientWidth(), getClientHeight())
125
126def init():
127    JS("""
128    $wnd.__pygwt_initHandlers(
129        function() {
130            Window_onResize();
131        },
132        function() {
133            return Window_onClosing();
134        },
135        function() {
136            Window_onClosed();
137            $wnd.onresize = null;
138            $wnd.onbeforeclose = null;
139            $wnd.onclose = null;
140        }
141    );
142    """)
143
144init()
145