Skip to content

Commit 29136f4

Browse files
committed
Add clssses and css to inspector
1 parent 334f874 commit 29136f4

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

ltk/ltk.css

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@
3131
color: black;
3232
padding: 0 8px;
3333
height: fit-content;
34-
width: fit-content;
34+
max-width: 600px;
35+
max-height: 400px;
36+
overflow: hidden;
37+
overflow-y: scroll;
3538
min-height: 24px;
3639
}
3740

ltk/ltk.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,19 @@
153153
window.getWidget = function(id) {
154154
return undefined;
155155
};
156+
157+
window.getStyle = function(node) {
158+
const result = {};
159+
const div = $(`<${node[0].tagName}>`).appendTo("body");
160+
const default_styles = window.getComputedStyle(div[0])
161+
const widget_styles = window.getComputedStyle(node[0])
162+
for (let prop in widget_styles) {
163+
if (widget_styles[prop] !== default_styles[prop]) {
164+
result[prop] = widget_styles[prop];
165+
}
166+
}
167+
return result;
168+
}
156169

157170
$.fn.widget = function() {
158171
return window.getWidget($(this))

ltk/widgets.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,10 @@ def show(self, widget):
6464
An LTK Python widget of class <tt>{widget.__class__.__name__}</tt><ul>
6565
<li>{widget.__class__.__doc__.replace("<", "&lt;")}
6666
{self.get_attrs(widget)}
67+
{self.get_classes(widget)}
6768
<li>{self.get_creation_link(widget)}
6869
<li>{widget.children().length} children
70+
{self.get_css(widget)}
6971
""")
7072
details_left = max(0, left - self.details.outerWidth() + 2) \
7173
if left + width > find("body").width() * 3 / 4 else left + width - 2
@@ -79,6 +81,20 @@ def hide(self):
7981
self.right.css("display", "none")
8082
self.details.css("display", "none")
8183

84+
def get_css(self, widget):
85+
""" Show the CSS of a widget """
86+
js_styles = window.getStyle(widget.element)
87+
return "<li> css:<pre style='font-size: 12px;'>" + window.JSON.stringify(js_styles, None, 4) + "</pre>"
88+
89+
def get_classes(self, widget):
90+
""" Show the classes of a widget """
91+
result = []
92+
for name, value in widget.__class__.__dict__.items():
93+
if name.startswith("_") or name in INSPECT_IGNORE_ATTRIBUTES:
94+
continue
95+
result.append(f"{name} = {value}")
96+
return ("<li>" if result else "") + "<li>".join(result)
97+
8298
def get_attrs(self, widget):
8399
""" Show the attributes of a widget """
84100
result = []

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"
66

77
[project]
88
name = "pyscript-ltk"
9-
version = "0.2.21"
9+
version = "0.2.22"
1010
description = "A little toolkit for writing UIs in PyScript"
1111
readme = "README.md"
1212
authors = [{ name = "Chris Laffra", email = "[email protected]" }]

0 commit comments

Comments
 (0)