Contacts.py :  » Ajax » pyjamas » src » examples » mail » 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 » mail » Contacts.py
from pyjamas.ui.Composite import Composite
from pyjamas.ui.HTML import HTML
from pyjamas.ui.HorizontalPanel import HorizontalPanel
from pyjamas.ui.Image import Image
from pyjamas.ui.PopupPanel import PopupPanel
from pyjamas.ui.VerticalPanel import VerticalPanel
from pyjamas.ui.Widget import Widget
from pyjamas.ui.Label import Label
from Logger import Logger

class Contact:
    def __init__(self, name, email):
        self.photo = "http://code.google.com/webtoolkit/documentation/examples/desktopclone/default_photo.jpg"
        self.name = name
        self.email = email

class ContactPopup(PopupPanel):
    def __init__(self, contact):
        # The popup's constructor's argument is a boolean specifying that it
        # auto-close itself when the user clicks outside of it.

        PopupPanel.__init__(self, True)

        inner = VerticalPanel()
        nameLabel = Label(contact.name)
        emailLabel = Label(contact.email)
        inner.add(nameLabel)
        inner.add(emailLabel)
        
        panel = HorizontalPanel()
        panel.setSpacing(4)
        panel.add(Image(contact.photo))
        panel.add(inner)
        
        self.add(panel)
        self.setStyleName("mail-ContactPopup")
        nameLabel.setStyleName("mail-ContactPopupName")
        emailLabel.setStyleName("mail-ContactPopupEmail")


class Contacts(Composite):
    def __init__(self):
        Composite.__init__(self)

        self.contacts = []
        self.contacts.append(Contact("Benoit Mandelbrot", "benoit@example.com"))
        self.contacts.append(Contact("Albert Einstein", "albert@example.com"))
        self.contacts.append(Contact("Rene Descartes", "rene@example.com"))
        self.contacts.append(Contact("Bob Saget", "bob@example.com"))
        self.contacts.append(Contact("Ludwig von Beethoven", "ludwig@example.com"))
        self.contacts.append(Contact("Richard Feynman", "richard@example.com"))
        self.contacts.append(Contact("Alan Turing", "alan@example.com"))
        self.contacts.append(Contact("John von Neumann", "john@example.com"))

        self.panel = VerticalPanel()

        # Add all the contacts to the list.
        i = 0
        while (i < len(self.contacts)):
            self.addContact(self.contacts[i])
            i =  i + 1

        self.initWidget(self.panel)
        self.setStyleName("mail-Contacts")

    def addContact(self, contact):
        link = HTML("<a href='javascript:;'>" + contact.name + "</a>")
        self.panel.add(link)
        
        # Add a click listener that displays a ContactPopup when it is clicked.
        listener = ContactListener(contact, link)
        link.addClickListener(listener)

class ContactListener:
    def __init__(self, contact, link):
        self.cont = contact
        self.link = link
        
    def onClick(self, sender):
        if (sender == self.link):
            popup = ContactPopup(self.cont)
            left = self.link.getAbsoluteLeft() + 32
            top = self.link.getAbsoluteTop() + 8
            popup.setPopupPosition(left, top)
            popup.show()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.