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


Python Edit.keypress方法代码示例

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


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

示例1: TextEditor

# 需要导入模块: from urwid import Edit [as 别名]
# 或者: from urwid.Edit import keypress [as 别名]
class TextEditor(WidgetWrap):
    """Editor for creating arbitrary text."""

    __metaclass__ = signals.MetaSignals
    signals = ['done']

    def __init__(self, 
                 prompt, 
                 content, 
                 done_signal_handler):
        if content:
            content += ' '
        self.editor = Edit(u'%s (twice enter key to validate or esc) \n>> ' % prompt, content)

        widgets = [self.editor]
        w = AttrMap(Columns(widgets), 'editor')

        connect_signal(self, 'done', done_signal_handler)

        self.__super.__init__(w)

    def keypress(self, size, key):
        if key == 'enter' and self.last_key == 'enter':
            self.emit_done_signal(self.editor.get_edit_text())
            return
        elif key == 'esc':
            self.emit_done_signal()
            return

        self.last_key = key
        size = size,
        self.editor.keypress(size, key)

    def emit_done_signal(self, content=None):
        emit_signal(self, 'done', content)
开发者ID:gigigi,项目名称:turses,代码行数:37,代码来源:ui.py

示例2: BaseEditor

# 需要导入模块: from urwid import Edit [as 别名]
# 或者: from urwid.Edit import keypress [as 别名]
class BaseEditor(WidgetWrap):
    """Base class for editors."""

    __metaclass__ = signals.MetaSignals
    signals = ["done"]

    def __init__(self, prompt, content, done_signal_handler, cursor_position=None):
        """
        Initializes editor, connects 'done' signal.

        When pressing 'enter' twice the `submit` method is called, which by
        default calls `emit_done_signal` with the text that has been
        introduced.

        When pressing 'esc' the `cancel` method is called, which by default
        calls `emit_done_signal` with no arguments.

        The subclasses must call the `_wrap` method with the editor widgets
        and `BaseEditor` will wrap it in a `urwid.Colums` widget, calling to
        `urwid.WidgetWrap.__init__` with the wrapped widget.
        """
        caption = _(u"%s (twice enter key to validate or esc) \n>> ") % prompt
        if content:
            content += " "
        self.content = content
        self.editor = Edit(caption=caption, edit_text=content, edit_pos=cursor_position)
        self.last_key = None

        connect_signal(self, "done", done_signal_handler)

    def _wrap(self, widgets):
        widgets = widgets if isinstance(widgets, list) else [widgets]
        composed_widget = Columns(widgets)

        widget = AttrMap(LineBox(composed_widget), "editor")
        WidgetWrap.__init__(self, widget)

    def keypress(self, size, key):
        if key == "enter" and self.last_key == "enter":
            self.submit()
            return
        elif key == "esc":
            self.cancel()
            return

        self.last_key = key
        size = (size,)
        self.editor.keypress(size, key)

    def submit(self):
        self.emit_done_signal(self.editor.get_edit_text())

    def cancel(self):
        self.emit_done_signal()

    def emit_done_signal(self, content=None):
        emit_signal(self, "done", content)
开发者ID:ivanov,项目名称:turses,代码行数:59,代码来源:ui.py

示例3: TweetEditor

# 需要导入模块: from urwid import Edit [as 别名]
# 或者: from urwid.Edit import keypress [as 别名]
class TweetEditor(WidgetWrap):
    """Editor for creating tweets."""

    __metaclass__ = signals.MetaSignals
    signals = ['done']

    def __init__(self, 
                 prompt, 
                 content, 
                 done_signal_handler):
        if content:
            content += ' '
        self.editor = Edit(u'%s (twice enter key to validate or esc) \n>> ' % prompt, content)

        self.counter = len(content)
        self.counter_widget = Text(str(self.counter))

        widgets = [('fixed', 4, self.counter_widget), self.editor]
        w = AttrMap(Columns(widgets), 'editor')

        connect_signal(self, 'done', done_signal_handler)
        connect_signal(self.editor, 'change', self.update_counter)

        self.__super.__init__(w)

    def update_counter(self, edit, new_edit_text):
        self.counter = len(new_edit_text)
        self.counter_widget.set_text(str(self.counter))

    def keypress(self, size, key):
        if key == 'enter' and self.last_key == 'enter':
            if self.counter > TWEET_MAX_CHARS:
                return
            else:
                self.emit_done_signal(self.editor.get_edit_text())
        elif key == 'esc':
            self.emit_done_signal()
            return

        self.last_key = key
        size = size,
        self.editor.keypress(size, key)

    def emit_done_signal(self, content=None):
        emit_signal(self, 'done', content)
开发者ID:gigigi,项目名称:turses,代码行数:47,代码来源:ui.py

示例4: keypress

# 需要导入模块: from urwid import Edit [as 别名]
# 或者: from urwid.Edit import keypress [as 别名]
 def keypress(self, size, key):
     if key == 'enter':
         self._top[1]()
         self._done(self.get_edit_text())
     elif key == 'esc':
         self._top[1]()
     elif key == 'tab' and self._tab:
         text = self.get_edit_text()[:self.edit_pos]
         text_len = len(text)
         match = None
         for entry in self._tab(text):
             if entry.startswith(text):
                 entry = entry[text_len:]
                 if match is None:
                     match = entry
                 else:
                     while not entry.startswith(match):
                         match = match[:-1]
         if match:
             self.insert_text(match)
     else:
         return Edit.keypress(self, size, key)
开发者ID:foreni-packages,项目名称:hachoir-urwid,代码行数:24,代码来源:urwid_ui.py

示例5: BaseEditor

# 需要导入模块: from urwid import Edit [as 别名]
# 或者: from urwid.Edit import keypress [as 别名]
class BaseEditor(with_metaclass(signals.MetaSignals, WidgetWrap)):
    """Base class for editors."""
    signals = ['done']

    def __init__(self,
                 prompt,
                 content,
                 done_signal_handler,
                 cursor_position=None):
        """
        Initializes editor, connects 'done' signal.

        When pressing 'enter' twice the `submit` method is called, which by
        default calls `emit_done_signal` with the text that has been
        introduced.

        When pressing 'esc' the `cancel` method is called, which by default
        calls `emit_done_signal` with no arguments.

        The subclasses must call the `_wrap` method with the editor widgets
        and `BaseEditor` will wrap it in a `urwid.Colums` widget, calling to
        `urwid.WidgetWrap.__init__` with the wrapped widget.
        """
        caption = _(u'{0} (Enter key twice to validate, '
                    u'Esc or Ctrl-C to cancel) \n>> ').format(prompt)
        if content:
            content += ' '
        self.content = content
        self.editor = Edit(caption=caption,
                           edit_text=content,
                           edit_pos=cursor_position)
        self.last_key = None

        connect_signal(self, 'done', done_signal_handler)

    def _wrap(self, widgets):
        widgets = widgets if isinstance(widgets, list) else [widgets]
        composed_widget = Columns(widgets)

        widget = AttrMap(LineBox(composed_widget), 'editor')
        super(BaseEditor, self).__init__(widget)

    def keypress(self, size, key):
        if key == 'enter' and self.last_key == 'enter':
            self.submit()
            return
        elif key == 'esc':
            self.cancel()
            return

        self.last_key = key
        size = size,
        self.editor.keypress(size, key)

    def submit(self):
        self.emit_done_signal(self.editor.get_edit_text())

    def cancel(self):
        self.emit_done_signal()

    def emit_done_signal(self, content=None):
        emit_signal(self, 'done', content)
开发者ID:ripperbone,项目名称:turses,代码行数:64,代码来源:ui.py


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