dashlab 0.3.6__tar.gz → 0.3.7__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (24) hide show
  1. {dashlab-0.3.6 → dashlab-0.3.7}/PKG-INFO +1 -1
  2. {dashlab-0.3.6 → dashlab-0.3.7}/dashlab/_version.py +1 -1
  3. {dashlab-0.3.6 → dashlab-0.3.7}/dashlab/utils.py +22 -7
  4. {dashlab-0.3.6 → dashlab-0.3.7}/dashlab.egg-info/PKG-INFO +1 -1
  5. {dashlab-0.3.6 → dashlab-0.3.7}/LICENSE +0 -0
  6. {dashlab-0.3.6 → dashlab-0.3.7}/README.md +0 -0
  7. {dashlab-0.3.6 → dashlab-0.3.7}/dashlab/__init__.py +0 -0
  8. {dashlab-0.3.6 → dashlab-0.3.7}/dashlab/_internal.py +0 -0
  9. {dashlab-0.3.6 → dashlab-0.3.7}/dashlab/base.py +0 -0
  10. {dashlab-0.3.6 → dashlab-0.3.7}/dashlab/core.py +0 -0
  11. {dashlab-0.3.6 → dashlab-0.3.7}/dashlab/patches.py +0 -0
  12. {dashlab-0.3.6 → dashlab-0.3.7}/dashlab/static/animator.css +0 -0
  13. {dashlab-0.3.6 → dashlab-0.3.7}/dashlab/static/animator.js +0 -0
  14. {dashlab-0.3.6 → dashlab-0.3.7}/dashlab/static/fscreen.css +0 -0
  15. {dashlab-0.3.6 → dashlab-0.3.7}/dashlab/static/fscreen.js +0 -0
  16. {dashlab-0.3.6 → dashlab-0.3.7}/dashlab/static/listw.css +0 -0
  17. {dashlab-0.3.6 → dashlab-0.3.7}/dashlab/static/listw.js +0 -0
  18. {dashlab-0.3.6 → dashlab-0.3.7}/dashlab/widgets.py +0 -0
  19. {dashlab-0.3.6 → dashlab-0.3.7}/dashlab.egg-info/SOURCES.txt +0 -0
  20. {dashlab-0.3.6 → dashlab-0.3.7}/dashlab.egg-info/dependency_links.txt +0 -0
  21. {dashlab-0.3.6 → dashlab-0.3.7}/dashlab.egg-info/requires.txt +0 -0
  22. {dashlab-0.3.6 → dashlab-0.3.7}/dashlab.egg-info/top_level.txt +0 -0
  23. {dashlab-0.3.6 → dashlab-0.3.7}/pyproject.toml +0 -0
  24. {dashlab-0.3.6 → dashlab-0.3.7}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dashlab
3
- Version: 0.3.6
3
+ Version: 0.3.7
4
4
  Summary: A Python package for dashboard and data visualization tools.
5
5
  Author-email: Abdul Saboor <asaboor.my@outlook.com>
6
6
  License-Expression: MIT
@@ -1,4 +1,4 @@
1
1
  # This is automatically updated at build time, do not edit manually.
2
2
  # Double qoites are checked here
3
3
 
4
- __version__ = "0.3.6"
4
+ __version__ = "0.3.7"
@@ -2,6 +2,7 @@ import inspect, re, sys, textwrap
2
2
  import ipywidgets as ipw
3
3
 
4
4
  from contextlib import contextmanager
5
+ from pathlib import Path
5
6
  from IPython.core.ultratb import AutoFormattedTB
6
7
  from ipywidgets import DOMWidget
7
8
 
@@ -94,6 +95,19 @@ def _validate_key(key):
94
95
  key = key.replace(f'{match}',match.replace(',','$'),1) # Make safe from splitting with comma
95
96
  return key
96
97
 
98
+ def _handle_raw_css(value):
99
+ "Handle raw CSS from string or Path object."
100
+ if not isinstance(value, (str, Path)):
101
+ raise TypeError("Raw CSS value for empty key must be string or file path!")
102
+
103
+ if isinstance(value, Path):
104
+ value = value.read_text()
105
+ elif Path(value).is_file():
106
+ value = Path(value).read_text()
107
+
108
+ value = '\n'.join(line.strip() for line in value.splitlines()) # Clean extra spaces
109
+ return value
110
+
97
111
  def _build_css(selector, props):
98
112
  """
99
113
  CSS is formatted using a `props` nested dictionary to simplify the process.
@@ -103,8 +117,8 @@ def _build_css(selector, props):
103
117
  - All nested selectors are joined with space, so code`'.A': {'.B': ... }` becomes code['css']`.A .B {...}` in CSS.
104
118
  - A '^' in start of a selector joins to parent selector without space, so code`'.A': {'^:hover': ...}` becomes code['css']`.A:hover {...}` in CSS. You can also use code`'.A:hover'` directly but it will restrict other nested keys to hover only.
105
119
  - A list/tuple of values for a key in dict generates CSS fallback, so code`'.A': {'font-size': ('20px','2em')}` becomes code['css']`.A {font-size: 20px; font-size: 2em;}` in CSS.
106
- - An empty key with a string value injects direct CSS wrapped in code['css']`@scope`, so code`'.A': {'': 'raw css here'}` becomes code['css']`@scope (.A) { raw css here }` in CSS.
107
- This can be used to inject complex CSS like `@import`, `@font-face`, `@layer` etc. `:root` is replaced with `:scope` to make variables local to the selector.
120
+ - An empty key with a string/path value injects raw CSS wrapped in nested code['css']`&`, so code`'.A': {'': 'raw css here'}` becomes code['css']`& { .A { raw css here } }` in CSS.
121
+ This, however, can NOT be used to inject complex CSS like `@import`, `@layer` etc. `:root` is replaced with `&` to make variables local to the selector at given nesting level.
108
122
 
109
123
  Read about specificity of CSS selectors [here](https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity).
110
124
  """
@@ -115,11 +129,12 @@ def _build_css(selector, props):
115
129
 
116
130
  for key, value in props.items():
117
131
  key = _validate_key(key) # Just validate key
118
- if not key.strip() and isinstance(value, str): # Empty key with string value is direct CSS
119
- value = '\n'.join(line.strip() for line in value.splitlines()) # Clean extra spaces
120
- value = value.replace(':root',':scope') # Take external root to scope
121
- content += ("@scope (" + " ".join(selector) + ") {\n")
122
- content += (textwrap.indent(value, '\t')+ "\n}\n")
132
+ if not key.strip(): # Empty key with string value is direct CSS
133
+ # We can't handle complex @import, @charset here since that neede to be at root level, and we have scattered styles everywhere
134
+ value = _handle_raw_css(value)
135
+ value = value.replace(':root','&') # Take external root to this scope only
136
+ content += (" ".join(selector) + " {\n\t & {\n") # nested scope with added spcificity
137
+ content += (textwrap.indent(value, '\t\t') + "\n\t}\n}\n")
123
138
  continue
124
139
 
125
140
  if isinstance(value, dict):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dashlab
3
- Version: 0.3.6
3
+ Version: 0.3.7
4
4
  Summary: A Python package for dashboard and data visualization tools.
5
5
  Author-email: Abdul Saboor <asaboor.my@outlook.com>
6
6
  License-Expression: MIT
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes