本文整理汇总了Python中pyjamas.ui.TextBox.TextBox.addChangeListener方法的典型用法代码示例。如果您正苦于以下问题:Python TextBox.addChangeListener方法的具体用法?Python TextBox.addChangeListener怎么用?Python TextBox.addChangeListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyjamas.ui.TextBox.TextBox
的用法示例。
在下文中一共展示了TextBox.addChangeListener方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TextEditor
# 需要导入模块: from pyjamas.ui.TextBox import TextBox [as 别名]
# 或者: from pyjamas.ui.TextBox.TextBox import addChangeListener [as 别名]
class TextEditor(Editor):
""" Base class for text style editors, which displays an editable text
field, containing a text representation of the object trait value.
"""
# ---------------------------------------------------------------------------
# Finishes initializing the editor by creating the underlying toolkit
# widget:
# ---------------------------------------------------------------------------
def init(self, parent):
""" Finishes initializing the editor by creating the underlying toolkit
widget.
"""
self.control = TextBox()
self.control.setText(self.str_value)
self.control.addChangeListener(getattr(self, "update_object"))
self.set_tooltip()
# ---------------------------------------------------------------------------
# Handles the user changing the contents of the edit control:
# ---------------------------------------------------------------------------
def update_object(self, sender):
""" Handles the user changing the contents of the edit control.
"""
try:
self.value = unicode(self.control.getText())
except TraitError, excp:
pass
示例2: PreferencesDlg
# 需要导入模块: from pyjamas.ui.TextBox import TextBox [as 别名]
# 或者: from pyjamas.ui.TextBox.TextBox import addChangeListener [as 别名]
class PreferencesDlg(DialogBox):
fileLocation = None
def __init__(self, left = 50, top = 50):
DialogBox.__init__(self, modal = False)
self.setPopupPosition(left, top)
self.setText("Preferences")
ftable = FlexTable()
ftableFormatter = ftable.getFlexCellFormatter()
row = 0
self.fileLocation = getCookie("fileLocation")
row += 1
ftable.setWidget(row, 0, Label("Sheet loaded on startup", wordWrap=False))
self.fileLocationInput = TextBox()
self.fileLocationInput.addChangeListener(self.checkValid)
self.fileLocationInput.addKeyboardListener(self)
self.fileLocationInput.setVisibleLength(30)
self.fileLocationInput.setText(self.fileLocation)
ftable.setWidget(row, 1, self.fileLocationInput)
row += 1
hpanel = HorizontalPanel()
self.saveBtn = Button("Save", self.onSave)
self.saveBtn.setEnabled(False)
hpanel.add(self.saveBtn)
self.cancelBtn = Button("Cancel", self.onCancel)
hpanel.add(self.cancelBtn)
ftable.setWidget(row, 0, hpanel)
ftableFormatter.setColSpan(row, 0, 2)
self.setWidget(ftable)
def onCancel(self, sender):
self.hide()
def onSave(self, sender):
setCookie("fileLocation", self.fileLocationInput.getText(), 1000000000)
self.hide()
def checkValid(self, evt=None):
if self.fileLocation != self.fileLocationInput.getText():
self.saveBtn.setEnabled(True)
else:
self.saveBtn.setEnabled(False)
def onClick(self, sender):
pass
def onKeyUp(self, sender, keyCode, modifiers):
self.checkValid()
def onKeyDown(self, sender, keyCode, modifiers):
pass
def onKeyPress(self, sender, keyCode, modifiers):
pass
示例3: onClick
# 需要导入模块: from pyjamas.ui.TextBox import TextBox [as 别名]
# 或者: from pyjamas.ui.TextBox.TextBox import addChangeListener [as 别名]
def onClick(self, sender):
global statusbar, boxes
statusbar.setText("Button pressed")
pass
if sender == self.buttonupdate:
self.commobj = AMS.AMS_Comm()
statusbar.setText("Updating data: Press Display list button to refesh")
if sender == self.button:
if AMS.sent > AMS.recv:
statusbar.setText("Press button again: sent " + str(AMS.sent) + " recv " + str(AMS.recv))
if (
self.commobj.commname == "No AMS publisher running"
or not self.commobj.commname
or self.commobj.comm == -1
):
if self.tree:
self.panel.remove(self.tree)
else:
statusbar.setText("Memories for AMS Comm: " + self.commobj.commname)
result = self.commobj.get_memory_list()
if self.tree:
self.panel.remove(self.tree)
self.tree = Tree()
for i in result:
if i == "Stack":
continue
subtree = TreeItem(i)
memory = self.commobj.memory_attach(i)
fields = memory.get_field_list()
if not isinstance(fields, list):
fields = [fields]
block = false
for j in fields:
field = memory.get_field_info(j)
if str(field[1]) == "AMS_READ":
if j == "Publish Block":
if field[4] == "true":
block = true
else:
subtree.addItem(j + " = " + str(field[4]))
else:
if j == "Block" and not block:
continue
PN = HorizontalPanel()
PN.add(Label(Text=j + " ="))
tb = TextBox(Text=str(field[4]))
boxes[tb] = [i, j, memory]
tb.addChangeListener(self.textboxlistener)
PN.add(tb)
subtree.addItem(PN)
self.tree.addItem(subtree)
self.panel.add(self.tree)
示例4: addRow
# 需要导入模块: from pyjamas.ui.TextBox import TextBox [as 别名]
# 或者: from pyjamas.ui.TextBox.TextBox import addChangeListener [as 别名]
def addRow(self, timeVO = None):
self.rows += 1
col = -1
for name, maxLength, visibleLength in self.columns:
col += 1
textBox = TextBox()
textBox.setText("")
textBox.col = col
textBox.row = self.rows
textBox.addChangeListener(self.checkValid)
textBox.addKeyboardListener(self)
textBox.addFocusListener(self)
textBox.setName(name)
if not maxLength is None:
textBox.setMaxLength(maxLength)
if not visibleLength is None:
textBox.setVisibleLength(visibleLength)
self.setWidget(self.rows, col, textBox)
if not timeVO is None:
self.setRow(self.rows, timeVO)
示例5: createRegisterPanel
# 需要导入模块: from pyjamas.ui.TextBox import TextBox [as 别名]
# 或者: from pyjamas.ui.TextBox.TextBox import addChangeListener [as 别名]
def createRegisterPanel( self, registerNames ) :
"""
Creates panels and buttons for everything given in registerNames, and returns the main panel.
"""
flowPanel=FlowPanel()
for buttonName in registerNames :
newPanel=HorizontalPanel()
label=Label(buttonName)
newPanel.add( label )
newTextBox=TextBox()
newTextBox.setEnabled(False)
newTextBox.setWidth(80)
statusBox=TextBox()
statusBox.setEnabled(False)
statusBox.setWidth(30)
newPanel.add(newTextBox)
newPanel.add(statusBox)
newPanel.setCellHorizontalAlignment( newTextBox, HasHorizontalAlignment.ALIGN_RIGHT )
newPanel.setCellHorizontalAlignment( statusBox, HasHorizontalAlignment.ALIGN_RIGHT )
newPanel.setCellWidth( statusBox, "20px" )
newPanel.setWidth("100%")
#newPanel.setStyleName("areaStyle");
#newPanel.setBorderWidth(5);
newTextBox.setText("select chip...")
newTextBox.addChangeListener(self)
newTextBox.setTitle(buttonName) # This isn't displayed, but it's useful to have stored
self.i2cValueEntries[buttonName]=newTextBox
self.statusValueEntries[buttonName]=statusBox
statusBox.setTitle(buttonName)
statusBox.setText("...")
flowPanel.add(newPanel)
return flowPanel
示例6: DateField
# 需要导入模块: from pyjamas.ui.TextBox import TextBox [as 别名]
# 或者: from pyjamas.ui.TextBox.TextBox import addChangeListener [as 别名]
class DateField(Composite, DateSelectedHandler):
img_base = None
icon_img = None
icon_style = "calendar-img"
today_text = "Today"
today_style = "calendar-today-link"
def __init__(self, format='%d-%m-%Y'):
DateSelectedHandler.__init__(self)
if self.img_base is None:
self.img_base = pygwt.getImageBaseURL(True)
if self.icon_img is None:
self.icon_img = self.img_base + 'icon_calendar.gif'
self.format = format
self.tbox = TextBox()
self.tbox.setVisibleLength(10)
# assume valid sep is - / . or nothing
if format.find('-') >= 0:
self.sep = '-'
elif format.find('/') >= 0:
self.sep = '/'
elif format.find('.') >= 0:
self.sep = '.'
else:
self.sep = ''
# self.sep = format[2] # is this too presumptious?
self.calendar = Calendar()
self.img = Image(self.icon_img)
self.img.addStyleName(self.icon_style)
self.calendarLink = HyperlinkImage(self.img)
self.todayLink = Hyperlink(self.today_text)
self.todayLink.addStyleName(self.today_style)
#
# lay it out
#
hp = HorizontalPanel()
hp.setSpacing(2)
vp = VerticalPanel()
hp.add(self.tbox)
vp.add(self.calendarLink)
vp.add(self.todayLink)
#vp.add(self.calendar)
hp.add(vp)
Composite.__init__(self)
self.initWidget(hp)
#
# done with layout, so now set up some listeners
#
self.tbox.addFocusListener(self) # hook to onLostFocus
self.calendar.addSelectedDateListener(getattr(self, "onDateSelected"))
self.todayLink.addClickListener(getattr(self, "onTodayClicked"))
self.calendarLink.addClickListener(getattr(self, "onShowCalendar"))
self.tbox.addChangeListener(getattr(self, "onFieldChanged"))
self.tbox.addInputListener(getattr(self, "onFieldChanged"))
self._last_date = None
def emitSelectedDate(self):
_d = self.getDate()
if _d == self._last_date:
return
self._last_date = _d
self.fireDateSelectedEvent(_d)
def onFieldChanged(self, event):
self.emitSelectedDate()
def getTextBox(self):
return self.tbox
def getCalendar(self):
return self.calendar
def getDate(self):
""" returns datetime.date object or None if empty/unparsable by current format"""
_sdate = self.tbox.getText()
try:
return datetime.strptime(_sdate, self.format).date()
except ValueError:
return None
def setID(self, id):
self.tbox.setID(id)
def onDateSelected(self, yyyy, mm, dd):
secs = time.mktime((int(yyyy), int(mm), int(dd), 0, 0, 0, 0, 0, -1))
d = time.strftime(self.format, time.localtime(secs))
self.tbox.setText(d)
self.emitSelectedDate()
def onLostFocus(self, sender):
#
text = self.tbox.getText().strip()
# if blank - leave it alone
if text and len(text) == 8:
# ok what format do we have? assume ddmmyyyy --> dd-mm-yyyy
#.........这里部分代码省略.........
示例7: UserForm
# 需要导入模块: from pyjamas.ui.TextBox import TextBox [as 别名]
# 或者: from pyjamas.ui.TextBox.TextBox import addChangeListener [as 别名]
class UserForm(AbsolutePanel):
MODE_ADD = "modeAdd";
MODE_EDIT = "modeEdit";
user = None
mode = None
usernameInput = None
firstInput = None
lastInput = None
emailInput = None
passwordInput = None
confirmInput = None
departmentCombo = None
addBtn = None
cancelBtn = None
def __init__(self,parent):
AbsolutePanel.__init__(self)
ftable = FlexTable()
ftable.setWidget(0, 0, Label("First Name", wordWrap=False))
ftableFormatter = ftable.getFlexCellFormatter()
self.firstInput = TextBox()
self.firstInput.addChangeListener(self.checkValid)
self.firstInput.addKeyboardListener(self)
ftable.setWidget(0, 1, self.firstInput)
ftable.setWidget(1, 0, Label("Last Name", wordWrap=False))
self.lastInput = TextBox()
self.lastInput.addChangeListener(self.checkValid)
self.lastInput.addKeyboardListener(self)
ftable.setWidget(1, 1, self.lastInput)
ftable.setWidget(2, 0, Label("Email", wordWrap=False))
self.emailInput = TextBox()
self.emailInput.addChangeListener(self.checkValid)
self.emailInput.addKeyboardListener(self)
ftable.setWidget(2, 1, self.emailInput)
w = Label("* Username", wordWrap=False)
w.addMouseListener(TooltipListener("Required, not changable"))
ftable.setWidget(3, 0, w)
self.usernameInput = TextBox()
self.usernameInput.addChangeListener(self.checkValid)
self.usernameInput.addKeyboardListener(self)
ftable.setWidget(3, 1, self.usernameInput)
w = Label("* Password", wordWrap=False)
w.addMouseListener(TooltipListener("Required"))
ftable.setWidget(4, 0, w)
self.passwordInput = PasswordTextBox()
self.passwordInput.addChangeListener(self.checkValid)
self.passwordInput.addKeyboardListener(self)
ftable.setWidget(4, 1, self.passwordInput)
w = Label("* Confirm", wordWrap=False)
w.addMouseListener(TooltipListener("Required"))
ftable.setWidget(5, 0, w)
self.confirmInput = PasswordTextBox()
self.confirmInput.addChangeListener(self.checkValid)
self.confirmInput.addKeyboardListener(self)
ftable.setWidget(5, 1, self.confirmInput)
w = Label("* Department", wordWrap=False)
w.addMouseListener(TooltipListener("Required"))
ftable.setWidget(6, 0, w)
self.departmentCombo = ListBox()
self.departmentCombo.addChangeListener(self.checkValid)
self.departmentCombo.addKeyboardListener(self)
ftable.setWidget(6, 1, self.departmentCombo)
hpanel = HorizontalPanel()
self.addBtn = Button("Add User")
self.addBtn.setEnabled(False)
hpanel.add(self.addBtn)
self.cancelBtn = Button("Cancel")
hpanel.add(self.cancelBtn)
ftable.setWidget(7, 0, hpanel)
ftableFormatter.setColSpan(7, 0, 2)
self.add(ftable)
self.clearForm()
return
def clearForm(self):
self.user = None
self.usernameInput.setText('')
self.firstInput.setText('')
self.lastInput.setText('')
self.emailInput.setText('')
self.passwordInput.setText('')
self.confirmInput.setText('')
self.departmentCombo.setItemTextSelection(None)
self.updateMode(self.MODE_ADD)
self.checkValid()
def updateUser(self, user):
def setText(elem, value):
#.........这里部分代码省略.........
示例8: MechOptionPanel
# 需要导入模块: from pyjamas.ui.TextBox import TextBox [as 别名]
# 或者: from pyjamas.ui.TextBox.TextBox import addChangeListener [as 别名]
class MechOptionPanel(HorizontalPanel):
def __init__(self, handle, idx, checkOptions = [False, True]):
HorizontalPanel.__init__(self)
self.log = logging.getConsoleLogger(type(self).__name__, lev)
self.log.disabled = False
self.log.debug('__init__: Instantiation')
self.idx = idx
self._handle = handle
self._checkOptions = checkOptions
self.setStyleName('os-mech-checkbox-options')
#checkbox = CheckBox('symbol')
#checkbox.setChecked(checkOptions[0])
#checkbox.addClickListener(self.onClickOption)
#checkbox.setID('CBSY%d'%idx)
#self.append(checkbox)
#checkbox = CheckBox('value')
#checkbox.setChecked(checkOptions[1])
#checkbox.addClickListener(self.onClickOption)
#checkbox.setID('CBVA%d'%idx)
#self.append(checkbox)
self._textBoxRatio = TextBox('1:1')
self._ratioCache = self._textBoxRatio.getText()
self._textBoxRatio.setTitle('Ratio')
self._ratioCache = self._textBoxRatio.getText()
self._textBoxRatio.addChangeListener(self.onRatioChange)
self._textBoxRatio.setID('TXRT%d'%idx)
self._textBoxRatio.setStyleName('os-mech-textbox-ratio')
self._listBoxSize = ListBox()
self._listBoxSize.addChangeListener(self.onSizeSet)
self._listBoxSize.setVisibleItemCount(1)
self._listBoxSize.setStyleName('os-mech-listbox-size')
self._listBoxUnit = ListBox()
self._listBoxUnit.addChangeListener(self.onUnitSet)
self._listBoxUnit.setVisibleItemCount(1)
self._listBoxUnit.setStyleName('os-mech-listbox-unit')
self.append(Label('Ratio'))
self.append(self._textBoxRatio)
self.append(Label('Size'))
self.append(self._listBoxSize)
self.append(Label('Unit'))
self.append(self._listBoxUnit)
def onSizeSet(self, sender, event):
value = sender.getSelectedItemText()[0]
self.log.debug('Change size to %s'%value)
self._handle.remoteService.mech_options_set(self._handle._handle, self.idx, 'size', value)
def onUnitSet(self, sender, event):
value = sender.getSelectedValues()[0]
self._handle.remoteService.mech_options_set(self._handle._handle, self.idx, 'unit',int(value))
def onRatioChange(self, sender, event):
#validate ratio change
matches = re.findall(r'^\d{1,4}:\d{1,4}$', self._textBoxRatio.getText())
if len(matches) == 1: # correct
self._ratioCache = self._textBoxRatio.getText()
self._handle.remoteService.mech_options_set(self._handle._handle, self.idx, 'ratio', self._ratioCache)
else: # invalid
self._textBoxRatio.setText(self._ratioCache)
def actSizeFill(self, options, value = 0):
for idx, option in enumerate(options, idx):
self._listBoxSize.addItem(option, idx)
self._listBoxSize.setSelectedIndex(value)
def actUnitFill(self, options, value = 0):
for number, name in options.items():
self._listBoxUnit.addItem(name, number)
if value < 100000:
self._listBoxUnit.setSelectedIndex(value)
else:
self._listBoxUnit.selectValue(value)
def actSizeSet(self, value):
self.log.debug('actSizeSet, setting value %s'%value)
self._listBoxSize.selectValue(value)
def actRatioChange(self, ratio):
self._textBoxRatio.setText(ratio)
self._ratioCache = ratio
def onClickOption(self, sender, event):
sendId = int(sender.getID()[4:])
if sendId == 0:
self._checkOptions[0] = sender.isChecked()
self._checkOptions[1] = not(sender.isChecked())
else:
self._checkOptions[0] = not(sender.isChecked())
self._checkOptions[1] = sender.isChecked()
checkbox = self.getWidget(0)
checkbox.setChecked(self._checkOptions[0])
checkbox = self.getWidget(1)
checkbox.setChecked(self._checkOptions[1])
self._handle.remoteService.mech_options_set(self._handle._handle, self.idx, 'checkOptions', self._checkOptions)
示例9: GeocodingSimple
# 需要导入模块: from pyjamas.ui.TextBox import TextBox [as 别名]
# 或者: from pyjamas.ui.TextBox.TextBox import addChangeListener [as 别名]
class GeocodingSimple(DockPanel):
def __init__(self):
DockPanel.__init__(self)
self.setSize('100%', '100%')
self.geocoder = Geocoder()
# widgets
topPanel = HorizontalPanel()
self.add(topPanel, DockPanel.NORTH)
self.address = TextBox()
self.address.setText("Sydney, NSW")
self.address.addChangeListener(self.codeAddress)
topPanel.add(self.address)
button = Button("Geocode")
button.addClickListener(self.codeAddress)
topPanel.add(button)
# now, the map
mapPanel = SimplePanel()
mapPanel.setSize('600', '400')
self.add(mapPanel, DockPanel.CENTER)
options = MapOptions(zoom=8, center=LatLng(-34.397, 150.644),
mapTypeId=MapTypeId.ROADMAP)
self.map = Map(mapPanel.getElement(), options)
def codeAddress(self):
address = self.address.getText()
print "codeAddress ", address
if self.geocoder:
request = GeocoderRequest(address=address)
self.geocoder.geocode(request, self.geocodeResult)
def geocodeResult(self, results, status):
print "geocodeResult"
if status == GeocoderStatus.OK:
for res in results:
print res.formatted_address
print res.geometry.location.lat()
print res.geometry.location.lng()
for compo in res.address_components:
print "- " + compo.short_name
print ""
self.map.setCenter(results[0].geometry.location)
marker = Marker(MarkerOptions(map=self.map,
position=results[0].geometry.location))
else:
Window.alert(
"Geocode was not successful for the following reason: " +
status)