Commands: corrected edit command dialog focus handling to capture associated key

This commit is contained in:
f4exb 2018-01-06 05:51:14 +01:00
parent 8a032d0532
commit b002596677
3 changed files with 51 additions and 18 deletions

View File

@ -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();
}
}

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python
dev_focus_url#!/usr/bin/env python
import requests, traceback, sys
from optparse import OptionParser

59
swagger/sdrangel/examples/ptt.py Normal file → Executable file
View File

@ -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")