Skip to content

Commit

Permalink
changes for MS Windows build
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrian Haensler committed Apr 5, 2023
1 parent dfef55b commit 8e61a82
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 7 deletions.
8 changes: 6 additions & 2 deletions lcc_browser/can/drivers/usbcan_zhou_ligong.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion lcc_browser/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion lcc_browser/settings_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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))

Expand Down
2 changes: 2 additions & 0 deletions lcc_browser/wx_controls/event_id_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions lcc_browser/wx_controls/int_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
14 changes: 11 additions & 3 deletions lcc_browser/wx_controls/map_input.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import wx
import os
from lcc_browser.wx_controls.tool_button import ToolButton

class MapControl(wx.Choice):
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions lcc_browser/wx_controls/string_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
Expand Down

0 comments on commit 8e61a82

Please sign in to comment.