def hamlib_attach(self, model): Hamlib.rig_set_debug(Hamlib.RIG_DEBUG_NONE) # RIG_DEBUG_TRACE self.hamlib = Hamlib.Rig(model) self.hamlib.set_conf("serial_speed", "9600") self.hamlib.set_conf("retry", "5") self.hamlib.open()
def __init__(self, args): super().__init__() self.timer = QTimer() self.timer.timeout.connect(self.poll) self.timer.start(500) Hamlib.rig_set_debug(Hamlib.RIG_DEBUG_NONE) self.connect()
def initRotator(my_rot): print("Initialising Rotator") Hamlib.rig_set_debug(Hamlib.RIG_DEBUG_NONE) # Init RIG_MODEL_DUMMY my_rot.set_conf("rot_pathname", ROTATOR_SERIAL_PORT) #my_rot.set_conf("speed", "600") my_rot.open() my_rot.set_position(0, 0)
def __init__(self, serial_device, serial_speed, rig_id) -> None: super().__init__() self.rig_id = rig_id self.serial_speed = serial_speed self.serial_device = serial_device self.rig = None if Hamlib: Hamlib.rig_set_debug(Hamlib.RIG_DEBUG_NONE) # Hamlib.rig_set_debug(Hamlib.RIG_DEBUG_TRACE) rig = Hamlib.Rig(120) rig.state.rigport.pathname = '/dev/ttyAMA0' rig.state.rigport.parm.serial.rate = 9600 rig.open() self.rig = rig
def hamlib_autofill(self, rig_model, rig_pathname): """ Set the various fields using data from the radio via Hamlib. :arg str rig_model: The model of the radio/rig. :arg str rig_pathname: The path to the rig (or rig control device). """ # Open a communication channel to the radio. 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() except: logging.error("Could not open a communication channel to the rig via Hamlib!") return # Frequency try: frequency = "%.6f" % (rig.get_freq()/1.0e6) # Converting to MHz here. # Convert to the desired unit, if necessary. if(self.frequency_unit != "MHz"): frequency = str(self.convert_frequency(frequency, from_unit="MHz", to_unit=self.frequency_unit)) self.sources["FREQ"].set_text(frequency) except: logging.error("Could not obtain the current frequency via Hamlib!") # Mode try: (mode, width) = rig.get_mode() mode = Hamlib.rig_strrmode(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)) except: logging.error("Could not obtain the current mode (e.g. FM, AM, CW) via Hamlib!") # Close communication channel. try: rig.close() except: logging.error("Could not close the communication channel to the rig via Hamlib!") return
def __init__(self, mcclog, conf): self.mcclog = mcclog self.rotortype = conf.rotortype self.rotorport = conf.rotorport self.rotorspeed = conf.rotorspeed # Disable all debug output from Hamlib Hamlib.rig_set_debug (Hamlib.RIG_DEBUG_NONE) # Validate rotor model if self.rotortype.lower() == "easycomm1": model = Hamlib.ROT_MODEL_EASYCOMM1 elif self.rotortype.lower() == "easycomm2": model = Hamlib.ROT_MODEL_EASYCOMM2 elif self.rotortype.lower() == "gs232": model = Hamlib.ROT_MODEL_GS232 elif self.rotortype.lower() == "gs232a": model = Hamlib.ROT_MODEL_GS232A elif self.rotortype.lower() == "gs232b": model = Hamlib.ROT_MODEL_GS232B else: raise Exception("Unknown rotor model: {0}".format(self.rotortype)) # Validate device file if not os.path.exists(self.rotorport): raise Exception("Device {0} does not exist".format(self.rotorport)) # Validate serial speed if not self.rotorspeed in [300, 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200]: raise Exception("Serial speed {0} bps is not supported".format(self.rotorspeed)) # Create rotor object self.rot = Hamlib.Rot(model) # Setup serial port self.rot.set_conf("rot_pathname", self.rotorport) self.rot.set_conf("serial_speed", str(self.rotorspeed)) # Open rotor # The Python bindings for Hamlib does not return anything # so we have no knowledge if this was actually successful... self.rot.open() self.mcclog.info("Rotor initiated to {0} on port {1}, speed={2}".format(self.rotortype, self.rotorport, self.rotorspeed))
def prepare_for_session(self, session_pipeline): """ Prepares the radio for use by a new session by loading the necessary services and setting up Hamlib. @note This method loads the active 'tracker' service from the session pipeline. The driver will use this service to load the doppler shift multiplier for the active target. If a 'tracker' service can not be loaded, no doppler correction will be applied. @note This method loads the active 'tnc_state' service from the session pipeline. The driver will use this service to make sure that it does not allow its uplink frequency to be changed if data is being transmitted. If this service can't be located, no such protection will be provided (possibly putting the radio into an undefined state). @param session_pipeline The Pipeline associated with the new session. @return Returns True once the radio is ready for use by the session. """ self._reset_driver_state() # Load the 'tracker' service self._session_pipeline = session_pipeline try: self._tracker_service = session_pipeline.load_service("tracker") self._tracker_service.register_position_receiver(self.process_new_doppler_correction) except pipeline.ServiceTypeNotFound as e: # A tracker service isn't available logging.error("The "+self.id+" driver could not load a 'tracker' service from the session's pipeline.") # Load the 'tnc_state' service try: self._tnc_state_service = session_pipeline.load_service("tnc_state") except pipeline.ServiceTypeNotFound as e: # A tnc_state service isn't available logging.error("The "+self.id+" driver could not load a 'tnc_state' service from the session's pipeline.") # Create a Hamlib rig for the radio Hamlib.rig_set_debug(Hamlib.RIG_DEBUG_NONE) self._command_handler.radio_rig = Hamlib.Rig(Hamlib.RIG_MODEL_IC910) self._command_handler.radio_rig.set_conf("rig_pathname",self.icom_device_path) self._command_handler.radio_rig.set_conf("retry","5") self._command_handler.radio_rig.open() return True
""" Module for monitoring the RF spectrum using the rig. """ import math import inspect from time import sleep import Hamlib from spectrum.common import check_device Hamlib.rig_set_debug(Hamlib.RIG_DEBUG_NONE) def get_capabilities(): """ Return a dictionary of rig capabilities. """ caps = {'models': [], 'rates': [], 'parities': [], 'modes': []} is_int = lambda n: isinstance(n, int) #FIXME WinRadio RIG_MODEL_G313 is causing problems on Linux machines - ignore for now for model in [n for x, n in inspect.getmembers(Hamlib, is_int) if x.startswith('RIG_MODEL_') and x != 'RIG_MODEL_G313']: rig = Hamlib.Rig(model) if rig.this is None: continue caps['models'].append({ 'model': model, 'manufacturer': rig.caps.mfg_name, 'name': rig.caps.model_name, 'version': rig.caps.version, 'status': Hamlib.rig_strstatus(rig.caps.status), 'modes': rig.state.mode_list })
def StartUp(): """Simple script to test the Hamlib.py module with Python3.""" print("%s: Python %s; %s\n" \ % (sys.argv[0], sys.version.split()[0], Hamlib.cvar.hamlib_version)) Hamlib.rig_set_debug(Hamlib.RIG_DEBUG_NONE) # Init RIG_MODEL_DUMMY my_rig = Hamlib.Rig(Hamlib.RIG_MODEL_DUMMY) my_rig.set_conf("rig_pathname", "/dev/Rig") my_rig.set_conf("retry", "5") my_rig.open () # 1073741944 is token value for "itu_region" # but using get_conf is much more convenient region = my_rig.get_conf(1073741944) rpath = my_rig.get_conf("rig_pathname") retry = my_rig.get_conf("retry") print("status(str):\t\t%s" % Hamlib.rigerror(my_rig.error_status)) print("get_conf:\t\tpath = %s, retry = %s, ITU region = %s" \ % (rpath, retry, region)) my_rig.set_freq(Hamlib.RIG_VFO_B, 5700000000) my_rig.set_vfo(Hamlib.RIG_VFO_B) print("freq:\t\t\t%s" % my_rig.get_freq()) my_rig.set_freq(Hamlib.RIG_VFO_A, 145550000) (mode, width) = my_rig.get_mode() print("mode:\t\t\t%s\nbandwidth:\t\t%s" % (Hamlib.rig_strrmode(mode), width)) my_rig.set_mode(Hamlib.RIG_MODE_CW) (mode, width) = my_rig.get_mode() print("mode:\t\t\t%s\nbandwidth:\t\t%s" % (Hamlib.rig_strrmode(mode), width)) print("ITU_region:\t\t%s" % my_rig.state.itu_region) print("Backend copyright:\t%s" % my_rig.caps.copyright) print("Model:\t\t\t%s" % my_rig.caps.model_name) print("Manufacturer:\t\t%s" % my_rig.caps.mfg_name) print("Backend version:\t%s" % my_rig.caps.version) print("Backend status:\t\t%s" % Hamlib.rig_strstatus(my_rig.caps.status)) print("Rig info:\t\t%s" % my_rig.get_info()) my_rig.set_level("VOX", 1) print("VOX level:\t\t%s" % my_rig.get_level_i("VOX")) my_rig.set_level(Hamlib.RIG_LEVEL_VOX, 5) print("VOX level:\t\t%s" % my_rig.get_level_i(Hamlib.RIG_LEVEL_VOX)) af = 12.34 print("Setting AF to %0.2f...." % (af)) my_rig.set_level("AF", af) print("status:\t\t\t%s - %s" % (my_rig.error_status, Hamlib.rigerror(my_rig.error_status))) print("AF level:\t\t%0.2f" % my_rig.get_level_f(Hamlib.RIG_LEVEL_AF)) print("strength:\t\t%s" % my_rig.get_level_i(Hamlib.RIG_LEVEL_STRENGTH)) print("status:\t\t\t%s" % my_rig.error_status) print("status(str):\t\t%s" % Hamlib.rigerror(my_rig.error_status)) chan = Hamlib.channel(Hamlib.RIG_VFO_B) my_rig.get_channel(chan) print("get_channel status:\t%s" % my_rig.error_status) print("VFO:\t\t\t%s, %s" % (Hamlib.rig_strvfo(chan.vfo), chan.freq)) print("Attenuators:\t\t%s" % my_rig.caps.attenuator) print("\nSending Morse, '73'") my_rig.send_morse(Hamlib.RIG_VFO_A, "73") my_rig.close() print("\nSome static functions:") err, lon1, lat1 = Hamlib.locator2longlat("IN98XC") err, lon2, lat2 = Hamlib.locator2longlat("DM33DX") err, loc1 = Hamlib.longlat2locator(lon1, lat1, 3) err, loc2 = Hamlib.longlat2locator(lon2, lat2, 3) print("Loc1:\t\tIN98XC -> %9.4f, %9.4f -> %s" % (lon1, lat1, loc1)) print("Loc2:\t\tDM33DX -> %9.4f, %9.4f -> %s" % (lon2, lat2, loc2)) err, dist, az = Hamlib.qrb(lon1, lat1, lon2, lat2) longpath = Hamlib.distance_long_path(dist) print("Distance:\t%.3f km, azimuth %.2f, long path:\t%.3f km" \ % (dist, az, longpath)) # dec2dms expects values from 180 to -180 # sw is 1 when deg is negative (west or south) as 0 cannot be signed err, deg1, mins1, sec1, sw1 = Hamlib.dec2dms(lon1) err, deg2, mins2, sec2, sw2 = Hamlib.dec2dms(lat1) lon3 = Hamlib.dms2dec(deg1, mins1, sec1, sw1) lat3 = Hamlib.dms2dec(deg2, mins2, sec2, sw2) print('Longitude:\t%4.4f, %4d° %2d\' %2d" %1s\trecoded: %9.4f' \ % (lon1, deg1, mins1, sec1, ('W' if sw1 else 'E'), lon3)) print('Latitude:\t%4.4f, %4d° %2d\' %2d" %1s\trecoded: %9.4f' \ % (lat1, deg2, mins2, sec2, ('S' if sw2 else 'N'), lat3))
def hamlib_autofill(self, rig_model, rig_pathname): """ Set the various fields using data from the radio via Hamlib. :arg str rig_model: The model of the radio/rig. :arg str rig_pathname: The path to the rig (or rig control device). """ # Open a communication channel to the radio. 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() except: logging.error( "Could not open a communication channel to the rig via Hamlib!" ) return # Frequency try: frequency = "%.6f" % (rig.get_freq() / 1.0e6 ) # Converting to MHz here. # Convert to the desired unit, if necessary. if (self.frequency_unit != "MHz"): frequency = str( self.convert_frequency(frequency, from_unit="MHz", to_unit=self.frequency_unit)) self.sources["FREQ"].set_text(frequency) except: logging.error("Could not obtain the current frequency via Hamlib!") # Mode try: (mode, width) = rig.get_mode() mode = Hamlib.rig_strrmode(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(self.modes.keys()).index(mode)) self.sources["SUBMODE"].set_active( self.modes[mode].index(submode)) else: self.sources["MODE"].set_active( sorted(self.modes.keys()).index(mode)) except: logging.error( "Could not obtain the current mode (e.g. FM, AM, CW) via Hamlib!" ) # Close communication channel. try: rig.close() except: logging.error( "Could not close the communication channel to the rig via Hamlib!" ) return
def __init__(self, parent, log, index=None): """ Set up the layout of the record dialog. If a record index is specified in the 'index' argument, then the dialog turns into 'edit record mode' and fills the data sources with the existing data in the log. If the 'index' argument is None, then the dialog starts off with nothing in the data sources (e.g. the Gtk.Entry boxes). """ logging.debug("Setting up the record dialog...") if(index is not None): title = "Edit Record %d" % index else: title = "Add Record" Gtk.Dialog.__init__(self, title=title, parent=parent, flags=Gtk.DialogFlags.DESTROY_WITH_PARENT, buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OK, Gtk.ResponseType.OK)) # Check if a configuration file is present, since we might need it to set up the rest of the dialog. config = ConfigParser.ConfigParser() have_config = (config.read(expanduser('~/.pyqso.ini')) != []) ## QSO DATA FRAME qso_frame = Gtk.Frame() qso_frame.set_label("QSO Information") self.vbox.add(qso_frame) hbox_inner = Gtk.HBox(spacing=2) vbox_inner = Gtk.VBox(spacing=2) hbox_inner.pack_start(vbox_inner, True, True, 2) # Create label:entry pairs and store them in a dictionary self.sources = {} # CALL hbox_temp = Gtk.HBox(spacing=0) label = Gtk.Label(AVAILABLE_FIELD_NAMES_FRIENDLY["CALL"], halign=Gtk.Align.START) label.set_width_chars(15) label.set_alignment(0, 0.5) hbox_temp.pack_start(label, False, False, 2) self.sources["CALL"] = Gtk.Entry() self.sources["CALL"].set_width_chars(15) hbox_temp.pack_start(self.sources["CALL"], False, False, 2) icon = Gtk.Image() icon.set_from_stock(Gtk.STOCK_INFO, Gtk.IconSize.MENU) button = Gtk.Button() button.add(icon) button.connect("clicked", self.lookup_callback) # Looks up the callsign on qrz.com for callsign and station information. button.set_tooltip_text("Lookup on qrz.com") hbox_temp.pack_start(button, True, True, 2) vbox_inner.pack_start(hbox_temp, False, False, 2) # DATE hbox_temp = Gtk.HBox(spacing=0) label = Gtk.Label(AVAILABLE_FIELD_NAMES_FRIENDLY["QSO_DATE"], halign=Gtk.Align.START) label.set_width_chars(15) label.set_alignment(0, 0.5) hbox_temp.pack_start(label, False, False, 2) self.sources["QSO_DATE"] = Gtk.Entry() self.sources["QSO_DATE"].set_width_chars(15) hbox_temp.pack_start(self.sources["QSO_DATE"], False, False, 2) icon = Gtk.Image() icon.set_from_stock(Gtk.STOCK_GO_BACK, Gtk.IconSize.MENU) button = Gtk.Button() button.add(icon) button.connect("clicked", self.calendar_callback) button.set_tooltip_text("Select date from calendar") hbox_temp.pack_start(button, True, True, 2) vbox_inner.pack_start(hbox_temp, False, False, 2) # TIME hbox_temp = Gtk.HBox(spacing=0) label = Gtk.Label(AVAILABLE_FIELD_NAMES_FRIENDLY["TIME_ON"], halign=Gtk.Align.START) label.set_alignment(0, 0.5) label.set_width_chars(15) hbox_temp.pack_start(label, False, False, 2) self.sources["TIME_ON"] = Gtk.Entry() self.sources["TIME_ON"].set_width_chars(15) hbox_temp.pack_start(self.sources["TIME_ON"], False, False, 2) icon = Gtk.Image() icon.set_from_stock(Gtk.STOCK_MEDIA_PLAY, Gtk.IconSize.MENU) button = Gtk.Button() button.add(icon) button.connect("clicked", self.set_current_datetime_callback) button.set_tooltip_text("Use the current time and date") hbox_temp.pack_start(button, True, True, 2) vbox_inner.pack_start(hbox_temp, False, False, 2) # FREQ hbox_temp = Gtk.HBox(spacing=0) (section, option) = ("view", "default_freq_unit") if(have_config and config.has_option(section, option)): frequency_unit = config.get(section, option) else: frequency_unit = "MHz" label = Gtk.Label(AVAILABLE_FIELD_NAMES_FRIENDLY["FREQ"] + " (" + frequency_unit + ")", halign=Gtk.Align.START) label.set_alignment(0, 0.5) label.set_width_chars(15) hbox_temp.pack_start(label, False, False, 2) self.sources["FREQ"] = Gtk.Entry() self.sources["FREQ"].set_width_chars(15) hbox_temp.pack_start(self.sources["FREQ"], False, False, 2) vbox_inner.pack_start(hbox_temp, False, False, 2) # BAND hbox_temp = Gtk.HBox(spacing=0) label = Gtk.Label(AVAILABLE_FIELD_NAMES_FRIENDLY["BAND"], halign=Gtk.Align.START) label.set_alignment(0, 0.5) label.set_width_chars(15) hbox_temp.pack_start(label, False, False, 2) self.sources["BAND"] = Gtk.ComboBoxText() for band in BANDS: self.sources["BAND"].append_text(band) self.sources["BAND"].set_active(0) # Set an empty string as the default option. hbox_temp.pack_start(self.sources["BAND"], False, False, 2) vbox_inner.pack_start(hbox_temp, False, False, 2) # MODE hbox_temp = Gtk.HBox(spacing=0) label = Gtk.Label(AVAILABLE_FIELD_NAMES_FRIENDLY["MODE"]) label.set_alignment(0, 0.5) label.set_width_chars(15) hbox_temp.pack_start(label, False, False, 2) self.sources["MODE"] = Gtk.ComboBoxText() for mode in MODES: self.sources["MODE"].append_text(mode) self.sources["MODE"].set_active(0) # Set an empty string as the default option. hbox_temp.pack_start(self.sources["MODE"], False, False, 2) vbox_inner.pack_start(hbox_temp, False, False, 2) # POWER hbox_temp = Gtk.HBox(spacing=0) label = Gtk.Label(AVAILABLE_FIELD_NAMES_FRIENDLY["TX_PWR"], halign=Gtk.Align.START) label.set_alignment(0, 0.5) label.set_width_chars(15) hbox_temp.pack_start(label, False, False, 2) self.sources["TX_PWR"] = Gtk.Entry() self.sources["TX_PWR"].set_width_chars(15) hbox_temp.pack_start(self.sources["TX_PWR"], False, False, 2) vbox_inner.pack_start(hbox_temp, False, False, 2) vbox_inner = Gtk.VBox(spacing=2) hbox_inner.pack_start(Gtk.SeparatorToolItem(), False, False, 0) hbox_inner.pack_start(vbox_inner, True, True, 2) # RST_SENT hbox_temp = Gtk.HBox(spacing=0) label = Gtk.Label(AVAILABLE_FIELD_NAMES_FRIENDLY["RST_SENT"]) label.set_alignment(0, 0.5) label.set_width_chars(15) hbox_temp.pack_start(label, False, False, 2) self.sources["RST_SENT"] = Gtk.Entry() self.sources["RST_SENT"].set_width_chars(15) hbox_temp.pack_start(self.sources["RST_SENT"], False, False, 2) vbox_inner.pack_start(hbox_temp, False, False, 2) # RST_RCVD hbox_temp = Gtk.HBox(spacing=0) label = Gtk.Label(AVAILABLE_FIELD_NAMES_FRIENDLY["RST_RCVD"]) label.set_alignment(0, 0.5) label.set_width_chars(15) hbox_temp.pack_start(label, False, False, 2) self.sources["RST_RCVD"] = Gtk.Entry() self.sources["RST_RCVD"].set_width_chars(15) hbox_temp.pack_start(self.sources["RST_RCVD"], False, False, 2) vbox_inner.pack_start(hbox_temp, False, False, 2) # QSL_SENT hbox_temp = Gtk.HBox(spacing=0) label = Gtk.Label(AVAILABLE_FIELD_NAMES_FRIENDLY["QSL_SENT"]) label.set_alignment(0, 0.5) label.set_width_chars(15) hbox_temp.pack_start(label, False, False, 2) qsl_options = ["", "Y", "N", "R", "I"] self.sources["QSL_SENT"] = Gtk.ComboBoxText() for option in qsl_options: self.sources["QSL_SENT"].append_text(option) self.sources["QSL_SENT"].set_active(0) # Set an empty string as the default option. hbox_temp.pack_start(self.sources["QSL_SENT"], False, False, 2) vbox_inner.pack_start(hbox_temp, False, False, 2) # QSL_RCVD hbox_temp = Gtk.HBox(spacing=0) label = Gtk.Label(AVAILABLE_FIELD_NAMES_FRIENDLY["QSL_RCVD"]) label.set_alignment(0, 0.5) label.set_width_chars(15) hbox_temp.pack_start(label, False, False, 2) qsl_options = ["", "Y", "N", "R", "I"] self.sources["QSL_RCVD"] = Gtk.ComboBoxText() for option in qsl_options: self.sources["QSL_RCVD"].append_text(option) self.sources["QSL_RCVD"].set_active(0) # Set an empty string as the default option. hbox_temp.pack_start(self.sources["QSL_RCVD"], False, False, 2) vbox_inner.pack_start(hbox_temp, False, False, 2) # NOTES hbox_temp = Gtk.HBox(spacing=0) label = Gtk.Label(AVAILABLE_FIELD_NAMES_FRIENDLY["NOTES"]) label.set_alignment(0, 0.5) label.set_width_chars(15) hbox_temp.pack_start(label, False, False, 2) self.textview = Gtk.TextView() sw = Gtk.ScrolledWindow() sw.set_shadow_type(Gtk.ShadowType.ETCHED_IN) sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) sw.add(self.textview) self.sources["NOTES"] = self.textview.get_buffer() hbox_temp.pack_start(sw, True, True, 2) vbox_inner.pack_start(hbox_temp, True, True, 2) qso_frame.add(hbox_inner) ## STATION INFORMATION FRAME station_frame = Gtk.Frame() station_frame.set_label("Station Information") self.vbox.add(station_frame) hbox_inner = Gtk.HBox(spacing=2) vbox_inner = Gtk.VBox(spacing=2) hbox_inner.pack_start(vbox_inner, True, True, 2) # NAME hbox_temp = Gtk.HBox(spacing=0) label = Gtk.Label(AVAILABLE_FIELD_NAMES_FRIENDLY["NAME"], halign=Gtk.Align.START) label.set_width_chars(15) label.set_alignment(0, 0.5) hbox_temp.pack_start(label, False, False, 2) self.sources["NAME"] = Gtk.Entry() self.sources["NAME"].set_width_chars(15) hbox_temp.pack_start(self.sources["NAME"], False, False, 2) vbox_inner.pack_start(hbox_temp, False, False, 2) # ADDRESS hbox_temp = Gtk.HBox(spacing=0) label = Gtk.Label(AVAILABLE_FIELD_NAMES_FRIENDLY["ADDRESS"], halign=Gtk.Align.START) label.set_width_chars(15) label.set_alignment(0, 0.5) hbox_temp.pack_start(label, False, False, 2) self.sources["ADDRESS"] = Gtk.Entry() self.sources["ADDRESS"].set_width_chars(15) hbox_temp.pack_start(self.sources["ADDRESS"], False, False, 2) vbox_inner.pack_start(hbox_temp, False, False, 2) # STATE hbox_temp = Gtk.HBox(spacing=0) label = Gtk.Label(AVAILABLE_FIELD_NAMES_FRIENDLY["STATE"], halign=Gtk.Align.START) label.set_width_chars(15) label.set_alignment(0, 0.5) hbox_temp.pack_start(label, False, False, 2) self.sources["STATE"] = Gtk.Entry() self.sources["STATE"].set_width_chars(15) hbox_temp.pack_start(self.sources["STATE"], False, False, 2) vbox_inner.pack_start(hbox_temp, False, False, 2) # COUNTRY hbox_temp = Gtk.HBox(spacing=0) label = Gtk.Label(AVAILABLE_FIELD_NAMES_FRIENDLY["COUNTRY"], halign=Gtk.Align.START) label.set_width_chars(15) label.set_alignment(0, 0.5) hbox_temp.pack_start(label, False, False, 2) self.sources["COUNTRY"] = Gtk.Entry() self.sources["COUNTRY"].set_width_chars(15) hbox_temp.pack_start(self.sources["COUNTRY"], False, False, 2) vbox_inner.pack_start(hbox_temp, False, False, 2) vbox_inner = Gtk.VBox(spacing=2) hbox_inner.pack_start(Gtk.SeparatorToolItem(), False, False, 0) hbox_inner.pack_start(vbox_inner, True, True, 2) # DXCC hbox_temp = Gtk.HBox(spacing=0) label = Gtk.Label(AVAILABLE_FIELD_NAMES_FRIENDLY["DXCC"], halign=Gtk.Align.START) label.set_width_chars(15) label.set_alignment(0, 0.5) hbox_temp.pack_start(label, False, False, 2) self.sources["DXCC"] = Gtk.Entry() self.sources["DXCC"].set_width_chars(15) hbox_temp.pack_start(self.sources["DXCC"], False, False, 2) vbox_inner.pack_start(hbox_temp, False, False, 2) # CQZ hbox_temp = Gtk.HBox(spacing=0) label = Gtk.Label(AVAILABLE_FIELD_NAMES_FRIENDLY["CQZ"], halign=Gtk.Align.START) label.set_width_chars(15) label.set_alignment(0, 0.5) hbox_temp.pack_start(label, False, False, 2) self.sources["CQZ"] = Gtk.Entry() self.sources["CQZ"].set_width_chars(15) hbox_temp.pack_start(self.sources["CQZ"], False, False, 2) vbox_inner.pack_start(hbox_temp, False, False, 2) # ITUZ hbox_temp = Gtk.HBox(spacing=0) label = Gtk.Label(AVAILABLE_FIELD_NAMES_FRIENDLY["ITUZ"], halign=Gtk.Align.START) label.set_width_chars(15) label.set_alignment(0, 0.5) hbox_temp.pack_start(label, False, False, 2) self.sources["ITUZ"] = Gtk.Entry() self.sources["ITUZ"].set_width_chars(15) hbox_temp.pack_start(self.sources["ITUZ"], False, False, 2) vbox_inner.pack_start(hbox_temp, False, False, 2) # IOTA hbox_temp = Gtk.HBox(spacing=0) label = Gtk.Label(AVAILABLE_FIELD_NAMES_FRIENDLY["IOTA"], halign=Gtk.Align.START) label.set_width_chars(15) label.set_alignment(0, 0.5) hbox_temp.pack_start(label, False, False, 2) self.sources["IOTA"] = Gtk.Entry() self.sources["IOTA"].set_width_chars(15) hbox_temp.pack_start(self.sources["IOTA"], False, False, 2) vbox_inner.pack_start(hbox_temp, False, False, 2) station_frame.add(hbox_inner) # Populate various fields, if possible. if(index is not None): # The record already exists, so display its current data in the input boxes. record = log.get_record_by_index(index) field_names = AVAILABLE_FIELD_NAMES_ORDERED for i in range(0, len(field_names)): data = record[field_names[i].lower()] if(data is None): data = "" if(field_names[i] == "BAND"): self.sources[field_names[i]].set_active(BANDS.index(data)) elif(field_names[i] == "MODE"): self.sources[field_names[i]].set_active(MODES.index(data)) elif(field_names[i] == "QSL_SENT" or field_names[i] == "QSL_RCVD"): self.sources[field_names[i]].set_active(qsl_options.index(data)) elif(field_names[i] == "NOTES"): # Remember to put the new line escape characters back in when displaying the data in a Gtk.TextView text = data.replace("\\n", "\n") self.sources[field_names[i]].set_text(text) else: self.sources[field_names[i]].set_text(data) else: # Automatically fill in the current date and time self.set_current_datetime_callback() 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 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() frequency = "%.6f" % (rig.get_freq()/1.0e6) # Converting to MHz here self.sources["FREQ"].set_text(frequency) rig.close() except: logging.error("Could not obtain Frequency data via Hamlib!") # Do we want PyQSO to autocomplete the Band field based on the Frequency field? (section, option) = ("records", "autocomplete_band") if(have_config and config.get(section, option)): autocomplete_band = (config.get(section, option) == "True") if(autocomplete_band): self.sources["FREQ"].connect("changed", self._autocomplete_band) else: # If no configuration file exists, autocomplete the Band field by default. self.sources["FREQ"].connect("changed", self._autocomplete_band) self.show_all() logging.debug("Record dialog ready!") return
def StartUp(): print "Python", sys.version[:5], "test,", Hamlib.cvar.hamlib_version, "\n" #Hamlib.rig_set_debug (Hamlib.RIG_DEBUG_TRACE) Hamlib.rig_set_debug(Hamlib.RIG_DEBUG_NONE) # Init RIG_MODEL_DUMMY my_rig = Hamlib.Rig(Hamlib.RIG_MODEL_DUMMY) my_rig.set_conf("rig_pathname", "/dev/Rig") my_rig.set_conf("retry", "5") my_rig.open() # 1073741944 is token value for "itu_region" # but using get_conf is much more convenient region = my_rig.get_conf(1073741944) rpath = my_rig.get_conf("rig_pathname") retry = my_rig.get_conf("retry") print "status(str):\t\t", Hamlib.rigerror(my_rig.error_status) print "get_conf:\t\tpath = %s, retry = %s, ITU region = %s" \ % (rpath, retry, region) my_rig.set_freq(Hamlib.RIG_VFO_B, 5700000000) my_rig.set_vfo(Hamlib.RIG_VFO_B) print "freq:\t\t\t", my_rig.get_freq() my_rig.set_freq(Hamlib.RIG_VFO_A, 145550000) #my_rig.set_vfo ("VFOA") (mode, width) = my_rig.get_mode() print "mode:\t\t\t", Hamlib.rig_strrmode(mode), "\nbandwidth:\t\t", width my_rig.set_mode(Hamlib.RIG_MODE_CW) (mode, width) = my_rig.get_mode() print "mode:\t\t\t", Hamlib.rig_strrmode(mode), "\nbandwidth:\t\t", width print "ITU_region:\t\t", my_rig.state.itu_region print "Backend copyright:\t", my_rig.caps.copyright print "Model:\t\t\t", my_rig.caps.model_name print "Manufacturer:\t\t", my_rig.caps.mfg_name print "Backend version:\t", my_rig.caps.version print "Backend license:\t", my_rig.caps.copyright print "Rig info:\t\t", my_rig.get_info() my_rig.set_level("VOX", 1) print "VOX level:\t\t", my_rig.get_level_i("VOX") my_rig.set_level(Hamlib.RIG_LEVEL_VOX, 5) print "VOX level:\t\t", my_rig.get_level_i(Hamlib.RIG_LEVEL_VOX) print "strength:\t\t", my_rig.get_level_i(Hamlib.RIG_LEVEL_STRENGTH) print "status:\t\t\t", my_rig.error_status print "status(str):\t\t", Hamlib.rigerror(my_rig.error_status) chan = Hamlib.channel(Hamlib.RIG_VFO_B) my_rig.get_channel(chan) print "get_channel status:\t", my_rig.error_status print "VFO:\t\t\t", Hamlib.rig_strvfo(chan.vfo), ", ", chan.freq print "Attenuators:\t\t", my_rig.caps.attenuator print "\nSending Morse, '73'" my_rig.send_morse(Hamlib.RIG_VFO_A, "73") my_rig.close() print "\nSome static functions:" err, lon1, lat1 = Hamlib.locator2longlat("IN98XC") err, lon2, lat2 = Hamlib.locator2longlat("DM33DX") err, loc1 = Hamlib.longlat2locator(lon1, lat1, 3) err, loc2 = Hamlib.longlat2locator(lon2, lat2, 3) print "Loc1:\t\tIN98XC -> %9.4f, %9.4f -> %s" % (lon1, lat1, loc1) print "Loc2:\t\tDM33DX -> %9.4f, %9.4f -> %s" % (lon2, lat2, loc2) err, dist, az = Hamlib.qrb(lon1, lat1, lon2, lat2) longpath = Hamlib.distance_long_path(dist) print "Distance:\t%.3f km, azimuth %.2f, long path:\t%.3f km" \ % (dist, az, longpath) # dec2dms expects values from 180 to -180 # sw is 1 when deg is negative (west or south) as 0 cannot be signed err, deg1, mins1, sec1, sw1 = Hamlib.dec2dms(lon1) err, deg2, mins2, sec2, sw2 = Hamlib.dec2dms(lat1) lon3 = Hamlib.dms2dec(deg1, mins1, sec1, sw1) lat3 = Hamlib.dms2dec(deg2, mins2, sec2, sw2) print 'Longitude:\t%4.4f, %4d° %2d\' %2d" %1s\trecoded: %9.4f' \ % (lon1, deg1, mins1, sec1, ('W' if sw1 else 'E'), lon3) print 'Latitude:\t%4.4f, %4d° %2d\' %2d" %1s\trecoded: %9.4f' \ % (lat1, deg2, mins2, sec2, ('S' if sw2 else 'N'), lat3)
wf_pixel_size = (w_spectra / opt.size, h_wf / WF_LINES) # min, max dB for wf palette v_min, v_max = opt.v_min, opt.v_max # lower/higher end (dB) nsteps = 50 # number of distinct colors if opt.waterfall: # Instantiate the waterfall and palette data mywf = wf.Wf(opt, v_min, v_max, nsteps, wf_pixel_size) if (opt.control == "si570") and opt.hamlib: print "Warning: Hamlib requested with si570. Si570 wins! No Hamlib." if opt.hamlib and (opt.control != "si570"): import Hamlib # start up Hamlib rig connection Hamlib.rig_set_debug(Hamlib.RIG_DEBUG_NONE) rig = Hamlib.Rig(opt.hamlib_rigtype) rig.set_conf("rig_pathname", opt.hamlib_device) rig.set_conf("retry", "5") rig.open() # Create thread for Hamlib freq. checking. # Helps to even out the loop timing, maybe. hl_thread = threading.Thread(target=updatefreq, args=(opt.hamlib_interval, rig)) hl_thread.daemon = True hl_thread.start() print "Hamlib thread started." else: print "Hamlib not requested."
def main(): Hamlib.rig_set_debug(Hamlib.RIG_DEBUG_NONE) #Hamlib.rig_set_debug(Hamlib.RIG_DEBUG_TRACE) set_title("scan.py: initializing") print("Beginning scan sequence: %s" % GQRX_IP_ADDRESS) # Connect to the GQRX server with NetRig(GQRX_IP_ADDRESS) as gqrx: # Print header text print("Freq MHz\tdBm\tAcq\tSecs\tChannel") window_title_stale = True # Run through the master frequency list and apply the weightings freqs = [] for weight, freq, threshold, chname in FREQLIST: while weight > 0: freqs.append((freq, threshold, chname)) weight -= 1 # Main loop. while True: # Shuffle the frequency list: mixes things up a bit, and also # helps minimize VCO retunes, oddly enough random.shuffle(freqs) for freq, threshold, chname in freqs: # Clear the status line sys.stdout.write('\r' + ' ' * 80) # Change our frequency then wait a bit gqrx.rig.set_freq(freq) time.sleep(0.1) # Reset the window title to a generic thing if we're # not locked onto a signal. if window_title_stale: set_title("<scan>") window_title_stale = False # Start off taking one pass through the dwell loop rx_active = False acq_time = time.time() dwell_until = acq_time + 0.01 while rx_active or (dwell_until > time.time()): # Calculate the RSSI and update our status variables my_rssi = gqrx.rssi() rx_duration = time.time() - acq_time rx_active = my_rssi > threshold # Tell the user what's up if rx_active and not window_title_stale: set_title(chname) window_title_stale = True sys.stdout.write( '\r%4.4f\t%4d\t%s\t%3.1f\t%s' % ((freq / 1e6), my_rssi, '*' if rx_active else 'x', rx_duration, chname)) sys.stdout.flush() # If we're actively receiving and have been for more than # a second, latch onto this channel for a little bit in # case someone responds. if rx_active and rx_duration > 1: dwell_until = time.time() + 1.5 # Sleep for a moment to avoid churning. time.sleep(0.01)
def StartUp (): print "Python",sys.version[:5],"test,", Hamlib.cvar.hamlib_version #Hamlib.rig_set_debug (Hamlib.RIG_DEBUG_TRACE) Hamlib.rig_set_debug (Hamlib.RIG_DEBUG_NONE) # Init RIG_MODEL_DUMMY my_rig = Hamlib.Rig (Hamlib.RIG_MODEL_DUMMY) my_rig.set_conf ("rig_pathname","/dev/Rig") my_rig.set_conf ("retry","5") my_rig.open () # 1073741944 is token value for "itu_region" # but using get_conf is much more convenient region = my_rig.get_conf(1073741944) rpath = my_rig.get_conf("rig_pathname") retry = my_rig.get_conf("retry") print "status(str):",Hamlib.rigerror(my_rig.error_status) print "get_conf: path=",rpath,", retry =",retry,", ITU region=",region my_rig.set_freq (5700000000,Hamlib.RIG_VFO_B) print "freq:",my_rig.get_freq() my_rig.set_freq (145550000) my_rig.set_vfo (Hamlib.RIG_VFO_B) #my_rig.set_vfo ("VFOA") (mode, width) = my_rig.get_mode() print "mode:",Hamlib.rig_strrmode(mode),", bandwidth:",width my_rig.set_mode(Hamlib.RIG_MODE_CW) (mode, width) = my_rig.get_mode() print "mode:",Hamlib.rig_strrmode(mode),", bandwidth:",width print "ITU_region: ",my_rig.state.itu_region print "Backend copyright: ",my_rig.caps.copyright print "Model:",my_rig.caps.model_name print "Manufacturer:",my_rig.caps.mfg_name print "Backend version:",my_rig.caps.version print "Backend license:",my_rig.caps.copyright print "Rig info:", my_rig.get_info() my_rig.set_level ("VOX", 1) print "VOX level: ",my_rig.get_level_i("VOX") my_rig.set_level (Hamlib.RIG_LEVEL_VOX, 5) print "VOX level: ", my_rig.get_level_i(Hamlib.RIG_LEVEL_VOX) print "strength: ", my_rig.get_level_i(Hamlib.RIG_LEVEL_STRENGTH) print "status: ",my_rig.error_status print "status(str):",Hamlib.rigerror(my_rig.error_status) chan = Hamlib.channel(Hamlib.RIG_VFO_B) my_rig.get_channel(chan) print "get_channel status: ",my_rig.error_status print "VFO: ",Hamlib.rig_strvfo(chan.vfo),", ",chan.freq my_rig.close () print "\nSome static functions:" err, long1, lat1 = Hamlib.locator2longlat("IN98EC") err, long2, lat2 = Hamlib.locator2longlat("DM33DX") err, loc1 = Hamlib.longlat2locator(long1, lat1, 3) err, loc2 = Hamlib.longlat2locator(long2, lat2, 3) print "Loc1: IN98EC -> ",loc1 print "Loc2: DM33DX -> ",loc2 # TODO: qrb should normalize? err, dist, az = Hamlib.qrb(long1, lat1, long2, lat2) if az > 180: az -= 360 longpath = Hamlib.distance_long_path(dist) print "Distance: ",dist," km, long path: ",longpath err, deg, min, sec, sw = Hamlib.dec2dms(az) az2 = Hamlib.dms2dec(deg, min, sec, sw) if sw: deg = -deg print "Bearing: ",az,", ",deg,"° ",min,"' ",sec,", recoded: ",az2
def init(self, f): Hamlib.rig_set_debug_file(f) Hamlib.rig_set_debug(getattr(Hamlib, 'RIG_DEBUG_{0}'.format(RIG_LOG_LEVEL))) super(Worker, self).init(f)
def StartUp (): print "Python", sys.version[:5], "test,", Hamlib.cvar.hamlib_version, "\n" #Hamlib.rig_set_debug (Hamlib.RIG_DEBUG_TRACE) Hamlib.rig_set_debug (Hamlib.RIG_DEBUG_NONE) # Init RIG_MODEL_DUMMY my_rig = Hamlib.Rig (Hamlib.RIG_MODEL_DUMMY) my_rig.set_conf ("rig_pathname","/dev/Rig") my_rig.set_conf ("retry","5") my_rig.open () # 1073741944 is token value for "itu_region" # but using get_conf is much more convenient region = my_rig.get_conf(1073741944) rpath = my_rig.get_conf("rig_pathname") retry = my_rig.get_conf("retry") print "status(str):\t\t",Hamlib.rigerror(my_rig.error_status) print "get_conf:\t\tpath = %s, retry = %s, ITU region = %s" \ % (rpath, retry, region) my_rig.set_freq (Hamlib.RIG_VFO_B, 5700000000) my_rig.set_vfo (Hamlib.RIG_VFO_B) print "freq:\t\t\t",my_rig.get_freq() my_rig.set_freq (Hamlib.RIG_VFO_A, 145550000) #my_rig.set_vfo ("VFOA") (mode, width) = my_rig.get_mode() print "mode:\t\t\t",Hamlib.rig_strrmode(mode),"\nbandwidth:\t\t",width my_rig.set_mode(Hamlib.RIG_MODE_CW) (mode, width) = my_rig.get_mode() print "mode:\t\t\t",Hamlib.rig_strrmode(mode),"\nbandwidth:\t\t",width print "ITU_region:\t\t",my_rig.state.itu_region print "Backend copyright:\t",my_rig.caps.copyright print "Model:\t\t\t",my_rig.caps.model_name print "Manufacturer:\t\t",my_rig.caps.mfg_name print "Backend version:\t",my_rig.caps.version print "Backend license:\t",my_rig.caps.copyright print "Rig info:\t\t", my_rig.get_info() my_rig.set_level ("VOX", 1) print "VOX level:\t\t",my_rig.get_level_i("VOX") my_rig.set_level (Hamlib.RIG_LEVEL_VOX, 5) print "VOX level:\t\t", my_rig.get_level_i(Hamlib.RIG_LEVEL_VOX) print "strength:\t\t", my_rig.get_level_i(Hamlib.RIG_LEVEL_STRENGTH) print "status:\t\t\t",my_rig.error_status print "status(str):\t\t",Hamlib.rigerror(my_rig.error_status) chan = Hamlib.channel(Hamlib.RIG_VFO_B) my_rig.get_channel(chan) print "get_channel status:\t",my_rig.error_status print "VFO:\t\t\t",Hamlib.rig_strvfo(chan.vfo),", ",chan.freq print "\nSending Morse, '73'" my_rig.send_morse(Hamlib.RIG_VFO_A, "73") my_rig.close () print "\nSome static functions:" err, lon1, lat1 = Hamlib.locator2longlat("IN98XC") err, lon2, lat2 = Hamlib.locator2longlat("DM33DX") err, loc1 = Hamlib.longlat2locator(lon1, lat1, 3) err, loc2 = Hamlib.longlat2locator(lon2, lat2, 3) print "Loc1:\t\tIN98XC -> %9.4f, %9.4f -> %s" % (lon1, lat1, loc1) print "Loc2:\t\tDM33DX -> %9.4f, %9.4f -> %s" % (lon2, lat2, loc2) err, dist, az = Hamlib.qrb(lon1, lat1, lon2, lat2) longpath = Hamlib.distance_long_path(dist) print "Distance:\t%.3f km, azimuth %.2f, long path:\t%.3f km" \ % (dist, az, longpath) # dec2dms expects values from 180 to -180 # sw is 1 when deg is negative (west or south) as 0 cannot be signed err, deg1, mins1, sec1, sw1 = Hamlib.dec2dms(lon1) err, deg2, mins2, sec2, sw2 = Hamlib.dec2dms(lat1) lon3 = Hamlib.dms2dec(deg1, mins1, sec1, sw1) lat3 = Hamlib.dms2dec(deg2, mins2, sec2, sw2) print 'Longitude:\t%4.4f, %4d° %2d\' %2d" %1s\trecoded: %9.4f' \ % (lon1, deg1, mins1, sec1, ('W' if sw1 else 'E'), lon3) print 'Latitude:\t%4.4f, %4d° %2d\' %2d" %1s\trecoded: %9.4f' \ % (lat1, deg2, mins2, sec2, ('S' if sw2 else 'N'), lat3)
def get(self): Hamlib.rig_set_debug (Hamlib.RIG_DEBUG_NONE) # Init RIG_MODEL_DUMMY my_rig = Hamlib.Rig (Hamlib.RIG_MODEL_DUMMY) my_rig.set_conf ("rig_pathname","/dev/Rig") my_rig.set_conf ("retry","5") my_rig.open () # 1073741944 is token value for "itu_region" # but using get_conf is much more convenient region = my_rig.get_conf(1073741944) rpath = my_rig.get_conf("rig_pathname") retry = my_rig.get_conf("retry") print "status(str):\t\t",Hamlib.rigerror(my_rig.error_status) print "get_conf:\t\tpath = %s, retry = %s, ITU region = %s" \ % (rpath, retry, region) my_rig.set_freq (Hamlib.RIG_VFO_B, 5700000000) my_rig.set_vfo (Hamlib.RIG_VFO_B) test = "freq:\t\t\t",my_rig.get_freq() my_rig.set_freq (Hamlib.RIG_VFO_A, 145550000) #my_rig.set_vfo ("VFOA") (mode, width) = my_rig.get_mode() print "mode:\t\t\t",Hamlib.rig_strrmode(mode),"\nbandwidth:\t\t",width my_rig.set_mode(Hamlib.RIG_MODE_CW) (mode, width) = my_rig.get_mode() print "mode:\t\t\t",Hamlib.rig_strrmode(mode),"\nbandwidth:\t\t",width print "ITU_region:\t\t",my_rig.state.itu_region print "Backend copyright:\t",my_rig.caps.copyright print "Model:\t\t\t",my_rig.caps.model_name print "Manufacturer:\t\t",my_rig.caps.mfg_name print "Backend version:\t",my_rig.caps.version print "Backend license:\t",my_rig.caps.copyright print "Rig info:\t\t", my_rig.get_info() my_rig.set_level ("VOX", 1) print "VOX level:\t\t",my_rig.get_level_i("VOX") my_rig.set_level (Hamlib.RIG_LEVEL_VOX, 5) print "VOX level:\t\t", my_rig.get_level_i(Hamlib.RIG_LEVEL_VOX) print "strength:\t\t", my_rig.get_level_i(Hamlib.RIG_LEVEL_STRENGTH) print "status:\t\t\t",my_rig.error_status print "status(str):\t\t",Hamlib.rigerror(my_rig.error_status) chan = Hamlib.channel(Hamlib.RIG_VFO_B) my_rig.get_channel(chan) print "get_channel status:\t",my_rig.error_status print "VFO:\t\t\t",Hamlib.rig_strvfo(chan.vfo),", ",chan.freq print "\nSending Morse, '73'" my_rig.send_morse(Hamlib.RIG_VFO_A, "73") my_rig.close () return
def __init__(self, parent, log, index=None): """ Set up the layout of the record dialog, populate the various fields with the QSO details (if the record already exists), and show the dialog to the user. :arg parent: The parent Gtk window. :arg log: The log to which the record belongs (or will belong). :arg int index: If specified, then the dialog turns into 'edit record mode' and fills the data sources (e.g. the Gtk.Entry boxes) with the existing data in the log. If not specified (i.e. index is None), then the dialog starts off with nothing in the data sources. """ logging.debug("Setting up the record dialog...") if (index is not None): title = "Edit Record %d" % index else: title = "Add Record" Gtk.Dialog.__init__(self, title=title, parent=parent, flags=Gtk.DialogFlags.DESTROY_WITH_PARENT, buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OK, Gtk.ResponseType.OK)) # Check if a configuration file is present, since we might need it to set up the rest of the dialog. config = configparser.ConfigParser() have_config = (config.read( expanduser('~/.config/pyqso/preferences.ini')) != []) # QSO DATA FRAME qso_frame = Gtk.Frame() qso_frame.set_label("QSO Information") self.vbox.add(qso_frame) hbox_inner = Gtk.HBox(spacing=2) vbox_inner = Gtk.VBox(spacing=2) hbox_inner.pack_start(vbox_inner, True, True, 2) # Create label:entry pairs and store them in a dictionary self.sources = {} # CALL hbox_temp = Gtk.HBox(spacing=0) label = Gtk.Label(AVAILABLE_FIELD_NAMES_FRIENDLY["CALL"], halign=Gtk.Align.START) label.set_width_chars(15) label.set_alignment(0, 0.5) hbox_temp.pack_start(label, False, False, 2) self.sources["CALL"] = Gtk.Entry() self.sources["CALL"].set_width_chars(15) hbox_temp.pack_start(self.sources["CALL"], False, False, 2) icon = Gtk.Image() icon.set_from_stock(Gtk.STOCK_INFO, Gtk.IconSize.MENU) button = Gtk.Button() button.add(icon) button.connect( "clicked", self.lookup_callback ) # Looks up the callsign using an online database, for callsign and station information. button.set_tooltip_text("Callsign lookup") hbox_temp.pack_start(button, True, True, 2) vbox_inner.pack_start(hbox_temp, False, False, 2) # DATE hbox_temp = Gtk.HBox(spacing=0) label = Gtk.Label(AVAILABLE_FIELD_NAMES_FRIENDLY["QSO_DATE"], halign=Gtk.Align.START) label.set_width_chars(15) label.set_alignment(0, 0.5) hbox_temp.pack_start(label, False, False, 2) self.sources["QSO_DATE"] = Gtk.Entry() self.sources["QSO_DATE"].set_width_chars(15) hbox_temp.pack_start(self.sources["QSO_DATE"], False, False, 2) icon = Gtk.Image() icon.set_from_stock(Gtk.STOCK_GO_BACK, Gtk.IconSize.MENU) button = Gtk.Button() button.add(icon) button.connect("clicked", self.calendar_callback) button.set_tooltip_text("Select date from calendar") hbox_temp.pack_start(button, True, True, 2) vbox_inner.pack_start(hbox_temp, False, False, 2) # TIME hbox_temp = Gtk.HBox(spacing=0) label = Gtk.Label(AVAILABLE_FIELD_NAMES_FRIENDLY["TIME_ON"], halign=Gtk.Align.START) label.set_alignment(0, 0.5) label.set_width_chars(15) hbox_temp.pack_start(label, False, False, 2) self.sources["TIME_ON"] = Gtk.Entry() self.sources["TIME_ON"].set_width_chars(15) hbox_temp.pack_start(self.sources["TIME_ON"], False, False, 2) icon = Gtk.Image() icon.set_from_stock(Gtk.STOCK_MEDIA_PLAY, Gtk.IconSize.MENU) button = Gtk.Button() button.add(icon) button.connect("clicked", self.set_current_datetime_callback) button.set_tooltip_text("Use the current time and date") hbox_temp.pack_start(button, True, True, 2) vbox_inner.pack_start(hbox_temp, False, False, 2) # FREQ hbox_temp = Gtk.HBox(spacing=0) label = Gtk.Label(AVAILABLE_FIELD_NAMES_FRIENDLY["FREQ"], halign=Gtk.Align.START) label.set_alignment(0, 0.5) label.set_width_chars(15) hbox_temp.pack_start(label, False, False, 2) self.sources["FREQ"] = Gtk.Entry() self.sources["FREQ"].set_width_chars(15) hbox_temp.pack_start(self.sources["FREQ"], False, False, 2) vbox_inner.pack_start(hbox_temp, False, False, 2) # BAND hbox_temp = Gtk.HBox(spacing=0) label = Gtk.Label(AVAILABLE_FIELD_NAMES_FRIENDLY["BAND"], halign=Gtk.Align.START) label.set_alignment(0, 0.5) label.set_width_chars(15) hbox_temp.pack_start(label, False, False, 2) self.sources["BAND"] = Gtk.ComboBoxText() for band in BANDS: self.sources["BAND"].append_text(band) self.sources["BAND"].set_active( 0) # Set an empty string as the default option. hbox_temp.pack_start(self.sources["BAND"], False, False, 2) vbox_inner.pack_start(hbox_temp, False, False, 2) # MODE hbox_temp = Gtk.HBox(spacing=0) label = Gtk.Label(AVAILABLE_FIELD_NAMES_FRIENDLY["MODE"]) label.set_alignment(0, 0.5) label.set_width_chars(15) hbox_temp.pack_start(label, False, False, 2) self.sources["MODE"] = Gtk.ComboBoxText() for mode in sorted(MODES.keys()): self.sources["MODE"].append_text(mode) self.sources["MODE"].set_active( 0) # Set an empty string as the default option. self.sources["MODE"].connect("changed", self._on_mode_changed) hbox_temp.pack_start(self.sources["MODE"], False, False, 2) vbox_inner.pack_start(hbox_temp, False, False, 2) # SUBMODE hbox_temp = Gtk.HBox(spacing=0) label = Gtk.Label(AVAILABLE_FIELD_NAMES_FRIENDLY["SUBMODE"]) label.set_alignment(0, 0.5) label.set_width_chars(15) hbox_temp.pack_start(label, False, False, 2) self.sources["SUBMODE"] = Gtk.ComboBoxText() self.sources["SUBMODE"].append_text("") self.sources["SUBMODE"].set_active( 0 ) # Set an empty string initially. As soon as the user selects a particular MODE, the available SUBMODES will appear. hbox_temp.pack_start(self.sources["SUBMODE"], False, False, 2) vbox_inner.pack_start(hbox_temp, False, False, 2) # POWER hbox_temp = Gtk.HBox(spacing=0) label = Gtk.Label(AVAILABLE_FIELD_NAMES_FRIENDLY["TX_PWR"], halign=Gtk.Align.START) label.set_alignment(0, 0.5) label.set_width_chars(15) hbox_temp.pack_start(label, False, False, 2) self.sources["TX_PWR"] = Gtk.Entry() self.sources["TX_PWR"].set_width_chars(15) hbox_temp.pack_start(self.sources["TX_PWR"], False, False, 2) vbox_inner.pack_start(hbox_temp, False, False, 2) vbox_inner = Gtk.VBox(spacing=2) hbox_inner.pack_start(Gtk.SeparatorToolItem(), False, False, 0) hbox_inner.pack_start(vbox_inner, True, True, 2) # RST_SENT hbox_temp = Gtk.HBox(spacing=0) label = Gtk.Label(AVAILABLE_FIELD_NAMES_FRIENDLY["RST_SENT"]) label.set_alignment(0, 0.5) label.set_width_chars(15) hbox_temp.pack_start(label, False, False, 2) self.sources["RST_SENT"] = Gtk.Entry() self.sources["RST_SENT"].set_width_chars(15) hbox_temp.pack_start(self.sources["RST_SENT"], False, False, 2) vbox_inner.pack_start(hbox_temp, False, False, 2) # RST_RCVD hbox_temp = Gtk.HBox(spacing=0) label = Gtk.Label(AVAILABLE_FIELD_NAMES_FRIENDLY["RST_RCVD"]) label.set_alignment(0, 0.5) label.set_width_chars(15) hbox_temp.pack_start(label, False, False, 2) self.sources["RST_RCVD"] = Gtk.Entry() self.sources["RST_RCVD"].set_width_chars(15) hbox_temp.pack_start(self.sources["RST_RCVD"], False, False, 2) vbox_inner.pack_start(hbox_temp, False, False, 2) # QSL_SENT hbox_temp = Gtk.HBox(spacing=0) label = Gtk.Label(AVAILABLE_FIELD_NAMES_FRIENDLY["QSL_SENT"]) label.set_alignment(0, 0.5) label.set_width_chars(15) hbox_temp.pack_start(label, False, False, 2) qsl_options = ["", "Y", "N", "R", "I"] self.sources["QSL_SENT"] = Gtk.ComboBoxText() for option in qsl_options: self.sources["QSL_SENT"].append_text(option) self.sources["QSL_SENT"].set_active( 0) # Set an empty string as the default option. hbox_temp.pack_start(self.sources["QSL_SENT"], False, False, 2) vbox_inner.pack_start(hbox_temp, False, False, 2) # QSL_RCVD hbox_temp = Gtk.HBox(spacing=0) label = Gtk.Label(AVAILABLE_FIELD_NAMES_FRIENDLY["QSL_RCVD"]) label.set_alignment(0, 0.5) label.set_width_chars(15) hbox_temp.pack_start(label, False, False, 2) qsl_options = ["", "Y", "N", "R", "I"] self.sources["QSL_RCVD"] = Gtk.ComboBoxText() for option in qsl_options: self.sources["QSL_RCVD"].append_text(option) self.sources["QSL_RCVD"].set_active( 0) # Set an empty string as the default option. hbox_temp.pack_start(self.sources["QSL_RCVD"], False, False, 2) vbox_inner.pack_start(hbox_temp, False, False, 2) # NOTES hbox_temp = Gtk.HBox(spacing=0) label = Gtk.Label(AVAILABLE_FIELD_NAMES_FRIENDLY["NOTES"]) label.set_alignment(0, 0.5) label.set_width_chars(15) hbox_temp.pack_start(label, False, False, 2) self.textview = Gtk.TextView() sw = Gtk.ScrolledWindow() sw.set_shadow_type(Gtk.ShadowType.ETCHED_IN) sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) sw.add(self.textview) self.sources["NOTES"] = self.textview.get_buffer() hbox_temp.pack_start(sw, True, True, 2) vbox_inner.pack_start(hbox_temp, True, True, 2) qso_frame.add(hbox_inner) # STATION INFORMATION FRAME station_frame = Gtk.Frame() station_frame.set_label("Station Information") self.vbox.add(station_frame) hbox_inner = Gtk.HBox(spacing=2) vbox_inner = Gtk.VBox(spacing=2) hbox_inner.pack_start(vbox_inner, True, True, 2) # NAME hbox_temp = Gtk.HBox(spacing=0) label = Gtk.Label(AVAILABLE_FIELD_NAMES_FRIENDLY["NAME"], halign=Gtk.Align.START) label.set_width_chars(15) label.set_alignment(0, 0.5) hbox_temp.pack_start(label, False, False, 2) self.sources["NAME"] = Gtk.Entry() self.sources["NAME"].set_width_chars(15) hbox_temp.pack_start(self.sources["NAME"], False, False, 2) vbox_inner.pack_start(hbox_temp, False, False, 2) # ADDRESS hbox_temp = Gtk.HBox(spacing=0) label = Gtk.Label(AVAILABLE_FIELD_NAMES_FRIENDLY["ADDRESS"], halign=Gtk.Align.START) label.set_width_chars(15) label.set_alignment(0, 0.5) hbox_temp.pack_start(label, False, False, 2) self.sources["ADDRESS"] = Gtk.Entry() self.sources["ADDRESS"].set_width_chars(15) hbox_temp.pack_start(self.sources["ADDRESS"], False, False, 2) vbox_inner.pack_start(hbox_temp, False, False, 2) # STATE hbox_temp = Gtk.HBox(spacing=0) label = Gtk.Label(AVAILABLE_FIELD_NAMES_FRIENDLY["STATE"], halign=Gtk.Align.START) label.set_width_chars(15) label.set_alignment(0, 0.5) hbox_temp.pack_start(label, False, False, 2) self.sources["STATE"] = Gtk.Entry() self.sources["STATE"].set_width_chars(15) hbox_temp.pack_start(self.sources["STATE"], False, False, 2) vbox_inner.pack_start(hbox_temp, False, False, 2) # COUNTRY hbox_temp = Gtk.HBox(spacing=0) label = Gtk.Label(AVAILABLE_FIELD_NAMES_FRIENDLY["COUNTRY"], halign=Gtk.Align.START) label.set_width_chars(15) label.set_alignment(0, 0.5) hbox_temp.pack_start(label, False, False, 2) self.sources["COUNTRY"] = Gtk.Entry() self.sources["COUNTRY"].set_width_chars(15) hbox_temp.pack_start(self.sources["COUNTRY"], False, False, 2) vbox_inner.pack_start(hbox_temp, False, False, 2) vbox_inner = Gtk.VBox(spacing=2) hbox_inner.pack_start(Gtk.SeparatorToolItem(), False, False, 0) hbox_inner.pack_start(vbox_inner, True, True, 2) # DXCC hbox_temp = Gtk.HBox(spacing=0) label = Gtk.Label(AVAILABLE_FIELD_NAMES_FRIENDLY["DXCC"], halign=Gtk.Align.START) label.set_width_chars(15) label.set_alignment(0, 0.5) hbox_temp.pack_start(label, False, False, 2) self.sources["DXCC"] = Gtk.Entry() self.sources["DXCC"].set_width_chars(15) hbox_temp.pack_start(self.sources["DXCC"], False, False, 2) vbox_inner.pack_start(hbox_temp, False, False, 2) # CQZ hbox_temp = Gtk.HBox(spacing=0) label = Gtk.Label(AVAILABLE_FIELD_NAMES_FRIENDLY["CQZ"], halign=Gtk.Align.START) label.set_width_chars(15) label.set_alignment(0, 0.5) hbox_temp.pack_start(label, False, False, 2) self.sources["CQZ"] = Gtk.Entry() self.sources["CQZ"].set_width_chars(15) hbox_temp.pack_start(self.sources["CQZ"], False, False, 2) vbox_inner.pack_start(hbox_temp, False, False, 2) # ITUZ hbox_temp = Gtk.HBox(spacing=0) label = Gtk.Label(AVAILABLE_FIELD_NAMES_FRIENDLY["ITUZ"], halign=Gtk.Align.START) label.set_width_chars(15) label.set_alignment(0, 0.5) hbox_temp.pack_start(label, False, False, 2) self.sources["ITUZ"] = Gtk.Entry() self.sources["ITUZ"].set_width_chars(15) hbox_temp.pack_start(self.sources["ITUZ"], False, False, 2) vbox_inner.pack_start(hbox_temp, False, False, 2) # IOTA hbox_temp = Gtk.HBox(spacing=0) label = Gtk.Label(AVAILABLE_FIELD_NAMES_FRIENDLY["IOTA"], halign=Gtk.Align.START) label.set_width_chars(15) label.set_alignment(0, 0.5) hbox_temp.pack_start(label, False, False, 2) self.sources["IOTA"] = Gtk.Entry() self.sources["IOTA"].set_width_chars(15) hbox_temp.pack_start(self.sources["IOTA"], False, False, 2) vbox_inner.pack_start(hbox_temp, False, False, 2) station_frame.add(hbox_inner) # Populate various fields, if possible. if (index is not None): # The record already exists, so display its current data in the input boxes. record = log.get_record_by_index(index) field_names = AVAILABLE_FIELD_NAMES_ORDERED for i in range(0, len(field_names)): data = record[field_names[i].lower()] if (data is None): data = "" if (field_names[i] == "BAND"): self.sources[field_names[i]].set_active(BANDS.index(data)) elif (field_names[i] == "MODE"): self.sources[field_names[i]].set_active( sorted(MODES.keys()).index(data)) submode_data = record["submode"] if (submode_data is None): submode_data = "" self.sources["SUBMODE"].set_active( MODES[data].index(submode_data)) elif (field_names[i] == "SUBMODE"): continue elif (field_names[i] == "QSL_SENT" or field_names[i] == "QSL_RCVD"): self.sources[field_names[i]].set_active( qsl_options.index(data)) elif (field_names[i] == "NOTES"): # Remember to put the new line escape characters back in when displaying the data in a Gtk.TextView text = data.replace("\\n", "\n") self.sources[field_names[i]].set_text(text) else: self.sources[field_names[i]].set_text(data) else: # Automatically fill in the current date and time self.set_current_datetime_callback() # Set up default field values # Mode (section, option) = ("records", "default_mode") if (have_config and config.has_option(section, option)): mode = config.get(section, option) else: mode = "" self.sources["MODE"].set_active(sorted(MODES.keys()).index(mode)) # Submode (section, option) = ("records", "default_submode") if (have_config and config.has_option(section, option)): submode = config.get(section, option) else: submode = "" self.sources["SUBMODE"].set_active(MODES[mode].index(submode)) # Power (section, option) = ("records", "default_power") if (have_config and config.has_option(section, option)): power = config.get(section, option) else: power = "" self.sources["TX_PWR"].set_text(power) 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 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() frequency = "%.6f" % (rig.get_freq() / 1.0e6 ) # Converting to MHz here self.sources["FREQ"].set_text(frequency) rig.close() except: logging.error( "Could not obtain Frequency data via Hamlib!") # Do we want PyQSO to autocomplete the Band field based on the Frequency field? (section, option) = ("records", "autocomplete_band") if (have_config and config.get(section, option)): autocomplete_band = (config.get(section, option) == "True") if (autocomplete_band): self.sources["FREQ"].connect("changed", self._autocomplete_band) else: # If no configuration file exists, autocomplete the Band field by default. self.sources["FREQ"].connect("changed", self._autocomplete_band) self.show_all() logging.debug("Record dialog ready!") return