Email.py :  » Ajax » pyjamas » src » examples » djangoweb » media » 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 » djangoweb » media » Email.py
from pyjamas.ui.RootPanel import RootPanel
from pyjamas.ui.TextArea import TextArea
from pyjamas.ui.Label import Label
from pyjamas.ui.Button import Button
from pyjamas.ui.Composite import Composite
from pyjamas.ui.HTML import HTML
from pyjamas.ui.VerticalPanel import VerticalPanel
from pyjamas.ui.HorizontalPanel import HorizontalPanel
from pyjamas.ui.ListBox import ListBox
from pyjamas.ui.TextBox import TextBox
from pyjamas.JSONService import JSONProxy

from pyjamas import Factory

class Email(Composite):
    def __init__(self, **kwargs):

        element = None
        if kwargs.has_key('Element'):
            element = kwargs.pop('Element')

        panel = VerticalPanel(Element=element)
        Composite.__init__(self, panel, **kwargs)

        self.TEXT_WAITING = "Please wait..."
        self.TEXT_ERROR = "Server Error"

        self.remote_py = EchoServicePython()

        self.status=Label()
        self.subject = TextBox()
        self.subject.setVisibleLength(60)
        self.sender = TextBox()
        self.sender.setVisibleLength(40)
        self.message = TextArea()
        self.message.setCharacterWidth(60)
        self.message.setVisibleLines(15)
        
        self.button_py = Button("Send", self)

        buttons = HorizontalPanel()
        buttons.add(self.button_py)
        buttons.setSpacing(8)
        
        panel.add(HTML("Subject:"))
        panel.add(self.subject)
        panel.add(HTML("From:"))
        panel.add(self.sender)
        panel.add(HTML("Your Message - please keep it to under 1,000 characters"))
        panel.add(self.message)
        panel.add(buttons)
        panel.add(self.status)
        
    def onClick(self, sender):
        self.status.setText(self.TEXT_WAITING)
        text = self.message.getText()
        msg_sender = self.sender.getText()
        msg_subject = self.subject.getText()

        # demonstrate proxy & callMethod()
        if sender == self.button_py:
            id = self.remote_py.send(msg_sender, msg_subject, text, self)
        if id<0:
            self.status.setText(self.TEXT_ERROR)

    def onRemoteResponse(self, response, request_info):
        self.status.setText(response)

    def onRemoteError(self, code, message, request_info):
        self.status.setText("Server Error or Invalid Response: ERROR " + \
                str(code) + " - " + str(message))

Factory.registerClass('pyjamas.apps.Email', Email)

class EchoServicePython(JSONProxy):
    def __init__(self):
        JSONProxy.__init__(self, "/services/email.py", ["send"])
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.