Skip to content

Commit

Permalink
add option in Preferences to keep watches (default is Off)
Browse files Browse the repository at this point in the history
  • Loading branch information
lechat committed Dec 11, 2017
1 parent 1ea224c commit 1ad4f86
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 24 deletions.
24 changes: 13 additions & 11 deletions pudb/debugger.py
Original file line number Diff line number Diff line change
Expand Up @@ -898,17 +898,19 @@ def edit_inspector_detail(w, size, key):
var.watch_expr.expression = watch_edit.get_edit_text()

elif result == "del":
from pudb.settings import load_watches, save_watches
stored_expressions = [expr.strip() for expr in load_watches()]

# Remove saved expression
for i, stored_expr in enumerate(stored_expressions):
if stored_expr == var.watch_expr.expression:
del stored_watches[i]

# Save it here because self.update_var_view() is going to
# read saved watches again
save_watches(stored_watches)
if CONFIG["persist_watches"]:
from pudb.settings import load_watches, save_watches
stored_expressions = [expr.strip()
for expr in load_watches()]

# Remove saved expression
for i, stored_expr in enumerate(stored_expressions):
if stored_expr == var.watch_expr.expression:
del stored_expressions[i]

# Save it here because self.update_var_view() is going to
# read saved watches again
save_watches(stored_expressions)

for i, watch_expr in enumerate(fvi.watches):
if watch_expr is var.watch_expr:
Expand Down
26 changes: 26 additions & 0 deletions pudb/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ def load_config():

conf_dict.setdefault("wrap_variables", True)

conf_dict.setdefault("persist_watches", False)

conf_dict.setdefault("display", "auto")

conf_dict.setdefault("prompt_on_quit", True)
Expand All @@ -123,6 +125,7 @@ def normalize_bool_inplace(name):

normalize_bool_inplace("line_numbers")
normalize_bool_inplace("wrap_variables")
normalize_bool_inplace("persist_watches")
normalize_bool_inplace("prompt_on_quit")

return conf_dict
Expand Down Expand Up @@ -175,6 +178,9 @@ def _update_stringifier():
def _update_wrap_variables():
ui.update_var_view()

def _update_persist_watches():
pass

def _update_config(check_box, new_state, option_newvalue):
option, newvalue = option_newvalue
new_conf_dict = {option: newvalue}
Expand Down Expand Up @@ -219,6 +225,11 @@ def _update_config(check_box, new_state, option_newvalue):
conf_dict.update(new_conf_dict)
_update_wrap_variables()

elif option == "persist_watches":
new_conf_dict["persist_watches"] = not check_box.get_state()
conf_dict.update(new_conf_dict)
_update_persist_watches()

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 @@ -353,6 +364,17 @@ def _update_config(check_box, new_state, option_newvalue):

# }}}

# {{{ persist watches

cb_persist_watches = urwid.CheckBox("Persist watches",
bool(conf_dict["persist_watches"]), on_state_change=_update_config,
user_data=("persist_watches", None))

persist_watches_info = urwid.Text("\nKeep watched expressions between "
"debugging sessions.")

# }}}

# {{{ display

display_info = urwid.Text("What driver is used to talk to your terminal. "
Expand Down Expand Up @@ -402,6 +424,10 @@ def _update_config(check_box, new_state, option_newvalue):
+ [cb_wrap_variables]
+ [wrap_variables_info]

+ [urwid.AttrMap(urwid.Text("\nPersist Watches:\n"), "group head")]
+ [cb_persist_watches]
+ [persist_watches_info]

+ [urwid.AttrMap(urwid.Text("\nDisplay driver:\n"), "group head")]
+ [display_info]
+ display_rbs
Expand Down
29 changes: 16 additions & 13 deletions pudb/var_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,19 +536,22 @@ def make_var_view(frame_var_info, locals, globals):
ret_walker = BasicValueWalker(frame_var_info)
watch_widget_list = []

from pudb.settings import load_watches, save_watches
stored_expressions = [expr.strip() for expr in load_watches()]

# As watch expressions are stored in a list, simply appending stored
# expressions to that list will add duplicates. This part is to avoid that.
from pudb.var_view import WatchExpression
existing_expressions = [expr.expression for expr in frame_var_info.watches]
for stored_expr in stored_expressions:
if stored_expr not in existing_expressions:
frame_var_info.watches.append(WatchExpression(stored_expr))

# Save watches because new ones may have added to a list
save_watches([expr.expression for expr in frame_var_info.watches])
if CONFIG["persist_watches"]:
from pudb.settings import load_watches, save_watches
stored_expressions = [expr.strip() for expr in load_watches()]

# As watch expressions are stored in a list, simply appending stored
# expressions to that list will add duplicates. This part is to avoid that.
from pudb.var_view import WatchExpression
existing_expressions = [expr.expression
for expr in frame_var_info.watches]

for stored_expr in stored_expressions:
if stored_expr not in existing_expressions:
frame_var_info.watches.append(WatchExpression(stored_expr))

# Save watches because new ones may have added to a list
save_watches([expr.expression for expr in frame_var_info.watches])

for watch_expr in frame_var_info.watches:
try:
Expand Down

0 comments on commit 1ad4f86

Please sign in to comment.