Esempio n. 1
0
    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()
Esempio n. 2
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
Esempio n. 3
0
    def __init__(self, app, conf):
        BaseHardware.__init__(self, app, conf)
        self.model = 25018  # Funcube Pro+
        self.vfo = None
        self.lna = None
        self.mixer = None
        self.ifgain = None
        self.receiver = Hamlib.Rig(self.model)
        self.receiver.open()
        self.vfo = int(self.receiver.get_freq())
        if (self.vfo == 0):
            print('+++ Could not find FuncubePro+ !\nExiting')
            exit()

        self.mixer = self.receiver.get_level_i(Hamlib.RIG_LEVEL_ATT,
                                               Hamlib.RIG_VFO_CURR)
        self.lna = self.receiver.get_level_i(Hamlib.RIG_LEVEL_PREAMP,
                                             Hamlib.RIG_VFO_CURR)
        self.ifgain = (int)(self.receiver.get_level_f(
            Hamlib.RIG_LEVEL_RF, Hamlib.RIG_VFO_CURR) * 100)
Esempio n. 4
0
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))
Esempio n. 5
0
    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
Esempio n. 6
0
 def __init__(self, app, conf):
     BaseHardware.__init__(self, app, conf)
     self.model=25019			#Could be a paramter later, to handel different models
     self.vfo = None
     self.receiver = Hamlib.Rig(self.model)
     self.receiver.state.rigport.pathname='/dev/ttyUSB0' #Could be a parameter later
Esempio n. 7
0
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)
Esempio n. 8
0
File: iq.py Progetto: n7ihq/TPPSDR
# 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."

# Create thread for cpu load monitor
Esempio n. 9
0
    def __init__(self, addr):
        self.rig = Hamlib.Rig(Hamlib.RIG_MODEL_NETRIGCTL)
        self.rig.set_conf("rig_pathname", addr)
        self.rig.open()

        self.rig.rig.state.has_get_level = Hamlib.RIG_LEVEL_STRENGTH
Esempio n. 10
0
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
Esempio n. 11
0
import Hamlib
import time, subprocess, os, signal

Hamlib.rig_set_debug(Hamlib.RIG_DEBUG_NONE)

tuned_freq = -1
sdr_process = -1

# Init RIG_MODEL_DUMMY
rig = Hamlib.Rig(Hamlib.RIG_MODEL_NETRIGCTL)
rig.set_conf("rig_pathname", "127.0.0.1:4532")
rig.set_conf("retry", "5")

rig.open()

os.environ["CSDR_PRINT_BUFSIZES"] = "1"
os.environ["CSDR_DYNAMIC_BUFSIZE_ON"] = "1"

# config stuff
tuner_offset = 30000
sample_rate = 250000
gain = 40
audio_rate = 48000
tbw = 0.15
bandwidth = 3000
buffer_size = 4096


def sdr_command(freq):
    freq = int(freq)
    center = freq + tuner_offset
Esempio n. 12
0
    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
Esempio n. 13
0
    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
Esempio n. 14
0
 def setupRig(self, rigCode):
     self.rig = Hamlib.Rig(rigCode)
     self.rig.set_conf("rig_pathname", "/dev/ttyUSB0")
     self.rig.set_conf("retry", "5")
     self.rig.open()
     self.rigFreq = self.rig.get_freq()
Esempio n. 15
0
 def connect(self):
     self.rig = Hamlib.Rig(Hamlib.RIG_MODEL_NETRIGCTL)
     self.rig.open()
     self.error_count = 0  # poll() will reconnect if there was an error