当前位置: 首页>>代码示例>>Python>>正文


Python TextBox.addKeyboardListener方法代码示例

本文整理汇总了Python中pyjamas.ui.TextBox.TextBox.addKeyboardListener方法的典型用法代码示例。如果您正苦于以下问题:Python TextBox.addKeyboardListener方法的具体用法?Python TextBox.addKeyboardListener怎么用?Python TextBox.addKeyboardListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyjamas.ui.TextBox.TextBox的用法示例。


在下文中一共展示了TextBox.addKeyboardListener方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: PreferencesDlg

# 需要导入模块: from pyjamas.ui.TextBox import TextBox [as 别名]
# 或者: from pyjamas.ui.TextBox.TextBox import addKeyboardListener [as 别名]
class PreferencesDlg(DialogBox):

    fileLocation = None

    def __init__(self, left = 50, top = 50):
        DialogBox.__init__(self, modal = False)

        self.setPopupPosition(left, top)
        self.setText("Preferences")
        ftable = FlexTable()
        ftableFormatter = ftable.getFlexCellFormatter()
        row = 0

        self.fileLocation = getCookie("fileLocation")

        row += 1
        ftable.setWidget(row, 0, Label("Sheet loaded on startup", wordWrap=False))
        self.fileLocationInput = TextBox()
        self.fileLocationInput.addChangeListener(self.checkValid)
        self.fileLocationInput.addKeyboardListener(self)
        self.fileLocationInput.setVisibleLength(30)
        self.fileLocationInput.setText(self.fileLocation)
        ftable.setWidget(row, 1, self.fileLocationInput)

        row += 1
        hpanel = HorizontalPanel()
        self.saveBtn = Button("Save", self.onSave)
        self.saveBtn.setEnabled(False)
        hpanel.add(self.saveBtn)
        self.cancelBtn = Button("Cancel", self.onCancel)
        hpanel.add(self.cancelBtn)
        ftable.setWidget(row, 0, hpanel)
        ftableFormatter.setColSpan(row, 0, 2)

        self.setWidget(ftable)

    def onCancel(self, sender):
        self.hide()

    def onSave(self, sender):
        setCookie("fileLocation", self.fileLocationInput.getText(), 1000000000)
        self.hide()

    def checkValid(self, evt=None):
        if self.fileLocation != self.fileLocationInput.getText():
            self.saveBtn.setEnabled(True)
        else:
            self.saveBtn.setEnabled(False)

    def onClick(self, sender):
        pass

    def onKeyUp(self, sender, keyCode, modifiers):
        self.checkValid()

    def onKeyDown(self, sender, keyCode, modifiers):
        pass

    def onKeyPress(self, sender, keyCode, modifiers):
        pass
开发者ID:FreakTheMighty,项目名称:pyjamas,代码行数:62,代码来源:PreferencesDlg.py

示例2: onModuleLoad

# 需要导入模块: from pyjamas.ui.TextBox import TextBox [as 别名]
# 或者: from pyjamas.ui.TextBox.TextBox import addKeyboardListener [as 别名]
class GridEdit:
    def onModuleLoad(self):

        self.input = TextBox()
        self.input.setEnabled(False)
        self.input.addKeyboardListener(self)

        self.g=Grid()
        self.g.resize(5, 5)
        self.g.setHTML(0, 0, "<b>Grid Edit</b>")
        self.g.setBorderWidth(2)
        self.g.setCellPadding(4)
        self.g.setCellSpacing(1)
        self.g.setWidth("500px")
        self.g.setHeight("120px")
        self.g.addTableListener(self)

        self.initGrid()
        RootPanel().add(self.input)
        RootPanel().add(self.g)

    def onKeyDown(self, sender, keycode, modifiers):
        pass

    def onKeyUp(self, sender, keycode, modifiers):
        pass

    def onKeyPress(self, sender, keycode, modifiers):
        if keycode == KeyboardListener.KEY_ESCAPE:
            self.input.setEnabled(False)
        elif keycode == KeyboardListener.KEY_ENTER:
            self.input.setEnabled(False)
            val = self.input.getText()
            self.set_grid_value(self.row, self.col, val)

    def onCellClicked(self, sender, row, col):
        self.row = row
        self.col = col
        val = self.values[row][col]
        self.input.setText(val)
        self.input.setEnabled(True)
        self.input.setFocus(True)

    def set_grid_value(self, row, col, val):
        self.values[row][col] = val
        if val == "":
            val = "&nbsp;"
        self.g.setHTML(row, col, val)

    def initGrid(self):

        self.values = {}
        for y in range(5):
            self.values[y] = {}
            for x in range(5):
                self.values[y][x] = ""
        for y in range(5):
            for x in range(5):
                val = self.values[y][x]
                self.set_grid_value(y, x, val)
开发者ID:Afey,项目名称:pyjs,代码行数:62,代码来源:GridEdit.py

示例3: InputControl

# 需要导入模块: from pyjamas.ui.TextBox import TextBox [as 别名]
# 或者: from pyjamas.ui.TextBox.TextBox import addKeyboardListener [as 别名]
class InputControl(Control):

    def __init__(self, min_value, max_value, start_value=None, step=None,
                       **kwargs):

        if not kwargs.has_key("StyleName"):
            kwargs['StyleName'] = "gwt-InputControl"
        self.input = TextBox()
        self.input.addKeyboardListener(self)
        #element = DOM.createDiv()
        if kwargs.has_key('Element'):
            # XXX FIXME: unlikely to work!
            element = kwargs.pop('Element')
        else:
            element = self.input.getElement() # YUK!!!
        Control.__init__(self, element, min_value, max_value, start_value, step,
                               **kwargs)

        self.addClickListener(self)
        self.addFocusListener(self)
        self.addKeyboardListener(self)

    def onFocus(self, sender):
        self.addStyleName("gwt-InputControl-focussed")

    def onLostFocus(self, sender):
        self.removeStyleName("gwt-InputControl-focussed")

    def setControlPos(self, value):

        self.input.setText(value)

    def onKeyPress(self, sender, keycode, modifiers):
        if keycode == KeyboardListener.KEY_ENTER:
            DOM.eventPreventDefault(DOM.eventGetCurrentEvent())
            txt = self.input.getText()
            if not txt:
                return
            new_value = float(txt)
            new_value = self.processValue(new_value)
            self.setControlPos(new_value)
            self.setValue(new_value)
        else:
            Control.onKeyPress(self, sender, keycode, modifiers)
开发者ID:Afey,项目名称:pyjs,代码行数:46,代码来源:InputControl.py

示例4: addRow

# 需要导入模块: from pyjamas.ui.TextBox import TextBox [as 别名]
# 或者: from pyjamas.ui.TextBox.TextBox import addKeyboardListener [as 别名]
 def addRow(self, timeVO = None):
     self.rows += 1
     col = -1
     for name, maxLength, visibleLength in self.columns:
         col += 1
         textBox = TextBox()
         textBox.setText("")
         textBox.col = col
         textBox.row = self.rows
         textBox.addChangeListener(self.checkValid)
         textBox.addKeyboardListener(self)
         textBox.addFocusListener(self)
         textBox.setName(name)
         if not maxLength is None:
             textBox.setMaxLength(maxLength)
         if not visibleLength is None:
             textBox.setVisibleLength(visibleLength)
         self.setWidget(self.rows, col, textBox)
     if not timeVO is None:
         self.setRow(self.rows, timeVO)
开发者ID:Afey,项目名称:pyjs,代码行数:22,代码来源:TimeGrid.py

示例5: graybox

# 需要导入模块: from pyjamas.ui.TextBox import TextBox [as 别名]
# 或者: from pyjamas.ui.TextBox.TextBox import addKeyboardListener [as 别名]
class graybox():
	def onModuleLoad(self):
		self.remote = DataService()
		panel = VerticalPanel()
	
		self.graybox = TextBox()
		self.graybox.addKeyboardListener(self)
	
		self.grayList = ListBox()
		self.grayList.setVisibleItemCount(20)
		self.grayList.setWidth("200px")
		self.grayList.addClickListener(self)
		self.Status = Label("Status Label")
	
		panel.add(Label("Add New Task:"))
		panel.add(self.graybox)
		panel.add(Label("Click to Remove:"))
		panel.add(self.grayList)
		panel.add(self.Status)
		self.remote.getTasks(self)
	
		RootPanel().add(panel)
开发者ID:iepathos,项目名称:graykoolaid,代码行数:24,代码来源:gray.py

示例6: onModuleLoad

# 需要导入模块: from pyjamas.ui.TextBox import TextBox [as 别名]
# 或者: from pyjamas.ui.TextBox.TextBox import addKeyboardListener [as 别名]
class SoftChordApp:
    def onModuleLoad(self):
        """
        Gets run when the page is first loaded.
        Creates the widgets.
        """

        self.remote = DataService()
        
        main_layout = VerticalPanel()

        h_layout = HorizontalPanel()
        h_layout.setPadding(10)
        
        songlist_layout = VerticalPanel()
        
        songlist_layout.add(Label("Add New Song:"))
 	

        self.newSongTextBox = TextBox()
	self.newSongTextBox.addKeyboardListener(self)
        songlist_layout.add(self.newSongTextBox)
        
       	self.addSongButton = Button("Add Song")
	self.addSongButton.addClickListener(self)
	songlist_layout.add(self.addSongButton)

        #songlist_layout.add(Label("Click to Remove:"))

        self.songListBox = ListBox()
        self.songListBox.setVisibleItemCount(7)
        self.songListBox.setWidth("300px")
        self.songListBox.setHeight("400px")
        self.songListBox.addClickListener(self)
        songlist_layout.add(self.songListBox)
        
        self.deleteSongButton = Button("Delete")
        self.deleteSongButton.addClickListener(self)
        songlist_layout.add(self.deleteSongButton)
         
        h_layout.add(songlist_layout)
        
        #self.textArea = TextArea()
        #self.textArea.setCharacterWidth(30)
        #self.textArea.setVisibleLines(50)
        #h_layout.add(self.textArea)
        
        #self.scrollPanel = ScrollPanel(Size=("400px", "500px"))
        self.songHtml = HTML("<b>Please select a song in the left table</b>")
        #self.scrollPanel.add(self.songHtml)
        #h_layout.add(self.scrollPanel)
        h_layout.add(self.songHtml)
        
        main_layout.add(h_layout)
        
        self.status = Label()
        main_layout.add(self.status)
        
        RootPanel().add(main_layout)
        
        # Populate the song table:
        self.remote.getAllSongs(self)
    

    def onKeyUp(self, sender, keyCode, modifiers):
        pass

    def onKeyDown(self, sender, keyCode, modifiers):
        pass

    def onKeyPress(self, sender, keyCode, modifiers):
        """
        This functon handles the onKeyPress event
        """
        if keyCode == KeyboardListener.KEY_ENTER and sender == self.newSongTextBox:
            id = self.remote.addSong(self.newSongTextBox.getText(), self)
            self.newSongTextBox.setText("")

            if id<0:
                self.status.setText("Server Error or Invalid Response")

    def onClick(self, sender):
        """
        Gets called when a user clicked in the <sender> widget.
        Currently deletes the song on which the user clicked.
        """
        if sender == self.songListBox:
            song_id = self.songListBox.getValue(self.songListBox.getSelectedIndex())
            self.status.setText("selected song_id: %s" % song_id)
            id = self.remote.getSong(song_id, self)
            if id<0:
                self.status.setText("Server Error or Invalid Response")
        
	elif sender == self.addSongButton:
            id = self.remote.addSong(self.newSongTextBox.getText(), self)
            self.newSongTextBox.setText("")
            if id<0:
                self.status.setText("Server Error or Invalid Response")
 
        elif sender == self.deleteSongButton:
#.........这里部分代码省略.........
开发者ID:academicsam,项目名称:softChord,代码行数:103,代码来源:softchordapp.py

示例7: onModuleLoad

# 需要导入模块: from pyjamas.ui.TextBox import TextBox [as 别名]
# 或者: from pyjamas.ui.TextBox.TextBox import addKeyboardListener [as 别名]
class StockWatcher:
    def onModuleLoad(self):
        '''
        This is the main entry point method.
        '''
        
        # Setup JSON RPC
        self.remote = DataService()
        
        # Initialize member variables
        self.mainPanel = VerticalPanel()
        self.stocksFlexTable = FlexTable()
        self.addPanel = HorizontalPanel()
        self.newSymbolTextBox = TextBox()
        self.lastUpdatedLabel = Label()
        self.addStockButton = Button('Add', self.addStock)
        self.stocks = []
        self.stocksTableColumns = ['Symbol', 'Price', 'Change', 'Remove']
        
        # Add styles to elements in the stock list table
        self.stocksFlexTable.getRowFormatter().addStyleName(0, 'watchListHeader')
        self.stocksFlexTable.addStyleName('watchList')
        self.stocksFlexTable.getCellFormatter().addStyleName(0, 1, 'watchListNumericColumn')
        self.stocksFlexTable.getCellFormatter().addStyleName(0, 2, 'watchListNumericColumn')
        self.stocksFlexTable.getCellFormatter().addStyleName(0, 3, 'watchListRemoveColumn')
        
        # Create table for stock data
        for i in range(len(self.stocksTableColumns)):
            self.stocksFlexTable.setText(0, i, self.stocksTableColumns[i])
        
        # Assemble Add Stock panel
        self.addPanel.add(self.newSymbolTextBox)
        self.addPanel.add(self.addStockButton)
        self.addPanel.addStyleName('addPanel')
        
        # Assemble Main panel
        self.mainPanel.add(self.stocksFlexTable)
        self.mainPanel.add(self.addPanel)
        self.mainPanel.add(self.lastUpdatedLabel)
        
        # Associate the Main panel with the HTML host page
        RootPanel().add(self.mainPanel)
        
        # Move cursor focus to the input box
        self.newSymbolTextBox.setFocus(True)
        
        # Setup timer to refresh list automatically
        refresh = self.refreshWatchlist
        class MyTimer(Timer):
            def run(self):
                refresh()
        refreshTimer = MyTimer()
        refreshTimer.scheduleRepeating(5000)
        
        # Listen for keyboard events in the input box
        self_addStock = self.addStock
        class StockTextBox_KeyboardHandler():
            def onKeyPress(self, sender, keycode, modifiers):
                if keycode == KEY_ENTER:
                    self_addStock()
            def onKeyDown(self, sender, keycode, modifiers): return
            def onKeyUp(self, sender, keycode, modifiers): return
        self.newSymbolTextBox.addKeyboardListener(StockTextBox_KeyboardHandler())
        
        # Load the stocks
        self.remote.getStocks(self)
    
    def addStock(self, sender, symbol=None):
        '''
        Add stock to FlexTable. Executed when the user clicks the addStockButton
        or presses enter in the newSymbolTextBox
        '''
        
        if symbol is None:
            # Get the symbol
            symbol = self.newSymbolTextBox.getText().upper().trim()
            self.newSymbolTextBox.setText('')
            # Don't add the stock if it's already in the table
            if symbol in self.stocks:
                return
            # Tell the server that we're adding this stock
            self.remote.addStock(symbol, self)
            self.newSymbolTextBox.setFocus(True)
            # Stocks code must be between 1 and 10 chars that are numbers/letters/dots
            p = re.compile('^[0-9A-Z\\.]{1,10}$')
            if p.match(symbol) == None:
                Window.alert('"%s" is not a valid symbol.' % symbol)
                self.newSymbolTextBox.selectAll()
                return    
        
        # Add the stock to the table
        row = self.stocksFlexTable.getRowCount()
        self.stocks.append(symbol)
        self.stocksFlexTable.setText(row, 0, symbol)
        self.stocksFlexTable.setWidget(row, 2, Label())
        self.stocksFlexTable.getCellFormatter().addStyleName(row, 1, 'watchListNumericColumn')
        self.stocksFlexTable.getCellFormatter().addStyleName(row, 2, 'watchListNumericColumn')
        self.stocksFlexTable.getCellFormatter().addStyleName(row, 3, 'watchListRemoveColumn')
        
        # Add a button to remove this stock from the table
#.........这里部分代码省略.........
开发者ID:fedenko,项目名称:StockWatcher2,代码行数:103,代码来源:StockWatcher.py

示例8: onModuleLoad

# 需要导入模块: from pyjamas.ui.TextBox import TextBox [as 别名]
# 或者: from pyjamas.ui.TextBox.TextBox import addKeyboardListener [as 别名]
class PageVerify:
    # setup JSON RPC
    facebook_user = {}
    users = []
    new_user = {}
    get_data = {}
    app_info = {}
    verification_key = None
    verification_status = False

    def onModuleLoad(self):
        self.remote = DataService()

        # do JSON RPC calls
        self.remote.get_facebook_user(self)
        self.remote.get_app_info(self, "verify")

        # labels and banners
        self.html_verify_banner = HTML("<h1>Verify your NetID</h1>")
        self.html_confirm_banner = HTML("<h1>Confirming your NetID...</h1>")

        self.lbl_verify_text = Label("Please verify your account.")
        self.lbl_confirm_text = Label("Confirming Acount...")
        self.lbl_confirm_result = Label()

        # textboxes
        self.tb_verify_netid = TextBox()

        # hook up keyboard events
        send_confirmation_email = self.send_confirmation_email
        class Add_KeyboardHandler():
            def onKeyPress(self, sender, keycode, modifiers):
                if keycode == KEY_ENTER:
                    send_confirmation_email()
            def onKeyDown(self, sender, keycode, modifiers): return
            def onKeyUp(self, sender, keycode, modifiers): return
        self.kbh = Add_KeyboardHandler()
        self.tb_verify_netid.addKeyboardListener(self.kbh)

        # buttons
        self.btn_verify = Button("Verify!", self.send_confirmation_email)

        # NetID information form
        self.table_verify_netid = FlexTable()
        self.table_verify_netid.setText(0, 0, "NetID:")
        self.table_verify_netid.setWidget(0, 1, self.tb_verify_netid)
        self.table_verify_netid.setWidget(1, 1, self.btn_verify)

        # panels
        self.main_panel = VerticalPanel()

        # check get information, if present, verify, if not request form
        self.location = Window.getLocation().getHref()
        self.tmp = self.location.split('?')
        self.tmp = self.tmp[len(self.tmp) - 1].split("&")
        for e in self.tmp:
            get_var = e.split("=")
            if len(get_var) == 2:
                PageVerify.get_data[get_var[0]] = get_var[1]

        if "vk" in PageVerify.get_data:
            # we have request from verification email
            self.main_panel.add(self.html_confirm_banner)
            self.main_panel.add(self.lbl_confirm_text)
            self.main_panel.add(self.lbl_confirm_result)
            self.verify_user()
        else:
            self.main_panel.add(self.html_verify_banner)
            self.main_panel.add(self.lbl_verify_text)
            self.main_panel.add(self.table_verify_netid)
            
        self.main_panel.addStyleName("verify_panel")

        # add everything to root panel
        RootPanel("page_verify").add(self.main_panel)

    def send_confirmation_email(self, sender, netid = None):
        """ given a valid NetID, send a confirmation email
            with a link (using encrypted key) to validate
            the user's NetID
        """
        if netid == None:
            netid = self.tb_verify_netid.getText()

        # create a new user with netid and facebook id
        self.remote.create_user(self, PageVerify.facebook_user['facebook_id'], netid, PageVerify.facebook_user['full_name'])

        # create cryptogram based on email name
        self.remote.encrypt(self, netid)

        # subject line
        subject = "Hello from Textbook Connect!"

        class EmailTimer(Timer):
            def __init__(self, context):
                Timer.__init__(self)
                self.max_tries = 10
                self.tries = 0
                self.context = context

#.........这里部分代码省略.........
开发者ID:cy245,项目名称:TextbookConnect,代码行数:103,代码来源:page_verify.py

示例9: UserForm

# 需要导入模块: from pyjamas.ui.TextBox import TextBox [as 别名]
# 或者: from pyjamas.ui.TextBox.TextBox import addKeyboardListener [as 别名]
class UserForm(AbsolutePanel):

    MODE_ADD    = "modeAdd";
    MODE_EDIT   = "modeEdit";

    user = None
    mode = None

    usernameInput = None
    firstInput = None
    lastInput = None
    emailInput = None
    passwordInput = None
    confirmInput = None
    departmentCombo = None
    addBtn = None
    cancelBtn = None

    def __init__(self,parent):
        AbsolutePanel.__init__(self)
        ftable = FlexTable()

        ftable.setWidget(0, 0, Label("First Name", wordWrap=False))
        ftableFormatter = ftable.getFlexCellFormatter()
        self.firstInput = TextBox()
        self.firstInput.addChangeListener(self.checkValid)
        self.firstInput.addKeyboardListener(self)
        ftable.setWidget(0, 1, self.firstInput)

        ftable.setWidget(1, 0, Label("Last Name", wordWrap=False))
        self.lastInput = TextBox()
        self.lastInput.addChangeListener(self.checkValid)
        self.lastInput.addKeyboardListener(self)
        ftable.setWidget(1, 1, self.lastInput)

        ftable.setWidget(2, 0, Label("Email", wordWrap=False))
        self.emailInput = TextBox()
        self.emailInput.addChangeListener(self.checkValid)
        self.emailInput.addKeyboardListener(self)
        ftable.setWidget(2, 1, self.emailInput)

        w = Label("* Username", wordWrap=False)
        w.addMouseListener(TooltipListener("Required, not changable"))
        ftable.setWidget(3, 0, w)
        self.usernameInput = TextBox()
        self.usernameInput.addChangeListener(self.checkValid)
        self.usernameInput.addKeyboardListener(self)
        ftable.setWidget(3, 1, self.usernameInput)

        w = Label("* Password", wordWrap=False)
        w.addMouseListener(TooltipListener("Required"))
        ftable.setWidget(4, 0, w)
        self.passwordInput = PasswordTextBox()
        self.passwordInput.addChangeListener(self.checkValid)
        self.passwordInput.addKeyboardListener(self)
        ftable.setWidget(4, 1, self.passwordInput)

        w = Label("* Confirm", wordWrap=False)
        w.addMouseListener(TooltipListener("Required"))
        ftable.setWidget(5, 0, w)
        self.confirmInput = PasswordTextBox()
        self.confirmInput.addChangeListener(self.checkValid)
        self.confirmInput.addKeyboardListener(self)
        ftable.setWidget(5, 1, self.confirmInput)

        w = Label("* Department", wordWrap=False)
        w.addMouseListener(TooltipListener("Required"))
        ftable.setWidget(6, 0, w)
        self.departmentCombo = ListBox()
        self.departmentCombo.addChangeListener(self.checkValid)
        self.departmentCombo.addKeyboardListener(self)
        ftable.setWidget(6, 1, self.departmentCombo)

        hpanel = HorizontalPanel()
        self.addBtn = Button("Add User")
        self.addBtn.setEnabled(False)
        hpanel.add(self.addBtn)
        self.cancelBtn = Button("Cancel")
        hpanel.add(self.cancelBtn)
        ftable.setWidget(7, 0, hpanel)
        ftableFormatter.setColSpan(7, 0, 2)

        self.add(ftable)
        self.clearForm()
        return

    def clearForm(self):
        self.user = None
        self.usernameInput.setText('')
        self.firstInput.setText('')
        self.lastInput.setText('')
        self.emailInput.setText('')
        self.passwordInput.setText('')
        self.confirmInput.setText('')
        self.departmentCombo.setItemTextSelection(None)
        self.updateMode(self.MODE_ADD)
        self.checkValid()

    def updateUser(self, user):
        def setText(elem, value):
#.........这里部分代码省略.........
开发者ID:Afey,项目名称:pyjs,代码行数:103,代码来源:components.py

示例10: onModuleLoad

# 需要导入模块: from pyjamas.ui.TextBox import TextBox [as 别名]
# 或者: from pyjamas.ui.TextBox.TextBox import addKeyboardListener [as 别名]
class TodoApp:
    def onModuleLoad(self):
        self.remote = DataService()
        panel = VerticalPanel()

        self.todoTextBox = TextBox()
        self.todoTextBox.addKeyboardListener(self)

        self.todoList = ListBox()
        self.todoList.setVisibleItemCount(7)
        self.todoList.setWidth("200px")
        self.todoList.addClickListener(self)

        panel.add(Label("Add New Todo:"))
        panel.add(self.todoTextBox)
        panel.add(Label("Click to Remove:"))
        panel.add(self.todoList)

        self.status = Label()
        panel.add(self.status)

        RootPanel().add(panel)



    def onKeyUp(self, sender, keyCode, modifiers):
        pass

    def onKeyDown(self, sender, keyCode, modifiers):
        pass

    def onKeyPress(self, sender, keyCode, modifiers):
        """
        This functon handles the onKeyPress event, and will add the item in the text box to the list when the user presses the enter key.  In the future, this method will also handle the auto complete feature.
        """
        if keyCode == KeyboardListener.KEY_ENTER and sender == self.todoTextBox:
            id = self.remote.addTask(sender.getText(),self)
            sender.setText("")

            if id<0:
                self.status.setText("Server Error or Invalid Response")


    def onClick(self, sender):
        id = self.remote.deleteTask(sender.getValue(sender.getSelectedIndex()),self)
        if id<0:
            self.status.setText("Server Error or Invalid Response")

    def onRemoteResponse(self, response, request_info):
        self.status.setText("response received")
        if request_info.method == 'getTasks' or request_info.method == 'addTask' or request_info.method == 'deleteTask':
            self.status.setText(self.status.getText() + "HERE!")
            self.todoList.clear()
            for task in response:
                self.todoList.addItem(task[0])
                self.todoList.setValue(self.todoList.getItemCount()-1,task[1])
        else:
            self.status.setText(self.status.getText() + "none!")

    def onRemoteError(self, code, errobj, request_info):
        message = errobj['message']
        self.status.setText("Server Error or Invalid Response: ERROR %s - %s" % (code, message))
开发者ID:Afey,项目名称:pyjs,代码行数:64,代码来源:TodoApp.py

示例11: WebPageEdit

# 需要导入模块: from pyjamas.ui.TextBox import TextBox [as 别名]
# 或者: from pyjamas.ui.TextBox.TextBox import addKeyboardListener [as 别名]
class WebPageEdit(Composite):
    def __init__(self, sink):
        Composite.__init__(self)

        self.remote = sink.remote

        panel = VerticalPanel(Width="100%", Spacing=8)

        self.view = Button("View", self)
        self.newpage = Button("New", self)
        self.todoId = None
        self.todoTextName = TextBox()
        self.todoTextName.addKeyboardListener(self)

        self.todoTextArea = RichTextEditor(basePath="/fckeditor/")
        self.todoTextArea.setWidth("100%")
        self.todoTextArea.addSaveListener(self)

        self.todoList = ListBox()
        self.todoList.setVisibleItemCount(7)
        self.todoList.setWidth("200px")
        self.todoList.addClickListener(self)

        self.fDialogButton = Button("Upload Files", self)

        self.status = HTML()

        panel.add(HTML("Status:"))
        panel.add(self.status)
        panel.add(self.fDialogButton)
        panel.add(Label("Create New Page (doesn't save current one!):"))
        panel.add(self.newpage)
        panel.add(Label("Add/Edit New Page:"))
        panel.add(self.todoTextName)
        panel.add(Label("Click to Load and Edit (doesn't save current one!):"))
        panel.add(self.todoList)
        panel.add(self.view)
        panel.add(Label("New Page HTML.  Click 'save' icon to save.  (pagename is editable as well)"))
        panel.add(self.todoTextArea)

        self.setWidget(panel)

        self.remote.getPages(self)

    def onKeyUp(self, sender, keyCode, modifiers):
        pass

    def onKeyDown(self, sender, keyCode, modifiers):
        pass

    def onKeyPress(self, sender, keyCode, modifiers):
        """
        This functon handles the onKeyPress event, and will add the item in the text box to the list when the user presses the enter key.  In the future, this method will also handle the auto complete feature.
        """
        pass

    def onSave(self, editor):
        self.status.setText("")
        name = self.todoTextName.getText()
        if not name:
            self.status.setText("Please enter a name for the page")
            return
        item = {"name": name, "text": self.todoTextArea.getHTML()}
        if self.todoId is None:
            rid = self.remote.addPage(item, self)
        else:
            item["id"] = self.todoId
            rid = self.remote.updatePage(item, self)

        if rid < 0:
            self.status.setHTML("Server Error or Invalid Response")
            return

    def onClick(self, sender):
        if sender == self.newpage:
            self.todoId = None
            self.todoTextName.setText("")
            self.todoTextArea.setHTML("")
            return
        elif sender == self.view:
            name = self.todoTextName.getText()
            html = self.todoTextArea.getHTML()
            if not html:
                return
            p = HTMLDialog(name, html)
            p.setPopupPosition(10, 10)
            p.setWidth(Window.getClientWidth() - 40)
            p.setHeight(Window.getClientHeight() - 40)
            p.show()
            return
        elif sender == self.fDialogButton:
            Window.open(fileedit_url, "fileupload", "width=800,height=600")
            return
            dlg = FileDialog(fileedit_url)
            left = self.fDialogButton.getAbsoluteLeft() + 10
            top = self.fDialogButton.getAbsoluteTop() + 10
            dlg.setPopupPosition(left, top)
            dlg.show()

        id = self.remote.getPage(sender.getValue(sender.getSelectedIndex()), self)
#.........这里部分代码省略.........
开发者ID:janjaapbos,项目名称:pyjs,代码行数:103,代码来源:WebPageEdit.py


注:本文中的pyjamas.ui.TextBox.TextBox.addKeyboardListener方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。