- fixed issue when doing th CTRL (or SHIFT) + LMB, the focus is automatically moved to Project Tab

- further work in internationalization, added a fallback to English language in case there is no translation for a string
This commit is contained in:
Marius Stanciu
2019-03-08 14:10:23 +02:00
parent 328182d863
commit 6ba037fd83
22 changed files with 1012 additions and 843 deletions

View File

@@ -8,9 +8,16 @@ import FlatCAMTranslation as fcTranslate
fcTranslate.apply_language('ToolNonCopperClear')
def _tr(text):
try:
return _(text)
except:
return text
class NonCopperClear(FlatCAMTool, Gerber):
toolName = _("Non-Copper Clearing")
toolName = _tr("Non-Copper Clearing")
def __init__(self, app):
self.app = app
@@ -48,7 +55,7 @@ class NonCopperClear(FlatCAMTool, Gerber):
self.object_label = QtWidgets.QLabel("Gerber:")
self.object_label.setToolTip(
_("Gerber object to be cleared of excess copper. ")
_tr("Gerber object to be cleared of excess copper. ")
)
e_lab_0 = QtWidgets.QLabel('')
@@ -56,9 +63,9 @@ class NonCopperClear(FlatCAMTool, Gerber):
form_layout.addRow(e_lab_0)
#### Tools ####
self.tools_table_label = QtWidgets.QLabel('<b>%s</b>' % _('Tools Table'))
self.tools_table_label = QtWidgets.QLabel('<b>%s</b>' % _tr('Tools Table'))
self.tools_table_label.setToolTip(
_("Tools pool from which the algorithm\n"
_tr("Tools pool from which the algorithm\n"
"will pick the ones used for copper clearing.")
)
self.tools_box.addWidget(self.tools_table_label)
@@ -67,13 +74,13 @@ class NonCopperClear(FlatCAMTool, Gerber):
self.tools_box.addWidget(self.tools_table)
self.tools_table.setColumnCount(4)
self.tools_table.setHorizontalHeaderLabels(['#', _('Diameter'), 'TT', ''])
self.tools_table.setHorizontalHeaderLabels(['#', _tr('Diameter'), 'TT', ''])
self.tools_table.setColumnHidden(3, True)
self.tools_table.setSortingEnabled(False)
# self.tools_table.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows)
self.tools_table.horizontalHeaderItem(0).setToolTip(
_("This is the Tool Number.\n"
_tr("This is the Tool Number.\n"
"Non copper clearing will start with the tool with the biggest \n"
"diameter, continuing until there are no more tools.\n"
"Only tools that create NCC clearing geometry will still be present\n"
@@ -81,11 +88,11 @@ class NonCopperClear(FlatCAMTool, Gerber):
"this function will not be able to create painting geometry.")
)
self.tools_table.horizontalHeaderItem(1).setToolTip(
_("Tool Diameter. It's value (in current FlatCAM units) \n"
_tr("Tool Diameter. It's value (in current FlatCAM units) \n"
"is the cut width into the material."))
self.tools_table.horizontalHeaderItem(2).setToolTip(
_("The Tool Type (TT) can be:<BR>"
_tr("The Tool Type (TT) can be:<BR>"
"- <B>Circular</B> with 1 ... 4 teeth -> it is informative only. Being circular, <BR>"
"the cut width in material is exactly the tool diameter.<BR>"
"- <B>Ball</B> -> informative only and make reference to the Ball type endmill.<BR>"
@@ -104,9 +111,9 @@ class NonCopperClear(FlatCAMTool, Gerber):
hlay = QtWidgets.QHBoxLayout()
self.tools_box.addLayout(hlay)
self.addtool_entry_lbl = QtWidgets.QLabel('<b>%s:</b>' % _('Tool Dia'))
self.addtool_entry_lbl = QtWidgets.QLabel('<b>%s:</b>' % _tr('Tool Dia'))
self.addtool_entry_lbl.setToolTip(
_("Diameter for the new tool to add in the Tool Table")
_tr("Diameter for the new tool to add in the Tool Table")
)
self.addtool_entry = FCEntry()
@@ -118,9 +125,9 @@ class NonCopperClear(FlatCAMTool, Gerber):
grid2 = QtWidgets.QGridLayout()
self.tools_box.addLayout(grid2)
self.addtool_btn = QtWidgets.QPushButton(_('Add'))
self.addtool_btn = QtWidgets.QPushButton(_tr('Add'))
self.addtool_btn.setToolTip(
_("Add a new tool to the Tool Table\n"
_tr("Add a new tool to the Tool Table\n"
"with the diameter specified above.")
)
@@ -130,9 +137,9 @@ class NonCopperClear(FlatCAMTool, Gerber):
# "by first selecting a row in the Tool Table."
# )
self.deltool_btn = QtWidgets.QPushButton(_('Delete'))
self.deltool_btn = QtWidgets.QPushButton(_tr('Delete'))
self.deltool_btn.setToolTip(
_("Delete a selection of tools in the Tool Table\n"
_tr("Delete a selection of tools in the Tool Table\n"
"by first selecting a row(s) in the Tool Table.")
)
@@ -149,9 +156,9 @@ class NonCopperClear(FlatCAMTool, Gerber):
e_lab_1 = QtWidgets.QLabel('')
grid3.addWidget(e_lab_1, 0, 0)
nccoverlabel = QtWidgets.QLabel(_('Overlap:'))
nccoverlabel = QtWidgets.QLabel(_tr('Overlap:'))
nccoverlabel.setToolTip(
_("How much (fraction) of the tool width to overlap each tool pass.\n"
_tr("How much (fraction) of the tool width to overlap each tool pass.\n"
"Example:\n"
"A value here of 0.25 means 25% from the tool diameter found above.\n\n"
"Adjust the value starting with lower values\n"
@@ -165,18 +172,18 @@ class NonCopperClear(FlatCAMTool, Gerber):
self.ncc_overlap_entry = FCEntry()
grid3.addWidget(self.ncc_overlap_entry, 1, 1)
nccmarginlabel = QtWidgets.QLabel(_('Margin:'))
nccmarginlabel = QtWidgets.QLabel(_tr('Margin:'))
nccmarginlabel.setToolTip(
_("Bounding box margin.")
_tr("Bounding box margin.")
)
grid3.addWidget(nccmarginlabel, 2, 0)
self.ncc_margin_entry = FCEntry()
grid3.addWidget(self.ncc_margin_entry, 2, 1)
# Method
methodlabel = QtWidgets.QLabel(_('Method:'))
methodlabel = QtWidgets.QLabel(_tr('Method:'))
methodlabel.setToolTip(
_("Algorithm for non-copper clearing:<BR>"
_tr("Algorithm for non-copper clearing:<BR>"
"<B>Standard</B>: Fixed step inwards.<BR>"
"<B>Seed-based</B>: Outwards from seed.<BR>"
"<B>Line-based</B>: Parallel lines.")
@@ -190,27 +197,27 @@ class NonCopperClear(FlatCAMTool, Gerber):
grid3.addWidget(self.ncc_method_radio, 3, 1)
# Connect lines
pathconnectlabel = QtWidgets.QLabel(_("Connect:"))
pathconnectlabel = QtWidgets.QLabel(_tr("Connect:"))
pathconnectlabel.setToolTip(
_("Draw lines between resulting\n"
_tr("Draw lines between resulting\n"
"segments to minimize tool lifts.")
)
grid3.addWidget(pathconnectlabel, 4, 0)
self.ncc_connect_cb = FCCheckBox()
grid3.addWidget(self.ncc_connect_cb, 4, 1)
contourlabel = QtWidgets.QLabel(_("Contour:"))
contourlabel = QtWidgets.QLabel(_tr("Contour:"))
contourlabel.setToolTip(
_("Cut around the perimeter of the polygon\n"
_tr("Cut around the perimeter of the polygon\n"
"to trim rough edges.")
)
grid3.addWidget(contourlabel, 5, 0)
self.ncc_contour_cb = FCCheckBox()
grid3.addWidget(self.ncc_contour_cb, 5, 1)
restlabel = QtWidgets.QLabel(_("Rest M.:"))
restlabel = QtWidgets.QLabel(_tr("Rest M.:"))
restlabel.setToolTip(
_("If checked, use 'rest machining'.\n"
_tr("If checked, use 'rest machining'.\n"
"Basically it will clear copper outside PCB features,\n"
"using the biggest tool and continue with the next tools,\n"
"from bigger to smaller, to clear areas of copper that\n"
@@ -222,9 +229,9 @@ class NonCopperClear(FlatCAMTool, Gerber):
self.ncc_rest_cb = FCCheckBox()
grid3.addWidget(self.ncc_rest_cb, 6, 1)
self.generate_ncc_button = QtWidgets.QPushButton(_('Generate Geometry'))
self.generate_ncc_button = QtWidgets.QPushButton(_tr('Generate Geometry'))
self.generate_ncc_button.setToolTip(
_("Create the Geometry Object\n"
_tr("Create the Geometry Object\n"
"for non-copper routing.")
)
self.tools_box.addWidget(self.generate_ncc_button)
@@ -264,7 +271,7 @@ class NonCopperClear(FlatCAMTool, Gerber):
self.set_tool_ui()
self.build_ui()
self.app.ui.notebook.setTabText(2, _("NCC Tool"))
self.app.ui.notebook.setTabText(2, _tr("NCC Tool"))
def set_tool_ui(self):
self.tools_frame.show()
@@ -459,16 +466,16 @@ class NonCopperClear(FlatCAMTool, Gerber):
try:
tool_dia = float(self.addtool_entry.get_value().replace(',', '.'))
except ValueError:
self.app.inform.emit(_("[ERROR_NOTCL]Wrong value format entered, "
self.app.inform.emit(_tr("[ERROR_NOTCL]Wrong value format entered, "
"use a number."))
return
if tool_dia is None:
self.build_ui()
self.app.inform.emit(_("[WARNING_NOTCL] Please enter a tool diameter to add, in Float format."))
self.app.inform.emit(_tr("[WARNING_NOTCL] Please enter a tool diameter to add, in Float format."))
return
if tool_dia == 0:
self.app.inform.emit(_("[WARNING_NOTCL] Please enter a tool diameter with non-zero value, in Float format."))
self.app.inform.emit(_tr("[WARNING_NOTCL] Please enter a tool diameter with non-zero value, in Float format."))
return
# construct a list of all 'tooluid' in the self.tools
@@ -492,12 +499,12 @@ class NonCopperClear(FlatCAMTool, Gerber):
if float('%.4f' % tool_dia) in tool_dias:
if muted is None:
self.app.inform.emit(_("[WARNING_NOTCL]Adding tool cancelled. Tool already in Tool Table."))
self.app.inform.emit(_tr("[WARNING_NOTCL]Adding tool cancelled. Tool already in Tool Table."))
self.tools_table.itemChanged.connect(self.on_tool_edit)
return
else:
if muted is None:
self.app.inform.emit(_("[success] New tool added to Tool Table."))
self.app.inform.emit(_tr("[success] New tool added to Tool Table."))
self.ncc_tools.update({
int(self.tooluid): {
'tooldia': float('%.4f' % tool_dia),
@@ -530,7 +537,7 @@ class NonCopperClear(FlatCAMTool, Gerber):
try:
new_tool_dia = float(self.tools_table.item(row, 1).text().replace(',', '.'))
except ValueError:
self.app.inform.emit(_("[ERROR_NOTCL] Wrong value format entered, "
self.app.inform.emit(_tr("[ERROR_NOTCL] Wrong value format entered, "
"use a number."))
return
@@ -539,7 +546,7 @@ class NonCopperClear(FlatCAMTool, Gerber):
# identify the tool that was edited and get it's tooluid
if new_tool_dia not in tool_dias:
self.ncc_tools[tooluid]['tooldia'] = new_tool_dia
self.app.inform.emit(_("[success] Tool from Tool Table was edited."))
self.app.inform.emit(_tr("[success] Tool from Tool Table was edited."))
self.build_ui()
return
else:
@@ -550,7 +557,7 @@ class NonCopperClear(FlatCAMTool, Gerber):
break
restore_dia_item = self.tools_table.item(row, 1)
restore_dia_item.setText(str(old_tool_dia))
self.app.inform.emit(_("[WARNING_NOTCL] Edit cancelled. New diameter value is already in the Tool Table."))
self.app.inform.emit(_tr("[WARNING_NOTCL] Edit cancelled. New diameter value is already in the Tool Table."))
self.build_ui()
def on_tool_delete(self, rows_to_delete=None, all=None):
@@ -589,12 +596,12 @@ class NonCopperClear(FlatCAMTool, Gerber):
self.ncc_tools.pop(t, None)
except AttributeError:
self.app.inform.emit(_("[WARNING_NOTCL]Delete failed. Select a tool to delete."))
self.app.inform.emit(_tr("[WARNING_NOTCL]Delete failed. Select a tool to delete."))
return
except Exception as e:
log.debug(str(e))
self.app.inform.emit(_("[success] Tool(s) deleted from Tool Table."))
self.app.inform.emit(_tr("[success] Tool(s) deleted from Tool Table."))
self.build_ui()
def on_ncc(self):
@@ -606,7 +613,7 @@ class NonCopperClear(FlatCAMTool, Gerber):
try:
over = float(self.ncc_overlap_entry.get_value().replace(',', '.'))
except ValueError:
self.app.inform.emit(_("[ERROR_NOTCL]Wrong value format entered, "
self.app.inform.emit(_tr("[ERROR_NOTCL]Wrong value format entered, "
"use a number."))
return
over = over if over else self.app.defaults["tools_nccoverlap"]
@@ -618,7 +625,7 @@ class NonCopperClear(FlatCAMTool, Gerber):
try:
margin = float(self.ncc_margin_entry.get_value().replace(',', '.'))
except ValueError:
self.app.inform.emit(_("[ERROR_NOTCL]Wrong value format entered, "
self.app.inform.emit(_tr("[ERROR_NOTCL]Wrong value format entered, "
"use a number."))
return
margin = margin if margin else self.app.defaults["tools_nccmargin"]
@@ -640,14 +647,14 @@ class NonCopperClear(FlatCAMTool, Gerber):
try:
self.ncc_obj = self.app.collection.get_by_name(self.obj_name)
except:
self.app.inform.emit(_("[ERROR_NOTCL]Could not retrieve object: %s") % self.obj_name)
self.app.inform.emit(_tr("[ERROR_NOTCL]Could not retrieve object: %s") % self.obj_name)
return "Could not retrieve object: %s" % self.obj_name
# Prepare non-copper polygons
try:
bounding_box = self.ncc_obj.solid_geometry.envelope.buffer(distance=margin, join_style=JOIN_STYLE.mitre)
except AttributeError:
self.app.inform.emit(_("[ERROR_NOTCL]No Gerber file available."))
self.app.inform.emit(_tr("[ERROR_NOTCL]No Gerber file available."))
return
# calculate the empty area by subtracting the solid_geometry from the object bounding box geometry
@@ -685,7 +692,7 @@ class NonCopperClear(FlatCAMTool, Gerber):
sorted_tools.sort(reverse=True)
# Do job in background
proc = self.app.proc_container.new(_("Clearing Non-Copper areas."))
proc = self.app.proc_container.new(_tr("Clearing Non-Copper areas."))
def initialize(geo_obj, app_obj):
assert isinstance(geo_obj, FlatCAMGeometry), \
@@ -703,7 +710,7 @@ class NonCopperClear(FlatCAMTool, Gerber):
current_uid = int(1)
for tool in sorted_tools:
self.app.inform.emit(_('[success] Non-Copper Clearing with ToolDia = %s started.') % str(tool))
self.app.inform.emit(_tr('[success] Non-Copper Clearing with ToolDia = %s started.') % str(tool))
cleared_geo[:] = []
# Get remaining tools offset
@@ -772,14 +779,14 @@ class NonCopperClear(FlatCAMTool, Gerber):
app_obj.new_object("geometry", name, initialize)
except Exception as e:
proc.done()
self.app.inform.emit(_('[ERROR_NOTCL] NCCTool.clear_non_copper() --> %s') % str(e))
self.app.inform.emit(_tr('[ERROR_NOTCL] NCCTool.clear_non_copper() --> %s') % str(e))
return
proc.done()
if app_obj.poly_not_cleared is False:
self.app.inform.emit(_('[success] NCC Tool finished.'))
self.app.inform.emit(_tr('[success] NCC Tool finished.'))
else:
self.app.inform.emit(_('[WARNING_NOTCL] NCC Tool finished but some PCB features could not be cleared. '
self.app.inform.emit(_tr('[WARNING_NOTCL] NCC Tool finished but some PCB features could not be cleared. '
'Check the result.'))
# reset the variable for next use
app_obj.poly_not_cleared = False
@@ -787,7 +794,7 @@ class NonCopperClear(FlatCAMTool, Gerber):
# focus on Selected Tab
self.app.ui.notebook.setCurrentWidget(self.app.ui.selected_tab)
self.tools_frame.hide()
self.app.ui.notebook.setTabText(2, _("Tools"))
self.app.ui.notebook.setTabText(2, _tr("Tools"))
# Promise object with the new name
self.app.collection.promise(name)
@@ -807,7 +814,7 @@ class NonCopperClear(FlatCAMTool, Gerber):
sorted_tools.sort(reverse=True)
# Do job in background
proc = self.app.proc_container.new(_("Clearing Non-Copper areas."))
proc = self.app.proc_container.new(_tr("Clearing Non-Copper areas."))
def initialize_rm(geo_obj, app_obj):
assert isinstance(geo_obj, FlatCAMGeometry), \
@@ -825,7 +832,7 @@ class NonCopperClear(FlatCAMTool, Gerber):
# Generate area for each tool
while sorted_tools:
tool = sorted_tools.pop(0)
self.app.inform.emit(_('[success] Non-Copper Rest Clearing with ToolDia = %s started.') % str(tool))
self.app.inform.emit(_tr('[success] Non-Copper Rest Clearing with ToolDia = %s started.') % str(tool))
tool_used = tool - 1e-12
cleared_geo[:] = []
@@ -923,7 +930,7 @@ class NonCopperClear(FlatCAMTool, Gerber):
app_obj.new_object("geometry", name, initialize_rm)
except Exception as e:
proc.done()
self.app.inform.emit(_('[ERROR_NOTCL] NCCTool.clear_non_copper_rest() --> %s') % str(e))
self.app.inform.emit(_tr('[ERROR_NOTCL] NCCTool.clear_non_copper_rest() --> %s') % str(e))
return
if app_obj.poly_not_cleared is True:
@@ -931,7 +938,7 @@ class NonCopperClear(FlatCAMTool, Gerber):
# focus on Selected Tab
self.app.ui.notebook.setCurrentWidget(self.app.ui.selected_tab)
else:
self.app.inform.emit(_('[ERROR_NOTCL] NCC Tool finished but could not clear the object '
self.app.inform.emit(_tr('[ERROR_NOTCL] NCC Tool finished but could not clear the object '
'with current settings.'))
# focus on Project Tab
self.app.ui.notebook.setCurrentWidget(self.app.ui.project_tab)