- made showing a shape when hovering over objects, optional, by adding a Preferences -> General parameter

- starting to work in internationalization using gettext()
- Finished adding _() in FlatCAM Tools
This commit is contained in:
Marius Stanciu
2019-03-07 17:37:38 +02:00
committed by Marius
parent b20a6a1a85
commit 94d2fb23e2
18 changed files with 949 additions and 834 deletions

View File

@@ -3,10 +3,9 @@ from ObjectCollection import *
from FlatCAMApp import *
from shapely.geometry import box
class CutOut(FlatCAMTool):
toolName = "Cutout PCB"
toolName = _("Cutout PCB")
gapFinished = pyqtSignal()
def __init__(self, app):
@@ -42,12 +41,12 @@ class CutOut(FlatCAMTool):
# self.type_obj_combo.setItemIcon(1, QtGui.QIcon("share/drill16.png"))
self.type_obj_combo.setItemIcon(2, QtGui.QIcon("share/geometry16.png"))
self.type_obj_combo_label = QtWidgets.QLabel("Obj Type:")
self.type_obj_combo_label = QtWidgets.QLabel(_("Obj Type:"))
self.type_obj_combo_label.setToolTip(
"Specify the type of object to be cutout.\n"
_("Specify the type of object to be cutout.\n"
"It can be of type: Gerber or Geometry.\n"
"What is selected here will dictate the kind\n"
"of objects that will populate the 'Object' combobox."
"of objects that will populate the 'Object' combobox.")
)
self.type_obj_combo_label.setFixedWidth(60)
form_layout.addRow(self.type_obj_combo_label, self.type_obj_combo)
@@ -58,39 +57,39 @@ class CutOut(FlatCAMTool):
self.obj_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
self.obj_combo.setCurrentIndex(1)
self.object_label = QtWidgets.QLabel("Object:")
self.object_label = QtWidgets.QLabel(_("Object:"))
self.object_label.setToolTip(
"Object to be cutout. "
_("Object to be cutout. ")
)
form_layout.addRow(self.object_label, self.obj_combo)
# Tool Diameter
self.dia = FCEntry()
self.dia_label = QtWidgets.QLabel("Tool Dia:")
self.dia_label = QtWidgets.QLabel(_("Tool Dia:"))
self.dia_label.setToolTip(
"Diameter of the tool used to cutout\n"
"the PCB shape out of the surrounding material."
_( "Diameter of the tool used to cutout\n"
"the PCB shape out of the surrounding material.")
)
form_layout.addRow(self.dia_label, self.dia)
# Margin
self.margin = FCEntry()
self.margin_label = QtWidgets.QLabel("Margin:")
self.margin_label = QtWidgets.QLabel(_("Margin:"))
self.margin_label.setToolTip(
"Margin over bounds. A positive value here\n"
_( "Margin over bounds. A positive value here\n"
"will make the cutout of the PCB further from\n"
"the actual PCB border"
"the actual PCB border")
)
form_layout.addRow(self.margin_label, self.margin)
# Gapsize
self.gapsize = FCEntry()
self.gapsize_label = QtWidgets.QLabel("Gap size:")
self.gapsize_label = QtWidgets.QLabel(_("Gap size:"))
self.gapsize_label.setToolTip(
"The size of the bridge gaps in the cutout\n"
_( "The size of the bridge gaps in the cutout\n"
"used to keep the board connected to\n"
"the surrounding material (the one \n"
"from which the PCB is cutout)."
"from which the PCB is cutout).")
)
form_layout.addRow(self.gapsize_label, self.gapsize)
@@ -103,9 +102,9 @@ class CutOut(FlatCAMTool):
# 8 - 2*left + 2*right +2*top + 2*bottom
## Title2
title_param_label = QtWidgets.QLabel("<font size=4><b>A. Automatic Bridge Gaps</b></font>")
title_param_label = QtWidgets.QLabel("<font size=4><b>%s</b></font>" % _('A. Automatic Bridge Gaps'))
title_param_label.setToolTip(
"This section handle creation of automatic bridge gaps."
_("This section handle creation of automatic bridge gaps.")
)
self.layout.addWidget(title_param_label)
@@ -114,9 +113,9 @@ class CutOut(FlatCAMTool):
self.layout.addLayout(form_layout_2)
# Gaps
gaps_label = QtWidgets.QLabel('Gaps:')
gaps_label = QtWidgets.QLabel(_('Gaps:'))
gaps_label.setToolTip(
"Number of gaps used for the Automatic cutout.\n"
_("Number of gaps used for the Automatic cutout.\n"
"There can be maximum 8 bridges/gaps.\n"
"The choices are:\n"
"- lr - left + right\n"
@@ -124,7 +123,7 @@ class CutOut(FlatCAMTool):
"- 4 - left + right +top + bottom\n"
"- 2lr - 2*left + 2*right\n"
"- 2tb - 2*top + 2*bottom\n"
"- 8 - 2*left + 2*right +2*top + 2*bottom"
"- 8 - 2*left + 2*right +2*top + 2*bottom")
)
gaps_label.setFixedWidth(60)
@@ -139,50 +138,50 @@ class CutOut(FlatCAMTool):
hlay = QtWidgets.QHBoxLayout()
self.layout.addLayout(hlay)
title_ff_label = QtWidgets.QLabel("<b>FreeForm:</b>")
title_ff_label = QtWidgets.QLabel("<b>%s</b>" % _('FreeForm:'))
title_ff_label.setToolTip(
"The cutout shape can be of ny shape.\n"
"Useful when the PCB has a non-rectangular shape."
_("The cutout shape can be of ny shape.\n"
"Useful when the PCB has a non-rectangular shape.")
)
hlay.addWidget(title_ff_label)
hlay.addStretch()
self.ff_cutout_object_btn = QtWidgets.QPushButton("Generate Geo")
self.ff_cutout_object_btn = QtWidgets.QPushButton(_("Generate Geo"))
self.ff_cutout_object_btn.setToolTip(
"Cutout the selected object.\n"
_("Cutout the selected object.\n"
"The cutout shape can be of any shape.\n"
"Useful when the PCB has a non-rectangular shape."
"Useful when the PCB has a non-rectangular shape.")
)
hlay.addWidget(self.ff_cutout_object_btn)
hlay2 = QtWidgets.QHBoxLayout()
self.layout.addLayout(hlay2)
title_rct_label = QtWidgets.QLabel("<b>Rectangular:</b>")
title_rct_label = QtWidgets.QLabel("<b>%s</b>" % _('Rectangular:'))
title_rct_label.setToolTip(
"The resulting cutout shape is\n"
_("The resulting cutout shape is\n"
"always a rectangle shape and it will be\n"
"the bounding box of the Object."
"the bounding box of the Object.")
)
hlay2.addWidget(title_rct_label)
hlay2.addStretch()
self.rect_cutout_object_btn = QtWidgets.QPushButton("Generate Geo")
self.rect_cutout_object_btn = QtWidgets.QPushButton(_("Generate Geo"))
self.rect_cutout_object_btn.setToolTip(
"Cutout the selected object.\n"
_("Cutout the selected object.\n"
"The resulting cutout shape is\n"
"always a rectangle shape and it will be\n"
"the bounding box of the Object."
"the bounding box of the Object.")
)
hlay2.addWidget(self.rect_cutout_object_btn)
## Title5
title_manual_label = QtWidgets.QLabel("<font size=4><b>B. Manual Bridge Gaps</b></font>")
title_manual_label = QtWidgets.QLabel("<font size=4><b>%s</b></font>" % _('B. Manual Bridge Gaps'))
title_manual_label.setToolTip(
"This section handle creation of manual bridge gaps.\n"
_("This section handle creation of manual bridge gaps.\n"
"This is done by mouse clicking on the perimeter of the\n"
"Geometry object that is used as a cutout object. "
"Geometry object that is used as a cutout object. ")
)
self.layout.addWidget(title_manual_label)
@@ -196,9 +195,9 @@ class CutOut(FlatCAMTool):
self.man_object_combo.setRootModelIndex(self.app.collection.index(2, 0, QtCore.QModelIndex()))
self.man_object_combo.setCurrentIndex(1)
self.man_object_label = QtWidgets.QLabel("Geo Obj:")
self.man_object_label = QtWidgets.QLabel(_("Geo Obj:"))
self.man_object_label.setToolTip(
"Geometry object used to create the manual cutout."
_("Geometry object used to create the manual cutout.")
)
self.man_object_label.setFixedWidth(60)
# e_lab_0 = QtWidgets.QLabel('')
@@ -209,44 +208,44 @@ class CutOut(FlatCAMTool):
hlay3 = QtWidgets.QHBoxLayout()
self.layout.addLayout(hlay3)
self.man_geo_label = QtWidgets.QLabel("Manual Geo:")
self.man_geo_label = QtWidgets.QLabel(_("Manual Geo:"))
self.man_geo_label.setToolTip(
"If the object to be cutout is a Gerber\n"
_("If the object to be cutout is a Gerber\n"
"first create a Geometry that surrounds it,\n"
"to be used as the cutout, if one doesn't exist yet.\n"
"Select the source Gerber file in the top object combobox."
"Select the source Gerber file in the top object combobox.")
)
hlay3.addWidget(self.man_geo_label)
hlay3.addStretch()
self.man_geo_creation_btn = QtWidgets.QPushButton("Generate Geo")
self.man_geo_creation_btn = QtWidgets.QPushButton(_("Generate Geo"))
self.man_geo_creation_btn.setToolTip(
"If the object to be cutout is a Gerber\n"
_("If the object to be cutout is a Gerber\n"
"first create a Geometry that surrounds it,\n"
"to be used as the cutout, if one doesn't exist yet.\n"
"Select the source Gerber file in the top object combobox."
"Select the source Gerber file in the top object combobox.")
)
hlay3.addWidget(self.man_geo_creation_btn)
hlay4 = QtWidgets.QHBoxLayout()
self.layout.addLayout(hlay4)
self.man_bridge_gaps_label = QtWidgets.QLabel("Manual Add Bridge Gaps:")
self.man_bridge_gaps_label = QtWidgets.QLabel(_("Manual Add Bridge Gaps:"))
self.man_bridge_gaps_label.setToolTip(
"Use the left mouse button (LMB) click\n"
_("Use the left mouse button (LMB) click\n"
"to create a bridge gap to separate the PCB from\n"
"the surrounding material."
"the surrounding material.")
)
hlay4.addWidget(self.man_bridge_gaps_label)
hlay4.addStretch()
self.man_gaps_creation_btn = QtWidgets.QPushButton("Generate Gap")
self.man_gaps_creation_btn = QtWidgets.QPushButton(_("Generate Gap"))
self.man_gaps_creation_btn.setToolTip(
"Use the left mouse button (LMB) click\n"
_("Use the left mouse button (LMB) click\n"
"to create a bridge gap to separate the PCB from\n"
"the surrounding material.\n"
"The LMB click has to be done on the perimeter of\n"
"the Geometry object used as a cutout geometry."
"the Geometry object used as a cutout geometry.")
)
hlay4.addWidget(self.man_gaps_creation_btn)
@@ -315,11 +314,11 @@ class CutOut(FlatCAMTool):
try:
cutout_obj = self.app.collection.get_by_name(str(name))
except:
self.app.inform.emit("[ERROR_NOTCL]Could not retrieve object: %s" % name)
self.app.inform.emit(_("[ERROR_NOTCL]Could not retrieve object: %s") % name)
return "Could not retrieve object: %s" % name
if cutout_obj is None:
self.app.inform.emit("[ERROR_NOTCL]There is no object selected for Cutout.\nSelect one and try again.")
self.app.inform.emit(_("[ERROR_NOTCL]There is no object selected for Cutout.\nSelect one and try again."))
return
try:
@@ -329,13 +328,13 @@ class CutOut(FlatCAMTool):
try:
dia = float(self.dia.get_value().replace(',', '.'))
except ValueError:
self.app.inform.emit("[WARNING_NOTCL] Tool diameter value is missing or wrong format. "
"Add it and retry.")
self.app.inform.emit(_("[WARNING_NOTCL] Tool diameter value is missing or wrong format. "
"Add it and retry."))
return
if 0 in {dia}:
self.app.inform.emit("[WARNING_NOTCL]Tool Diameter is zero value. Change it to a positive integer.")
self.app.inform.emit(_("[WARNING_NOTCL]Tool Diameter is zero value. Change it to a positive integer."))
return "Tool Diameter is zero value. Change it to a positive integer."
try:
@@ -345,8 +344,8 @@ class CutOut(FlatCAMTool):
try:
margin = float(self.margin.get_value().replace(',', '.'))
except ValueError:
self.app.inform.emit("[WARNING_NOTCL] Margin value is missing or wrong format. "
"Add it and retry.")
self.app.inform.emit(_("[WARNING_NOTCL] Margin value is missing or wrong format. "
"Add it and retry."))
return
try:
@@ -356,25 +355,25 @@ class CutOut(FlatCAMTool):
try:
gapsize = float(self.gapsize.get_value().replace(',', '.'))
except ValueError:
self.app.inform.emit("[WARNING_NOTCL] Gap size value is missing or wrong format. "
"Add it and retry.")
self.app.inform.emit(_("[WARNING_NOTCL] Gap size value is missing or wrong format. "
"Add it and retry."))
return
try:
gaps = self.gaps.get_value()
except TypeError:
self.app.inform.emit("[WARNING_NOTCL] Number of gaps value is missing. Add it and retry.")
self.app.inform.emit(_("[WARNING_NOTCL] Number of gaps value is missing. Add it and retry."))
return
if gaps not in ['LR', 'TB', '2LR', '2TB', '4', '8']:
self.app.inform.emit("[WARNING_NOTCL] Gaps value can be only one of: 'lr', 'tb', '2lr', '2tb', 4 or 8. "
"Fill in a correct value and retry. ")
self.app.inform.emit(_("[WARNING_NOTCL] Gaps value can be only one of: 'lr', 'tb', '2lr', '2tb', 4 or 8. "
"Fill in a correct value and retry. "))
return
if cutout_obj.multigeo is True:
self.app.inform.emit("[ERROR]Cutout operation cannot be done on a multi-geo Geometry.\n"
self.app.inform.emit(_("[ERROR]Cutout operation cannot be done on a multi-geo Geometry.\n"
"Optionally, this Multi-geo Geometry can be converted to Single-geo Geometry,\n"
"and after that perform Cutout.")
"and after that perform Cutout."))
return
# Get min and max data for each object as we just cut rectangles across X or Y
@@ -438,7 +437,7 @@ class CutOut(FlatCAMTool):
ymax + gapsize)
cutout_obj.plot()
self.app.inform.emit("[success] Any form CutOut operation finished.")
self.app.inform.emit(_("[success] Any form CutOut operation finished."))
self.app.ui.notebook.setCurrentWidget(self.app.ui.project_tab)
self.app.should_we_save = True
@@ -454,11 +453,11 @@ class CutOut(FlatCAMTool):
try:
cutout_obj = self.app.collection.get_by_name(str(name))
except:
self.app.inform.emit("[ERROR_NOTCL]Could not retrieve object: %s" % name)
self.app.inform.emit(_("[ERROR_NOTCL]Could not retrieve object: %s") % name)
return "Could not retrieve object: %s" % name
if cutout_obj is None:
self.app.inform.emit("[ERROR_NOTCL]Object not found: %s" % cutout_obj)
self.app.inform.emit(_("[ERROR_NOTCL]Object not found: %s") % cutout_obj)
try:
dia = float(self.dia.get_value())
@@ -467,12 +466,12 @@ class CutOut(FlatCAMTool):
try:
dia = float(self.dia.get_value().replace(',', '.'))
except ValueError:
self.app.inform.emit("[WARNING_NOTCL] Tool diameter value is missing or wrong format. "
"Add it and retry.")
self.app.inform.emit(_("[WARNING_NOTCL] Tool diameter value is missing or wrong format. "
"Add it and retry."))
return
if 0 in {dia}:
self.app.inform.emit("[ERROR_NOTCL]Tool Diameter is zero value. Change it to a positive integer.")
self.app.inform.emit(_("[ERROR_NOTCL]Tool Diameter is zero value. Change it to a positive integer."))
return "Tool Diameter is zero value. Change it to a positive integer."
try:
@@ -482,8 +481,8 @@ class CutOut(FlatCAMTool):
try:
margin = float(self.margin.get_value().replace(',', '.'))
except ValueError:
self.app.inform.emit("[WARNING_NOTCL] Margin value is missing or wrong format. "
"Add it and retry.")
self.app.inform.emit(_("[WARNING_NOTCL] Margin value is missing or wrong format. "
"Add it and retry."))
return
try:
@@ -493,25 +492,25 @@ class CutOut(FlatCAMTool):
try:
gapsize = float(self.gapsize.get_value().replace(',', '.'))
except ValueError:
self.app.inform.emit("[WARNING_NOTCL] Gap size value is missing or wrong format. "
"Add it and retry.")
self.app.inform.emit(_("[WARNING_NOTCL] Gap size value is missing or wrong format. "
"Add it and retry."))
return
try:
gaps = self.gaps.get_value()
except TypeError:
self.app.inform.emit("[WARNING_NOTCL] Number of gaps value is missing. Add it and retry.")
self.app.inform.emit(_("[WARNING_NOTCL] Number of gaps value is missing. Add it and retry."))
return
if gaps not in ['LR', 'TB', '2LR', '2TB', '4', '8']:
self.app.inform.emit("[WARNING_NOTCL] Gaps value can be only one of: 'lr', 'tb', '2lr', '2tb', 4 or 8. "
"Fill in a correct value and retry. ")
self.app.inform.emit(_("[WARNING_NOTCL] Gaps value can be only one of: 'lr', 'tb', '2lr', '2tb', 4 or 8. "
"Fill in a correct value and retry. "))
return
if cutout_obj.multigeo is True:
self.app.inform.emit("[ERROR]Cutout operation cannot be done on a multi-geo Geometry.\n"
self.app.inform.emit(_("[ERROR]Cutout operation cannot be done on a multi-geo Geometry.\n"
"Optionally, this Multi-geo Geometry can be converted to Single-geo Geometry,\n"
"and after that perform Cutout.")
"and after that perform Cutout."))
return
# Get min and max data for each object as we just cut rectangles across X or Y
@@ -572,12 +571,12 @@ class CutOut(FlatCAMTool):
ymax + gapsize)
cutout_obj.plot()
self.app.inform.emit("[success] Any form CutOut operation finished.")
self.app.inform.emit(_("[success] Any form CutOut operation finished."))
self.app.ui.notebook.setCurrentWidget(self.app.ui.project_tab)
self.app.should_we_save = True
def on_manual_gap_click(self):
self.app.inform.emit("Click on the selected geometry object perimeter to create a bridge gap ...")
self.app.inform.emit(_("Click on the selected geometry object perimeter to create a bridge gap ..."))
self.app.geo_editor.tool_shape.enabled = True
try:
@@ -587,12 +586,12 @@ class CutOut(FlatCAMTool):
try:
self.cutting_dia = float(self.dia.get_value().replace(',', '.'))
except ValueError:
self.app.inform.emit("[WARNING_NOTCL] Tool diameter value is missing or wrong format. "
"Add it and retry.")
self.app.inform.emit(_("[WARNING_NOTCL] Tool diameter value is missing or wrong format. "
"Add it and retry."))
return
if 0 in {self.cutting_dia}:
self.app.inform.emit("[ERROR_NOTCL]Tool Diameter is zero value. Change it to a positive integer.")
self.app.inform.emit(_("[ERROR_NOTCL]Tool Diameter is zero value. Change it to a positive integer."))
return "Tool Diameter is zero value. Change it to a positive integer."
try:
@@ -602,8 +601,8 @@ class CutOut(FlatCAMTool):
try:
self.cutting_gapsize = float(self.gapsize.get_value().replace(',', '.'))
except ValueError:
self.app.inform.emit("[WARNING_NOTCL] Gap size value is missing or wrong format. "
"Add it and retry.")
self.app.inform.emit(_("[WARNING_NOTCL] Gap size value is missing or wrong format. "
"Add it and retry."))
return
self.app.plotcanvas.vis_disconnect('key_press', self.app.ui.keyPressEvent)
@@ -618,7 +617,7 @@ class CutOut(FlatCAMTool):
def doit(self, event):
# do paint single only for left mouse clicks
if event.button == 1:
self.app.inform.emit("Making manual bridge gap...")
self.app.inform.emit(_("Making manual bridge gap..."))
pos = self.app.plotcanvas.vispy_canvas.translate_coords(event.pos)
self.on_manual_cutout(click_pos=pos)
@@ -641,11 +640,11 @@ class CutOut(FlatCAMTool):
try:
cutout_obj = self.app.collection.get_by_name(str(name))
except:
self.app.inform.emit("[ERROR_NOTCL]Could not retrieve Geoemtry object: %s" % name)
self.app.inform.emit(_("[ERROR_NOTCL]Could not retrieve Geoemtry object: %s") % name)
return "Could not retrieve object: %s" % name
if cutout_obj is None:
self.app.inform.emit("[ERROR_NOTCL]Geometry object for manual cutout not found: %s" % cutout_obj)
self.app.inform.emit(_("[ERROR_NOTCL]Geometry object for manual cutout not found: %s") % cutout_obj)
return
# use the snapped position as reference
@@ -655,7 +654,7 @@ class CutOut(FlatCAMTool):
cutout_obj.subtract_polygon(cut_poly)
cutout_obj.plot()
self.app.inform.emit("[success] Added manual Bridge Gap.")
self.app.inform.emit(_("[success] Added manual Bridge Gap."))
self.app.should_we_save = True
@@ -672,17 +671,17 @@ class CutOut(FlatCAMTool):
try:
cutout_obj = self.app.collection.get_by_name(str(name))
except:
self.app.inform.emit("[ERROR_NOTCL]Could not retrieve Gerber object: %s" % name)
self.app.inform.emit(_("[ERROR_NOTCL]Could not retrieve Gerber object: %s") % name)
return "Could not retrieve object: %s" % name
if cutout_obj is None:
self.app.inform.emit("[ERROR_NOTCL]There is no Gerber object selected for Cutout.\n"
"Select one and try again.")
self.app.inform.emit(_("[ERROR_NOTCL]There is no Gerber object selected for Cutout.\n"
"Select one and try again."))
return
if not isinstance(cutout_obj, FlatCAMGerber):
self.app.inform.emit("[ERROR_NOTCL]The selected object has to be of Gerber type.\n"
"Select a Gerber file and try again.")
self.app.inform.emit(_("[ERROR_NOTCL]The selected object has to be of Gerber type.\n"
"Select a Gerber file and try again."))
return
try:
@@ -692,12 +691,12 @@ class CutOut(FlatCAMTool):
try:
dia = float(self.dia.get_value().replace(',', '.'))
except ValueError:
self.app.inform.emit("[WARNING_NOTCL] Tool diameter value is missing or wrong format. "
"Add it and retry.")
self.app.inform.emit(_("[WARNING_NOTCL] Tool diameter value is missing or wrong format. "
"Add it and retry."))
return
if 0 in {dia}:
self.app.inform.emit("[ERROR_NOTCL]Tool Diameter is zero value. Change it to a positive integer.")
self.app.inform.emit(_("[ERROR_NOTCL]Tool Diameter is zero value. Change it to a positive integer."))
return "Tool Diameter is zero value. Change it to a positive integer."
try:
@@ -707,8 +706,8 @@ class CutOut(FlatCAMTool):
try:
margin = float(self.margin.get_value().replace(',', '.'))
except ValueError:
self.app.inform.emit("[WARNING_NOTCL] Margin value is missing or wrong format. "
"Add it and retry.")
self.app.inform.emit(_("[WARNING_NOTCL] Margin value is missing or wrong format. "
"Add it and retry."))
return
def geo_init(geo_obj, app_obj):