本文整理汇总了Python中pyjamas.ui.Button.Button.setVisible方法的典型用法代码示例。如果您正苦于以下问题:Python Button.setVisible方法的具体用法?Python Button.setVisible怎么用?Python Button.setVisible使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyjamas.ui.Button.Button
的用法示例。
在下文中一共展示了Button.setVisible方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GridWidget
# 需要导入模块: from pyjamas.ui.Button import Button [as 别名]
# 或者: from pyjamas.ui.Button.Button import setVisible [as 别名]
#.........这里部分代码省略.........
self.adj_grid.setWidget(j, 2, self.incr_buttons[key])
self.adj_labels[key] = Label("Constant %d: %f" % (key[1], self.TD_CONSTS[key]))
self.adj_grid.setWidget(j, 1, self.adj_labels[key])
def init(self):
'''Initializes the grid on which the game is played.
'''
for y_board in range(3):
for x_board in range(3):
g=Grid()
g.resize(3, 3)
g.setBorderWidth(2)
g.setCellPadding(9)
g.setCellSpacing(1)
for x_cell in range(3):
for y_cell in range(3):
b = Button('Play here.', self)
b.point = {'x_cell':x_cell, 'y_cell':y_cell, 'y_board': y_board, 'x_board': x_board}
g.setWidget(y_cell, x_cell, b)
self.add(g)
self.g.setWidget(y_board, x_board, g)
def start_new_game(self):
#g.__init__() nope, can't use this :(
self.state = State()
self.game_over = False
self.depthLimit = 3
self.human_first = True
self.ai_first.setVisible(True) # new game, so we make this button visible
self.check_win()
self.max_player = '-1'
self.min_player = '-1'
self.state_to_grid()
def onClick(self, sender):
if sender == self.increase_depth:
self.depthLimit += 1
self.depth_label.setHTML("""AI will search to a <a href="#depth_explanation">depth</a> of """ + str(self.depthLimit) +".")
if sender == self.decrease_depth:
self.depthLimit -= 1
self.depth_label.setHTML("""AI will search to a <a href="#depth_explanation">depth</a> of """ + str(self.depthLimit) +".")
if sender == self.new_game:
self.start_new_game()
self.check_adjusts(sender)
if not self.game_over:
if sender == self.ai_first and self.min_player == -1: # we only set min_player and max_player when they are not yet initialized
self.human_first = False
self.max_player = '1'
self.min_player = '2'
self.state.next_piece[2] = self.max_player
self.ai_first.setVisible(False) # can't go first any more so we make it invisible...
new_state = ab(self.state, self.TD_CONSTS, depth_limit=self.depthLimit)[1]
last_position = find_last_move(self.state, new_state)
示例2: addMovie
# 需要导入模块: from pyjamas.ui.Button import Button [as 别名]
# 或者: from pyjamas.ui.Button.Button import setVisible [as 别名]
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):
self.remote.deleteMovie((movie.name, movie.category), self)
removeMovieButton.addClickListener(removeMovieButton_Click)
def editMovieButton_Click(sender):
# Add textboxes and listbox
editMovieButton.setVisible(False)
cancelButton.setVisible(True)
saveButton.setVisible(True)
editCategory = TextBox()
editName = TextBox()
editRating = ListBox(False)
for i in range(self.MAX_RATING + 1):
editRating.addItem(str(i))
# Variable width textboxes
catlen = len(movie.category)
namelen = len(movie.name)
if (catlen > 8):
editCategory.setWidth(str(catlen*10) + "px")
else:
editCategory.setWidth("80px")
if (namelen > 8):
editName.setWidth(str(namelen*10) + "px")
else:
editName.setWidth("80px")
self.moviesFlexTable.setWidget(row, 1, editCategory)
self.moviesFlexTable.setWidget(row, 2, editName)
self.moviesFlexTable.setWidget(row, 3, editRating)
editCategory.setText(movie.category)
editName.setText(movie.name)
editRating.setSelectedIndex(movie.rating)
editMovieButton.addClickListener(editMovieButton_Click)
def saveButton_Click(sender):
catText = self.moviesFlexTable.getWidget(row, 1)
nameText = self.moviesFlexTable.getWidget(row, 2)
ratingList = self.moviesFlexTable.getWidget(row, 3)
newCategory = catText.getText().trim().lower()
newCategory = newCategory[0].upper() + newCategory[1:]
newName = nameText.getText().trim()
newRating = ratingList.getSelectedIndex()
if not self.verifyInputs(newName, newCategory):
return
# Removes temporarily to check for duplicates
self.movies.remove(movie)
newMovie = Movie(newName, newCategory, newRating)
if newMovie in self.movies:
Window.alert("'" + newName + "' is already in table.")
nameText.selectAll()
return
self.remote.editMovie((movie.name, movie.category), (newMovie.name, newMovie.category, newMovie.rating), self)
saveButton.addClickListener(saveButton_Click)
def cancelButton_Click(sender):
self.moviesFlexTable.remove(self.moviesFlexTable.getWidget(row, 1))
self.moviesFlexTable.remove(self.moviesFlexTable.getWidget(row, 2))
self.moviesFlexTable.remove(self.moviesFlexTable.getWidget(row, 3))
# Reverts fields to old movie info
self.moviesFlexTable.setText(row, 1, movie.category)
self.moviesFlexTable.setText(row, 2, movie.name)
self.moviesFlexTable.setText(row, 3, movie.rating)
cancelButton.setVisible(False)
saveButton.setVisible(False)
editMovieButton.setVisible(True)
cancelButton.addClickListener(cancelButton_Click)
示例3: GridWidget
# 需要导入模块: from pyjamas.ui.Button import Button [as 别名]
# 或者: from pyjamas.ui.Button.Button import setVisible [as 别名]
class GridWidget(AbsolutePanel):
def __init__(self):
AbsolutePanel.__init__(self)
StyleSheetCssText(margins) # initialize css...
header = """<div><H2 align="center">Welcome to Unbeatable Tic-Tac-Toe!</H2><br>My <a href="https://github.com/chetweger/min-max-games/blob/master/ttt/ttt.py">implementation</a> uses the min-max search algorithm with alpha beta pruning and a transposition table!</div>"""
header = HTML(header, StyleName='margins_both')
self.add(header)
self.ai_first = Button("AI first.", self, StyleName='margins_left')
self.add(self.ai_first)
self.new_game = Button("New game", self, StyleName='margins_left')
self.add(self.new_game)
self.g=Grid(StyleName='margins_left')
self.g.resize(3, 3)
self.g.setBorderWidth(2)
self.g.setCellPadding(4)
self.g.setCellSpacing(1)
self.init()
self.add(self.g)
self.state = State()
self.game_resolution=Label("", StyleName='margins_left')
self.add(self.game_resolution)
def start_new_game(self):
self.state = State()
self.game_over = False
self.ai_first.setVisible(True)
self.state_to_grid(self.state)
def onClick(self, sender):
if sender == self.ai_first:
print 'player is ', self.state.player
self.state.max_v = 1
self.state.min_v = 2
self.ai_first.setVisible(False)
print 'button ai_first exists', hasattr(self, 'ai_first')
self.state.print_me()
next_state = ab(self.state)
self.state = next_state
self.state_to_grid(next_state)
print '[after]player is ', self.state.player
elif sender == self.new_game:
self.start_new_game()
else:
print 'player is ', self.state.player
'''
self.g.setText(0, 1, 'wassup')
self.g.setText(p['x'], p['y'], str(self.state.min_v))
'''
if self.ai_first.isVisible():
print 'Setting state.max_v'
self.state.max_v = 2
self.state.min_v = 1
self.ai_first.setVisible(False)
p = sender.point
self.g.setText(p['y'], p['x'], str(self.state.player))
self.state = self.grid_to_state()
self.check_for_tie() # end 1
if is_win(self.state):
self.state_to_grid(self.state, game_over=True, over_message='You won! This should not happen. This is a bug. Please email [email protected] describing the conditions of the game.')
self.state.player = next_player(self.state.player)
self.state.print_me()
next_state = ab(self.state)
self.state = next_state
self.state_to_grid(next_state)
self.check_for_tie() # end 1
if is_win(self.state):
self.state_to_grid(self.state, game_over=True, over_message='You lost! Better luck next time.')
def check_for_tie(self):
if is_over(self.state):
self.state_to_grid(self.state, game_over=True, over_message='The game is a tie.')
def state_to_grid(self, state, game_over=False, over_message=''):
if over_message:
self.game_resolution.setText(over_message)
self.game_resolution.setVisible(True)
else:
self.game_resolution.setVisible(False)
board = state.board
for y in range(3):
for x in range(3):
if board[y][x] == 0:
if not game_over:
b = Button('Press', self)
b.point = {'x':x, 'y':y}
#.........这里部分代码省略.........