Skip to content

Commit 2da2020

Browse files
lechatAleksey Maksimov
authored and
Aleksey Maksimov
committed
add option in Preferences to keep watches (default is Off)
1 parent f975aab commit 2da2020

File tree

3 files changed

+55
-24
lines changed

3 files changed

+55
-24
lines changed

pudb/debugger.py

+13-11
Original file line numberDiff line numberDiff line change
@@ -901,17 +901,19 @@ def edit_inspector_detail(w, size, key):
901901
var.watch_expr.expression = watch_edit.get_edit_text()
902902

903903
elif result == "del":
904-
from pudb.settings import load_watches, save_watches
905-
stored_expressions = [expr.strip() for expr in load_watches()]
906-
907-
# Remove saved expression
908-
for i, stored_expr in enumerate(stored_expressions):
909-
if stored_expr == var.watch_expr.expression:
910-
del stored_watches[i]
911-
912-
# Save it here because self.update_var_view() is going to
913-
# read saved watches again
914-
save_watches(stored_watches)
904+
if CONFIG["persist_watches"]:
905+
from pudb.settings import load_watches, save_watches
906+
stored_expressions = [expr.strip()
907+
for expr in load_watches()]
908+
909+
# Remove saved expression
910+
for i, stored_expr in enumerate(stored_expressions):
911+
if stored_expr == var.watch_expr.expression:
912+
del stored_expressions[i]
913+
914+
# Save it here because self.update_var_view() is going to
915+
# read saved watches again
916+
save_watches(stored_expressions)
915917

916918
for i, watch_expr in enumerate(fvi.watches):
917919
if watch_expr is var.watch_expr:

pudb/settings.py

+26
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ def load_config():
109109
conf_dict.setdefault("wrap_variables", True)
110110
conf_dict.setdefault("default_variables_access_level", "public")
111111

112+
conf_dict.setdefault("persist_watches", False)
113+
112114
conf_dict.setdefault("display", "auto")
113115

114116
conf_dict.setdefault("prompt_on_quit", True)
@@ -124,6 +126,7 @@ def normalize_bool_inplace(name):
124126

125127
normalize_bool_inplace("line_numbers")
126128
normalize_bool_inplace("wrap_variables")
129+
normalize_bool_inplace("persist_watches")
127130
normalize_bool_inplace("prompt_on_quit")
128131

129132
return conf_dict
@@ -179,6 +182,9 @@ def _update_default_variables_access_level():
179182
def _update_wrap_variables():
180183
ui.update_var_view()
181184

185+
def _update_persist_watches():
186+
pass
187+
182188
def _update_config(check_box, new_state, option_newvalue):
183189
option, newvalue = option_newvalue
184190
new_conf_dict = {option: newvalue}
@@ -230,6 +236,11 @@ def _update_config(check_box, new_state, option_newvalue):
230236
conf_dict.update(new_conf_dict)
231237
_update_wrap_variables()
232238

239+
elif option == "persist_watches":
240+
new_conf_dict["persist_watches"] = not check_box.get_state()
241+
conf_dict.update(new_conf_dict)
242+
_update_persist_watches()
243+
233244
heading = urwid.Text("This is the preferences screen for PuDB. "
234245
"Hit Ctrl-P at any time to get back to it.\n\n"
235246
"Configuration settings are saved in "
@@ -384,6 +395,17 @@ def _update_config(check_box, new_state, option_newvalue):
384395

385396
# }}}
386397

398+
# {{{ persist watches
399+
400+
cb_persist_watches = urwid.CheckBox("Persist watches",
401+
bool(conf_dict["persist_watches"]), on_state_change=_update_config,
402+
user_data=("persist_watches", None))
403+
404+
persist_watches_info = urwid.Text("\nKeep watched expressions between "
405+
"debugging sessions.")
406+
407+
# }}}
408+
387409
# {{{ display
388410

389411
display_info = urwid.Text("What driver is used to talk to your terminal. "
@@ -438,6 +460,10 @@ def _update_config(check_box, new_state, option_newvalue):
438460
+ [cb_wrap_variables]
439461
+ [wrap_variables_info]
440462

463+
+ [urwid.AttrMap(urwid.Text("\nPersist Watches:\n"), "group head")]
464+
+ [cb_persist_watches]
465+
+ [persist_watches_info]
466+
441467
+ [urwid.AttrMap(urwid.Text("\nDisplay driver:\n"), "group head")]
442468
+ [display_info]
443469
+ display_rbs

pudb/var_view.py

+16-13
Original file line numberDiff line numberDiff line change
@@ -544,19 +544,22 @@ def make_var_view(frame_var_info, locals, globals):
544544
ret_walker = BasicValueWalker(frame_var_info)
545545
watch_widget_list = []
546546

547-
from pudb.settings import load_watches, save_watches
548-
stored_expressions = [expr.strip() for expr in load_watches()]
549-
550-
# As watch expressions are stored in a list, simply appending stored
551-
# expressions to that list will add duplicates. This part is to avoid that.
552-
from pudb.var_view import WatchExpression
553-
existing_expressions = [expr.expression for expr in frame_var_info.watches]
554-
for stored_expr in stored_expressions:
555-
if stored_expr not in existing_expressions:
556-
frame_var_info.watches.append(WatchExpression(stored_expr))
557-
558-
# Save watches because new ones may have added to a list
559-
save_watches([expr.expression for expr in frame_var_info.watches])
547+
if CONFIG["persist_watches"]:
548+
from pudb.settings import load_watches, save_watches
549+
stored_expressions = [expr.strip() for expr in load_watches()]
550+
551+
# As watch expressions are stored in a list, simply appending stored
552+
# expressions to that list will add duplicates. This part is to avoid that.
553+
from pudb.var_view import WatchExpression
554+
existing_expressions = [expr.expression
555+
for expr in frame_var_info.watches]
556+
557+
for stored_expr in stored_expressions:
558+
if stored_expr not in existing_expressions:
559+
frame_var_info.watches.append(WatchExpression(stored_expr))
560+
561+
# Save watches because new ones may have added to a list
562+
save_watches([expr.expression for expr in frame_var_info.watches])
560563

561564
for watch_expr in frame_var_info.watches:
562565
try:

0 commit comments

Comments
 (0)