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() }
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() }