Skip to content

Commit 47f92b7

Browse files
committed
migrate new costume style syntax
1 parent 7790d9f commit 47f92b7

File tree

4 files changed

+22
-24
lines changed

4 files changed

+22
-24
lines changed

demos/__main__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from demos.gomoku_game import main as gomoku_game
1313

1414
from pywebio import STATIC_PATH
15-
from pywebio.output import put_markdown, put_row, put_html, style
15+
from pywebio.output import put_markdown, put_row, put_html
1616
from pywebio.platform.tornado import webio_handler
1717
from pywebio.session import info as session_info
1818
from tornado.options import define, options
@@ -109,10 +109,10 @@ def index():
109109
Basic demo and data visualization demo of PyWebIO.
110110
PyWebIO的基本demo和数据可视化demo
111111
"""
112-
style(put_row([
112+
put_row([
113113
put_markdown('# PyWebIO demos'),
114114
put_html('<a class="github-button" data-size="large" href="https://github.com/wang0618/PyWebIO" data-show-count="true" aria-label="Star wang0618/PyWebIO on GitHub">Star</a>')
115-
], size='1fr auto'), 'align-items:center')
115+
], size='1fr auto').style('align-items:center')
116116
put_html('<script async defer src="https://buttons.github.io/buttons.js"></script>')
117117

118118
if 'zh' in session_info.user_language:

pywebio/io_ctrl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def __init__(self, spec, on_embed=None):
7575
# For Context manager
7676
self.enabled_context_manager = False
7777
self.container_selector = None
78-
self.container_dom_id = None
78+
self.container_dom_id = None # todo: this name is ambiguous, rename it to `scope_name` or others
7979
self.custom_enter = None
8080
self.custom_exit = None
8181

pywebio/output.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ def put_code(content, language='', rows=None, scope=Scope.Current, position=Outp
426426
out = put_markdown(code, scope=scope, position=position)
427427
if rows is not None:
428428
max_height = rows * 19 + 32 # 32 is the code css padding
429-
out = style(out, "max-height: %spx" % max_height)
429+
out.style("max-height: %spx" % max_height)
430430
return out
431431

432432

@@ -921,15 +921,15 @@ def put_loading(shape='border', color='dark', scope=Scope.Current, position=Outp
921921
<span class="sr-only">Loading...</span>
922922
</div>""".format(shape=shape, color=color)
923923

924-
dom_id = random_str(10)
924+
scope_name = random_str(10)
925925

926926
def enter(self):
927-
self.spec['container_dom_id'] = scope2dom(dom_id, no_css_selector=True)
927+
self.spec['container_dom_id'] = scope2dom(scope_name, no_css_selector=True)
928928
self.send()
929-
return dom_id
929+
return scope_name
930930

931931
def exit_(self, exc_type, exc_val, exc_tb):
932-
remove(dom_id)
932+
remove(scope_name)
933933
return False # Propagate Exception
934934

935935
return put_html(html, sanitize=False, scope=scope, position=position). \
@@ -1266,7 +1266,7 @@ def put_grid(content, cell_width='auto', cell_height='auto', cell_widths=None, c
12661266

12671267
css = 'grid-row-start: span {row}; grid-column-start: span {col};'.format(row=cell.row, col=cell.col)
12681268
elem = put_html('<div></div>') if cell.content is None else cell.content
1269-
content[x][y] = style(elem, css)
1269+
content[x][y] = elem.style(css)
12701270
else:
12711271
lens[x] += 1
12721272

test/template.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,22 +61,20 @@ def basic_output():
6161
put_html("<hr/>")
6262

6363
put_markdown('### Style')
64-
style(put_text('Red'), 'color:red')
64+
put_text('Red').style('color:red')
6565

66-
style([
67-
put_text('Red'),
68-
put_markdown('~~del~~')
69-
], 'color:red')
66+
put_text('Red').style('color:red')
67+
put_markdown('~~del~~').style('color:red')
7068

7169
put_table([
7270
['A', 'B'],
73-
['C', style(put_text('Red'), 'color:red')],
71+
['C', put_text('Red').style('color:red')],
7472
])
7573

76-
put_collapse('title', style([
77-
put_text('text'),
78-
put_markdown('~~del~~'),
79-
], 'margin-left:20px'), open=True)
74+
put_collapse('title', [
75+
put_text('text').style('margin-left:20px'),
76+
put_markdown('~~del~~').style('margin-left:20px'),
77+
], open=True)
8078

8179
put_markdown('### Table')
8280
put_table([
@@ -256,18 +254,18 @@ def edit_row(choice, row):
256254
put_code('C'),
257255
]), None,
258256
put_code('python'), None,
259-
style(put_code('python\n' * 20), 'max-height:200px;'),
257+
put_code('python\n' * 20).style('max-height:200px;'),
260258
])
261259

262260
put_grid([
263-
[style(put_code('[%s,%s]' % (x, y)), 'margin-right:10px;') for y in range(4)]
261+
[put_code('[%s,%s]' % (x, y)).style('margin-right:10px;') for y in range(4)]
264262
for x in range(5)
265263
], direction='column')
266264

267-
put_row([style(put_code(i), 'margin-right:10px;') for i in range(4)], 'repeat(auto-fill, 25%)')
265+
put_row([put_code(i).style('margin-right:10px;') for i in range(4)], 'repeat(auto-fill, 25%)')
268266

269267
put_markdown('### Span')
270-
cell = lambda text: style(put_code(text), 'margin-right:10px;')
268+
cell = lambda text: put_code(text).style('margin-right:10px;')
271269
put_grid([
272270
[span(cell('A'), col=2), None],
273271
[span(cell('C'), row=2, col=2), span(cell('D'), row=2)],

0 commit comments

Comments
 (0)