Skip to content

Commit 2a836c0

Browse files
committed
Refactor all kicad specific code into separate module
... that doesn't get imported unless it is needed. This is preparation for adding easyeda support. Issue #95
1 parent a7084af commit 2a836c0

File tree

13 files changed

+619
-553
lines changed

13 files changed

+619
-553
lines changed

InteractiveHtmlBom/__init__.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1+
import os
12
import sys
23
import threading
34
import time
45

5-
import pcbnew
66
import wx
77
import wx.aui
88

9-
from .generate_interactive_bom import InteractiveHtmlBomPlugin
10-
119

1210
def check_for_bom_button():
1311
# From Miles McCoo's blog
@@ -22,19 +20,20 @@ def find_pcbnew_window():
2220
def callback(_):
2321
plugin.Run()
2422

25-
import os
2623
path = os.path.dirname(__file__)
2724
while not wx.GetApp():
2825
time.sleep(1)
2926
bm = wx.Bitmap(path + '/icon.png', wx.BITMAP_TYPE_PNG)
3027
button_wx_item_id = 0
28+
29+
from pcbnew import ID_H_TOOLBAR
3130
while True:
3231
time.sleep(1)
33-
pcbwin = find_pcbnew_window()
34-
if not pcbwin:
32+
pcbnew_window = find_pcbnew_window()
33+
if not pcbnew_window:
3534
continue
3635

37-
top_tb = pcbwin.FindWindowById(pcbnew.ID_H_TOOLBAR)
36+
top_tb = pcbnew_window.FindWindowById(ID_H_TOOLBAR)
3837
if button_wx_item_id == 0 or not top_tb.FindTool(button_wx_item_id):
3938
top_tb.AddSeparator()
4039
button_wx_item_id = wx.NewId()
@@ -44,13 +43,16 @@ def callback(_):
4443
top_tb.Realize()
4544

4645

47-
plugin = InteractiveHtmlBomPlugin()
48-
plugin.defaults()
49-
plugin.register()
46+
if not os.environ.get('INTERACTIVE_HTML_BOM_CLI_MODE', False):
47+
from .ecad.kicad import InteractiveHtmlBomPlugin
48+
49+
plugin = InteractiveHtmlBomPlugin()
50+
plugin.defaults()
51+
plugin.register()
5052

51-
# Add a button the hacky way if plugin button is not supported
52-
# in pcbnew, unless this is linux.
53-
if not plugin.pcbnew_icon_support and not sys.platform.startswith('linux'):
54-
t = threading.Thread(target=check_for_bom_button)
55-
t.daemon = True
56-
t.start()
53+
# Add a button the hacky way if plugin button is not supported
54+
# in pcbnew, unless this is linux.
55+
if not plugin.pcbnew_icon_support and not sys.platform.startswith('linux'):
56+
t = threading.Thread(target=check_for_bom_button)
57+
t.daemon = True
58+
t.start()

InteractiveHtmlBom/core/config.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,21 @@
99

1010

1111
class Config:
12+
FILE_NAME_FORMAT_HINT = (
13+
'Output file name format supports substitutions:\n'
14+
'\n'
15+
' %f : original pcb file name without extension.\n'
16+
' %p : pcb/project title from pcb metadata.\n'
17+
' %c : company from pcb metadata.\n'
18+
' %r : revision from pcb metadata.\n'
19+
' %d : pcb date from metadata if available, '
20+
'file modification date otherwise.\n'
21+
' %D : bom generation date.\n'
22+
' %T : bom generation time.\n'
23+
'\n'
24+
'Extension .html will be added automatically.'
25+
) # type: str
26+
1227
# Helper constants
1328
config_file = os.path.join(os.path.dirname(__file__), '..', 'config.ini')
1429
bom_view_choices = ['bom-only', 'left-right', 'top-bottom']

0 commit comments

Comments
 (0)