From 18d0e840b5a9895566ccd81e4eff507fdcd89c1a Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Sun, 18 Mar 2012 09:38:42 +1300 Subject: [PATCH] KVEditor -> GridEditor --- libmproxy/console/__init__.py | 8 ++++---- libmproxy/console/flowview.py | 6 +++--- .../console/{kveditor.py => grideditor.py} | 20 +++++++++---------- libmproxy/console/palettes.py | 2 +- 4 files changed, 18 insertions(+), 18 deletions(-) rename libmproxy/console/{kveditor.py => grideditor.py} (93%) diff --git a/libmproxy/console/__init__.py b/libmproxy/console/__init__.py index ff059d969..960e4bd77 100644 --- a/libmproxy/console/__init__.py +++ b/libmproxy/console/__init__.py @@ -17,7 +17,7 @@ import mailcap, mimetypes, tempfile, os, subprocess, glob, time, shlex import os.path, sys import urwid from .. import controller, utils, flow, version -import flowlist, flowview, help, common, kveditor, palettes +import flowlist, flowview, help, common, grideditor, palettes EVENTLOG_SIZE = 500 @@ -543,10 +543,10 @@ class ConsoleMaster(flow.FlowMaster): self.header = None self.make_view() - def view_kveditor(self, title, value, callback, *args, **kwargs): - self.body = kveditor.KVEditor(self, title, value, callback, *args, **kwargs) + def view_grideditor(self, title, value, callback, *args, **kwargs): + self.body = grideditor.GridEditor(self, title, value, callback, *args, **kwargs) self.header = None - self.help_context = kveditor.help_context + self.help_context = grideditor.help_context self.statusbar = StatusBar(self, self.footer_text_help) self.make_view() diff --git a/libmproxy/console/flowview.py b/libmproxy/console/flowview.py index 6a0e1b08b..6f864f922 100644 --- a/libmproxy/console/flowview.py +++ b/libmproxy/console/flowview.py @@ -395,7 +395,7 @@ class ConnectionView(common.WWrap): conn.set_form_urlencoded(flow.ODict(lst)) def edit_form(self, conn): - self.master.view_kveditor("Editing form", conn.get_form_urlencoded().lst, self.set_form, conn) + self.master.view_grideditor("Editing form", conn.get_form_urlencoded().lst, self.set_form, conn) def edit_form_confirm(self, key, conn): if key == "y": @@ -427,9 +427,9 @@ class ConnectionView(common.WWrap): else: self.edit_form(conn) elif part == "h": - self.master.view_kveditor("Editing headers", conn.headers.lst, self.set_headers, conn) + self.master.view_grideditor("Editing headers", conn.headers.lst, self.set_headers, conn) elif part == "q": - self.master.view_kveditor("Editing query", conn.get_query().lst, self.set_query, conn) + self.master.view_grideditor("Editing query", conn.get_query().lst, self.set_query, conn) elif part == "u" and self.state.view_flow_mode == common.VIEW_FLOW_REQUEST: self.master.prompt_edit("URL", conn.get_url(), self.set_url) elif part == "m" and self.state.view_flow_mode == common.VIEW_FLOW_REQUEST: diff --git a/libmproxy/console/kveditor.py b/libmproxy/console/grideditor.py similarity index 93% rename from libmproxy/console/kveditor.py rename to libmproxy/console/grideditor.py index ef8ff7e90..479486e0a 100644 --- a/libmproxy/console/kveditor.py +++ b/libmproxy/console/grideditor.py @@ -66,7 +66,7 @@ class SEdit(common.WWrap): return True -class KVItem(common.WWrap): +class GridItem(common.WWrap): def __init__(self, focused, editing, maxk, k, v): self.focused, self.editing, self.maxk = focused, editing, maxk if focused == 0 and editing: @@ -103,7 +103,7 @@ class KVItem(common.WWrap): KEY_MAX = 30 -class KVWalker(urwid.ListWalker): +class GridWalker(urwid.ListWalker): def __init__(self, lst, editor): self.lst, self.editor = lst, editor self.maxk = min(max(len(v[0]) for v in lst), KEY_MAX) if lst else 20 @@ -146,7 +146,7 @@ class KVWalker(urwid.ListWalker): def start_edit(self): if self.lst: - self.editing = KVItem(self.focus_col, True, self.maxk, *self.lst[self.focus]) + self.editing = GridItem(self.focus_col, True, self.maxk, *self.lst[self.focus]) self._modified() def stop_edit(self): @@ -176,7 +176,7 @@ class KVWalker(urwid.ListWalker): if self.editing: return self.editing, self.focus elif self.lst: - return KVItem(self.focus_col, False, self.maxk, *self.lst[self.focus]), self.focus + return GridItem(self.focus_col, False, self.maxk, *self.lst[self.focus]), self.focus else: return None, None @@ -187,20 +187,20 @@ class KVWalker(urwid.ListWalker): def get_next(self, pos): if pos+1 >= len(self.lst): return None, None - return KVItem(None, False, self.maxk, *self.lst[pos+1]), pos+1 + return GridItem(None, False, self.maxk, *self.lst[pos+1]), pos+1 def get_prev(self, pos): if pos-1 < 0: return None, None - return KVItem(None, False, self.maxk, *self.lst[pos-1]), pos-1 + return GridItem(None, False, self.maxk, *self.lst[pos-1]), pos-1 -class KVListBox(urwid.ListBox): +class GridListBox(urwid.ListBox): def __init__(self, lw): urwid.ListBox.__init__(self, lw) -class KVEditor(common.WWrap): +class GridEditor(common.WWrap): def __init__(self, master, title, value, callback, *cb_args, **cb_kwargs): value = copy.deepcopy(value) self.master, self.title, self.value, self.callback = master, title, value, callback @@ -208,8 +208,8 @@ class KVEditor(common.WWrap): p = urwid.Text(title) p = urwid.Padding(p, align="left", width=("relative", 100)) p = urwid.AttrWrap(p, "heading") - self.walker = KVWalker(self.value, self) - self.lb = KVListBox(self.walker) + self.walker = GridWalker(self.value, self) + self.lb = GridListBox(self.walker) self.w = urwid.Frame(self.lb, header = p) self.master.statusbar.update("") self.show_empty_msg() diff --git a/libmproxy/console/palettes.py b/libmproxy/console/palettes.py index d9d1aeaf2..78c796293 100644 --- a/libmproxy/console/palettes.py +++ b/libmproxy/console/palettes.py @@ -44,7 +44,7 @@ dark = [ # Hex view ('offset', 'dark cyan', 'default'), - # KV Editor + # Grid Editor ('focusfield', 'black', 'light gray'), ('editfield', 'black', 'light cyan'), ]