Пример #1
1
func initGUI() {

	/*
		ff := ui.ListFontFamilies()
		for i := 0; i < ff.NumFamilies(); i++ {
			log.Printf("%3d. Font family '%s'\n", i + 1, ff.Family(i))
		}
	*/

	window := ui.NewWindow("Привет мир!", 800, 480, false)
	window.SetMargined(true)

	progress := ui.NewProgressBar()
	labelTime := ui.NewLabel("")

	labelInfo := ui.NewLabel("Info")
	labelInfoButtonHandler := func(b *ui.Button) {
		labelInfo.SetText("Click button " + b.Text())
	}

	hbox := ui.NewHorizontalBox()
	hbox.SetPadded(true)

	hbox.Append(func() *ui.Box {
		box := ui.NewVerticalBox()
		box.SetPadded(true)

		box.Append(func() *ui.Button {
			button := ui.NewButton("Button 1")
			button.OnClicked(labelInfoButtonHandler)
			return button
		}(), false)
		box.Append(func() *ui.Button {
			button := ui.NewButton("Button 2")
			button.OnClicked(labelInfoButtonHandler)
			return button
		}(), false)
		box.Append(func() *ui.Button {
			button := ui.NewButton("Button 3")
			button.OnClicked(labelInfoButtonHandler)
			return button
		}(), false)
		box.Append(ui.NewHorizontalSeparator(), false)

		label := ui.NewLabel("It's all")
		box.Append(label, true)

		box.Append(func() *ui.Button {
			button := ui.NewButton("Exit")
			button.OnClicked(func(*ui.Button) {
				ui.Quit()
			})
			return button
		}(), false)

		return box
	}(), false)

	areaHandler := NewHistogramAreaHandler(20)
	area := ui.NewArea(areaHandler)

	hbox.Append(func() *ui.Box {
		box := ui.NewVerticalBox()
		box.SetPadded(true)
		box.Append(labelInfo, false)
		box.Append(labelTime, false)

		tab := ui.NewTab()
		tab.Append("Histogram demo", area)
		tab.Append("Controls demo", func() *ui.Box {
			box := ui.NewVerticalBox()
			box.SetPadded(true)

			box.Append(ui.NewEntry(), false)
			box.Append(ui.NewCheckbox("Check it"), false)
			box.Append(func() *ui.RadioButtons {
				radio := ui.NewRadioButtons()
				radio.Append("Radio button 1")
				radio.Append("Radio button 2")
				radio.Append("Radio button 3")
				return radio
			}(), false)
			box.Append(func() *ui.Group {
				combo := ui.NewCombobox()
				combo.Append("First")
				combo.Append("Second")
				combo.Append("Third")
				combo.Append("Fourth")
				combo.OnSelected(func(cb *ui.Combobox) {
					ui.MsgBoxError(window, "OnSelected", "Line #"+strconv.Itoa(cb.Selected()+1))
				})
				group := ui.NewGroup("Can't get text, only index")
				group.SetChild(combo)
				return group
			}(), false)
			box.Append(ui.NewSlider(0, 100), false)
			box.Append(ui.NewSpinbox(0, 10), false)
			box.Append(ui.NewDatePicker(), false)
			box.Append(ui.NewDateTimePicker(), false)

			return box
		}())
		tab.Append("Tab 3", ui.NewLabel("At tab 3"))
		box.Append(tab, true)

		box.Append(progress, false)

		return box
	}(), true)

	window.SetChild(hbox)

	window.OnClosing(func(*ui.Window) bool {
		log.Println("Window close")
		ui.Quit()
		return true
	})
	window.Show()

	progressCounter := 0
	progressTicker := time.NewTicker(time.Millisecond * 50)
	go func() {
		for _ = range progressTicker.C {
			// Что бы записать значение в виджет используем потокобезопасный вызов
			ui.QueueMain(func() {
				progress.SetValue(progressCounter)
			})
			progressCounter++
			if progressCounter > 100 {
				progressCounter = 0
			}
		}
	}()

	timeTicker := time.NewTicker(time.Millisecond * 10)
	go func() {
		for t := range timeTicker.C {
			// Что бы записать значение в виджет используем потокобезопасный вызов
			ui.QueueMain(func() {
				labelTime.SetText(t.Format(time.StampMilli))
			})
		}
	}()

	hystogrammTicker := time.NewTicker(time.Millisecond * 500)
	go func() {
		for _ = range hystogrammTicker.C {
			// Что бы записать значение в виджет используем потокобезопасный вызов
			ui.QueueMain(func() {
				areaHandler.Push(rand.Intn(100))
				area.QueueRedrawAll()
			})
		}
	}()

	log.Println("InitGUI done")
}
Пример #2
0
//gui界面,用的 github.com/andlabs/ui 的ui库
func gui() {
	input = ui.NewTextField()
	input.OnChanged(func() {
		go feedback() // 主要是这里在不同的刷新(table)内容
	})
	button := ui.NewButton("查词")
	button.OnClicked(guiTranslate)
	inputBox := ui.NewHorizontalStack(input, button)
	inputBox.SetStretchy(0)
	tab := ui.NewTab()
	table = ui.NewTable(reflect.TypeOf(str{}))
	table.OnSelected(tableSelected)
	tab.Append("单词", table)
	si = ui.NewLabel("Simple")
	tab.Append("简约", si)
	al = ui.NewLabel("All")
	tab.Append("全部", al)
	stack := ui.NewVerticalStack(inputBox, tab)
	stack.SetStretchy(1)
	w = ui.NewWindow("Window", 280, 350, stack)
	w.OnClosing(func() bool {
		ui.Stop()
		return true
	})
	w.Show()
}
Пример #3
0
func initGUI() {
	b := ui.NewButton("Button")
	c := ui.NewCheckbox("Checkbox")
	tf := ui.NewTextField()
	tf.SetText("Text Field")
	pf := ui.NewPasswordField()
	pf.SetText("Password Field")
	l := ui.NewStandaloneLabel("Label")

	t := ui.NewTab()
	t.Append("Tab 1", ui.Space())
	t.Append("Tab 2", ui.Space())
	t.Append("Tab 3", ui.Space())

	g := ui.NewGroup("Group", ui.Space())

	icons, il := readIcons()
	table := ui.NewTable(reflect.TypeOf(icons[0]))
	table.Lock()
	d := table.Data().(*[]icon)
	*d = icons
	table.Unlock()
	table.LoadImageList(il)

	area := ui.NewArea(200, 200, &areaHandler{tileImage(20)})

	stack := ui.NewVerticalStack(
		b,
		c,
		tf,
		pf,
		l,
		t,
		g,
		table,
		area)
	stack.SetStretchy(5)
	stack.SetStretchy(6)
	stack.SetStretchy(7)
	stack.SetStretchy(8)

	w = ui.NewWindow("Window", 400, 500, stack)
	w.OnClosing(func() bool {
		ui.Stop()
		return true
	})
	w.Show()
}
Пример #4
0
// Initializes the GUI. Function is passed to ui.Do.
func initGui() {
	var cs, ps, ns song
	var player *gst.Element
	var playing bool

	// Creates the initial songs that will be used as long as the program runs.
	cs = song{api: &current.Current.songAPIType}
	ps = song{api: &current.Previous1.songAPIType}
	// ps2 := song{api: &current.Previous2.songAPIType}
	ns = song{api: &current.Next1.songAPIType}
	// ns2 := song{api: &current.Next2.songAPIType}

	// Creates the player and the controls for the player (as well as label).
	player = initPlayer()
	playing = true
	psl := ui.NewLabel("Currently Playing")
	ppbtn := ui.NewButton("Pause")
	ppbtn.OnClicked(func() {
		if playing {
			ppbtn.SetText("Play")
			player.SetState(gst.STATE_PAUSED)
			psl.SetText("Currently Paused")
		} else {
			ppbtn.SetText("Pause")
			psl.SetText("Currently Playing")
			player.SetState(gst.STATE_PLAYING)
		}
		playing = !playing
	})

	// Creates the notification system
	nt := notificator.New(notificator.Options{
		DefaultIcon: "icon/default.png",
		AppName:     "GoFip",
	})

	// Notification settings. Will be passed to the updateGui goroutine to Check
	// whether or not to send a system notification when the music changes.
	ntc := ui.NewCheckbox("Notifications")
	ntc.SetChecked(true)
	// Defines a closableTicker that is used in the updateGui goroutine
	// This allows to close the ticker when the setting button is unchecked.
	ct := closableTicker{
		ticker: time.NewTicker(1 * time.Minute),
		halt:   make(chan bool, 1),
	}
	prc := ui.NewCheckbox("Periodic Check")
	prc.SetChecked(true)
	prc.OnToggled(func() {
		if !prc.Checked() {
			ct.stop()
		} else {
			ct = closableTicker{
				ticker: time.NewTicker(1 * time.Minute),
				halt:   make(chan bool, 1),
			}
			go updateGui(ct, nt, ntc, &cs, &ps, &ns)
		}
	})

	// Start the goroutine to update the GUI every minute (default behaviour)
	// Uses the closableTicker defined earlier so the goroutine can be stopped.
	go updateGui(ct, nt, ntc, &cs, &ps, &ns)

	// Creating the tabs with the songs as well as settings and credits.
	createTabs(&cs, &ps, &ns)
	ts := ui.NewTab()
	ts.Append("Current", cs.stack)
	ts.Append("Previous", ps.stack)
	ts.Append("Next", ns.stack)
	ts.Append("Settings", ui.NewVerticalStack(ntc, prc))
	ts.Append("Credits", ui.NewLabel("Depado 2015"))

	// Creates the main vertical stack that is passed to the main window.
	mvs := ui.NewVerticalStack(ts, ppbtn, psl)
	// The tab control must be set to stretchy otherwise it won't display the content.
	mvs.SetStretchy(0)

	// Creates the main window and the behaviour on close event.
	window = ui.NewWindow("GoFIP", width, height, mvs)
	window.OnClosing(func() bool {
		ui.Stop()
		return true
	})
	window.Show()

	// Starts the player once the window is shown.
	player.SetState(gst.STATE_PLAYING)
}