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


Python ProxyEntry.set_position方法代码示例

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


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

示例1: EditorPropertyName

# 需要导入模块: from kiwi.ui.widgets.entry import ProxyEntry [as 别名]
# 或者: from kiwi.ui.widgets.entry.ProxyEntry import set_position [as 别名]
class EditorPropertyName(EditorProperty):

    duplicate_name_msg = _("There is already a widget with this name")
    no_name_msg = _("The widget must have a name")

    def __init__(self, property_class, app):
        EditorProperty.__init__(self, property_class, app)

        self.input = ProxyEntry()
        self.input.set_property('data-type', str)
        self.input.connect('changed', self._changed_text)

    def load(self, widget):
        self._start_load(widget)
        self._internal_load(widget)
        self._finish_load()

    def _internal_load(self, widget):
        value = self.property.value
        pos = self.input.get_position()
        self.input.delete_text(0, -1)
        if value:
            self.input.insert_text(value)

        self.input.set_position(pos)

        # validate that the name exists and is unique
        if not value:
            self.input.set_invalid(self.no_name_msg)
        elif self._project.get_gadget_by_name(value) != widget:
            self.input.set_invalid(self.duplicate_name_msg)
        else:
            self.input.set_valid()

    def _changed_text(self, entry):
        """
        Update the name property of the widget if the name is valid.
        """
        if self.property_loading:
            return

        name = entry.get_chars(0, -1)
        if not name:
            self.input.set_invalid(self.no_name_msg)
        elif self._project.get_gadget_by_name(name):
            self.input.set_invalid(self.duplicate_name_msg)
        else:
            self.input.set_valid()
            self.set(name)
开发者ID:dsaran,项目名称:packagehelper,代码行数:51,代码来源:propertyeditor.py

示例2: DateEntry

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

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

    # Callbacks

    def _on_entry__changed(self, entry):
        try:
            date = self.get_date()
        except ValidationError:
            date = None
        self._changed(date)

    def _on_entry__activate(self, entry):
        self.emit('activate')

    def _on_entry__scroll_event(self, entry, event):
        if event.direction == Gdk.ScrollDirection.UP:
            days = 1
        elif event.direction == Gdk.ScrollDirection.DOWN:
            days = -1
        else:
            return

        try:
            date = self.get_date()
        except ValidationError:
            date = None

        if not date:
            newdate = datetime.date.today()
        else:
            newdate = date + datetime.timedelta(days=days)
        self.set_date(newdate)

    def _on_button__toggled(self, button):
        if self._popping_down:
            return

        try:
            date = self.get_date()
        except ValidationError:
            date = None

        self._popup.popup(date)

    def _on_popup__hide(self, popup):
        self._popping_down = True
        self._button.set_active(False)
        self._popping_down = False

    def _on_popup__date_selected(self, popup, date):
        self.set_date(date)
        popup.popdown()
        self.entry.grab_focus()
        self.entry.set_position(len(self.entry.get_text()))
        self._changed(date)

    def _changed(self, date):
        if self._block_changed:
            return
        if self._old_date != date:
            self.emit('changed')
            self._old_date = date

    # Public API

    def set_date(self, date):
        """Sets the date.
        :param date: date to set
        :type date: a datetime.date instance or None
        """
        if not isinstance(date, datetime.date) and date not in [None, ValueUnset]:
            raise TypeError(
                "date must be a datetime.date instance or None, not %r" % (
                    date,))

        if date in [None, ValueUnset]:
            value = ''
        else:
            value = date_converter.as_string(date)

        # We're block the changed call and doing it manually because
        # set_text() triggers a delete-text and then an insert-text,
        # both which are emitting an entry::changed signal
        self._block_changed = True
        self.entry.set_text(value)
        self._block_changed = False

        self._changed(date)

    def get_date(self):
        """Get the selected date
        :returns: the date.
        :rtype: datetime.date or None
        """
        try:
            date = self.entry.read()
        except ValidationError:
            date = None
        if date == ValueUnset:
            date = None
        return date
开发者ID:hackedbellini,项目名称:kiwi,代码行数:104,代码来源:dateentry.py

示例3: DateEntry

# 需要导入模块: from kiwi.ui.widgets.entry import ProxyEntry [as 别名]
# 或者: from kiwi.ui.widgets.entry.ProxyEntry import set_position [as 别名]
class DateEntry(gtk.HBox):
    """I am an entry which you can input a date on.
    In addition to an gtk.Entry I also contain a button
    with an arrow you can click to get popup window with a gtk.Calendar
    for which you can use to select the date
    """
    gsignal('changed')
    gsignal('activate')
    def __init__(self):
        gtk.HBox.__init__(self)

        self._popping_down = False
        self._old_date = None

        # bootstrap problems, kiwi.ui.widgets.entry imports dateentry
        # we need to use a proxy entry because we want the mask
        from kiwi.ui.widgets.entry import ProxyEntry
        self.entry = ProxyEntry()
        self.entry.connect('changed', self._on_entry__changed)
        self.entry.connect('activate', self._on_entry__activate)
        self.entry.set_property('data-type', datetime.date)
        mask = self.entry.get_mask()
        if mask:
            self.entry.set_width_chars(len(mask))
        self.pack_start(self.entry, False, False)
        self.entry.show()

        self._button = gtk.ToggleButton()
        self._button.connect('scroll-event', self._on_entry__scroll_event)
        self._button.connect('toggled', self._on_button__toggled)
        self._button.set_focus_on_click(False)
        self.pack_start(self._button, False, False)
        self._button.show()

        arrow = gtk.Arrow(gtk.ARROW_DOWN, gtk.SHADOW_NONE)
        self._button.add(arrow)
        arrow.show()

        self._popup = _DateEntryPopup(self)
        self._popup.connect('date-selected', self._on_popup__date_selected)
        self._popup.connect('hide', self._on_popup__hide)
        self._popup.set_size_request(-1, 24)

    # Virtual methods

    def do_grab_focus(self):
        self.entry.grab_focus()

    # Callbacks

    def _on_entry__changed(self, entry):
        try:
            date = self.get_date()
        except ValidationError:
            date = None
        self._changed(date)

    def _on_entry__activate(self, entry):
        self.emit('activate')

    def _on_entry__scroll_event(self, entry, event):
        if event.direction == gdk.SCROLL_UP:
            days = 1
        elif event.direction == gdk.SCROLL_DOWN:
            days = -1
        else:
            return

        try:
            date = self.get_date()
        except ValidationError:
            date = None

        if not date:
            newdate = datetime.date.today()
        else:
            newdate = date + datetime.timedelta(days=days)
        self.set_date(newdate)

    def _on_button__toggled(self, button):
        if self._popping_down:
            return

        try:
            date = self.get_date()
        except ValidationError:
            date = None

        self._popup.popup(date)

    def _on_popup__hide(self, popup):
        self._popping_down = True
        self._button.set_active(False)
        self._popping_down = False

    def _on_popup__date_selected(self, popup, date):
        self.set_date(date)
        popup.popdown()
        self.entry.grab_focus()
        self.entry.set_position(len(self.entry.get_text()))
#.........这里部分代码省略.........
开发者ID:Schevo,项目名称:kiwi,代码行数:103,代码来源:dateentry.py


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