2015-03-20 00:26:08 +00:00
|
|
|
import urwid
|
2015-04-06 22:01:18 +00:00
|
|
|
from . import signals
|
2015-03-31 20:25:50 +00:00
|
|
|
|
2015-03-20 00:26:08 +00:00
|
|
|
|
|
|
|
class Window(urwid.Frame):
|
2015-03-31 20:25:50 +00:00
|
|
|
def __init__(self, master, body, header, footer, helpctx):
|
2015-04-06 22:01:18 +00:00
|
|
|
urwid.Frame.__init__(
|
|
|
|
self,
|
|
|
|
urwid.AttrWrap(body, "background"),
|
|
|
|
header = urwid.AttrWrap(header, "background") if header else None,
|
|
|
|
footer = urwid.AttrWrap(footer, "background") if footer else None
|
|
|
|
)
|
2015-03-20 00:26:08 +00:00
|
|
|
self.master = master
|
2015-03-31 20:25:50 +00:00
|
|
|
self.helpctx = helpctx
|
2015-03-22 00:32:24 +00:00
|
|
|
signals.focus.connect(self.sig_focus)
|
|
|
|
|
|
|
|
def sig_focus(self, sender, section):
|
|
|
|
self.focus_position = section
|
2015-03-20 00:26:08 +00:00
|
|
|
|
2015-06-01 23:05:45 +00:00
|
|
|
def mouse_event(self, *args, **kwargs):
|
|
|
|
# args: (size, event, button, col, row)
|
|
|
|
k = super(self.__class__, self).mouse_event(*args, **kwargs)
|
2015-06-01 23:13:12 +00:00
|
|
|
if not k:
|
|
|
|
if args[1] == "mouse drag":
|
|
|
|
signals.status_message.send(
|
|
|
|
message = "Hold down alt or ctrl to select text.",
|
|
|
|
expire = 1
|
|
|
|
)
|
|
|
|
elif args[1] == "mouse press" and args[2] == 4:
|
|
|
|
self.keypress(args[0], "up")
|
|
|
|
elif args[1] == "mouse press" and args[2] == 5:
|
|
|
|
self.keypress(args[0], "down")
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
return True
|
2015-06-01 23:05:45 +00:00
|
|
|
|
2015-03-20 00:26:08 +00:00
|
|
|
def keypress(self, size, k):
|
2015-03-31 20:25:50 +00:00
|
|
|
k = super(self.__class__, self).keypress(size, k)
|
2015-03-22 00:32:24 +00:00
|
|
|
if k == "?":
|
2015-03-31 20:25:50 +00:00
|
|
|
self.master.view_help(self.helpctx)
|
2015-03-22 00:32:24 +00:00
|
|
|
elif k == "c":
|
|
|
|
if not self.master.client_playback:
|
2015-03-22 00:59:34 +00:00
|
|
|
signals.status_prompt_path.send(
|
2015-03-22 00:32:24 +00:00
|
|
|
self,
|
2015-03-22 00:59:34 +00:00
|
|
|
prompt = "Client replay",
|
2015-03-22 00:32:24 +00:00
|
|
|
callback = self.master.client_playback_path
|
2015-03-20 00:26:08 +00:00
|
|
|
)
|
2015-03-22 00:32:24 +00:00
|
|
|
else:
|
|
|
|
signals.status_prompt_onekey.send(
|
|
|
|
self,
|
|
|
|
prompt = "Stop current client replay?",
|
|
|
|
keys = (
|
2015-03-20 00:26:08 +00:00
|
|
|
("yes", "y"),
|
|
|
|
("no", "n"),
|
|
|
|
),
|
2015-03-22 00:32:24 +00:00
|
|
|
callback = self.master.stop_client_playback_prompt,
|
2015-03-20 00:26:08 +00:00
|
|
|
)
|
2015-03-22 00:32:24 +00:00
|
|
|
elif k == "i":
|
|
|
|
signals.status_prompt.send(
|
|
|
|
self,
|
2015-03-22 00:59:34 +00:00
|
|
|
prompt = "Intercept filter",
|
2015-03-22 00:32:24 +00:00
|
|
|
text = self.master.state.intercept_txt,
|
|
|
|
callback = self.master.set_intercept
|
|
|
|
)
|
2015-04-03 01:10:57 +00:00
|
|
|
elif k == "o":
|
|
|
|
self.master.view_options()
|
2015-03-22 00:32:24 +00:00
|
|
|
elif k == "Q":
|
|
|
|
raise urwid.ExitMainLoop
|
|
|
|
elif k == "q":
|
2015-03-31 20:25:50 +00:00
|
|
|
signals.pop_view_state.send(self)
|
2015-03-22 00:32:24 +00:00
|
|
|
elif k == "S":
|
|
|
|
if not self.master.server_playback:
|
2015-03-22 00:59:34 +00:00
|
|
|
signals.status_prompt_path.send(
|
2015-03-22 00:32:24 +00:00
|
|
|
self,
|
2015-03-22 00:59:34 +00:00
|
|
|
prompt = "Server replay path",
|
2015-03-22 00:32:24 +00:00
|
|
|
callback = self.master.server_playback_path
|
2015-03-20 00:26:08 +00:00
|
|
|
)
|
|
|
|
else:
|
2015-03-22 00:32:24 +00:00
|
|
|
signals.status_prompt_onekey.send(
|
|
|
|
self,
|
|
|
|
prompt = "Stop current server replay?",
|
|
|
|
keys = (
|
|
|
|
("yes", "y"),
|
|
|
|
("no", "n"),
|
|
|
|
),
|
|
|
|
callback = self.master.stop_server_playback_prompt,
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
return k
|