diff --git a/src/app.py b/src/app.py index 9c737e5..27bf7dc 100755 --- a/src/app.py +++ b/src/app.py @@ -1,8 +1,9 @@ #!/usr/bin/env python3 #coding: utf-8 -from flask import Flask, render_template, Markup, request, redirect, url_for +from flask import Flask, render_template, Markup, request, redirect, url_for, make_response from classes import note -from funcs import dumpnotes, getnotes, catnotes, delnote, findnote, addnote, mknotedir, exportnotes +from funcs import dumpnotes, getnotes, catnotes, delnote, findnote, addnote, mknotedir, exportnotes, getthemes +from random import choice #!---------- squiNotes.py ---------- # My notes-taking app @@ -12,9 +13,25 @@ from funcs import dumpnotes, getnotes, catnotes, delnote, findnote, addnote, mkn #----------! MAIN app = Flask(__name__) mknotedir() +#Theme variable will be made global in every flask function +#css path will then be deducted @app.route('/', methods=['GET']) def render(): + #Does the user have a theme ? + #theme list + themes = getthemes() + + #Setting default theme if the user does not have one... + if request.cookies.get('csslink') is None: + csslink = themes[0] + resp = make_response(render_template("homepage.html", nr = catnotes(getnotes()), csslink = csslink)) + resp.set_cookie("csslink", csslink) + #...or using their preferred theme if do have one + else: + csslink = request.cookies.get('csslink') + resp = make_response(render_template("homepage.html", nr = catnotes(getnotes()), csslink = csslink)) + #Delete has been clicked try: todelete = request.args.get("delete") @@ -31,43 +48,66 @@ def render(): except Exception as e: pass + #Switch theme has been clicked + try: + switchpls = request.args.get("switchpls") + if switchpls is not None: + #Clicking "Change theme" switches to a random (other) theme + current = csslink + while csslink == current: + csslink = choice(themes) + + #Commiting new theme, setting cookie for it, return template + resp = make_response(render_template("homepage.html", nr = catnotes(getnotes()), csslink = csslink)) + resp.set_cookie('csslink', csslink) + return resp + + except Exception as e: + pass + #Read has been clicked try: toread = request.args.get("toread") if toread is not None: return redirect(url_for('readmode', note=(int(toread)))) except Exception as e: - print(e) pass - return render_template("homepage.html", nr = catnotes(getnotes())) + return resp #Export mode @app.route('/export', methods=['GET']) def rawnotes(): + #No theme in export return render_template("export.html", rawnotes = exportnotes()) #Read mode @app.route('/readmode', methods=['GET','POST']) def readmode(): + #theme + csslink = request.cookies.get('csslink') + + + #Render page if request.method == 'GET': notenumber = request.args.get("note") mynote = findnote(int(notenumber)) - return render_template("read.html", note=mynote.flaskrender()) + return render_template("read.html", note=mynote.flaskrender(), csslink = csslink) #Edition mode @app.route('/edit', methods=['GET', 'POST']) def edit(): import time + #theme + csslink = request.cookies.get('csslink') + + #Render edition page if request.method == "GET": - print("GET") notenumber = request.args.get("notenumber") mynote = findnote(int(notenumber)) - return render_template("edit.html", notenumber=notenumber, ntitle=mynote.title, ntext=mynote.text) + return render_template("edit.html", notenumber=notenumber, ntitle=mynote.title, ntext=mynote.text, csslink = csslink) if request.method == "POST": - print("POST") - print(request.args.get("submit")) notetitle = request.form['title'] notetext = request.form['text'] notenumber = int(request.form['notenumber']) @@ -75,13 +115,17 @@ def edit(): rightnow = int(time.time()) newnote = note(createtime=notenumber, modtime=rightnow, title=notetitle, text=notetext) addnote(newnote) - return render_template("read.html", note=newnote.flaskrender()) + return render_template("read.html", note=newnote.flaskrender(), csslink = csslink) #Basic route, allows note creation @app.route('/', methods=['POST']) def homepage(): import time + + #theme + csslink = request.cookies.get('csslink') + #New note try: notetitle = request.form['title'] @@ -91,9 +135,7 @@ def homepage(): addnote(newnote) except: pass - return render_template("homepage.html", nr = catnotes(getnotes())) - - + return render_template("homepage.html", nr = catnotes(getnotes()), csslink = csslink) if __name__ == '__main__': app.run(host="0.0.0.0") diff --git a/src/funcs.py b/src/funcs.py index 3a32553..bfb38bf 100644 --- a/src/funcs.py +++ b/src/funcs.py @@ -94,3 +94,22 @@ def exportnotes(): return +def getthemes(): + """ + Find all themes present in our css folder and return a nice list of + css links, for the user to pick into + """ + from flask import url_for + from os import listdir + + allfiles = listdir("./static/styles") + themefiles, themes = [], [] + for myfile in allfiles: + if myfile.endswith(".css"): + themefiles.append(myfile) + + for themefile in themefiles: + themes.append(url_for('static', filename=f'styles/{themefile}')) + + return themes + diff --git a/src/static/styles/main.css b/src/static/styles/0-dracula.css similarity index 99% rename from src/static/styles/main.css rename to src/static/styles/0-dracula.css index 58cf0f6..2d48d04 100644 --- a/src/static/styles/main.css +++ b/src/static/styles/0-dracula.css @@ -73,6 +73,10 @@ a { font-size: 1em; } +.themebutton { + float: right; +} + .exportlink { float: right; } diff --git a/src/static/styles/1-lightcula.css b/src/static/styles/1-lightcula.css new file mode 100644 index 0000000..7556d1b --- /dev/null +++ b/src/static/styles/1-lightcula.css @@ -0,0 +1,230 @@ +@font-face { + font-family: "Work Sans"; + src: url(WorkSans-Regular.ttf); +} + +@font-face { + font-family: "Work Sans"; + src: url(WorkSans-Bold.ttf); + font-weight: bold; +} + +@font-face { + font-family: "Work Sans"; + src: url(WorkSans-Italic.ttf); + font-style: italic; +} + +@font-face { + font-family: "Work Sans"; + src: url(WorkSans-BoldItalic.ttf); + font-weight: bold; + font-style: italic; +} + + +html { + background-color: white; + font-family: 'Work Sans'; + color: #f8f8f2; +} + +h1 { + color: #50fa7b; +} + +h2 { + color: #50fa7b; +} + +h3 { + color: #50fa7b; +} + +h4 { + color: #50fa7b; +} + +h5 { + color: #50fa7b; +} + +button { + background-color: #22242e; + border: none; + color: #8be9fd; + padding: 1px 2px; + text-align: left; + text-decoration: none; + display: inline-block; + font-size: 1em; + font-style: italic; + cursor: pointer; +} + +hr { + border: 3px dotted; +} + +a { + color: #8be9fd; + text-decoration: underline; + font-style: italic; + font-size: 1em; +} + +.themebutton { + float: right; +} + +.exportlink { + float: right; +} + +.pagetitle { + font-size: 3em; + color: #ff79c6; + float: left; +} + + +.notetitle { + color: #ff79c6; + font-size: 2em; +} + +.notetime { + color: #6272a4; + font-style: italic; +} + +/* +.title { + background: #44475a; + color: #50fa7b; + font-weight: bold; + font-size: 2em + border-style: none; + border-radius: 1px; + outline: none; + border-width: 1px; +} +*/ + +.text { + font-family: 'Noto Sans'; + width: 100%; + background: #44475a; + color: #f8f8f2; + border-radius: 5px; + border-style: none; + outline: none; + border-width: 1px; + height: 80%; + font-size: 15px; + -webkit-box-shadow: 0 3px 6px rgba(0,0,0,.16),0 3px 6px rgba(0,0,0,.23); +} + +.title { + font-family: 'Noto Sans'; + width: 100%; + background: #44475a; + color: #f8f8f2; + border-radius: 5px; + border-style: none; + outline: none; + border-width: 1px; + height: 25px; + margin: 5px 0px 5px 0px; + font-size: 15px; + -webkit-box-shadow: 0 3px 6px rgba(0,0,0,.16),0 3px 6px rgba(0,0,0,.23); +} + +.rawtext { + white-space: pre-wrap; +} + +/* Syntax highlighting */ +pre { line-height: 125%; } +td.linenos .normal { color: #f1fa8c; background-color: #44475a; padding-left: 5px; padding-right: 5px; } +span.linenos { color: #f1fa8c; background-color: #44475a; padding-left: 5px; padding-right: 5px; } +td.linenos .special { color: #50fa7b; background-color: #6272a4; padding-left: 5px; padding-right: 5px; } +span.linenos.special { color: #50fa7b; background-color: #6272a4; padding-left: 5px; padding-right: 5px; } +.codehilite .hll { background-color: #44475a } +.codehilite { background: #282a36; color: #f8f8f2 } +.codehilite .c { color: #6272a4 } /* Comment */ +.codehilite .err { color: #f8f8f2 } /* Error */ +.codehilite .g { color: #f8f8f2 } /* Generic */ +.codehilite .k { color: #ff79c6 } /* Keyword */ +.codehilite .l { color: #f8f8f2 } /* Literal */ +.codehilite .n { color: #f8f8f2 } /* Name */ +.codehilite .o { color: #ff79c6 } /* Operator */ +.codehilite .x { color: #f8f8f2 } /* Other */ +.codehilite .p { color: #f8f8f2 } /* Punctuation */ +.codehilite .ch { color: #6272a4 } /* Comment.Hashbang */ +.codehilite .cm { color: #6272a4 } /* Comment.Multiline */ +.codehilite .cp { color: #ff79c6 } /* Comment.Preproc */ +.codehilite .cpf { color: #6272a4 } /* Comment.PreprocFile */ +.codehilite .c1 { color: #6272a4 } /* Comment.Single */ +.codehilite .cs { color: #6272a4 } /* Comment.Special */ +.codehilite .gd { color: #8b080b } /* Generic.Deleted */ +.codehilite .ge { color: #f8f8f2; text-decoration: underline } /* Generic.Emph */ +.codehilite .gr { color: #f8f8f2 } /* Generic.Error */ +.codehilite .gh { color: #f8f8f2; font-weight: bold } /* Generic.Heading */ +.codehilite .gi { color: #f8f8f2; font-weight: bold } /* Generic.Inserted */ +.codehilite .go { color: #44475a } /* Generic.Output */ +.codehilite .gp { color: #f8f8f2 } /* Generic.Prompt */ +.codehilite .gs { color: #f8f8f2 } /* Generic.Strong */ +.codehilite .gu { color: #f8f8f2; font-weight: bold } /* Generic.Subheading */ +.codehilite .gt { color: #f8f8f2 } /* Generic.Traceback */ +.codehilite .kc { color: #ff79c6 } /* Keyword.Constant */ +.codehilite .kd { color: #8be9fd; font-style: italic } /* Keyword.Declaration */ +.codehilite .kn { color: #ff79c6 } /* Keyword.Namespace */ +.codehilite .kp { color: #ff79c6 } /* Keyword.Pseudo */ +.codehilite .kr { color: #ff79c6 } /* Keyword.Reserved */ +.codehilite .kt { color: #8be9fd } /* Keyword.Type */ +.codehilite .ld { color: #f8f8f2 } /* Literal.Date */ +.codehilite .m { color: #ffb86c } /* Literal.Number */ +.codehilite .s { color: #bd93f9 } /* Literal.String */ +.codehilite .na { color: #50fa7b } /* Name.Attribute */ +.codehilite .nb { color: #8be9fd; font-style: italic } /* Name.Builtin */ +.codehilite .nc { color: #50fa7b } /* Name.Class */ +.codehilite .no { color: #f8f8f2 } /* Name.Constant */ +.codehilite .nd { color: #f8f8f2 } /* Name.Decorator */ +.codehilite .ni { color: #f8f8f2 } /* Name.Entity */ +.codehilite .ne { color: #f8f8f2 } /* Name.Exception */ +.codehilite .nf { color: #50fa7b } /* Name.Function */ +.codehilite .nl { color: #8be9fd; font-style: italic } /* Name.Label */ +.codehilite .nn { color: #f8f8f2 } /* Name.Namespace */ +.codehilite .nx { color: #f8f8f2 } /* Name.Other */ +.codehilite .py { color: #f8f8f2 } /* Name.Property */ +.codehilite .nt { color: #ff79c6 } /* Name.Tag */ +.codehilite .nv { color: #8be9fd; font-style: italic } /* Name.Variable */ +.codehilite .ow { color: #ff79c6 } /* Operator.Word */ +.codehilite .w { color: #f8f8f2 } /* Text.Whitespace */ +.codehilite .mb { color: #ffb86c } /* Literal.Number.Bin */ +.codehilite .mf { color: #ffb86c } /* Literal.Number.Float */ +.codehilite .mh { color: #ffb86c } /* Literal.Number.Hex */ +.codehilite .mi { color: #ffb86c } /* Literal.Number.Integer */ +.codehilite .mo { color: #ffb86c } /* Literal.Number.Oct */ +.codehilite .sa { color: #bd93f9 } /* Literal.String.Affix */ +.codehilite .sb { color: #bd93f9 } /* Literal.String.Backtick */ +.codehilite .sc { color: #bd93f9 } /* Literal.String.Char */ +.codehilite .dl { color: #bd93f9 } /* Literal.String.Delimiter */ +.codehilite .sd { color: #bd93f9 } /* Literal.String.Doc */ +.codehilite .s2 { color: #bd93f9 } /* Literal.String.Double */ +.codehilite .se { color: #bd93f9 } /* Literal.String.Escape */ +.codehilite .sh { color: #bd93f9 } /* Literal.String.Heredoc */ +.codehilite .si { color: #bd93f9 } /* Literal.String.Interpol */ +.codehilite .sx { color: #bd93f9 } /* Literal.String.Other */ +.codehilite .sr { color: #bd93f9 } /* Literal.String.Regex */ +.codehilite .s1 { color: #bd93f9 } /* Literal.String.Single */ +.codehilite .ss { color: #bd93f9 } /* Literal.String.Symbol */ +.codehilite .bp { color: #f8f8f2; font-style: italic } /* Name.Builtin.Pseudo */ +.codehilite .fm { color: #50fa7b } /* Name.Function.Magic */ +.codehilite .vc { color: #8be9fd; font-style: italic } /* Name.Variable.Class */ +.codehilite .vg { color: #8be9fd; font-style: italic } /* Name.Variable.Global */ +.codehilite .vi { color: #8be9fd; font-style: italic } /* Name.Variable.Instance */ +.codehilite .vm { color: #8be9fd; font-style: italic } /* Name.Variable.Magic */ +.codehilite .il { color: #ffb86c } /* Literal.Number.Integer.Long */ + diff --git a/src/static/styles/2-greencula.css b/src/static/styles/2-greencula.css new file mode 100644 index 0000000..f412015 --- /dev/null +++ b/src/static/styles/2-greencula.css @@ -0,0 +1,230 @@ +@font-face { + font-family: "Work Sans"; + src: url(WorkSans-Regular.ttf); +} + +@font-face { + font-family: "Work Sans"; + src: url(WorkSans-Bold.ttf); + font-weight: bold; +} + +@font-face { + font-family: "Work Sans"; + src: url(WorkSans-Italic.ttf); + font-style: italic; +} + +@font-face { + font-family: "Work Sans"; + src: url(WorkSans-BoldItalic.ttf); + font-weight: bold; + font-style: italic; +} + + +html { + background-color: green; + font-family: 'Work Sans'; + color: #f8f8f2; +} + +h1 { + color: #50fa7b; +} + +h2 { + color: #50fa7b; +} + +h3 { + color: #50fa7b; +} + +h4 { + color: #50fa7b; +} + +h5 { + color: #50fa7b; +} + +button { + background-color: #22242e; + border: none; + color: #8be9fd; + padding: 1px 2px; + text-align: left; + text-decoration: none; + display: inline-block; + font-size: 1em; + font-style: italic; + cursor: pointer; +} + +hr { + border: 3px dotted; +} + +a { + color: #8be9fd; + text-decoration: underline; + font-style: italic; + font-size: 1em; +} + +.themebutton { + float: right; +} + +.exportlink { + float: right; +} + +.pagetitle { + font-size: 3em; + color: #ff79c6; + float: left; +} + + +.notetitle { + color: #ff79c6; + font-size: 2em; +} + +.notetime { + color: #6272a4; + font-style: italic; +} + +/* +.title { + background: #44475a; + color: #50fa7b; + font-weight: bold; + font-size: 2em + border-style: none; + border-radius: 1px; + outline: none; + border-width: 1px; +} +*/ + +.text { + font-family: 'Noto Sans'; + width: 100%; + background: #44475a; + color: #f8f8f2; + border-radius: 5px; + border-style: none; + outline: none; + border-width: 1px; + height: 80%; + font-size: 15px; + -webkit-box-shadow: 0 3px 6px rgba(0,0,0,.16),0 3px 6px rgba(0,0,0,.23); +} + +.title { + font-family: 'Noto Sans'; + width: 100%; + background: #44475a; + color: #f8f8f2; + border-radius: 5px; + border-style: none; + outline: none; + border-width: 1px; + height: 25px; + margin: 5px 0px 5px 0px; + font-size: 15px; + -webkit-box-shadow: 0 3px 6px rgba(0,0,0,.16),0 3px 6px rgba(0,0,0,.23); +} + +.rawtext { + white-space: pre-wrap; +} + +/* Syntax highlighting */ +pre { line-height: 125%; } +td.linenos .normal { color: #f1fa8c; background-color: #44475a; padding-left: 5px; padding-right: 5px; } +span.linenos { color: #f1fa8c; background-color: #44475a; padding-left: 5px; padding-right: 5px; } +td.linenos .special { color: #50fa7b; background-color: #6272a4; padding-left: 5px; padding-right: 5px; } +span.linenos.special { color: #50fa7b; background-color: #6272a4; padding-left: 5px; padding-right: 5px; } +.codehilite .hll { background-color: #44475a } +.codehilite { background: #282a36; color: #f8f8f2 } +.codehilite .c { color: #6272a4 } /* Comment */ +.codehilite .err { color: #f8f8f2 } /* Error */ +.codehilite .g { color: #f8f8f2 } /* Generic */ +.codehilite .k { color: #ff79c6 } /* Keyword */ +.codehilite .l { color: #f8f8f2 } /* Literal */ +.codehilite .n { color: #f8f8f2 } /* Name */ +.codehilite .o { color: #ff79c6 } /* Operator */ +.codehilite .x { color: #f8f8f2 } /* Other */ +.codehilite .p { color: #f8f8f2 } /* Punctuation */ +.codehilite .ch { color: #6272a4 } /* Comment.Hashbang */ +.codehilite .cm { color: #6272a4 } /* Comment.Multiline */ +.codehilite .cp { color: #ff79c6 } /* Comment.Preproc */ +.codehilite .cpf { color: #6272a4 } /* Comment.PreprocFile */ +.codehilite .c1 { color: #6272a4 } /* Comment.Single */ +.codehilite .cs { color: #6272a4 } /* Comment.Special */ +.codehilite .gd { color: #8b080b } /* Generic.Deleted */ +.codehilite .ge { color: #f8f8f2; text-decoration: underline } /* Generic.Emph */ +.codehilite .gr { color: #f8f8f2 } /* Generic.Error */ +.codehilite .gh { color: #f8f8f2; font-weight: bold } /* Generic.Heading */ +.codehilite .gi { color: #f8f8f2; font-weight: bold } /* Generic.Inserted */ +.codehilite .go { color: #44475a } /* Generic.Output */ +.codehilite .gp { color: #f8f8f2 } /* Generic.Prompt */ +.codehilite .gs { color: #f8f8f2 } /* Generic.Strong */ +.codehilite .gu { color: #f8f8f2; font-weight: bold } /* Generic.Subheading */ +.codehilite .gt { color: #f8f8f2 } /* Generic.Traceback */ +.codehilite .kc { color: #ff79c6 } /* Keyword.Constant */ +.codehilite .kd { color: #8be9fd; font-style: italic } /* Keyword.Declaration */ +.codehilite .kn { color: #ff79c6 } /* Keyword.Namespace */ +.codehilite .kp { color: #ff79c6 } /* Keyword.Pseudo */ +.codehilite .kr { color: #ff79c6 } /* Keyword.Reserved */ +.codehilite .kt { color: #8be9fd } /* Keyword.Type */ +.codehilite .ld { color: #f8f8f2 } /* Literal.Date */ +.codehilite .m { color: #ffb86c } /* Literal.Number */ +.codehilite .s { color: #bd93f9 } /* Literal.String */ +.codehilite .na { color: #50fa7b } /* Name.Attribute */ +.codehilite .nb { color: #8be9fd; font-style: italic } /* Name.Builtin */ +.codehilite .nc { color: #50fa7b } /* Name.Class */ +.codehilite .no { color: #f8f8f2 } /* Name.Constant */ +.codehilite .nd { color: #f8f8f2 } /* Name.Decorator */ +.codehilite .ni { color: #f8f8f2 } /* Name.Entity */ +.codehilite .ne { color: #f8f8f2 } /* Name.Exception */ +.codehilite .nf { color: #50fa7b } /* Name.Function */ +.codehilite .nl { color: #8be9fd; font-style: italic } /* Name.Label */ +.codehilite .nn { color: #f8f8f2 } /* Name.Namespace */ +.codehilite .nx { color: #f8f8f2 } /* Name.Other */ +.codehilite .py { color: #f8f8f2 } /* Name.Property */ +.codehilite .nt { color: #ff79c6 } /* Name.Tag */ +.codehilite .nv { color: #8be9fd; font-style: italic } /* Name.Variable */ +.codehilite .ow { color: #ff79c6 } /* Operator.Word */ +.codehilite .w { color: #f8f8f2 } /* Text.Whitespace */ +.codehilite .mb { color: #ffb86c } /* Literal.Number.Bin */ +.codehilite .mf { color: #ffb86c } /* Literal.Number.Float */ +.codehilite .mh { color: #ffb86c } /* Literal.Number.Hex */ +.codehilite .mi { color: #ffb86c } /* Literal.Number.Integer */ +.codehilite .mo { color: #ffb86c } /* Literal.Number.Oct */ +.codehilite .sa { color: #bd93f9 } /* Literal.String.Affix */ +.codehilite .sb { color: #bd93f9 } /* Literal.String.Backtick */ +.codehilite .sc { color: #bd93f9 } /* Literal.String.Char */ +.codehilite .dl { color: #bd93f9 } /* Literal.String.Delimiter */ +.codehilite .sd { color: #bd93f9 } /* Literal.String.Doc */ +.codehilite .s2 { color: #bd93f9 } /* Literal.String.Double */ +.codehilite .se { color: #bd93f9 } /* Literal.String.Escape */ +.codehilite .sh { color: #bd93f9 } /* Literal.String.Heredoc */ +.codehilite .si { color: #bd93f9 } /* Literal.String.Interpol */ +.codehilite .sx { color: #bd93f9 } /* Literal.String.Other */ +.codehilite .sr { color: #bd93f9 } /* Literal.String.Regex */ +.codehilite .s1 { color: #bd93f9 } /* Literal.String.Single */ +.codehilite .ss { color: #bd93f9 } /* Literal.String.Symbol */ +.codehilite .bp { color: #f8f8f2; font-style: italic } /* Name.Builtin.Pseudo */ +.codehilite .fm { color: #50fa7b } /* Name.Function.Magic */ +.codehilite .vc { color: #8be9fd; font-style: italic } /* Name.Variable.Class */ +.codehilite .vg { color: #8be9fd; font-style: italic } /* Name.Variable.Global */ +.codehilite .vi { color: #8be9fd; font-style: italic } /* Name.Variable.Instance */ +.codehilite .vm { color: #8be9fd; font-style: italic } /* Name.Variable.Magic */ +.codehilite .il { color: #ffb86c } /* Literal.Number.Integer.Long */ + diff --git a/src/templates/edit.html b/src/templates/edit.html index b66b6ef..ac04fb1 100644 --- a/src/templates/edit.html +++ b/src/templates/edit.html @@ -1,6 +1,6 @@ - + sqnotes diff --git a/src/templates/homepage.html b/src/templates/homepage.html index 9883196..55d3f98 100644 --- a/src/templates/homepage.html +++ b/src/templates/homepage.html @@ -1,12 +1,12 @@ - + sqnotes - +

$ ~/sqnotes

Raw notes

diff --git a/src/templates/read.html b/src/templates/read.html index 56bace9..f5e76a5 100644 --- a/src/templates/read.html +++ b/src/templates/read.html @@ -1,6 +1,6 @@ - + sqnotes