Add iframes

Trying more fluid experience with iframes.
This commit is contained in:
Sasha MOREL 2021-09-05 13:42:00 +02:00
parent 3dc6d4323b
commit 44255d6bc2
1 changed files with 24 additions and 10 deletions

34
sms.py
View File

@ -27,7 +27,7 @@ def html_header (title = 'No title'):
return ('<html>\n<head>\n\t<title>' + title + '</title>\n' + '''\t<style> return ('<html>\n<head>\n\t<title>' + title + '</title>\n' + '''\t<style>
body { body {
margin: 0 auto; margin: 0 auto;
max-width: 800px; max-width: 100%;
padding: 0 20px; padding: 0 20px;
} }
@ -80,6 +80,14 @@ def html_title (text):
return ('\n\t<h1>' + text + '</h1>') return ('\n\t<h1>' + text + '</h1>')
def html_iframe (src, height = '150', width = '300', name = None, style = 'border:none;'):
r = '<iframe src="' + src + '" width="' + width + '" height="' + height + '" style="' + style + '"'
if name is not None:
r += ' name="' + name + '"'
r += '></iframe>'
return (r)
def html_paragraph (text): def html_paragraph (text):
return ('\n\t<p>' + text + '</p>') return ('\n\t<p>' + text + '</p>')
@ -92,10 +100,10 @@ def html_list (lst):
return (t) return (t)
def html_link (url, text = None): def html_link (url, text = None, target = '_self'):
if text is None: if text is None:
text = url text = url
return ('<a href="' + url + '">' + text + '</a>') return ('<a href="' + url + '" target="' + target + '">' + text + '</a>')
def html_table (body, table_style = None, cell_style = None): def html_table (body, table_style = None, cell_style = None):
@ -253,6 +261,15 @@ class Web_Service (BaseHTTPRequestHandler):
if locked_client == client: if locked_client == client:
global sms global sms
if self.path == '/': if self.path == '/':
self.send_response (200)
self.send_header ('Content-type', 'text/html; charset=UTF-8')
self.end_headers ()
self.wfile.write ((
html_header (title = 'Termux WebSMS') +
html_iframe ('/list', height = '100%', width = '30%', name = 'list') + html_iframe ('about:blank', height = '100%', width = '70%', name = 'messages') +
html_footer ()
).encode ('utf-8'))
elif self.path == '/list':
self.send_response (200) self.send_response (200)
self.send_header ('Content-type', 'text/html; charset=UTF-8') self.send_header ('Content-type', 'text/html; charset=UTF-8')
self.end_headers () self.end_headers ()
@ -262,14 +279,14 @@ class Web_Service (BaseHTTPRequestHandler):
s = ls [i] [0] + ' (' + str (ls [i] [3]) + ')' s = ls [i] [0] + ' (' + str (ls [i] [3]) + ')'
if len (ls [i]) == 5: if len (ls [i]) == 5:
s = ls [i] [4] + ' (' + str (ls [i] [3]) + ')' s = ls [i] [4] + ' (' + str (ls [i] [3]) + ')'
lst.append ([html_link ('/?thread=' + str (i), text = s), ls [i] [1], ls [i] [2] [0:50]]) lst.append (html_link ('/?thread=' + str (i), text = s, target = 'messages'))
self.wfile.write (( self.wfile.write ((
html_header (title = 'Conversations list') + html_header (title = 'Conversations list') +
html_title ('Conversation') + html_title ('Conversation') +
html_paragraph (html_link ('/new', text = 'New conversation')) + html_paragraph (html_link ('/new', text = 'New conversation', target = 'messages')) +
html_paragraph (html_link ('/', text = 'Refresh list')) + html_paragraph (html_link ('/list', text = 'Refresh list')) +
html_paragraph ('List of conversations follows:') + html_paragraph ('List of conversations follows:') +
html_table (lst) + html_list (lst) +
html_footer () html_footer ()
).encode ('utf-8')) ).encode ('utf-8'))
elif self.path == '/new': elif self.path == '/new':
@ -282,7 +299,6 @@ class Web_Service (BaseHTTPRequestHandler):
lst.append (html_link ('/new?num=' + quote (i ['number']), text = i ['name'] + ' (' + i ['number'] + ')')) lst.append (html_link ('/new?num=' + quote (i ['number']), text = i ['name'] + ' (' + i ['number'] + ')'))
self.wfile.write (( self.wfile.write ((
html_header (title = 'New conversation') + html_header (title = 'New conversation') +
html_paragraph (html_link ('/', text = '← Back to list')) +
html_title ('Create a new conversation') + html_title ('Create a new conversation') +
html_paragraph ('Put number here:') + html_paragraph ('Put number here:') +
html_form ( html_form (
@ -302,7 +318,6 @@ class Web_Service (BaseHTTPRequestHandler):
number = self.path [9:] number = self.path [9:]
self.wfile.write (( self.wfile.write ((
html_header (title = 'New conversation') + html_header (title = 'New conversation') +
html_paragraph (html_link ('/', text = '← Back to list')) +
html_paragraph (html_link ('/new', text = '← Back to new message')) + html_paragraph (html_link ('/new', text = '← Back to new message')) +
html_title ('Create a new conversation with ' + unquote (number)) + html_title ('Create a new conversation with ' + unquote (number)) +
html_paragraph ('Message:') + html_paragraph ('Message:') +
@ -343,7 +358,6 @@ class Web_Service (BaseHTTPRequestHandler):
name = name + ' (' + number + ')' name = name + ' (' + number + ')'
self.wfile.write (( self.wfile.write ((
html_header (title = 'Conversation with ' + name) + html_header (title = 'Conversation with ' + name) +
html_paragraph (html_link ('/', text = '← Back to list')) +
html_title (name) + html_title (name) +
html_form ( html_form (
html_form_text ('msg', textarea = True) + html_form_text ('msg', textarea = True) +