From df27c359ac434a79972d1dda97ff0c052b71ae4d Mon Sep 17 00:00:00 2001 From: "Christian T. Jacobs" Date: Tue, 7 Feb 2017 15:31:16 +0000 Subject: [PATCH] Also auto-fill the Mode field using Hamlib, if desired. Addresses issue #49. --- pyqso/preferences_dialog.py | 2 +- pyqso/record_dialog.py | 26 +++++++++++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/pyqso/preferences_dialog.py b/pyqso/preferences_dialog.py index aa432ba..8a908c1 100644 --- a/pyqso/preferences_dialog.py +++ b/pyqso/preferences_dialog.py @@ -268,7 +268,7 @@ class HamlibPage(Gtk.VBox): vbox_inner = Gtk.VBox(spacing=2) - self.sources["AUTOFILL"] = Gtk.CheckButton("Auto-fill Frequency field") + self.sources["AUTOFILL"] = Gtk.CheckButton("Auto-fill Frequency and Mode fields") (section, option) = ("hamlib", "autofill") if(have_config and config.has_option(section, option)): self.sources["AUTOFILL"].set_active(config.get(section, option) == "True") diff --git a/pyqso/record_dialog.py b/pyqso/record_dialog.py index 2391369..012746f 100644 --- a/pyqso/record_dialog.py +++ b/pyqso/record_dialog.py @@ -425,14 +425,14 @@ class RecordDialog(Gtk.Dialog): power = "" self.sources["TX_PWR"].set_text(power) + # If the Hamlib module is present, then use it to fill in various fields if desired. if(have_hamlib): - # If the Hamlib module is present, then use it to fill in the Frequency field if desired. if(have_config and config.has_option("hamlib", "autofill") and config.has_option("hamlib", "rig_model") and config.has_option("hamlib", "rig_pathname")): autofill = (config.get("hamlib", "autofill") == "True") rig_model = config.get("hamlib", "rig_model") rig_pathname = config.get("hamlib", "rig_pathname") if(autofill): - # Use Hamlib (if available) to get the frequency + # Frequency try: Hamlib.rig_set_debug(Hamlib.RIG_DEBUG_NONE) rig = Hamlib.Rig(Hamlib.__dict__[rig_model]) # Look up the model's numerical index in Hamlib's symbol dictionary @@ -442,7 +442,27 @@ class RecordDialog(Gtk.Dialog): self.sources["FREQ"].set_text(frequency) rig.close() except: - logging.error("Could not obtain Frequency data via Hamlib!") + logging.error("Could not obtain the current frequency via Hamlib!") + + # Mode + try: + Hamlib.rig_set_debug(Hamlib.RIG_DEBUG_NONE) + rig = Hamlib.Rig(Hamlib.__dict__[rig_model]) # Look up the model's numerical index in Hamlib's symbol dictionary + rig.set_conf("rig_pathname", rig_pathname) + rig.open() + (mode, width) = rig.get_mode() + mode = mode.upper() + # Handle USB and LSB as special cases. + if(mode == "USB" or mode == "LSB"): + submode = mode + mode = "SSB" + self.sources["MODE"].set_active(sorted(MODES.keys()).index(mode)) + self.sources["SUBMODE"].set_active(MODES[mode].index(submode)) + else: + self.sources["MODE"].set_active(sorted(MODES.keys()).index(mode)) + rig.close() + except: + logging.error("Could not obtain the current mode (e.g. FM, AM, CW) via Hamlib!") # Do we want PyQSO to autocomplete the Band field based on the Frequency field? (section, option) = ("records", "autocomplete_band")