Skip to content

Instantly share code, notes, and snippets.

@enthus1ast
Created September 20, 2018 00:25
Show Gist options
  • Save enthus1ast/e25a52d768fcefb40b02070398607002 to your computer and use it in GitHub Desktop.
Save enthus1ast/e25a52d768fcefb40b02070398607002 to your computer and use it in GitHub Desktop.
################
import webview
import strutils
import os
const indexHTML = """
<!doctype html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
</head>
<body>
<button onclick="api.baa('hallo')">baa</button>
<button onclick="api.close()">Close</button>
<button onclick="api.open()">Open</button>
<button onclick="api.opendir()">Open directory</button>
<button onclick="api.save()">Save</button>
<button onclick="api.message()">Message</button>
<button onclick="api.info('asdasd')">info</button>
<button onclick="api.warn()">warn</button>
<button onclick="api.error()">error</button>
<button onclick="api.changeColor()">changeColor</button>
<button onclick="api.toggleFullScreen()">toggleFullScreen</button>
<button onclick="api.changeTitle(document.getElementById('new-title').value)">
Change title
</button>
<input id="new-title" type="text" />
</body>
</html>
"""
import uri
# let fn="$1/xxx.html"%[getTempDir()]
# writeFile(fn, indexHTML)
var w = newWebView("Simple window demo2", "data:text/html," & indexHTML , 600, 300, true)
var fullScreen = true
w.bindProcs("api"):
proc open() = echo w.dialogOpen()
proc save() = echo w.dialogSave()
proc opendir() = echo w.dialogOpen(flag=dFlagDir)
proc message() = w.msg("hello", "message")
proc info(msg: string) = w.info(msg, "info")
proc warn() = w.warn("hello", "warn")
proc error() = w.error("hello", "error")
proc changeTitle(title: string) = w.setTitle(title)
proc close() = w.terminate()
proc changeColor() = w.setColor(210,210,210,100)
proc toggleFullScreen() = fullScreen = not w.setFullscreen(fullScreen)
proc baa(param: string) =
echo "baa"
discard w.eval("alert(\"foo baa\");")
var w = newWebView("Simple window demo2", "data:text/html," & indexHTML , 0 , 0 )
# w.setFullscreen()
w.runPolling(poll, 1)
w.exit()
# removeFile(fn)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment