本文整理汇总了Python中urwid.Edit.set_edit_text方法的典型用法代码示例。如果您正苦于以下问题:Python Edit.set_edit_text方法的具体用法?Python Edit.set_edit_text怎么用?Python Edit.set_edit_text使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类urwid.Edit
的用法示例。
在下文中一共展示了Edit.set_edit_text方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: StringEditor
# 需要导入模块: from urwid import Edit [as 别名]
# 或者: from urwid.Edit import set_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, **kwargs):
self._edit = Edit(caption=caption, **kwargs)
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):
return self._edit.get_edit_text()
@value.setter # NOQA
def value(self, value):
self._edit.set_edit_text(value)
示例2: LockScreen
# 需要导入模块: from urwid import Edit [as 别名]
# 或者: from urwid.Edit import set_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)
示例3: LoginWindow
# 需要导入模块: from urwid import Edit [as 别名]
# 或者: from urwid.Edit import set_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
示例4: Client
# 需要导入模块: from urwid import Edit [as 别名]
# 或者: from urwid.Edit import set_edit_text [as 别名]
#.........这里部分代码省略.........
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())
self.input.set_edit_text("")
continue
self.top.keypress(size, k)
self.input.set_edit_text(self.input.get_edit_text() + k)
self.update_screen(size)
def unknownCommand(self, command):
self.lines.append(Text("Unknown command: %s" % command))
def syntaxError(self, command, args, expected):
self.lines.append(
Text("Syntax error ({0:s}): {1:s} Expected: {2:s}".format(
command, args, expected)
)
)
def processCommand(self, s): # noqa
match = CMD_REGEX.match(s)
if match is not None:
command = match.groupdict()["command"]
if not match.groupdict()["args"] == "":
tokens = match.groupdict()["args"].split(" ")
else:
tokens = []
fn = "cmd" + command.upper()
if hasattr(self, fn):
f = getattr(self, fn)
if callable(f):
示例5: CursesGUI
# 需要导入模块: from urwid import Edit [as 别名]
# 或者: from urwid.Edit import set_edit_text [as 别名]
#.........这里部分代码省略.........
# The loggers get a Handler that writes to the screen. We want this to only
# happen if the screen exists, so de-register them after the reactor stops.
reactor.addSystemEventTrigger('after','startup', self.register_loggers)
reactor.addSystemEventTrigger('before','shutdown', self.unregister_loggers)
reactor.run()
# We might have stopped the screen already, and the stop() method
# doesn't check for stopping twice.
if self.called_loop_stop:
self.logger.warn('Internal error!')
else:
self.loop.stop()
self.called_loop_stop = True
@fail_safely
def handle_input(self, key):
if key == 'enter':
text = self.edit_widget.edit_text
if text in ['q', 'Q']:
self.handle_quit_request()
else:
self.quit_flag = False
try:
i = int(text)
except ValueError:
i = None
self.handle_invalid_choice(text)
if i is not None:
self.handle_choice(i)
self.edit_widget.set_edit_text('')
def _roll_write(self, line, attr=None):
"""Add a line to the roll with palette attributes 'attr'.
If no attr is specified, None is used.
Default attr is plain text
"""
text = Text((attr, '* ' + line))
self.roll_list.append(text)
self.roll_list.set_focus(len(self.roll_list)-1)
self._modified()
@fail_safely
def update_state(self, state):
"""Sets the game state window via one large string.
"""
self.logger.debug('Drawing game state.')
self.state_text[:] = [self.colorize(s) for s in state.split('\n')]
self._modified()
@fail_safely
def update_game_log(self, log):
"""Sets the game log window via one large string.
"""
self.logger.debug('Drawing game log.')
self.game_log_list[:] = [self.colorize(s) for s in log.split('\n')]
self.game_log_list.set_focus(len(self.game_log_list)-1)
self._modified()
@fail_safely