本文整理汇总了Python中pyjamas.ui.FlexTable.FlexTable.addTableListener方法的典型用法代码示例。如果您正苦于以下问题:Python FlexTable.addTableListener方法的具体用法?Python FlexTable.addTableListener怎么用?Python FlexTable.addTableListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyjamas.ui.FlexTable.FlexTable
的用法示例。
在下文中一共展示了FlexTable.addTableListener方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MailList
# 需要导入模块: from pyjamas.ui.FlexTable import FlexTable [as 别名]
# 或者: from pyjamas.ui.FlexTable.FlexTable import addTableListener [as 别名]
class MailList(Composite):
VISIBLE_EMAIL_COUNT = 10
def __init__(self, mailObject):
Composite.__init__(self)
self.countLabel = HTML()
self.newerButton = HTML("<a href='javascript:;'>< newer</a>", True)
self.olderButton = HTML("<a href='javascript:;'>older ></a>", True)
self.startIndex = 0
self.selectedRow = -1
self.table = FlexTable()
self.navBar = HorizontalPanel()
self.mailObject = mailObject
# Setup the table.
self.table.setCellSpacing(0)
self.table.setCellPadding(2)
self.table.setWidth("100%")
# Hook up events.
self.table.addTableListener(self)
self.newerButton.addClickListener(self)
self.olderButton.addClickListener(self)
# Create the 'navigation' bar at the upper-right.
innerNavBar = HorizontalPanel()
innerNavBar.setSpacing(8)
innerNavBar.add(self.newerButton)
innerNavBar.add(self.countLabel)
innerNavBar.add(self.olderButton)
self.navBar.setStyleName("mail-ListNavBar")
self.navBar.setHorizontalAlignment(HasAlignment.ALIGN_RIGHT)
self.navBar.add(innerNavBar)
self.navBar.setWidth("100%")
self.initWidget(self.table)
self.setStyleName("mail-List")
self.initTable()
self.update()
def onCellDoubleClicked(self, sender, row, cell):
pass
def onCellClicked(self, sender, row, cell):
# Select the row that was clicked (-1 to account for header row).
if (row > 0):
self.selectRow(row - 1)
def onClick(self, sender):
if (sender == self.olderButton):
# Move forward a page.
self.startIndex = self.startIndex + MailList.VISIBLE_EMAIL_COUNT
if (self.startIndex >= MailItems().getMailItemCount()):
self.startIndex = self.startIndex - MailList.VISIBLE_EMAIL_COUNT
else:
self.styleRow(self.selectedRow, False)
self.selectedRow = -1
self.update()
elif (sender == self.newerButton):
# Move back a page.
self.startIndex = self.startIndex - MailList.VISIBLE_EMAIL_COUNT
if (self.startIndex < 0):
self.startIndex = 0
else:
self.styleRow(self.selectedRow, False)
self.selectedRow = -1
self.update()
def initTable(self):
# Create the header row.
self.table.setText(0, 0, "sender")
self.table.setText(0, 1, "email")
self.table.setText(0, 2, "subject")
self.table.setWidget(0, 3, self.navBar)
self.table.getRowFormatter().setStyleName(0, "mail-ListHeader")
# Initialize the rest of the rows.
i = 0
while i < MailList.VISIBLE_EMAIL_COUNT:
self.table.setText(i + 1, 0, "")
self.table.setText(i + 1, 1, "")
self.table.setText(i + 1, 2, "")
self.table.getCellFormatter().setWordWrap(i + 1, 0, False)
self.table.getCellFormatter().setWordWrap(i + 1, 1, False)
self.table.getCellFormatter().setWordWrap(i + 1, 2, False)
self.table.getFlexCellFormatter().setColSpan(i + 1, 2, 2)
i = i + 1
def selectRow(self, row):
# When a row (other than the first one, which is used as a header) is
# selected, display its associated MailItem.
item = MailItems().getMailItem(self.startIndex + row)
if item is None:
return
#.........这里部分代码省略.........
示例2: RadioEditor
# 需要导入模块: from pyjamas.ui.FlexTable import FlexTable [as 别名]
# 或者: from pyjamas.ui.FlexTable.FlexTable import addTableListener [as 别名]
class RadioEditor ( BaseEditor ):
""" Enumeration editor, used for the "custom" style, that displays radio
buttons.
"""
# Is the button layout row-major or column-major?
row_major = Bool( False )
#---------------------------------------------------------------------------
# Finishes initializing the editor by creating the underlying toolkit
# widget:
#---------------------------------------------------------------------------
def init ( self, parent ):
""" Finishes initializing the editor by creating the underlying toolkit
widget.
"""
super( RadioEditor, self ).init( parent )
self.control = FlexTable( BorderWidth=0, Width="100%" )
self.control.addTableListener( self.update_object )
self.rebuild_editor()
#---------------------------------------------------------------------------
# Handles the user clicking one of the 'custom' radio buttons:
#---------------------------------------------------------------------------
def update_object ( self, index ):
""" Handles the user clicking one of the custom radio buttons.
"""
try:
self.value = self.mapping[ self.names[ index ] ]
except:
pass
#---------------------------------------------------------------------------
# Updates the editor when the object trait changes external to the editor:
#---------------------------------------------------------------------------
def update_editor ( self ):
""" Updates the editor when the object trait changes externally to the
editor.
"""
table = self.control
value = self.value
for row in range( table.getRowCount() ):
for cell in range( table.getCellCount( row ) ):
rb = table.getWidget( row, cell )
rb.setChecked( rb.getText == value )
#---------------------------------------------------------------------------
# Rebuilds the contents of the editor whenever the original factory
# object's 'values' trait changes:
#---------------------------------------------------------------------------
def rebuild_editor ( self ):
""" Rebuilds the contents of the editor whenever the original factory
object's **values** trait changes.
"""
# Clear any existing content:
self.control.clear()
# Get the current trait value:
cur_name = self.str_value
# Create a sizer to manage the radio buttons:
names = self.names
mapping = self.mapping
n = len( names )
cols = self.factory.cols
rows = (n + cols - 1) / cols
if self.row_major:
incr = [ 1 ] * cols
else:
incr = [ n / cols ] * cols
rem = n % cols
for i in range( cols ):
incr[i] += (rem > i)
incr[-1] = -(reduce( lambda x, y: x + y, incr[:-1], 0 ) - 1)
# Add the set of all possible choices:
table = self.control
index = 0
for i in range( rows ):
for j in range( cols ):
if n > 0:
name = names[index]
rb = self.create_button(name)
rb.setText = mapping[name]
rb.setChecked(name == cur_name)
rb.addClickListener( getattr(self, "update_object") )
self.set_tooltip(rb)
table.setWidget(i, j, rb)
index += incr[j]
#.........这里部分代码省略.........