当前位置: 首页>>代码示例>>Python>>正文


Python ProxyEntry.is_valid方法代码示例

本文整理汇总了Python中kiwi.ui.widgets.entry.ProxyEntry.is_valid方法的典型用法代码示例。如果您正苦于以下问题:Python ProxyEntry.is_valid方法的具体用法?Python ProxyEntry.is_valid怎么用?Python ProxyEntry.is_valid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在kiwi.ui.widgets.entry.ProxyEntry的用法示例。


在下文中一共展示了ProxyEntry.is_valid方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: CalculatorPopup

# 需要导入模块: from kiwi.ui.widgets.entry import ProxyEntry [as 别名]
# 或者: from kiwi.ui.widgets.entry.ProxyEntry import is_valid [as 别名]

#.........这里部分代码省略.........
        else:
            self._warning.set_from_stock(Gtk.STOCK_DIALOG_WARNING,
                                         Gtk.IconSize.MENU)
            self._warning.set_tooltip_text(warning)
            self._warning.show()

    def _get_new_value(self):
        operation = self._entry.get_text().strip()
        operation = operation.replace(',', '.')

        if operation.endswith('%'):
            op_value = operation[:-1]
            percentage = True
        else:
            op_value = operation
            percentage = False

        if not operation:
            return

        if operation[0] in ['+', '-']:
            raise ValueError(_("Operator signals are not supported..."))

        if self._mode == self.MODE_SUB:
            op = operator.sub
        elif self._mode == self.MODE_ADD:
            op = operator.add

        try:
            op_value = decimal.Decimal(op_value)
        except decimal.InvalidOperation:
            raise ValueError(
                _("'%s' is not a valid operation...") % (operation,))

        if percentage:
            value = op(self._new_value, self._new_value * (op_value / 100))
        else:
            value = op(self._new_value, op_value)

        return value

    def _update_new_value(self):
        if not self._entry.is_valid():
            return

        self._new_value = self._get_new_value()
        self._entry.set_text('')
        self._preview_new_value()

    def _preview_new_value(self):
        self._label.set_markup('<b>%s</b>' % (
            self._converter.as_string(self._new_value), ))

    def _maybe_apply_new_value(self):
        if self._entry.get_text():
            self._update_new_value()
            return

        self.attached_widget.update(self._new_value)

        self.popdown()

    def _toggle_calculator_icon(self):
        if self.attached_widget.get_sensitive():
            icon = STOQ_CALC
        else:
            icon = None

        self.attached_widget.set_property(self._icon_pos + '-name', icon)

    #
    #  Callbacks
    #

    def _on_entry__validate(self, entry, value):
        try:
            value = self._get_new_value()
        except ValueError as err:
            return ValidationError('%s\n%s' % (err,
                                   _("Use absolute or percentage (%) value")))

        if value:
            warning = self.attached_widget.emit('validate', value)
            warning = warning and str(warning)
        else:
            warning = None

        self._set_warning(warning)

    def _after_entry__changed(self, entry):
        entry.validate(force=True)

    def _on_entry_sensitive__notify(self, obj, pspec):
        self._toggle_calculator_icon()

    def _on_entry__icon_press(self, entry, icon_pos, event):
        if icon_pos != Gtk.EntryIconPosition.SECONDARY:
            return

        self.popup()
开发者ID:hackedbellini,项目名称:stoq,代码行数:104,代码来源:calculator.py

示例2: CalculatorPopup

# 需要导入模块: from kiwi.ui.widgets.entry import ProxyEntry [as 别名]
# 或者: from kiwi.ui.widgets.entry.ProxyEntry import is_valid [as 别名]

#.........这里部分代码省略.........

        if operation.endswith('%'):
            op_value = operation[:-1]
            percentage = True
        else:
            op_value = operation
            percentage = False

        if not operation:
            return

        if operation[0] in ['+', '-']:
            raise ValueError(_("Operator signals are not supported..."))

        if self._mode == self.MODE_SUB:
            op = operator.sub
        elif self._mode == self.MODE_ADD:
            op = operator.add

        try:
            op_value = decimal.Decimal(op_value)
        except decimal.InvalidOperation:
            raise ValueError(
                _("'%s' is not a valid operation...") % (operation,))

        if percentage:
            value = op(self._new_value, self._new_value * (op_value / 100))
        else:
            value = op(self._new_value, op_value)

        return value

    def _update_new_value(self):
        if not self._entry.is_valid():
            return

        self._new_value = self._get_new_value()
        self._entry.set_text('')
        self._preview_new_value()

    def _preview_new_value(self):
        self._label.set_markup('<b>%s</b>' % (
            self._converter.as_string(self._new_value), ))

    def _maybe_apply_new_value(self):
        if self._entry.get_text():
            self._update_new_value()
            return

        self._popped_entry.update(self._new_value)

        self.popdown()

    def _toggle_calculator_icon(self):
        if self._popped_entry.get_sensitive():
            pixbuf = self.render_icon(STOQ_CALC, gtk.ICON_SIZE_MENU)
        else:
            pixbuf = None

        self._popped_entry.set_property(self._icon_pos + '-pixbuf', pixbuf)

    #
    #  Callbacks
    #

    def _on__key_press_event(self, window, event):
开发者ID:EasyDevSolutions,项目名称:stoq,代码行数:70,代码来源:calculator.py


注:本文中的kiwi.ui.widgets.entry.ProxyEntry.is_valid方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。