Skip to content

Commit

Permalink
Make the default stringifier a setting
Browse files Browse the repository at this point in the history
Right now, only type, str, and repr are allowed, but the ability to
define your own stringifier will be added.
  • Loading branch information
asmeurer committed Jul 28, 2011
1 parent 26a39f2 commit 90d21d3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
30 changes: 30 additions & 0 deletions pudb/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ def load_config():

conf_dict.setdefault("current_stack_frame", "top")

conf_dict.setdefault("stringifier", "type")

def normalize_bool_inplace(name):
try:
if conf_dict[name].lower() in ["0", "false", "off"]:
Expand Down Expand Up @@ -114,6 +116,9 @@ def _update_line_numbers():
def _update_current_stack_frame():
ui.update_stack()

def _update_stringifier():
ui.update_var_view()

def _update_config(check_box, new_state, option_newvalue):
option, newvalue = option_newvalue
new_conf_dict = {option: newvalue}
Expand All @@ -136,6 +141,13 @@ def _update_config(check_box, new_state, option_newvalue):
if new_state:
conf_dict.update(new_conf_dict)
_update_current_stack_frame()

elif option == "stringifier":
# only activate if the new state of the radio button is 'on'
if new_state:
conf_dict.update(new_conf_dict)
_update_stringifier()

heading = urwid.Text("This is the preferences screen for PuDB. "
"Hit Ctrl-P at any time to get back to it.\n\n"
"Configuration settings are saved in "
Expand Down Expand Up @@ -188,6 +200,20 @@ def _update_config(check_box, new_state, option_newvalue):
for name in stack_opts
]

stringifier_rb_group = []
stringifier_opts = ["type", "str", "repr"]
stringifier_info = urwid.Text("This is the default function that will be "
"called on variables in the variables list. Note that you can change "
"this on a per-variable basis by selecting a variable and hitting Enter "
"or by typing t/s/r. Note that str and repr will be slower than type "
"and have the potential to crash PuDB.")
stringifier_rbs = [
urwid.RadioButton(stack_rb_group, name,
conf_dict["stringifier"] == name,
on_state_change=_update_config,
user_data=("stringifier", name))
for name in stringifier_opts
]
if ui.dialog(
urwid.ListBox(
[heading]
Expand All @@ -201,6 +227,9 @@ def _update_config(check_box, new_state, option_newvalue):
+ [urwid.AttrMap(urwid.Text("\nStack Order:\n"), "group head")]
+ [stack_info]
+ stack_rbs
+ [urwid.AttrMap(urwid.Text("\nVariable Stringifier:\n"), "group head")]
+ [stringifier_info]
+ stringifier_rbs
),
[
("OK", True),
Expand All @@ -220,6 +249,7 @@ def _update_config(check_box, new_state, option_newvalue):
_update_theme()
# _update_line_numbers() is equivalent to _update_theme()
_update_current_stack_frame()
_update_stringifier()



Expand Down
4 changes: 3 additions & 1 deletion pudb/var_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
except ImportError:
HAVE_NUMPY = 0

from pudb import CONFIG

# data ------------------------------------------------------------------------
class FrameVarInfo(object):
def __init__(self):
Expand All @@ -24,7 +26,7 @@ def get_inspect_info(self, id_path, read_only):
class InspectInfo(object):
def __init__(self):
self.show_detail = False
self.display_type = "type"
self.display_type = CONFIG["stringifier"]
self.highlighted = False
self.repeated_at_top = False
self.show_private_members = False
Expand Down

0 comments on commit 90d21d3

Please sign in to comment.