diff --git a/lcc_browser/can/drivers/usbcan_zhou_ligong.py b/lcc_browser/can/drivers/usbcan_zhou_ligong.py index 7e54e3c..0ac8e07 100644 --- a/lcc_browser/can/drivers/usbcan_zhou_ligong.py +++ b/lcc_browser/can/drivers/usbcan_zhou_ligong.py @@ -107,8 +107,12 @@ def receive(self): print('lost sync?', hex(buffer[0])) return None if len(buffer) < 16: - print("CAN buffer length {len(buffer)} should be at least 16. Ignoring data") - return None + # partial data: give data some more time to arrive, then give up + sleep(.05) + buffer += self.ser.read(16 - len(buffer)) + if len(buffer) < 16: + print(f"CAN buffer length {len(buffer)} should be at least 16. Ignoring data") + return None is_extended = buffer[1] is_remote = buffer[2] data_len = buffer[3] diff --git a/lcc_browser/settings.py b/lcc_browser/settings.py index 521cd7c..729fb8a 100644 --- a/lcc_browser/settings.py +++ b/lcc_browser/settings.py @@ -14,7 +14,7 @@ def load(self): if not os.path.exists(settings_filename): print("No setting found at", settings_filename) self["node_id"] = "02.01.0D.00.00.00" - self["html_path"] = "index.html" + self["html_path"] = os.path.abspath("index.html") self["auto_connect"] = False self["can_settings"] = {} return diff --git a/lcc_browser/settings_dialog.py b/lcc_browser/settings_dialog.py index 74668ed..ca13bb5 100644 --- a/lcc_browser/settings_dialog.py +++ b/lcc_browser/settings_dialog.py @@ -2,6 +2,7 @@ import wx import os from urllib.parse import urlparse +from urllib.request import url2pathname import pathlib from lcc_browser.lcc.lcc_protocol import id_to_bytes @@ -41,8 +42,12 @@ def __init__(self, parent, settings): self.node_id.SetValidator(NodeIdValidator()) self.node_id.SetValue(settings.get("node_id")) self.html_path.SetValidator(FilenameValidator()) + print(settings.get("html_path")) p = urlparse(settings.get("html_path")) - html_path = os.path.abspath(os.path.join(p.netloc, p.path)) + html_path = url2pathname(p.path) # fix leading slash in Windows + html_path = os.path.abspath(os.path.join(p.netloc, html_path)) + print(p.netloc, p.path) + print(html_path) self.html_path.SetValue(html_path) self.auto_connect.SetValue(settings.get("auto_connect", False)) diff --git a/lcc_browser/wx_controls/event_id_input.py b/lcc_browser/wx_controls/event_id_input.py index bfad46d..5f477e2 100644 --- a/lcc_browser/wx_controls/event_id_input.py +++ b/lcc_browser/wx_controls/event_id_input.py @@ -24,6 +24,7 @@ def __init__(self, parent): self.SetToolTip(wx.ToolTip("")) self.input.Bind(wx.EVT_CHAR, self.on_char) self.input.Bind(wx.EVT_TEXT, self.on_text) + self.input.Bind(wx.EVT_KEY_UP, self.on_text) sizer = wx.BoxSizer(wx.HORIZONTAL) sizer.Add(self.input) @@ -60,6 +61,7 @@ def on_text(self, evt=None): else: self.GetToolTip().SetTip("Value present on node") self.input.SetBackgroundColour(wx.NullColour) + self.Refresh() def SetValue(self, text): self.input.SetValue(text) diff --git a/lcc_browser/wx_controls/int_input.py b/lcc_browser/wx_controls/int_input.py index f479f13..8a686b3 100644 --- a/lcc_browser/wx_controls/int_input.py +++ b/lcc_browser/wx_controls/int_input.py @@ -35,6 +35,7 @@ def __init__(self, parent, min, max, default): self.SetSizer(sizer) self.input.Bind(wx.EVT_SPINCTRL, self.on_change) + self.input.Bind(wx.EVT_KEY_UP, self.on_change) self.default_value = default self.initial_value = None @@ -56,6 +57,7 @@ def on_change(self, evt=None): else: self.GetToolTip().SetTip("Value present on node") self.input.SetBackgroundColour(wx.NullColour) + self.Refresh() def SetValue(self, val): self.initial_value = val diff --git a/lcc_browser/wx_controls/map_input.py b/lcc_browser/wx_controls/map_input.py index 516063a..4eb9e46 100644 --- a/lcc_browser/wx_controls/map_input.py +++ b/lcc_browser/wx_controls/map_input.py @@ -1,4 +1,5 @@ import wx +import os from lcc_browser.wx_controls.tool_button import ToolButton class MapControl(wx.Choice): @@ -53,18 +54,25 @@ def __init__(self, parent, choices, cdi_entry, default, datatype): self.SetSizer(sizer) + def set_background_color(self, color): + if os.name == 'nt': + self.SetBackgroundColour(color) + else: + self.input.SetBackgroundColour(color) + def on_choice(self, evt=None): if self.input.GetSelection() == wx.NOT_FOUND: self.GetToolTip().SetTip("Make a selection") - self.input.SetBackgroundColour(wx.NullColour) + self.set_background_color(wx.NullColour) else: is_modified = self.input.GetValue() != self.initial_value if is_modified: self.GetToolTip().SetTip("Ready for upload to node") - self.input.SetBackgroundColour(wx.YELLOW) + self.set_background_color(wx.YELLOW) else: self.GetToolTip().SetTip("Value present on node") - self.input.SetBackgroundColour(wx.NullColour) + self.set_background_color(wx.NullColour) + self.Refresh() def GetValue(self): return self.input.GetValue() diff --git a/lcc_browser/wx_controls/string_input.py b/lcc_browser/wx_controls/string_input.py index b9296ed..d79f3e9 100644 --- a/lcc_browser/wx_controls/string_input.py +++ b/lcc_browser/wx_controls/string_input.py @@ -26,6 +26,7 @@ def __init__(self, parent, size): self.SetSizer(sizer) self.input.Bind(wx.EVT_TEXT, self.on_change) + self.input.Bind(wx.EVT_KEY_UP, self.on_change) self.initial_value = None def validate(self): @@ -44,6 +45,7 @@ def on_change(self, evt=None): else: self.GetToolTip().SetTip("Value present on node") self.input.SetBackgroundColour(wx.NullColour) + self.Refresh() def SetValue(self, val): self.initial_value = val