From b0025966775973c2e26825d25cb444df523a93b4 Mon Sep 17 00:00:00 2001 From: f4exb Date: Sat, 6 Jan 2018 05:51:14 +0100 Subject: [PATCH] Commands: corrected edit command dialog focus handling to capture associated key --- sdrgui/gui/editcommanddialog.cpp | 8 +-- .../sdrangel/examples/devicesets_config.py | 2 +- swagger/sdrangel/examples/ptt.py | 59 +++++++++++++++---- 3 files changed, 51 insertions(+), 18 deletions(-) mode change 100644 => 100755 swagger/sdrangel/examples/ptt.py diff --git a/sdrgui/gui/editcommanddialog.cpp b/sdrgui/gui/editcommanddialog.cpp index 02125af9c..73003064c 100644 --- a/sdrgui/gui/editcommanddialog.cpp +++ b/sdrgui/gui/editcommanddialog.cpp @@ -153,8 +153,8 @@ void EditCommandDialog::on_keyCapture_toggled(bool checked) { if (checked) { - ui->keyCapture->setFocus(); - ui->keyCapture->setFocusPolicy(Qt::StrongFocus); + setFocus(); + setFocusPolicy(Qt::StrongFocus); connect(m_commandKeyReceiver, SIGNAL(capturedKey(Qt::Key, Qt::KeyboardModifiers, bool)), this, SLOT(commandKeyPressed(Qt::Key, Qt::KeyboardModifiers, bool))); } @@ -162,8 +162,8 @@ void EditCommandDialog::on_keyCapture_toggled(bool checked) { disconnect(m_commandKeyReceiver, SIGNAL(capturedKey(Qt::Key, Qt::KeyboardModifiers, bool)), this, SLOT(commandKeyPressed(Qt::Key, Qt::KeyboardModifiers, bool))); - ui->keyCapture->setFocusPolicy(Qt::NoFocus); - ui->keyCapture->clearFocus(); + setFocusPolicy(Qt::NoFocus); + clearFocus(); } } diff --git a/swagger/sdrangel/examples/devicesets_config.py b/swagger/sdrangel/examples/devicesets_config.py index 3dd312d34..4ac928128 100755 --- a/swagger/sdrangel/examples/devicesets_config.py +++ b/swagger/sdrangel/examples/devicesets_config.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +dev_focus_url#!/usr/bin/env python import requests, traceback, sys from optparse import OptionParser diff --git a/swagger/sdrangel/examples/ptt.py b/swagger/sdrangel/examples/ptt.py old mode 100644 new mode 100755 index 4815bd652..5c1d245e0 --- a/swagger/sdrangel/examples/ptt.py +++ b/swagger/sdrangel/examples/ptt.py @@ -1,6 +1,17 @@ #!/usr/bin/env python - -import requests, json, traceback, sys +''' + PTT (Push To Talk) script example. + + Assumes Rx and Tx are contiguous device sets with Rx at index i and Tx at index i+1 + + When going from Rx to Tx (push) the device set index specified must be the Rx one + When going from Tx to Rx (release) the device set index specified must be the Tx one + Defaults are Rx at index 0 and Tx at index 1 + + Default web API base address is http://127.0.0.1:8091/sdrangel (default of sdrangel web API) + You may change the address and port portion with the -a parameter. Ex: -a 44.168.40.128:8888 +''' +import requests, json, traceback, sys, time from optparse import OptionParser base_url = "http://127.0.0.1:8091/sdrangel" @@ -8,14 +19,18 @@ base_url = "http://127.0.0.1:8091/sdrangel" # ====================================================================== def getInputOptions(): - parser = OptionParser(usage="usage: %%prog [-t]\n") + parser = OptionParser(usage="usage: %prog [-a address:port] [-d index][-t]\n") parser.add_option("-a", "--address", dest="address", help="address and port", metavar="ADDRESS", type="string") parser.add_option("-t", "--transmit", dest="transmit", help="transmit", metavar="TRANSMIT", action="store_true", default=False) + parser.add_option("-d", "--deviceset-index", dest="deviceset_index", help="index of currently active device set (Rx or Tx)", metavar="INDEX", type="int") (options, args) = parser.parse_args() - if (options.address == None): - options.address = "127.0.0.1:8888" + if options.address == None: + options.address = "127.0.0.1:8091" + + if options.deviceset_index == None: + options.deviceset_index = 0 return options @@ -61,6 +76,17 @@ def stopDevice(deviceIndex): else: print("Error getting device %d running state" % deviceIndex) +# ====================================================================== +def setFocus(deviceIndex): + dev_focus_url = base_url+("/deviceset/%d/focus" % deviceIndex) + r = requests.patch(url=dev_focus_url) + if r.status_code / 100 == 2: + print("Focus set on device set %d" % deviceIndex) + elif r.status_code == 400: + print("Set focus on device set is not supported in a server instance") + else: + print("Error setting focus on device set %d" % deviceIndex) + # ====================================================================== def main(): try: @@ -73,19 +99,26 @@ def main(): deviceSets = rj.get("deviceSets", None) if deviceSets is not None: if len(deviceSets) > 1: - if deviceSets[0]["samplingDevice"]["tx"] == 0 and deviceSets[1]["samplingDevice"]["tx"] == 1: - if options.transmit: - stopDevice(0) - startDevice(1) + if options.transmit: + if deviceSets[options.deviceset_index]["samplingDevice"]["tx"] == 0 and deviceSets[options.deviceset_index+1]["samplingDevice"]["tx"] == 1: + stopDevice(options.deviceset_index) + time.sleep(1) + startDevice(options.deviceset_index+1) + setFocus(options.deviceset_index+1) else: - stopDevice(1) - startDevice(0) + print("Incorrect configuration expecting Rx%d and Tx%d" % (options.deviceset_index, options.deviceset_index+1)) else: - print("Incorrect configuration expecting Rx0 and Tx1") + if deviceSets[options.deviceset_index-1]["samplingDevice"]["tx"] == 0 and deviceSets[options.deviceset_index]["samplingDevice"]["tx"] == 1: + stopDevice(options.deviceset_index) + time.sleep(1) + startDevice(options.deviceset_index-1) + setFocus(options.deviceset_index-1) + else: + print("Incorrect configuration expecting Rx%d and Tx%d" % (options.deviceset_index-1, options.deviceset_index)) else: print("Need at least a Rx and a Tx device set") else: - print("Cannot get device sets configuration") + print("Cannot get device sets configuration") else: print("Error getting device sets configuration")