• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python urwid.Edit类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: FilterBox

class FilterBox(WidgetWrap):

    def __init__(self, edit_changed_cb, label="", info_text=""):
        self.label = Text(label)
        self.info_text = Text(info_text)
        self.editbox = Edit(caption=('text', "Filter: "))
        connect_signal(self.editbox, 'change',
                       edit_changed_cb)

        w = Pile([Columns([AttrMap(self.editbox,
                                   'filter', 'filter_focus')])
                  # self.info_text  # -- WORKAROUND for issue #194
                  ])
        super().__init__(w)

    def set_info(self, n_showing, n_total):
        m = ["Filter ", ('label', "({} of {} shown): ".format(n_showing,
                                                              n_total))]
        self.editbox.set_caption(m)
        if False:   # WORKAROUND for issue #194
            t = ''
        else:
            t = ('label',
                 "  Filter on hostname or hardware info like 'cores:4'")
        self.info_text.set_text(t)
开发者ID:Ubuntu-Solutions-Engineering,项目名称:bundle-placement,代码行数:25,代码来源:filter_box.py


示例2: TextEditor

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,代码行数:35,代码来源:ui.py


示例3: LockScreen

class LockScreen(Overlay):
    LOCKED = "The screen is locked. Please enter a password (this is the " \
             "password you entered for OpenStack during installation). "

    INVALID = ("error", "Invalid password.")

    IOERROR = ("error", "Problem accessing {pwd}. Please make sure "
               "it contains exactly one line that is the lock "
               "password.".format(pwd=pegasus.PASSWORD_FILE))

    def __init__(self, underlying, unlock):
        self.unlock = unlock
        self.password = Edit("Password: ", mask='*')
        self.invalid = Text("")
        w = ListBox([Text(self.LOCKED), self.invalid,
                     self.password])
        w = LineBox(w)
        w = AttrWrap(w, "dialog")
        Overlay.__init__(self, w, underlying, 'center', 60, 'middle', 8)

    def keypress(self, size, key):
        if key == 'enter':
            if pegasus.OPENSTACK_PASSWORD is None:
                self.invalid.set_text(self.IOERROR)
            elif pegasus.OPENSTACK_PASSWORD == self.password.get_edit_text():
                self.unlock()
            else:
                self.invalid.set_text(self.INVALID)
                self.password.set_edit_text("")
        else:
            return Overlay.keypress(self, size, key)
开发者ID:BoydYang,项目名称:cloud-installer,代码行数:31,代码来源:gui.py


示例4: BaseEditor

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,代码行数:57,代码来源:ui.py


示例5: StringEditor

class StringEditor(WidgetWrap):
    """ Edit input class
    Initializes and Edit object and attachs its result
    to the `value` accessor.
    """
    def __init__(self, caption=None, default=None, **kwargs):
        if caption is None:
            caption = ""
        self._edit = Edit(caption=caption, **kwargs)
        if default is not None:
            self._edit.set_edit_text(default)
        self.error = None
        super().__init__(self._edit)

    def keypress(self, size, key):
        if self.error:
            self._edit.set_edit_text("")
            self.error = None
        return super().keypress(size, key)

    def set_error(self, msg):
        self.error = msg
        return self._edit.set_edit_text(msg)

    @property
    def value(self):
        if self._edit.get_edit_text() == "":
            return None
        return self._edit.get_edit_text()

    @value.setter  # NOQA
    def value(self, value):
        self._edit.set_edit_text(value)
开发者ID:Ubuntu-Solutions-Engineering,项目名称:bundle-placement,代码行数:33,代码来源:input.py


示例6: create_interface

    def create_interface(self):
        self.screen = Screen()
        self.screen.start()

        self.screen.register_palette([
            ("title", "white", "dark blue", "standout"),
            ("line", "light gray", "black"),
            ("help", "white", "dark blue")]
        )

        self.body = ListBox(SimpleListWalker([]))
        self.lines = self.body.body

        self.title = Text(MAIN_TITLE)
        self.header = AttrWrap(self.title, "title")

        self.help = AttrWrap(
            Text(HELP_STRINGS["main"]),
            "help"
        )

        self.input = Edit(caption="%s> " % self.ircchannel)
        self.footer = Pile([self.help, self.input])

        self.top = Frame(self.body, self.header, self.footer)
开发者ID:spaceone,项目名称:circuits,代码行数:25,代码来源:circ.py


示例7: __init__

    def __init__(self, choice_callback=None,
                       command_callback=None,
                       help_callback=None):

        self.palette = [
                ('brick', 'light red', 'black'),
                ('rubble', 'yellow', 'black'),
                ('wood', 'light green', 'black'),
                ('concrete', 'white', 'black'),
                ('stone', 'light cyan', 'black'),
                ('marble', 'light magenta', 'black'),
                ('jack', 'dark gray', 'white'),
                ('msg_info', 'white', 'black'),
                ('msg_err', 'light red', 'black'),
                ('msg_debug', 'light green', 'black'),
                ]

        self.choice_callback = choice_callback
        self.command_callback = command_callback
        self.help_callback = help_callback

        self.screen = None
        self.loop = None
        self.called_loop_stop = False
        self.reactor_stop_fired = False

        self.quit_flag = False
        self.edit_msg = "Make selection ('q' to quit): "
        self.roll_list = SimpleListWalker([])
        self.game_log_list = SimpleListWalker([])
        self.choices_list = SimpleListWalker([])

        self.state_text = SimpleListWalker([Text('Connecting...')])

        self.edit_widget = Edit(self.edit_msg)
        self.roll = ListBox(self.roll_list)
        self.game_log = ListBox(self.game_log_list)
        self.choices = ListBox(self.choices_list)
        self.state = ListBox(self.state_text)

        self.left_frame = Pile([
                LineBox(self.state),
                (13, LineBox(self.choices)),
                ])

        self.right_frame = Pile([
                LineBox(self.game_log),
                LineBox(self.roll)
                ])

        self.state.set_focus(len(self.state_text)-1)

        self.columns = Columns([('weight', 0.75, self.left_frame),
                                ('weight', 0.25, self.right_frame)
                                ])
        self.frame_widget = Frame(footer=self.edit_widget,
                                  body=self.columns,
                                  focus_part='footer')

        self.exc_info = None
开发者ID:comat0se,项目名称:cloaca,代码行数:60,代码来源:curses_gui.py


示例8: __init__

    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)
开发者ID:Erik-k,项目名称:turses,代码行数:30,代码来源:ui.py


示例9: __init__

 def __init__(self, caption=None, default=None, **kwargs):
     if caption is None:
         caption = ""
     self._edit = Edit(caption=caption, **kwargs)
     if default is not None:
         self._edit.set_edit_text(default)
     self.error = None
     super().__init__(self._edit)
开发者ID:Ubuntu-Solutions-Engineering,项目名称:bundle-placement,代码行数:8,代码来源:input.py


示例10: TweetEditor

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,代码行数:45,代码来源:ui.py


示例11: __init__

 def __init__(self, underlying, unlock):
     self.unlock = unlock
     self.password = Edit("Password: ", mask='*')
     self.invalid = Text("")
     w = ListBox([Text(self.LOCKED), self.invalid,
                  self.password])
     w = LineBox(w)
     w = AttrWrap(w, "dialog")
     Overlay.__init__(self, w, underlying, 'center', 60, 'middle', 8)
开发者ID:BoydYang,项目名称:cloud-installer,代码行数:9,代码来源:gui.py


示例12: __init__

    def __init__(self, edit_changed_cb, label="", info_text=""):
        self.label = Text(label)
        self.info_text = Text(info_text)
        self.editbox = Edit(caption=('text', "Filter: "))
        connect_signal(self.editbox, 'change',
                       edit_changed_cb)

        w = Pile([Columns([AttrMap(self.editbox,
                                   'filter', 'filter_focus')])
                  # self.info_text  # -- WORKAROUND for issue #194
                  ])
        super().__init__(w)
开发者ID:Ubuntu-Solutions-Engineering,项目名称:bundle-placement,代码行数:12,代码来源:filter_box.py


示例13: __init__

    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)
开发者ID:gigigi,项目名称:turses,代码行数:14,代码来源:ui.py


示例14: EditInput

class EditInput(WidgetWrap):

    """ Edit input class

    Initializes an Edit object and attaches its result to
    the `value` accessor.
    """

    def __init__(self, caption, **kwargs):
        self._edit = Edit(caption=caption, **kwargs)
        super().__init__(self._edit)

    @property
    def value(self):
        """ Returns text of input
        """
        return self._edit.get_edit_text()
开发者ID:JamesGuthrie,项目名称:openstack-installer,代码行数:17,代码来源:input.py


示例15: keypress

 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,代码行数:22,代码来源:urwid_ui.py


示例16: _create_login_widget

    def _create_login_widget(self):
        self.username_entry = Edit(align='right')
        self.username_entry.keypress = self._username_keypress
        self.password_entry = Password(align='right')
        self.password_entry.keypress = self._password_keypress

        username_row = Columns([
            ('fixed', 10, Text("Usuario:", align='right')),
            ('fixed', 10, self.username_entry),
        ])

        password_row = Columns([
            ('fixed', 10, Text("Clave:", align='right')),
            ('fixed', 10, self.password_entry),
        ])

        self.pile = Pile([
            username_row,
            Divider(),
            password_row,
        ], focus_item=0)

        self.login_widget = Filler(Columns([Divider(), self.pile, Divider()]))
开发者ID:coyotevz,项目名称:Nobix-ng,代码行数:23,代码来源:login.py


示例17: move_cursor_to_coords

 def move_cursor_to_coords(self, size, x, y):
     if self._end:
         x = "right"
         self._end = False
     return Edit.move_cursor_to_coords(self, size, x, y)
开发者ID:foreni-packages,项目名称:hachoir-urwid,代码行数:5,代码来源:urwid_ui.py


示例18: __init__

 def __init__(self, caption, **kwargs):
     self._edit = Edit(caption=caption, **kwargs)
     super().__init__(Color.string_input(self._edit,
                                         focus_map="string_input focus"))
开发者ID:kavinsivak,项目名称:openstack-installer,代码行数:4,代码来源:input.py


示例19: Client

class Client(Component):

    channel = "client"

    def init(self, host, port=6667, opts=None):
        self.host = host
        self.port = port
        self.opts = opts
        self.hostname = gethostname()

        self.nick = opts.nick
        self.ircchannel = opts.channel

        # Add TCPClient and IRC to the system.
        TCPClient(channel=self.channel).register(self)
        IRC(channel=self.channel).register(self)

        self.create_interface()

    def create_interface(self):
        self.screen = Screen()
        self.screen.start()

        self.screen.register_palette([
            ("title", "white", "dark blue", "standout"),
            ("line", "light gray", "black"),
            ("help", "white", "dark blue")]
        )

        self.body = ListBox(SimpleListWalker([]))
        self.lines = self.body.body

        self.title = Text(MAIN_TITLE)
        self.header = AttrWrap(self.title, "title")

        self.help = AttrWrap(
            Text(HELP_STRINGS["main"]),
            "help"
        )

        self.input = Edit(caption="%s> " % self.ircchannel)
        self.footer = Pile([self.help, self.input])

        self.top = Frame(self.body, self.header, self.footer)

    def ready(self, component):
        """Ready Event

        This event is triggered by the underlying ``TCPClient`` Component
        when it is ready to start making a new connection.
        """

        self.fire(connect(self.host, self.port))

    def connected(self, host, port):
        """connected Event

        This event is triggered by the underlying ``TCPClient`` Component
        when a successfully connection has been made.
        """

        nick = self.nick
        hostname = self.hostname
        name = "%s on %s using circuits/%s" % (nick, hostname, systemVersion)

        self.fire(NICK(nick))
        self.fire(USER(nick, hostname, host, name))

    def numeric(self, source, numeric, *args):
        """Numeric Event

        This event is triggered by the ``IRC`` Protocol Component when we have
        received an IRC Numberic Event from server we are connected to.
        """

        if numeric == ERR_NICKNAMEINUSE:
            self.fire(NICK("{0:s}_".format(args[0])))
        elif numeric in (RPL_ENDOFMOTD, ERR_NOMOTD):
            self.fire(JOIN(self.ircchannel))

    @handler("stopped", channel="*")
    def _on_stopped(self, component):
        self.screen.stop()

    @handler("generate_events")
    def _on_generate_events(self, event):
        event.reduce_time_left(0)

        size = self.screen.get_cols_rows()

        if not select(
                self.screen.get_input_descriptors(), [], [], 0.1)[0] == []:
            timeout, keys, raw = self.screen.get_input_nonblocking()

            for k in keys:
                if k == "window resize":
                    size = self.screen.get_cols_rows()
                    continue
                elif k == "enter":
                    self.processCommand(self.input.get_edit_text())
#.........这里部分代码省略.........
开发者ID:spaceone,项目名称:circuits,代码行数:101,代码来源:circ.py


示例20: __init__

 def __init__(self, enter, leave):
     self._top = enter, leave
     Edit.__init__(self)
开发者ID:foreni-packages,项目名称:hachoir-urwid,代码行数:3,代码来源:urwid_ui.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python urwid.Frame类代码示例发布时间:2022-05-27
下一篇:
Python urwid.set_encoding函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap