The go language uses Go-sciter to create desktop Apps (iii) event handling, function and method definitions, and calls between go and Tiscript

Source: Internet
Author: User
Tags define function

Sciter handles script Tiscript, which handles some of the logic in UI interactions, like JS, but a little bit different, and people familiar with the front end should be able to get started quickly.

Tiscrip Script Document

https://sciter.com/developers/sciter-docs/script/

Dom class documents

https://sciter.com/developers/sciter-docs/dom-classes/

  

The Demo4.go code is as follows:

Package Main;import ("Github.com/sciter-sdk/go-sciter" "Github.com/sciter-sdk/go-sciter/window" "Log" "FMT")// Sets the handler for the element func setelementhandlers (root *sciter. Element) {btn1, _: = root. Selectbyid ("btn1");//handling element simple Click event btn1. OnClick (func () {fmt. Println ("Btn1 was clicked");}); /Here the method defined for the element is called in Tiscript//and accessed as an element's property btn1. DefineMethod ("Test", func (args ... *sciter). Value) *sciter. Value {//We print out the parameters passed in for _, arg: = Range args {//string () converts the argument to a string fmt. Print (Arg. String () + "");} Returns a null value of return sciter. Nullvalue ();}); BTN2, _: = root. Selectbyid ("btn2");//Call the method defined in Tiscript data, _: = Btn2. Callmethod ("Test2", Sciter. NewValue ("1"), Sciter. NewValue ("2"), Sciter. NewValue ("3"));//The return value of the output call method FMT. PRINTLN (data. String ()); Sets the callback Func setcallbackhandlers (w *window. Window) {//callbackhandler is a structure that defines some of the methods//You can customize your own callback CB by implementing these methods: = &sciter. callbackhandler{//Loading Data begins Onloaddata:func (P *sciter. scnloaddata) int {//Displays the URIFMT that loaded the resource. PRINTLN ("Load:", P.uri ()); return Sciter. load_ok;},//Ondataloaded:func (P *sciter) during the loading of data. scndataloaded) int {fmt. Println ("Loading:", P.uri ()); return Sciter. Load_ok;},};w.setcallback (CB);} Defines the function func Setwinhandler (w *window. Window) {//define function, in the Tis script you need to call//define the INC function through the View object, return the parameter plus 1w. Definefunction ("Inc", func (args ... *sciter). Value) *sciter. Value {return sciter. NewValue (Args[0]. Int () + 1);}); /define DEC function, return parameter minus 1w. Definefunction ("Dec", func (args ... *sciter). Value) *sciter. Value {return sciter. NewValue (Args[0]. Int ()-1);});} The test calls the function func testcallfunc (w *window. window) {//Call the function defined in the Tis script data, _: = W.call ("sum", sciter. NewValue (Ten), Sciter. NewValue ()); Fmt. PRINTLN (data. String ()); root, _: = W.getrootelement ();//We can also specify an element to invoke the function data, _ = root. CallFunction ("Sum", sciter. NewValue (), Sciter. NewValue (+)); Fmt. PRINTLN (data. String ()); Func Main () {//Creates a new window W, err: = window. New (Sciter. Defaultwindowcreateflag, Sciter. Defaultrect); if err! = Nil {log. Fatal (err);} W.loadfile ("demo4.html");//Set title W. Settitle ("event handling");//Set Callback handler Setcallbackhandlers (w);//get root element root, _: = W.getrootelement ();// Set the element handler setelementhandlers (root);//Setup windowHandler Setwinhandler (w);//Test Call Function Testcallfunc (w);//Display window W. Show ();//Run window, enter message loop W. Run ();}

The

demo4.html code is as follows:

<! DOCTYPE html>

The go language uses Go-sciter to create desktop Apps (iii) event handling, function and method definitions, and calls between go and Tiscript

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.