Permalink
Browse files

create InnerHTML and InnerText classes, remove duplicated functions, …

…use multiple base classes

git-svn-id: https://pyjamas.svn.sourceforge.net/svnroot/pyjamas/trunk@2362 7a2bd370-bda8-463c-979e-2900ccfb811e
  • Loading branch information...
lkcl
lkcl committed Dec 9, 2009
1 parent 511a7ce commit c3763b8c5030e7787a322bc9e5c157adf76dc3d7
@@ -8,7 +8,7 @@
import pygwt
def greet(fred):
- print "greet button"
+ fred.setText("No, really click me!")
Window.alert("Hello, AJAX!")
if __name__ == '__main__':
@@ -15,23 +15,12 @@
from pyjamas import DOM
from pyjamas import Factory
from FocusWidget import FocusWidget
+from pyjamas.ui import InnerText, InnerHTML
-class ButtonBase(FocusWidget):
+class ButtonBase(FocusWidget, InnerHTML, InnerText):
def __init__(self, element, **kwargs):
FocusWidget.__init__(self, element, **kwargs)
- def getHTML(self):
- return DOM.getInnerHTML(self.getElement())
-
- def getText(self):
- return DOM.getInnerText(self.getElement())
-
- def setHTML(self, html):
- DOM.setInnerHTML(self.getElement(), html)
-
- def setText(self, text):
- DOM.setInnerText(self.getElement(), text)
-
Factory.registerClass('pyjamas.ui.ButtonBase', ButtonBase)
@@ -17,8 +17,9 @@
from Label import Label
from pyjamas.ui import Event
+from pyjamas.ui import InnerHTML
-class HTML(Label):
+class HTML(Label, InnerHTML):
def __init__(self, html=None, wordWrap=True, Element=None, **kwargs):
if not kwargs.has_key('StyleName'): kwargs['StyleName']="gwt-HTML"
@@ -30,11 +31,5 @@ def __init__(self, html=None, wordWrap=True, Element=None, **kwargs):
Label.__init__(self, **kwargs)
self.sinkEvents(Event.ONCLICK | Event.MOUSEEVENTS)
- def getHTML(self):
- return DOM.getInnerHTML(self.getElement())
-
- def setHTML(self, html):
- DOM.setInnerHTML(self.getElement(), html)
-
Factory.registerClass('pyjamas.ui.HTML', HTML)
@@ -14,6 +14,7 @@
# limitations under the License.
from pyjamas import DOM
from pyjamas import Factory
+from pyjamas.ui import InnerHTML
from ComplexPanel import ComplexPanel
@@ -55,7 +56,7 @@ def getElementById(element, id):
return None
-class HTMLPanel(ComplexPanel):
+class HTMLPanel(ComplexPanel, InnerHTML):
def __init__(self, html, **kwargs):
# NOTE! don't set a default style on this panel, because the
# HTML might expect to have one already.
@@ -68,12 +69,6 @@ def __init__(self, html, **kwargs):
self.setElement(element)
ComplexPanel.__init__(self, **kwargs)
- def setHTML(self, html):
- DOM.setInnerHTML(self.getElement(), html)
-
- def getHTML(self):
- return DOM.getInnerHTML(self.getElement())
-
def add(self, widget, id):
element = getElementById(self.getElement(), id)
if element is None:
@@ -14,12 +14,13 @@
# limitations under the License.
from pyjamas import DOM
from pyjamas import Factory
+from pyjamas.ui import InnerText
from Widget import Widget
from MouseListener import MouseHandler
from ClickListener import ClickHandler
-class Label(Widget, MouseHandler, ClickHandler):
+class Label(Widget, MouseHandler, ClickHandler, InnerText):
def __init__(self, text=None, wordWrap=True, **kwargs):
if not kwargs.has_key('StyleName'): kwargs['StyleName']="gwt-Label"
@@ -41,19 +42,13 @@ def __init__(self, text=None, wordWrap=True, **kwargs):
def getHorizontalAlignment(self):
return self.horzAlign
- def getText(self):
- return DOM.getInnerText(self.getElement())
-
def getWordWrap(self):
return not (DOM.getStyleAttribute(self.getElement(), "whiteSpace") == "nowrap")
def setHorizontalAlignment(self, align):
self.horzAlign = align
DOM.setStyleAttribute(self.getElement(), "textAlign", align)
- def setText(self, text):
- DOM.setInnerText(self.getElement(), text)
-
def setWordWrap(self, wrap):
if wrap:
style = "normal"
@@ -17,8 +17,9 @@
from UIObject import UIObject
from pyjamas.ui import Event
+from pyjamas.ui import InnerHTML, InnerText
-class MenuItem(UIObject):
+class MenuItem(UIObject, InnerHTML, InnerText):
# also callable as:
# MenuItem(text, cmd)
# MenuItem(text, asHTML, cmd)
@@ -68,30 +69,18 @@ def __init__(self, text, asHTML, subMenu=None, **kwargs):
def getCommand(self):
return self.command
- def getHTML(self):
- return DOM.getInnerHTML(self.getElement())
-
def getParentMenu(self):
return self.parentMenu
def getSubMenu(self):
return self.subMenu
- def getText(self):
- return DOM.getInnerText(self.getElement())
-
def setCommand(self, cmd):
self.command = cmd
- def setHTML(self, html):
- DOM.setInnerHTML(self.getElement(), html)
-
def setSubMenu(self, subMenu):
self.subMenu = subMenu
- def setText(self, text):
- DOM.setInnerText(self.getElement(), text)
-
def setParentMenu(self, parentMenu):
self.parentMenu = parentMenu
@@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+from pyjamas import DOM
+
class HasHorizontalAlignment:
ALIGN_LEFT = "left"
ALIGN_CENTER = "center"
@@ -61,4 +63,19 @@ def __init__(self, **kwargs):
fn(*args)
else:
fn(args)
-
+class InnerHTML(object):
+
+ def getHTML(self):
+ return DOM.getInnerHTML(self.getElement())
+
+ def setHTML(self, html):
+ DOM.setInnerHTML(self.getElement(), html)
+
+class InnerText(object):
+
+ def setText(self, text):
+ DOM.setInnerText(self.getElement(), text)
+
+ def getText(self):
+ return DOM.getInnerText(self.getElement())
+

0 comments on commit c3763b8

Please sign in to comment.