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 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 PopupPanel import PopupPanel 
 19  from HTML import HTML 
 20  from FlexTable import FlexTable 
 21  from pyjamas.ui import HasHorizontalAlignment 
 22  from pyjamas.ui import HasVerticalAlignment 
 23   
24 -class DialogBox(PopupPanel):
25 - def __init__(self, autoHide=None, modal=True, **kwargs):
26 27 PopupPanel.__init__(self, autoHide, modal, **kwargs) 28 self.caption = HTML() 29 self.child = None 30 self.dragging = False 31 self.dragStartX = 0 32 self.dragStartY = 0 33 self.panel = FlexTable(Height="100%", BorderWidth="0", 34 CellPadding="0", CellSpacing="0") 35 self.panel.setWidget(0, 0, self.caption) 36 self.panel.getCellFormatter().setHeight(1, 0, "100%") 37 self.panel.getCellFormatter().setWidth(1, 0, "100%") 38 self.panel.getCellFormatter().setAlignment(1, 0, HasHorizontalAlignment.ALIGN_CENTER, HasVerticalAlignment.ALIGN_MIDDLE) 39 PopupPanel.setWidget(self, self.panel) 40 41 self.setStyleName("gwt-DialogBox") 42 self.caption.setStyleName("Caption") 43 self.caption.addMouseListener(self)
44
45 - def getHTML(self):
46 return self.caption.getHTML()
47
48 - def getText(self):
49 return self.caption.getText()
50
51 - def onEventPreview(self, event):
52 # preventDefault on mousedown events, outside of the 53 # dialog, to stop text-selection on dragging 54 type = DOM.eventGetType(event) 55 if type == 'mousedown': 56 target = DOM.eventGetTarget(event) 57 elem = self.caption.getElement() 58 event_targets_popup = target and DOM.isOrHasChild(elem, target) 59 if event_targets_popup: 60 DOM.eventPreventDefault(event) 61 return PopupPanel.onEventPreview(self, event)
62
63 - def onMouseDown(self, sender, x, y):
64 self.dragging = True 65 DOM.setCapture(self.caption.getElement()) 66 self.dragStartX = x 67 self.dragStartY = y
68
69 - def onMouseEnter(self, sender):
70 pass
71
72 - def onMouseLeave(self, sender):
73 pass
74
75 - def onMouseMove(self, sender, x, y):
76 if self.dragging: 77 absX = x + self.getAbsoluteLeft() 78 absY = y + self.getAbsoluteTop() 79 self.setPopupPosition(absX - self.dragStartX, absY - self.dragStartY)
80
81 - def onMouseUp(self, sender, x, y):
82 self.dragging = False 83 DOM.releaseCapture(self.caption.getElement())
84
85 - def remove(self, widget):
86 if self.child != widget: 87 return False 88 89 self.panel.remove(widget) 90 self.child = None 91 return True
92
93 - def setHTML(self, html):
94 self.caption.setHTML(html)
95
96 - def setText(self, text):
97 self.caption.setText(text)
98
99 - def doAttachChildren(self):
100 PopupPanel.doAttachChildren(self) 101 self.caption.onAttach()
102
103 - def doDetachChildren(self):
104 PopupPanel.doDetachChildren(self) 105 self.caption.onDetach()
106
107 - def setWidget(self, widget):
108 if self.child is not None: 109 self.panel.remove(self.child) 110 111 if widget is not None: 112 self.panel.setWidget(1, 0, widget) 113 114 self.child = widget
115 116 Factory.registerClass('pyjamas.ui.DialogBox', DialogBox) 117