本文整理汇总了Python中pyjamas.ui.TextBox.TextBox.setFocus方法的典型用法代码示例。如果您正苦于以下问题:Python TextBox.setFocus方法的具体用法?Python TextBox.setFocus怎么用?Python TextBox.setFocus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyjamas.ui.TextBox.TextBox
的用法示例。
在下文中一共展示了TextBox.setFocus方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: onModuleLoad
# 需要导入模块: from pyjamas.ui.TextBox import TextBox [as 别名]
# 或者: from pyjamas.ui.TextBox.TextBox import setFocus [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 = " "
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)
示例2: onModuleLoad
# 需要导入模块: from pyjamas.ui.TextBox import TextBox [as 别名]
# 或者: from pyjamas.ui.TextBox.TextBox import setFocus [as 别名]
class Search:
def onModuleLoad(self):
Window.alert('Loadingg')
# Setup JSON RPC
self.remote = DataService()
parser = JSONParser()
#initialize member variables
self.mainPanel = VerticalPanel()
self.searchPanel = HorizontalPanel()
self.resultsPanel = VerticalPanel()
self.deptLabel = Label('Department')
self.deptBox = TextBox()
self.courseNoLabel = Label ('Course Number')
self.courseNoBox = TextBox()
self.searchButton = Button('Search', self.searchCourses)
self.searchPanel = VerticalPanel()
# Assemble search panel
self.searchPanel.add(self.deptLabel)
self.searchPanel.add(self.deptBox)
self.searchPanel.add(self.courseNoLabel)
self.searchPanel.add(self.courseNoBox)
self.searchPanel.add(self.searchButton)
# Assemble results panel
self.resultsLabel = Label('Results here')
self.resultsPanel.add(self.resultsLabel)
# Assemble main panel
self.mainPanel.add(self.searchPanel)
self.mainPanel.add(self.resultsPanel)
# Associate mainPanel with the HTML host page
RootPanel().add(self.mainPanel)
# Move cursor focus to input box
self.deptBox.setFocus(True)
#Search courses
def searchCourses(self):
Window.alert('Searching')
示例3: onModuleLoad
# 需要导入模块: from pyjamas.ui.TextBox import TextBox [as 别名]
# 或者: from pyjamas.ui.TextBox.TextBox import setFocus [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
#.........这里部分代码省略.........
示例4: onModuleLoad
# 需要导入模块: from pyjamas.ui.TextBox import TextBox [as 别名]
# 或者: from pyjamas.ui.TextBox.TextBox import setFocus [as 别名]
#.........这里部分代码省略.........
### Categories table
self.topCategoryMoviesFlexTable.setText(0, 0, "Category")
self.topCategoryMoviesFlexTable.setText(0, 1, "Top Movie")
self.topCategoryMoviesFlexTable.setText(0, 2, "Average Rating")
self.topCategoryMoviesFlexTable.addStyleName("topCategoryMoviesList")
self.topCategoryMoviesFlexTable.getRowFormatter().addStyleName(0, "listHeader")
self.topCategoryMoviesFlexTable.setCellPadding(6)
self.topCategoryMoviesFlexTable.getCellFormatter().setStyleName(0, 0, "listHeaderColumn")
self.topCategoryMoviesFlexTable.getCellFormatter().setStyleName(0, 1, "listHeaderColumn")
self.categoriesLabel = Label("Movie Categories")
self.categoriesLabel.addStyleName("listLabel")
self.categoriesPanel.add(self.categoriesLabel)
self.categoriesPanel.add(self.topCategoryMoviesFlexTable)
self.categoriesPanel.setStyleName("categoriesPanel")
### Assemble Main panel
self.rightPanel.add(self.topRatedPanel)
self.rightPanel.add(self.categoriesPanel)
self.mainPanel.add(self.moviesPanel)
self.mainPanel.add(self.rightPanel)
self.mainPanel.setStyleName("mainPanel")
self.mainPanel.setSpacing(25)
# Associate panels with the HTML host page
RootPanel('addPanel').add(self.addPanel)
RootPanel('main').add(self.mainPanel)
# Move cursor focus to the input box
self.newMovieNameTextBox.setFocus(True)
# 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: