@@ -312,7 +312,17 @@ def parse_modules(pcb):
312
312
return modules
313
313
314
314
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 ):
316
326
pcb_file_name = pcb .GetFileName ()
317
327
if not pcb_file_name :
318
328
wx .MessageBox ('Please save the board file before generating BOM.' )
@@ -358,7 +368,8 @@ def main(pcb):
358
368
js .write ("var pcbdata = " )
359
369
js .write (json .dumps (pcbdata ))
360
370
361
- os .system ('start "" "' + bom_file_dir + '/ibom.html"' )
371
+ if launch_browser :
372
+ open_file (os .path .join (bom_file_dir , 'ibom.html' ))
362
373
363
374
364
375
class GenerateInteractiveBomPlugin (pcbnew .ActionPlugin ):
@@ -385,9 +396,12 @@ def Run(self):
385
396
parser = argparse .ArgumentParser (
386
397
description = 'KiCad PCB pick and place assistant' )
387
398
parser .add_argument ('file' , type = str , help = "KiCad PCB file" )
399
+ parser .add_argument ('--nobrowser' , help = "Don't launch browser" ,
400
+ action = "store_true" )
388
401
args = parser .parse_args ()
402
+ if not os .path .isfile (args .file ):
403
+ print ("File %s does not exist." % args .file )
404
+ exit (1 )
389
405
print ("Loading %s" % args .file )
390
- main (pcbnew .LoadBoard (args .file ))
406
+ main (pcbnew .LoadBoard (os . path . abspath ( args .file )), not args . nobrowser )
391
407
392
- else :
393
- GenerateInteractiveBomPlugin ().register ()
0 commit comments