Pyjamas 简介,第 1 部分: 协同使用 GWT 和 Python 的优势
2010-08-26 00:00:00 来源:WEB开发网清单 2. ContactListGUI
import pyjd # this get stripped out for JavaScript translation
from pyjamas.ui.RootPanel import RootPanel
from pyjamas.ui.Button import Button
from pyjamas.ui.Label import Label
from pyjamas import Window
from pyjamas.ui.Grid import Grid
from pyjamas.ui.Hyperlink import Hyperlink
from pyjamas.ui.TextBox import TextBox
# Constants
CONTACT_LISTING_ROOT_PANEL = "contactListing"
CONTACT_FORM_ROOT_PANEL = "contactForm"
CONTACT_STATUS_ROOT_PANEL = "contactStatus"
CONTACT_TOOL_BAR_ROOT_PANEL = "contactToolBar"
EDIT_LINK = 3
REMOVE_LINK = 4
#Service code removed
class ContactListGUI:
def __init__(self):
self.contactService = ContactService(self)
self.currentContact = Contact("Rick", "rhightower@gmail.com", "555-555-5555")
self.addButton = Button("Add contact", self.gui_eventAddButtonClicked)
self.addNewButton = Button("Add new contact", self.gui_eventAddNewButtonClicked)
self.updateButton = Button("Update contact", self.gui_eventUpdateButtonClicked)
self.nameField = TextBox()
self.emailField = TextBox()
self.phoneField = TextBox()
self.status = Label()
self.contactGrid = Grid(2,5)
self.contactGrid.addTableListener(self)
self.buildForm()
self.placeWidgets()
self.contactService.listContacts()
def onCellClicked(self, sender, row, cell):
print "sender=%s row=%s cell=%s" % (sender, row, cell)
self.gui_eventContactGridClicked(row, cell)
def onClick(self, sender):
if sender == self.addButton:
self.gui_eventAddButtonClicked()
elif sender == self.addNewButton:
self.gui_eventAddNewButtonClicked()
elif sender == self.updateButton:
self.gui_eventUpdateButtonClicked()
def buildForm(self):
formGrid = Grid(4,3)
formGrid.setVisible(False)
formGrid.setWidget(0, 0, Label("Name"))
formGrid.setWidget(0, 1, self.nameField);
formGrid.setWidget(1, 0, Label("email"))
formGrid.setWidget(1, 1, self.emailField)
formGrid.setWidget(2, 0, Label("phone"))
formGrid.setWidget(2, 1, self.phoneField)
formGrid.setWidget(3, 0, self.updateButton)
formGrid.setWidget(3, 1, self.addButton)
self.formGrid = formGrid
def placeWidgets(self):
RootPanel(CONTACT_LISTING_ROOT_PANEL).add(self.contactGrid)
RootPanel(CONTACT_FORM_ROOT_PANEL).add(self.formGrid)
RootPanel(CONTACT_STATUS_ROOT_PANEL).add(self.status)
RootPanel(CONTACT_TOOL_BAR_ROOT_PANEL).add(self.addNewButton)
def loadForm(self, contact):
self.formGrid.setVisible(True)
self.currentContact = contact
self.emailField.setText(contact.email)
self.phoneField.setText(contact.phone)
self.nameField.setText(contact.name)
def copyFieldDateToContact(self):
self.currentContact.email = self.emailField.getText()
self.currentContact.name = self.nameField.getText()
self.currentContact.phone = self.phoneField.getText()
- ››Pyjamas 简介,第 1 部分: 协同使用 GWT 和 Pytho...
- ››简介CentOS配置ssh系统技术
- ››部分 WM6.5 手机有望升级到 Windows Phone 7
- ››简介:Oracle 11g分区
- ››部分英特尔芯片不支持Windows 7“XP模式”
- ››简介穿过防火墙来远程控制协议分析仪
- ››简介Visual C++ 2008 Feature Pack
- ››简介使用Java编写Palm OS程序的解决方案
- ››简介使用Java编写PalmOS程序的解决方案
- ››简介DB2 9.5和IBM Data Studio
- ››简介Mysql中的临时表使用方法
- ››部分VZPP无法正常访问怎么解决?
更多精彩
赞助商链接