Skip to content

Commit

Permalink
move addons into main pyjamas library, convert Canvas2D to semi-work …
Browse files Browse the repository at this point in the history
…under hulahop

git-svn-id: https://pyjamas.svn.sourceforge.net/svnroot/pyjamas/trunk@771 7a2bd370-bda8-463c-979e-2900ccfb811e
  • Loading branch information
lkcl committed Jul 3, 2009
1 parent 3b7edbf commit 5037d8b
Show file tree
Hide file tree
Showing 11 changed files with 120 additions and 77 deletions.
4 changes: 4 additions & 0 deletions examples/addonsgallery/AddonsGallery.py
@@ -1,3 +1,5 @@
import pyjd # dummy for pyjs

from pyjamas.ui.Button import Button
from pyjamas.ui.RootPanel import RootPanel
from pyjamas.ui.HTML import HTML
Expand Down Expand Up @@ -89,5 +91,7 @@ def showIntro(self):


if __name__ == '__main__':
pyjd.setup("./public/AddonsGallery.html")
app = AddonsGallery()
app.onModuleLoad()
pyjd.run()
2 changes: 1 addition & 1 deletion examples/addonsgallery/AutoCompleteTab.py
Expand Up @@ -3,7 +3,7 @@
from pyjamas.ui.HTML import HTML
from pyjamas.ui.VerticalPanel import VerticalPanel
from pyjamas.ui.HorizontalPanel import HorizontalPanel
from AutoComplete import AutoCompleteTextBox
from pyjamas.ui.AutoComplete import AutoCompleteTextBox

class AutoCompleteTab(Sink):
def __init__(self):
Expand Down
25 changes: 13 additions & 12 deletions examples/addonsgallery/CanvasTab.py
Expand Up @@ -7,6 +7,7 @@
from pyjamas.Canvas2D import Canvas, CanvasImage, ImageLoadListener
from pyjamas.Timer import Timer
from math import floor, cos, sin
import time

class CanvasTab(Sink):
def __init__(self):
Expand Down Expand Up @@ -62,7 +63,8 @@ def __init__(self):
def draw(self):
for i in range(0, 6):
for j in range(0, 6):
self.context.fillStyle = 'rgb(' + floor(255-42.5*i) + ',' + floor(255-42.5*j) + ',0)'
self.context.fillStyle = 'rgb(%d,%d,0)' % \
( floor(255-42.5*i), floor(255-42.5*j))
self.context.fillRect(j*25,i*25,25,25)

def onMouseDown(self, sender, x, y):
Expand Down Expand Up @@ -101,7 +103,7 @@ def draw(self):
# Loop through rings (from inside to out)
for i in range(1,6):
self.context.save()
self.context.fillStyle = 'rgb('+(51*i)+','+(255-51*i)+',255)'
self.context.fillStyle = 'rgb(%d,%d,255)'%((51*i), (255-51*i))

# draw individual dots
for j in range(0,i*6):
Expand Down Expand Up @@ -164,7 +166,7 @@ def onError(self):
pass

def draw(self):
ptrn = self.context.createPattern(self.img, 'repeat')
ptrn = self.context.createPattern(self.img.getElement(), 'repeat')
self.context.fillStyle = ptrn
self.context.fillRect(0,0,200,200)

Expand All @@ -188,6 +190,8 @@ def drawSpirograph(self, R, r, O):
pi = 3.14159265358979323
x1 = R-O
y1 = 0
x2 = -1
y2 = -1
i = 1
self.context.beginPath()
self.context.moveTo(x1,y1)
Expand Down Expand Up @@ -226,16 +230,10 @@ def onTimer(self, t=None):
self.draw()

def getTimeSeconds(self):
JS("""
var x = new Date();
return x.getSeconds();
""")
return time.time() % 60

def getTimeMilliseconds(self):
JS("""
var x = new Date();
return x.getMilliseconds();
""")
return (time.time() * 1000.0) % 1.0

def draw(self):
pi = 3.14159265358979323
Expand All @@ -256,7 +254,10 @@ def draw(self):
self.context.rotate( ((2*pi)/60)*self.getTimeSeconds() + ((2*pi)/60000)*self.getTimeMilliseconds() )
self.context.translate(105,0)
self.context.fillRect(0,-12,50,24) # Shadow
self.context.drawImage(self.earth,-12,-12)
try:
self.context.drawImage(self.earth,-12,-12)
except:
self.context.drawImage(self.earth)

# Moon
self.context.save()
Expand Down
2 changes: 1 addition & 1 deletion examples/addonsgallery/TooltipTab.py
Expand Up @@ -3,7 +3,7 @@
from pyjamas.ui.HTML import HTML
from pyjamas.ui.VerticalPanel import VerticalPanel
from pyjamas.ui.HorizontalPanel import HorizontalPanel
from Tooltip import TooltipListener
from pyjamas.ui.Tooltip import TooltipListener

class TooltipTab(Sink):
def __init__(self):
Expand Down
17 changes: 13 additions & 4 deletions library/pygwt.py
@@ -1,3 +1,6 @@
import sys
import os

sNextHashId = 0

def getNextHashId():
Expand All @@ -12,12 +15,18 @@ def getHashCode(o):
""")

def getModuleName():
JS("""
return $moduleName;
""")

mod_name = sys.argv[0]
mod_name = os.path.split(mod_name)[1]
mod_name = os.path.spliext(mod_name)[0]

return mod_name

def getModuleBaseURL():
print "TODO"

print "getModuleBaseURL: TODO"
return ""

return ""
JS("""
// this is intentionally not using $doc, because we want the module's own url
Expand Down
66 changes: 14 additions & 52 deletions library/pyjamas/Canvas2D.py
Expand Up @@ -97,67 +97,29 @@ def getContext(self):
return self.context

def isEmulation(self):
JS("""
return (typeof $wnd.G_vmlCanvasManager != "undefined");
""")
return False

def init(self):
JS("""
var el = this.getElement().firstChild;
if (typeof $wnd.G_vmlCanvasManager != "undefined") {
var parent = el.parent;
el = $wnd.G_vmlCanvasManager.fixElement_(el);
el.getContext = function () {
if (this.context_) {
return this.context_;
}
return this.context_ = new $wnd.CanvasRenderingContext2D(el);
};
el = self.getElement().firstChild
ctx = el.getContext("2d")

el.attachEvent("onpropertychange", function (e) {
// we need to watch changes to width and height
switch (e.propertyName) {
case "width":
case "height":
// coord size changed?
break;
}
});
// if style.height is set
var attrs = el.attributes;
if (attrs.width && attrs.width.specified) {
// TODO: use runtimeStyle and coordsize
// el.getContext().setWidth_(attrs.width.nodeValue);
el.style.width = attrs.width.nodeValue + "px";
}
if (attrs.height && attrs.height.specified) {
// TODO: use runtimeStyle and coordsize
// el.getContext().setHeight_(attrs.height.nodeValue);
el.style.height = attrs.height.nodeValue + "px";
}
}
var ctx = el.getContext("2d");
ctx._createPattern = ctx.createPattern;
"""
ctx._createPattern = ctx.createPattern
ctx.createPattern = function(img, rep) {
if (!(img instanceof Image)) img = img.getElement();
return this._createPattern(img, rep);
return self._createPattern(img, rep)
}
ctx._drawImage = ctx.drawImage;
ctx._drawImage = ctx.drawImage
ctx.drawImage = function() {
var a=arguments;
if (!(a[0] instanceof Image)) a[0] = a[0].getElement();
if (a.length==9) return this._drawImage(a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8]);
else if (a.length==5) return this._drawImage(a[0], a[1], a[2], a[3], a[4]);
return this._drawImage(a[0], a[1], a[2]);
var a=arguments
if (!(a[0] instanceof Image)) a[0] = a[0].getElement()
if (a.length==9) return self._drawImage(a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8])
else if (a.length==5) return self._drawImage(a[0], a[1], a[2], a[3], a[4])
return self._drawImage(a[0], a[1], a[2])
}
this.context = ctx;
""")
"""
self.context = ctx

class CanvasImage(Image):
def __init__(self, url="", load_listener = None):
Expand Down
2 changes: 1 addition & 1 deletion library/pyjamas/Timer.py
Expand Up @@ -37,7 +37,7 @@ def notify(self, *args):
self.notify_fn()

def cancel(self):
print "TODO"
print "Timer.cancel: TODO"

def run(self):
pass
Expand Down
65 changes: 65 additions & 0 deletions library/pyjamas/platform/Canvas2DPyJS.py
@@ -0,0 +1,65 @@
class Canvas(Widget):

def isEmulation(self):
JS("""
return (typeof $wnd.G_vmlCanvasManager != "undefined");
""")

def init(self):
JS("""
var el = this.getElement().firstChild;
if (typeof $wnd.G_vmlCanvasManager != "undefined") {
var parent = el.parent;
el = $wnd.G_vmlCanvasManager.fixElement_(el);
el.getContext = function () {
if (this.context_) {
return this.context_;
}
return this.context_ = new $wnd.CanvasRenderingContext2D(el);
};
el.attachEvent("onpropertychange", function (e) {
// we need to watch changes to width and height
switch (e.propertyName) {
case "width":
case "height":
// coord size changed?
break;
}
});
// if style.height is set
var attrs = el.attributes;
if (attrs.width && attrs.width.specified) {
// TODO: use runtimeStyle and coordsize
// el.getContext().setWidth_(attrs.width.nodeValue);
el.style.width = attrs.width.nodeValue + "px";
}
if (attrs.height && attrs.height.specified) {
// TODO: use runtimeStyle and coordsize
// el.getContext().setHeight_(attrs.height.nodeValue);
el.style.height = attrs.height.nodeValue + "px";
}
}
var ctx = el.getContext("2d");
ctx._createPattern = ctx.createPattern;
ctx.createPattern = function(img, rep) {
if (!(img instanceof Image)) img = img.getElement();
return this._createPattern(img, rep);
}
ctx._drawImage = ctx.drawImage;
ctx.drawImage = function() {
var a=arguments;
if (!(a[0] instanceof Image)) a[0] = a[0].getElement();
if (a.length==9) return this._drawImage(a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8]);
else if (a.length==5) return this._drawImage(a[0], a[1], a[2], a[3], a[4]);
return this._drawImage(a[0], a[1], a[2]);
}
this.context = ctx;
""")

Expand Up @@ -99,7 +99,7 @@ def onKeyUp(self, arg0, arg1, arg2):
self.choicesPopup.show()
self.visible = True
self.choicesPopup.setPopupPosition(self.getAbsoluteLeft(), self.getAbsoluteTop() + self.getOffsetHeight())
self.choices.setWidth(self.getOffsetWidth() + "px")
self.choices.setWidth("%dpx" % self.getOffsetWidth())
else:
self.visible = False
self.choicesPopup.hide()
Expand Down
4 changes: 3 additions & 1 deletion addons/Tooltip.py → library/pyjamas/ui/Tooltip.py
Expand Up @@ -2,7 +2,7 @@
# Ported by Willie Gollino from Tooltip component for GWT - Originally by Alexei Sokolov http://gwt.components.googlepages.com/

from pyjamas.ui.PopupPanel import PopupPanel
from pyjamas.ui.HTML import HTML, RootPanel
from pyjamas.ui.HTML import HTML
from pyjamas.ui.RootPanel import RootPanel
from pyjamas.Timer import Timer

Expand All @@ -23,6 +23,8 @@ def __init__(self, sender, offsetX, offsetY, text, show_delay, hide_delay, style
left = sender.getAbsoluteLeft() + offsetX
top = sender.getAbsoluteTop() + offsetY

print "tooltip", left, top

self.setPopupPosition(left, top)
self.setStyleName(styleName)

Expand Down
8 changes: 4 additions & 4 deletions library/pyjamas/ui/UIObject.py
Expand Up @@ -86,7 +86,7 @@ def setElement(self, element):
def setHeight(self, height):
"""Set the height of the element associated with this UIObject. The
value should be given as a CSS value, such as 100px, 30%, or 50pi"""
DOM.setStyleAttribute(self.element, "height", height)
DOM.setStyleAttribute(self.element, "height", str(height))

def getHeight(self):
return DOM.getStyleAttribute(self.element, "height")
Expand All @@ -95,9 +95,9 @@ def setPixelSize(self, width, height):
"""Set the width and height of the element associated with this UIObject
in pixels. Width and height should be numbers."""
if width >= 0:
self.setWidth(width + "px")
self.setWidth("%dpx" % width)
if height >= 0:
self.setHeight(height + "px")
self.setHeight("%dpx" % height)

def setSize(self, width, height):
"""Set the width and height of the element associated with this UIObject. The
Expand Down Expand Up @@ -144,7 +144,7 @@ def setTitle(self, title):
def setWidth(self, width):
"""Set the width of the element associated with this UIObject. The
value should be given as a CSS value, such as 100px, 30%, or 50pi"""
DOM.setStyleAttribute(self.element, "width", width)
DOM.setStyleAttribute(self.element, "width", str(width))

def getWidth(self):
return DOM.getStyleAttribute(self.element, "width")
Expand Down

0 comments on commit 5037d8b

Please sign in to comment.