MapAreaDemo.py :  » Ajax » pyjamas » src » examples » maparea » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Ajax » pyjamas 
pyjamas » src » examples » maparea » MapAreaDemo.py
import pyjd

from pyjamas import DOM

from pyjamas.ui.RootPanel import RootPanel
from pyjamas.ui.HTML import HTML
from pyjamas.ui.Label import Label
from pyjamas.ui.Map import ImageMap,MapArea
from pyjamas.ui.HorizontalPanel import HorizontalPanel
from pyjamas.ui.VerticalPanel import VerticalPanel
from pyjamas.ui.ScrollPanel import ScrollPanel
from pyjamas.ui.MenuBar import MenuBar
from pyjamas.ui.Image import Image
from pyjamas.ui.ContextMenuPopupPanel import ContextMenuPopupPanel

from pyjamas import log


class MapAreaDemo:

    def onModuleLoad(self):
        # build image display
        img = Image("babykatie_small.jpg", width="300px", height="300px")
        img.element.setAttribute("usemap", "#themap")
        img.element.setAttribute("ismap", "1")
        imagepanel = ScrollPanel()
        imagepanel.add(img)

        # build message display
        msgpanel = VerticalPanel()
        msgpanel.add(Label("move mouse over baby katie's eyes, nose and mouth."))
        msgarea1 = Label("movement messages")
        msgpanel.add(msgarea1)
        msgarea2 = Label("click messages")
        msgpanel.add(msgarea2)

        imageClickHandler = MapClickHandler(msgarea1, msgarea2)

        # build imagemap
        map = ImageMap("themap", width="300px", height="300px")
        areas = [ \
            NamedMapArea("right eye", "circle", "73, 97, 7"),
            NamedMapArea("left eye", "circle", "116, 88, 5"),
            NamedMapArea("nose", "rect", "88, 97, 115, 115", href="http://lkcl.net"),
            NamedMapArea("mouth", "polygon", "82, 129, 102, 124, 119, 119, 121, 125, 103, 132, 79, 133"),
            ]
        for nma in areas:
            nma.addMouseListener(imageClickHandler)
            nma.addClickListener(imageClickHandler)
            map.add(nma)

        # layout page
        hpanel = HorizontalPanel()
        hpanel.add(map)
        hpanel.add(imagepanel)
        hpanel.add(msgpanel)
                    
        RootPanel().add(hpanel)


class NamedMapArea(MapArea):
    """ An area inside an imagemap with a name
    """
    
    def __init__(self, areaname, shape, coords, href="", **kwargs):
        self.areaname = areaname
        MapArea.__init__(self, shape, coords, href=href, **kwargs)
    

class MapClickHandler:

    def __init__(self, msgarea1, msgarea2):
        self.msgarea1 = msgarea1
        self.msgarea2 = msgarea2

    def _mouseActionMessage(self, name, action, x=None, y=None):
        #msg =  "%s %s (%d,%d)" % (name, action, x, y)  # throws JS errors
        msg = name + ' ' + action + ' (' + str(x) + ', ' + str(y) + ')'
        self.msgarea1.setText(msg)
        log.writebr(msg)

    def onMouseMove(self, sender, x, y):
        self._mouseActionMessage(sender.areaname, "move", x, y)
        
    def onMouseDown(self, sender, x, y):
        self._mouseActionMessage(sender.areaname, "down", x, y)

    def onMouseUp(self, sender, x, y):
        self._mouseActionMessage(sender.areaname, "up", x, y)

    def onMouseEnter(self, sender):
        self._mouseActionMessage(sender.areaname, "enter")

    def onMouseLeave(self, sender):
        self._mouseActionMessage(sender.areaname, "leave")

    def onClick(self, sender):
        msg = "you clicked on baby katie's " + sender.areaname
        self.msgarea2.setText(msg)
        log.writebr(msg)
    

if __name__ == '__main__':
    pyjd.setup("http://127.0.0.1/examples/maparea/public/MapAreaDemo.html")
    app = MapAreaDemo()
    app.onModuleLoad()
    pyjd.run()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.