-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
main.py
701 lines (587 loc) · 27 KB
/
main.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
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
# The MIT License (MIT)
# Copyright 2021,2022 HalfMarble LLC
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
import os.path
import tempfile
import subprocess
import webbrowser
import sys
from os import listdir
from os.path import dirname
from kivy import Config
from kivy.uix.filechooser import FileChooserIconView
from PcbMouseBites import *
from PcbRail import *
from PcbExport import *
Config.set('kivy', 'keyboard_mode', 'system')
Config.set('graphics', 'width', '1600')
Config.set('graphics', 'height', '960')
Config.set('graphics', 'minimum_width', '1024')
Config.set('graphics', 'minimum_height', '670')
from kivy.app import App
from kivy.factory import Factory
from kivy.utils import platform
from kivy.uix.widget import Widget
from kivy.properties import ListProperty, ObservableList
from typing import Final
from kivy.clock import Clock
from kivy.uix.popup import Popup
from kivy.uix.label import Label
from kivy.uix.floatlayout import FloatLayout
from kivy.properties import ObjectProperty
from os.path import sep, expanduser, isdir, dirname
from AppSettings import *
from Utilities import *
from GridRenderer import *
from OffScreenImage import *
from OffScreenScatter import *
from Pcb import *
from PcbBoard import *
from PcbPanel import *
from UI import *
from PcbFile import *
class LoadDialog(FloatLayout):
load = ObjectProperty(None)
cancel = ObjectProperty(None)
class SaveDialog(FloatLayout):
save = ObjectProperty(None)
cancel = ObjectProperty(None)
Factory.register('LoadDialog', cls=LoadDialog)
class PanelizerApp(App):
_zoom_values = [500, 300, 200, 175, 150, 125, 110, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10]
_zoom_values_index = _zoom_values.index(100)
_zoom_str = '{}%'.format(_zoom_values[_zoom_values_index])
_zoom_values_properties = ListProperty([])
def __init__(self, **kwargs):
super(PanelizerApp, self).__init__(**kwargs)
self._demo = True
self._demo_label = None
self._settings = AppSettings
self._tmp_folders_to_delete = []
self._app_tmp_folder = None
self._current_pcb_folder = None
self._finish_load_selected = None
self._finish_save_selected = None
if platform == 'win':
self._root_path = dirname(expanduser('~'))
else:
self._root_path = expanduser('~')
self._load_file_path = self._root_path
self._save_folder_path = self._root_path
self._load_popup = None
self._save_popup = None
self._progress = None
self._error_popup = None
self._settings_popup = None
self._about_popup = None
self._screen = None
self._surface = None
self._grid = None
self._grid_renderer = GridRenderer()
self._pcb = None
self._pcb_board = None
self._pcb_panel = None
self._board_scale_fit = 1.0
self._panel_scale_fit = 1.0
self._scale = 100.0
self._angle = 0.0
self._pixels_per_cm = 1.0
self._size = (100, 100)
self._show_panel = False
self._panels_x = INITIAL_COLUMNS
self._panels_y = INITIAL_ROWS
self._panelization_str = '{}x{}'.format(self._panels_x, self._panels_y)
self._bites_count = AppSettings.bites_count
def build(self):
self.title = Constants.APP_STR
self._surface = self.root.ids._surface
self._zoom_values_index = self._zoom_values.index(self._scale)
for value in self._zoom_values:
self._zoom_values_properties.append('{}%'.format(value))
self._progress = Progress(title='Progress processing Pcb')
self._error_popup = Error(title='Error')
self._settings_popup = Settings(title='Panelizing settings')
self._about_popup = About(title='{}'.format(self.title))
self._grid = OffScreenImage(client=self._grid_renderer, shader=None)
self._surface.add_widget(self._grid)
# let the system layout the window
redraw_window()
self._demo_label = DemoLabel()
self.load_pcb(join(dirname(__file__), DEMO_PCB_PATH_STR), None)
Clock.schedule_once(self.load_underlying_demo_pcb_board, 2.0)
# for debugging: allows me to supply the underlying Pcb gerber files
# so that I can test export panel of the "demo" board quickly
def load_underlying_demo_pcb_board(self, time):
demo_real_pcb = '/Users/gerard/pcbs/neatoboardG'
if os.path.isdir(demo_real_pcb):
self._demo = False
self._current_pcb_folder = demo_real_pcb
#self.load(demo_real_pcb, [])
def load_pcb(self, path, name):
self.root.ids._panelization_button.state = 'normal'
self.rotate(True)
if self._pcb_board is not None:
self._pcb_board.deactivate()
self._pcb_board = None
if self._pcb_panel is not None:
self._pcb_panel.deactivate()
self._pcb_panel = None
self._pcb = Pcb(self.root.ids, path, name)
if self._pcb.valid:
self._pixels_per_cm = self._pcb.pixels_per_cm
self._pcb_board = PcbBoard(root=self._surface, pcb=self._pcb)
self._pcb_board.activate()
self._pcb_panel = PcbPanel(parent=self, root=self._surface, pcb=self._pcb)
self._panels_x = INITIAL_COLUMNS
self._panels_y = INITIAL_ROWS
self._pcb_panel.panelize(self._panels_x, self._panels_y, self._angle, self._bites_count)
self._demo = True if name is None else False
else:
self._pixels_per_cm = self._pcb.pixels_per_cm
self._pcb_board = PcbBoard(root=self._surface, pcb=self._pcb)
self._pcb_board.activate()
self.update_status()
self.panelize()
# Clock.schedule_interval(self.timer_callback, 0.1)
return self._pcb.invalid_reason
def show_panel(self):
if self._pcb_panel is not None:
self._show_panel = self.root.ids._panelization_button.state == 'down'
if not self._show_panel:
self.root.ids._panelization_button.state = 'down'
self._pcb_board.deactivate()
self._pcb_panel.activate()
def panelize(self):
self._surface.remove_widget(self._demo_label)
if self._pcb is not None:
self._show_panel = self.root.ids._panelization_button.state == 'down'
if self._show_panel:
self._pcb_board.deactivate()
if self._pcb_panel is not None:
self._pcb_panel.deactivate()
self.update_scale()
self.calculate_pcb_fit_scale()
if self._pcb_panel is not None:
self._pcb_panel.panelize(self._panels_x, self._panels_y, self._angle, self._bites_count)
self.center()
if self._pcb_panel is not None:
self._pcb_panel.activate()
else:
if self._pcb_panel is not None:
self._pcb_panel.deactivate()
self.update_scale()
self.center()
self._pcb_board.activate()
self.update_status()
self.calculate_pcb_fit_scale()
if self._demo:
self._surface.add_widget(self._demo_label)
def panelize_column(self, add):
if self._pcb is not None:
if add:
self._panels_x += 1
if self._panels_x > MAX_COLUMNS:
self._panels_x = MAX_COLUMNS
beep()
print('WARNING: clamping self.panels_x: {}'.format(self._panels_x))
else:
self._panels_x -= 1
if self._panels_x < 1:
self._panels_x = 1
beep()
self.root.ids._panelization_button.state = 'down'
self.panelize()
def panelize_row(self, add):
if self._pcb is not None:
if add:
self._panels_y += 1
if self._panels_y > MAX_ROWS:
self._panels_y = MAX_ROWS
beep()
print('WARNING: clamping self.panels_y: {}'.format(self._panels_y))
else:
self._panels_y -= 1
if self._panels_y < 1:
self._panels_y = 1
beep()
self.root.ids._panelization_button.state = 'down'
self.panelize()
def calculate_pcb_fit_scale(self):
if self._pcb is not None:
self._board_scale_fit = calculate_fit_scale(FIT_SCALE, self._size, self._pcb.size_pixels)
if self._pcb_panel is not None:
self._panel_scale_fit = calculate_fit_scale(FIT_SCALE, self._size, self._pcb_panel.size_pixels)
self.update_scale()
def update_scale(self):
if self._pcb is not None:
self._scale = self._zoom_values[self._zoom_values_index]
if self._pcb_board is not None:
self._pcb_board.set_scale(self._board_scale_fit * self._scale)
if self._pcb_panel is not None:
self._pcb_panel.set_scale(self._panel_scale_fit * self._scale)
if self._show_panel:
pixels_per_cm_scaled = (self._pixels_per_cm * self._panel_scale_fit * self._scale) / 100.0
else:
pixels_per_cm_scaled = (self._pixels_per_cm * self._board_scale_fit * self._scale) / 100.0
self._grid_renderer.set_pixels_per_cm(pixels_per_cm_scaled)
self.center()
def update_status(self):
self._panelization_str = '{}x{}'.format(self._panels_x, self._panels_y)
self.root.ids._panelization_label.text = self._panelization_str
status = self.root.ids._status_label
status.text = ''
units = ''
if self._pcb.valid:
units = 'mm'
if self._pcb is not None:
#self.root.ids._save_button.disabled = False
status.text += ' Pcb: {},'.format(self._pcb.board_name)
if self._angle == 0.0:
status.text += ' size: {}{} x {}{},'.format(round(self._pcb.size_mm[0], 2), units,
round(self._pcb.size_mm[1], 2), units)
else:
status.text += ' size: {}{} x {}{},'.format(round(self._pcb.size_mm[1], 2), units,
round(self._pcb.size_mm[0], 2), units)
status.text += ' {}valid Pcb, '.format('in' if not self._pcb.valid else '')
if self._pcb_panel is not None:
# self.root.ids._save_button.disabled = True
status.text += ' panel Pcb count: {},'.format(self._panels_x * self._panels_y)
status.text += ' panel size: {}{} x {}{},'.format(round(self._pcb_panel.size_mm[0], 2), units,
round(self._pcb_panel.size_mm[1], 2), units)
status.text += ' {}valid layout.'.format('in' if not self._pcb_panel.valid_layout else '')
else:
status.text += ' invalid layout.'
if self._demo:
status.text += ' DEMO mode.'
else:
status.text = ' Invalid Pcb.'
def update_zoom_title(self):
if self._pcb is not None:
self._zoom_str = self._zoom_values_properties[self._zoom_values_index]
self.root.ids._zoom_button.text = self._zoom_str
self.update_scale()
self.update_status()
def select_zoom_index(self, index):
if self._pcb is not None:
self._zoom_values_index = index
self.update_zoom_title()
def select_zoom(self, in_out):
if self._pcb is not None:
if in_out:
self._zoom_values_index += 1
if self._zoom_values_index >= len(self._zoom_values):
self._zoom_values_index = (len(self._zoom_values) - 1)
beep()
else:
self._zoom_values_index -= 1
if self._zoom_values_index < 0:
self._zoom_values_index = 0
beep()
self.update_zoom_title()
def layer_toggle(self, layer, state):
if self._pcb is not None:
self._pcb.set_layer(self.root.ids, layer, state)
if self._pcb_board is not None:
self._pcb_board.paint()
if self._pcb_panel is not None:
self._pcb_panel.paint()
self.update_status()
def resize(self, size):
if self._pcb is not None:
self._size = size
self.calculate_pcb_fit_scale()
def rotate(self, vertical):
if self._pcb is not None:
if vertical:
self._angle = 0.0
self.root.ids._vertical_button.state = 'down'
self.root.ids._horizontal_button.state = 'normal'
else:
self._angle = 90.0
self.root.ids._vertical_button.state = 'normal'
self.root.ids._horizontal_button.state = 'down'
self.panelize()
def center(self):
self._grid.paint(self._size)
if self._pcb is not None:
if self._pcb_board is not None:
self._pcb_board.center(self._size, self._angle)
if self._pcb_panel is not None:
self._pcb_panel.center(self._size, self._angle)
self.update_status()
def dismiss_load_popup(self):
if self._load_popup is not None:
self._load_popup.dismiss()
def load_finish(self, time):
path = self._finish_load_selected
temp_zip_dir = None
filename_only = os.path.basename(os.path.splitext(path)[0])
filename_ext = os.path.splitext(path)[1].lower()
if filename_ext == '.zip':
temp_zip_dir = tempfile.TemporaryDirectory().name
#print('creating temporary zip directory', temp_zip_dir)
try:
os.mkdir(temp_zip_dir)
except FileExistsError:
pass
unzip_file(temp_zip_dir, path)
path = temp_zip_dir
else:
if not os.path.isdir(path):
path = self._load_file_path
if os.path.isdir(path):
temp_dir = tempfile.TemporaryDirectory().name
#print('creating temporary directory', temp_dir)
try:
os.mkdir(temp_dir)
except FileExistsError:
pass
self._current_pcb_folder = path
generate_pcb_data_layers(path, '.', temp_dir, self._progress, filename_only)
error_msg = self.load_pcb(temp_dir, filename_only)
#print('marking temporary directory for deletion {}', temp_dir)
self._tmp_folders_to_delete.append(temp_dir)
if temp_zip_dir is not None:
#print('marking temporary zip directory for deletion {}', temp_zip_dir)
self._tmp_folders_to_delete.append(temp_zip_dir)
self._progress.dismiss()
if error_msg is not None:
self.error_open(error_msg)
def load(self, path, selection):
# print('load')
# print(' path {}'.format(path))
# print(' selection {}'.format(selection))
# print(' self._root_path {}'.format(self._root_path))
if self._root_path in path:
self._load_file_path = path
self._finish_load_selected = path
if len(selection) > 0:
self._load_file_path = os.path.dirname(os.path.abspath(selection[0]))
self._finish_load_selected = self._load_file_path
if len(selection) > 0:
if self._root_path in selection[0]:
self._finish_load_selected = os.path.abspath(selection[0])
if os.path.isfile(self._finish_load_selected):
selection_ext = os.path.splitext(self._finish_load_selected)[1].lower()
if selection_ext != '.zip':
self._finish_load_selected = os.path.dirname(self._finish_load_selected)
self.dismiss_load_popup()
Clock.schedule_once(self.load_finish, 1.0)
self._progress.open()
update_progressbar(self._progress, 'Loading Pcb ...', 0.0)
def load_pcb_from_disk(self):
content = LoadDialog(load=self.load, cancel=self.dismiss_load_popup)
file_chooser = content.ids._load_file_chooser
file_chooser.rootpath = self._root_path
file_chooser.path = self._load_file_path
file_chooser.dirselect = True
self._load_popup = Popup(title="Select folder with Pcb gerber files or .zip archive file to load",
content=content, size_hint=(0.9, 0.9))
self._load_popup.open()
def save_finish(self, time):
path = self._finish_save_selected
try:
if not os.path.exists(path):
os.makedirs(path)
except:
self._progress.dismiss()
self.error_open("Unable to export to {}!".format(path))
return
update_progressbar(self._progress, 'exporting mouse bites Pcb...', 0.1)
mouse_bite_path = PcbMouseBites.generate_pcb_files()
print('generated mouse bite files in {}'.format(mouse_bite_path))
update_progressbar(self._progress, 'exporting rails Pcb...', 0.2)
rail_path = PcbRail.generate_pcb_files()
print('generated rails files in {}'.format(rail_path))
pcb_size = self._pcb.size_mm
pcb_width_mm = pcb_size[0]
pcb_height_mm = pcb_size[1]
rail_origins = self._pcb_panel.get_rails_origins(pcb_width_mm, pcb_height_mm)
pcb_origins = self._pcb_panel.get_pcbs_origins(pcb_width_mm, pcb_height_mm)
mouse_bite_origins = self._pcb_panel.get_mouse_bites_origins(pcb_width_mm, pcb_height_mm)
# print('rail_origins {}'.format(rail_origins))
# print('pcb_origins {}'.format(pcb_origins))
# print('mouse_bite_origins {}'.format(mouse_bite_origins))
pcb_rect_mm = (self._pcb.origin_mm, self._pcb.size_mm)
error_msg = export_pcb_panel(self._progress, path,
self._current_pcb_folder, pcb_origins, pcb_rect_mm,
rail_path, rail_origins,
mouse_bite_path, mouse_bite_origins, AppSettings.bite, AppSettings.gap,
self._angle)
if error_msg is not None:
self.error_open(error_msg)
self._progress.dismiss()
def dismiss_save_popup(self):
self._save_popup.dismiss()
def save(self, path, selection, foldername):
# print('save')
# print(' path {}'.format(path))
# print(' selection {}'.format(selection))
# print(' foldername {}'.format(foldername))
# print(' self._root_path {}'.format(self._root_path))
if len(selection) > 0:
if self._root_path in selection[0]:
self._save_folder_path = selection[0]
if not os.path.isdir(self._save_folder_path) and os.path.isfile(self._save_folder_path):
self._save_folder_path = os.path.dirname(selection[0])
if foldername is not None and len(foldername) > 0:
self._finish_save_selected = os.path.join(self._save_folder_path, foldername)
else:
self._finish_save_selected = os.path.join(self._save_folder_path, self._pcb.board_name+"_panelized")
self.dismiss_save_popup()
if False:
#if os.path.isdir(self._finish_save_selected):
string = truncate_str_middle(self._finish_save_selected, 60)
self.error_open("Folder {} already exists!".format(string))
else:
update_progressbar(self._progress, 'exporting Pcb panel...', 0.0)
Clock.schedule_once(self.save_finish, 1.0)
self._progress.open()
def save_panel_to_disk(self):
if self._demo:
self.error_open("Can not export DEMO Pcb board (no src gerber files available)")
return
if self._pcb_panel is not None:
self.show_panel()
if self._pcb_panel.valid_layout:
content = SaveDialog(save=self.save, cancel=self.dismiss_save_popup)
file_chooser = content.ids._save_file_chooser
file_chooser.rootpath = self._root_path
file_chooser.path = self._save_folder_path
file_chooser.dirselect = True
content.ids._save_file_name.text = self._pcb.board_name+'_panelized'
self._save_popup = Popup(title="Select folder where to export the Pcb panel",
content=content, size_hint=(0.9, 0.9))
self._save_popup.open()
else:
self.error_open("Invalid Pcb panel layout")
else:
self.error_open("Invalid Pcb board")
def error_open(self, text):
label = self._error_popup.ids._error_label
label.text = text
self._error_popup.open()
def error_close(self):
self._error_popup.dismiss()
def settings_apply(self):
self._settings_popup.ids._gap_setting.text = '{:0.3f}'.format(AppSettings.gap)
self._settings_popup.ids._rail_setting.text = '{:0.3f}'.format(AppSettings.rail)
self._settings_popup.ids._bites_count_setting.text = '{:d}'.format(int(self._bites_count))
self._settings_popup.ids._bite_setting.text = '{:0.3f}'.format(AppSettings.bite)
self._settings_popup.ids._bite_hole_radius_setting.text = '{:0.3f}'.format(AppSettings.bite_hole_radius)
self._settings_popup.ids._bite_hole_space_setting.text = '{:0.3f}'.format(AppSettings.bite_hole_space)
self._settings_popup.ids._use_vcut_setting.state = 'down' if AppSettings.use_vcut else 'normal'
self._settings_popup.ids._use_jlc_setting.state = 'down' if AppSettings.use_jlc else 'normal'
self._settings_popup.ids._merge_error_setting.text = '{:0.3f}'.format(AppSettings.merge_error)
def settings_open(self):
self.show_panel()
self.settings_apply()
self._settings_popup.open()
def settings_default(self):
self._settings.default()
self.settings_apply()
def settings_close(self):
self._settings_popup.dismiss()
try:
gap = float(self._settings_popup.ids._gap_setting.text)
except:
gap = AppSettings.gap
try:
rail = float(self._settings_popup.ids._rail_setting.text)
except:
rail = AppSettings.rail
try:
self._bites_count = int(self._settings_popup.ids._bites_count_setting.text)
except:
self._bites_count = AppSettings.bites_count
try:
bite = float(self._settings_popup.ids._bite_setting.text)
except:
bite = AppSettings.bite
try:
bite_hole_radius = float(self._settings_popup.ids._bite_hole_radius_setting.text)
except:
bite_hole_radius = AppSettings.bite_hole_radius
try:
bite_hole_space = float(self._settings_popup.ids._bite_hole_space_setting.text)
except:
bite_hole_space = AppSettings.bite_hole_space
use_vcut = True if self._settings_popup.ids._use_vcut_setting.state == 'down' else False
use_jlc = True if self._settings_popup.ids._use_jlc_setting.state == 'down' else False
try:
merge_error = float(self._settings_popup.ids._merge_error_setting.text)
except:
merge_error = AppSettings.merge_error
AppSettings.set(gap, rail, self._bites_count, bite, bite_hole_radius, bite_hole_space, use_vcut, use_jlc, merge_error)
PcbRail.invalidate()
PcbMouseBites.invalidate()
self.panelize()
def settings_cancel(self):
self._settings_popup.dismiss()
def settings_oshpark(self):
gap = Constants.OSHPARK_PCB_PANEL_GAP_MM
rail = Constants.OSHPARK_PCB_PANEL_RAIL_HEIGHT_MM
bite = Constants.OSHPARK_PCB_PANEL_BITES_SIZE_MM
bite_hole_radius = Constants.OSHPARK_PCB_BITES_HOLE_RADIUS_MM
bite_hole_space = Constants.OSHPARK_PCB_BITES_HOLE_SPACE_MM
use_vcut = Constants.OSHPARK_PCB_PANEL_VCUT
use_jlc = False
merge_error = AppSettings.merge_error
AppSettings.set(gap, rail, self._bites_count, bite, bite_hole_radius, bite_hole_space, use_vcut, use_jlc, merge_error)
self.settings_apply()
def settings_jlcpcb(self):
gap = Constants.JLC_PCB_PANEL_GAP_MM
rail = Constants.JLC_PCB_PANEL_RAIL_HEIGHT_MM
bite = Constants.JLC_PCB_PANEL_BITES_SIZE_MM
bite_hole_radius = Constants.JLC_PCB_BITES_HOLE_RADIUS_MM
bite_hole_space = Constants.JLC_PCB_BITES_HOLE_SPACE_MM
use_vcut = Constants.JLC_PCB_PANEL_VCUT
use_jlc = True
merge_error = AppSettings.merge_error
AppSettings.set(gap, rail, self._bites_count, bite, bite_hole_radius, bite_hole_space, use_vcut, use_jlc, merge_error)
self.settings_apply()
def settings_pcbway(self):
gap = Constants.PCBWAY_PCB_PANEL_GAP_MM
rail = Constants.PCBWAY_PCB_PANEL_RAIL_HEIGHT_MM
bite = Constants.PCBWAY_PCB_PANEL_BITES_SIZE_MM
bite_hole_radius = Constants.PCBWAY_PCB_BITES_HOLE_RADIUS_MM
bite_hole_space = Constants.PCBWAY_PCB_BITES_HOLE_SPACE_MM
use_vcut = Constants.PCBWAY_PCB_PANEL_VCUT
use_jlc = False
merge_error = AppSettings.merge_error
AppSettings.set(gap, rail, self._bites_count, bite, bite_hole_radius, bite_hole_space, use_vcut, use_jlc, merge_error)
self.settings_apply()
def about(self):
self._about_popup.open()
def about_ok(self):
url = 'https://ko-fi.com/halfmarble'
if sys.platform == 'darwin':
subprocess.Popen(['open', url])
else:
webbrowser.open_new_tab(url)
self._about_popup.dismiss()
def cleanup(self):
if ALLOW_DIR_DELETIONS:
PcbRail.cleanup()
PcbMouseBites.cleanup()
if len(self._tmp_folders_to_delete) > 0:
for folder in self._tmp_folders_to_delete:
rmrf(folder)
if __name__ == '__main__':
app = PanelizerApp()
app.run()
app.cleanup()