Package pyjamas :: Package ui :: Module DialogBox
[hide private]
[frames] | no frames]

Source Code for Module pyjamas.ui.DialogBox

  1  # Copyright 2006 James Tauber and contributors 
  2  # Copyright (C) 2009, 2010 Luke Kenneth Casson Leighton <lkcl@lkcl.net> 
  3  # 
  4  # Licensed under the Apache License, Version 2.0 (the "License"); 
  5  # you may not use this file except in compliance with the License. 
  6  # You may obtain a copy of the License at 
  7  # 
  8  #     http://www.apache.org/licenses/LICENSE-2.0 
  9  # 
 10  # Unless required by applicable law or agreed to in writing, software 
 11  # distributed under the License is distributed on an "AS IS" BASIS, 
 12  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 13  # See the License for the specific language governing permissions and 
 14  # limitations under the License. 
 15  from pyjamas import DOM 
 16  from pyjamas import Factory 
 17   
 18  from pyjamas.ui.PopupPanel import PopupPanel 
 19  from pyjamas.ui.HTML import HTML 
 20  from pyjamas.ui.FlexTable import FlexTable 
 21  from pyjamas.ui import HasHorizontalAlignment 
 22  from pyjamas.ui import HasVerticalAlignment 
 23  from pyjamas.ui import GlassWidget 
24 25 26 -class DialogBox(PopupPanel):
27 _props = [ 28 ("caption", "Caption", "HTML", None), 29 ] 30
31 - def __init__(self, autoHide=None, modal=True, centered=False, 32 **kwargs):
33 # Init section 34 self.dragging = False 35 self.dragStartX = 0 36 self.dragStartY = 0 37 self.child = None 38 self.panel = FlexTable( 39 Height="100%", 40 BorderWidth="0", 41 CellPadding="0", 42 CellSpacing="0", 43 ) 44 cf = self.panel.getCellFormatter() 45 cf.setHeight(1, 0, "100%") 46 cf.setWidth(1, 0, "100%") 47 cf.setAlignment( 48 1, 0, 49 HasHorizontalAlignment.ALIGN_CENTER, 50 HasVerticalAlignment.ALIGN_MIDDLE, 51 ) 52 53 # Arguments section 54 self.modal = modal 55 self.caption = HTML() 56 self.panel.setWidget(0, 0, self.caption) 57 self.caption.setStyleName("Caption") 58 self.caption.addMouseListener(self) 59 60 # Finalize 61 kwargs['StyleName'] = kwargs.get('StyleName', "gwt-DialogBox") 62 PopupPanel.__init__(self, autoHide, modal, **kwargs) 63 PopupPanel.setWidget(self, self.panel) 64 65 self.centered = centered
66
67 - def onWindowResized(self, width, height):
68 super(DialogBox, self).onWindowResized(width, height) 69 if self.centered: 70 self.centerBox()
71
72 - def show(self):
73 super(DialogBox, self).show() 74 if self.centered: 75 self.centerBox()
76 77 @classmethod
78 - def _getProps(self):
79 return PopupPanel._getProps() + self._props
80
81 - def onEventPreview(self, event):
82 # preventDefault on mousedown events, outside of the 83 # dialog, to stop text-selection on dragging 84 type = DOM.eventGetType(event) 85 if type == 'mousedown': 86 target = DOM.eventGetTarget(event) 87 elem = self.caption.getElement() 88 event_targets_popup = target and DOM.isOrHasChild(elem, target) 89 if event_targets_popup: 90 DOM.eventPreventDefault(event) 91 return PopupPanel.onEventPreview(self, event)
92
93 - def getHTML(self):
94 return self.caption.getHTML()
95
96 - def getText(self):
97 return self.caption.getText()
98
99 - def setHTML(self, html):
100 self.caption.setHTML(html)
101
102 - def setText(self, text):
103 self.caption.setText(text)
104
105 - def onMouseDown(self, sender, x, y):
106 self.dragging = True 107 GlassWidget.show(self.caption) 108 self.dragStartX = x 109 self.dragStartY = y
110
111 - def onMouseEnter(self, sender):
112 pass
113
114 - def onMouseLeave(self, sender):
115 pass
116
117 - def onMouseMove(self, sender, x, y):
118 if not self.dragging: 119 return 120 absX = x + self.getAbsoluteLeft() 121 absY = y + self.getAbsoluteTop() 122 self.setPopupPosition(absX - self.dragStartX, 123 absY - self.dragStartY)
124
125 - def onMouseUp(self, sender, x, y):
126 self.endDragging()
127
128 - def onMouseGlassEnter(self, sender):
129 pass
130
131 - def onMouseGlassLeave(self, sender):
132 self.endDragging()
133
134 - def endDragging(self):
135 if not self.dragging: 136 return 137 self.dragging = False 138 GlassWidget.hide()
139
140 - def remove(self, widget):
141 if self.child != widget: 142 return False 143 144 self.panel.remove(widget) 145 self.child = None 146 return True
147
148 - def doAttachChildren(self):
149 PopupPanel.doAttachChildren(self) 150 self.caption.onAttach()
151
152 - def doDetachChildren(self):
153 PopupPanel.doDetachChildren(self) 154 self.caption.onDetach()
155
156 - def setWidget(self, widget):
157 if self.child is not None: 158 self.panel.remove(self.child) 159 160 if widget is not None: 161 self.panel.setWidget(1, 0, widget) 162 163 self.child = widget
164 165 Factory.registerClass('pyjamas.ui.DialogBox', 'DialogBox', DialogBox) 166