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


Python Grid.setCellPadding方法代码示例

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


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

示例1: onModuleLoad

# 需要导入模块: from pyjamas.ui.Grid import Grid [as 别名]
# 或者: from pyjamas.ui.Grid.Grid import setCellPadding [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

示例2: __init__

# 需要导入模块: from pyjamas.ui.Grid import Grid [as 别名]
# 或者: from pyjamas.ui.Grid.Grid import setCellPadding [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)
开发者ID:rgeos,项目名称:bingo,代码行数:30,代码来源:bingo.py

示例3: GridWidget

# 需要导入模块: from pyjamas.ui.Grid import Grid [as 别名]
# 或者: from pyjamas.ui.Grid.Grid import setCellPadding [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))
开发者ID:anandology,项目名称:pyjamas,代码行数:61,代码来源:GridTest.py

示例4: RightPanel

# 需要导入模块: from pyjamas.ui.Grid import Grid [as 别名]
# 或者: from pyjamas.ui.Grid.Grid import setCellPadding [as 别名]
class RightPanel(DockPanel):

    def __init__(self):
        DockPanel.__init__(self)
        self.grids = {}
        self.g = Grid()
        self.g.setCellSpacing("0px")
        self.g.setCellPadding("8px")
        self.title = HTML("&nbsp;")
        self.title.setStyleName("rightpanel-title")
        self.add(self.title, DockPanel.NORTH)
        self.setCellWidth(self.title, "100%")
        self.setCellHorizontalAlignment(self.title,
                                        HasHorizontalAlignment.ALIGN_LEFT)
        self.add(self.g, DockPanel.CENTER)

    def setTitle(self, title):
        self.title.setHTML(title)
        
    def clear_items(self):

        for i in range(len(self.grids)):
            g = self.grids[i]
            if hasattr(g, "clear_items"):
                g.clear_items()

        self.grids = {}
        self.g.resize(0, 0)

    def setup_panels(self, datasets):

        self.grids = {}
        self.data = {}
        self.names = {}
        self.loaded = {}
        size = len(datasets)
        self.g.resize(size, 1)
        #for i in range(size):
        #    item = datasets[i]
        #    fname = item[0]
        #    self.grids[i] = RightGrid(fname)
        #    self.g.setWidget(i, 0, self.grids[i])
   
    def add_html(self, html, name, index):
        self.data[index] = html
        self.names[index] = name
        self.grids[index] = HTML(html)
        self.g.setWidget(index, 0, self.grids[index])

    def add_items(self, items, name, index):
        self.data[index] = items
        self.names[index] = name
        self.grids[index] = RightGrid("")
        self.grids[index].set_items(items)
        self.g.setWidget(index, 0, self.grids[index])
开发者ID:FreakTheMighty,项目名称:pyjamas,代码行数:57,代码来源:InfoDirectory.py

示例5: state_to_grid

# 需要导入模块: from pyjamas.ui.Grid import Grid [as 别名]
# 或者: from pyjamas.ui.Grid.Grid import setCellPadding [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)
开发者ID:chetweger,项目名称:min-max-games,代码行数:48,代码来源:Meta.py

示例6: init

# 需要导入模块: from pyjamas.ui.Grid import Grid [as 别名]
# 或者: from pyjamas.ui.Grid.Grid import setCellPadding [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)
开发者ID:chetweger,项目名称:min-max-games,代码行数:21,代码来源:Meta.py

示例7: GridWidget

# 需要导入模块: from pyjamas.ui.Grid import Grid [as 别名]
# 或者: from pyjamas.ui.Grid.Grid import setCellPadding [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)
#.........这里部分代码省略.........
开发者ID:chetweger,项目名称:min-max-games,代码行数:103,代码来源:Meta.py

示例8: __init__

# 需要导入模块: from pyjamas.ui.Grid import Grid [as 别名]
# 或者: from pyjamas.ui.Grid.Grid import setCellPadding [as 别名]
    def __init__(self, statusSummary, sender):
        VerticalPanel.__init__(self, Spacing=10,
                               StyleName='userlist-error-box')
        self.add(HTML("We're currently working on users you mentioned",
                      StyleName='userlist-error-title'))

        self.add(HTML(
            """<p>Below is a summary of work already in progress, or
        queued, which must complete before we can run your query. Please
        note that Tickery is subject to Twitter's API rate limiting and
        general network latency, so you may need to be patient. We'll get
        there!</p>

        <p><a href=\"%s\">Here's a link</a> to this results page so you can
        come back to see how we're doing.  You can also click %r again to
        see updated progress.</p>""" %
            (sender.resultsLink(), go.goButtonText),
            StyleName='userlist-error-text'))

        nRows = 0

        underway = statusSummary['underway']
        nUnderway = len(underway)
        queued = statusSummary['queued']
        nQueued = len(queued)

        nCols = 4
        width = 200

        if nUnderway:
            nRows += nUnderway + 1
        if nQueued:
            nRows += nQueued + 1

        g = Grid(nRows, nCols, StyleName='users')
        g.setCellPadding(2)
        cellFormatter = g.getCellFormatter()
        row = 0

        if nUnderway:
            g.setHTML(row, 0, 'Users currently being processed&nbsp;')
            cellFormatter.setStyleName(row, 0, 'title-lhs')
            g.setText(row, 1, 'Name')
            cellFormatter.setStyleName(row, 1, 'title')
            g.setText(row, 2, 'Friends')
            cellFormatter.setStyleName(row, 2, 'title')
            g.setText(row, 3, '% done')
            cellFormatter.setStyleName(row, 3, 'title')
            cellFormatter.setWidth(row, 3, width)
            row += 1

            for u, nFriends, done in underway:
                cellFormatter.setStyleName(row, 0, 'blank')
                n = utils.splitthousands(nFriends)
                g.setHTML(row, 1, utils.screennameToTwitterLink(u))
                g.setHTML(row, 2, utils.screennameToTwitterFriendsLink(u, n))
                cellFormatter.setHorizontalAlignment(row, 2, 'right')

                pct = '%d' % int(done * 100.0)
                left = Label(pct, StyleName='done', Width=int(done * width))
                g.setWidget(row, 3, left)

                row += 1

        if nQueued:
            g.setHTML(row, 0, 'Users queued for processing&nbsp;')
            cellFormatter.setStyleName(row, 0, 'title-lhs')
            g.setText(row, 1, 'Name')
            cellFormatter.setStyleName(row, 1, 'title')
            g.setText(row, 2, 'Friends')
            cellFormatter.setStyleName(row, 2, 'title')
            g.setText(row, 3, 'Queue position')
            cellFormatter.setStyleName(row, 3, 'title')
            row += 1

            for u, nFriends, pos in queued:
                cellFormatter.setStyleName(row, 0, 'blank')
                n = utils.splitthousands(nFriends)
                g.setHTML(row, 1, utils.screennameToTwitterLink(u))
                g.setHTML(row, 2, utils.screennameToTwitterFriendsLink(u, n))
                cellFormatter.setHorizontalAlignment(row, 2, 'right')
                g.setText(row, 3, pos)
                cellFormatter.setHorizontalAlignment(row, 3, 'right')
                row += 1

        self.add(g)
开发者ID:fluidinfo,项目名称:Tickery,代码行数:88,代码来源:unknown.py

示例9: GridWidget

# 需要导入模块: from pyjamas.ui.Grid import Grid [as 别名]
# 或者: from pyjamas.ui.Grid.Grid import setCellPadding [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}
#.........这里部分代码省略.........
开发者ID:chetweger,项目名称:min-max-games,代码行数:103,代码来源:TTT.py

示例10: GridWidget

# 需要导入模块: from pyjamas.ui.Grid import Grid [as 别名]
# 或者: from pyjamas.ui.Grid.Grid import setCellPadding [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):

#.........这里部分代码省略.........
开发者ID:chetweger,项目名称:min-max-games,代码行数:103,代码来源:LearnMeta.py


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