本文整理汇总了Python中pyjamas.ui.TextBox.TextBox.selectAll方法的典型用法代码示例。如果您正苦于以下问题:Python TextBox.selectAll方法的具体用法?Python TextBox.selectAll怎么用?Python TextBox.selectAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyjamas.ui.TextBox.TextBox
的用法示例。
在下文中一共展示了TextBox.selectAll方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: onModuleLoad
# 需要导入模块: from pyjamas.ui.TextBox import TextBox [as 别名]
# 或者: from pyjamas.ui.TextBox.TextBox import selectAll [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
#.........这里部分代码省略.........
示例2: onModuleLoad
# 需要导入模块: from pyjamas.ui.TextBox import TextBox [as 别名]
# 或者: from pyjamas.ui.TextBox.TextBox import selectAll [as 别名]
#.........这里部分代码省略.........
# Load the movies
self.remote.getMovies(self)
def verifyInputs(self, name, category):
if len(name) == 0:
Window.alert("Movie name cannot be empty.")
return False
if len(name) > 100:
Window.alert("Movie name is too long. Maximum length is 100 characters.")
return False
if len(category) == 0:
Window.alert("Category cannot be empty.")
return False
p = re.compile('^[0-9A-Za-z\\.\\-\\(\\) ]{1,100}$')
if p.match(category) == None:
Window.alert('"%s" is not a valid category.' % category)
return False
return True
def addMovieButton_Click(self, event):
name = self.newMovieNameTextBox.getText().trim()
cat = self.newMovieCategoryTextBox.getText().trim().lower()
category = cat[0].upper() + cat[1:]
rating = self.newMovieRatingListBox.getSelectedIndex()
if not self.verifyInputs(name, category):
return
movie = Movie(name, category, rating)
if movie in self.movies:
Window.alert("'" + name + "' is already in table.")
self.newMovieNameTextBox.selectAll()
return
self.remote.addMovie((name, category, rating), self)
self.newMovieNameTextBox.setText('')
def addMovie(self, sender, movie):
self.movies.append(movie)
row = self.moviesFlexTable.getRowCount()
self.moviesFlexTable.setText(row, 1, movie.category)
self.moviesFlexTable.setText(row, 2, movie.name)
self.moviesFlexTable.setText(row, 3, movie.rating)
# Adds buttons for remove, edit, save and cancel
removeMovieButton = Button("x")
editMovieButton = Button("Edit")
saveButton = Button("Save")
cancelButton = Button("Cancel")
# Save and cancel are hidden by default
saveButton.setVisible(False)
cancelButton.setVisible(False)
# Add buttons to row
buttons = HorizontalPanel()
buttons.add(removeMovieButton)
buttons.add(editMovieButton)
buttons.add(cancelButton)
buttons.add(saveButton)
self.moviesFlexTable.setWidget(row, 0, buttons)
def removeMovieButton_Click(sender):