- 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

@@ -5,7 +5,7 @@ from ObjectCollection import *
class ToolPaint(FlatCAMTool, Gerber):
toolName = "Paint Area"
toolName = _("Paint Area")
def __init__(self, app):
self.app = app
@@ -41,19 +41,19 @@ class ToolPaint(FlatCAMTool, Gerber):
self.object_combo.setRootModelIndex(self.app.collection.index(2, 0, QtCore.QModelIndex()))
self.object_combo.setCurrentIndex(1)
self.object_label = QtWidgets.QLabel("Geometry:")
self.object_label = QtWidgets.QLabel(_("Geometry:"))
self.object_label.setToolTip(
"Geometry object to be painted. "
_("Geometry object to be painted. ")
)
e_lab_0 = QtWidgets.QLabel('')
form_layout.addRow(self.object_label, self.object_combo)
form_layout.addRow(e_lab_0)
#### Tools ####
self.tools_table_label = QtWidgets.QLabel('<b>Tools Table</b>')
self.tools_table_label = QtWidgets.QLabel('<b>%s</b>' % _('Tools Table'))
self.tools_table_label.setToolTip(
"Tools pool from which the algorithm\n"
"will pick the ones used for painting."
_("Tools pool from which the algorithm\n"
"will pick the ones used for painting.")
)
self.tools_box.addWidget(self.tools_table_label)
@@ -61,25 +61,25 @@ class ToolPaint(FlatCAMTool, Gerber):
self.tools_box.addWidget(self.tools_table)
self.tools_table.setColumnCount(4)
self.tools_table.setHorizontalHeaderLabels(['#', 'Diameter', 'TT', ''])
self.tools_table.setHorizontalHeaderLabels(['#', _('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"
_("This is the Tool Number.\n"
"Painting will start with the tool with the biggest diameter,\n"
"continuing until there are no more tools.\n"
"Only tools that create painting geometry will still be present\n"
"in the resulting geometry. This is because with some tools\n"
"this function will not be able to create painting geometry."
"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"
"is the cut width into the material.")
_("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>"
_("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>"
@@ -89,7 +89,7 @@ class ToolPaint(FlatCAMTool, Gerber):
"as the cut width into material will be equal with the value in the Tool Diameter "
"column of this table.<BR>"
"Choosing the <B>V-Shape</B> Tool Type automatically will select the Operation Type "
"in the resulting geometry as Isolation.")
"in the resulting geometry as Isolation."))
self.empty_label = QtWidgets.QLabel('')
self.tools_box.addWidget(self.empty_label)
@@ -98,9 +98,9 @@ class ToolPaint(FlatCAMTool, Gerber):
hlay = QtWidgets.QHBoxLayout()
self.tools_box.addLayout(hlay)
self.addtool_entry_lbl = QtWidgets.QLabel('<b>Tool Dia:</b>')
self.addtool_entry_lbl = QtWidgets.QLabel('<b>%s:</b>' % _('Tool Dia'))
self.addtool_entry_lbl.setToolTip(
"Diameter for the new tool."
_("Diameter for the new tool.")
)
self.addtool_entry = FCEntry()
@@ -112,10 +112,10 @@ class ToolPaint(FlatCAMTool, Gerber):
grid2 = QtWidgets.QGridLayout()
self.tools_box.addLayout(grid2)
self.addtool_btn = QtWidgets.QPushButton('Add')
self.addtool_btn = QtWidgets.QPushButton(_('Add'))
self.addtool_btn.setToolTip(
"Add a new tool to the Tool Table\n"
"with the diameter specified above."
_("Add a new tool to the Tool Table\n"
"with the diameter specified above.")
)
# self.copytool_btn = QtWidgets.QPushButton('Copy')
@@ -124,10 +124,10 @@ class ToolPaint(FlatCAMTool, Gerber):
# "by first selecting a row in the Tool Table."
# )
self.deltool_btn = QtWidgets.QPushButton('Delete')
self.deltool_btn = QtWidgets.QPushButton(_('Delete'))
self.deltool_btn.setToolTip(
"Delete a selection of tools in the Tool Table\n"
"by first selecting a row(s) in the Tool Table."
_("Delete a selection of tools in the Tool Table\n"
"by first selecting a row(s) in the Tool Table.")
)
grid2.addWidget(self.addtool_btn, 0, 0)
@@ -141,9 +141,9 @@ class ToolPaint(FlatCAMTool, Gerber):
self.tools_box.addLayout(grid3)
# Overlap
ovlabel = QtWidgets.QLabel('Overlap:')
ovlabel = QtWidgets.QLabel(_('Overlap:'))
ovlabel.setToolTip(
"How much (fraction) of the tool width to overlap each tool pass.\n"
_("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"
@@ -151,30 +151,30 @@ class ToolPaint(FlatCAMTool, Gerber):
"not painted.\n"
"Lower values = faster processing, faster execution on PCB.\n"
"Higher values = slow processing and slow execution on CNC\n"
"due of too many paths."
"due of too many paths.")
)
grid3.addWidget(ovlabel, 1, 0)
self.paintoverlap_entry = FCEntry()
grid3.addWidget(self.paintoverlap_entry, 1, 1)
# Margin
marginlabel = QtWidgets.QLabel('Margin:')
marginlabel = QtWidgets.QLabel(_('Margin:'))
marginlabel.setToolTip(
"Distance by which to avoid\n"
_("Distance by which to avoid\n"
"the edges of the polygon to\n"
"be painted."
"be painted.")
)
grid3.addWidget(marginlabel, 2, 0)
self.paintmargin_entry = FCEntry()
grid3.addWidget(self.paintmargin_entry, 2, 1)
# Method
methodlabel = QtWidgets.QLabel('Method:')
methodlabel = QtWidgets.QLabel(_('Method:'))
methodlabel.setToolTip(
"Algorithm for non-copper clearing:<BR>"
_("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."
"<B>Line-based</B>: Parallel lines.")
)
grid3.addWidget(methodlabel, 3, 0)
self.paintmethod_combo = RadioSet([
@@ -185,45 +185,45 @@ class ToolPaint(FlatCAMTool, Gerber):
grid3.addWidget(self.paintmethod_combo, 3, 1)
# Connect lines
pathconnectlabel = QtWidgets.QLabel("Connect:")
pathconnectlabel = QtWidgets.QLabel(_("Connect:"))
pathconnectlabel.setToolTip(
"Draw lines between resulting\n"
"segments to minimize tool lifts."
_("Draw lines between resulting\n"
"segments to minimize tool lifts.")
)
grid3.addWidget(pathconnectlabel, 4, 0)
self.pathconnect_cb = FCCheckBox()
grid3.addWidget(self.pathconnect_cb, 4, 1)
contourlabel = QtWidgets.QLabel("Contour:")
contourlabel = QtWidgets.QLabel(_("Contour:"))
contourlabel.setToolTip(
"Cut around the perimeter of the polygon\n"
"to trim rough edges."
_("Cut around the perimeter of the polygon\n"
"to trim rough edges.")
)
grid3.addWidget(contourlabel, 5, 0)
self.paintcontour_cb = FCCheckBox()
grid3.addWidget(self.paintcontour_cb, 5, 1)
restlabel = QtWidgets.QLabel("Rest M.:")
restlabel = QtWidgets.QLabel(_("Rest M.:"))
restlabel.setToolTip(
"If checked, use 'rest machining'.\n"
_("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"
"could not be cleared by previous tool, until there is\n"
"no more copper to clear or there are no more tools.\n\n"
"If not checked, use the standard algorithm."
"If not checked, use the standard algorithm.")
)
grid3.addWidget(restlabel, 6, 0)
self.rest_cb = FCCheckBox()
grid3.addWidget(self.rest_cb, 6, 1)
# Polygon selection
selectlabel = QtWidgets.QLabel('Selection:')
selectlabel = QtWidgets.QLabel(_('Selection:'))
selectlabel.setToolTip(
"How to select the polygons to paint.<BR>"
_("How to select the polygons to paint.<BR>"
"Options:<BR>"
"- <B>Single</B>: left mouse click on the polygon to be painted.<BR>"
"- <B>All</B>: paint all polygons."
"- <B>All</B>: paint all polygons.")
)
grid3.addWidget(selectlabel, 7, 0)
# grid3 = QtWidgets.QGridLayout()
@@ -235,13 +235,13 @@ class ToolPaint(FlatCAMTool, Gerber):
grid3.addWidget(self.selectmethod_combo, 7, 1)
# GO Button
self.generate_paint_button = QtWidgets.QPushButton('Create Paint Geometry')
self.generate_paint_button = QtWidgets.QPushButton(_('Create Paint Geometry'))
self.generate_paint_button.setToolTip(
"After clicking here, click inside<BR>"
_("After clicking here, click inside<BR>"
"the polygon you wish to be painted if <B>Single</B> is selected.<BR>"
"If <B>All</B> is selected then the Paint will start after click.<BR>"
"A new Geometry object with the tool<BR>"
"paths will be created."
"paths will be created.")
)
self.tools_box.addWidget(self.generate_paint_button)
@@ -318,7 +318,7 @@ class ToolPaint(FlatCAMTool, Gerber):
FlatCAMTool.run(self)
self.set_tool_ui()
self.app.ui.notebook.setTabText(2, "Paint Tool")
self.app.ui.notebook.setTabText(2, _("Paint Tool"))
def on_radio_selection(self):
if self.selectmethod_combo.get_value() == 'single':
@@ -515,13 +515,13 @@ class ToolPaint(FlatCAMTool, Gerber):
try:
tool_dia = float(self.addtool_entry.get_value().replace(',', '.'))
except ValueError:
self.app.inform.emit("[ERROR_NOTCL]Wrong value format entered, "
"use a number.")
self.app.inform.emit(_("[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(_("[WARNING_NOTCL] Please enter a tool diameter to add, in Float format."))
return
# construct a list of all 'tooluid' in the self.tools
@@ -545,12 +545,12 @@ class ToolPaint(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(_("[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(_("[success] New tool added to Tool Table."))
self.paint_tools.update({
int(self.tooluid): {
'tooldia': float('%.4f' % tool_dia),
@@ -585,15 +585,15 @@ class ToolPaint(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, "
"use a number.")
self.app.inform.emit(_("[ERROR_NOTCL]Wrong value format entered, "
"use a number."))
return
tooluid = int(self.tools_table.item(row, 3).text())
# identify the tool that was edited and get it's tooluid
if new_tool_dia not in tool_dias:
self.paint_tools[tooluid]['tooldia'] = new_tool_dia
self.app.inform.emit("[success] Tool from Tool Table was edited.")
self.app.inform.emit(_("[success] Tool from Tool Table was edited."))
self.build_ui()
return
else:
@@ -604,7 +604,7 @@ class ToolPaint(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(_("[WARNING_NOTCL] Edit cancelled. New diameter value is already in the Tool Table."))
self.build_ui()
# def on_tool_copy(self, all=None):
@@ -701,18 +701,18 @@ class ToolPaint(FlatCAMTool, Gerber):
self.paint_tools.pop(t, None)
except AttributeError:
self.app.inform.emit("[WARNING_NOTCL]Delete failed. Select a tool to delete.")
self.app.inform.emit(_("[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(_("[success] Tool(s) deleted from Tool Table."))
self.build_ui()
def on_paint_button_click(self):
self.app.report_usage("geometry_on_paint_button")
self.app.report_usage(_("geometry_on_paint_button"))
self.app.inform.emit("[WARNING_NOTCL]Click inside the desired polygon.")
self.app.inform.emit(_("[WARNING_NOTCL]Click inside the desired polygon."))
try:
overlap = float(self.paintoverlap_entry.get_value())
except ValueError:
@@ -720,8 +720,8 @@ class ToolPaint(FlatCAMTool, Gerber):
try:
overlap = float(self.paintoverlap_entry.get_value().replace(',', '.'))
except ValueError:
self.app.inform.emit("[ERROR_NOTCL]Wrong value format entered, "
"use a number.")
self.app.inform.emit(_("[ERROR_NOTCL]Wrong value format entered, "
"use a number."))
return
connect = self.pathconnect_cb.get_value()
@@ -734,17 +734,17 @@ class ToolPaint(FlatCAMTool, Gerber):
try:
self.paint_obj = self.app.collection.get_by_name(str(self.obj_name))
except:
self.app.inform.emit("[ERROR_NOTCL]Could not retrieve object: %s" % self.obj_name)
self.app.inform.emit(_("[ERROR_NOTCL]Could not retrieve object: %s") % self.obj_name)
return
if self.paint_obj is None:
self.app.inform.emit("[ERROR_NOTCL]Object not found: %s" % self.paint_obj)
self.app.inform.emit(_("[ERROR_NOTCL]Object not found: %s") % self.paint_obj)
return
# test if the Geometry Object is multigeo and return Fail if True because
# for now Paint don't work on MultiGeo
if self.paint_obj.multigeo is True:
self.app.inform.emit("[ERROR_NOTCL] Can't do Paint on MultiGeo geometries ...")
self.app.inform.emit(_("[ERROR_NOTCL] Can't do Paint on MultiGeo geometries ..."))
return 'Fail'
o_name = '%s_multitool_paint' % (self.obj_name)
@@ -757,7 +757,7 @@ class ToolPaint(FlatCAMTool, Gerber):
contour=contour)
if select_method == "single":
self.app.inform.emit("[WARNING_NOTCL]Click inside the desired polygon.")
self.app.inform.emit(_("[WARNING_NOTCL]Click inside the desired polygon."))
# use the first tool in the tool table; get the diameter
tooldia = float('%.4f' % float(self.tools_table.item(0, 1).text()))
@@ -766,7 +766,7 @@ class ToolPaint(FlatCAMTool, Gerber):
def doit(event):
# do paint single only for left mouse clicks
if event.button == 1:
self.app.inform.emit("Painting polygon...")
self.app.inform.emit(_("Painting polygon..."))
self.app.plotcanvas.vis_disconnect('mouse_press', doit)
pos = self.app.plotcanvas.vispy_canvas.translate_coords(event.pos)
self.paint_poly(self.paint_obj,
@@ -811,17 +811,17 @@ class ToolPaint(FlatCAMTool, Gerber):
try:
paint_margin = float(self.paintmargin_entry.get_value().replace(',', '.'))
except ValueError:
self.app.inform.emit("[ERROR_NOTCL]Wrong value format entered, "
"use a number.")
self.app.inform.emit(_("[ERROR_NOTCL]Wrong value format entered, "
"use a number."))
return
# No polygon?
if poly is None:
self.app.log.warning('No polygon found.')
self.app.inform.emit('[WARNING] No polygon found.')
self.app.inform.emit(_('[WARNING] No polygon found.'))
return
proc = self.app.proc_container.new("Painting polygon.")
proc = self.app.proc_container.new(_("Painting polygon."))
name = outname if outname else self.obj_name + "_paint"
@@ -863,7 +863,7 @@ class ToolPaint(FlatCAMTool, Gerber):
geo_obj.solid_geometry += list(cp.get_objects())
return cp
else:
self.app.inform.emit('[ERROR_NOTCL] Geometry could not be painted completely')
self.app.inform.emit(_('[ERROR_NOTCL] Geometry could not be painted completely'))
return None
geo_obj.solid_geometry = []
@@ -889,8 +889,8 @@ class ToolPaint(FlatCAMTool, Gerber):
except Exception as e:
log.debug("Could not Paint the polygons. %s" % str(e))
self.app.inform.emit(
"[ERROR] Could not do Paint. Try a different combination of parameters. "
"Or a different strategy of paint\n%s" % str(e))
_("[ERROR] Could not do Paint. Try a different combination of parameters. "
"Or a different strategy of paint\n%s") % str(e))
return
if cp is not None:
@@ -931,13 +931,13 @@ class ToolPaint(FlatCAMTool, Gerber):
app_obj.new_object("geometry", name, gen_paintarea)
except Exception as e:
proc.done()
self.app.inform.emit('[ERROR_NOTCL] PaintTool.paint_poly() --> %s' % str(e))
self.app.inform.emit(_('[ERROR_NOTCL] PaintTool.paint_poly() --> %s') % str(e))
return
proc.done()
# focus on Selected Tab
self.app.ui.notebook.setCurrentWidget(self.app.ui.selected_tab)
self.app.inform.emit("Polygon Paint started ...")
self.app.inform.emit(_("Polygon Paint started ..."))
# Promise object with the new name
self.app.collection.promise(name)
@@ -966,11 +966,11 @@ class ToolPaint(FlatCAMTool, Gerber):
try:
paint_margin = float(self.paintmargin_entry.get_value().replace(',', '.'))
except ValueError:
self.app.inform.emit("[ERROR_NOTCL]Wrong value format entered, "
"use a number.")
self.app.inform.emit(_("[ERROR_NOTCL]Wrong value format entered, "
"use a number."))
return
proc = self.app.proc_container.new("Painting polygon.")
proc = self.app.proc_container.new(_("Painting polygon..."))
name = outname if outname else self.obj_name + "_paint"
over = overlap
conn = connect
@@ -1085,8 +1085,8 @@ class ToolPaint(FlatCAMTool, Gerber):
except Exception as e:
log.debug("Could not Paint the polygons. %s" % str(e))
self.app.inform.emit(
"[ERROR] Could not do Paint All. Try a different combination of parameters. "
"Or a different Method of paint\n%s" % str(e))
_("[ERROR] Could not do Paint All. Try a different combination of parameters. "
"Or a different Method of paint\n%s") % str(e))
return
# add the solid_geometry to the current too in self.paint_tools dictionary and then reset the
@@ -1109,16 +1109,16 @@ class ToolPaint(FlatCAMTool, Gerber):
if geo_obj.tools[tooluid]['solid_geometry']:
has_solid_geo += 1
if has_solid_geo == 0:
self.app.inform.emit("[ERROR] There is no Painting Geometry in the file.\n"
self.app.inform.emit(_("[ERROR] There is no Painting Geometry in the file.\n"
"Usually it means that the tool diameter is too big for the painted geometry.\n"
"Change the painting parameters and try again.")
"Change the painting parameters and try again."))
return
# Experimental...
# print("Indexing...", end=' ')
# geo_obj.make_index()
self.app.inform.emit("[success] Paint All Done.")
self.app.inform.emit(_("[success] Paint All Done."))
# Initializes the new geometry object
def gen_paintarea_rest_machining(geo_obj, app_obj):
@@ -1174,8 +1174,8 @@ class ToolPaint(FlatCAMTool, Gerber):
except Exception as e:
log.debug("Could not Paint the polygons. %s" % str(e))
self.app.inform.emit(
"[ERROR] Could not do Paint All. Try a different combination of parameters. "
"Or a different Method of paint\n%s" % str(e))
_("[ERROR] Could not do Paint All. Try a different combination of parameters. "
"Or a different Method of paint\n%s") % str(e))
return
# find the tooluid associated with the current tool_dia so we know where to add the tool solid_geometry
@@ -1204,16 +1204,16 @@ class ToolPaint(FlatCAMTool, Gerber):
if geo_obj.tools[tooluid]['solid_geometry']:
has_solid_geo += 1
if has_solid_geo == 0:
self.app.inform.emit("[ERROR_NOTCL] There is no Painting Geometry in the file.\n"
self.app.inform.emit(_("[ERROR_NOTCL] There is no Painting Geometry in the file.\n"
"Usually it means that the tool diameter is too big for the painted geometry.\n"
"Change the painting parameters and try again.")
"Change the painting parameters and try again."))
return
# Experimental...
# print("Indexing...", end=' ')
# geo_obj.make_index()
self.app.inform.emit("[success] Paint All with Rest-Machining Done.")
self.app.inform.emit(_("[success] Paint All with Rest-Machining done."))
def job_thread(app_obj):
try:
@@ -1229,7 +1229,7 @@ class ToolPaint(FlatCAMTool, Gerber):
# focus on Selected Tab
self.app.ui.notebook.setCurrentWidget(self.app.ui.selected_tab)
self.app.inform.emit("Polygon Paint started ...")
self.app.inform.emit(_("Polygon Paint started ..."))
# Promise object with the new name
self.app.collection.promise(name)