Skip to content

Instantly share code, notes, and snippets.

@Reyuu
Created March 19, 2020 23:25
Show Gist options
  • Save Reyuu/3fe195633f987cd671f4e9a0decd0ac6 to your computer and use it in GitHub Desktop.
Save Reyuu/3fe195633f987cd671f4e9a0decd0ac6 to your computer and use it in GitHub Desktop.
Example pywebview
import webview
import jinja2
def load_css(window):
with open("style.css") as f:
window.load_css(f.read())
def create_html(*args, **kwargs):
templateloader = jinja2.FileSystemLoader(searchpath="./")
templateEnv = jinja2.Environment(loader=templateloader)
TEMPLATE_FILE = "template.html"
template = templateEnv.get_template(TEMPLATE_FILE)
outputText = template.render(*args, **kwargs)
if debug:
with open("debug.html", "w") as f:
f.write(outputText)
return outputText
if __name__ == '__main__':
debug = True
subject = "This is an example subject"
description = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."
ticket_created_at = "20170303"
requester = "Another Doe"
comments = [
{"author": "John Doe", "created_at": "20170303", "content": "That's a great idea! <br> Working!!" },
{"author": "John Doe", "created_at": "20170303", "content": "That's a great idea! <br> Working!!" },
{"author": "John Doe", "created_at": "20170303", "content": "That's a great idea! <br> Working!!" },
{"author": "John Doe", "created_at": "20170303", "content": "That's a great idea! <br> Working!!" },
{"author": "John Doe", "created_at": "20170303", "content": "That's a great idea! <br> Working!!" }
]
window = webview.create_window('Load HTML Example', frameless=True, text_select=False, html=create_html(subject=subject,
requester=requester,
comments=comments,
description=description,
created_at=ticket_created_at,
debug=debug
))
webview.start(load_css, window, debug=debug)
@import url("https://fonts.googleapis.com/css?family=Asap|Baloo+Bhaina+2&display=swap");
* .body {
padding: 10px;
font-family: "Asap", sans-serif;
color: #000;
}
* .body .main {
border-top-left-radius: 10px;
border-top-right-radius: 10px;
background-color: #ffca7a;
padding: 5px;
border-bottom: solid #000 0.1rem;
}
* .body .main h3 {
font-size: 1.7em;
margin-left: 30px;
}
* .body .main span {
margin-left: 20px;
padding: 5px;
border-radius: 10px;
}
* .body .main div {
padding: 5px;
margin-top: 20px;
border-top-left-radius: 10px;
border-top-right-radius: 10px;
border-style: solid;
border-color: #ffab2d;
border-width: 0.1rem;
background: #fff2e0;
}
* .body .comment {
border-top-left-radius: 10px;
border-top-right-radius: 10px;
background-color: #ffca7a;
margin-top: 20px;
padding-top: 5px;
padding-left: 5px;
padding-right: 5px;
border-bottom: solid #000 0.1rem;
}
* .body .comment div {
padding: 5px;
}
* .body .comment div span {
margin-left: 20px;
padding: 5px;
border-radius: 10px;
font-size: 0.8em;
}
* .body .comment div span + span {
padding-left: 20px;
}
* .body .comment div + div {
border-top-left-radius: 10px;
border-top-right-radius: 10px;
border-style: solid;
border-color: #ffab2d;
border-width: 0.1rem;
background: #fff2e0;
}
* .body .comment-internal {
background-color: #ffab2d;
}
/*# sourceMappingURL=style.css.map */
$primary: rgb(255, 171, 45);
$text-color: #000;
@import url('https://fonts.googleapis.com/css?family=Asap|Baloo+Bhaina+2&display=swap');
*{
.body{
//background-color: $primary;
padding: 10px;
font-family: "Asap", sans-serif;
color: $text-color;
.main{
border-top-left-radius: 10px;
border-top-right-radius: 10px;
background-color: lighten($primary, 15%);
padding: 5px;
border-bottom: solid #000 0.1rem;
h3{
font-size: 1.7em;
margin-left: 30px;
}
span{
margin-left: 20px;
padding: 5px;
border-radius: 10px;
//background-color: $primary;
}
div{
padding: 5px;
margin-top: 20px;
border-top-left-radius: 10px;
border-top-right-radius: 10px;
border-style: solid;
border-color: $primary;
border-width: 0.1rem;
background: lighten($primary, 35%);
}
}
.comment{
border-top-left-radius: 10px;
border-top-right-radius: 10px;
background-color: lighten($primary, 15%);
margin-top: 20px;
padding-top: 5px;
padding-left: 5px;
padding-right: 5px;
border-bottom: solid #000 0.1rem;
div{
padding: 5px;
span{
margin-left: 20px;
padding: 5px;
border-radius: 10px;
font-size: 0.8em;
//background-color: $primary;
}
span+span{
padding-left: 20px;
}
}
div+div{
border-top-left-radius: 10px;
border-top-right-radius: 10px;
border-style: solid;
border-color: $primary;
border-width: 0.1rem;
background: lighten($primary, 35%);
}
}
.comment-internal{
background-color: $primary;
}
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="./style.css">
</head>
<body>
<div class="body">
<div class="main">
<h3>{{ subject }}</h3>
<span>Author: {{ requester }}</span><span>Created at: {{ created_at }}</span>
<div>{{ description }}</div>
</div>
{% for comment in comments %}
<div class="comment">
<div><span>Author: {{ comment.author }}</span><span>Created at: {{ comment.created_at }}</span></div>
<div>{{ comment.content }}</div>
</div>
{% endfor %}
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment