Skip to content

Commit

Permalink
show the macro keys in fyne
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Thienel <[email protected]>
  • Loading branch information
ftl committed Dec 8, 2024
1 parent 6ef9c73 commit 1c8bd11
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 23 deletions.
2 changes: 1 addition & 1 deletion core/keyer/keyer.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const PatternCount = 4

// ButtonView represents the visual parts of trigger the transmission of the keyer macros.
type ButtonView interface {
ShowMessage(...interface{})
ShowMessage(...any)
SetLabel(int, string)
SetPattern(int, string)
SetSpeed(int)
Expand Down
19 changes: 11 additions & 8 deletions fyneui/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ type application struct {
version string
sponsors string

app fyne.App
shortcuts *Shortcuts
mainWindow *mainWindow
mainMenu *mainMenu
qsoList *qsoList
statusBar *statusBar
app fyne.App
shortcuts *Shortcuts
mainWindow *mainWindow
mainMenu *mainMenu
qsoList *qsoList
keyerControl *keyerControl
statusBar *statusBar

controller *app.Controller
}
Expand All @@ -51,20 +52,22 @@ func (a *application) activate() {

a.shortcuts = setupShortcuts(a.controller)
a.qsoList = setupQSOList()
a.keyerControl = setupKeyerControl()
a.statusBar = setupStatusBar()

mainWindow := a.app.NewWindow("Hello Contest")
a.mainWindow = setupMainWindow(mainWindow, a.qsoList, a.statusBar)
a.mainWindow = setupMainWindow(mainWindow, a.qsoList, a.keyerControl, a.statusBar)
a.shortcuts.AddTo(mainWindow.Canvas())

a.mainMenu = setupMainMenu(a.mainWindow.window, a.controller, a.shortcuts)

a.qsoList.SetLogbookController(a.controller.QSOList)
a.keyerControl.SetKeyerController(a.controller.Keyer)

a.controller.SetView(a.mainWindow)
a.controller.QSOList.Notify(a.qsoList)
a.controller.Keyer.SetView(a.keyerControl)
a.controller.ServiceStatus.Notify(a.statusBar)

a.controller.Refresh()

a.mainWindow.UseDefaultWindowGeometry() // TODO: store/restore the window geometry
Expand Down
138 changes: 138 additions & 0 deletions fyneui/keyerControl.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
package fyneui

import (
"fmt"
"log"

"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/widget"
)

const parrot = "🦜"

// KeyerController controls the keyer.
type KeyerController interface {
Send(int)
Stop()
EnterSpeed(int)
OpenKeyerSettings()
}

func setupKeyerControl() *keyerControl {
result := &keyerControl{}

result.stop = widget.NewButton("ESC: Stop TX", result.onStop)
result.buttons = []*widget.Button{
widget.NewButton("F1", result.onMacro(0)),
widget.NewButton("F2", result.onMacro(1)),
widget.NewButton("F3", result.onMacro(2)),
widget.NewButton("F4", result.onMacro(3)),
}
result.macros = widget.NewButton("Macros...", result.onMacros)

result.container = container.NewGridWithColumns(5,
result.stop, result.buttons[0], result.buttons[1], result.buttons[2], result.buttons[3],
result.macros,
)

return result
}

type keyerControl struct {
container *fyne.Container
controller KeyerController

cqLabelText string
parrotActive bool

stop *widget.Button
buttons []*widget.Button
macros *widget.Button
// TODO: Speed Control
}

func (c *keyerControl) SetKeyerController(controller KeyerController) {
c.controller = controller
}

func (c *keyerControl) SetParrotActive(active bool) {
c.parrotActive = active
c.updateCQButtonLabel()
}

func (c *keyerControl) ShowMessage(...any) {
// TODO: show this message somewhere
}

func (c *keyerControl) updateCQButtonLabel() {
c.buttons[0].SetText(c.buildLabel(0, c.cqLabelText))
}

func (c *keyerControl) SetLabel(index int, text string) {
if index == 0 {
c.cqLabelText = text
}

label := c.buildLabel(index, text)
c.buttons[index].SetText(label)
}

func (c *keyerControl) buildLabel(index int, text string) string {
var decoration string
if index == 0 && c.parrotActive {
decoration = parrot
} else {
decoration = fmt.Sprintf("F%d", index+1)
}

if text == "" {
return decoration
}
return fmt.Sprintf("%s: %s", decoration, text)
}

func (c *keyerControl) SetPattern(index int, text string) {
// TODO: add tooltip support from https://github.com/dweymouth/fyne-tooltip
// c.buttons[index].SetTooltip(fmt.Sprintf("F%d: %s", index+1, text))
}

func (c *keyerControl) onStop() {
if c.controller == nil {
log.Println("onStop: no keyer controller")
return
}
c.controller.Stop()
}

func (c *keyerControl) onMacro(index int) func() {
return func() {
if c.controller == nil {
log.Printf("onMacro(%d): no keyer controller", index)
return
}
c.controller.Send(index)
}
}

func (c *keyerControl) onMacros() {
if c.controller == nil {
log.Println("onMacros: no keyer controller")
return
}
c.controller.OpenKeyerSettings()
}

func (c *keyerControl) onChangeSpeed(delta int) func() {
// TODO: speed control
return func() {}
}

func (c *keyerControl) onSetSpeed(speed int) func() {
// TODO: speed control
return func() {}
}

func (c *keyerControl) SetSpeed(speed int) {
// TODO: speed control
}
14 changes: 8 additions & 6 deletions fyneui/mainWindow.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,20 @@ type mainWindow struct {
window fyne.Window
}

func setupMainWindow(window fyne.Window, qsoList *qsoList, statusBar *statusBar) *mainWindow {
func setupMainWindow(window fyne.Window, qsoList *qsoList, keyerControl *keyerControl, statusBar *statusBar) *mainWindow {
result := &mainWindow{
window: window,
}
window.SetMaster()

bottom := container.NewVBox(keyerControl.container, statusBar.container)

root := container.NewBorder(
nil, // top
statusBar.container, // bottom
nil, // left
nil, // right
qsoList.container, // center
nil, // top
bottom, // bottom
nil, // left
nil, // right
qsoList.container, // center
)
window.SetContent(root)

Expand Down
8 changes: 0 additions & 8 deletions ui/keyerButtonView.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"log"

"github.com/gotk3/gotk3/gdk"
"github.com/gotk3/gotk3/gtk"
)

Expand All @@ -17,7 +16,6 @@ type KeyerController interface {
Send(int)
Stop()
EnterSpeed(int)
Save()
OpenKeyerSettings()
}

Expand Down Expand Up @@ -52,7 +50,6 @@ func setupKeyerView(builder *gtk.Builder) *keyerView {

result.speedEntry = getUI(builder, "speedEntry").(*gtk.SpinButton)
result.speedEntry.Connect("value-changed", result.onSpeedChanged)
result.speedEntry.Connect("focus_out_event", result.onEntryFocusOut)

return result
}
Expand All @@ -69,11 +66,6 @@ func (v *keyerView) doIgnoreChanges(f func()) {
f()
}

func (v *keyerView) onEntryFocusOut(widget interface{}, _ *gdk.Event) bool {
v.controller.Save()
return false
}

func (k *keyerView) onButton(index int) func(button *gtk.Button) bool {
return func(button *gtk.Button) bool {
if k.controller == nil {
Expand Down

0 comments on commit 1c8bd11

Please sign in to comment.