keyboard support
This commit is contained in:
parent
962e7cce3b
commit
0fe8a10bc3
25
main.go
25
main.go
@ -49,7 +49,10 @@ func main() {
|
||||
ui.MainWindow.SetWindowTitle(os.Args[1] + " - " + appName)
|
||||
|
||||
ui.infoArea.AddItem(fmt.Sprintf("Sorting %d entries", len(entries)))
|
||||
ui.infoArea.AddItem("Use [Q] and [Z] to select with the keyboard")
|
||||
ui.infoArea.ScrollToBottom()
|
||||
|
||||
active := true
|
||||
ret := make(chan bool, 0)
|
||||
ui.b1.OnClicked(func() { // Set up click handlers only once
|
||||
ret <- true
|
||||
@ -58,8 +61,29 @@ func main() {
|
||||
ret <- false
|
||||
})
|
||||
|
||||
ui.MainWindow.OnKeyPressEvent(func(super func(event *qt.QKeyEvent), event *qt.QKeyEvent) {
|
||||
if !active {
|
||||
super(event)
|
||||
return
|
||||
}
|
||||
|
||||
keytext := strings.ToLower(event.Text())
|
||||
if keytext == `q` {
|
||||
ret <- true
|
||||
|
||||
} else if keytext == `z` {
|
||||
ret <- false
|
||||
|
||||
} else { // not our event
|
||||
super(event)
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
ui.MainWindow.Show()
|
||||
|
||||
ui.infoArea.SetFocusPolicy(qt.NoFocus) // prevent stealing keyboard input
|
||||
|
||||
comparisons := 0
|
||||
|
||||
go func() {
|
||||
@ -78,6 +102,7 @@ func main() {
|
||||
|
||||
return <-ret
|
||||
})
|
||||
active = false
|
||||
|
||||
mainthread.Start(func() {
|
||||
ui.b1.SetEnabled(false)
|
||||
|
Loading…
x
Reference in New Issue
Block a user