本文整理汇总了Python中urwid.Edit.get_edit_text方法的典型用法代码示例。如果您正苦于以下问题:Python Edit.get_edit_text方法的具体用法?Python Edit.get_edit_text怎么用?Python Edit.get_edit_text使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类urwid.Edit
的用法示例。
在下文中一共展示了Edit.get_edit_text方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: StringEditor
# 需要导入模块: from urwid import Edit [as 别名]
# 或者: from urwid.Edit import get_edit_text [as 别名]
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)
示例2: TextEditor
# 需要导入模块: from urwid import Edit [as 别名]
# 或者: from urwid.Edit import get_edit_text [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)
示例3: LockScreen
# 需要导入模块: from urwid import Edit [as 别名]
# 或者: from urwid.Edit import get_edit_text [as 别名]
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)
示例4: BaseEditor
# 需要导入模块: from urwid import Edit [as 别名]
# 或者: from urwid.Edit import get_edit_text [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)
示例5: EditInput
# 需要导入模块: from urwid import Edit [as 别名]
# 或者: from urwid.Edit import get_edit_text [as 别名]
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()
示例6: TweetEditor
# 需要导入模块: from urwid import Edit [as 别名]
# 或者: from urwid.Edit import get_edit_text [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)
示例7: BaseEditor
# 需要导入模块: from urwid import Edit [as 别名]
# 或者: from urwid.Edit import get_edit_text [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)
示例8: LoginWindow
# 需要导入模块: from urwid import Edit [as 别名]
# 或者: from urwid.Edit import get_edit_text [as 别名]
#.........这里部分代码省略.........
self.pile = Pile([
username_row,
Divider(),
password_row,
], focus_item=0)
self.login_widget = Filler(Columns([Divider(), self.pile, Divider()]))
def show(self):
"""Show login window"""
#self.pile.set_focus(0)
self.clear()
loop = self.app.loop
self.overlay.bottom_w = loop.widget
loop.widget = self.overlay
if loop.screen.started:
loop.draw_screen()
def hide(self):
"""Hide login window"""
loop = self.app.loop
loop.widget = self.overlay.bottom_w
if loop.screen.started:
loop.draw_screen()
def login(self, user):
"""
Login the session, showing all content and hidding login window.
"""
# connect esc-esc signal to logout
widget = self.overlay.bottom_w
widget.orig_keypress = widget.keypress
widget.keypress = self._wrapped_keypress
self._last_key_time = time.time()
self._timeout_sig_id = self.app.loop.set_alarm_in(self.max_time+1,
self._check_logout)
if hasattr(widget, 'set_user') and callable(widget.set_user):
widget.set_user(user)
self.hide()
self._emit("login")
def logout(self):
"""Logout the session, hidding all content and showing login window
again.
"""
# disconnect esc-esc signal
self.app.loop.widget.keypress = self.app.loop.widget.orig_keypress
self.app.loop.remove_alarm(self._timeout_sig_id)
self.show()
self._emit("logout")
def clear(self):
self.username_entry.set_edit_text("")
self.password_entry.set_edit_text("")
self.pile.set_focus(0)
def _wrapped_keypress(self, size, key):
self._last_key_time = time.time()
if key == 'esc':
if self._out_count == 1 and (time.time() - self._evt_time) < 1:
self._out_count = 0
self._evt_time = 0
self.logout()
else:
self._out_count = 1
self._evt_time = time.time()
return None
else:
return self.app.loop.widget.orig_keypress(size, key)
def _username_keypress(self, size, key):
if key == 'enter':
key = 'down'
return self.username_entry.__class__.keypress(self.username_entry, size, key)
def _password_keypress(self, size, key):
if key == 'enter':
password = self.password_entry.get_edit_text()
username = self.username_entry.get_edit_text()
self.password_entry.set_edit_text("")
if password and username:
user = self.get_user(username, password)
if user:
#self.username_entry.set_edit_text("")
self.login(user)
return
return self.password_entry.__class__.keypress(self.password_entry, size, key)
def _check_logout(self, main_loop, user_data=None):
etime = int(time.time() - self._last_key_time)
if etime >= self.max_time:
self.logout()
else:
main_loop.remove_alarm(self._timeout_sig_id)
self._timeout_sig_id = main_loop.set_alarm_in(self.max_time-etime, self._check_logout)
return False
示例9: Client
# 需要导入模块: from urwid import Edit [as 别名]
# 或者: from urwid.Edit import get_edit_text [as 别名]
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())
#.........这里部分代码省略.........