Skip to content

Commit 1252622

Browse files
committed
Trying to structure PAGE elements, in order to allow accessing them as standard tags/widgets. This will make it easier to interface body events.
1 parent b64c7e6 commit 1252622

2 files changed

Lines changed: 54 additions & 2 deletions

File tree

remi/gui.py

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,55 @@ def onchange(self):
235235
return ()
236236

237237

238+
class HTML(Tag):
239+
def __init__(self, **kwargs):
240+
super(HTML, self).__init__(*args, **kwargs, _type='html')
241+
242+
head = HEAD()
243+
body = BODY()
244+
self.add_child('head', head)
245+
self.add_child('body', body)
246+
247+
248+
class HEAD(Tag):
249+
def __init__(self, title, js, css, html, **kwargs):
250+
super(HEAD, self).__init__(*args, **kwargs, _type='head')
251+
self.add_child('meta',
252+
"""<meta content='text/html;charset=utf-8' http-equiv='Content-Type'>
253+
<meta content='utf-8' http-equiv='encoding'>
254+
<meta name="viewport" content="width=device-width, initial-scale=1.0">""")
255+
256+
self.set_css(css)
257+
self.set_html(html)
258+
self.set_javascript(js)
259+
self.set_title(title)
260+
261+
def set_javascript(self, js):
262+
self.add_child("js", js)
263+
264+
def set_html(self, html):
265+
self.add_child("html", html)
266+
267+
def set_css(self, css):
268+
self.add_child("css", css)
269+
270+
def set_title(self, title):
271+
self.add_child('title', "<title>%s</title>" % title)
272+
273+
274+
class BODY(Widget):
275+
EVENT_ONLOAD = 'onload'
276+
277+
def __init__(self, *args, **kwargs):
278+
super(BODY, self).__init__(*args, **kwargs, _type='body')
279+
loading_anim = Widget()
280+
loading_anim.set_identifier("loading-animation")
281+
loading_widget = Widget(children=[loading_anim])
282+
loading_widget.set_identifier("loading")
283+
284+
self.append(loading_widget)
285+
286+
238287
class Tag(object):
239288
"""
240289
Tag is the base class of the framework. It represents an element that can be added to the GUI,
@@ -333,7 +382,8 @@ def _need_update(self, emitter=None):
333382
#if there is an emitter, it means self is the actual changed widget
334383
if emitter:
335384
tmp = dict(self.attributes)
336-
tmp['style'] = jsonize(self.style)
385+
if len(self.style):
386+
tmp['style'] = jsonize(self.style)
337387
self._repr_attributes = ' '.join('%s="%s"' % (k, v) if v is not None else k for k, v in
338388
tmp.items())
339389
if not self.ignore_update:
@@ -356,7 +406,8 @@ def enable_refresh(self):
356406

357407
def add_class(self, cls):
358408
self._classes.append(cls)
359-
self.attributes['class'] = ' '.join(self._classes) if self._classes else ''
409+
if len(self._classes):
410+
self.attributes['class'] = ' '.join(self._classes) if self._classes else ''
360411

361412
def remove_class(self, cls):
362413
try:

remi/server.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,7 @@ def _process_all(self, func):
848848
self.send_header('Content-type', 'text/html')
849849
self.end_headers()
850850
self.wfile.write(encode_text("<!DOCTYPE html>\n"))
851+
851852
self.wfile.write(encode_text("<html>\n<head>\n"))
852853
self.wfile.write(encode_text(
853854
"""<meta content='text/html;charset=utf-8' http-equiv='Content-Type'>

0 commit comments

Comments
 (0)