8000 Debugger widget by hyamanieu · Pull Request #2548 · holoviz/panel · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
3bee676
First commit proposal debugger widget
hyamanieu Jul 14, 2021
41565b3
To work within a notebook
hyamanieu Jul 17, 2021
5f69a37
soberer look with css
hyamanieu Jul 17, 2021
1a563cd
minor visual bug
hyamanieu Jul 17, 2021
399fcbb
prepare merge to master
hyamanieu Jul 20, 2021
c4e2953
doc, added levels, style
hyamanieu Jul 20, 2021
ed8e819
button on top and soberer, readded reactive.py
hyamanieu Jul 20, 2021
54a2943
Merge branch 'holoviz:master' into debugger_widget
hyamanieu Jul 21, 2021
c370092
correct conflicts within reative.py
hyamanieu Jul 21, 2021
f245a79
formatting issues, doubled variable
hyamanieu Jul 21, 2021
fa2fe4d
Raise exceptions + handle .show
hyamanieu Jul 21, 2021
3cd5362
flakes
hyamanieu Jul 21, 2021
3e054f7
Merge branch 'holoviz:master' into debugger_widget
hyamanieu Jul 25, 2021
843e2c7
Merge branch 'master' of github.com:holoviz/panel into debugger_widget
hyamanieu Jul 26, 2021
754a470
Add save btn
hyamanieu Jul 26, 2021
48da9d6
Merge branch 'holoviz:master' into debugger_widget
hyamanieu Jul 29, 2021
1dcdf72
Fixed buttons + unit test
hyamanieu Jul 29, 2021
6568f0d
signature fix
hyamanieu Jul 29, 2021
2b11f4c
Added doc in reference gallery
hyamanieu Jul 30, 2021
a9f35e6
Grammar
hyamanieu Jul 30, 2021
39581cf
Merge branch 'master' into debugger_widget
hyamanieu Nov 10, 2021
d013768
Merge branch 'master' of github.com:holoviz/panel into debugger_widget
hyamanieu Apr 3, 2022
6587d7f
Cleanup and sizing fixes
philippjfr Apr 4, 2022
88ff629
Minor fixes
philippjfr Apr 4, 2022
d7114ab
Subscribe to panel logger
philippjfr Apr 4, 2022
0f4c5b2
Doc correction and more controls
hyamanieu Apr 9, 2022
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
Prev Previous commit
Next Next commit
Add save btn
  • Loading branch information
hyamanieu committed Jul 26, 2021
commit 754a4708a0ee5aa21ee32fded3d03a9c5074c011
47 changes: 44 additions & 3 deletions panel/dist/css/debugger.css
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
.bk.debugger-card {
border: 1px solid rgba(0,0,0,1);
color: rgba(255,255,255,1);
background-color: rgba(0,0,0,1);
border-radius: 0rem;
}
.bk.debugger-card-header {
align-items: center;
background-color: rgba(0, 0, 0, 1);
align-items: left;
text-align: left;
background-color: rgba(0, 0, 0, 1)!important;
color: rgba(255, 255, 255, 1);
border-radius: 0rem;
display: inline-flex;
justify-content: start;
Expand All @@ -21,4 +25,41 @@
color: rgba(255, 255, 255, 1);
font-size: 1em;
overflow-wrap: break-word;
}
}

/* Special debugger buttons for clearing and saving */
.bk button.special_btn {
width: 25px;
height: 25px;
background-color: black;
color: white;
display: inline-block;
}


.bk button.special_btn .tooltiptext {
visibility: hidden;
width: 100px;
background-color: darkgray;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 5px 0;

/* Position the tooltip */
position: relative;
z-index: 1;
top: 100%;
left: 100%;
margin-left: -100px;
display: block;
}

.bk button.special_btn:hover .tooltiptext {
visibility: visible;
}



.bk button.clear_btn:hover .shown { display: none;}
.bk button.clear_btn:hover:before { content: "☑"; }
74 changes: 60 additions & 14 deletions panel/widgets/debugger.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 8000 +10,7 @@
from ..layout.card import Card
from ..reactive import ReactiveHTML
from ..io.state import state

from ..layout import Row, HSpacer



Expand Down Expand Up @@ -112,17 +112,31 @@ def filter(self,record):

return True

class TermButton(ReactiveHTML):
class _SpecialButton(ReactiveHTML):
clicks = param.Integer(default=0)
title = param.String(doc="Text shown on button", default='Clear')
#Note: using name instead of title will thrown an error.
_template = """<button id="clear" onclick='${_input_change}'
style="width: ${model.width}px;height: 25px;background-color: black;color: white">Clear</button>"""

def _input_change(self, event):
self.clicks += 1


class ClearButton(_SpecialButton):
_template = """<button class='special_btn clear_btn'
id="clear_btn"
onclick='${_input_change}'
style="width: ${model.width}px;">
<span class="shown">☐</span>
<span class="tooltiptext">Acknowledge logs and clear</span>
</button>"""

class SaveButton(_SpecialButton):
_template = """<button class='special_btn'
id="save_btn"
onclick='${_input_change}'
style="width: ${model.width}px;">
💾
<span class="tooltiptext">Save logs</span>
</button>"""


class Debugger(Card):
"""
A uneditable Card layout holding a terminal printing out logs from your
Expand Down Expand Up @@ -166,7 +180,8 @@ def __init__(self, *args, **kwargs):

terminal = Terminal(min_height=200,
min_width=400,
sizing_mode='stretch_width')
sizing_mode='stretch_width',
name=self.name)
stream_handler = logging.StreamHandler(terminal)
stream_handler.terminator = " \n"

Expand All @@ -184,18 +199,48 @@ def __init__(self, *args, **kwargs):
logger= logging.getLogger('panel.callbacks')
logger.addHandler(stream_handler)

#header
#callbacks for header
self.param.watch(self.update_log_counts,'_number_of_errors')
self.param.watch(self.update_log_counts,'_number_of_warnings')
self.param.watch(self.update_log_counts,'_number_of_infos')

#body
self.ackn_btn = TermButton(width=terminal.width)#setting title directly will throw a ValueError
#as it gets converted to a .pane.markup.Markdown object.
self.ackn_btn.title='Acknowledge errors'
#buttons
self.ackn_btn = ClearButton()
self.save_btn = SaveButton()
self.ackn_btn.param.watch(self.acknowledge_errors, ['clicks'])

js_cb = """
function saveTerminalToFile() {
var filename = terminal.name+'.txt'
console.log(filename)
var blob = new Blob([terminal.output],
{ type: "text/plain;charset=utf-8" });
if (navigator.msSaveBlob) {
navigator.msSaveBlob(blob, filename);
} else {
var link = document.createElement('a');
var url = URL.createObjectURL(blob);
link.href = url;
link.download = filename;
document.body.appendChild(link);
link.click();
setTimeout(function() {
document.body.removeChild(link);
window.URL.revokeObjectURL(url);
}, 0);
}
}
saveTerminalToFile();
"""

self.save_btn.jscallback(clicks=js_cb, args={'terminal':terminal})

#set header
self.title = ''

#body
self.terminal = terminal
self.append(self.ackn_btn)
self.append(Row(self.name, HSpacer(),self.ackn_btn,self.save_btn, align=('end','start')))
self.append(terminal)

#make it an uneditable card
Expand All @@ -204,6 +249,7 @@ def __init__(self, *args, **kwargs):
#by default it should be collapsed and small.
self.collapsed = True



def update_log_counts(self, event):
title = []
Expand Down
0