本文整理汇总了Python中pyjamas.ui.Grid.Grid.getWidget方法的典型用法代码示例。如果您正苦于以下问题:Python Grid.getWidget方法的具体用法?Python Grid.getWidget怎么用?Python Grid.getWidget使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyjamas.ui.Grid.Grid
的用法示例。
在下文中一共展示了Grid.getWidget方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Form
# 需要导入模块: from pyjamas.ui.Grid import Grid [as 别名]
# 或者: from pyjamas.ui.Grid.Grid import getWidget [as 别名]
class Form(FormPanel):
def __init__(self, svc, **kwargs):
self.describe_listeners = []
if kwargs.has_key('listener'):
listener = kwargs.pop('listener')
self.addDescribeListener(listener)
if kwargs.has_key('data'):
data = kwargs.pop('data')
else:
data = None
FormPanel.__init__(self, **kwargs)
self.svc = svc
self.grid = Grid()
self.grid.resize(0, 3)
self.add(self.grid)
self.describer = FormDescribeGrid(self)
self.saver = FormSaveGrid(self)
self.getter = FormGetGrid(self)
self.formsetup(data)
def addDescribeListener(self, l):
self.describe_listeners.append(l)
def add_widget(self, description, widget):
""" adds a widget, with error rows interspersed
"""
num_rows = self.grid.getRowCount()
self.grid.resize((num_rows+1), 3)
self.grid.setHTML(num_rows, 0, description)
self.grid.setWidget(num_rows, 1, widget)
def get(self, **kwargs):
writebr(repr(kwargs))
self.svc({}, {'get': kwargs}, self.getter)
def save(self, data=None):
self.clear_errors()
if data is None:
data = self.getValue()
self.data = data
writebr(repr(self.data))
self.svc(data, {'save': None}, self.saver)
def save_respond(self, response):
if not response['success']:
errors = response['errors']
self.set_errors(errors)
for l in self.describe_listeners:
l.onErrors(self, errors)
return
for l in self.describe_listeners:
l.onSaveDone(self, response)
def formsetup(self, data=None):
if data is None:
data = {}
self.data = data
self.svc(data, {'describe': None}, self.describer)
def clear_errors(self):
for idx, fname in enumerate(self.fields):
self.grid.setHTML(idx, 2, None)
def set_errors(self, errors):
offsets = {}
for idx, fname in enumerate(self.fields):
offsets[fname] = idx
for k, err in errors.items():
err = "<br />".join(err)
idx = offsets[k]
self.grid.setHTML(idx, 2, err)
def update_values(self, data = None):
if data is not None:
self.data = data
for idx, fname in enumerate(self.fields):
val = None
if self.data.has_key(fname):
val = self.data[fname]
w = self.grid.getWidget(idx, 1)
w.setValue(val)
def do_get(self, response):
fields = response.get('instance', None)
if fields:
self.update_values(fields)
for l in self.describe_listeners:
l.onRetrieveDone(self, fields)
#.........这里部分代码省略.........
示例2: InputBox
# 需要导入模块: from pyjamas.ui.Grid import Grid [as 别名]
# 或者: from pyjamas.ui.Grid.Grid import getWidget [as 别名]
class InputBox(FocusPanel):
_props = [ ("maxLength", "Max Length", "MaxLength", int),
("text", "Text", "Text", None),
("matchPattern", "Match Pattern", "MatchPattern", None),
("cursorStyle", "Cursor Style", "CursorStyle", None),
]
@classmethod
def _getProps(self):
return FocusPanel._getProps() + self._props
def __init__(self, **kwargs):
""" setMatchPattern - defaults to '' to match everything
match pattern examples: '^[0-9]*$' is for digits only
'^[0-9,A-Z]*$' is for digits and uppercase
setMaxLength
setText
OB """
kwargs['MatchPattern'] = kwargs.pop('MatchPattern', '')
cs = kwargs.pop('CursorStyle', "inputbox-cursor")
gs = kwargs.pop('StyleName', 'gwt-inputbox')
ap = AbsolutePanel(StyleName="inputbox")
self.tp = Grid(StyleName=gs, Width="100%", Height="100%",
CellPadding=0, CellSpacing=0)
self.cursor = HTML(StyleName=cs)
ap.add(self.tp)
ap.add(self.cursor, 0, 0)
self.cf = self.tp.getCellFormatter()
FocusPanel.__init__(self, Widget=ap, **kwargs)
self.addTableListener(self)
self.addKeyboardListener(self)
self.addFocusListener(self)
self.word_selected_pos = 0
self.ctimer = Timer(notify=self.cursorFlash)
self.focusset = False
self.cstate = False
self._keypressListeners = []
def addKeypressListener(self, listener):
self._keypressListeners.append(listener)
def removeKeypressListener(self, listener):
self._keypressListeners.remove(listener)
def getMatchPattern(self):
return self.mp
def setMatchPattern(self, mp):
self.mp = mp
self.rexp = re.compile(self.mp)
def addDblTableListener(self, listener):
self.tp.addDblTableListener(listener)
def addTableListener(self, listener):
self.tp.addTableListener(listener)
def _move_cursor(self, col):
""" moves the css-styled cursor
"""
#old style (useful for insert mode - don't delete this line for now!)
#self.cf.setStyleName(0, col, "inputbox-square-word-cursor", highlight)
el = self.cf.getRawElement(0, col+1)
w = self.getWidget()
px = self.tp.getAbsoluteLeft()
py = self.tp.getAbsoluteTop()
width = DOM.getOffsetWidth(el)
px = DOM.getAbsoluteLeft(el) - px
py = DOM.getAbsoluteTop(el) - py
w.setWidgetPosition(self.cursor, px, py)
def _highlight_cursor(self, col, highlight):
""" highlights (or dehighlights) the currently selected cell
"""
#old style (useful for insert mode - don't delete this line for now!)
#self.cf.setStyleName(0, col, "inputbox-square-word-cursor", highlight)
print "_highlight", col, highlight
self._move_cursor(col)
self.cursor.setStyleName("inputbox-square-word-cursor", highlight)
def set_grid_value(self, v, y, x):
if v:
w = ""
else:
w = "0px"
v = v or EMPTY
s = HTML(v, StyleName="inputbox-square")
self.tp.setWidget(y, x, s)
self.cf.setAlignment(y, x, HasAlignment.ALIGN_LEFT,
HasAlignment.ALIGN_MIDDLE)
self.cf.setWidth(y, x, w)
#.........这里部分代码省略.........
示例3: GridWidget
# 需要导入模块: from pyjamas.ui.Grid import Grid [as 别名]
# 或者: from pyjamas.ui.Grid.Grid import getWidget [as 别名]
#.........这里部分代码省略.........
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)
self.state = new_state
self.state_to_grid(prev_x_board=last_position['x_board'],
prev_y_board=last_position['y_board'],
prev_x_cell=last_position['x_cell'],
prev_y_cell=last_position['y_cell'],)
if hasattr(sender, 'point'):
if self.min_player == -1: # we only set min_player and max_player when they are not yet initialized
self.max_player = '2'
self.min_player = '1'
self.ai_first.setVisible(False) # can't go first any more so we make it invisible...
point = sender.point
g = self.g.getWidget(point['y_board'], point['x_board'])
g.setText(point['y_cell'], point['x_cell'], str(self.min_player))
self.grid_to_state(point)
self.check_win()
self.state.next_piece[2] = self.max_player
new_state = ab(self.state, self.TD_CONSTS, depth_limit=self.depthLimit)[1]
last_position = find_last_move(self.state, new_state)
self.state = new_state
self.state_to_grid(prev_x_board=last_position['x_board'],
prev_y_board=last_position['y_board'],
prev_x_cell=last_position['x_cell'],
prev_y_cell=last_position['y_cell'],)
self.check_win()
def check_adjusts(self, sender):
td_keys = ['c1', 'c2', 'c3', 'c4', 'c5', 'c6']
for key in td_keys:
if self.incr_buttons[key] == sender:
self.change_td_const(key, '+')
if self.decr_buttons[key] == sender:
self.change_td_const(key, '-')
self.adj_labels[key].setText("Constant %d: %f" % (key[1], self.TD_CONSTS[key]))
def change_td_const(self, key, sign):
if sign == '+':
示例4: GridWidget
# 需要导入模块: from pyjamas.ui.Grid import Grid [as 别名]
# 或者: from pyjamas.ui.Grid.Grid import getWidget [as 别名]
#.........这里部分代码省略.........
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}
self.g.setWidget(y, x, b)
else:
self.g.setText(y, x, '-')
elif board[y][x] == '1':
self.g.setText(y, x, '1')
elif board[y][x] == '2':
self.g.setText(y, x, '2')
else:
print 'state_to_grid exception'
#assert False
def grid_to_state(self):
next_state = State()
for y in range(3):
for x in range(3):
if isinstance(self.g.getWidget(y, x), Button):
print y, x
next_state.board[y][x] = 0
elif self.g.getText(y, x) == '1' or self.g.getText(y, x) == '2':
next_state.board[y][x] = int(self.g.getText(y,x))
else:
print 'grid_to_state exception'
#assert False
next_state.min_v = self.state.min_v
next_state.max_v = self.state.max_v
next_state.player = self.state.player
return next_state
def init(self):
for y in range(3):
for x in range(3):
b = Button('Press', self)
b.point = {'x':x, 'y':y}
self.g.setWidget(y, x, b)