Skip to content

Commit

Permalink
Saving more paremeters as preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
mgm8 committed Aug 23, 2024
1 parent f3b7e0d commit 6c51dbb
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 15 deletions.
76 changes: 62 additions & 14 deletions spacelab_transmitter/spacelabtransmitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@
_DEFAULT_CALLSIGN = 'PP5UF'
_DEFAULT_LOCATION = 'Florianópolis'
_DEFAULT_COUNTRY = 'Brazil'
_DEFAULT_DOPPLER_ADDRESS = '127.0.0.1'
_DEFAULT_DOPPLER_PORT = 7356
_DEFAULT_FREQUENCY = 437000000
_DEFAULT_SAMPLE_RATE = 1000000
_DEFAULT_GAIN_USRP = 40
_DEFAULT_GAIN_PLUTO = -30

_DIR_CONFIG_DEFAULTJSON = 'spacelab_transmitter.json'

Expand Down Expand Up @@ -152,7 +158,7 @@ def _build_widgets(self):
else:
self.window.set_icon_from_file(_ICON_FILE_LINUX_SYSTEM)
self.window.set_wmclass(self.window.get_title(), self.window.get_title())
self.window.connect("destroy", Gtk.main_quit)
self.window.connect("destroy", self.on_main_window_destroy)

# Entry_preferences_general_callsign builder
self.entry_preferences_general_callsign = self.builder.get_object("entry_preferences_general_callsign")
Expand Down Expand Up @@ -187,10 +193,6 @@ def _build_widgets(self):
# Switch button Doppler correction
self.switch_doppler = self.builder.get_object("switch_doppler")

# Logfile chooser button
self.logfile_chooser_button = self.builder.get_object("logfile_chooser_button")
self.logfile_chooser_button.set_filename(_DEFAULT_LOGFILE_PATH)

# SDR Parameters
self.liststore_sdr = self.builder.get_object("liststore_sdr_devices")
for sat in _SDR_MODELS:
Expand Down Expand Up @@ -229,6 +231,15 @@ def _build_widgets(self):
self.entry_preferences_general_location = self.builder.get_object("entry_preferences_general_location")
self.entry_preferences_general_country = self.builder.get_object("entry_preferences_general_country")

self.radiobutton_doppler_tle_file = self.builder.get_object("radiobutton_doppler_tle_file")
self.filechooser_doppler_tle_file = self.builder.get_object("filechooser_doppler_tle_file")
self.radiobutton_doppler_network = self.builder.get_object("radiobutton_doppler_network")
self.entry_doppler_address = self.builder.get_object("entry_doppler_address")
self.entry_doppler_port = self.builder.get_object("entry_doppler_port")

self.logfile_chooser_button = self.builder.get_object("logfile_chooser_button")
self.logfile_chooser_button.set_filename(_DEFAULT_LOGFILE_PATH)

# Ping Request
self.button_ping_request = self.builder.get_object("button_ping_request")
self.button_ping_request.connect("clicked", self.on_button_ping_request_command_clicked)
Expand Down Expand Up @@ -301,7 +312,8 @@ def run(self):
self.window.show_all()
Gtk.main()

def destroy(window, self):
def on_main_window_destroy(self, window):
self._save_preferences()
Gtk.main_quit()

def on_button_ping_request_command_clicked(self, button):
Expand Down Expand Up @@ -693,17 +705,41 @@ def _load_preferences(self):
config = json.loads(f.read())
f.close()

self.entry_preferences_general_callsign.set_text(config["callsign"])
self.entry_preferences_general_location.set_text(config["location"])
self.entry_preferences_general_country.set_text(config["country"])
self.logfile_chooser_button.set_filename(config["logfile_path"])
try:
self.entry_preferences_general_callsign.set_text(config["callsign"])
self.entry_preferences_general_location.set_text(config["location"])
self.entry_preferences_general_country.set_text(config["country"])
if config["doppler_from_network"]:
self.radiobutton_doppler_network.set_active(True)
else:
self.radiobutton_doppler_tle_file.set_active(True)
self.filechooser_doppler_tle_file.set_filename(config["tle_file"] if config["tle_file"] != None else "")
self.entry_doppler_address.set_text(config["doppler_address"])
self.entry_doppler_port.set_text(config["doppler_port"])
self.logfile_chooser_button.set_filename(config["logfile_path"])
self.combobox_sdr.set_active(config["sdr_dev"])
self.entry_carrier_frequency.set_text(config["sdr_freq"])
self.entry_sample_rate.set_text(config["sdr_sample_rate"])
except:
self._load_default_preferences()
self._save_preferences()

def _load_default_preferences(self):
self.entry_preferences_general_callsign.set_text(_DEFAULT_CALLSIGN)
self.entry_preferences_general_location.set_text(_DEFAULT_LOCATION)
self.entry_preferences_general_country.set_text(_DEFAULT_COUNTRY)

self.filechooser_doppler_tle_file.set_filename("")
self.radiobutton_doppler_network.set_active(True)
self.entry_doppler_address.set_text(_DEFAULT_DOPPLER_ADDRESS)
self.entry_doppler_port.set_text(str(_DEFAULT_DOPPLER_PORT))

self.logfile_chooser_button.set_filename(_DEFAULT_LOGFILE_PATH)


self.combobox_sdr.set_active(-1)
self.entry_carrier_frequency.set_text(str(_DEFAULT_FREQUENCY))
self.entry_sample_rate.set_text(str(_DEFAULT_SAMPLE_RATE))

def _save_preferences(self):
home = os.path.expanduser('~')
location = os.path.join(home, _DIR_CONFIG_LINUX)
Expand All @@ -713,9 +749,16 @@ def _save_preferences(self):

with open(location + '/' + _DIR_CONFIG_DEFAULTJSON, 'w', encoding='utf-8') as f:
json.dump({"callsign": self.entry_preferences_general_callsign.get_text(),
"location": self.entry_preferences_general_location.get_text(),
"country": self.entry_preferences_general_country.get_text(),
"logfile_path": self.logfile_chooser_button.get_filename()}, f, ensure_ascii=False, indent=4)
"location": self.entry_preferences_general_location.get_text(),
"country": self.entry_preferences_general_country.get_text(),
"doppler_from_network": self.radiobutton_doppler_network.get_active(),
"tle_file": self.filechooser_doppler_tle_file.get_filename(),
"doppler_address": self.entry_doppler_address.get_text(),
"doppler_port": self.entry_doppler_port.get_text(),
"logfile_path": self.logfile_chooser_button.get_filename(),
"sdr_dev": self.combobox_sdr.get_active(),
"sdr_freq": self.entry_carrier_frequency.get_text(),
"sdr_sample_rate": self.entry_sample_rate.get_text()}, f, ensure_ascii=False, indent=4)

def on_toolbutton_about_clicked(self, toolbutton):
response = self.aboutdialog.run()
Expand Down Expand Up @@ -770,8 +813,13 @@ def on_switch_button_clicked(self, false, button):
def on_combobox_sdr_changed(self, combobox):
if self.combobox_sdr.get_active() == 0: # USRP
self.spinbutton_tx_gain.set_range(0, 90)
self.spinbutton_tx_gain.set_value(_DEFAULT_GAIN_USRP)
elif self.combobox_sdr.get_active() == 1: # Pluto SDR
self.spinbutton_tx_gain.set_range(-90, 0)
self.spinbutton_tx_gain.set_value(_DEFAULT_GAIN_PLUTO)
else:
self.spinbutton_tx_gain.set_range(0, 90)
self.spinbutton_tx_gain.set_value(_DEFAULT_GAIN_USRP)

def _get_link_info(self):
sat_config_file = str()
Expand Down
2 changes: 1 addition & 1 deletion spacelab_transmitter/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
__copyright__ = "Copyright The SpaceLab-Transmitter Contributors"
__credits__ = ["Gabriel Mariano Marcelino, Vitória Beatriz Bianchin"]
__license__ = "GPLv3"
__version__ = "0.4.9"
__version__ = "0.4.10"
__maintainer__ = "Gabriel Mariano Marcelino - PU5GMA"
__email__ = "gabriel.mm8@gmail.com"
__status__ = "Development"

0 comments on commit 6c51dbb

Please sign in to comment.