Пример #1
0
func main() {
	go ui.Do(func() {
		name := ui.NewTextField()
		button := ui.NewButton("greet")
		greeting := ui.NewLabel("")

		stack := ui.NewVerticalStack(
			ui.NewLabel("name:"),
			name,
			button,
			greeting)

		window = ui.NewWindow("hello world", 200, 100, stack)

		button.OnClicked(func() {
			greeting.SetText("hello, " + name.Text() + "!")
		})

		window.OnClosing(func() bool {
			ui.Stop()
			return true
		})

		window.Show()
	})

	err := ui.Go()
	if err != nil {
		panic(err)
	}
}
Пример #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 gui() {
	commands := spotify.Commands()
	leftButton := ui.NewButton("<<")
	playButton := ui.NewButton("||")
	rightButton := ui.NewButton(">>")

	leftButton.OnClicked(func() {
		spotify.Execute(commands["previousTrack"])
	})

	playButton.OnClicked(func() {
		spotify.Execute(commands["playpause"])
	})

	rightButton.OnClicked(func() {
		spotify.Execute(commands["nextTrack"])
	})

	stack := ui.NewHorizontalStack(
		leftButton,
		playButton,
		rightButton)

	w := ui.NewWindow("Spotify Client", 90, 25, stack)
	w.OnClosing(func() bool {
		ui.Stop()
		return true
	})
	w.Show()
}
Пример #4
0
func showPreview(img *image.RGBA) {
	w2 = ui.NewWindow("Stuff", img.Bounds().Dx(), img.Bounds().Dy(), ui.NewArea(img.Bounds().Dx(), img.Bounds().Dy(), (*imageArea)(img)))
	w2.OnClosing(func() bool {
		ui.Stop()
		return true
	})
	w2.Show()
}
Пример #5
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()
}
Пример #6
0
func initUI() {
	button := ui.NewButton("Load")
	button.OnClicked(func() {
		ui.OpenFile(w, func(filename string) {
			go renderPreview(filename)
		})
	})

	stack := ui.NewVerticalStack(button)

	w = ui.NewWindow("Video", 800, 600, stack)
	w.OnClosing(func() bool {
		ui.Stop()
		return true
	})
	w.Show()
}
Пример #7
0
func gui() {
	// All windows must have a control inside.
	// ui.Space() creates a control that is just a blank space for us to use.
	newControl := ui.Space()

	// Then we create a window.
	w := ui.NewWindow("Window", 280, 350, newControl)

	// We tell package ui to destroy our window and shut down cleanly when the user closes the window by clicking the X button in the titlebar.
	w.OnClosing(func() bool {
		// This informs package ui to shut down cleanly when it can.
		ui.Stop()
		// And this informs package ui that we want to hide AND destroy the window.
		return true
	})

	// And finally, we need to show the window.
	w.Show()
}
Пример #8
0
func main() {
	simulation.Init()

	timer_10ms := time.Tick(10 * time.Millisecond)

	go ui.Do(func() {
		widthFloat := float64(inWidth * dpi)
		heightFloat := float64(inHeight * dpi)
		width := int(widthFloat)
		height := int(heightFloat)

		// Give ourselves a drawable canvas:
		canvas := &canvasArea{
			img: image.NewRGBA(image.Rect(0, 0, width, height)),
		}
		area := ui.NewArea(width, height, canvas)
		w := ui.NewWindow("e-minor v2", width+8*2, height+28*2, area)
		w.SetMargined(false)
		w.OnClosing(func() bool {
			ui.Stop()
			return true
		})

		w.Show()

		// This *should* be in the main UI message loop, but the 'ui' package does not expose the message loop.
		go func() {
			for {
				select {
				case <-timer_10ms:
					simulation.Timer_10msec()
				default:
					simulation.Handle()
				}
			}
		}()
	})

	err := ui.Go()
	if err != nil {
		panic(err)
	}
}
Пример #9
0
func main() {
	go ui.Do(func() {
		textview := ui.NewTextbox()
		textview.SetText("asd")

		window = ui.NewWindow("Hello", 300, 300, textview)
		window.OnClosing(func() bool {
			ui.Stop()
			return true
		})

		window.Show()
	})
	go startListen()
	err := ui.Go()
	if err != nil {
		panic(err)
	}

}
Пример #10
0
func gui() {
	connect()
	var c Container

	//Stack for the control
	l := ui.NewLabel("Image to start")
	imageName := ui.NewTextField()
	imageName.SetText("ipython/scipystack")
	startBtn := ui.NewButton("Launch")
	controlStack := ui.NewVerticalStack(l, imageName, startBtn)
	controlGrp := ui.NewGroup("Launch Image", controlStack)
	controlGrp.SetMargined(true)

	// Table of running containers
	table := ui.NewTable(reflect.TypeOf(c))
	openBrowserBtn := ui.NewButton("Open in browser")
	killBtn := ui.NewButton("Kill")
	manageRunningContainerGrp := ui.NewHorizontalStack(openBrowserBtn, killBtn)
	containerControlGrp := ui.NewVerticalStack(table, manageRunningContainerGrp)
	containerListGrp := ui.NewGroup("Running containers", containerControlGrp)
	containerListGrp.SetMargined(true)

	//Container info area
	selectedContainerInfo := ui.NewTextField()

	// Now make a new 2 column stack
	topStack := ui.NewHorizontalStack(controlGrp, containerListGrp)
	topStack.SetStretchy(0)
	topStack.SetStretchy(1)

	mainStack := ui.NewVerticalStack(topStack, selectedContainerInfo)
	mainStack.SetStretchy(0)
	mainStack.SetStretchy(1)

	startBtn.OnClicked(func() {
		go Start(imageName.Text())
	})

	table.OnSelected(func() {
		c := table.Selected()
		table.Lock()
		d := table.Data().(*[]Container)
		//this makes a shallow copy of the structure so that we can access elements per
		//   http://giantmachines.tumblr.com/post/51007535999/golang-struct-shallow-copy
		newC := *d
		table.Unlock()
		if c > -1 {
			fmt.Println("Getting info for container ", newC[c].Name)
			selectedContainerInfo.SetText(Info(newC[c].Name))
		}
	})

	openBrowserBtn.OnClicked(func() {
		c := table.Selected()
		table.Lock()
		d := table.Data().(*[]Container)
		//this makes a shallow copy of the structure so that we can access elements per
		//   http://giantmachines.tumblr.com/post/51007535999/golang-struct-shallow-copy
		newC := *d
		table.Unlock()
		url := fmt.Sprintf("%s.%s", newC[c].Name, os.Getenv("DOMAIN_NAME"))
		webbrowser.Open(url)
	})

	killBtn.OnClicked(func() {
		c := table.Selected()
		table.Lock()
		d := table.Data().(*[]Container)
		//this makes a shallow copy of the structure so that we can access elements per
		//   http://giantmachines.tumblr.com/post/51007535999/golang-struct-shallow-copy
		newC := *d
		table.Unlock()
		go Kill(newC[c].Name)
	})

	w = ui.NewWindow("Manage Containers on RCS", 600, 450, mainStack)
	w.SetMargined(true)

	w.OnClosing(func() bool {
		ui.Stop()
		return true
	})
	go updateTable(table)
	w.Show()

}
Пример #11
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)
}
Пример #12
0
func gui() {

	//Define endpoint
	apiEndpointLabel := ui.NewLabel("API Endpoint:")
	apiEndpointTextField := ui.NewTextField()
	if len(os.Getenv("CARINA_API_ENDPOINT")) > 0 {
		apiEndpointTextField.SetText(os.Getenv("CARINA_API_ENDPOINT"))
	} else {
		apiEndpointTextField.SetText(libcarina.BetaEndpoint)
	}
	//Define credentials area
	usernameLabel := ui.NewLabel("Username:"******"CARINA_USERNAME")) > 0 {
		usernameTextField.SetText(os.Getenv("CARINA_USERNAME"))
	}
	apiKeyLabel := ui.NewLabel("API Key:")
	apiKeyTextField := ui.NewPasswordField()
	if len(os.Getenv("CARINA_APIKEY")) > 0 {
		apiKeyTextField.SetText(os.Getenv("CARINA_APIKEY"))
	}
	connectBtn := ui.NewButton("Connect")

	// layout the login controls on a grid
	loginGrid := ui.NewGrid()
	loginGrid.Add(apiEndpointLabel, nil, ui.East, true, ui.LeftTop, false, ui.Center, 1, 1)
	loginGrid.Add(apiEndpointTextField, apiEndpointLabel, ui.South, true, ui.Fill, false, ui.Center, 1, 1)
	loginGrid.Add(usernameLabel, apiEndpointLabel, ui.East, true, ui.LeftTop, false, ui.Center, 1, 1)
	loginGrid.Add(usernameTextField, usernameLabel, ui.South, true, ui.Fill, false, ui.Center, 1, 1)
	loginGrid.Add(apiKeyLabel, usernameLabel, ui.East, true, ui.LeftTop, false, ui.Center, 1, 1)
	loginGrid.Add(apiKeyTextField, apiKeyLabel, ui.South, true, ui.Fill, false, ui.Center, 1, 1)
	loginGrid.Add(connectBtn, nil, ui.East, true, ui.LeftTop, false, ui.Center, 1, 1)
	loginGrid.SetPadded(true)

	//div grp1
	divGrp1 := ui.NewGroup("", ui.Space())
	divGrp1.SetMargined(true)

	// Define the table that lists all running clusters
	var c libcarina.Cluster
	clusterListTable := ui.NewTable(reflect.TypeOf(c))

	// Create control buttons
	newBtn := ui.NewButton("New")
	growBtn := ui.NewButton("Grow")
	rebuildBtn := ui.NewButton("Rebuild")
	credentialsBtn := ui.NewButton("Credentials")
	deleteBtn := ui.NewButton("Delete")
	buttonStack := ui.NewVerticalStack(newBtn, growBtn, rebuildBtn, credentialsBtn, deleteBtn)

	//div grp2
	divGrp2 := ui.NewGroup("", ui.Space())
	divGrp2.SetMargined(true)

	//Show containers on the cluster
	containerListLabel := ui.NewLabel("Containers")
	var cont dockerclient.Container
	containerListTable := ui.NewTable(reflect.TypeOf(cont))

	mainGrid := ui.NewGrid()
	mainGrid.Add(loginGrid, nil, ui.East, true, ui.Fill, false, ui.Center, 12, 1)
	mainGrid.Add(divGrp1, loginGrid, ui.South, true, ui.Fill, false, ui.Center, 12, 1)
	mainGrid.Add(clusterListTable, divGrp1, ui.South, true, ui.Fill, false, ui.Center, 9, 1)
	mainGrid.Add(buttonStack, clusterListTable, ui.East, true, ui.Fill, false, ui.Center, 3, 1)
	mainGrid.Add(divGrp2, clusterListTable, ui.South, true, ui.Fill, false, ui.Center, 12, 1)
	mainGrid.Add(containerListLabel, divGrp2, ui.South, true, ui.Fill, false, ui.Center, 12, 1)
	mainGrid.Add(containerListTable, containerListLabel, ui.South, true, ui.Fill, false, ui.Center, 12, 1)
	mainGrid.SetPadded(true)

	connectBtn.OnClicked(func() {
		connect(apiEndpointTextField.Text(), usernameTextField.Text(), apiKeyTextField.Text())
		go monitorClusterList(clusterListTable)
	})

	clusterListTable.OnSelected(func() {
		c, found := getSelectedCluster(clusterListTable)
		if found {
			if c.Status == "active" {
				containers := getContainers(c.ClusterName)
				containerListTable.Lock()
				d := containerListTable.Data().(*[]dockerclient.Container)
				*d = containers
				containerListTable.Unlock()
				txt := fmt.Sprintf("%d containers running on %s cluster", len(containers), c.ClusterName)
				containerListLabel.SetText(txt)
			}
		}
	})

	newBtn.OnClicked(func() {
		if loggedInFlag {
			newCluster()
		}
	})

	deleteBtn.OnClicked(func() {
		c, found := getSelectedCluster(clusterListTable)
		if found {
			carinaClient.Delete(c.ClusterName)
			fmt.Println("Deleting", c.ClusterName)
		}
	})

	rebuildBtn.OnClicked(func() {
		c, found := getSelectedCluster(clusterListTable)
		if found {
			fmt.Println("Rebuiding", c.ClusterName)
			carinaClient.Rebuild(c.ClusterName)
		}
	})

	credentialsBtn.OnClicked(func() {
		c, found := getSelectedCluster(clusterListTable)
		if found {
			fmt.Println("Getting credentials for", c.ClusterName)
			carinaClient.GetCredentials(c.ClusterName)
		}
	})

	growBtn.OnClicked(func() {
		c, found := getSelectedCluster(clusterListTable)
		if found {
			fmt.Println("Growing", c.ClusterName)
		}
	})

	//Main stack of the interfaces
	w = ui.NewWindow("Carina by Rackspace GUI Client ("+VERSION+")", 620, 300, mainGrid)
	w.SetMargined(true)

	w.OnClosing(func() bool {
		ui.Stop()
		return true
	})
	w.Show()

}