Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

reworking lots more classes/panels - #34

git-svn-id: https://pyjamas.svn.sourceforge.net/svnroot/pyjamas/trunk@852 7a2bd370-bda8-463c-979e-2900ccfb811e
  • Loading branch information...
commit 1ed2c49fa4df5333871bee8f3f35598a9ac67287 1 parent 2d352d0
lkcl authored
View
18 examples/kitchensink/Layouts.py
@@ -31,11 +31,10 @@ def __init__(self):
to see the nifty scroll bars!"""
contents = HTML(text)
- scroller = ScrollPanel(contents)
- scroller.setStyleName("ks-layouts-Scroller")
+ scroller = ScrollPanel(contents, StyleName="ks-layouts-Scroller")
- dock = DockPanel()
- dock.setHorizontalAlignment(HasAlignment.ALIGN_CENTER)
+ dock = DockPanel(HorizontalAlignment=HasAlignment.ALIGN_CENTER,
+ Spacing=10)
north0 = HTML("This is the <i>first</i> north component", True)
east = HTML("<center>This<br>is<br>the<br>east<br>component</center>", True)
south = HTML("This is the south component")
@@ -53,14 +52,12 @@ def __init__(self):
for i in range(8):
flow.add(CheckBox("Flow %d" % i))
- horz = HorizontalPanel()
- horz.setVerticalAlignment(HasAlignment.ALIGN_MIDDLE)
+ horz = HorizontalPanel(VerticalAlignment=HasAlignment.ALIGN_MIDDLE)
horz.add(Button("Button"))
horz.add(HTML("<center>This is a<br>very<br>tall thing</center>", True))
horz.add(Button("Button"))
- vert = VerticalPanel()
- vert.setHorizontalAlignment(HasAlignment.ALIGN_CENTER)
+ vert = VerticalPanel(HorizontalAlignment=HasAlignment.ALIGN_CENTER)
vert.add(Button("Small"))
vert.add(Button("--- BigBigBigBig ---"))
vert.add(Button("tiny"))
@@ -91,9 +88,8 @@ def __init__(self):
disclose.add(HTML("""<b>Ta-daaaaa!</b><br />Ok - it could have
been<br />more of a surprise."""))
- panel = VerticalPanel()
- panel.setSpacing(8)
- panel.setHorizontalAlignment(HasAlignment.ALIGN_CENTER)
+ panel = VerticalPanel(Spacing=8,
+ HorizontalAlignment=HasAlignment.ALIGN_CENTER)
panel.add(self.makeLabel("Dock Panel"))
panel.add(dock)
View
15 examples/kitchensink/Lists.py
@@ -16,14 +16,11 @@ def __init__(self):
["foo3", "bar3", "baz3", "toto3", "tintin3"],
["foo4", "bar4", "baz4", "toto4", "tintin4"]]
- self.combo=ListBox()
- self.list=ListBox()
+ self.combo=ListBox(VisibleItemCount=1)
+ self.list=ListBox(MultipleSelect=True, VisibleItemCount=10)
self.echo=Label()
- self.combo.setVisibleItemCount(1)
self.combo.addChangeListener(self)
- self.list.setVisibleItemCount(10)
- self.list.setMultipleSelect(True)
for i in range(len(self.sStrings)):
self.combo.addItem("List %d" % i)
@@ -32,14 +29,12 @@ def __init__(self):
self.list.addChangeListener(self)
- horz = HorizontalPanel()
- horz.setVerticalAlignment(HasAlignment.ALIGN_TOP)
- horz.setSpacing(8)
+ horz = HorizontalPanel(VerticalAlignment=HasAlignment.ALIGN_TOP,
+ Spacing=8)
horz.add(self.combo)
horz.add(self.list)
- panel = VerticalPanel()
- panel.setHorizontalAlignment(HasAlignment.ALIGN_LEFT)
+ panel = VerticalPanel(HorizontalAlignment=HasAlignment.ALIGN_LEFT)
panel.add(horz)
panel.add(self.echo)
self.initWidget(panel)
View
10 examples/kitchensink/Tables.py
@@ -7,8 +7,8 @@
class Tables(Sink):
def __init__(self):
Sink.__init__(self)
- inner = Grid(10, 5)
- outer = FlexTable()
+ inner = Grid(10, 5, Width="100%", BorderWidth="1")
+ outer = FlexTable(Width="100%", BorderWidth="1")
outer.setWidget(0, 0, Image(self.baseURL() + "rembrandt/LaMarcheNocturne.jpg"))
outer.getFlexCellFormatter().setColSpan(0, 0, 2)
@@ -22,12 +22,6 @@ def __init__(self):
for j in range(5):
inner.setText(i, j, "%d" % i + ",%d" % j)
- inner.setWidth("100%")
- outer.setWidth("100%")
-
- inner.setBorderWidth("1")
- outer.setBorderWidth("1")
-
self.initWidget(outer)
def onShow(self):
View
5 library/pyjamas/ui/AbsolutePanel.py
@@ -18,11 +18,11 @@
class AbsolutePanel(ComplexPanel):
- def __init__(self):
- ComplexPanel.__init__(self)
+ def __init__(self, **kwargs):
self.setElement(DOM.createDiv())
DOM.setStyleAttribute(self.getElement(), "position", "relative")
DOM.setStyleAttribute(self.getElement(), "overflow", "hidden")
+ ComplexPanel.__init__(self, **kwargs)
def add(self, widget, left=None, top=None):
ComplexPanel.add(self, widget, self.getElement())
@@ -53,6 +53,7 @@ def getWidgetTop(self, widget):
def checkWidgetParent(self, widget):
if widget.getParent() != self:
+ # TODO: raise as exception instead
console.error("Widget must be a child of this panel.")
View
8 library/pyjamas/ui/CellPanel.py
@@ -17,15 +17,15 @@
class CellPanel(ComplexPanel):
- def __init__(self):
- ComplexPanel.__init__(self)
-
+ def __init__(self, **kwargs):
self.table = DOM.createTable()
+ self.setElement(self.table)
self.body = DOM.createTBody()
self.spacing = None
self.padding = None
DOM.appendChild(self.table, self.body)
- self.setElement(self.table)
+
+ ComplexPanel.__init__(self, **kwargs)
def getTable(self):
return self.table
View
5 library/pyjamas/ui/ComplexPanel.py
@@ -19,9 +19,8 @@ class ComplexPanel(Panel):
"""
Superclass for widgets with multiple children.
"""
- def __init__(self):
- Panel.__init__(self)
- self.children = []
+ def __init__(self, **kwargs):
+ Panel.__init__(self, **kwargs)
def add(self, widget, container):
self.insert(widget, container, len(self.children))
View
4 library/pyjamas/ui/Composite.py
@@ -16,9 +16,9 @@
from pyjamas.ui.Widget import Widget
class Composite(Widget):
- def __init__(self):
- Widget.__init__(self)
+ def __init__(self, **kwargs):
self.widget = None
+ Widget.__init__(self, **kwargs)
def initWidget(self, widget):
if self.widget is not None:
View
4 library/pyjamas/ui/DeckPanel.py
@@ -17,10 +17,10 @@
from pyjamas.ui.ComplexPanel import ComplexPanel
class DeckPanel(ComplexPanel):
- def __init__(self):
- ComplexPanel.__init__(self)
+ def __init__(self, **kwargs):
self.visibleWidget = None
self.setElement(DOM.createDiv())
+ ComplexPanel.__init__(self, **kwargs)
def add(self, widget):
self.insert(widget, self.getWidgetCount())
View
8 library/pyjamas/ui/DialogBox.py
@@ -27,13 +27,9 @@ def __init__(self, autoHide=None, modal=True):
self.dragging = False
self.dragStartX = 0
self.dragStartY = 0
- self.panel = FlexTable()
-
+ self.panel = FlexTable(Height="100%", BorderWidth="0",
+ CellPadding="0", CellSpacing="0")
self.panel.setWidget(0, 0, self.caption)
- self.panel.setHeight("100%")
- self.panel.setBorderWidth("0")
- self.panel.setCellPadding("0")
- self.panel.setCellSpacing("0")
self.panel.getCellFormatter().setHeight(1, 0, "100%")
self.panel.getCellFormatter().setWidth(1, 0, "100%")
self.panel.getCellFormatter().setAlignment(1, 0, HasHorizontalAlignment.ALIGN_CENTER, HasVerticalAlignment.ALIGN_MIDDLE)
View
9 library/pyjamas/ui/DockPanel.py
@@ -40,16 +40,17 @@ class DockPanel(CellPanel):
SOUTH = "south"
WEST = "west"
- def __init__(self):
- CellPanel.__init__(self)
+ def __init__(self, **kwargs):
+
+ if not kwargs.has_key('Spacing'): kwargs['Spacing'] = 0
+ if not kwargs.has_key('Padding'): kwargs['Padding'] = 0
self.horzAlign = HasHorizontalAlignment.ALIGN_LEFT
self.vertAlign = HasVerticalAlignment.ALIGN_TOP
self.center = None
self.dock_children = [] # TODO: can self.children be used instead?
- DOM.setAttribute(self.getTable(), "cellSpacing", "0")
- DOM.setAttribute(self.getTable(), "cellPadding", "0")
+ CellPanel.__init__(self, **kwargs)
def add(self, widget, direction):
if direction == self.CENTER:
View
8 library/pyjamas/ui/FlexTable.py
@@ -22,10 +22,10 @@
from pyjamas.ui.FlexCellFormatter import FlexCellFormatter
class FlexTable(HTMLTable):
- def __init__(self):
- HTMLTable.__init__(self)
- self.cellFormatter = FlexCellFormatter(self)
- self.rowFormatter = RowFormatter(self)
+ def __init__(self, **kwargs):
+ if not kwargs.has_key('CellFormatter'):
+ kwargs['CellFormatter'] = FlexCellFormatter(self)
+ HTMLTable.__init__(self, **kwargs)
def addCell(self, row):
self.insertCell(row, self.getCellCount(row))
View
6 library/pyjamas/ui/Grid.py
@@ -19,12 +19,10 @@
class Grid(HTMLTable):
- def __init__(self, rows=0, columns=0):
- HTMLTable.__init__(self)
- self.cellFormatter = CellFormatter(self)
- self.rowFormatter = RowFormatter(self)
+ def __init__(self, rows=0, columns=0, **kwargs):
self.numColumns = 0
self.numRows = 0
+ HTMLTable.__init__(self, **kwargs)
if rows > 0 or columns > 0:
self.resize(rows, columns)
View
13 library/pyjamas/ui/HTMLTable.py
@@ -22,10 +22,12 @@
class HTMLTable(Panel):
- def __init__(self):
- Panel.__init__(self)
- self.cellFormatter = CellFormatter(self)
- self.rowFormatter = RowFormatter(self)
+ def __init__(self, **kwargs):
+ if not kwargs.has_key('CellFormatter'):
+ kwargs['CellFormatter'] = CellFormatter(self)
+ if not kwargs.has_key('RowFormatter'):
+ kwargs['RowFormatter'] = RowFormatter(self)
+
self.tableListeners = []
self.widgetMap = {}
@@ -33,8 +35,11 @@ def __init__(self):
self.bodyElem = DOM.createTBody()
DOM.appendChild(self.tableElem, self.bodyElem)
self.setElement(self.tableElem)
+
self.sinkEvents(Event.ONCLICK)
+ Panel.__init__(self, **kwargs)
+
def addTableListener(self, listener):
self.tableListeners.append(listener)
View
11 library/pyjamas/ui/HorizontalPanel.py
@@ -19,18 +19,19 @@
class HorizontalPanel(CellPanel):
- def __init__(self):
- CellPanel.__init__(self)
+ def __init__(self, **kwargs):
+
+ if not kwargs.has_key('Spacing'): kwargs['Spacing'] = 0
+ if not kwargs.has_key('Padding'): kwargs['Padding'] = 0
self.horzAlign = HasHorizontalAlignment.ALIGN_LEFT
self.vertAlign = HasVerticalAlignment.ALIGN_TOP
+ CellPanel.__init__(self, **kwargs)
+
self.tableRow = DOM.createTR()
DOM.appendChild(self.getBody(), self.tableRow)
- DOM.setAttribute(self.getTable(), "cellSpacing", "0")
- DOM.setAttribute(self.getTable(), "cellPadding", "0")
-
def add(self, widget):
self.insert(widget, self.getWidgetCount())
View
14 library/pyjamas/ui/Image.py
@@ -20,18 +20,18 @@
prefetchImages = {}
class Image(Widget):
- def __init__(self, url=""):
- Widget.__init__(self)
+ def __init__(self, url="", **kwargs):
+ if not kwargs.has_key('StyleName'): kwargs['StyleName']="gwt-Image"
+ if url: kwargs['Url'] = url
+
+ self.setElement(DOM.createImg())
+
self.clickListeners = []
self.loadListeners = []
self.mouseListeners = []
- self.setElement(DOM.createImg())
self.sinkEvents(Event.ONCLICK | Event.MOUSEEVENTS | Event.ONLOAD | Event.ONERROR)
- self.setStyleName("gwt-Image")
-
- if url:
- self.setUrl(url)
+ Widget.__init__(self, **kwargs)
def addClickListener(self, listener):
self.clickListeners.append(listener)
View
6 library/pyjamas/ui/ListBox.py
@@ -17,12 +17,12 @@
from pyjamas.ui import Event
class ListBox(FocusWidget):
- def __init__(self):
+ def __init__(self, **kwargs):
+ if not kwargs.has_key('StyleName'): kwargs['StyleName']="gwt-ListBox"
self.changeListeners = []
self.INSERT_AT_END = -1
- FocusWidget.__init__(self, DOM.createSelect())
+ FocusWidget.__init__(self, DOM.createSelect(), **kwargs)
self.sinkEvents(Event.ONCHANGE)
- self.setStyleName("gwt-ListBox")
def addChangeListener(self, listener):
self.changeListeners.append(listener)
View
4 library/pyjamas/ui/Panel.py
@@ -17,9 +17,9 @@
from pyjamas.ui.Widget import Widget
class Panel(Widget):
- def __init__(self):
- Widget.__init__(self)
+ def __init__(self, **kwargs):
self.children = []
+ Widget.__init__(self, **kwargs)
def add(self):
console.error("This panel does not support no-arg add()")
View
7 library/pyjamas/ui/PasswordTextBox.py
@@ -16,8 +16,9 @@
from pyjamas.ui.TextBoxBase import TextBoxBase
class PasswordTextBox(TextBoxBase):
- def __init__(self):
- TextBoxBase.__init__(self, DOM.createInputPassword())
- self.setStyleName("gwt-PasswordTextBox")
+ def __init__(self, **kwargs):
+ if not kwargs.has_key('StyleName'):
+ kwargs['StyleName']="gwt-PasswordTextBox"
+ TextBoxBase.__init__(self, DOM.createInputPassword(), **kwargs)
View
11 library/pyjamas/ui/RadioButton.py
@@ -16,14 +16,13 @@
from pyjamas.ui.CheckBox import CheckBox
class RadioButton(CheckBox):
- def __init__(self, group, label=None, asHTML=False):
- self.initElement(DOM.createInputRadio(group))
-
- self.setStyleName("gwt-RadioButton")
+ def __init__(self, group, label=None, asHTML=False, **kwargs):
+ if not kwargs.has_key('StyleName'):kwargs['StyleName']="gwt-RadioButton"
if label:
if asHTML:
- self.setHTML(label)
+ kwargs['HTML'] = label
else:
- self.setText(label)
+ kwargs['Text'] = label
+ self.initElement(DOM.createInputRadio(group), **kwargs)
View
13 library/pyjamas/ui/ScrollPanel.py
@@ -17,15 +17,16 @@
from pyjamas.ui import Event
class ScrollPanel(SimplePanel):
- def __init__(self, child=None):
- SimplePanel.__init__(self)
+ def __init__(self, child=None, **kwargs):
self.scrollListeners = []
- self.setAlwaysShowScrollBars(False)
- self.sinkEvents(Event.ONSCROLL)
-
if child is not None:
- self.setWidget(child)
+ kwargs['Widget'] = child
+ if not kwargs.has_key('AlwaysShowScrollBars'):
+ kwargs['AlwaysShowScrollBars'] = False
+
+ SimplePanel.__init__(self, **kwargs)
+ self.sinkEvents(Event.ONSCROLL)
def addScrollListener(self, listener):
self.scrollListeners.append(listener)
View
4 library/pyjamas/ui/SimplePanel.py
@@ -21,11 +21,11 @@ class SimplePanel(Panel):
you'd like to be able to replace the widget with another, or if you need to
wrap something in a DIV.
"""
- def __init__(self, element=None):
- Panel.__init__(self)
+ def __init__(self, element=None, **kwargs):
if element is None:
element = DOM.createDiv()
self.setElement(element)
+ Panel.__init__(self, **kwargs)
def add(self, widget):
if self.getWidget() is not None:
View
6 library/pyjamas/ui/TextArea.py
@@ -20,9 +20,9 @@ class TextArea(TextBoxBase):
HTML textarea widget, allowing multi-line text entry. Use setText/getText to
get and access the current text.
"""
- def __init__(self):
- TextBoxBase.__init__(self, DOM.createTextArea())
- self.setStyleName("gwt-TextArea")
+ def __init__(self, **kwargs):
+ if not kwargs.has_key('StyleName'): kwargs['StyleName']="gwt-TextArea"
+ TextBoxBase.__init__(self, DOM.createTextArea(), **kwargs)
def getCharacterWidth(self):
return DOM.getIntAttribute(self.getElement(), "cols")
View
6 library/pyjamas/ui/TextBox.py
@@ -16,9 +16,9 @@
from pyjamas.ui.TextBoxBase import TextBoxBase
class TextBox(TextBoxBase):
- def __init__(self):
- TextBoxBase.__init__(self, DOM.createInputText())
- self.setStyleName("gwt-TextBox")
+ def __init__(self, **kwargs):
+ if not kwargs.has_key('StyleName'): kwargs['StyleName']="gwt-TextBox"
+ TextBoxBase.__init__(self, DOM.createInputText(), **kwargs)
def getMaxLength(self):
return DOM.getIntAttribute(self.getElement(), "maxLength")
View
4 library/pyjamas/ui/TextBoxBase.py
@@ -22,12 +22,12 @@ class TextBoxBase(FocusWidget):
ALIGN_LEFT = "left"
ALIGN_RIGHT = "right"
- def __init__(self, element):
+ def __init__(self, element, **kwargs):
self.changeListeners = []
self.clickListeners = []
self.currentEvent = None
- FocusWidget.__init__(self, element)
+ FocusWidget.__init__(self, element, **kwargs)
self.sinkEvents(Event.ONCHANGE)
def addChangeListener(self, listener):
View
9 library/pyjamas/ui/VerticalPanel.py
@@ -19,14 +19,15 @@
class VerticalPanel(CellPanel):
- def __init__(self):
- CellPanel.__init__(self)
+ def __init__(self, **kwargs):
+
+ if not kwargs.has_key('Spacing'): kwargs['Spacing'] = 0
+ if not kwargs.has_key('Padding'): kwargs['Padding'] = 0
self.horzAlign = HasHorizontalAlignment.ALIGN_LEFT
self.vertAlign = HasVerticalAlignment.ALIGN_TOP
- DOM.setAttribute(self.getTable(), "cellSpacing", "0")
- DOM.setAttribute(self.getTable(), "cellPadding", "0")
+ CellPanel.__init__(self, **kwargs)
def add(self, widget):
self.insert(widget, self.getWidgetCount())
Please sign in to comment.
Something went wrong with that request. Please try again.