forked from Bouni/kicad-jlcpcb-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.py
397 lines (338 loc) · 14.2 KB
/
settings.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
"""This module contains the settings dialog."""
import logging
import wx # pylint: disable=import-error
from .events import UpdateSetting
from .helpers import HighResWxSize, loadBitmapScaled
class SettingsDialog(wx.Dialog):
"""Dialog for plugin settings."""
def __init__(self, parent):
wx.Dialog.__init__(
self,
parent,
id=wx.ID_ANY,
title="JLCPCB tools settings",
pos=wx.DefaultPosition,
size=HighResWxSize(parent.window, wx.Size(1300, 800)),
style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER | wx.MAXIMIZE_BOX,
)
self.logger = logging.getLogger(__name__)
self.parent = parent
# ---------------------------------------------------------------------
# ---------------------------- Hotkeys --------------------------------
# ---------------------------------------------------------------------
quitid = wx.NewId()
self.Bind(wx.EVT_MENU, self.quit_dialog, id=quitid)
entries = [wx.AcceleratorEntry(), wx.AcceleratorEntry(), wx.AcceleratorEntry()]
entries[0].Set(wx.ACCEL_CTRL, ord("W"), quitid)
entries[1].Set(wx.ACCEL_CTRL, ord("Q"), quitid)
entries[2].Set(wx.ACCEL_SHIFT, wx.WXK_ESCAPE, quitid)
accel = wx.AcceleratorTable(entries)
self.SetAcceleratorTable(accel)
# ---------------------------------------------------------------------
# ------------------------- Change settings ---------------------------
# ---------------------------------------------------------------------
##### Tented vias #####
self.tented_vias_setting = wx.CheckBox(
self,
id=wx.ID_ANY,
label="Do not tent vias",
pos=wx.DefaultPosition,
size=wx.DefaultSize,
style=0,
name="gerber_tented_vias",
)
self.tented_vias_setting.SetToolTip(
wx.ToolTip("Whether vias should be coverd by soldermask or not")
)
self.tented_vias_image = wx.StaticBitmap(
self,
wx.ID_ANY,
loadBitmapScaled("tented.png", self.parent.scale_factor, static=True),
wx.DefaultPosition,
wx.DefaultSize,
0,
)
self.tented_vias_setting.Bind(wx.EVT_CHECKBOX, self.update_settings)
tented_vias_sizer = wx.BoxSizer(wx.HORIZONTAL)
tented_vias_sizer.Add(self.tented_vias_image, 10, wx.ALL | wx.EXPAND, 5)
tented_vias_sizer.Add(self.tented_vias_setting, 100, wx.ALL | wx.EXPAND, 5)
##### Fill zones #####
self.fill_zones_setting = wx.CheckBox(
self,
id=wx.ID_ANY,
label="Fill zones",
pos=wx.DefaultPosition,
size=wx.DefaultSize,
style=0,
name="gerber_fill_zones",
)
self.fill_zones_setting.SetToolTip(
wx.ToolTip("Whether zones should be filled on gerber generation")
)
self.fill_zones_image = wx.StaticBitmap(
self,
wx.ID_ANY,
loadBitmapScaled("fill-zones.png", self.parent.scale_factor, static=True),
wx.DefaultPosition,
wx.DefaultSize,
0,
)
self.fill_zones_setting.Bind(wx.EVT_CHECKBOX, self.update_settings)
fill_zones_sizer = wx.BoxSizer(wx.HORIZONTAL)
fill_zones_sizer.Add(self.fill_zones_image, 10, wx.ALL | wx.EXPAND, 5)
fill_zones_sizer.Add(self.fill_zones_setting, 100, wx.ALL | wx.EXPAND, 5)
##### Plot values #####
self.plot_values_setting = wx.CheckBox(
self,
id=wx.ID_ANY,
label="Plot values",
pos=wx.DefaultPosition,
size=wx.DefaultSize,
style=0,
name="gerber_plot_values",
)
self.plot_values_setting.SetToolTip(
wx.ToolTip("Whether value should be plotted on gerber generation")
)
self.plot_values_image = wx.StaticBitmap(
self,
wx.ID_ANY,
loadBitmapScaled("plot_values.png", self.parent.scale_factor, static=True),
wx.DefaultPosition,
wx.DefaultSize,
0,
)
self.plot_values_setting.Bind(wx.EVT_CHECKBOX, self.update_settings)
plot_values_sizer = wx.BoxSizer(wx.HORIZONTAL)
plot_values_sizer.Add(self.plot_values_image, 10, wx.ALL | wx.EXPAND, 5)
plot_values_sizer.Add(self.plot_values_setting, 100, wx.ALL | wx.EXPAND, 5)
##### Plot references #####
self.plot_references_setting = wx.CheckBox(
self,
id=wx.ID_ANY,
label="Plot references",
pos=wx.DefaultPosition,
size=wx.DefaultSize,
style=0,
name="gerber_plot_references",
)
self.plot_references_setting.SetToolTip(
wx.ToolTip("Whether value should be plotted on gerber generation")
)
self.plot_references_image = wx.StaticBitmap(
self,
wx.ID_ANY,
loadBitmapScaled("plot_refs.png", self.parent.scale_factor, static=True),
wx.DefaultPosition,
wx.DefaultSize,
0,
)
self.plot_references_setting.Bind(wx.EVT_CHECKBOX, self.update_settings)
plot_references_sizer = wx.BoxSizer(wx.HORIZONTAL)
plot_references_sizer.Add(self.plot_references_image, 10, wx.ALL | wx.EXPAND, 5)
plot_references_sizer.Add(
self.plot_references_setting, 100, wx.ALL | wx.EXPAND, 5
)
##### LCSC priority #####
self.lcsc_priority_setting = wx.CheckBox(
self,
id=wx.ID_ANY,
label="LCSC number priority",
pos=wx.DefaultPosition,
size=wx.DefaultSize,
style=0,
name="general_lcsc_priority",
)
self.lcsc_priority_setting.SetToolTip(
wx.ToolTip(
"Whether LCSC number from schematic should overrule those in the database"
)
)
self.lcsc_priority_image = wx.StaticBitmap(
self,
wx.ID_ANY,
loadBitmapScaled("schematic.png", self.parent.scale_factor, static=True),
wx.DefaultPosition,
wx.DefaultSize,
0,
)
self.lcsc_priority_setting.Bind(wx.EVT_CHECKBOX, self.update_settings)
lcsc_priority_sizer = wx.BoxSizer(wx.HORIZONTAL)
lcsc_priority_sizer.Add(self.lcsc_priority_image, 10, wx.ALL | wx.EXPAND, 5)
lcsc_priority_sizer.Add(self.lcsc_priority_setting, 100, wx.ALL | wx.EXPAND, 5)
##### Only parts with LCSC number in BOM/CPL #####
self.lcsc_bom_cpl_setting = wx.CheckBox(
self,
id=wx.ID_ANY,
label="Add parts without LCSC numbers to BOM/CPL",
pos=wx.DefaultPosition,
size=wx.DefaultSize,
style=0,
name="gerber_lcsc_bom_cpl",
)
self.lcsc_bom_cpl_setting.SetToolTip(
wx.ToolTip("Whether parts wihout LCSC number should be added to BOM/CPL")
)
self.lcsc_bom_cpl_image = wx.StaticBitmap(
self,
wx.ID_ANY,
loadBitmapScaled("bom.png", self.parent.scale_factor, static=True),
wx.DefaultPosition,
wx.DefaultSize,
0,
)
self.lcsc_bom_cpl_setting.Bind(wx.EVT_CHECKBOX, self.update_settings)
lcsc_bom_cpl_sizer = wx.BoxSizer(wx.HORIZONTAL)
lcsc_bom_cpl_sizer.Add(self.lcsc_bom_cpl_image, 10, wx.ALL | wx.EXPAND, 5)
lcsc_bom_cpl_sizer.Add(self.lcsc_bom_cpl_setting, 100, wx.ALL | wx.EXPAND, 5)
# ---------------------------------------------------------------------
# ---------------------- Main Layout Sizer ----------------------------
# ---------------------------------------------------------------------
layout = wx.GridSizer(10, 2, 0, 0)
layout.Add(tented_vias_sizer, 0, wx.ALL | wx.EXPAND, 5)
layout.Add(fill_zones_sizer, 0, wx.ALL | wx.EXPAND, 5)
layout.Add(plot_values_sizer, 0, wx.ALL | wx.EXPAND, 5)
layout.Add(plot_references_sizer, 0, wx.ALL | wx.EXPAND, 5)
layout.Add(lcsc_priority_sizer, 0, wx.ALL | wx.EXPAND, 5)
layout.Add(lcsc_bom_cpl_sizer, 0, wx.ALL | wx.EXPAND, 5)
self.SetSizer(layout)
self.Layout()
self.Centre(wx.BOTH)
self.load_settings()
def update_tented_vias(self, tented):
"""Update settings dialog according to the settings."""
if tented:
self.tented_vias_setting.SetValue(tented)
self.tented_vias_setting.SetLabel("Tented vias")
self.tented_vias_image.SetBitmap(
loadBitmapScaled("tented.png", self.parent.scale_factor, static=True)
)
else:
self.tented_vias_setting.SetValue(tented)
self.tented_vias_setting.SetLabel("Untented vias")
self.tented_vias_image.SetBitmap(
loadBitmapScaled("untented.png", self.parent.scale_factor, static=True)
)
def update_fill_zones(self, fill):
"""Update settings dialog according to the settings."""
if fill:
self.fill_zones_setting.SetValue(fill)
self.fill_zones_setting.SetLabel("Fill zones")
self.fill_zones_image.SetBitmap(
loadBitmapScaled(
"fill-zones.png", self.parent.scale_factor, static=True
)
)
else:
self.fill_zones_setting.SetValue(fill)
self.fill_zones_setting.SetLabel("Don't fill zones")
self.fill_zones_image.SetBitmap(
loadBitmapScaled(
"unfill-zones.png", self.parent.scale_factor, static=True
)
)
def update_plot_values(self, plot_values):
"""Update settings dialog according to the settings."""
if plot_values:
self.plot_values_setting.SetValue(plot_values)
self.plot_values_setting.SetLabel("Plot values on silkscreen")
self.plot_values_image.SetBitmap(
loadBitmapScaled(
"plot_values.png", self.parent.scale_factor, static=True
)
)
else:
self.plot_values_setting.SetValue(plot_values)
self.plot_values_setting.SetLabel("Don't plot values on silkscreen")
self.plot_values_image.SetBitmap(
loadBitmapScaled("no_values.png", self.parent.scale_factor, static=True)
)
def update_plot_references(self, plot_references):
"""Update settings dialog according to the settings."""
if plot_references:
self.plot_references_setting.SetValue(plot_references)
self.plot_references_setting.SetLabel("Plot references on silkscreen")
self.plot_references_image.SetBitmap(
loadBitmapScaled("plot_refs.png", self.parent.scale_factor, static=True)
)
else:
self.plot_references_setting.SetValue(plot_references)
self.plot_references_setting.SetLabel("Don't plot references on silkscreen")
self.plot_references_image.SetBitmap(
loadBitmapScaled("no_refs.png", self.parent.scale_factor, static=True)
)
def update_lcsc_priority(self, priority):
"""Update settings dialog according to the settings."""
if priority:
self.lcsc_priority_setting.SetValue(priority)
self.lcsc_priority_setting.SetLabel(
"LCSC numbers from schematic have priority"
)
self.lcsc_priority_image.SetBitmap(
loadBitmapScaled("schematic.png", self.parent.scale_factor, static=True)
)
else:
self.lcsc_priority_setting.SetValue(priority)
self.lcsc_priority_setting.SetLabel(
"LCSC numbers from database have priority"
)
self.lcsc_priority_image.SetBitmap(
loadBitmapScaled(
"database-outline.png", self.parent.scale_factor, static=True
)
)
def update_lcsc_bom_cpl(self, add):
"""Update settings dialog according to the settings."""
if add:
self.lcsc_bom_cpl_setting.SetValue(add)
self.lcsc_bom_cpl_setting.SetLabel(
"Add parts without LCSC number to BOM/POS"
)
self.lcsc_bom_cpl_image.SetBitmap(
loadBitmapScaled("bom.png", self.parent.scale_factor, static=True)
)
else:
self.lcsc_bom_cpl_setting.SetValue(add)
self.lcsc_bom_cpl_setting.SetLabel(
"Don't add parts without LCSC number to BOM/POS"
)
self.lcsc_bom_cpl_image.SetBitmap(
loadBitmapScaled("no_bom.png", self.parent.scale_factor, static=True)
)
def load_settings(self):
"""Load settings and set checkboxes accordingly"""
self.update_tented_vias(
self.parent.settings.get("gerber", {}).get("tented_vias", True)
)
self.update_fill_zones(
self.parent.settings.get("gerber", {}).get("fill_zones", True)
)
self.update_plot_values(
self.parent.settings.get("gerber", {}).get("plot_values", True)
)
self.update_plot_references(
self.parent.settings.get("gerber", {}).get("plot_references", True)
)
self.update_lcsc_priority(
self.parent.settings.get("general", {}).get("lcsc_priority", True)
)
self.update_lcsc_bom_cpl(
self.parent.settings.get("gerber", {}).get("lcsc_bom_cpl", True)
)
def update_settings(self, event):
"""Update and persist a setting that was changed."""
section, name = event.GetEventObject().GetName().split("_", 1)
value = event.GetEventObject().GetValue()
getattr(self, f"update_{name}")(value)
wx.PostEvent(
self.parent,
UpdateSetting(
section=section,
setting=name,
value=value,
),
)
def quit_dialog(self, *_):
"""Close this dialog."""
self.Destroy()
self.EndModal(0)