forked from msvisser/panelize-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpanelize_action.py
63 lines (52 loc) · 1.97 KB
/
panelize_action.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import pcbnew
import os
import wx
from wx.core import DateTime, LogDebug, LogInfo
from .panelize import Panel, PanelSettings
from .panelize_gui import PanelizePluginDialog
class PanelizePlugin(pcbnew.ActionPlugin):
def defaults(self):
self.name = "Create Panel"
self.category = "Modify PCB"
self.description = "Automatically create a panel of boards"
self.show_toolbar_button = True
self.icon_file_name = os.path.join(os.path.dirname(__file__), 'panelize_plugin.png')
self.settings_history = PanelSettings("")
def Run(self):
# Check if the current board is empty
if not pcbnew.GetBoard().IsEmpty():
dlg = wx.MessageDialog(None,
'A panel cannot be created when the board is non-empty. Delete everything, or create a new empty board.',
'Cannot create panel',
wx.OK
)
dlg.ShowModal()
dlg.Destroy()
return
# Ask the user for the board and settings
panelize_dialog = PanelizePluginDialog()
panelize_dialog.LoadSettings(self.settings_history)
# Uncomment for debugging
# wx.Log.SetLogLevel(6)
# self.log_window = wx.LogWindow(None, 'Log Window', True)
# Do not show window for faster debugging
# ok = panelize_dialog.Show()
ok = panelize_dialog.ShowModal()
LogDebug("Plugin started..")
if not ok:
panelize_dialog.Destroy()
return
settings = panelize_dialog.GetSettings()
panelize_dialog.Destroy()
self.settings_history = settings
# Load the board to be panelized
try:
Panel(settings).create_panel()
except IOError:
dlg = wx.MessageDialog(None,
'The board that was selected could not be opened.',
'Cannot open board',
wx.OK
)
dlg.ShowModal()
dlg.Destroy()