本文整理汇总了Python中pyjamas.ui.TextBox.TextBox.setID方法的典型用法代码示例。如果您正苦于以下问题:Python TextBox.setID方法的具体用法?Python TextBox.setID怎么用?Python TextBox.setID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyjamas.ui.TextBox.TextBox
的用法示例。
在下文中一共展示了TextBox.setID方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DateField
# 需要导入模块: from pyjamas.ui.TextBox import TextBox [as 别名]
# 或者: from pyjamas.ui.TextBox.TextBox import setID [as 别名]
class DateField(Composite):
icon_img = "icon_calendar.gif"
icon_style = "calendar-img"
today_text = "Today"
today_style = "calendar-today-link"
def __init__(self, format='%d-%m-%Y'):
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"))
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)
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
txt = text[0:2] + self.sep + text[2:4] + self.sep + text[4:8]
self.tbox.setText(txt)
def onFocus(self, sender):
pass
def onTodayClicked(self, event):
today = time.strftime(self.format)
self.tbox.setText(today)
def onShowCalendar(self, sender):
txt = self.tbox.getText().strip()
try:
if txt:
_d = datetime.strptime(txt,self.format).date()
self.calendar.setDate(_d)
except ValueError: pass
p = CalendarPopup(self.calendar)
x = self.tbox.getAbsoluteLeft() + 10
y = self.tbox.getAbsoluteTop() + 10
p.setPopupPosition(x, y)
p.show()
示例2: MechOptionPanel
# 需要导入模块: from pyjamas.ui.TextBox import TextBox [as 别名]
# 或者: from pyjamas.ui.TextBox.TextBox import setID [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)