本文整理汇总了Python中pyjamas.ui.Grid.Grid.setBorderWidth方法的典型用法代码示例。如果您正苦于以下问题:Python Grid.setBorderWidth方法的具体用法?Python Grid.setBorderWidth怎么用?Python Grid.setBorderWidth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyjamas.ui.Grid.Grid
的用法示例。
在下文中一共展示了Grid.setBorderWidth方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: onModuleLoad
# 需要导入模块: from pyjamas.ui.Grid import Grid [as 别名]
# 或者: from pyjamas.ui.Grid.Grid import setBorderWidth [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: __init__
# 需要导入模块: from pyjamas.ui.Grid import Grid [as 别名]
# 或者: from pyjamas.ui.Grid.Grid import setBorderWidth [as 别名]
def __init__(self):
# layed out in a grid with odd rows a different color for
# visual separation
#lucky = Grid(9,10, CellPadding=25, CellSpacing=1, BorderWidth=1)
lucky = Grid()
lucky.resize(9,10)
lucky.setBorderWidth(1)
lucky.setCellPadding(25)
lucky.setCellSpacing(1)
val = 0
for x in range(0,9):
for y in range(0,10):
val += 1
lucky.setText(x,y,val)
grid = Grid(1,3,CellPadding=20,CellSpacing=0)
rf = grid.getRowFormatter()
rf.setStyleName(0, 'oddrow')
# popup timer buttons
ptb = PopupTimerButton(1)
grid.setWidget(0, 0, CaptionPanel('Start the Lucky Number Countdown', ptb, StyleName='left'))
grid.setWidget(0, 1, CaptionPanel('Current Lucky Number',ptb.box))
grid.setWidget(0, 2, lucky)
# add it all to the root panel
RootPanel().add(grid, lucky)
示例3: GridWidget
# 需要导入模块: from pyjamas.ui.Grid import Grid [as 别名]
# 或者: from pyjamas.ui.Grid.Grid import setBorderWidth [as 别名]
class GridWidget(AbsolutePanel):
def __init__(self):
AbsolutePanel.__init__(self)
self.page=0
self.min_page=1
self.max_page=10
self.addb=Button("Next >", self)
self.subb=Button("< Prev", self)
self.clearb=Button("Clear", self)
self.g=Grid()
self.g.resize(5, 5)
self.g.setWidget(0, 0, HTML("<b>Grid Test</b>"))
self.g.setBorderWidth(2)
self.g.setCellPadding(4)
self.g.setCellSpacing(1)
self.updatePageDisplay()
self.add(self.subb)
self.add(self.addb)
self.add(self.clearb)
self.add(self.g)
def onClick(self, sender):
if sender == self.clearb:
print "clear"
self.g.clear()
return
elif sender==self.addb:
self.page+=1
elif sender==self.subb:
self.page-=1
self.updatePageDisplay()
def updatePageDisplay(self):
if self.page<self.min_page: self.page=self.min_page
elif self.page>self.max_page: self.page=self.max_page
total_pages=(self.max_page-self.min_page) + 1
self.g.setHTML(0, 4, "<b>page %d of %d</b>" % (self.page, total_pages))
if self.page>=self.max_page:
self.addb.setEnabled(False)
else:
self.addb.setEnabled(True)
if self.page<=self.min_page:
self.subb.setEnabled(False)
else:
self.subb.setEnabled(True)
for y in range(1, 5):
for x in range(5):
self.g.setText(y, x, "%d (%d,%d)" % (self.page, x, y))
示例4: state_to_grid
# 需要导入模块: from pyjamas.ui.Grid import Grid [as 别名]
# 或者: from pyjamas.ui.Grid.Grid import setBorderWidth [as 别名]
def state_to_grid(self, prev_x_board=-1, prev_y_board=-1, prev_x_cell=-1, prev_y_cell=-1):
board = self.state.boards
for y_board in range(3):
for x_board in range(3):
# for this mini-grid, do i make buttons or dashes?
will_make_buttons = self.will_buttons(y_board, x_board)
g=Grid()
g.resize(3, 3)
g.setBorderWidth(2)
g.setCellPadding(9)
g.setCellSpacing(1)
for y_cell in range(3):
for x_cell in range(3):
if board[y_board][x_board][y_cell][x_cell]['cell'] == 0:
if will_make_buttons:
if self.min_player == -1:
b = Button('Play 1 here.', self)
else:
b = Button('Play %d here.' % (self.state.next_piece[2]), self)
b.point = {'x_cell':x_cell, 'y_cell':y_cell, 'y_board': y_board, 'x_board': x_board}
else:
b = HTML('-')
elif board[y_board][x_board][y_cell][x_cell]['cell'] == 1:
if (prev_x_cell == x_cell and
prev_y_cell == y_cell and
prev_y_board == y_board and
prev_x_board == x_board):
b = HTML('<p style="color:red">1</p>')
else:
b = HTML('1')
elif board[y_board][x_board][y_cell][x_cell]['cell'] == 2:
if (prev_x_cell == x_cell and
prev_y_cell == y_cell and
prev_y_board == y_board and
prev_x_board == x_board):
b = HTML('<p style="color:red">2</p>')
else:
b = HTML('2')
g.setWidget(y_cell, x_cell, b)
self.add(g)
self.g.setWidget(y_board, x_board, g)
示例5: init
# 需要导入模块: from pyjamas.ui.Grid import Grid [as 别名]
# 或者: from pyjamas.ui.Grid.Grid import setBorderWidth [as 别名]
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)
示例6: __init__
# 需要导入模块: from pyjamas.ui.Grid import Grid [as 别名]
# 或者: from pyjamas.ui.Grid.Grid import setBorderWidth [as 别名]
class Viewer:
def __init__(self, db_url, parent_panel, doc_callback=None, page_size=5):
self.db_url = db_url
self.parent_panel = parent_panel
self.doc_callback = doc_callback
self.page_size = page_size
def onModuleLoad(self):
## Grid setup
self.grid = Grid()
# Note: The resize method args are Rows,Cols (Curses style)
self.grid.resize(1,4)
self.grid.setBorderWidth(1)
self.grid.setHTML(0,0,'#')
self.grid.setHTML(0,1,'ID')
self.grid.setHTML(0,2,'Revision')
self.grid.setHTML(0,3,'Delete')
self.grid.addTableListener(self)
self.parent_panel.add(self.grid)
## Buttons
self.button_panel = HorizontalPanel()
# Prev
self.first_button = Button("<-", self.firstPage)
self.first_button.setEnabled(False)
self.button_panel.add(self.first_button)
self.prev_button = Button("Previous", self.prevPage)
self.prev_button.setEnabled(False)
self.button_panel.add(self.prev_button)
self.next_button = Button("Next", self.nextPage)
self.next_button.setEnabled(False)
self.button_panel.add(self.next_button)
self.parent_panel.add(self.button_panel)
def populate(self, json):
view_obj = JSONParser().decode(json)
view_rows = view_obj['rows']
offset = view_obj['offset']
num_rows = len(view_rows)
self.first_key = view_rows[0]['key']
if offset != 0:
self.first_button.setEnabled(True)
if num_rows > self.page_size:
self.next_key = view_rows[-1:][0]['key']
self.next_button.setEnabled(True)
self.grid.resize(self.page_size+1,4)
else:
self.grid.resize(num_rows+1,4)
for row_num in range(num_rows):
if row_num < self.page_size:
self.grid.setHTML(row_num+1, 0, 1+offset+row_num)
self.grid.setHTML(row_num+1, 1, view_rows[row_num]['key'])
self.grid.setHTML(row_num+1, 2,
view_rows[row_num]['value']['rev'])
self.grid.setHTML(row_num+1, 3, '<b>X O X</b>')
if len(self.prev_keys)>0:
self.prev_button.setEnabled(True)
def onCellClicked(self, sender, row, col):
doc_id = self.grid.getHTML(row, 1)
if col == 3:
doc_rev = self.grid.getHTML(row, 2)
url = self.db_url+doc_id+'?rev='+doc_rev
HTTPRequest().asyncDelete(None, None, url=url,
handler=DeleteHandler(self))
else:
if self.doc_callback is not None:
self.doc_callback(doc_id)
def firstPage(self):
self.loadPage(None)
def nextPage(self):
self.prev_keys.append(self.first_key)
self.loadPage(self.next_key)
def prevPage(self):
self.loadPage(self.prev_keys.pop())
def setView(self, view_path, first_key = None):
self.view_path = view_path
#self.prev_keys = []
#self.next_key = None
self.loadPage(first_key)
def loadPage(self, startkey=None):
limit = int(self.page_size)+1
view_url = self.db_url+self.view_path+'?limit=%d'%limit
if startkey is not None:
view_url += '&startkey="%s"'%startkey
else:
self.prev_keys = []
self.first_button.setEnabled(False)
#.........这里部分代码省略.........
示例7: GridWidget
# 需要导入模块: from pyjamas.ui.Grid import Grid [as 别名]
# 或者: from pyjamas.ui.Grid.Grid import setBorderWidth [as 别名]
class GridWidget(AbsolutePanel):
def __init__(self):
self.state = State()
self.game_over = False
self.TD_CONSTS = {'c3': 0.767944, 'c2': 1.049451, 'c1': 3.074038, 'c6': 0.220823, 'c5': 0.281883, 'c4': 0.605861}
AbsolutePanel.__init__(self)
StyleSheetCssText(margins) # initialize css...
self.welcome_label = HTML('<H2 align="center">Welcome to Meta-Tic-Tac-Toe!</H2><p>Play first by clicking on one of the positions in the middle board or let the AI go first by clicking on "AI first". To change the difficulty click on "Increase/Decrease search depth". Note: if there is a pop-up saying that the script is taking a long time to complete, this is not a bug - the AI is just taking a while to find the next move. Select the option to continue the script.</p>', StyleName='margins_both')
self.add(self.welcome_label)
self.depthLimit = 3
self.human_first = True
self.ai_first = Button("AI first.", self, StyleName='margins_left')
self.add(self.ai_first)
self.increase_depth = Button("Increase search depth", self)
self.decrease_depth = Button("Decrease search depth", self)
self.depth_label = HTML("""AI will search to a <a href="#depth_explanation">depth</a> of """ + str(self.depthLimit) +".")
self.depth_grid = Grid(StyleName='margins_left')
self.depth_grid.resize(1, 3)
self.depth_grid.setBorderWidth(2)
self.depth_grid.setCellPadding(9)
self.depth_grid.setCellSpacing(1)
self.add(self.depth_grid)
self.depth_grid.setWidget(0, 0, self.decrease_depth)
self.depth_grid.setWidget(0, 1, self.depth_label)
self.depth_grid.setWidget(0, 2, self.increase_depth)
self.new_game = Button("New game", self, StyleName='margins_left')
self.add(self.new_game)
self.score_label = Label("CURRENT SCORE: Human: %d | AI: %d"% (0,0), StyleName='margins_left')
self.add(self.score_label)
self.game_over_msg = HTML("", StyleName='margins_left')
self.add(self.game_over_msg)
# initialize the board grid:
self.g=Grid(StyleName='margins_left')
self.g.resize(3, 3)
self.g.setBorderWidth(2)
self.g.setCellPadding(9)
self.g.setCellSpacing(1)
self.init()
self.add(self.g)
# initialize the contstants adjustment grid:
self.adj_grid = Grid(StyleName='margins_left')
self.adj_grid.resize(7, 3)
self.adj_grid.setBorderWidth(2)
self.adj_grid.setCellPadding(9)
self.adj_grid.setCellSpacing(1)
self.init_constants_adj_grid()
self.add(self.adj_grid)
self.max_player = '-1'
self.min_player = '-1'
self.state_to_grid()
def init_constants_adj_grid(self):
'''Initializes the grid that allows the TD_CONSTS to be adjusted.
'''
self.decr_buttons = {}
self.adj_labels = {}
self.incr_buttons = {}
td_keys = ['c1', 'c2', 'c3', 'c4', 'c5', 'c6']
self.adj_grid.setWidget(0, 1, HTML('''Adjust the <a href="#utility_function">constants</a> to change<br>the AI's behavior.'''))
for i, key in enumerate(td_keys):
j = i + 1
self.decr_buttons[key] = Button('<', self)
self.adj_grid.setWidget(j, 0, self.decr_buttons[key])
self.incr_buttons[key] = Button('>', self)
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)
#.........这里部分代码省略.........
示例8: GridWidget
# 需要导入模块: from pyjamas.ui.Grid import Grid [as 别名]
# 或者: from pyjamas.ui.Grid.Grid import setBorderWidth [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}
#.........这里部分代码省略.........
示例9: GridWidget
# 需要导入模块: from pyjamas.ui.Grid import Grid [as 别名]
# 或者: from pyjamas.ui.Grid.Grid import setBorderWidth [as 别名]
class GridWidget(AbsolutePanel):
def __init__(self):
self.state = State()
self.game_round = 0
self.TD_CONSTS = {'c3': 1., 'c2': 1., 'c1': 1., 'c6': 1., 'c5': 1., 'c4': 1.}
self.CONSTS = {'c3': .5, 'c2': 1., 'c1': 3., 'c6': .5, 'c5': .5, 'c4': .5}
self.BEST_CONSTANTS = {'c3': 0.767944, 'c2': 1.049451, 'c1': 3.074038, 'c6': 0.220823, 'c5': 0.281883, 'c4': 0.605861}
self.ONES_CONSTS = {'c3': 1., 'c2': 1., 'c1': 1., 'c6': 1., 'c5': 1., 'c4': 1.}
AbsolutePanel.__init__(self)
self.welcome_label = HTML('<H2 align="center">Welcome to Meta-Tic-Tac-Toe!</H2>To watch the AI play itself, press either "begin game" button. Note: if there is a pop-up saying that the script is taking a long time to complete, this is not a bug - the AI is just taking a while to find the next move. Select the option to continue the script.', StyleName='margins_both')
self.add(self.welcome_label)
self.depth_limit = 2
self.train_td = Button("Begin game. Learning AI first!", self, StyleName='margins_left')
self.add(self.train_td)
self.train_static = Button("Begin game. Static AI first!", self, StyleName='margins_left')
self.add(self.train_static)
self.score_label = Label("CURRENT SCORE: Learning AI: %d | Static AI: %d"% (0,0), StyleName='margins_left')
self.add(self.score_label)
self.game_over_message = Label("", StyleName='margins_left')
self.add(self.game_over_message)
StyleSheetCssText(margins)
self.increase_depth = Button("Increase ply search depth.", self)
self.decrease_depth = Button("Decrease ply search depth.", self)
self.depth_label = Label("Current depth is " + str(self.depth_limit) +".")
self.depth_grid = Grid(StyleName='margins_left')
self.depth_grid.resize(1, 3)
self.depth_grid.setBorderWidth(2)
self.depth_grid.setCellPadding(9)
self.depth_grid.setCellSpacing(1)
self.add(self.depth_grid)
self.depth_grid.setWidget(0, 0, self.decrease_depth)
self.depth_grid.setWidget(0, 1, self.depth_label)
self.depth_grid.setWidget(0, 2, self.increase_depth)
# initialize the board grid:
self.g=Grid(StyleName='margins_left')
self.g.resize(3, 3)
self.g.setBorderWidth(2)
self.g.setCellPadding(9)
self.g.setCellSpacing(1)
self.init()
self.add(self.g)
# initialize the contstants adjustment grid:
self.adj_grid = Grid(StyleName='margins_left')
self.adj_grid.resize(7, 4)
self.adj_grid.setBorderWidth(2)
self.adj_grid.setCellPadding(9)
self.adj_grid.setCellSpacing(1)
self.init_constants_adj_grid()
self.add(self.adj_grid)
self.reset_constants = Button("Reset all of Learning AI's constants to 1.", self, StyleName='margins_left')
self.add(self.reset_constants)
self.state_to_grid()
def init_constants_adj_grid(self):
'''Initializes the grid that allows the TD_CONSTS to be adjusted.
'''
self.decr_buttons = {}
self.adj_learning_labels = {}
self.adj_static_labels = {}
self.incr_buttons = {}
td_keys = ['c1', 'c2', 'c3', 'c4', 'c5', 'c6']
learning_ai_header = Label("Constant for the learning AI.")
self.adj_grid.setWidget(0, 0, learning_ai_header)
static_ai_header = Label("Constants for the static AI.")
self.adj_grid.setWidget(0, 2, static_ai_header)
for i, key in enumerate(td_keys):
j = i + 1 # off by one because of header...
self.adj_learning_labels[key] = Label("Constant %d: %f" % (key[1], self.TD_CONSTS[key]))
self.adj_grid.setWidget(j, 0, self.adj_learning_labels[key])
self.decr_buttons[key] = Button('<', self)
self.adj_grid.setWidget(j, 1, self.decr_buttons[key])
self.adj_static_labels[key] = Label("Constant %d: %f" % (key[1], self.CONSTS[key]))
self.adj_grid.setWidget(j, 2, self.adj_static_labels[key])
self.incr_buttons[key] = Button('>', self)
self.adj_grid.setWidget(j, 3, self.incr_buttons[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):
#.........这里部分代码省略.........