-
-
Notifications
You must be signed in to change notification settings - Fork 477
/
float.py
228 lines (199 loc) · 7.29 KB
/
float.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
from __future__ import annotations
from typing import ClassVar, List
import param
from ..config import config as pn_config
from ..io.resources import CDN_DIST, bundled_files
from ..reactive import ReactiveHTML
from ..util import classproperty
from .base import ListLike
POSITIONS = [
'center',
'left-top',
'center-top',
'right-top',
'right-center',
'right-bottom',
'center-bottom',
'left-bottom',
'left-center',
]
STATUS = [
"normalized",
"maximized",
"minimized",
"smallified",
"smallifiedmax",
"closed"
]
class FloatPanel(ListLike, ReactiveHTML):
"""
Float provides a floating panel layout.
"""
config = param.Dict({}, doc="""
Additional jsPanel configuration with precedence over
parameter values.""")
contained = param.Boolean(default=True, doc="""
Whether the component is contained within parent container
or completely free floating.""")
position = param.Selector(default='right-top', objects=POSITIONS, doc="""
The initial position if the container is free-floating.""")
offsetx = param.Integer(default=None, bounds=(0, None), doc="""
Horizontal offset in pixels.""")
offsety = param.Integer(default=None, bounds=(0, None), doc="""
Vertical offset in pixels.""")
theme = param.String(default="primary", doc="""
The theme which can be one of:
- Built-ins: 'default', 'primary', 'secondary', 'info',
'success', 'warning', 'danger', 'light', 'dark' and 'none'
- HEX, RGB and HSL color values like '#123456' Any
standardized color name like 'forestgreen' and color names
from the Material Design Color System like 'purple900'
- Additionally a theme string may include one of the modifiers
'filled', 'filledlight', 'filleddark' or 'fillcolor'
separated from the theme color by a space like 'primary""")
status = param.Selector(default="normalized", objects=STATUS, doc="""
The current status of the panel.""")
_extension_name = 'floatpanel'
_template = """
<div id="float" class="bk-root" style="padding:8px;padding-right:30px">
{% for obj in objects %}
<div id="flex-item">${obj}</div>
{% endfor %}
</div>
"""
_rename = {'loading': None}
_scripts = {
"render": """
if (state.panel) {
view.run_script('close')
}
var config = {
headerTitle: data.name,
content: float,
theme: data.theme,
id: 'jsPanel'+data.id,
position: view.run_script('get_position'),
contentSize: `${model.width} ${model.height}`,
onstatuschange: function() {
data.status = this.status
},
onbeforeclose: function() {
data.status = 'closed'
return true
},
}
if (data.contained) {
config.container = view.container
}
config = {...config, ...data.config}
state.panel = jsPanel.create(config);
if (data.status !== 'normalized') {
view.run_script('status')
}
state.resizeHandler = (event) => {
if (event.panel === state.panel) {
view.invalidate_layout()
}
}
document.addEventListener('jspanelresizestop', state.resizeHandler, false)
""",
"name": "state.panel.setHeaderTitle(data.name)",
"status": """
var action = data.status.replace('ied', 'y').replace('d', '')
if (action === 'close') {
state.closed = true
} else if (state.closed) {
view.run_script('close')
return
}
state.panel[action]()
""",
"close": "try { state.panel.close() } catch {}",
"get_position": """
return {
at: data.position,
my: data.position,
offsetX: data.offsetx,
offsetY: data.offsety,
}
""",
"reposition": """
if (data.contained) {
view.run_script('contained')
return
}
state.panel.reposition(view.run_script('get_position'));
""",
"contained": "delete state.panel; view.invalidate_render();",
"theme": "state.panel.setTheme(data.theme)",
"remove": """
document.removeEventListener('jspanelresizestop', state.resizeHandler, false);
view.run_script('close');
state.panel = undefined;
""",
"offsetx": "view.run_script('reposition')",
"offsety": "view.run_script('reposition')",
"position": "if (!data.contained) { view.run_script('reposition') }",
}
__css_raw__ = [f"{pn_config.npm_cdn}/jspanel4@4.12.0/dist/jspanel.css"]
__javascript_raw__ = [
f"{pn_config.npm_cdn}/jspanel4@4.12.0/dist/jspanel.js",
f"{pn_config.npm_cdn}/jspanel4@4.12.0/dist/extensions/modal/jspanel.modal.js",
f"{pn_config.npm_cdn}/jspanel4@4.12.0/dist/extensions/tooltip/jspanel.tooltip.js",
f"{pn_config.npm_cdn}/jspanel4@4.12.0/dist/extensions/hint/jspanel.hint.js",
f"{pn_config.npm_cdn}/jspanel4@4.12.0/dist/extensions/layout/jspanel.layout.js",
f"{pn_config.npm_cdn}/jspanel4@4.12.0/dist/extensions/contextmenu/jspanel.contextmenu.js",
f"{pn_config.npm_cdn}/jspanel4@4.12.0/dist/extensions/dock/jspanel.dock.js",
]
__js_require__ = {
'paths': {
'jspanel': f"{pn_config.npm_cdn}/jspanel4@4.12.0/dist/jspanel",
'jspanel-modal': f"{pn_config.npm_cdn}/jspanel4@4.12.0/dist/extensions/modal/jspanel.modal",
'jspanel-tooltip': f"{pn_config.npm_cdn}/jspanel4@4.12.0/dist/extensions/tooltip/jspanel.tooltip",
'jspanel-hint': f"{pn_config.npm_cdn}/jspanel4@4.12.0/dist/extensions/hint/jspanel.hint",
'jspanel-layout': f"{pn_config.npm_cdn}/jspanel4@4.12.0/dist/extensions/layout/jspanel.layout",
'jspanel-contextmenu': f"{pn_config.npm_cdn}/jspanel4@4.12.0/dist/extensions/contextmenu/jspanel.contextmenu",
'jspanel-dock': f"{pn_config.npm_cdn}/jspanel4@4.12.0/dist/extensions/dock/jspanel.dock",
},
'exports': {
'jspanel': 'jsPanel'
},
'shim': {
'jspanel': {
'exports': 'jsPanel'
}
}
}
_stylesheets: ClassVar[List[str]] = [
f'{CDN_DIST}css/floatpanel.css'
]
@classproperty
def __js_skip__(cls):
return {
'jsPanel': cls.__javascript__,
}
@classproperty
def __javascript__(cls):
return bundled_files(cls)
@classproperty
def __css__(cls):
return bundled_files(cls, 'css')
def __init__(self, *objects, name='', **params):
super().__init__(objects=list(objects), name=name, **params)
def select(self, selector=None):
"""
Iterates over the Viewable and any potential children in the
applying the Selector.
Arguments
---------
selector: type or callable or None
The selector allows selecting a subset of Viewables by
declaring a type or callable function to filter by.
Returns
-------
viewables: list(Viewable)
"""
objects = super().select(selector)
for obj in self:
objects += obj.select(selector)
return objects