Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSV fixes #1107

Merged
merged 4 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions chirp/directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,12 @@ def __repr__(self):
ex.metadata = metadata
raise ex
else:
# If we don't find anything else and the file appears to be a CSV
# file, then explicitly open it with the generic driver so we can
# get relevant errors instead of just "Unknown file format".
if image_file.lower().endswith('.csv'):
rclass = get_radio('Generic_CSV')
return rclass(image_file)
raise errors.ImageDetectFailed("Unknown file format")


Expand Down
8 changes: 7 additions & 1 deletion chirp/drivers/generic_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ def _load(self, f):
lineno += 1
if lineno == 1:
header = line
for field in header:
# Log unknown header names for the UI to capture and expose
if field not in chirp_common.Memory.CSV_FORMAT:
LOG.error('Header line has unknown field %r' % field)
self.file_has_rTone = "rToneFreq" in header
self.file_has_cTone = "cToneFreq" in header
continue
Expand Down Expand Up @@ -348,7 +352,9 @@ def find_csv_header(filedata):
filedata = filedata[1:]
while filedata.startswith('#'):
filedata = filedata[filedata.find('\n') + 1:]
return filedata.startswith('Location,')
delims = ['', '"', "'"]
return any([filedata.startswith('%sLocation%s,' % (d, d))
for d in delims])


@directory.register
Expand Down
54 changes: 47 additions & 7 deletions chirp/wxui/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import platform
import shutil
import tempfile
import textwrap
import threading

import wx
Expand Down Expand Up @@ -711,8 +710,51 @@ def temporary_debug_log():
return dst


class MultiErrorDialog(wx.Dialog):
def __init__(self, *args, **kw):
super().__init__(*args, **kw)
vbox = wx.BoxSizer(wx.VERTICAL)
self.SetSizer(vbox)

self.choices = []
self.choice_box = wx.ListBox(self)
vbox.Add(self.choice_box, border=10, proportion=0,
flag=wx.EXPAND | wx.ALL)

self.message = wx.TextCtrl(self)
self.message.SetEditable(False)
vbox.Add(self.message, border=10, proportion=1,
flag=wx.EXPAND | wx.ALL)

buttons = self.CreateButtonSizer(wx.OK)
vbox.Add(buttons, border=10, flag=wx.ALL)

self.Bind(wx.EVT_BUTTON, self._button)
self.choice_box.Bind(wx.EVT_LISTBOX, self._selected)

self.SetMinSize((600, 400))
self.Fit()
self.Center()

def _button(self, event):
self.EndModal(wx.ID_OK)

def select(self, index):
error = self.choices[index]
self.message.SetValue('%s in %s:\n%s' % (
error.levelname, error.module, error.getMessage()))

def _selected(self, event):
self.select(event.GetInt())

def set_errors(self, errors):
self.choices = errors
self.choice_box.Set([x.getMessage() for x in self.choices])
self.select(0)


@contextlib.contextmanager
def expose_logs(level, root, label, maxlen=128):
def expose_logs(level, root, label, maxlen=128, parent=None):
if not isinstance(root, tuple):
root = (root,)

Expand All @@ -725,9 +767,7 @@ def expose_logs(level, root, label, maxlen=128):
lines = list(itertools.chain.from_iterable(x.get_history()
for x in histories))
if lines:
msg = os.linesep.join(textwrap.shorten(x.getMessage(), maxlen)
for x in lines)
d = wx.MessageDialog(
None, str(msg), label,
style=wx.OK | wx.ICON_INFORMATION)
d = MultiErrorDialog(parent)
d.SetTitle(label)
d.set_errors(lines)
d.ShowModal()
5 changes: 3 additions & 2 deletions chirp/wxui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,8 @@ def open_file(self, filename, exists=True, select=True, rclass=None):
self.enable_bugreport()
CSVRadio = directory.get_radio('Generic_CSV')
label = _('Driver messages')
with common.expose_logs(logging.WARNING, 'chirp.drivers', label):
with common.expose_logs(logging.WARNING, 'chirp.drivers', label,
parent=self):
if exists:
if not os.path.exists(filename):
raise FileNotFoundError(
Expand Down Expand Up @@ -1356,7 +1357,7 @@ def _menu_import(self, event):
r = d.ShowModal()
if r == wx.ID_YES:
with common.expose_logs(logging.WARNING, 'chirp.drivers',
_('Import messages')):
_('Import messages'), parent=self):
radio = directory.get_radio_by_image(filename)
self.current_editorset.current_editor.memedit_import_all(radio)
elif r == wx.ID_NO:
Expand Down
Loading
Loading