SCITER : GUI APPLICATION WITH GOLANG USING HTML/CSS

https://www.mchampaneri.in/2018/06/sciter-gui-application-with-golang.html

gui library for golang sciter

GUI library for golang sciter

Last Update: 03-07-2018

This is the words from Sciter’s Web site,

Sciter brings a stack of web technologies to desktop UI development. Web designers and developers can reuse their experience and expertise in creating modern looking desktop applications.

Various GUI frameworks offer different UI declaration and styling languages, such as QML and XAML (Microsoft WPF). On the contrary, Sciter allows using time proven, robust, and flexible HTML and CSS for GUI definition and GPU accelerated rendering.

Before using sciter I already tried other alternatives but none of them was satisfactory as an example first i tried andlabs/ui library i already have written a post on it. You can read it on post gui programming with golang. But this library is still under construction and has no support for production apps.

Secondly, I go for electron but the problem was my simple calc like the app was of size 150mb. Which is 15mb of go and other was the electron.

Before some time I found another alternative, sciter , which is now also free to use for even commercially ( which was not before some time ).

I suppose you have read upper two paragraphs in grey text. If you want to know more about sciter you can visit its site which is https://sciter.com/

Here is a simple example of sciter application
Simple GUI App with Scitter & Golang

Simple GUI App with Scitter & Golang
Here I am sharing the source code of golang and HTML file. [ which has to be in the same folder ]

  1. package main
  2. import (
  3. "fmt"
  4. "github.com/fatih/color"
  5. sciter "github.com/sciter-sdk/go-sciter"
  6. "github.com/sciter-sdk/go-sciter/window"
  7. )
  8. // Specifying havily used
  9. // Singltons to make them
  10. // package wide available
  11. var root *sciter.Element
  12. var rootSelectorErr error
  13. var w *window.Window
  14. var windowErr error
  15. // Preapare Scitre For Execution ///
  16. func init() {
  17. // initlzigin window for downloaer
  18. // app with appropriate properties
  19. rect := sciter.NewRect(0, 100, 300, 350)
  20. w, windowErr = window.New(sciter.SW_TITLEBAR|
  21. sciter.SW_CONTROLS|
  22. sciter.SW_MAIN|
  23. sciter.SW_GLASSY,
  24. rect)
  25. if windowErr != nil {
  26. fmt.Println("Can not create new window")
  27. return
  28. }
  29. // Loading main html file for app
  30. htloadErr := w.LoadFile("./simpleGuiApp.html")
  31. if htloadErr != nil {
  32. fmt.Println("Can not load html in the screen", htloadErr.Error())
  33. return
  34. }
  35. // Initializng Selector at global level as we are going to need
  36. // it mostly and as it is
  37. root, rootSelectorErr = w.GetRootElement()
  38. if rootSelectorErr != nil {
  39. fmt.Println("Can not select root element")
  40. return
  41. }
  42. // Set title of the appliaction window
  43. w.SetTitle("Simple Calc")
  44. }
  45. // Preaprare Program for execution ///
  46. func main() {
  47. addbutton, _ := root.SelectById("add")
  48. out1, errout1 := root.SelectById("output1")
  49. if errout1 != nil {
  50. color.Red("failed to bound output 1 ", errout1.Error())
  51. }
  52. addbutton.OnClick(func() {
  53. output := add()
  54. out1.SetText(fmt.Sprint(output))
  55. })
  56. w.Show()
  57. w.Run()
  58. }
  59. //////////////////////////////////////////////////
  60. /// Function of calc ///
  61. //////////////////////////////////////////////////
  62. func add() int {
  63. // Refreshing and fetching inputs()
  64. in1, errin1 := root.SelectById("input1")
  65. if errin1 != nil {
  66. color.Red("failed to bound input 1 ", errin1.Error())
  67. }
  68. in2, errin2 := root.SelectById("input2")
  69. if errin2 != nil {
  70. color.Red("failed to bound input 2 ", errin2.Error())
  71. }
  72. in1val, errv1 := in1.GetValue()
  73. color.Green(in1val.String())
  74. if errv1 != nil {
  75. color.Red(errv1.Error())
  76. }
  77. in2val, errv2 := in2.GetValue()
  78. if errv2 != nil {
  79. color.Red(errv2.Error())
  80. }
  81. color.Green(in2val.String())
  82. return in1val.Int() + in2val.Int()
  83. }
  84. ///////////////////////////////////////////////////
  1. <html>
  2. <head>
  3. <head>
  4. <title>Simple Calc</title>
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. </head>
  7. </head>
  8. <body>
  9. <label for="">Input First</label>
  10. <input type="number" style="width: 250px; margin: 0 auto;" id="input1" >
  11. <label for="">Input Second</label>
  12. <input type="number" style="width: 250px; margin: 0 auto;" id="input2" >
  13. <input type="button" style="width: 125px; margin: 0 auto;" value="Add ( + )" id="add">
  14. <hr>
  15. <input type="number" style="width: 250px; margin: 0 auto;" id="output1" disabled>
  16. </body>
  17. </html>

But the conclusion is that sciter is most promising GUI library to create GUI app with golang.

Update : 26-06-2018

GoLang-Sciter Learn by example [ link to my GitHub repo ]
Examples [ chapters ] in increasing order of complexity. I will update it continuously unless I feel it’s complete. So stay tuned and watch

Update : 03-07-2018

I am writing a blog just about golang & sciter [ exclusively golang and sciter. nothing else. ] Itsgo-sciter.mchampaneri.in

Hope find it useful!

ft_authoradmin  ft_create_time2018-12-30 16:54
 ft_update_time2018-12-30 16:55