[chirp_devel] [PATCH] Natively support null-terminated strings in Browser. #4685
# HG changeset patch # User Tom Hayward tom@tomh.us # Date 1490741376 25200 # Tue Mar 28 15:49:36 2017 -0700 # Node ID 54540fcafdf2ce6dcd5a0fd7791155038fbf972e # Parent 17545c2e365451d38a27091f4016f34d7b4f2013 Natively support null-terminated strings in Browser. #4685
When a bitwise char array that contains a null character is requested in the Browser, there is an error:
Traceback (most recent call last): File "/home/tom/src/chirp.hg/chirp/ui/radiobrowser.py", line 313, in _tree_click e = CharArrayEditor(item) File "/home/tom/src/chirp.hg/chirp/ui/radiobrowser.py", line 123, in __init__ self._build_ui() File "/home/tom/src/chirp.hg/chirp/ui/radiobrowser.py", line 206, in _build_ui ent.set_text(str(self._element)) TypeError: Gtk.Entry.set_text() argument 1 must be string without null bytes, not str
This error results in the char array contents not being displayed at all. All we get is the attribute name.
Radios commonly store strings shorter than the maximum length with null characters filling the remaining space. This is so common the browser should be able to display it.
This change strips the null characters off the char array so that Gtk doesn't freak out. This results in the string being displayed correctly.
The side effect is that the null characters are discarded on change. If the field is edited in the browser, Chirp fills the empty chars with spaces, not null characters like were there originally. Visually there is no difference, but the stored data are different.
diff -r 17545c2e3654 -r 54540fcafdf2 chirp/ui/radiobrowser.py --- a/chirp/ui/radiobrowser.py Tue Mar 28 15:42:45 2017 -0700 +++ b/chirp/ui/radiobrowser.py Tue Mar 28 15:49:36 2017 -0700 @@ -202,7 +202,7 @@
def _build_ui(self): ent = FixedEntry(len(self._element)) - ent.set_text(str(self._element)) + ent.set_text(str(self._element).rstrip("\x00")) ent.connect('changed', self._changed) ent.show() self.pack_start(ent, 1, 1, 1)
participants (1)
-
Tom Hayward