move to go.wit.com/gui/gadgets

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2023-12-29 02:43:00 -06:00
parent 5d32baf06e
commit a3dd21aef0
5 changed files with 23 additions and 153 deletions

View File

@ -1,83 +0,0 @@
// This is a simple example
package cloudflare
import (
"log"
"fmt"
"time"
"go.wit.com/gui"
)
// TODO: use: https://github.com/robfig/cron/
// ttl := cloudflare.DurationSlider(g2, "control panel TTL (in tenths of seconds)", 10 * time.Millisecond, 5 * time.Second)
// ttl.Set(200 * time.Millisecond)
// The Node is a binary tree. This is how all GUI elements are stored
// simply the name and the size of whatever GUI element exists
type Duration struct {
p *gui.Node // parent widget
l *gui.Node // label widget
s *gui.Node // slider widget
Label string
Low time.Duration
High time.Duration
Duration time.Duration
Custom func()
}
func (n *Duration) Set(d time.Duration) {
var timeRange, step, offset time.Duration
if (d > n.High) {
d = n.High
}
if (d < n.Low) {
d = n.Low
}
// set the duration
n.Duration = d
// figure out the integer offset for the Slider GUI Widget
timeRange = n.High - n.Low
step = timeRange / 1000
if (step == 0) {
log.Println("duration.Set() division by step == 0", n.Low, n.High, timeRange, step)
n.s.Set(0)
return
}
offset = d - n.Low
i := int(offset / step)
log.Println("duration.Set() =", n.Low, n.High, d, "i =", i)
n.s.I = i
n.s.Set(i)
n.s.Custom()
}
func NewDurationSlider(n *gui.Node, label string, low time.Duration, high time.Duration) *Duration {
d := Duration {
p: n,
Label: label,
High: high,
Low: low,
}
// various timeout settings
d.l = n.NewLabel(label)
d.s = n.NewSlider(label, 0, 1000)
d.s.Custom = func () {
d.Duration = low + (high - low) * time.Duration(d.s.I) / 1000
log.Println("d.Duration =", d.Duration)
s := fmt.Sprintf("%s (%v)", d.Label, d.Duration)
d.l.SetText(s)
if (d.Custom != nil) {
d.Custom()
}
}
return &d
}

View File

@ -1,48 +0,0 @@
// This is a simple example
package cloudflare
import (
"go.wit.com/log"
"go.wit.com/gui"
)
type OneLiner struct {
p *gui.Node // parent widget
l *gui.Node // label widget
v *gui.Node // value widget
value string
label string
Custom func()
}
func (n *OneLiner) Get() string {
return n.value
}
func (n *OneLiner) Set(value string) *OneLiner {
log.Println("OneLiner.Set() =", value)
if (n.v != nil) {
n.v.Set(value)
}
n.value = value
return n
}
func NewOneLiner(n *gui.Node, name string) *OneLiner {
d := OneLiner {
p: n,
value: "",
}
// various timeout settings
d.l = n.NewLabel(name)
d.v = n.NewLabel("")
d.v.Custom = func() {
d.value = d.v.S
log.Println("OneLiner.Custom() user changed value to =", d.value)
}
return &d
}

View File

@ -21,7 +21,7 @@ import (
"go.wit.com/log" "go.wit.com/log"
"go.wit.com/gui" "go.wit.com/gui"
"go.wit.com/control-panel-dns/cloudflare" "go.wit.com/gui/gadgets"
"go.wit.com/shell" "go.wit.com/shell"
"github.com/miekg/dns" "github.com/miekg/dns"
@ -40,10 +40,10 @@ type digStatus struct {
box *gui.Node box *gui.Node
summary *gui.Node summary *gui.Node
status *cloudflare.OneLiner status *gadgets.OneLiner
statusAAAA *cloudflare.OneLiner statusAAAA *gadgets.OneLiner
speed *cloudflare.OneLiner speed *gadgets.OneLiner
speedActual *cloudflare.OneLiner speedActual *gadgets.OneLiner
details *gui.Node details *gui.Node
dsLocalhost *dnsStatus dsLocalhost *dnsStatus
@ -53,8 +53,8 @@ type digStatus struct {
DnsDigUDP *gui.Node DnsDigUDP *gui.Node
DnsDigTCP *gui.Node DnsDigTCP *gui.Node
httpGoWitCom *cloudflare.OneLiner httpGoWitCom *gadgets.OneLiner
statusHTTP *cloudflare.OneLiner statusHTTP *gadgets.OneLiner
} }
type dnsStatus struct { type dnsStatus struct {
@ -104,11 +104,11 @@ func NewDigStatusWindow(p *gui.Node) *digStatus {
g := ds.summary.NewGrid("LookupStatus", 2, 2) g := ds.summary.NewGrid("LookupStatus", 2, 2)
g.Pad() g.Pad()
ds.status = cloudflare.NewOneLiner(g, "status").Set("unknown") ds.status = gadgets.NewOneLiner(g, "status").Set("unknown")
ds.statusAAAA = cloudflare.NewOneLiner(g, "IPv6 status").Set("unknown") ds.statusAAAA = gadgets.NewOneLiner(g, "IPv6 status").Set("unknown")
ds.statusHTTP = cloudflare.NewOneLiner(g, "IPv6 via HTTP").Set("unknown") ds.statusHTTP = gadgets.NewOneLiner(g, "IPv6 via HTTP").Set("unknown")
ds.speed = cloudflare.NewOneLiner(g, "speed").Set("unknown") ds.speed = gadgets.NewOneLiner(g, "speed").Set("unknown")
ds.speedActual = cloudflare.NewOneLiner(g, "actual").Set("unknown") ds.speedActual = gadgets.NewOneLiner(g, "actual").Set("unknown")
// make the area to store the raw details // make the area to store the raw details
ds.details = ds.box.NewGroup("Details") ds.details = ds.box.NewGroup("Details")
@ -200,9 +200,9 @@ func (ds *digStatus) set(a any, s string) {
n.SetText(s) n.SetText(s)
return return
} }
var ol *cloudflare.OneLiner var ol *gadgets.OneLiner
if reflect.TypeOf(a) == reflect.TypeOf(ol) { if reflect.TypeOf(a) == reflect.TypeOf(ol) {
ol = a.(*cloudflare.OneLiner) ol = a.(*gadgets.OneLiner)
ol.Set(s) ol.Set(s)
return return
} }
@ -374,7 +374,7 @@ func (ds *digStatus) makeHttpStatusGrid() {
group := ds.details.NewGroup("dns.google.com via HTTPS") group := ds.details.NewGroup("dns.google.com via HTTPS")
grid := group.NewGrid("LookupStatus", 2, 2) grid := group.NewGrid("LookupStatus", 2, 2)
ds.httpGoWitCom = cloudflare.NewOneLiner(grid, "go.wit.com") ds.httpGoWitCom = gadgets.NewOneLiner(grid, "go.wit.com")
me.digStatus.set(ds.httpGoWitCom, "unknown") me.digStatus.set(ds.httpGoWitCom, "unknown")
group.Pad() group.Pad()

7
gui.go
View File

@ -11,6 +11,7 @@ import (
"strings" "strings"
"go.wit.com/gui" "go.wit.com/gui"
"go.wit.com/gui/gadgets"
"go.wit.com/log" "go.wit.com/log"
"go.wit.com/shell" "go.wit.com/shell"
"go.wit.com/control-panel-dns/cloudflare" "go.wit.com/control-panel-dns/cloudflare"
@ -178,11 +179,11 @@ func debugTab(title string) {
} }
// makes a slider widget // makes a slider widget
me.ttl = cloudflare.NewDurationSlider(g2, "Loop Timeout", 10 * time.Millisecond, 5 * time.Second) me.ttl = gadgets.NewDurationSlider(g2, "Loop Timeout", 10 * time.Millisecond, 5 * time.Second)
me.ttl.Set(300 * time.Millisecond) me.ttl.Set(300 * time.Millisecond)
// makes a slider widget // makes a slider widget
me.dnsTtl = cloudflare.NewDurationSlider(g2, "DNS Timeout", 800 * time.Millisecond, 300 * time.Second) me.dnsTtl = gadgets.NewDurationSlider(g2, "DNS Timeout", 800 * time.Millisecond, 300 * time.Second)
me.dnsTtl.Set(60 * time.Second) me.dnsTtl.Set(60 * time.Second)
g2.Margin() g2.Margin()
@ -358,7 +359,7 @@ func statusGrid(n *gui.Node) {
gridP.NewLabel("DNS Status =") gridP.NewLabel("DNS Status =")
me.DnsStatus = gridP.NewLabel("unknown") me.DnsStatus = gridP.NewLabel("unknown")
me.statusIPv6 = cloudflare.NewOneLiner(gridP, "IPv6 working") me.statusIPv6 = gadgets.NewOneLiner(gridP, "IPv6 working")
me.statusIPv6.Set("known") me.statusIPv6.Set("known")
gridP.NewLabel("hostname =") gridP.NewLabel("hostname =")

View File

@ -5,7 +5,7 @@ import (
"net" "net"
"time" "time"
"go.wit.com/gui" "go.wit.com/gui"
"go.wit.com/control-panel-dns/cloudflare" "go.wit.com/gui/gadgets"
"github.com/miekg/dns" "github.com/miekg/dns"
) )
@ -24,8 +24,8 @@ type Host struct {
artificialSleep float64 `default:"0.7"` // artificial sleep on startup artificialSleep float64 `default:"0.7"` // artificial sleep on startup
artificialS string `default:"abc"` // artificial sleep on startup artificialS string `default:"abc"` // artificial sleep on startup
ttl *cloudflare.Duration ttl *gadgets.Duration
dnsTtl *cloudflare.Duration dnsTtl *gadgets.Duration
dnsSleep time.Duration dnsSleep time.Duration
localSleep time.Duration localSleep time.Duration
@ -75,7 +75,7 @@ type Host struct {
dbProc *gui.Node // button for setting proc debugging on dbProc *gui.Node // button for setting proc debugging on
digStatus *digStatus digStatus *digStatus
statusIPv6 *cloudflare.OneLiner statusIPv6 *gadgets.OneLiner
digStatusButton *gui.Node digStatusButton *gui.Node
hostnameStatus *hostnameStatus hostnameStatus *hostnameStatus