本文整理汇总了Python中pyjamas.ui.TextBox.TextBox.getWidth方法的典型用法代码示例。如果您正苦于以下问题:Python TextBox.getWidth方法的具体用法?Python TextBox.getWidth怎么用?Python TextBox.getWidth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyjamas.ui.TextBox.TextBox
的用法示例。
在下文中一共展示了TextBox.getWidth方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Spinner
# 需要导入模块: from pyjamas.ui.TextBox import TextBox [as 别名]
# 或者: from pyjamas.ui.TextBox.TextBox import getWidth [as 别名]
class Spinner(HorizontalPanel):
CHAR_WIDTH = 15
def __init__(self, minvalue=0, maxvalue=100, startvalue=10, interval=1, buttonStyleName=None, decrText='<',
incrText='>', **kwargs):
HorizontalPanel.__init__(self, **kwargs)
self.minvalue = minvalue
self.maxvalue = maxvalue
self.interval = interval
self.changeListeners = []
self.lessButton = Button(decrText, listener=self._onArrowClick, StyleName=buttonStyleName)
self.add(self.lessButton)
self.textbox = TextBox()
self.textbox.addInputListener(self._onTextboxInput)
self.add(self.textbox)
self.moreButton = Button(incrText, listener=self._onArrowClick, StyleName=buttonStyleName)
self.add(self.moreButton)
self.value = startvalue + 1
self.setValue(startvalue)
return
def _resizeTextbox(self):
width = max(2, len(self.textbox.getText())) * self.CHAR_WIDTH
if self.textbox.getWidth() != width:
self.textbox.setWidth(width)
def _onArrowClick(self, sender):
if sender == self.lessButton:
incr = -1 * self.interval
elif sender == self.moreButton:
incr = self.interval
else:
raise NotImplementedError()
val = self.getValue() + incr
self.setValue(val)
def _onTextboxInput(self, sender):
text = sender.getText()
try:
val = int(text)
except Exception:
return
self.setValue(val)
return
def addOnChangeListener(self, listener):
self.changeListeners.append(listener)
def removeOnChangeListener(self, listener):
self.changeListeners.remove(listener)
def getValue(self):
return self.value
def setValue(self, value):
fixedval = min(self.maxvalue, value)
fixedval = max(self.minvalue, fixedval)
if fixedval == self.value:
return
self.value = fixedval
self.textbox.setText(str(self.value))
self._resizeTextbox()
self.raiseOnChanged()
def raiseOnChanged(self):
for c in self.changeListeners:
c(self.value)