當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Driver.CallSync方法代碼示例

本文整理匯總了Golang中github.com/google/gxui.Driver.CallSync方法的典型用法代碼示例。如果您正苦於以下問題:Golang Driver.CallSync方法的具體用法?Golang Driver.CallSync怎麽用?Golang Driver.CallSync使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/google/gxui.Driver的用法示例。


在下文中一共展示了Driver.CallSync方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: appMain


//.........這裏部分代碼省略.........
		}
		downloadedCerts = append(downloadedCerts, cert)
		urlTextBox.SetText("")
		updateDownloadedCerts()
	}

	urlTextBox.OnTextChanged(func([]gxui.TextBoxEdit) {
		isEmpty := (urlTextBox.Text() == "")
		fetchButton.SetVisible(!isEmpty)
	})
	urlTextBox.OnKeyPress(func(event gxui.KeyboardEvent) {
		char := event.Key
		if char == gxui.KeyEnter || char == gxui.KeyKpEnter {
			isEmpty := (urlTextBox.Text() == "")
			if !isEmpty {
				downloadCert()
			}
		}
	})

	fetchButton.OnClick(func(gxui.MouseEvent) {
		downloadCert()
	})

	removeButton.OnClick(func(gxui.MouseEvent) {
		if uploading {
			return
		}
		selected := certList.Selected()
		i := certList.Adapter().ItemIndex(selected)
		downloadedCerts = append(downloadedCerts[:i], downloadedCerts[i+1:]...)
		updateDownloadedCerts()
		removeButton.SetVisible(false)
	})
	certList.OnSelectionChanged(func(gxui.AdapterItem) {
		removeButton.SetVisible(true)
	})
	removeButton.SetVisible(false)

	refreshPortList := func() {
		if uploading {
			return
		}
		if list, err := serial.GetPortsList(); err != nil {
			log.Println("Error fetching serial ports" + err.Error())
		} else {
			portListAdapter.SetItems(list)
		}
	}
	refreshPortList()

	refreshButton.OnClick(func(gxui.MouseEvent) {
		refreshPortList()
		portSelected = false
		updateUploadButton()
	})
	portList.OnSelectionChanged(func(gxui.AdapterItem) {
		portSelected = true
		updateUploadButton()
	})

	updateProgress := func(msg string, percent int) {
		time.Sleep(time.Second)
		driver.CallSync(func() {
			if percent == -1 {
				progressStatus.SetColor(gxui.Red)
				progressBar.SetVisible(false)
			} else if percent == 100 {
				progressStatus.SetColor(gxui.Green)
				progressBar.SetVisible(false)
			} else {
				progressStatus.SetColor(gxui.White)
				progressBar.SetProgress(percent)
				progressBar.SetVisible(true)
			}
			progressStatus.SetText(msg)
		})
	}
	progressBar.SetVisible(false)

	uploadButton.OnClick(func(gxui.MouseEvent) {
		if uploading {
			return
		}
		port := portList.Selected().(string)
		uploading = true
		go uploadCertificates(port, driver, updateProgress)
		log.Println(port)
	})

	updateDownloadedCerts()

	window := theme.CreateWindow(800, 600, "Linear layout")
	window.SetTitle("WINC1500 SSL Certificate updater")
	window.SetScale(flags.DefaultScaleFactor)
	window.AddChild(layout)
	window.OnClose(driver.Terminate)
	window.SetPadding(math.Spacing{L: 10, T: 10, R: 10, B: 10})
	window.Relayout()
}
開發者ID:adafruit,項目名稱:WiFi101-FirmwareUpdater,代碼行數:101,代碼來源:winc1500-uploader-gui.go


注:本文中的github.com/google/gxui.Driver.CallSync方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。