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


Python ProxyEntry.set_alignment方法代码示例

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


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

示例1: build_widget

# 需要导入模块: from kiwi.ui.widgets.entry import ProxyEntry [as 别名]
# 或者: from kiwi.ui.widgets.entry.ProxyEntry import set_alignment [as 别名]
    def build_widget(self):
        if self.editable:
            widget = ProxyEntry()
            if self.max_length != 0:
                widget.set_width_chars(self.max_length)
            if self.input_mask:
                widget.set_mask(self.input_mask)
        else:
            widget = ProxyLabel()
            # This label should be left aligned.
            widget.set_alignment(0, 0.5)

        return widget
开发者ID:hackedbellini,项目名称:kiwi,代码行数:15,代码来源:forms.py

示例2: CalculatorPopup

# 需要导入模块: from kiwi.ui.widgets.entry import ProxyEntry [as 别名]
# 或者: from kiwi.ui.widgets.entry.ProxyEntry import set_alignment [as 别名]
class CalculatorPopup(PopupWindow):
    """A popup calculator for entries

    Right now it supports both
    :class:`kiwi.ui.widgets.spinbutton.ProxySpinButton` and
    :class:`kiwi.ui.widgets.entry.ProxyEntry`, as long as their
    data types are numeric (e.g. int, currency, Decimal, etc)
    """

    #: The add mode. Any value typed on the entry will be added to the
    #: original value. e.g. 10% means +10%
    MODE_ADD = 0

    #: The sub mode. Any value typed on the entry will be subtracted from the
    #: original value. e.g. 10% means -10%
    MODE_SUB = 1

    _mode = None
    _data_type_mapper = {
        'currency': currency,
        'Decimal': decimal.Decimal,
    }

    def __init__(self, entry, mode):
        """
        :param entry: a :class:`kiwi.ui.widgets.spinbutton.ProxySpinButton`
            or a :class:`kiwi.ui.widgets.entry.ProxyEntry` subclass
        :param mode: one of :attr:`.MODE_ADD`, :attr:`.MODE_SUB`
        """
        self._mode = mode
        self._new_value = None
        self._data_type = self._data_type_mapper[entry.data_type]
        self._converter = converter.get_converter(self._data_type)

        super(CalculatorPopup, self).__init__(entry)

    #
    # Public API
    #

    def get_main_widget(self):
        # This is done on entry to check where to put the validation/mandatory
        # icons. We should put the calculator on the other side.
        # Note that spinbuttons are always right aligned and thus
        # xalign will always be 1.0
        if self.attached_widget.get_alignment() > 0.5:
            self._icon_pos = 'secondary-icon'
        else:
            self._icon_pos = 'primary-icon'

        self.attached_widget.set_property(self._icon_pos + '-activatable', True)
        self.attached_widget.set_property(
            self._icon_pos + '-tooltip-text',
            _("Do calculations on top of this value"))
        self.attached_widget.connect(
            'notify::sensitive', self._on_entry_sensitive__notify)
        self.attached_widget.connect('icon-press', self._on_entry__icon_press)
        self._toggle_calculator_icon()

        vbox = Gtk.VBox(spacing=6)
        vbox.show()

        self._main_label = Gtk.Label()
        self._main_label.set_ellipsize(Pango.EllipsizeMode.END)
        vbox.pack_start(self._main_label, True, True, 0)
        self._main_label.show()

        self._entry = ProxyEntry()
        # FIXME: We need a model_attribute here or else the entry.is_valid()
        # will always return None. Check proxywidget.py's FIXME to see why
        self._entry.model_attribute = 'not_used'
        self._entry.connect('validate', self._on_entry__validate)
        self._entry.connect_after('changed', self._after_entry__changed)
        self._entry.set_alignment(1.0)
        vbox.pack_start(self._entry, True, True, 0)
        self._entry.show()

        hbox = Gtk.HBox(spacing=6)
        vbox.pack_start(hbox, True, True, 0)
        hbox.show()

        self._label = Gtk.Label()
        self._label.set_property('xalign', 1.0)
        self._label.set_use_markup(True)
        hbox.pack_start(self._label, True, True, 0)
        self._label.show()

        self._warning = Gtk.Image()
        hbox.pack_start(self._warning, False, False, 0)

        return vbox

    def validate_popup(self):
        try:
            self._new_value = self._data_type(self.attached_widget.get_text())
        except decimal.InvalidOperation:
            return False

        self._entry.set_text('')
        self._entry.set_tooltip_text(_("Use absolute or percentage (%) value"))
#.........这里部分代码省略.........
开发者ID:hackedbellini,项目名称:stoq,代码行数:103,代码来源:calculator.py

示例3: CalculatorPopup

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

#.........这里部分代码省略.........
        self._popped_entry.set_property(self._icon_pos + '-tooltip-text',
                                        _("Do calculations on top of this value"))
        self._popped_entry.connect('notify::sensitive',
                                   self._on_popped_entry_sensitive__notify)
        self._popped_entry.connect('icon-press',
                                   self._on_popped_entry__icon_press)
        self._toggle_calculator_icon()

        frame = gtk.Frame()
        frame.set_shadow_type(gtk.SHADOW_ETCHED_OUT)
        self.add(frame)
        frame.show()

        alignment = gtk.Alignment(0.5, 0.5, 1.0, 1.0)
        alignment.set_padding(6, 6, 2, 2)
        frame.add(alignment)
        alignment.show()

        vbox = gtk.VBox(spacing=6)
        alignment.add(vbox)
        vbox.show()

        self._main_label = gtk.Label()
        self._main_label.set_ellipsize(pango.ELLIPSIZE_END)
        vbox.pack_start(self._main_label, True, True)
        self._main_label.show()

        self._entry = ProxyEntry()
        # FIXME: We need a model_attribute here or else the entry.is_valid()
        # will always return None. Check proxywidget.py's FIXME to see why
        self._entry.model_attribute = 'not_used'
        self._entry.connect('validate', self._on_entry__validate)
        self._entry.connect_after('changed', self._after_entry__changed)
        self._entry.set_alignment(1.0)
        vbox.pack_start(self._entry, True, True)
        self._entry.show()

        hbox = gtk.HBox(spacing=6)
        vbox.pack_start(hbox, True, True)
        hbox.show()

        self._label = gtk.Label()
        self._label.set_property('xalign', 1.0)
        self._label.set_use_markup(True)
        hbox.pack_start(self._label, True, True)
        self._label.show()

        self._warning = gtk.Image()
        hbox.pack_start(self._warning, False, False)

        self.set_resizable(False)
        self.set_screen(self._popped_entry.get_screen())

    def _update_ui(self):
        self._new_value = self._data_type(self._popped_entry.get_text())
        self._entry.set_text('')
        self._entry.set_tooltip_text(_("Use absolute or percentage (%) value"))
        self._preview_new_value()
        self._main_label.set_text(self._get_main_label())

    def _get_main_label(self):
        if self._mode == self.MODE_ADD:
            return (_("Surcharge") if self._data_type == currency else
                    _("Addition"))
        elif self._mode == self.MODE_SUB:
            return (_("Discount") if self._data_type == currency else
开发者ID:EasyDevSolutions,项目名称:stoq,代码行数:70,代码来源:calculator.py


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