pygtk - spinbutton:输出信号
我在应用程序中使用旋转按钮让用户选择 -1 到 100 之间的数字。在我的应用程序中 -1 表示无穷大。因此,如果用户选择值 -1,我想显示文本“Infinity”。这是我的代码:
def spin_output(spin):
digits = int(spin.props.digits)
value = spin.props.value
if value < 0:
spin.props.text = "Infinity" # u"\u221E"
else:
spin.props.text = '{0:.{1}f}'.format(value, digits)
return True
self.my_spin.connect('output', spin_output)
当选择“Infinity”值并且用户按下“向上”按钮时,该值更改为 100 而不是 0。 当我用 u"\u221E" 替换“Infinity”并且用户在选择它时按下“向上”按钮时,该值更改为 1。
我想要的是,用户可以按该顺序选择值:Infinity , 0, 1, ... 我的错误是什么?
我认为当用户更改值时,只有底层调整发生变化,而我的函数仅用于显示当前值。
I use a spinbutton in my application to let the user choose a number between -1 and 100. In my application -1 means Infinity. So I want to show the text "Infinity", if the user selects the value -1. This is my code:
def spin_output(spin):
digits = int(spin.props.digits)
value = spin.props.value
if value < 0:
spin.props.text = "Infinity" # u"\u221E"
else:
spin.props.text = '{0:.{1}f}'.format(value, digits)
return True
self.my_spin.connect('output', spin_output)
When the "Infinity"-value is selected and the user presses the "up"-button the value changes to 100 instead of 0.
When i replace "Infinity" with u"\u221E" and the user presses the "up"-button while it is selected, the value changes to 1.
What I want is, that the user can select the values in that order: Infinity, 0, 1, ...
What is my mistake?
I thought that only the underlying adjustment is changed when the user changes the value and my function is only used to show the current value.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
发生的情况是旋转按钮将字符串“infinity”解释为用户输入的字符串,并尝试将其解析为值。
gtk.Scale
小部件提供了一个名为format-value
的信号,用于显示自定义值,就像您尝试做的那样,但我没有看到类似的信号旋转按钮的信号。这是使用可以满足您要求的比例的东西:
What's happening is that the spin button is interpreting the string "infinity" as a string entered by the user, and trying to parse it as a value. The
gtk.Scale
widgets offer a signal calledformat-value
which is used to display custom values just like you're trying to do, but I don't see a similar signal for the spin button.Here is something using a scale that might do what you want:
好的,我找到了解决方案。我为输出信号处理程序编写了对应的内容...输入信号处理程序:-)
这似乎工作得很好;-)
Ok, i found a solution. I wrote the counterpart for the output-signal-handler ... the input-signal-handler :-)
This seems to work well ;-)