def toggle_breakpoint(w, size, key):
    bp_source_identifier = self.source_code_provider.get_source_identifier()
    if bp_source_identifier:
        (sline, pos) = self.source.get_focus()
        lineno = (pos + 1)
        existing_breaks = self.debugger.get_breaks(bp_source_identifier, lineno)
        if existing_breaks:
            err = None
            for bp in existing_breaks:
                if (not bp.enabled):
                    bp.enable()
                    sline.set_breakpoint(True)
                    break
            else:
                err = self.debugger.clear_break(bp_source_identifier, lineno)
                sline.set_breakpoint(False)
        else:
            file_lineno = (bp_source_identifier, lineno)
            if (file_lineno in self.debugger.set_traces):
                self.debugger.set_traces[file_lineno] = (not self.debugger.set_traces[file_lineno])
                sline.set_breakpoint(self.debugger.set_traces[file_lineno])
                return
            from pudb.lowlevel import get_breakpoint_invalid_reason
            invalid_reason = get_breakpoint_invalid_reason(bp_source_identifier, (pos + 1))
            if (invalid_reason is not None):
                do_set = (not self.dialog(urwid.ListBox(urwid.SimpleListWalker([urwid.Text(('The breakpoint you just set may be invalid, for the following reason:\n\n' + invalid_reason))])), [('Cancel', True), ('Set Anyway', False)], title='Possibly Invalid Breakpoint', focus_buttons=True))
            else:
                do_set = True
            if do_set:
                err = self.debugger.set_break(bp_source_identifier, (pos + 1))
                sline.set_breakpoint(True)
            else:
                err = None
        if err:
            self.message(('Error dealing with breakpoint:\n' + err))
        self.update_breakpoints()
    else:
        self.message('Cannot currently set a breakpoint here--source code does not correspond to a file location. (perhaps this is generated code)')
def toggle_breakpoint(w, size, key):
    bp_source_identifier = self.source_code_provider.get_source_identifier()
    if bp_source_identifier:
        (sline, pos) = self.source.get_focus()
        lineno = (pos + 1)
        existing_breaks = self.debugger.get_breaks(bp_source_identifier, lineno)
        if existing_breaks:
            err = None
            for bp in existing_breaks:
                if (not bp.enabled):
                    bp.enable()
                    sline.set_breakpoint(True)
                    break
            else:
                err = self.debugger.clear_break(bp_source_identifier, lineno)
                sline.set_breakpoint(False)
        else:
            file_lineno = (bp_source_identifier, lineno)
            if (file_lineno in self.debugger.set_traces):
                self.debugger.set_traces[file_lineno] = (not self.debugger.set_traces[file_lineno])
                sline.set_breakpoint(self.debugger.set_traces[file_lineno])
                return
            from pudb.lowlevel import get_breakpoint_invalid_reason
            invalid_reason = get_breakpoint_invalid_reason(bp_source_identifier, (pos + 1))
            if (invalid_reason is not None):
                do_set = (not self.dialog(urwid.ListBox(urwid.SimpleListWalker([urwid.Text(('The breakpoint you just set may be invalid, for the following reason:\n\n' + invalid_reason))])), [('Cancel', True), ('Set Anyway', False)], title='Possibly Invalid Breakpoint', focus_buttons=True))
            else:
                do_set = True
            if do_set:
                err = self.debugger.set_break(bp_source_identifier, (pos + 1))
                sline.set_breakpoint(True)
            else:
                err = None
        if err:
            self.message(('Error dealing with breakpoint:\n' + err))
        self.update_breakpoints()
    else:
        self.message('Cannot currently set a breakpoint here--source code does not correspond to a file location. (perhaps this is generated code)')