Package library :: Package pyjamas :: Module Window
[hide private]
[frames] | no frames]

Source Code for Module library.pyjamas.Window

  1  # This is the pyjd Window module. 
  2  # For the pyjamas/javascript version, see __browser__.pyjamas.Window 
  3   
  4  """ 
  5      Window provides access to the DOM model's global Window. 
  6  """ 
  7   
  8  closingListeners = [] 
  9  resizeListeners = [] 
 10   
 11  from __pyjamas__ import JS, doc, wnd, get_main_frame 
 12  from pyjamas import Location 
 13   
14 -def init_listeners():
15 pass
16
17 -def addWindowCloseListener(listener):
18 closingListeners.append(listener)
19
20 -def addWindowResizeListener(listener):
21 resizeListeners.append(listener)
22
23 -def removeWindowCloseListener(listener):
24 closingListeners.remove(listener)
25
26 -def removeWindowResizeListener(listener):
27 resizeListeners.remove(listener)
28
29 -def alert(txt):
30 get_main_frame()._alert(txt)
31
32 -def confirm(msg):
33 return wnd().confirm(msg)
34
35 -def prompt(msg, defaultReply=""):
36 return wnd().prompt(msg, defaultReply, "", 0)
37
38 -def enableScrolling(enable):
39 doc().body.style.overflow = enable and 'auto' or 'hidden'
40
41 -def scrollBy(x, y):
42 wnd().scrollBy(x, y)
43
44 -def scroll(x, y):
45 wnd().scroll(x, y)
46
47 -def getClientHeight():
48 try: 49 return wnd().innerHeight 50 except: 51 return doc().body.clientHeight;
52
53 -def getClientWidth():
54 try: 55 return wnd().innerWidth 56 except: 57 return doc().body.clientWidth;
58
59 -def getScrollLeft():
60 return getDocumentRoot().scrollLeft;
61
62 -def getScrollTop():
63 return getDocumentRoot().scrollTop;
64
65 -def getDocumentRoot():
66 if doc().compatMode == 'CSS1Compat': 67 return doc().documentElement 68 return doc().body
69
70 -def setLocation(url):
71 w = wnd() 72 w.location = url
73 74 location = None 75
76 -def getLocation():
77 global location 78 if not location: 79 location = Location.Location(wnd().location) 80 return location
81
82 -def getTitle():
83 return doc().title
84
85 -def open(url, name, features):
86 return wnd().open(url, name, features)
87
88 -def setMargin(size):
89 doc().body.style.margin = size
90
91 -def setTitle(title):
92 d = doc() 93 d.title = title
94
95 -def setOnError(onError):
96 pass
97
98 -def onError(msg, url, linenumber):
99 pass
100 101 # TODO: call fireClosedAndCatch
102 -def onClosed():
103 fireClosedImpl()
104 105 # TODO: call fireClosingAndCatch
106 -def onClosing():
107 fireClosingImpl()
108 109 # TODO: call fireResizedAndCatch
110 -def onResize():
111 fireResizedImpl()
112
113 -def fireClosedAndCatch(handler):
114 # FIXME - need implementation 115 pass
116
117 -def fireClosedImpl():
118 for listener in closingListeners: 119 listener.onWindowClosed()
120
121 -def fireClosingAndCatch(handler):
122 # FIXME - need implementation 123 pass
124
125 -def resize(width, height):
126 """ changes size to specified width and height 127 """ 128 wnd().resizeTo(width, height)
129
130 -def resizeBy(width, height):
131 """ changes size by specified width and height 132 """ 133 wnd().resizeBy(width, height)
134
135 -def fireClosingImpl():
136 ret = None 137 for listener in closingListeners: 138 msg = listener.onWindowClosing() 139 if ret is None: 140 ret = msg 141 return ret
142
143 -def fireResizedAndCatch(handler):
144 # FIXME - need implementation 145 pass
146
147 -def fireResizedImpl():
148 for listener in resizeListeners: 149 listener.onWindowResized(getClientWidth(), getClientHeight())
150
151 -def init():
152 pass
153 154 init() 155