本文整理匯總了Golang中github.com/icza/gowut/gwu.Event類的典型用法代碼示例。如果您正苦於以下問題:Golang Event類的具體用法?Golang Event怎麽用?Golang Event使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Event類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: HandleEvent
func (h *MyButtonHandler) HandleEvent(e gwu.Event) {
if _, isButton := e.Src().(gwu.Button); isButton {
ioutil.WriteFile(
fmt.Sprintf("wikiPages/%s", fileName),
[]byte(wikiText), os.FileMode(os.O_WRONLY|os.O_CREATE|os.O_TRUNC|0777))
}
}
示例2: HandleEvent
func (h *MyButtonHandler) HandleEvent(e gwu.Event) {
if b, isButton := e.Src().(gwu.Button); isButton {
b.SetText(b.Text() + h.text)
h.counter++
b.SetToolTip("You've clicked " + strconv.Itoa(h.counter) + " times!")
e.MarkDirty(b)
}
}
示例3: buildTimerDemo
func buildTimerDemo(event gwu.Event) gwu.Comp {
p := gwu.NewPanel()
p.SetCellPadding(3)
// Add timers to a panel which is always attached instead of our panel
// because the user can switch to another component demo causing this panel to be removed
// and that way timer events would address components that are not part of the window (returning error).
hiddenPan := event.Session().Attr("hiddenPan").(gwu.Panel)
p.Add(gwu.NewLabel("A Timer is used to detonate a bomb after 3 seconds."))
p.AddVSpace(10)
defText := "You can defuse the bomb with the button below. Tick... Tack..."
l := gwu.NewLabel(defText)
p.Add(l)
t := gwu.NewTimer(3 * time.Second)
b := gwu.NewButton("Defuse!")
t.AddEHandlerFunc(func(e gwu.Event) {
l.SetText("BOOOOM! You were too slow!")
l.Style().SetColor(gwu.CLR_RED)
b.SetEnabled(false)
e.MarkDirty(l, b)
}, gwu.ETYPE_STATE_CHANGE)
hiddenPan.Add(t)
row := gwu.NewHorizontalPanel()
b.AddEHandlerFunc(func(e gwu.Event) {
t.SetActive(false)
l.SetText("Bomb defused! Phew! Good Job!")
l.Style().SetColor(gwu.CLR_GREEN)
b.SetEnabled(false)
e.MarkDirty(t, l, b)
}, gwu.ETYPE_CLICK)
row.Add(b)
b2 := gwu.NewButton("Plant a new Bomb!")
b2.AddEHandlerFunc(func(e gwu.Event) {
t.SetActive(true)
t.Reset()
l.SetText(defText)
l.Style().SetColor("")
b.SetEnabled(true)
e.MarkDirty(t, l, b)
}, gwu.ETYPE_CLICK)
row.Add(b2)
p.Add(row)
p.AddVSpace(20)
p.Add(gwu.NewLabel("A Timer is used to refresh the time below repeatedly in every second for half a minute."))
tl := gwu.NewLabel("")
p.Add(tl)
t2 := gwu.NewTimer(time.Second)
t2.SetRepeat(true)
counter := 30
t2.AddEHandlerFunc(func(e gwu.Event) {
counter--
tl.SetText(fmt.Sprintf("%s (%d remaining)", time.Now().Format("2006-01-02 15:04:05"), counter))
e.MarkDirty(tl)
if counter <= 0 {
t2.SetActive(false)
e.MarkDirty(t2)
}
}, gwu.ETYPE_STATE_CHANGE)
hiddenPan.Add(t2)
b3 := gwu.NewButton("Restart")
b3.AddEHandlerFunc(func(e gwu.Event) {
counter = 30
t2.SetActive(true)
e.MarkDirty(t2)
}, gwu.ETYPE_CLICK)
p.Add(b3)
event.MarkDirty(hiddenPan)
return p
}
示例4: HandleEvent
func (zz ExpanderHandler) HandleEvent(e gwu.Event) {
switch t := e.Src().(type) {
case gwu.Expander:
dir, _ := expanderDir[t]
//fmt.Println("Dir=" + dir)
files, _ := ioutil.ReadDir(dir)
var p gwu.Panel
var table gwu.Table
p = nil
dirList := make([]gwu.Comp, 0, 0)
fileLabelList := make([]gwu.Comp, 0, 0)
fileTimeList := make([]gwu.Comp, 0, 0)
fileSizeList := make([]gwu.Comp, 0, 0)
for _, f := range files {
if p == nil {
p = gwu.NewPanel()
t.SetContent(p)
table = gwu.NewTable()
table.SetCellPadding(5)
p.Add(table)
}
if f.IsDir() {
// owned by root // only works on linux
newExpander := makeExpander(f.Name())
newExpander.SetToolTip("DIR - Click to view contents")
newExpander.Style().SetColor("blue")
if dir == "/" {
expanderDir[newExpander] = dir + f.Name()
} else {
expanderDir[newExpander] = dir + "/" + f.Name()
}
newExpander.AddEHandler(handler, gwu.ETYPE_STATE_CHANGE)
dirList = append(dirList, newExpander)
} else {
fileLabel := gwu.NewLabel(f.Name())
fileLabel.Style().SetPaddingLeft("20")
fileLabel.SetToolTip("FILE")
fileLabel.AddEHandler(foobar, gwu.ETYPE_MOUSE_DOWN)
fileLabelList = append(fileLabelList, fileLabel)
fileTimeLabel := gwu.NewLabel(f.ModTime().Format(layout))
fileTimeList = append(fileTimeList, fileTimeLabel)
fileSizeLabel := gwu.NewLabel(strconv.FormatInt(f.Size(), 10) + "k")
fileSizeList = append(fileSizeList, fileSizeLabel)
}
}
row := 0
for _, dir := range dirList {
table.Add(dir, row, 0)
row = row + 1
}
for i, _ := range fileLabelList {
table.Add(fileLabelList[i], row, 0)
rfmt := table.CellFmt(row, 0)
rfmt.SetHAlign(gwu.HA_LEFT)
rfmt.SetVAlign(gwu.VA_TOP)
table.Add(fileTimeList[i], row, 1)
rfmt = table.CellFmt(row, 1)
rfmt.SetHAlign(gwu.HA_LEFT)
rfmt.SetVAlign(gwu.VA_TOP)
table.Add(fileSizeList[i], row, 2)
rfmt = table.CellFmt(row, 2)
rfmt.SetHAlign(gwu.HA_RIGHT)
rfmt.SetVAlign(gwu.VA_TOP)
row = row + 1
}
default:
// t is some other type that we didn't name.
}
}