diff --git a/pudb/debugger.py b/pudb/debugger.py index 294aec46..d1f4cac3 100644 --- a/pudb/debugger.py +++ b/pudb/debugger.py @@ -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: diff --git a/pudb/settings.py b/pudb/settings.py index 67cbec62..53bd785f 100644 --- a/pudb/settings.py +++ b/pudb/settings.py @@ -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) @@ -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 @@ -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} @@ -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 " @@ -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. " @@ -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 diff --git a/pudb/var_view.py b/pudb/var_view.py index a45ef6bc..e133a777 100644 --- a/pudb/var_view.py +++ b/pudb/var_view.py @@ -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: