扫描时禁用按钮

This commit is contained in:
2026-07-17 17:12:22 +08:00
parent b067ffdc8e
commit 4a2086c6f1
2 changed files with 75 additions and 37 deletions
+55 -29
View File
@@ -24,35 +24,61 @@ func clearButton(label string, entry *widget.Entry) *widget.Button {
}) })
} }
func newIPKeypad(entry *widget.Entry) fyne.CanvasObject { func newIPKeypad(entry *widget.Entry) (fyne.CanvasObject, []*widget.Button) {
presets := container.NewHBox( var btns []*widget.Button
keyButton("192.168.", entry), p1 := keyButton("192.168.", entry)
keyButton("169.254.", entry), p2 := keyButton("169.254.", entry)
keyButton("10.", entry), p3 := keyButton("10.", entry)
keyButton("100.", entry), p4 := keyButton("100.", entry)
) btns = append(btns, p1, p2, p3, p4)
numpad := container.NewGridWithColumns(3, presets := container.NewHBox(p1, p2, p3, p4)
keyButton("1", entry), keyButton("2", entry), keyButton("3", entry),
keyButton("4", entry), keyButton("5", entry), keyButton("6", entry), n := []struct{ label string }{
keyButton("7", entry), keyButton("8", entry), keyButton("9", entry), {"1"}, {"2"}, {"3"}, {"4"}, {"5"}, {"6"},
entButton(entry), keyButton("0", entry), keyButton(".", entry), {"7"}, {"8"}, {"9"}, {"0"}, {"/"}, {"-"}, {"."},
keyButton("/", entry), keyButton("-", entry), clearButton("清空IP", entry), }
) var grid []fyne.CanvasObject
return container.NewVBox(presets, numpad) for _, v := range n {
b := keyButton(v.label, entry)
btns = append(btns, b)
grid = append(grid, b)
}
ent := entButton(entry)
btns = append(btns, ent)
grid = append(grid, ent)
clr := clearButton("清空IP", entry)
btns = append(btns, clr)
grid = append(grid, clr)
numpad := container.NewGridWithColumns(3, grid...)
return container.NewVBox(presets, numpad), btns
} }
func newPortKeypad(entry *widget.Entry) fyne.CanvasObject { func newPortKeypad(entry *widget.Entry) (fyne.CanvasObject, []*widget.Button) {
presets := container.NewGridWithColumns(3, var btns []*widget.Button
keyButton("1-65535", entry), keyButton("80;443", entry), keyButton("21", entry), presetLabels := []string{"1-65535", "80;443", "21", "22", "23", "3389", "445", "25565", "25;587"}
keyButton("22", entry), keyButton("23", entry), keyButton("3389", entry), var presetObjs []fyne.CanvasObject
keyButton("445", entry), keyButton("25565", entry), keyButton("25;587", entry), for _, l := range presetLabels {
) b := keyButton(l, entry)
numpad := container.NewGridWithColumns(3, btns = append(btns, b)
keyButton("1", entry), keyButton("2", entry), keyButton("3", entry), presetObjs = append(presetObjs, b)
keyButton("4", entry), keyButton("5", entry), keyButton("6", entry), }
keyButton("7", entry), keyButton("8", entry), keyButton("9", entry), presets := container.NewGridWithColumns(3, presetObjs...)
keyButton("0", entry), keyButton(";", entry), keyButton("-", entry),
entButton(entry), clearButton("清空端口", entry), numLabels := []string{"1", "2", "3", "4", "5", "6", "7", "8", "9", "0", ";", "-"}
) var grid []fyne.CanvasObject
return container.NewVBox(presets, numpad) for _, l := range numLabels {
b := keyButton(l, entry)
btns = append(btns, b)
grid = append(grid, b)
}
ent := entButton(entry)
btns = append(btns, ent)
grid = append(grid, ent)
clr := clearButton("清空端口", entry)
btns = append(btns, clr)
grid = append(grid, clr)
numpad := container.NewGridWithColumns(3, grid...)
return container.NewVBox(presets, numpad), btns
} }
+17 -5
View File
@@ -11,7 +11,7 @@ import (
"fyne.io/fyne/v2/widget" "fyne.io/fyne/v2/widget"
) )
const appVersion = "V1.5.1" const appVersion = "V0.0.1"
const ( const (
ipPlaceholder = "例子:\n127.0.0.1 - 单IP\n192.168.0.0/24 - 掩码IP段\n0.0.0.0-255.255.255.255 - IP段\ndomain.com - 单域名" ipPlaceholder = "例子:\n127.0.0.1 - 单IP\n192.168.0.0/24 - 掩码IP段\n0.0.0.0-255.255.255.255 - IP段\ndomain.com - 单域名"
@@ -30,6 +30,7 @@ type scanForm struct {
scanBtn *widget.Button scanBtn *widget.Button
pingBtn *widget.Button pingBtn *widget.Button
keypadBtn []*widget.Button
scanning bool scanning bool
} }
@@ -62,13 +63,17 @@ func (f *scanForm) build() fyne.CanvasObject {
ipSection := container.NewVBox( ipSection := container.NewVBox(
widget.NewLabel("IP"), widget.NewLabel("IP"),
f.ipList, f.ipList,
newIPKeypad(f.ipList),
) )
ipKeys, ipBtns := newIPKeypad(f.ipList)
ipSection.Add(ipKeys)
portSection := container.NewVBox( portSection := container.NewVBox(
widget.NewLabel("端口"), widget.NewLabel("端口"),
f.portList, f.portList,
newPortKeypad(f.portList),
) )
portKeys, portBtns := newPortKeypad(f.portList)
portSection.Add(portKeys)
f.keypadBtn = append(f.keypadBtn, ipBtns...)
f.keypadBtn = append(f.keypadBtn, portBtns...)
topRow := container.New(layout.NewGridLayoutWithColumns(2), ipSection, portSection) topRow := container.New(layout.NewGridLayoutWithColumns(2), ipSection, portSection)
controlRow := f.buildControlRow() controlRow := f.buildControlRow()
@@ -78,8 +83,8 @@ func (f *scanForm) build() fyne.CanvasObject {
widget.NewLabel(appVersion), widget.NewLabel(appVersion),
layout.NewSpacer(), layout.NewSpacer(),
widget.NewButton("Blog", func() { f.openURL("https://wnfed.com/") }), widget.NewButton("Blog", func() { f.openURL("https://wnfed.com/") }),
widget.NewButton("GitLab", func() { f.openURL("https://git.lmve.net/kevin/tcp_ip_scan") }), widget.NewButton("Gitea", func() { f.openURL("https://git.lmve.net/kevin/ip_scan_go") }),
widget.NewButton("GitHub", func() { f.openURL("https://github.com/wuwenfengmi1998/tcp_ip_scan") }), widget.NewButton("GitHub", func() { f.openURL("https://github.com/wuwenfengmi1998") }),
) )
return container.NewBorder(topArea, footer, nil, nil, f.output) return container.NewBorder(topArea, footer, nil, nil, f.output)
@@ -136,6 +141,13 @@ func (f *scanForm) togglePing() {
} }
func (f *scanForm) setInputsEnabled(enabled bool) { func (f *scanForm) setInputsEnabled(enabled bool) {
for _, b := range f.keypadBtn {
if enabled {
b.Enable()
} else {
b.Disable()
}
}
if enabled { if enabled {
f.ipList.Enable() f.ipList.Enable()
f.portList.Enable() f.portList.Enable()