You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
133 lines
3.6 KiB
133 lines
3.6 KiB
6 years ago
|
/*
|
||
|
Landesamt für Geoinformation und Landentwicklung, Referat 35
|
||
|
Einführung in die Sprache Go, 25.7.2017
|
||
6 years ago
|
Lektion 9: Darstellung mit Qt-Framework
|
||
6 years ago
|
*/
|
||
|
package main
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"math"
|
||
6 years ago
|
"os"
|
||
6 years ago
|
"runtime"
|
||
6 years ago
|
"strconv"
|
||
6 years ago
|
"sync"
|
||
|
"time"
|
||
|
|
||
6 years ago
|
"Präsentation3hGolang4LGLRef35/go2lgl_l09/myGui"
|
||
6 years ago
|
|
||
6 years ago
|
"github.com/therecipe/qt/core"
|
||
|
"github.com/therecipe/qt/gui"
|
||
6 years ago
|
"github.com/therecipe/qt/widgets"
|
||
6 years ago
|
|
||
|
"github.com/0xAX/notificator"
|
||
6 years ago
|
)
|
||
|
|
||
|
const (
|
||
6 years ago
|
anzahlTöpfchen uint8 = 35
|
||
|
anzahlKugeln uint32 = 1000000
|
||
|
intervallWartezeitSec uint8 = 1
|
||
|
höhenFaktor uint8 = 7
|
||
6 years ago
|
)
|
||
|
|
||
|
var timestamp [2]int64
|
||
|
|
||
6 years ago
|
var notify *notificator.Notificator
|
||
|
|
||
6 years ago
|
var wg, wgcli, wggui sync.WaitGroup
|
||
6 years ago
|
|
||
|
func main() {
|
||
|
runtime.GOMAXPROCS(runtime.NumCPU())
|
||
|
timestamp[0] = time.Now().UnixNano()
|
||
|
|
||
6 years ago
|
notify = notificator.New(notificator.Options{
|
||
|
DefaultIcon: "icon/default.png",
|
||
|
AppName: "LGL-Demo",
|
||
|
})
|
||
|
|
||
6 years ago
|
var töpfchenAlle []int = make([]int, anzahlTöpfchen, anzahlTöpfchen)
|
||
|
var c chan bool = make(chan bool, 1)
|
||
|
|
||
6 years ago
|
//Eröffne eine neue Applikation (als eine Sammlung von Widgets)
|
||
|
widgets.NewQApplication(len(os.Args), os.Args)
|
||
|
var c_widget = widgets.NewQWidget(nil, 0)
|
||
6 years ago
|
var ui_widget = myGui.LeseUIFile(c_widget)
|
||
6 years ago
|
var ui_textBrowser, ui_lcdNummer, ui_progressBar, ui_sliderArea = myGui.ErzeugeLayout(c_widget, ui_widget, &töpfchenAlle, c) // Beispiel für Parameterrückgabe als Tupel
|
||
|
|
||
|
ui_lcdNummer.SetDigitCount(len(strconv.Itoa((int)(anzahlKugeln))))
|
||
|
|
||
|
var c_slider [anzahlTöpfchen]*widgets.QSlider
|
||
|
for i := uint8(0); i < anzahlTöpfchen; i++ {
|
||
|
c_slider[i] = widgets.NewQSlider2(core.Qt__Vertical, nil)
|
||
|
c_slider[i].SetMinimum(0)
|
||
|
c_slider[i].SetMaximum(int(anzahlKugeln) / int(höhenFaktor))
|
||
|
c_slider[i].SetValue(0) // c_slider[i].Maximum() / 4
|
||
|
c_slider[i].SetSizePolicy2(widgets.QSizePolicy__MinimumExpanding, widgets.QSizePolicy__MinimumExpanding)
|
||
|
c_slider[i].ConnectResizeEvent(func(*gui.QResizeEvent) {
|
||
|
for j := uint8(0); j < anzahlTöpfchen; j++ {
|
||
|
c_slider[j].SetFixedHeight(c_widget.Height() * 93 / 100)
|
||
6 years ago
|
}
|
||
6 years ago
|
})
|
||
6 years ago
|
|
||
6 years ago
|
ui_sliderArea.AddWidget(c_slider[i], 0, core.Qt__AlignBottom)
|
||
|
}
|
||
6 years ago
|
|
||
|
wgcli.Add(1)
|
||
6 years ago
|
go func(t *[]int, ch chan bool) {
|
||
6 years ago
|
defer wgcli.Done()
|
||
6 years ago
|
sum := func(mySlice *[]int) int { // Zuweisung anonymer Funktion
|
||
|
var amount int
|
||
|
for _, v := range *mySlice {
|
||
|
amount += v
|
||
|
}
|
||
|
return amount
|
||
|
}
|
||
6 years ago
|
for i := int(0); true; i = sum(t) {
|
||
6 years ago
|
select {
|
||
6 years ago
|
case <-ch:
|
||
|
ui_textBrowser.Append(fmt.Sprint("\u2690", *t))
|
||
|
ui_lcdNummer.Display2(int(anzahlKugeln))
|
||
|
ui_progressBar.SetValue(100)
|
||
6 years ago
|
for j, v := range *t {
|
||
|
c_slider[j].SetValue(v)
|
||
|
//fmt.Println(j, v)
|
||
|
}
|
||
6 years ago
|
|
||
6 years ago
|
return
|
||
|
default:
|
||
6 years ago
|
ui_textBrowser.Append(fmt.Sprint("\u231B ", *t, runtime.NumGoroutine()))
|
||
6 years ago
|
ui_lcdNummer.Display2(i)
|
||
|
ui_progressBar.SetValue(int(math.Floor((float64(i) / float64(anzahlKugeln) * 100) + .5)))
|
||
6 years ago
|
for j, v := range *t {
|
||
|
c_slider[j].SetValue(v)
|
||
|
//fmt.Println(j, v)
|
||
|
}
|
||
|
time.Sleep(time.Second * time.Duration(intervallWartezeitSec))
|
||
6 years ago
|
}
|
||
|
}
|
||
|
}(&töpfchenAlle, c)
|
||
|
|
||
6 years ago
|
go func(wg *sync.WaitGroup, töpfchenAlle *[]int, c chan bool) {
|
||
6 years ago
|
for k := (uint32)(1); k <= anzahlKugeln; k++ {
|
||
6 years ago
|
wg.Add(1)
|
||
|
go zeigeMirDenGauß(int(anzahlKugeln), int(anzahlTöpfchen), töpfchenAlle)
|
||
|
|
||
|
for runtime.NumGoroutine() >= 50 { // Limitiere die Anzahl der go-Routinen
|
||
6 years ago
|
time.Sleep(time.Millisecond * 1)
|
||
|
}
|
||
6 years ago
|
}
|
||
6 years ago
|
c <- true
|
||
|
}(&wg, &töpfchenAlle, c)
|
||
|
|
||
|
widgets.QApplication_Exec()
|
||
6 years ago
|
|
||
6 years ago
|
wg.Wait()
|
||
|
wgcli.Wait()
|
||
6 years ago
|
close(c)
|
||
|
|
||
|
timestamp[1] = time.Now().UnixNano()
|
||
6 years ago
|
|
||
|
notify.Push("LGL-Demo", fmt.Sprintf("\nProzess ist fertig und hat %v Sekunden gedauert!\n\n", (float64(timestamp[1]-timestamp[0])*math.Pow(10, -9))), "/home/user/icon.png", notificator.UR_CRITICAL)
|
||
6 years ago
|
|
||
6 years ago
|
}
|