Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added setting to hide the header #614

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions pudb/debugger.py
Original file line number Diff line number Diff line change
Expand Up @@ -948,13 +948,15 @@ def helpside(w, size, key):
],
dividechars=1)

background = urwid.AttrMap(self.columns, "background")

self.caption = urwid.Text("")
header = urwid.AttrMap(self.caption, "header")
self.top = SignalWrap(urwid.Frame(
urwid.AttrMap(self.columns, "background"),
header))
self.header = urwid.AttrMap(self.caption, "header")

# }}}
self.top = SignalWrap(urwid.Frame(background, self.header))

if CONFIG["hide_header"]:
self.top._w.header = None

def change_rhs_box(name, index, direction, w, size, key):
from pudb.settings import save_config
Expand Down Expand Up @@ -2421,6 +2423,7 @@ def __call__(subself, w, size, key): # noqa: N805, E501 # pylint: disable=no-se
width=("relative", 75),
height=("relative", 75),
)

w = Attr(w, "background")

return self.event_loop(w)[0]
Expand Down Expand Up @@ -2838,11 +2841,16 @@ def interaction(self, exc_tuple, show_exc_dialog=True):
(None, " "),
("header warning", "[POST-MORTEM MODE]")
])
self.show_header()
CONFIG["hide_header"] = False

elif exc_tuple is not None:
caption.extend([
(None, " "),
("header warning", "[PROCESSING EXCEPTION - hit 'e' to examine]")
])
self.show_header()
CONFIG["hide_header"] = False
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a little weird; at this point the on-disk configuration will start disagreeing from the in-memory one. I'm guessing if one opens the preferences dialog, this changed config will then be persisted to disk, but not otherwise, which may be confusing.

Overall, I find this code a bit too stateful. I would like it better if there were simply one place that decides whether the header is shown (if configured so, or if an there's an exception), and then all the places that may cause state changes affecting this decision call that central place.


self.caption.set_text(caption)
self.event_loop()
Expand Down Expand Up @@ -2956,6 +2964,14 @@ def make_frame_ui(i, frame_lineno):
def update_cmdline_win(self):
self.set_cmdline_state(not CONFIG["hide_cmdline_win"])

def update_header(self):
"""Update the header to reflect the current settings."""
self.top._w.header = self.header if not CONFIG["hide_header"] else None

def show_header(self):
"""Show the header."""
self.top._w.header = self.header

# }}}

# vim: foldmethod=marker:expandtab:softtabstop=4
15 changes: 15 additions & 0 deletions pudb/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ def load_config():
conf_dict.setdefault("prompt_on_quit", "True")

conf_dict.setdefault("hide_cmdline_win", "False")
conf_dict.setdefault("hide_header", "False")

# hotkeys
conf_dict.setdefault("hotkeys_code", "C")
Expand All @@ -133,6 +134,7 @@ def normalize_bool_inplace(name):
normalize_bool_inplace("wrap_variables")
normalize_bool_inplace("prompt_on_quit")
normalize_bool_inplace("hide_cmdline_win")
normalize_bool_inplace("hide_header")

_config_[0] = conf_dict
return conf_dict
Expand Down Expand Up @@ -179,6 +181,9 @@ def _update_prompt_on_quit():
def _update_hide_cmdline_win():
ui.update_cmdline_win()

def _update_hide_header():
ui.update_header()

def _update_current_stack_frame():
ui.update_stack()

Expand Down Expand Up @@ -222,6 +227,11 @@ def _update_config(check_box, new_state, option_newvalue):
conf_dict.update(new_conf_dict)
_update_hide_cmdline_win()

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

elif option == "current_stack_frame":
# only activate if the new state of the radio button is 'on'
if new_state:
Expand Down Expand Up @@ -270,6 +280,10 @@ def _update_config(check_box, new_state, option_newvalue):
bool(conf_dict["hide_cmdline_win"]), on_state_change=_update_config,
user_data=("hide_cmdline_win", None))

hide_header = urwid.CheckBox("Hide header from top of window",
bool(conf_dict["hide_header"]), on_state_change=_update_config,
user_data=("hide_header", None))

# {{{ shells

shell_info = urwid.Text("This is the shell that will be "
Expand Down Expand Up @@ -441,6 +455,7 @@ def _update_config(check_box, new_state, option_newvalue):
+ [cb_line_numbers]
+ [cb_prompt_on_quit]
+ [hide_cmdline_win]
+ [hide_header]

+ [urwid.AttrMap(urwid.Text("\nShell:\n"), "group head")]
+ [shell_info]
Expand Down