본문 바로가기

Programming/Golang

Go언어 GUI 투명한 날짜 표시 프로그램 with go-sciter

반응형

간단히 날짜 표시하는 앱을 구현해보겠습니다.

 

1.main.go

package main

import (
	"fmt"
	"time"

	sciter "github.com/sciter-sdk/go-sciter"
	"github.com/sciter-sdk/go-sciter/window"
)

// Specifying  havily used
// Singltons to make them
// package wide available
var root *sciter.Element
var rootSelectorErr error
var w *window.Window
var windowErr error

// Preapare Scitre For Execution ///
func init() {

	// initlzigin window for downloaer
	// app with appropriate properties
	rect := sciter.NewRect(0, 100, 200, 350)
	w, windowErr = window.New(sciter.SW_TITLEBAR|
		sciter.SW_CONTROLS|
		sciter.SW_MAIN|
		sciter.SW_GLASSY,
		rect)

	if windowErr != nil {
		fmt.Println("Can not create new window")
		return
	}
	// Loading main html file for app
	htloadErr := w.LoadFile("./main.html")
	if htloadErr != nil {
		fmt.Println("Can not load html in the screen", htloadErr.Error())
		return
	}

	// Initializng  Selector at global level as we  are going to need
	// it mostly and as it is
	root, rootSelectorErr = w.GetRootElement()
	if rootSelectorErr != nil {
		fmt.Println("Can not select root element")
		return
	}

	// Set title of the appliaction window
	w.SetTitle("Simple")

}

// Preaprare Program for execution ///
func main() {

	t := time.Now().Format("2006-01-02 15:04:05")
	date_now, _ := root.SelectById("date")
	date_now.SetText(t)
	//date_now.SetText("hello")

	w.Show()
	w.Run()

}

 

2.main.html

<html window-frame="default" window-blurbehind>
<head>
    <head>
        <title>Simple Calc</title> 
        <meta name="viewport" content="width=device-width, initial-scale=1.0">  
        <style>
          html{
            background: transparent;
          }
          #date{
            color: white;
            text-align: left;
            font-size:20px;
          }
        </style>
    </head>
</head>
<body>
  <label id="date">date</label>
</body>
</html>

 

결과는 아래와 같이~~

 

투명하게 처리된 프로그램. 보이시나요?

 

 

Golang과 HTML로 GUI 실행파일 만든다는게 꽤 재미있네요. 자주 활용할 수 있을 것 같습니다.

오늘은 이만~~

반응형