Skip to content

Commit f1a3f47

Browse files
Kyle A LogueTeque5
authored andcommitted
tidy & dependency bugfix
* sort imports & black formatting * remove import * from gui * disable testing of gui (PySimpleGUI issue) * increment to v1.2.2
1 parent c32f18f commit f1a3f47

File tree

7 files changed

+212
-200
lines changed

7 files changed

+212
-200
lines changed

pyproject.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@ dependencies = [
3636
"hypothesis", # next-gen testing framework
3737
]
3838
apps = [
39+
"PySimpleGUI", # for gui interface
3940
"scipy", # for wav i/o
40-
# FIXME: PySimpleGUI 2024-02-12 v5.0.0 release seems to have a bug. Unpin version when possible.
41-
"PySimpleGUI < 5.0.0", # for gui interface
4241
]
4342

4443
[tool.setuptools]
@@ -60,7 +59,7 @@ source = ["sigmf", "tests"]
6059
command_line = "-m pytest -rA --doctest-modules --junitxml=pytest.xml"
6160

6261
[tool.pytest.ini_options]
63-
addopts = "--doctest-modules"
62+
addopts = "--doctest-modules --ignore=sigmf/apps/gui.py"
6463

6564
[tool.pylint]
6665
[tool.pylint.main]

sigmf/__init__.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,11 @@
55
# SPDX-License-Identifier: LGPL-3.0-or-later
66

77
# version of this python module
8-
__version__ = "1.2.1"
8+
__version__ = "1.2.2"
99
# matching version of the SigMF specification
1010
__specification__ = "1.2.0"
1111

12+
from . import archive, archivereader, error, schema, sigmffile, utils, validate
1213
from .archive import SigMFArchive
13-
from .sigmffile import SigMFFile, SigMFCollection
1414
from .archivereader import SigMFArchiveReader
15-
16-
from . import archive
17-
from . import archivereader
18-
from . import error
19-
from . import schema
20-
from . import sigmffile
21-
from . import utils
22-
from . import validate
15+
from .sigmffile import SigMFCollection, SigMFFile

sigmf/apps/gui.py

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@
1010
import logging
1111
import os
1212

13-
from PySimpleGUI import *
13+
import PySimpleGUI as sg
1414

1515
from .. import __version__ as toolversion
1616
from ..archive import SIGMF_ARCHIVE_EXT
1717
from ..sigmffile import SigMFFile, dtype_info, fromarchive
1818

1919
log = logging.getLogger()
2020

21-
validate_button = Button('Update', bind_return_key=False, enable_events=True)
22-
submit_button = Button('Save Archive', disabled=True, button_color=('white', '#D3D3D3'))
23-
load_button = Button('Load', key='Load Archive')
24-
combo_button = InputCombo((), size=(20, 1), enable_events=True, key='Capture Combo')
21+
validate_button = sg.Button('Update', bind_return_key=False, enable_events=True)
22+
submit_button = sg.Button('Save Archive', disabled=True, button_color=('white', '#D3D3D3'))
23+
load_button = sg.Button('Load', key='Load Archive')
24+
combo_button = sg.InputCombo((), size=(20, 1), enable_events=True, key='Capture Combo')
2525

2626

2727
class Unit:
@@ -267,7 +267,7 @@ def add_sigmf_field(funct, values, field_name, *args, required=False, type=None,
267267
else:
268268
funct(*args, input)
269269
except UserWarning as w:
270-
Popup('Warning: {}'.format(repr(w)), title='Warning')
270+
sg.Popup('Warning: {}'.format(repr(w)), title='Warning')
271271
except Exception as e:
272272
show_error(repr(e))
273273
return False
@@ -278,7 +278,7 @@ def add_sigmf_field(funct, values, field_name, *args, required=False, type=None,
278278

279279

280280
def show_error(message):
281-
PopupError(message, title='Error', line_width=60)
281+
sg.PopupError(message, title='Error', line_width=60)
282282

283283

284284
def validate_data(file):
@@ -289,7 +289,7 @@ def validate_data(file):
289289
submit_button.Update(disabled=True)
290290
return False
291291
else:
292-
PopupOK('Data is valid\n', file.dumps(pretty=True), title='')
292+
sg.PopupOK('Data is valid\n', file.dumps(pretty=True), title='')
293293
return True
294294

295295

@@ -305,7 +305,7 @@ def update_capture_screen(capture_data_input, capture_text_blocks, capture_dict)
305305
def update_global_screen(window_data_input, window_text_blocks, window_dict, archive):
306306
data_type = window_dict[SigMFFile.DATATYPE_KEY]
307307
data_info = dtype_info(data_type)
308-
sample_size = 64 if '64' in datatype else 32 if '32' in data_type else 16 if '16' in data_type else 8 if '8' in data_type else None
308+
sample_size = 64 if '64' in data_type else 32 if '32' in data_type else 16 if '16' in data_type else 8 if '8' in data_type else None
309309
assert sample_size is not None
310310
window_text_blocks[WindowInput.DATA_TYPE_FIXEDPOINT].Update(bool(data_info['is_fixedpoint']))
311311
window_text_blocks[WindowInput.DATA_TYPE_UNSIGNED].Update(bool(data_info['is_unsigned']))
@@ -404,36 +404,36 @@ def main():
404404
f = SigMFFile()
405405
capture_selector_dict = {}
406406

407-
layout = [[Text('This is the SigMF tool to archive RF datasets', size=(80, 1))],
408-
[Text('Enter your data and signal captures below. You must include', auto_size_text=True),
409-
Text('required', text_color='red', font=DEFAULT_FONT + ('italic',), auto_size_text=True),
410-
Text('fields.', size=(50, 1), auto_size_text=True)],
411-
[Text('_' * 150, auto_size_text=True)]]
407+
layout = [[sg.Text('This is the SigMF tool to archive RF datasets', size=(80, 1))],
408+
[sg.Text('Enter your data and signal captures below. You must include', auto_size_text=True),
409+
sg.Text('required', text_color='red', font=sg.DEFAULT_FONT + ('italic',), auto_size_text=True),
410+
sg.Text('fields.', size=(50, 1), auto_size_text=True)],
411+
[sg.Text('_' * 150, auto_size_text=True)]]
412412

413-
layout.append([Text('Global Data', font=('Arial', 12, 'bold'))])
413+
layout.append([sg.Text('Global Data', font=('Arial', 12, 'bold'))])
414414
num_components = 0
415415
line = []
416416
for el in window_input.iter_core():
417417
size = (30, 1) if len(line) == 0 else (None, None)
418418
auto_size = True if len(line) == 0 else (10, 1)
419-
line.extend([Text(el, justification='right', size=size,
419+
line.extend([sg.Text(el, justification='right', size=size,
420420
text_color='red' if el in window_input.req_tags else None, auto_size_text=auto_size)])
421421
if el in window_input.el_multiline:
422-
window_text_blocks.update({el: Multiline(window_input.el_text.get(el, ''), key=el,
422+
window_text_blocks.update({el: sg.Multiline(window_input.el_text.get(el, ''), key=el,
423423
tooltip=window_input.el_tooltips.get(el, None), size=(30, 2))})
424424
elif el in window_input.el_selector:
425-
window_text_blocks.update({el: Combo(values=window_input.el_selector[el], key=el,
425+
window_text_blocks.update({el: sg.Combo(values=window_input.el_selector[el], key=el,
426426
size=window_input.el_size.get(el, (None, None)))})
427427
elif el in window_input.el_checkbox:
428-
window_text_blocks.update({el: Checkbox(window_input.el_text.get(el, ''), key=el,
428+
window_text_blocks.update({el: sg.Checkbox(window_input.el_text.get(el, ''), key=el,
429429
size=window_input.el_size.get(el, (None, None)))})
430430
else:
431-
window_text_blocks.update({el: InputText(window_input.el_text.get(el, ''), key=el,
431+
window_text_blocks.update({el: sg.InputText(window_input.el_text.get(el, ''), key=el,
432432
tooltip=window_input.el_tooltips.get(el, None))})
433433
line.append(window_text_blocks[el])
434434

435435
if el in window_input.el_units:
436-
line.append(Text(window_input.el_units[el]))
436+
line.append(sg.Text(window_input.el_units[el]))
437437

438438
num_components += 1
439439
if num_components < window_input.first_line_size:
@@ -447,52 +447,52 @@ def main():
447447
if el is None:
448448
continue
449449
color = 'red' if el in window_input.req_tags else None
450-
window_text_blocks.update({el: InputText(window_input.el_text.get(el, ''), key=el,
450+
window_text_blocks.update({el: sg.InputText(window_input.el_text.get(el, ''), key=el,
451451
tooltip=window_input.el_tooltips.get(el, None))})
452-
line.extend([Text(el, justification='right', size=(size, 1), text_color=color), window_text_blocks[el]])
452+
line.extend([sg.Text(el, justification='right', size=(size, 1), text_color=color), window_text_blocks[el]])
453453
if el in window_input.el_units:
454-
line.append(Text(window_input.el_units[el], size=(5, 1)))
454+
line.append(sg.Text(window_input.el_units[el], size=(5, 1)))
455455
else:
456-
line.append(Text('', size=(5, 1)))
456+
line.append(sg.Text('', size=(5, 1)))
457457
layout.append(line)
458458

459459
layout.extend(
460-
[[Text('_' * 150, auto_size_text=True)],
461-
[Text('Individual Capture Data', font=('Arial', 12, 'bold'))],
462-
[Text('Capture Selector', auto_size_text=True), combo_button, Text('', size=(10, 1)),
463-
Button('Add Capture', enable_events=True), Button('Remove Capture', enable_events=True, size=(15, 1)),
464-
Button('Clear Capture', enable_events=True, size=(15, 1))]]
460+
[[sg.Text('_' * 150, auto_size_text=True)],
461+
[sg.Text('Individual Capture Data', font=('Arial', 12, 'bold'))],
462+
[sg.Text('Capture Selector', auto_size_text=True), combo_button, sg.Text('', size=(10, 1)),
463+
sg.Button('Add Capture', enable_events=True), sg.Button('Remove Capture', enable_events=True, size=(15, 1)),
464+
sg.Button('Clear Capture', enable_events=True, size=(15, 1))]]
465465
)
466466

467467
for el1, el2, el3 in capture_data_input.iter_x(3):
468468
line = []
469469
for el in [el1, el2, el3]:
470470
if el is None:
471471
continue
472-
capture_text_blocks.update({el: InputText(key=el, tooltip=capture_data_input.el_tooltips.get(el, None))})
472+
capture_text_blocks.update({el: sg.InputText(key=el, tooltip=capture_data_input.el_tooltips.get(el, None))})
473473
color = 'red' if el in capture_data_input.req_tags else None
474-
line.extend([Text(el, justification='right', size=(20, 1), text_color=color), capture_text_blocks[el]])
474+
line.extend([sg.Text(el, justification='right', size=(20, 1), text_color=color), capture_text_blocks[el]])
475475
if el in capture_data_input.el_units:
476-
line.append(Text(capture_data_input.el_units[el], size=(5, 1)))
476+
line.append(sg.Text(capture_data_input.el_units[el], size=(5, 1)))
477477
else:
478-
line.append(Text('', size=(5, 1)))
478+
line.append(sg.Text('', size=(5, 1)))
479479
layout.append(line)
480480

481481
window_text_blocks.update(
482-
{WindowInput.DATA_FILE: InputText('', key=WindowInput.DATA_FILE)})
482+
{WindowInput.DATA_FILE: sg.InputText('', key=WindowInput.DATA_FILE)})
483483
layout.extend(
484-
[[Text('_' * 150, auto_size_text=True)],
485-
[Text('Data Location', font=('Arial', 12, 'bold'))],
486-
[Text(WindowInput.DATA_FILE, size=(30, 1), justification='right', text_color='red'),
487-
window_text_blocks[WindowInput.DATA_FILE], FileBrowse()],
488-
[Text(WindowInput.OUTPUT_FOLDER, size=(30, 1), justification='right'),
489-
InputText('', key=WindowInput.OUTPUT_FOLDER), FolderBrowse(), submit_button],
490-
[Text(WindowInput.LOAD_PATH, size=(30, 1), justification='right'), InputText('', key=WindowInput.LOAD_PATH),
491-
FileBrowse(file_types=(("Archive Files", "*.sigmf"),)), load_button],
492-
[validate_button, Button('View Data')]]
484+
[[sg.Text('_' * 150, auto_size_text=True)],
485+
[sg.Text('Data Location', font=('Arial', 12, 'bold'))],
486+
[sg.Text(WindowInput.DATA_FILE, size=(30, 1), justification='right', text_color='red'),
487+
window_text_blocks[WindowInput.DATA_FILE], sg.FileBrowse()],
488+
[sg.Text(WindowInput.OUTPUT_FOLDER, size=(30, 1), justification='right'),
489+
sg.InputText('', key=WindowInput.OUTPUT_FOLDER), sg.FolderBrowse(), submit_button],
490+
[sg.Text(WindowInput.LOAD_PATH, size=(30, 1), justification='right'), sg.InputText('', key=WindowInput.LOAD_PATH),
491+
sg.FileBrowse(file_types=(("Archive Files", "*.sigmf"),)), load_button],
492+
[validate_button, sg.Button('View Data')]]
493493
)
494494

495-
window = Window('SigMF Archive Creator',
495+
window = sg.Window('SigMF Archive Creator',
496496
auto_size_buttons=False,
497497
default_element_size=(20, 1),
498498
auto_size_text=False,
@@ -534,7 +534,7 @@ def main():
534534
add_capture(capture_data_input, capture, capture_selector_dict, f, from_archive=True)
535535

536536
elif event == 'Data Type Help':
537-
PopupOK(
537+
sg.PopupOK(
538538
'Format: <TypeCharacters><ElementBitSize>_<Endianness>\n\n'
539539
'\tTypeCharacters:\n'
540540
'\t\tUnsigned data: \"u\"\n'
@@ -581,7 +581,7 @@ def main():
581581
continue
582582

583583
if validate_data(f):
584-
submit_button.Update(disabled=False, button_color=DEFAULT_BUTTON_COLOR)
584+
submit_button.Update(disabled=False, button_color=sg.DEFAULT_BUTTON_COLOR)
585585
elif event == 'Capture Combo':
586586
capture_dict = capture_selector_dict[values['Capture Combo']]
587587
update_capture_screen(capture_data_input, capture_text_blocks, capture_dict)
@@ -620,7 +620,7 @@ def main():
620620
elif event == 'Clear Capture':
621621
update_capture_screen(capture_data_input, capture_text_blocks, None)
622622
elif event == 'View Data':
623-
PopupOK('Current data:\n', f.dumps(pretty=True), title='')
623+
sg.PopupOK('Current data:\n', f.dumps(pretty=True), title='')
624624
elif event == 'Save Archive':
625625
output_folder = values[WindowInput.OUTPUT_FOLDER]
626626
if output_folder == '':
@@ -632,7 +632,7 @@ def main():
632632
window.Refresh()
633633
archive_file = output_folder + '/' + os.path.basename(f.data_file).split('.')[0] + SIGMF_ARCHIVE_EXT
634634
f.archive(archive_file)
635-
PopupOK('Saved archive as \n', archive_file, title='')
635+
sg.PopupOK('Saved archive as \n', archive_file, title='')
636636
elif event in ['Cancel', None, 'Exit']:
637637
window.Close()
638638
break

sigmf/archive.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
"""Create and extract SigMF archives."""
88

9-
import os
109
import io
10+
import os
1111
import shutil
1212
import tarfile
1313
import tempfile
@@ -20,7 +20,7 @@
2020
SIGMF_COLLECTION_EXT = ".sigmf-collection"
2121

2222

23-
class SigMFArchive():
23+
class SigMFArchive:
2424
"""Archive a SigMFFile.
2525
2626
A `.sigmf` file must include both valid metadata and data.
@@ -52,6 +52,7 @@ class SigMFArchive():
5252
- archive1.sigmf-meta
5353
- archive1.sigmf-data
5454
"""
55+
5556
def __init__(self, sigmffile, name=None, fileobj=None):
5657
self.sigmffile = sigmffile
5758
self.name = name
@@ -61,9 +62,7 @@ def __init__(self, sigmffile, name=None, fileobj=None):
6162

6263
archive_name = self._get_archive_name()
6364
sigmf_fileobj = self._get_output_fileobj()
64-
sigmf_archive = tarfile.TarFile(mode="w",
65-
fileobj=sigmf_fileobj,
66-
format=tarfile.PAX_FORMAT)
65+
sigmf_archive = tarfile.TarFile(mode="w", fileobj=sigmf_fileobj, format=tarfile.PAX_FORMAT)
6766
tmpdir = tempfile.mkdtemp()
6867
sigmf_md_filename = archive_name + SIGMF_METADATA_EXT
6968
sigmf_md_path = os.path.join(tmpdir, sigmf_md_filename)
@@ -75,7 +74,7 @@ def __init__(self, sigmffile, name=None, fileobj=None):
7574

7675
if isinstance(self.sigmffile.data_buffer, io.BytesIO):
7776
self.sigmffile.data_file = sigmf_data_path
78-
with open(sigmf_data_path, 'wb') as f:
77+
with open(sigmf_data_path, "wb") as f:
7978
f.write(self.sigmffile.data_buffer.getbuffer())
8079
else:
8180
shutil.copy(self.sigmffile.data_file, sigmf_data_path)

sigmf/archivereader.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,34 @@
66

77
"""Access SigMF archives without extracting them."""
88

9-
import os
109
import io
10+
import os
1111
import shutil
1212
import tarfile
1313
import tempfile
1414
from pathlib import Path
1515

1616
from . import __version__
17-
from .archive import SIGMF_ARCHIVE_EXT, SIGMF_DATASET_EXT, SIGMF_METADATA_EXT, SigMFArchive
17+
from .archive import (
18+
SIGMF_ARCHIVE_EXT,
19+
SIGMF_DATASET_EXT,
20+
SIGMF_METADATA_EXT,
21+
SigMFArchive,
22+
)
1823
from .error import SigMFFileError
1924
from .sigmffile import SigMFFile
2025
from .utils import dict_merge
2126

2227

23-
class SigMFArchiveReader():
28+
class SigMFArchiveReader:
2429
"""Access data within SigMF archive `tar` in-place without extracting.
2530
2631
Parameters:
2732
2833
name -- path to archive file to access. If file does not exist,
2934
or if `name` doesn't end in .sigmf, SigMFFileError is raised.
3035
"""
36+
3137
def __init__(self, name=None, skip_checksum=False, map_readonly=True, archive_buffer=None):
3238
self.name = name
3339
if self.name is not None:
@@ -38,10 +44,10 @@ def __init__(self, name=None, skip_checksum=False, map_readonly=True, archive_bu
3844
tar_obj = tarfile.open(self.name)
3945

4046
elif archive_buffer is not None:
41-
tar_obj = tarfile.open(fileobj=archive_buffer, mode='r:')
47+
tar_obj = tarfile.open(fileobj=archive_buffer, mode="r:")
4248

4349
else:
44-
raise ValueError('In sigmf.archivereader.__init__(), either `name` or `archive_buffer` must be not None')
50+
raise ValueError("In sigmf.archivereader.__init__(), either `name` or `archive_buffer` must be not None")
4551

4652
json_contents = None
4753
data_offset = None
@@ -70,12 +76,12 @@ def __init__(self, name=None, skip_checksum=False, map_readonly=True, archive_bu
7076
data_buffer = io.BytesIO(memb_fid.read())
7177

7278
else:
73-
print('A regular file', memb.name, 'was found but ignored in the archive')
79+
print(f"A regular file {memb.name} was found but ignored in the archive")
7480
else:
75-
print('A member of type', memb.type, 'and name', memb.name, 'was found but not handled, just FYI.')
81+
print(f"A member of type {memb.type} and name {memb.name} was found but not handled, just FYI.")
7682

7783
if data_offset is None:
78-
raise SigMFFileError('No .sigmf-data file found in archive!')
84+
raise SigMFFileError("No .sigmf-data file found in archive!")
7985

8086
self.sigmffile = SigMFFile(metadata=json_contents)
8187
valid_md = self.sigmffile.validate()

0 commit comments

Comments
 (0)