WEB开发网
开发学院软件开发Python Pyjamas 简介,第 1 部分: 协同使用 GWT 和 Pytho... 阅读

Pyjamas 简介,第 1 部分: 协同使用 GWT 和 Python 的优势

 2010-08-26 00:00:00 来源:WEB开发网   
核心提示: 清单 2. ContactListGUIimportpyjd#thisgetstrippedoutforJavaScripttranslationfrompyjamas.ui.RootPanelimportRootPanelfrompyjamas.ui.ButtonimportButtonfro

清单 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() 

上一页  1 2 3 4 5 6 7 8 9 10  下一页

Tags:Pyjamas 简介 部分

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接