Skip to content

Commit 4dbfa24

Browse files
committed
Fix browser launching for all platforms
Fixes #2
1 parent 5ac0b1e commit 4dbfa24

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

InteractiveHtmlBom/generate_interactive_bom.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,17 @@ def parse_modules(pcb):
312312
return modules
313313

314314

315-
def main(pcb):
315+
def open_file(filename):
316+
import subprocess
317+
if sys.platform.startswith('win'):
318+
os.startfile(filename)
319+
elif sys.platform.startswith('darwin'):
320+
subprocess.call(('open', filename))
321+
elif sys.platform.startswith('linux'):
322+
subprocess.call(('xdg-open', filename))
323+
324+
325+
def main(pcb, launch_browser=True):
316326
pcb_file_name = pcb.GetFileName()
317327
if not pcb_file_name:
318328
wx.MessageBox('Please save the board file before generating BOM.')
@@ -358,7 +368,8 @@ def main(pcb):
358368
js.write("var pcbdata = ")
359369
js.write(json.dumps(pcbdata))
360370

361-
os.system('start "" "' + bom_file_dir + '/ibom.html"')
371+
if launch_browser:
372+
open_file(os.path.join(bom_file_dir, 'ibom.html'))
362373

363374

364375
class GenerateInteractiveBomPlugin(pcbnew.ActionPlugin):
@@ -385,9 +396,12 @@ def Run(self):
385396
parser = argparse.ArgumentParser(
386397
description='KiCad PCB pick and place assistant')
387398
parser.add_argument('file', type=str, help="KiCad PCB file")
399+
parser.add_argument('--nobrowser', help="Don't launch browser",
400+
action="store_true")
388401
args = parser.parse_args()
402+
if not os.path.isfile(args.file):
403+
print("File %s does not exist." % args.file)
404+
exit(1)
389405
print("Loading %s" % args.file)
390-
main(pcbnew.LoadBoard(args.file))
406+
main(pcbnew.LoadBoard(os.path.abspath(args.file)), not args.nobrowser)
391407

392-
else:
393-
GenerateInteractiveBomPlugin().register()

0 commit comments

Comments
 (0)