- 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('ToolPanelize')
def _tr(text):
try:
return _(text)
except:
return text
class Panelize(FlatCAMTool):
toolName = _("Panelize PCB")
toolName = _tr("Panelize PCB")
def __init__(self, app):
super(Panelize, self).__init__(self)
@@ -41,9 +48,9 @@ class Panelize(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(_("Object Type:"))
self.type_obj_combo_label = QtWidgets.QLabel(_tr("Object Type:"))
self.type_obj_combo_label.setToolTip(
_("Specify the type of object to be panelized\n"
_tr("Specify the type of object to be panelized\n"
"It can be of type: Gerber, Excellon or Geometry.\n"
"The selection here decide the type of objects that will be\n"
"in the Object combobox.")
@@ -56,9 +63,9 @@ class Panelize(FlatCAMTool):
self.object_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
self.object_combo.setCurrentIndex(1)
self.object_label = QtWidgets.QLabel(_("Object:"))
self.object_label = QtWidgets.QLabel(_tr("Object:"))
self.object_label.setToolTip(
_("Object to be panelized. This means that it will\n"
_tr("Object to be panelized. This means that it will\n"
"be duplicated in an array of rows and columns.")
)
form_layout.addRow(self.object_label, self.object_combo)
@@ -74,9 +81,9 @@ class Panelize(FlatCAMTool):
self.type_box_combo.setItemIcon(0, QtGui.QIcon("share/flatcam_icon16.png"))
self.type_box_combo.setItemIcon(2, QtGui.QIcon("share/geometry16.png"))
self.type_box_combo_label = QtWidgets.QLabel(_("Box Type:"))
self.type_box_combo_label = QtWidgets.QLabel(_tr("Box Type:"))
self.type_box_combo_label.setToolTip(
_("Specify the type of object to be used as an container for\n"
_tr("Specify the type of object to be used as an container for\n"
"panelization. It can be: Gerber or Geometry type.\n"
"The selection here decide the type of objects that will be\n"
"in the Box Object combobox.")
@@ -89,53 +96,53 @@ class Panelize(FlatCAMTool):
self.box_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
self.box_combo.setCurrentIndex(1)
self.box_combo_label = QtWidgets.QLabel(_("Box Object:"))
self.box_combo_label = QtWidgets.QLabel(_tr("Box Object:"))
self.box_combo_label.setToolTip(
_("The actual object that is used a container for the\n "
_tr("The actual object that is used a container for the\n "
"selected object that is to be panelized.")
)
form_layout.addRow(self.box_combo_label, self.box_combo)
## Spacing Columns
self.spacing_columns = FCEntry()
self.spacing_columns_label = QtWidgets.QLabel(_("Spacing cols:"))
self.spacing_columns_label = QtWidgets.QLabel(_tr("Spacing cols:"))
self.spacing_columns_label.setToolTip(
_("Spacing between columns of the desired panel.\n"
_tr("Spacing between columns of the desired panel.\n"
"In current units.")
)
form_layout.addRow(self.spacing_columns_label, self.spacing_columns)
## Spacing Rows
self.spacing_rows = FCEntry()
self.spacing_rows_label = QtWidgets.QLabel(_("Spacing rows:"))
self.spacing_rows_label = QtWidgets.QLabel(_tr("Spacing rows:"))
self.spacing_rows_label.setToolTip(
_("Spacing between rows of the desired panel.\n"
_tr("Spacing between rows of the desired panel.\n"
"In current units.")
)
form_layout.addRow(self.spacing_rows_label, self.spacing_rows)
## Columns
self.columns = FCEntry()
self.columns_label = QtWidgets.QLabel(_("Columns:"))
self.columns_label = QtWidgets.QLabel(_tr("Columns:"))
self.columns_label.setToolTip(
_("Number of columns of the desired panel")
_tr("Number of columns of the desired panel")
)
form_layout.addRow(self.columns_label, self.columns)
## Rows
self.rows = FCEntry()
self.rows_label = QtWidgets.QLabel(_("Rows:"))
self.rows_label = QtWidgets.QLabel(_tr("Rows:"))
self.rows_label.setToolTip(
_("Number of rows of the desired panel")
_tr("Number of rows of the desired panel")
)
form_layout.addRow(self.rows_label, self.rows)
## Type of resulting Panel object
self.panel_type_radio = RadioSet([{'label': 'Gerber', 'value': 'gerber'},
{'label': 'Geometry', 'value': 'geometry'}])
self.panel_type_label = QtWidgets.QLabel(_("Panel Type:"))
self.panel_type_label = QtWidgets.QLabel(_tr("Panel Type:"))
self.panel_type_label.setToolTip(
_("Choose the type of object for the panel object:\n"
_tr("Choose the type of object for the panel object:\n"
"- Geometry\n"
"- Gerber")
)
@@ -143,9 +150,9 @@ class Panelize(FlatCAMTool):
form_layout.addRow(self.panel_type_radio)
## Constrains
self.constrain_cb = FCCheckBox(_("Constrain panel within:"))
self.constrain_cb = FCCheckBox(_tr("Constrain panel within:"))
self.constrain_cb.setToolTip(
_("Area define by DX and DY within to constrain the panel.\n"
_tr("Area define by DX and DY within to constrain the panel.\n"
"DX and DY values are in current units.\n"
"Regardless of how many columns and rows are desired,\n"
"the final panel will have as many columns and rows as\n"
@@ -154,17 +161,17 @@ class Panelize(FlatCAMTool):
form_layout.addRow(self.constrain_cb)
self.x_width_entry = FCEntry()
self.x_width_lbl = QtWidgets.QLabel(_("Width (DX):"))
self.x_width_lbl = QtWidgets.QLabel(_tr("Width (DX):"))
self.x_width_lbl.setToolTip(
_("The width (DX) within which the panel must fit.\n"
_tr("The width (DX) within which the panel must fit.\n"
"In current units.")
)
form_layout.addRow(self.x_width_lbl, self.x_width_entry)
self.y_height_entry = FCEntry()
self.y_height_lbl = QtWidgets.QLabel(_("Height (DY):"))
self.y_height_lbl = QtWidgets.QLabel(_tr("Height (DY):"))
self.y_height_lbl.setToolTip(
_("The height (DY)within which the panel must fit.\n"
_tr("The height (DY)within which the panel must fit.\n"
"In current units.")
)
form_layout.addRow(self.y_height_lbl, self.y_height_entry)
@@ -177,9 +184,9 @@ class Panelize(FlatCAMTool):
self.layout.addLayout(hlay_2)
hlay_2.addStretch()
self.panelize_object_button = QtWidgets.QPushButton(_("Panelize Object"))
self.panelize_object_button = QtWidgets.QPushButton(_tr("Panelize Object"))
self.panelize_object_button.setToolTip(
_("Panelize the specified object around the specified box.\n"
_tr("Panelize the specified object around the specified box.\n"
"In other words it creates multiple copies of the source object,\n"
"arranged in a 2D array of rows and columns.")
)
@@ -275,13 +282,13 @@ class Panelize(FlatCAMTool):
try:
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(_tr("[ERROR_NOTCL]Could not retrieve object: %s") % name)
return "Could not retrieve object: %s" % name
panel_obj = obj
if panel_obj is None:
self.app.inform.emit(_("[ERROR_NOTCL]Object not found: %s") % panel_obj)
self.app.inform.emit(_tr("[ERROR_NOTCL]Object not found: %s") % panel_obj)
return "Object not found: %s" % panel_obj
boxname = self.box_combo.currentText()
@@ -289,11 +296,11 @@ class Panelize(FlatCAMTool):
try:
box = self.app.collection.get_by_name(boxname)
except:
self.app.inform.emit(_("[ERROR_NOTCL]Could not retrieve object: %s") % boxname)
self.app.inform.emit(_tr("[ERROR_NOTCL]Could not retrieve object: %s") % boxname)
return "Could not retrieve object: %s" % boxname
if box is None:
self.app.inform.emit(_("[WARNING]No object Box. Using instead %s") % panel_obj)
self.app.inform.emit(_tr("[WARNING]No object Box. Using instead %s") % panel_obj)
box = panel_obj
self.outname = name + '_panelized'
@@ -305,7 +312,7 @@ class Panelize(FlatCAMTool):
try:
spacing_columns = float(self.spacing_columns.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
spacing_columns = spacing_columns if spacing_columns is not None else 0
@@ -317,7 +324,7 @@ class Panelize(FlatCAMTool):
try:
spacing_rows = float(self.spacing_rows.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
spacing_rows = spacing_rows if spacing_rows is not None else 0
@@ -330,7 +337,7 @@ class Panelize(FlatCAMTool):
rows = float(self.rows.get_value().replace(',', '.'))
rows = int(rows)
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
rows = rows if rows is not None else 1
@@ -343,7 +350,7 @@ class Panelize(FlatCAMTool):
columns = float(self.columns.get_value().replace(',', '.'))
columns = int(columns)
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
columns = columns if columns is not None else 1
@@ -355,7 +362,7 @@ class Panelize(FlatCAMTool):
try:
constrain_dx = float(self.x_width_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
@@ -366,7 +373,7 @@ class Panelize(FlatCAMTool):
try:
constrain_dy = float(self.y_height_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
@@ -374,7 +381,7 @@ class Panelize(FlatCAMTool):
if 0 in {columns, rows}:
self.app.inform.emit(_("[ERROR_NOTCL]Columns or Rows are zero value. Change them to a positive integer."))
self.app.inform.emit(_tr("[ERROR_NOTCL]Columns or Rows are zero value. Change them to a positive integer."))
return "Columns or Rows are zero value. Change them to a positive integer."
xmin, ymin, xmax, ymax = box.bounds()
@@ -478,7 +485,7 @@ class Panelize(FlatCAMTool):
def panelize_2():
if panel_obj is not None:
self.app.inform.emit(_("Generating panel ... Please wait."))
self.app.inform.emit(_tr("Generating panel ... Please wait."))
self.app.progress.emit(0)
@@ -581,18 +588,18 @@ class Panelize(FlatCAMTool):
plot=True, autoselected=True)
if self.constrain_flag is False:
self.app.inform.emit(_("[success]Panel done..."))
self.app.inform.emit(_tr("[success]Panel done..."))
else:
self.constrain_flag = False
self.app.inform.emit(_("[WARNING] Too big for the constrain area. Final panel has %s columns and %s rows") %
self.app.inform.emit(_tr("[WARNING] Too big for the constrain area. Final panel has %s columns and %s rows") %
(columns, rows))
proc = self.app.proc_container.new(_("Generating panel ... Please wait."))
proc = self.app.proc_container.new(_tr("Generating panel ... Please wait."))
def job_thread(app_obj):
try:
panelize_2()
self.app.inform.emit(_("[success]Panel created successfully."))
self.app.inform.emit(_tr("[success]Panel created successfully."))
except Exception as e:
proc.done()
log.debug(str(e))