Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow selecting region when restoring default bands list #728

Merged
merged 2 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 62 additions & 6 deletions src/NanoVNASaver/Settings/Bands.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from PyQt6 import QtCore, QtGui
from PyQt6.QtCore import QModelIndex, Qt

_DEFAULT_BANDS = (
_DEFAULT_REGION_1_BANDS = (
"2200 m;135700;137800",
"630 m;472000;479000",
"160 m;1800000;2000000",
Expand All @@ -39,13 +39,62 @@
"6 m;50000000;52000000",
"4 m;69887500;70512500",
"2 m;144000000;146000000",
"70 cm;432000000;438000000",
"70 cm;430000000;440000000",
"23 cm;1240000000;1300000000",
"13 cm;2320000000;2450000000",
"13 cm;2300000000;2450000000",
"5 cm;5650000000;5850000000",
)

_DEFAULT_REGION_2_BANDS = (
"2200 m;135700;137800",
"630 m;472000;479000",
"160 m;1800000;2000000",
"80 m;3500000;4000000",
"60 m;5250000;5450000",
"40 m;7000000;7300000",
"30 m;10100000;10150000",
"20 m;14000000;14350000",
"17 m;18068000;18168000",
"15 m;21000000;21450000",
"12 m;24890000;24990000",
"10 m;28000000;29700000",
"6 m;50000000;54000000",
"4 m;69887500;70512500",
"2 m;144000000;148000000",
"1.25 m;222000000;225000000",
"70 cm;420000000;450000000",
"33 cm;902000000;928000000",
"23 cm;1240000000;1300000000",
"13 cm;2300000000;2450000000",
"9 cm;3300000000;3500000000",
"5 cm;5650000000;5925000000",
)

_DEFAULT_REGION_3_BANDS = (
"2200 m;135700;137800",
"630 m;472000;479000",
"160 m;1800000;2000000",
"80 m;3500000;3900000",
"60 m;5250000;5450000",
"40 m;7000000;7200000",
"30 m;10100000;10150000",
"20 m;14000000;14350000",
"17 m;18068000;18168000",
"15 m;21000000;21450000",
"12 m;24890000;24990000",
"10 m;28000000;29700000",
"6 m;50000000;54000000",
"4 m;69887500;70512500",
"2 m;144000000;148000000",
"70 cm;430000000;440000000",
"23 cm;1240000000;1300000000",
"13 cm;2300000000;2450000000",
"9 cm;3300000000;3500000000",
"5 cm;5650000000;5850000000",
)



_HEADER_DATA = ("Band", "Start (Hz)", "End (Hz)")

logger = logging.getLogger(__name__)
Expand All @@ -68,7 +117,7 @@ def __init__(self):
self.enabled = self.settings.value("ShowBands", False, bool)
self.bands = [
band.split(";")
for band in self.settings.value("bands", _DEFAULT_BANDS)
for band in self.settings.value("bands", _DEFAULT_REGION_1_BANDS)
]

def saveSettings(self):
Expand All @@ -78,8 +127,15 @@ def saveSettings(self):
)
self.settings.sync()

def resetBands(self):
self.bands = [band.split(";") for band in _DEFAULT_BANDS]
def resetBands(self, regionIndex=1):
defaultBands = _DEFAULT_REGION_1_BANDS
#if(regionIndex == 1): #implicit default
# defaultBands = _DEFAULT_REGION_1_BANDS
if(regionIndex == 2):
defaultBands = _DEFAULT_REGION_2_BANDS
if(regionIndex == 3):
defaultBands = _DEFAULT_REGION_3_BANDS
self.bands = [band.split(";") for band in defaultBands]
self.layoutChanged.emit()
self.saveSettings()

Expand Down
26 changes: 19 additions & 7 deletions src/NanoVNASaver/Windows/Bands.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def __init__(self, app: QtWidgets.QWidget):

btn_add_row = QtWidgets.QPushButton("Add row")
btn_delete_row = QtWidgets.QPushButton("Delete row")
btn_reset_bands = QtWidgets.QPushButton("Reset bands")
btn_reset_bands = QtWidgets.QPushButton("Reset bands/Select region")
btn_layout = QtWidgets.QHBoxLayout()
btn_layout.addWidget(btn_add_row)
btn_layout.addWidget(btn_delete_row)
Expand All @@ -62,12 +62,24 @@ def deleteRows(self):
self.app.bands.removeRow(row.row())

def resetBands(self):
confirm = QtWidgets.QMessageBox(
confirmBox = QtWidgets.QMessageBox(
QtWidgets.QMessageBox.Icon.Warning,
"Confirm reset",
"Are you sure you want to reset the bands to default?",
QtWidgets.QMessageBox.StandardButton.Yes
| QtWidgets.QMessageBox.StandardButton.Cancel,
).exec()
if confirm == QtWidgets.QMessageBox.StandardButton.Yes:
self.app.bands.resetBands()
QtWidgets.QMessageBox.StandardButton.Cancel,
)
region_1_defaults_button = QtWidgets.QPushButton("Reset to Region 1 defaults", confirmBox)
region_2_defaults_button = QtWidgets.QPushButton("Reset to Region 2 defaults", confirmBox)
region_3_defaults_button = QtWidgets.QPushButton("Reset to Region 3 defaults", confirmBox)
confirmBox.addButton(region_1_defaults_button, QtWidgets.QMessageBox.ButtonRole.AcceptRole)
confirmBox.addButton(region_2_defaults_button, QtWidgets.QMessageBox.ButtonRole.AcceptRole)
confirmBox.addButton(region_3_defaults_button, QtWidgets.QMessageBox.ButtonRole.AcceptRole)
confirm = confirmBox.exec()

clicked_button = confirmBox.clickedButton()
if clicked_button == region_1_defaults_button:
self.app.bands.resetBands(1)
elif clicked_button == region_2_defaults_button:
self.app.bands.resetBands(2)
elif clicked_button == region_3_defaults_button:
self.app.bands.resetBands(3)
Loading