diff --git a/FlatCAMApp.py b/FlatCAMApp.py index 51d0a918..fb718be4 100644 --- a/FlatCAMApp.py +++ b/FlatCAMApp.py @@ -15,7 +15,6 @@ import random import logging import simplejson as json import lzma -import gettext import re import os @@ -45,7 +44,6 @@ from PlotCanvas import * from FlatCAMGUI import * from FlatCAMCommon import LoudDict from FlatCAMPostProc import load_postprocessors -import FlatCAMTranslation as fcTranslate from FlatCAMEditor import FlatCAMGeoEditor, FlatCAMExcEditor from FlatCAMProcess import * @@ -61,10 +59,22 @@ import tclCommands # from ParseFont import * +from gettext import * +import FlatCAMTranslation as fcTranslate +fcTranslate.apply_language('FlatCAMApp') + + +def _tr(text): + try: + return _(text) + except: + return text ######################################## ## App ## ######################################## + + class App(QtCore.QObject): """ The main application class. The constructor starts the GUI. @@ -847,12 +857,12 @@ class App(QtCore.QObject): ret_val = fcTranslate.apply_language('FlatCAMApp') if ret_val == "no language": - self.inform.emit("[ERROR] Could not find the Language files. The App strings are missing.") + self.inform.emit(_tr("[ERROR] Could not find the Language files. The App strings are missing.")) log.debug("Could not find the Language files. The App strings are missing.") else: # make the current language the current selection on the language combobox self.ui.general_defaults_form.general_app_group.language_cb.setCurrentText(ret_val) - log.debug("App.__init__() --> Applied %s language." % str(ret_val).capitalize()) + log.debug("App.__init__tr() --> Applied %s language." % str(ret_val).capitalize()) ################################### @@ -1609,6 +1619,9 @@ class App(QtCore.QObject): # Variable to store the status of the code editor self.toggle_codeeditor = False + # Variable to be used for situations when we don't want the LMB click on canvas to auto open the Project Tab + self.click_noproject = False + self.cursor = None # Variable to store the GCODE that was edited @@ -1666,7 +1679,7 @@ class App(QtCore.QObject): project_name = str(argument) if project_name == "": - self.inform.emit("Open cancelled.") + self.inform.emit(_tr("Open cancelled.")) else: # self.open_project(project_name) run_from_arg = True @@ -1680,7 +1693,7 @@ class App(QtCore.QObject): file_name = str(argument) if file_name == "": - self.inform.emit("Open Config file failed.") + self.inform.emit(_tr("Open Config file failed.")) else: # run_from_arg = True # self.worker_task.emit({'fcn': self.open_config_file, @@ -1861,7 +1874,7 @@ class App(QtCore.QObject): if isinstance(edited_object, FlatCAMGeometry): # for now, if the Geometry is MultiGeo do not allow the editing if edited_object.multigeo is True: - self.inform.emit("[WARNING_NOTCL]Editing a MultiGeo Geometry is not possible for the moment.") + self.inform.emit(_tr("[WARNING_NOTCL] Editing a MultiGeo Geometry is not possible for the moment.")) return # store the Geometry Editor Toolbar visibility before entering in the Editor @@ -1882,7 +1895,7 @@ class App(QtCore.QObject): # set call source to the Editor we go into self.call_source = 'exc_editor' else: - self.inform.emit("[WARNING_NOTCL]Select a Geometry or Excellon Object to edit.") + self.inform.emit(_tr("[WARNING_NOTCL]Select a Geometry or Excellon Object to edit.")) return # make sure that we can't select another object while in Editor Mode: @@ -1893,7 +1906,7 @@ class App(QtCore.QObject): self.ui.plot_tab_area.setTabText(0, "EDITOR Area") self.ui.plot_tab_area.protectTab(0) - self.inform.emit("[WARNING_NOTCL]Editor is activated ...") + self.inform.emit(_tr("[WARNING_NOTCL]Editor is activated ...")) self.should_we_save = True @@ -1926,7 +1939,7 @@ class App(QtCore.QObject): edited_obj.options['xmax'] = xmax edited_obj.options['ymax'] = ymax except AttributeError: - self.inform.emit("[WARNING] Object empty after edit.") + self.inform.emit(_tr("[WARNING] Object empty after edit.")) elif isinstance(edited_obj, FlatCAMExcellon): obj_type = "Excellon" @@ -1935,7 +1948,7 @@ class App(QtCore.QObject): self.exc_editor.deactivate() else: - self.inform.emit("[WARNING_NOTCL]Select a Geometry or Excellon Object to update.") + self.inform.emit(_tr("[WARNING_NOTCL]Select a Geometry or Excellon Object to update.")) return # if notebook is hidden we show it @@ -1948,7 +1961,7 @@ class App(QtCore.QObject): edited_obj.plot() self.ui.plot_tab_area.setTabText(0, "Plot Area") self.ui.plot_tab_area.protectTab(0) - self.inform.emit("[selected] %s is updated, returning to App..." % obj_type) + self.inform.emit(_tr("[selected] %s is updated, returning to App...") % obj_type) # reset the Object UI to original settings # edited_obj.set_ui(edited_obj.ui_type()) @@ -2271,7 +2284,7 @@ class App(QtCore.QObject): f.close() except IOError: self.log.error("Could not load defaults file.") - self.inform.emit("[ERROR] Could not load defaults file.") + self.inform.emit(_tr("[ERROR] Could not load defaults file.")) # in case the defaults file can't be loaded, show all toolbars self.defaults["global_toolbar_view"] = 255 return @@ -2283,7 +2296,7 @@ class App(QtCore.QObject): self.defaults["global_toolbar_view"] = 255 e = sys.exc_info()[0] App.log.error(str(e)) - self.inform.emit("[ERROR] Failed to parse defaults file.") + self.inform.emit(_tr("[ERROR] Failed to parse defaults file.")) return self.defaults.update(defaults) log.debug("FlatCAM defaults loaded from: %s" % filename) @@ -2312,7 +2325,7 @@ class App(QtCore.QObject): filename = str(filename) if filename == "": - self.inform.emit("[WARNING_NOTCL]FlatCAM preferences import cancelled.") + self.inform.emit(_tr("[WARNING_NOTCL]FlatCAM preferences import cancelled.")) else: try: f = open(filename) @@ -2320,7 +2333,7 @@ class App(QtCore.QObject): f.close() except IOError: self.log.error("Could not load defaults file.") - self.inform.emit("[ERROR_NOTCL] Could not load defaults file.") + self.inform.emit(_tr("[ERROR_NOTCL] Could not load defaults file.")) return try: @@ -2328,10 +2341,10 @@ class App(QtCore.QObject): except: e = sys.exc_info()[0] App.log.error(str(e)) - self.inform.emit("[ERROR_NOTCL] Failed to parse defaults file.") + self.inform.emit(_tr("[ERROR_NOTCL] Failed to parse defaults file.")) return self.defaults.update(defaults_from_file) - self.inform.emit("[success]Imported Defaults from %s" %filename) + self.inform.emit(_tr("[success]Imported Defaults from %s") %filename) def on_export_preferences(self): @@ -2351,7 +2364,7 @@ class App(QtCore.QObject): defaults_from_file = {} if filename == "": - self.inform.emit("[WARNING_NOTCL]FlatCAM preferences export cancelled.") + self.inform.emit(_tr("[WARNING_NOTCL]FlatCAM preferences export cancelled.")) return else: try: @@ -2367,7 +2380,7 @@ class App(QtCore.QObject): e = sys.exc_info()[0] App.log.error("Could not load defaults file.") App.log.error(str(e)) - self.inform.emit("[ERROR_NOTCL]Could not load defaults file.") + self.inform.emit(_tr("[ERROR_NOTCL]Could not load defaults file.")) return try: @@ -2386,7 +2399,7 @@ class App(QtCore.QObject): json.dump(defaults_from_file, f) f.close() except: - self.inform.emit("[ERROR_NOTCL] Failed to write defaults to file.") + self.inform.emit(_tr("[ERROR_NOTCL] Failed to write defaults to file.")) return self.file_saved.emit("preferences", filename) @@ -2438,7 +2451,7 @@ class App(QtCore.QObject): f = open(self.data_path + '/recent.json', 'w') except IOError: App.log.error("Failed to open recent items file for writing.") - self.inform.emit('[ERROR_NOTCL]Failed to open recent files file for writing.') + self.inform.emit(_tr('[ERROR_NOTCL]Failed to open recent files file for writing.')) return #try: @@ -2523,8 +2536,8 @@ class App(QtCore.QObject): try: return_value = initialize(obj, self) except Exception as e: - msg = "[ERROR_NOTCL] An internal error has ocurred. See shell.\n" - msg += "Object (%s) failed because: %s \n\n" % (kind, str(e)) + msg = _tr("[ERROR_NOTCL] An internal error has ocurred. See shell.\n") + msg += _tr("Object (%s) failed because: %s \n\n") % (kind, str(e)) msg += traceback.format_exc() self.inform.emit(msg) @@ -2544,7 +2557,7 @@ class App(QtCore.QObject): # Check units and convert if necessary # This condition CAN be true because initialize() can change obj.units if self.options["units"].upper() != obj.units.upper(): - self.inform.emit("Converting units to " + self.options["units"] + ".") + self.inform.emit(_tr("Converting units to ") + self.options["units"] + ".") obj.convert_units(self.options["units"]) t3 = time.time() self.log.debug("%f seconds converting units." % (t3 - t2)) @@ -2602,16 +2615,16 @@ class App(QtCore.QObject): # self.inform.emit('[selected] %s created & selected: %s' % # (str(obj.kind).capitalize(), str(obj.options['name']))) if obj.kind == 'gerber': - self.inform.emit('[selected]%s created/selected: %s' % + self.inform.emit('_tr([selected]%s created/selected: %s' % (obj.kind.capitalize(), 'green', str(obj.options['name']))) elif obj.kind == 'excellon': - self.inform.emit('[selected]%s created/selected: %s' % + self.inform.emit(_tr('[selected]%s created/selected: %s') % (obj.kind.capitalize(), 'brown', str(obj.options['name']))) elif obj.kind == 'cncjob': - self.inform.emit('[selected]%s created/selected: %s' % + self.inform.emit(_tr('[selected]%s created/selected: %s') % (obj.kind.capitalize(), 'blue', str(obj.options['name']))) elif obj.kind == 'geometry': - self.inform.emit('[selected]%s created/selected: %s' % + self.inform.emit(_tr('[selected]%s created/selected: %s') % (obj.kind.capitalize(), 'red', str(obj.options['name']))) # update the SHELL auto-completer model with the name of the new object @@ -2794,7 +2807,7 @@ class App(QtCore.QObject): e = sys.exc_info()[0] App.log.error("Could not load defaults file.") App.log.error(str(e)) - self.inform.emit("[ERROR_NOTCL] Could not load defaults file.") + self.inform.emit(_tr("[ERROR_NOTCL] Could not load defaults file.")) return try: @@ -2803,7 +2816,7 @@ class App(QtCore.QObject): e = sys.exc_info()[0] App.log.error("Failed to parse defaults file.") App.log.error(str(e)) - self.inform.emit("[ERROR_NOTCL] Failed to parse defaults file.") + self.inform.emit(_tr("[ERROR_NOTCL] Failed to parse defaults file.")) return # Update options @@ -2817,7 +2830,7 @@ class App(QtCore.QObject): json.dump(defaults, f, default=to_dict, indent=2, sort_keys=True) f.close() except: - self.inform.emit("[ERROR_NOTCL] Failed to write defaults to file.") + self.inform.emit(_tr("[ERROR_NOTCL] Failed to write defaults to file.")) return # Save the toolbar view @@ -2849,7 +2862,7 @@ class App(QtCore.QObject): self.defaults["global_toolbar_view"] = tb_status if not silent: - self.inform.emit("[success]Defaults saved.") + self.inform.emit(_tr("[success]Defaults saved.")) def save_factory_defaults(self, silent=False): """ @@ -2870,7 +2883,7 @@ class App(QtCore.QObject): e = sys.exc_info()[0] App.log.error("Could not load factory defaults file.") App.log.error(str(e)) - self.inform.emit("[ERROR_NOTCL] Could not load factory defaults file.") + self.inform.emit(_tr("[ERROR_NOTCL] Could not load factory defaults file.")) return try: @@ -2879,7 +2892,7 @@ class App(QtCore.QObject): e = sys.exc_info()[0] App.log.error("Failed to parse factory defaults file.") App.log.error(str(e)) - self.inform.emit("[ERROR_NOTCL] Failed to parse factory defaults file.") + self.inform.emit(_tr("[ERROR_NOTCL] Failed to parse factory defaults file.")) return # Update options @@ -2893,20 +2906,20 @@ class App(QtCore.QObject): json.dump(factory_defaults, f_f_def_s, default=to_dict, indent=2, sort_keys=True) f_f_def_s.close() except: - self.inform.emit("[ERROR_NOTCL] Failed to write factory defaults to file.") + self.inform.emit(_tr("[ERROR_NOTCL] Failed to write factory defaults to file.")) return if silent is False: - self.inform.emit("Factory defaults saved.") + self.inform.emit(_tr("Factory defaults saved.")) def final_save(self): if self.should_we_save and self.collection.get_list(): msgbox = QtWidgets.QMessageBox() # msgbox.setText("Save changes ...") - msgbox.setText("There are files/objects modified in FlatCAM. " + msgbox.setText(_tr("There are files/objects modified in FlatCAM. " "\n" - "Do you want to Save the project?") - msgbox.setWindowTitle("Save changes") + "Do you want to Save the project?")) + msgbox.setWindowTitle(_tr("Save changes")) msgbox.setWindowIcon(QtGui.QIcon('share/save_as.png')) msgbox.setStandardButtons(QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No | QtWidgets.QMessageBox.Cancel) @@ -2955,12 +2968,12 @@ class App(QtCore.QObject): # if len(set(geo_type_list)) == 1 means that all list elements are the same if len(set(geo_type_list)) != 1: - self.inform.emit("[ERROR] Failed join. The Geometry objects are of different types.\n" + self.inform.emit(_tr("[ERROR] Failed join. The Geometry objects are of different types.\n" "At least one is MultiGeo type and the other is SingleGeo type. A possibility is to " "convert from one to another and retry joining \n" "but in the case of converting from MultiGeo to SingleGeo, informations may be lost and " "the result may not be what was expected. \n" - "Check the generated GCODE.") + "Check the generated GCODE.")) return # if at least one True object is in the list then due of the previous check, all list elements are True objects @@ -2996,7 +3009,7 @@ class App(QtCore.QObject): for obj in objs: if not isinstance(obj, FlatCAMExcellon): - self.inform.emit("[ERROR_NOTCL]Failed. Excellon joining works only on Excellon objects.") + self.inform.emit(_tr("[ERROR_NOTCL]Failed. Excellon joining works only on Excellon objects.")) return def initialize(obj, app): @@ -3018,7 +3031,7 @@ class App(QtCore.QObject): for obj in objs: if not isinstance(obj, FlatCAMGerber): - self.inform.emit("[ERROR_NOTCL]Failed. Gerber joining works only on Gerber objects.") + self.inform.emit(_tr("[ERROR_NOTCL]Failed. Gerber joining works only on Gerber objects.")) return def initialize(obj, app): @@ -3033,11 +3046,11 @@ class App(QtCore.QObject): obj = self.collection.get_active() if obj is None: - self.inform.emit("[ERROR_NOTCL]Failed. Select a Geometry Object and try again.") + self.inform.emit(_tr("[ERROR_NOTCL]Failed. Select a Geometry Object and try again.")) return if not isinstance(obj, FlatCAMGeometry): - self.inform.emit("[ERROR_NOTCL]Expected a FlatCAMGeometry, got %s" % type(obj)) + self.inform.emit(_tr("[ERROR_NOTCL]Expected a FlatCAMGeometry, got %s") % type(obj)) return obj.multigeo = True @@ -3050,7 +3063,7 @@ class App(QtCore.QObject): self.should_we_save = True - self.inform.emit("[success] A Geometry object was converted to MultiGeo type.") + self.inform.emit(_tr("[success] A Geometry object was converted to MultiGeo type.")) def on_convert_multigeo_to_singlegeo(self): self.report_usage("on_convert_multigeo_to_singlegeo()") @@ -3058,11 +3071,11 @@ class App(QtCore.QObject): obj = self.collection.get_active() if obj is None: - self.inform.emit("[ERROR_NOTCL]Failed. Select a Geometry Object and try again.") + self.inform.emit(_tr("[ERROR_NOTCL]Failed. Select a Geometry Object and try again.")) return if not isinstance(obj, FlatCAMGeometry): - self.inform.emit("[ERROR_NOTCL]Expected a FlatCAMGeometry, got %s" % type(obj)) + self.inform.emit(_tr("[ERROR_NOTCL]Expected a FlatCAMGeometry, got %s") % type(obj)) return obj.multigeo = False @@ -3076,7 +3089,7 @@ class App(QtCore.QObject): self.should_we_save = True - self.inform.emit("[success] A Geometry object was converted to SingleGeo type.") + self.inform.emit(_tr("[success] A Geometry object was converted to SingleGeo type.")) def on_options_dict_change(self, field): self.options_write_form_field(field) @@ -3260,7 +3273,7 @@ class App(QtCore.QObject): current.to_form() self.plot_all() - self.inform.emit("[success]Converted units to %s" % self.defaults["units"]) + self.inform.emit(_tr("[success]Converted units to %s") % self.defaults["units"]) # self.ui.units_label.setText("[" + self.options["units"] + "]") self.set_screen_units(self.defaults["units"]) else: @@ -3271,7 +3284,7 @@ class App(QtCore.QObject): else: self.ui.general_defaults_form.general_app_group.units_radio.set_value('MM') self.toggle_units_ignore = False - self.inform.emit("[WARNING_NOTCL]Units conversion cancelled.") + self.inform.emit(_tr("[WARNING_NOTCL]Units conversion cancelled.")) self.options_read_form() self.defaults_read_form() @@ -3895,7 +3908,7 @@ class App(QtCore.QObject): filename = str(QtWidgets.QFileDialog.getSaveFileName(caption="Export G-Code ...", filter=_filter_)[0]) if filename == "": - self.inform.emit("[WARNING_NOTCL]Export Code cancelled.") + self.inform.emit(_tr("[WARNING_NOTCL]Export Code cancelled.")) return else: try: @@ -3905,14 +3918,14 @@ class App(QtCore.QObject): f.write(line) except FileNotFoundError: - self.inform.emit("[WARNING] No such file or directory") + self.inform.emit(_tr("[WARNING] No such file or directory")) return # Just for adding it to the recent files list. self.file_opened.emit("cncjob", filename) self.file_saved.emit("cncjob", filename) - self.inform.emit("Saved to: " + filename) + self.inform.emit(_tr("Saved to: %s") % filename) def handleFindGCode(self): self.report_usage("handleFindGCode()") @@ -3975,16 +3988,16 @@ class App(QtCore.QObject): if ok: if float(val) == 0: self.inform.emit( - "[WARNING_NOTCL] Please enter a tool diameter with non-zero value, in Float format.") + _tr("[WARNING_NOTCL] Please enter a tool diameter with non-zero value, in Float format.")) return self.collection.get_active().on_tool_add(dia=float(val)) else: self.inform.emit( - "[WARNING_NOTCL] Adding Tool cancelled ...") + _tr("[WARNING_NOTCL] Adding Tool cancelled ...")) else: msgbox = QtWidgets.QMessageBox() - msgbox.setText("Adding Tool works only when Advanced is checked.\n" - "Go to Preferences -> General - Show Advanced Options.") + msgbox.setText(_tr("Adding Tool works only when Advanced is checked.\n" + "Go to Preferences -> General - Show Advanced Options.")) msgbox.setWindowTitle("Tool adding ...") msgbox.setWindowIcon(QtGui.QIcon('share/warning.png')) msgbox.setStandardButtons(QtWidgets.QMessageBox.Ok) @@ -4007,34 +4020,34 @@ class App(QtCore.QObject): if ok: if float(val) == 0: self.inform.emit( - "[WARNING_NOTCL] Please enter a tool diameter with non-zero value, in Float format.") + _tr("[WARNING_NOTCL] Please enter a tool diameter with non-zero value, in Float format.")) return self.ncclear_tool.on_tool_add(dia=float(val)) else: self.inform.emit( - "[WARNING_NOTCL] Adding Tool cancelled ...") + _tr("[WARNING_NOTCL] Adding Tool cancelled ...")) # and only if the tool is Paint Area Tool elif tool_widget == self.paint_tool.toolName: if ok: if float(val) == 0: self.inform.emit( - "[WARNING_NOTCL] Please enter a tool diameter with non-zero value, in Float format.") + _tr("[WARNING_NOTCL] Please enter a tool diameter with non-zero value, in Float format.")) return self.paint_tool.on_tool_add(dia=float(val)) else: self.inform.emit( - "[WARNING_NOTCL] Adding Tool cancelled ...") + _tr("[WARNING_NOTCL] Adding Tool cancelled ...")) # and only if the tool is Solder Paste Dispensing Tool elif tool_widget == self.paste_tool.toolName: if ok: if float(val) == 0: self.inform.emit( - "[WARNING_NOTCL] Please enter a tool diameter with non-zero value, in Float format.") + _tr("[WARNING_NOTCL] Please enter a tool diameter with non-zero value, in Float format.")) return self.paste_tool.on_tool_add(dia=float(val)) else: self.inform.emit( - "[WARNING_NOTCL] Adding Tool cancelled ...") + _tr("[WARNING_NOTCL] Adding Tool cancelled ...")) # It's meant to delete tools in tool tables via a 'Delete' shortcut key but only if certain conditions are met @@ -4088,13 +4101,13 @@ class App(QtCore.QObject): while (self.collection.get_active()): self.delete_first_selected() - self.inform.emit("Object(s) deleted ...") + self.inform.emit(_tr("Object(s) deleted ...")) # make sure that the selection shape is deleted, too self.delete_selection_shape() else: - self.inform.emit("Failed. No object(s) selected...") + self.inform.emit(_tr("Failed. No object(s) selected...")) else: - self.inform.emit("Save the work in Editor and try again ...") + self.inform.emit(_tr("Save the work in Editor and try again ...")) def on_set_origin(self): """ @@ -4107,7 +4120,7 @@ class App(QtCore.QObject): #and ask him to click on the desired position self.report_usage("on_set_origin()") - self.inform.emit('Click to set the origin ...') + self.inform.emit(_tr('Click to set the origin ...')) self.plotcanvas.vis_connect('mouse_press', self.on_set_zero_click) @@ -4119,15 +4132,15 @@ class App(QtCore.QObject): """ self.report_usage("on_jump_to()") - dia_box = Dialog_box(title="Jump to ...", - label="Enter the coordinates in format X,Y:", + dia_box = Dialog_box(title=_tr("Jump to ..."), + label=_tr("Enter the coordinates in format X,Y:"), icon=QtGui.QIcon('share/jump_to16.png')) if dia_box.ok is True: try: location = eval(dia_box.location) if not isinstance(location, tuple): - self.inform.emit("Wrong coordinates. Enter coordinates in format: X,Y") + self.inform.emit(_tr("Wrong coordinates. Enter coordinates in format: X,Y")) return except: return @@ -4142,7 +4155,7 @@ class App(QtCore.QObject): jump_loc = self.plotcanvas.vispy_canvas.translate_coords_2((location[0], location[1])) cursor.setPos(canvas_origin.x() + jump_loc[0], (canvas_origin.y() + jump_loc[1])) - self.inform.emit("Done.") + self.inform.emit(_tr("Done.")) def on_copy_object(self): self.report_usage("on_copy_object()") @@ -4274,7 +4287,7 @@ class App(QtCore.QObject): obj.options['xmax'] = c obj.options['ymax'] = d # self.plot_all(zoom=False) - self.inform.emit('[success] Origin set ...') + self.inform.emit(_tr('[success] Origin set ...')) self.plotcanvas.vis_disconnect('mouse_press', self.on_set_zero_click) self.should_we_save = True @@ -4312,7 +4325,7 @@ class App(QtCore.QObject): ymaxlist = [] if not obj_list: - self.inform.emit("[WARNING_NOTCL] No object selected to Flip on Y axis.") + self.inform.emit(_tr("[WARNING_NOTCL] No object selected to Flip on Y axis.")) else: try: # first get a bounding box to fit all @@ -4337,9 +4350,9 @@ class App(QtCore.QObject): obj.mirror('X', [px, py]) obj.plot() self.object_changed.emit(obj) - self.inform.emit("[success] Flip on Y axis done.") + self.inform.emit(_tr("[success] Flip on Y axis done.")) except Exception as e: - self.inform.emit("[ERROR_NOTCL] Due of %s, Flip action was not executed." % str(e)) + self.inform.emit(_tr("[ERROR_NOTCL] Due of %s, Flip action was not executed.") % str(e)) return def on_flipx(self): @@ -4352,7 +4365,7 @@ class App(QtCore.QObject): ymaxlist = [] if not obj_list: - self.inform.emit("[WARNING_NOTCL] No object selected to Flip on X axis.") + self.inform.emit(_tr("[WARNING_NOTCL] No object selected to Flip on X axis.")) else: try: # first get a bounding box to fit all @@ -4377,9 +4390,9 @@ class App(QtCore.QObject): obj.mirror('Y', [px, py]) obj.plot() self.object_changed.emit(obj) - self.inform.emit("[success] Flip on X axis done.") + self.inform.emit(_tr("[success] Flip on X axis done.")) except Exception as e: - self.inform.emit("[ERROR_NOTCL] Due of %s, Flip action was not executed." % str(e)) + self.inform.emit(_tr("[ERROR_NOTCL] Due of %s, Flip action was not executed.") % str(e)) return def on_rotate(self, silent=False, preset=None): @@ -4392,10 +4405,10 @@ class App(QtCore.QObject): ymaxlist = [] if not obj_list: - self.inform.emit("[WARNING_NOTCL] No object selected to Rotate.") + self.inform.emit(_tr("[WARNING_NOTCL] No object selected to Rotate.")) else: if silent is False: - rotatebox = FCInputDialog(title="Transform", text="Enter the Angle value:", + rotatebox = FCInputDialog(title=_tr("Transform"), text=_tr("Enter the Angle value:"), min=-360, max=360, decimals=4, init_val=float(self.defaults['tools_transform_rotate'])) num, ok = rotatebox.get_value() @@ -4425,9 +4438,9 @@ class App(QtCore.QObject): sel_obj.rotate(-float(num), point=(px, py)) sel_obj.plot() self.object_changed.emit(sel_obj) - self.inform.emit("[success] Rotation done.") + self.inform.emit(_tr("[success] Rotation done.")) except Exception as e: - self.inform.emit("[ERROR_NOTCL] Due of %s, rotation movement was not executed." % str(e)) + self.inform.emit(_tr("[ERROR_NOTCL] Due of %s, rotation movement was not executed.") % str(e)) return def on_skewx(self): @@ -4438,9 +4451,9 @@ class App(QtCore.QObject): yminlist = [] if not obj_list: - self.inform.emit("[WARNING_NOTCL] No object selected to Skew/Shear on X axis.") + self.inform.emit(_tr("[WARNING_NOTCL] No object selected to Skew/Shear on X axis.")) else: - skewxbox = FCInputDialog(title="Transform", text="Enter the Angle value:", + skewxbox = FCInputDialog(title=_tr("Transform"), text=_tr("Enter the Angle value:"), min=-360, max=360, decimals=4, init_val=float(self.defaults['tools_transform_skew_x'])) num, ok = skewxbox.get_value() @@ -4459,7 +4472,7 @@ class App(QtCore.QObject): obj.skew(num, 0, point=(xminimal, yminimal)) obj.plot() self.object_changed.emit(obj) - self.inform.emit("[success] Skew on X axis done.") + self.inform.emit(_tr("[success] Skew on X axis done.")) def on_skewy(self): self.report_usage("on_skewy()") @@ -4469,9 +4482,9 @@ class App(QtCore.QObject): yminlist = [] if not obj_list: - self.inform.emit("[WARNING_NOTCL] No object selected to Skew/Shear on Y axis.") + self.inform.emit(_tr("[WARNING_NOTCL] No object selected to Skew/Shear on Y axis.")) else: - skewybox = FCInputDialog(title="Transform", text="Enter the Angle value:", + skewybox = FCInputDialog(title=_tr("Transform"), text=_tr("Enter the Angle value:"), min=-360, max=360, decimals=4, init_val=float(self.defaults['tools_transform_skew_y'])) num, ok = skewybox.get_value() @@ -4490,7 +4503,7 @@ class App(QtCore.QObject): obj.skew(0, num, point=(xminimal, yminimal)) obj.plot() self.object_changed.emit(obj) - self.inform.emit("[success] Skew on Y axis done.") + self.inform.emit(_tr("[success] Skew on Y axis done.")) def delete_first_selected(self): # Keep this for later @@ -4586,19 +4599,19 @@ class App(QtCore.QObject): if ok: if float(val) == 0: self.inform.emit( - "[WARNING_NOTCL] Please enter a grid value with non-zero value, in Float format.") + _tr("[WARNING_NOTCL] Please enter a grid value with non-zero value, in Float format.")) return else: if val not in self.defaults["global_grid_context_menu"][str(units)]: self.defaults["global_grid_context_menu"][str(units)].append(val) self.inform.emit( - "[success] New Grid added ...") + _tr("[success] New Grid added ...")) else: self.inform.emit( - "[WARNING_NOTCL] Grid already exists ...") + _tr("[WARNING_NOTCL] Grid already exists ...")) else: self.inform.emit( - "[WARNING_NOTCL] Adding New Grid cancelled ...") + _tr("[WARNING_NOTCL] Adding New Grid cancelled ...")) def on_grid_delete(self): ## Current application units in lower Case @@ -4613,20 +4626,20 @@ class App(QtCore.QObject): if ok: if float(val) == 0: self.inform.emit( - "[WARNING_NOTCL] Please enter a grid value with non-zero value, in Float format.") + _tr("[WARNING_NOTCL] Please enter a grid value with non-zero value, in Float format.")) return else: try: self.defaults["global_grid_context_menu"][str(units)].remove(val) except ValueError: self.inform.emit( - "[ERROR_NOTCL] Grid Value does not exist ...") + _tr("[ERROR_NOTCL] Grid Value does not exist ...")) return self.inform.emit( - "[success] Grid Value deleted ...") + _tr("[success] Grid Value deleted ...")) else: self.inform.emit( - "[WARNING_NOTCL] Delete Grid value cancelled ...") + _tr("[WARNING_NOTCL] Delete Grid value cancelled ...")) def on_shortcut_list(self): self.report_usage("on_shortcut_list()") @@ -4665,11 +4678,11 @@ class App(QtCore.QObject): name = obj.options["name"] except AttributeError: log.debug("on_copy_name() --> No object selected to copy it's name") - self.inform.emit("[WARNING_NOTCL]No object selected to copy it's name") + self.inform.emit(_tr("[WARNING_NOTCL]No object selected to copy it's name")) return self.clipboard.setText(name) - self.inform.emit("Name copied on clipboard ...") + self.inform.emit(_tr("Name copied on clipboard ...")) def on_mouse_click_over_plot(self, event): """ @@ -4707,6 +4720,9 @@ class App(QtCore.QObject): # If the SHIFT key is pressed when LMB is clicked then the coordinates are copied to clipboard if modifiers == QtCore.Qt.ShiftModifier: + # do not auto open the Project Tab + self.click_noproject = True + self.clipboard.setText(self.defaults["global_point_clipboard_format"] % (self.pos[0], self.pos[1])) return @@ -4934,11 +4950,16 @@ class App(QtCore.QObject): self.collection.set_all_inactive() # delete the possible selection box around a possible selected object self.delete_selection_shape() + # and as a convenience move the focus to the Project tab because Selected tab is now empty but # only when working on App + if self.call_source == 'app': + if self.click_noproject is False: + self.ui.notebook.setCurrentWidget(self.ui.project_tab) + else: + # restore auto open the Project Tab + self.click_noproject = False - if self.call_source != 'measurement': - self.ui.notebook.setCurrentWidget(self.ui.project_tab) # delete any text in the status bar, implicitly the last object name that was selected self.inform.emit("") else: @@ -4956,16 +4977,16 @@ class App(QtCore.QObject): # self.inform.emit('[selected] %s: %s selected' % # (str(curr_sel_obj.kind).capitalize(), str(curr_sel_obj.options['name']))) if curr_sel_obj.kind == 'gerber': - self.inform.emit('[selected]%s selected' % + self.inform.emit(_tr('[selected]%s selected') % ('green', str(curr_sel_obj.options['name']))) elif curr_sel_obj.kind == 'excellon': - self.inform.emit('[selected]%s selected' % + self.inform.emit(_tr('[selected]%s selected') % ('brown', str(curr_sel_obj.options['name']))) elif curr_sel_obj.kind == 'cncjob': - self.inform.emit('[selected]%s selected' % + self.inform.emit(_tr('[selected]%s selected') % ('blue', str(curr_sel_obj.options['name']))) elif curr_sel_obj.kind == 'geometry': - self.inform.emit('[selected]%s selected' % + self.inform.emit(_tr('[selected]%s selected') % ('red', str(curr_sel_obj.options['name']))) elif self.collection.get_active().options['name'] not in objects_under_the_click_list: @@ -4979,27 +5000,26 @@ class App(QtCore.QObject): # self.inform.emit('[selected] %s: %s selected' % # (str(curr_sel_obj.kind).capitalize(), str(curr_sel_obj.options['name']))) if curr_sel_obj.kind == 'gerber': - self.inform.emit('[selected]%s selected' % + self.inform.emit(_tr('[selected]%s selected') % ('green', str(curr_sel_obj.options['name']))) elif curr_sel_obj.kind == 'excellon': - self.inform.emit('[selected]%s selected' % + self.inform.emit(_tr('[selected]%s selected') % ('brown', str(curr_sel_obj.options['name']))) elif curr_sel_obj.kind == 'cncjob': - self.inform.emit('[selected]%s selected' % + self.inform.emit(_tr('[selected]%s selected') % ('blue', str(curr_sel_obj.options['name']))) elif curr_sel_obj.kind == 'geometry': - self.inform.emit('[selected]%s selected' % + self.inform.emit(_tr('[selected]%s selected') % ('red', str(curr_sel_obj.options['name']))) else: self.collection.set_all_inactive() self.delete_selection_shape() - if self.call_source != 'measurement': + if self.call_source == 'app': # delete any text in the status bar, implicitly the last object name that was selected self.inform.emit("") else: self.call_source = 'app' - else: # If there is no selected object # make active the first element of the overlapped objects list @@ -5028,16 +5048,16 @@ class App(QtCore.QObject): # self.inform.emit('[selected] %s: %s selected' % # (str(curr_sel_obj.kind).capitalize(), str(curr_sel_obj.options['name']))) if curr_sel_obj.kind == 'gerber': - self.inform.emit('[selected]%s selected' % + self.inform.emit(_tr('[selected]%s selected') % ('green', str(curr_sel_obj.options['name']))) elif curr_sel_obj.kind == 'excellon': - self.inform.emit('[selected]%s selected' % + self.inform.emit(_tr('[selected]%s selected') % ('brown', str(curr_sel_obj.options['name']))) elif curr_sel_obj.kind == 'cncjob': - self.inform.emit('[selected]%s selected' % + self.inform.emit(_tr('[selected]%s selected') % ('blue', str(curr_sel_obj.options['name']))) elif curr_sel_obj.kind == 'geometry': - self.inform.emit('[selected]%s selected' % + self.inform.emit(_tr('[selected]%s selected') % ('red', str(curr_sel_obj.options['name']))) # for obj in self.collection.get_list(): @@ -5154,10 +5174,10 @@ class App(QtCore.QObject): if self.collection.get_list() and self.should_we_save: msgbox = QtWidgets.QMessageBox() # msgbox.setText("Save changes ...") - msgbox.setText("There are files/objects opened in FlatCAM.\n" + msgbox.setText(_tr("There are files/objects opened in FlatCAM.\n" "Creating a New project will delete them.\n" - "Do you want to Save the project?") - msgbox.setWindowTitle("Save changes") + "Do you want to Save the project?")) + msgbox.setWindowTitle(_tr("Save changes")) msgbox.setWindowIcon(QtGui.QIcon('share/save_as.png')) msgbox.setStandardButtons(QtWidgets.QMessageBox.Cancel | QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No) @@ -5172,7 +5192,7 @@ class App(QtCore.QObject): self.on_file_new() else: self.on_file_new() - self.inform.emit("[success] New Project created...") + self.inform.emit(_tr("[success] New Project created...")) def on_file_new(self): """ @@ -5253,18 +5273,18 @@ class App(QtCore.QObject): try: obj = self.collection.get_active() except: - self.inform.emit("[WARNING_NOTCL] Select an Gerber or Excellon file to view it's source file.") + self.inform.emit(_tr("[WARNING_NOTCL] Select an Gerber or Excellon file to view it's source file.")) return 'fail' # then append the text from GCode to the text editor try: file = StringIO(obj.source_file) except AttributeError: - self.inform.emit("[WARNING_NOTCL] There is no selected object for which to see it's source file code.") + self.inform.emit(_tr("[WARNING_NOTCL] There is no selected object for which to see it's source file code.")) return 'fail' # add the tab if it was closed - self.ui.plot_tab_area.addTab(self.ui.cncjob_tab, "Code Editor") + self.ui.plot_tab_area.addTab(self.ui.cncjob_tab, _tr("Code Editor")) # first clear previous text in text editor (if any) self.ui.code_editor.clear() @@ -5277,7 +5297,7 @@ class App(QtCore.QObject): self.ui.code_editor.append(proc_line) except Exception as e: log.debug('App.on_view_source() -->%s' % str(e)) - self.inform.emit('[ERROR]App.on_view_source() -->%s' % str(e)) + self.inform.emit(_tr('[ERROR]App.on_view_source() -->%s') % str(e)) return self.ui.code_editor.moveCursor(QtGui.QTextCursor.Start) @@ -5323,7 +5343,7 @@ class App(QtCore.QObject): filenames = [str(filename) for filename in filenames] if len(filenames) == 0: - self.inform.emit("[WARNING_NOTCL]Open Gerber cancelled.") + self.inform.emit(_tr("[WARNING_NOTCL]Open Gerber cancelled.")) else: for filename in filenames: if filename != '': @@ -5352,7 +5372,7 @@ class App(QtCore.QObject): filenames = [str(filename) for filename in filenames] if len(filenames) == 0: - self.inform.emit("[WARNING_NOTCL]Open Excellon cancelled.") + self.inform.emit(_tr("[WARNING_NOTCL]Open Excellon cancelled.")) else: for filename in filenames: if filename != '': @@ -5382,7 +5402,7 @@ class App(QtCore.QObject): filenames = [str(filename) for filename in filenames] if len(filenames) == 0: - self.inform.emit("[WARNING_NOTCL]Open G-Code cancelled.") + self.inform.emit(_tr("[WARNING_NOTCL]Open G-Code cancelled.")) else: for filename in filenames: if filename != '': @@ -5411,7 +5431,7 @@ class App(QtCore.QObject): filename = str(filename) if filename == "": - self.inform.emit("[WARNING_NOTCL]Open Project cancelled.") + self.inform.emit(_tr("[WARNING_NOTCL]Open Project cancelled.")) else: # self.worker_task.emit({'fcn': self.open_project, # 'params': [filename]}) @@ -5436,7 +5456,7 @@ class App(QtCore.QObject): filename, _ = QtWidgets.QFileDialog.getOpenFileName(caption="Open Configuration File", filter = _filter_) if filename == "": - self.inform.emit("[WARNING_NOTCL]Open COnfig cancelled.") + self.inform.emit(_tr("[WARNING_NOTCL]Open COnfig cancelled.")) else: self.open_config_file(filename) @@ -5451,8 +5471,8 @@ class App(QtCore.QObject): obj = self.collection.get_active() if obj is None: - self.inform.emit("WARNING: No object selected.") - msg = "Please Select a Geometry object to export" + self.inform.emit(_tr("[WARNING_NOTCL] No object selected.")) + msg = _tr("Please Select a Geometry object to export") msgbox = QtWidgets.QMessageBox() msgbox.setInformativeText(msg) msgbox.setStandardButtons(QtWidgets.QMessageBox.Ok) @@ -5463,7 +5483,7 @@ class App(QtCore.QObject): # Check for more compatible types and add as required if (not isinstance(obj, FlatCAMGeometry) and not isinstance(obj, FlatCAMGerber) and not isinstance(obj, FlatCAMCNCjob) and not isinstance(obj, FlatCAMExcellon)): - msg = "[ERROR_NOTCL] Only Geometry, Gerber and CNCJob objects can be used." + msg = _tr("[ERROR_NOTCL] Only Geometry, Gerber and CNCJob objects can be used.") msgbox = QtWidgets.QMessageBox() msgbox.setInformativeText(msg) msgbox.setStandardButtons(QtWidgets.QMessageBox.Ok) @@ -5485,7 +5505,7 @@ class App(QtCore.QObject): filename = str(filename) if filename == "": - self.inform.emit("[WARNING_NOTCL]Export SVG cancelled.") + self.inform.emit(_tr("[WARNING_NOTCL]Export SVG cancelled.")) return else: self.export_svg(name, filename) @@ -5499,7 +5519,7 @@ class App(QtCore.QObject): image = _screenshot() data = np.asarray(image) if not data.ndim == 3 and data.shape[-1] in (3, 4): - self.inform.emit('[[WARNING_NOTCL]] Data must be a 3D array with last dimension 3 or 4') + self.inform.emit(_tr('[[WARNING_NOTCL]] Data must be a 3D array with last dimension 3 or 4')) return filter_ = "PNG File (*.png);;All Files (*.*)" @@ -5509,12 +5529,12 @@ class App(QtCore.QObject): directory=self.get_last_save_folder() + '/png_' + str(self.date).replace('-', ''), filter=filter_) except TypeError: - filename, _ = QtWidgets.QFileDialog.getSaveFileName(caption="Export PNG Image", filter=filter_) + filename, _ = QtWidgets.QFileDialog.getSaveFileName(caption=_tr("Export PNG Image"), filter=filter_) filename = str(filename) if filename == "": - self.inform.emit("Export PNG cancelled.") + self.inform.emit(_tr("Export PNG cancelled.")) return else: write_png(filename, data) @@ -5531,12 +5551,12 @@ class App(QtCore.QObject): obj = self.collection.get_active() if obj is None: - self.inform.emit("[WARNING_NOTCL] No object selected. Please select an Gerber object to export.") + self.inform.emit(_tr("[WARNING_NOTCL] No object selected. Please select an Gerber object to export.")) return # Check for more compatible types and add as required if not isinstance(obj, FlatCAMGerber): - self.inform.emit("[ERROR_NOTCL] Failed. Only Gerber objects can be saved as Gerber files...") + self.inform.emit(_tr("[ERROR_NOTCL] Failed. Only Gerber objects can be saved as Gerber files...")) return name = self.collection.get_active().options["name"] @@ -5548,12 +5568,12 @@ class App(QtCore.QObject): directory=self.get_last_save_folder() + '/' + name, filter=filter) except TypeError: - filename, _ = QtWidgets.QFileDialog.getSaveFileName(caption="Save Gerber source file", filter=filter) + filename, _ = QtWidgets.QFileDialog.getSaveFileName(caption=_tr("Save Gerber source file"), filter=filter) filename = str(filename) if filename == "": - self.inform.emit("[WARNING_NOTCL]Save Gerber source file cancelled.") + self.inform.emit(_tr("[WARNING_NOTCL]Save Gerber source file cancelled.")) return else: self.save_source_file(name, filename) @@ -5570,12 +5590,12 @@ class App(QtCore.QObject): obj = self.collection.get_active() if obj is None: - self.inform.emit("[WARNING_NOTCL] No object selected. Please select an Excellon object to export.") + self.inform.emit(_tr("[WARNING_NOTCL] No object selected. Please select an Excellon object to export.")) return # Check for more compatible types and add as required if not isinstance(obj, FlatCAMExcellon): - self.inform.emit("[ERROR_NOTCL] Failed. Only Excellon objects can be saved as Excellon files...") + self.inform.emit(_tr("[ERROR_NOTCL] Failed. Only Excellon objects can be saved as Excellon files...")) return name = self.collection.get_active().options["name"] @@ -5587,12 +5607,12 @@ class App(QtCore.QObject): directory=self.get_last_save_folder() + '/' + name, filter=filter) except TypeError: - filename, _ = QtWidgets.QFileDialog.getSaveFileName(caption="Save Excellon source file", filter=filter) + filename, _ = QtWidgets.QFileDialog.getSaveFileName(caption=_tr("Save Excellon source file"), filter=filter) filename = str(filename) if filename == "": - self.inform.emit("[WARNING_NOTCL]Saving Excellon source file cancelled.") + self.inform.emit(_tr("[WARNING_NOTCL]Saving Excellon source file cancelled.")) return else: self.save_source_file(name, filename) @@ -5609,12 +5629,12 @@ class App(QtCore.QObject): obj = self.collection.get_active() if obj is None: - self.inform.emit("[WARNING_NOTCL] No object selected. Please Select an Excellon object to export.") + self.inform.emit(_tr("[WARNING_NOTCL] No object selected. Please Select an Excellon object to export.")) return # Check for more compatible types and add as required if not isinstance(obj, FlatCAMExcellon): - self.inform.emit("[ERROR_NOTCL] Failed. Only Excellon objects can be saved as Excellon files...") + self.inform.emit(_tr("[ERROR_NOTCL] Failed. Only Excellon objects can be saved as Excellon files...")) return name = self.collection.get_active().options["name"] @@ -5626,12 +5646,12 @@ class App(QtCore.QObject): directory=self.get_last_save_folder() + '/' + name, filter=filter) except TypeError: - filename, _ = QtWidgets.QFileDialog.getSaveFileName(caption="Export Excellon", filter=filter) + filename, _ = QtWidgets.QFileDialog.getSaveFileName(caption=_tr("Export Excellon"), filter=filter) filename = str(filename) if filename == "": - self.inform.emit("[WARNING_NOTCL]Export Excellon cancelled.") + self.inform.emit(_tr("[WARNING_NOTCL]Export Excellon cancelled.")) return else: self.export_excellon(name, filename) @@ -5648,8 +5668,8 @@ class App(QtCore.QObject): obj = self.collection.get_active() if obj is None: - self.inform.emit("W[WARNING_NOTCL] No object selected.") - msg = "Please Select a Geometry object to export" + self.inform.emit(_tr("[WARNING_NOTCL] No object selected.")) + msg = _tr("Please Select a Geometry object to export") msgbox = QtWidgets.QMessageBox() msgbox.setInformativeText(msg) msgbox.setStandardButtons(QtWidgets.QMessageBox.Ok) @@ -5659,7 +5679,7 @@ class App(QtCore.QObject): # Check for more compatible types and add as required if not isinstance(obj, FlatCAMGeometry): - msg = "[ERROR_NOTCL] Only Geometry objects can be used." + msg = _tr("[ERROR_NOTCL] Only Geometry objects can be used.") msgbox = QtWidgets.QMessageBox() msgbox.setInformativeText(msg) msgbox.setStandardButtons(QtWidgets.QMessageBox.Ok) @@ -5676,12 +5696,12 @@ class App(QtCore.QObject): directory=self.get_last_save_folder() + '/' + name, filter=filter) except TypeError: - filename, _ = QtWidgets.QFileDialog.getSaveFileName(caption="Export DXF", filter=filter) + filename, _ = QtWidgets.QFileDialog.getSaveFileName(caption=_tr("Export DXF"), filter=filter) filename = str(filename) if filename == "": - self.inform.emit("[WARNING_NOTCL]Export DXF cancelled.") + self.inform.emit(_tr("[WARNING_NOTCL] Export DXF cancelled.")) return else: self.export_dxf(name, filename) @@ -5710,7 +5730,7 @@ class App(QtCore.QObject): filenames = [str(filename) for filename in filenames] if len(filenames) == 0: - self.inform.emit("[WARNING_NOTCL]Open SVG cancelled.") + self.inform.emit(_tr("[WARNING_NOTCL]Open SVG cancelled.")) else: for filename in filenames: if filename != '': @@ -5729,10 +5749,10 @@ class App(QtCore.QObject): filter = "DXF File (*.DXF);;All Files (*.*)" try: - filenames, _ = QtWidgets.QFileDialog.getOpenFileNames(caption="Import DXF", + filenames, _ = QtWidgets.QFileDialog.getOpenFileNames(caption=_tr("Import DXF"), directory=self.get_last_folder(), filter=filter) except TypeError: - filenames, _ = QtWidgets.QFileDialog.getOpenFileNames(caption="Import DXF", filter=filter) + filenames, _ = QtWidgets.QFileDialog.getOpenFileNames(caption=_tr("Import DXF"), filter=filter) if type_of_obj is not "geometry" and type_of_obj is not "gerber": type_of_obj = "geometry" @@ -5740,7 +5760,7 @@ class App(QtCore.QObject): filenames = [str(filename) for filename in filenames] if len(filenames) == 0: - self.inform.emit("[WARNING_NOTCL]Open DXF cancelled.") + self.inform.emit(_tr("[WARNING_NOTCL]Open DXF cancelled.")) else: for filename in filenames: if filename != '': @@ -5758,10 +5778,10 @@ class App(QtCore.QObject): App.log.debug("on_file_runscript()") _filter_ = "TCL script (*.TCL);;TCL script (*.TXT);;All Files (*.*)" try: - filename, _ = QtWidgets.QFileDialog.getOpenFileName(caption="Open TCL script", + filename, _ = QtWidgets.QFileDialog.getOpenFileName(caption=_tr("Open TCL script"), directory=self.get_last_folder(), filter=_filter_) except TypeError: - filename, _ = QtWidgets.QFileDialog.getOpenFileName(caption="Open TCL script", filter=_filter_) + filename, _ = QtWidgets.QFileDialog.getOpenFileName(caption=_tr("Open TCL script"), filter=_filter_) # The Qt methods above will return a QString which can cause problems later. # So far json.dump() will fail to serialize it. @@ -5769,7 +5789,7 @@ class App(QtCore.QObject): filename = str(filename) if filename == "": - self.inform.emit("[WARNING_NOTCL]Open TCL script cancelled.") + self.inform.emit(_tr("[WARNING_NOTCL]Open TCL script cancelled.")) else: try: with open(filename, "r") as tcl_script: @@ -5821,12 +5841,12 @@ class App(QtCore.QObject): directory=self.get_last_save_folder() + '/Project_' + self.date.replace('-', ''), filter=filter_) except TypeError: - filename, _ = QtWidgets.QFileDialog.getSaveFileName(caption="Save Project As ...", filter=filter_) + filename, _ = QtWidgets.QFileDialog.getSaveFileName(caption=_tr("Save Project As ..."), filter=filter_) filename = str(filename) if filename == '': - self.inform.emit("[WARNING_NOTCL]Save Project cancelled.") + self.inform.emit(_tr("[WARNING_NOTCL]Save Project cancelled.")) return try: @@ -5881,7 +5901,7 @@ class App(QtCore.QObject): # TODO: The return behavior has not been established... should raise exception? return "Could not retrieve object: %s" % obj_name - with self.proc_container.new("Exporting SVG") as proc: + with self.proc_container.new(_tr("Exporting SVG")) as proc: exported_svg = obj.export_svg(scale_factor=scale_factor) # Determine bounding area for svg export @@ -5914,7 +5934,7 @@ class App(QtCore.QObject): fp.write(svgcode.toprettyxml()) self.file_saved.emit("SVG", filename) - self.inform.emit("[success] SVG file exported to " + filename) + self.inform.emit(_tr("[success] SVG file exported to %s") % filename) def export_svg_negative(self, obj_name, box_name, filename, boundary, scale_factor=0.00, use_thread=True): """ @@ -5945,7 +5965,7 @@ class App(QtCore.QObject): return "Could not retrieve object: %s" % box_name if box is None: - self.inform.emit("[WARNING_NOTCL]No object Box. Using instead %s" % obj) + self.inform.emit(_tr("[WARNING_NOTCL]No object Box. Using instead %s") % obj) box = obj def make_negative_film(): @@ -6019,10 +6039,10 @@ class App(QtCore.QObject): self.progress.emit(100) self.file_saved.emit("SVG", filename) - self.inform.emit("[success] SVG file exported to " + filename) + self.inform.emit(_tr("[success] SVG file exported to %s") % filename) if use_thread is True: - proc = self.proc_container.new("Generating Film ... Please wait.") + proc = self.proc_container.new(_tr("Generating Film ... Please wait.")) def job_thread_film(app_obj): try: @@ -6065,7 +6085,7 @@ class App(QtCore.QObject): return "Could not retrieve object: %s" % box_name if box is None: - self.inform.emit("[WARNING_NOTCL]No object Box. Using instead %s" % obj) + self.inform.emit(_tr("[WARNING_NOTCL]No object Box. Using instead %s") % obj) box = obj def make_black_film(): @@ -6133,10 +6153,10 @@ class App(QtCore.QObject): self.progress.emit(100) self.file_saved.emit("SVG", filename) - self.inform.emit("[success] SVG file exported to " + filename) + self.inform.emit(_tr("[success] SVG file exported to %s") % filename) if use_thread is True: - proc = self.proc_container.new("Generating Film ... Please wait.") + proc = self.proc_container.new(_tr("Generating Film ... Please wait.")) def job_thread_film(app_obj): try: @@ -6283,26 +6303,26 @@ class App(QtCore.QObject): fp.write(exported_excellon) self.file_saved.emit("Excellon", filename) - self.inform.emit("[success] Excellon file exported to " + filename) + self.inform.emit(_tr("[success] Excellon file exported to %s") % filename) except Exception as e: log.debug("App.export_excellon.make_excellon() --> %s" % str(e)) return 'fail' if use_thread is True: - with self.proc_container.new("Exporting Excellon") as proc: + with self.proc_container.new(_tr("Exporting Excellon")) as proc: def job_thread_exc(app_obj): ret = make_excellon() if ret == 'fail': - self.inform.emit('[ERROR_NOTCL] Could not export Excellon file.') + self.inform.emit(_tr('[ERROR_NOTCL] Could not export Excellon file.')) return self.worker_task.emit({'fcn': job_thread_exc, 'params': [self]}) else: ret = make_excellon() if ret == 'fail': - self.inform.emit('[ERROR_NOTCL] Could not export Excellon file.') + self.inform.emit(_tr('[ERROR_NOTCL] Could not export Excellon file.')) return def export_dxf(self, obj_name, filename, use_thread=True): @@ -6341,25 +6361,25 @@ class App(QtCore.QObject): dxf_code.saveas(filename) self.file_saved.emit("DXF", filename) - self.inform.emit("[success] DXF file exported to " + filename) + self.inform.emit(_tr("[success] DXF file exported to %s") % filename) except: return 'fail' if use_thread is True: - with self.proc_container.new("Exporting DXF") as proc: + with self.proc_container.new(_tr("Exporting DXF")) as proc: def job_thread_exc(app_obj): ret = make_dxf() if ret == 'fail': - self.inform.emit('[[WARNING_NOTCL]] Could not export DXF file.') + self.inform.emit(_tr('[[WARNING_NOTCL]] Could not export DXF file.')) return self.worker_task.emit({'fcn': job_thread_exc, 'params': [self]}) else: ret = make_dxf() if ret == 'fail': - self.inform.emit('[[WARNING_NOTCL]] Could not export DXF file.') + self.inform.emit(_tr('[[WARNING_NOTCL]] Could not export DXF file.')) return def import_svg(self, filename, geo_type='geometry', outname=None): @@ -6379,8 +6399,8 @@ class App(QtCore.QObject): elif geo_type == "gerber": obj_type = geo_type else: - self.inform.emit("[ERROR_NOTCL] Not supported type was choosed as parameter. " - "Only Geometry and Gerber are supported") + self.inform.emit(_tr("[ERROR_NOTCL] Not supported type is picked as parameter. " + "Only Geometry and Gerber are supported")) return units = self.ui.general_defaults_form.general_app_group.units_radio.get_value().upper() @@ -6389,7 +6409,7 @@ class App(QtCore.QObject): geo_obj.import_svg(filename, obj_type, units=units) geo_obj.multigeo = False - with self.proc_container.new("Importing SVG") as proc: + with self.proc_container.new(_tr("Importing SVG")) as proc: # Object name name = outname or filename.split('/')[-1].split('\\')[-1] @@ -6400,7 +6420,7 @@ class App(QtCore.QObject): self.file_opened.emit("svg", filename) # GUI feedback - self.inform.emit("[success] Opened: " + filename) + self.inform.emit(_tr("[success] Opened: %s") % filename) self.progress.emit(100) def import_dxf(self, filename, geo_type='geometry', outname=None): @@ -6421,8 +6441,8 @@ class App(QtCore.QObject): elif geo_type == "gerber": obj_type = geo_type else: - self.inform.emit("[ERROR_NOTCL] Not supported type was choosed as parameter. " - "Only Geometry and Gerber are supported") + self.inform.emit(_tr("[ERROR_NOTCL] Not supported type is picked as parameter. " + "Only Geometry and Gerber are supported")) return units = self.ui.general_defaults_form.general_app_group.units_radio.get_value().upper() @@ -6431,7 +6451,7 @@ class App(QtCore.QObject): geo_obj.import_dxf(filename, obj_type, units=units) geo_obj.multigeo = False - with self.proc_container.new("Importing DXF") as proc: + with self.proc_container.new(_tr("Importing DXF")) as proc: # Object name name = outname or filename.split('/')[-1].split('\\')[-1] @@ -6442,7 +6462,7 @@ class App(QtCore.QObject): self.file_opened.emit("dxf", filename) # GUI feedback - self.inform.emit("[success] Opened: " + filename) + self.inform.emit(_tr("[success] Opened: %s") % filename) self.progress.emit(100) def import_image(self, filename, type='gerber', dpi=96, mode='black', mask=[250, 250, 250, 250], outname=None): @@ -6462,15 +6482,15 @@ class App(QtCore.QObject): elif type == "gerber": obj_type = type else: - self.inform.emit("[ERROR_NOTCL] Not supported type was picked as parameter. " - "Only Geometry and Gerber are supported") + self.inform.emit(_tr("[ERROR_NOTCL] Not supported type is picked as parameter. " + "Only Geometry and Gerber are supported")) return def obj_init(geo_obj, app_obj): geo_obj.import_image(filename, units=units, dpi=dpi, mode=mode, mask=mask) geo_obj.multigeo = False - with self.proc_container.new("Importing Image") as proc: + with self.proc_container.new(_tr("Importing Image")) as proc: # Object name name = outname or filename.split('/')[-1].split('\\')[-1] @@ -6482,7 +6502,7 @@ class App(QtCore.QObject): self.file_opened.emit("image", filename) # GUI feedback - self.inform.emit("[success] Opened: " + filename) + self.inform.emit(_tr("[success] Opened: %s") % filename) self.progress.emit(100) def open_gerber(self, filename, outname=None): @@ -6511,18 +6531,18 @@ class App(QtCore.QObject): try: gerber_obj.parse_file(filename) except IOError: - app_obj.inform.emit("[ERROR_NOTCL] Failed to open file: " + filename) + app_obj.inform.emit(_tr("[ERROR_NOTCL] Failed to open file: %s") % filename) app_obj.progress.emit(0) - self.inform.emit('[ERROR_NOTCL] Failed to open file: ' + filename) + self.inform.emit(_tr('[ERROR_NOTCL] Failed to open file: %s') % filename) return "fail" except ParseError as err: - app_obj.inform.emit("[ERROR_NOTCL] Failed to parse file: " + filename + ". " + str(err)) + app_obj.inform.emit(_tr("[ERROR_NOTCL] Failed to parse file: %s. %s") % (filename, str(err))) app_obj.progress.emit(0) self.log.error(str(err)) return "fail" except: - msg = "[ERROR] An internal error has ocurred. See shell.\n" + msg = _tr("[ERROR] An internal error has ocurred. See shell.\n") msg += traceback.format_exc() app_obj.inform.emit(msg) return "fail" @@ -6531,7 +6551,7 @@ class App(QtCore.QObject): # app_obj.inform.emit("[ERROR] No geometry found in file: " + filename) # self.collection.set_active(gerber_obj.options["name"]) # self.collection.delete_active() - self.inform.emit("[ERROR_NOTCL] Object is not Gerber file or empty. Aborting object creation.") + self.inform.emit(_tr("[ERROR_NOTCL] Object is not Gerber file or empty. Aborting object creation.")) return "fail" # Further parsing @@ -6539,7 +6559,7 @@ class App(QtCore.QObject): App.log.debug("open_gerber()") - with self.proc_container.new("Opening Gerber") as proc: + with self.proc_container.new(_tr("Opening Gerber")) as proc: self.progress.emit(10) @@ -6549,7 +6569,7 @@ class App(QtCore.QObject): ### Object creation ### ret = self.new_object("gerber", name, obj_init, autoselected=False) if ret == 'fail': - self.inform.emit('[ERROR_NOTCL] Open Gerber failed. Probable not a Gerber file.') + self.inform.emit(_tr('[ERROR_NOTCL] Open Gerber failed. Probable not a Gerber file.')) return # Register recent file @@ -6558,8 +6578,7 @@ class App(QtCore.QObject): self.progress.emit(100) # GUI feedback - self.inform.emit("[success] Opened: " + filename) - + self.inform.emit(_tr("[success] Opened: %s") % filename) def open_excellon(self, filename, outname=None): """ @@ -6585,15 +6604,15 @@ class App(QtCore.QObject): ret = excellon_obj.parse_file(filename) if ret == "fail": log.debug("Excellon parsing failed.") - self.inform.emit("[ERROR_NOTCL] This is not Excellon file.") + self.inform.emit(_tr("[ERROR_NOTCL] This is not Excellon file.")) return "fail" except IOError: - app_obj.inform.emit("[ERROR_NOTCL] Cannot open file: " + filename) + app_obj.inform.emit(_tr("[ERROR_NOTCL] Cannot open file: %s") % filename) log.debug("Could not open Excellon object.") self.progress.emit(0) # TODO: self and app_bjj mixed return "fail" except: - msg = "[ERROR_NOTCL] An internal error has occurred. See shell.\n" + msg = _tr("[ERROR_NOTCL] An internal error has occurred. See shell.\n") msg += traceback.format_exc() app_obj.inform.emit(msg) return "fail" @@ -6609,24 +6628,24 @@ class App(QtCore.QObject): for tool in excellon_obj.tools: if excellon_obj.tools[tool]['solid_geometry']: return - app_obj.inform.emit("[ERROR_NOTCL] No geometry found in file: " + filename) + app_obj.inform.emit(_tr("[ERROR_NOTCL] No geometry found in file: %s") % filename) return "fail" - with self.proc_container.new("Opening Excellon."): + with self.proc_container.new(_tr("Opening Excellon.")): # Object name name = outname or filename.split('/')[-1].split('\\')[-1] ret = self.new_object("excellon", name, obj_init, autoselected=False) if ret == 'fail': - self.inform.emit('[ERROR_NOTCL] Open Excellon file failed. Probable not an Excellon file.') + self.inform.emit(_tr('[ERROR_NOTCL] Open Excellon file failed. Probable not an Excellon file.')) return # Register recent file self.file_opened.emit("excellon", filename) # GUI feedback - self.inform.emit("[success] Opened: " + filename) + self.inform.emit(_tr("[success] Opened: %s") % filename) # self.progress.emit(100) def open_gcode(self, filename, outname=None): @@ -6658,7 +6677,7 @@ class App(QtCore.QObject): gcode = f.read() f.close() except IOError: - app_obj_.inform.emit("[ERROR_NOTCL] Failed to open " + filename) + app_obj_.inform.emit(_tr("[ERROR_NOTCL] Failed to open %s") % filename) self.progress.emit(0) return "fail" @@ -6668,13 +6687,13 @@ class App(QtCore.QObject): ret = job_obj.gcode_parse() if ret == "fail": - self.inform.emit("[ERROR_NOTCL] This is not GCODE") + self.inform.emit(_tr("[ERROR_NOTCL] This is not GCODE")) return "fail" self.progress.emit(60) job_obj.create_geometry() - with self.proc_container.new("Opening G-Code."): + with self.proc_container.new(_tr("Opening G-Code.")): # Object name name = outname or filename.split('/')[-1].split('\\')[-1] @@ -6682,16 +6701,16 @@ class App(QtCore.QObject): # New object creation and file processing ret = self.new_object("cncjob", name, obj_init, autoselected=False) if ret == 'fail': - self.inform.emit("[ERROR_NOTCL] Failed to create CNCJob Object. Probable not a GCode file.\n " + self.inform.emit(_tr("[ERROR_NOTCL] Failed to create CNCJob Object. Probable not a GCode file.\n " "Attempting to create a FlatCAM CNCJob Object from " - "G-Code file failed during processing") + "G-Code file failed during processing")) return "fail" # Register recent file self.file_opened.emit("cncjob", filename) # GUI feedback - self.inform.emit("[success] Opened: " + filename) + self.inform.emit(_tr("[success] Opened: %s") % filename) self.progress.emit(100) def open_config_file(self, filename, run_from_arg=None): @@ -6705,7 +6724,7 @@ class App(QtCore.QObject): App.log.debug("Opening config file: " + filename) # add the tab if it was closed - self.ui.plot_tab_area.addTab(self.ui.cncjob_tab, "Code Editor") + self.ui.plot_tab_area.addTab(self.ui.cncjob_tab, _tr("Code Editor")) # first clear previous text in text editor (if any) self.ui.code_editor.clear() @@ -6722,7 +6741,7 @@ class App(QtCore.QObject): f.close() except IOError: App.log.error("Failed to open config file: %s" % filename) - self.inform.emit("[ERROR_NOTCL] Failed to open config file: %s" % filename) + self.inform.emit(_tr("[ERROR_NOTCL] Failed to open config file: %s") % filename) return def open_project(self, filename, run_from_arg=None): @@ -6747,14 +6766,14 @@ class App(QtCore.QObject): f = open(filename, 'r') except IOError: App.log.error("Failed to open project file: %s" % filename) - self.inform.emit("[ERROR_NOTCL] Failed to open project file: %s" % filename) + self.inform.emit(_tr("[ERROR_NOTCL] Failed to open project file: %s") % filename) return try: d = json.load(f, object_hook=dict2obj) except: App.log.error("Failed to parse project file: %s" % filename) - self.inform.emit("[ERROR_NOTCL] Failed to parse project file: %s" % filename) + self.inform.emit(_tr("[ERROR_NOTCL] Failed to parse project file: %s") % filename) f.close() # Open and parse a compressed Project file @@ -6764,7 +6783,7 @@ class App(QtCore.QObject): d = json.loads(file_content, object_hook=dict2obj) except IOError: App.log.error("Failed to open project file: %s" % filename) - self.inform.emit("[ERROR_NOTCL] Failed to open project file: %s" % filename) + self.inform.emit(_tr("[ERROR_NOTCL] Failed to open project file: %s") % filename) return self.file_opened.emit("project", filename) @@ -6790,7 +6809,7 @@ class App(QtCore.QObject): App.log.debug(obj['kind'] + ": " + obj['options']['name']) self.new_object(obj['kind'], obj['options']['name'], obj_init, active=False, fit=False, plot=True) self.plot_all() - self.inform.emit("[success] Project loaded from: " + filename) + self.inform.emit(_tr("[success] Project loaded from: %s") % filename) self.should_we_save = False @@ -6920,9 +6939,9 @@ class App(QtCore.QObject): def shelp(p=None): if not p: - return "Available commands:\n" + \ + return _tr("Available commands:\n") + \ '\n'.join([' ' + cmd for cmd in sorted(commands)]) + \ - "\n\nType help for usage.\n Example: help open_gerber" + _tr("\n\nType help for usage.\n Example: help open_gerber") if p not in commands: return "Unknown command: %s" % p @@ -7070,7 +7089,7 @@ class App(QtCore.QObject): commands = { 'help': { 'fcn': shelp, - 'help': "Shows list of commands." + 'help': _tr("Shows list of commands.") }, } @@ -7123,14 +7142,14 @@ class App(QtCore.QObject): f = open(self.data_path + '/recent.json') except IOError: App.log.error("Failed to load recent item list.") - self.inform.emit("[ERROR_NOTCL] Failed to load recent item list.") + self.inform.emit(_tr("[ERROR_NOTCL] Failed to load recent item list.")) return try: self.recent = json.load(f) except json.scanner.JSONDecodeError: App.log.error("Failed to parse recent item list.") - self.inform.emit("[ERROR_NOTCL] Failed to parse recent item list.") + self.inform.emit(_tr("[ERROR_NOTCL] Failed to parse recent item list.")) f.close() return f.close() @@ -7191,14 +7210,14 @@ class App(QtCore.QObject): # label.setAlignment(QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter) sel_title = QtWidgets.QTextEdit( - 'Shortcut Key List') + _tr('Shortcut Key List')) sel_title.setTextInteractionFlags(QtCore.Qt.NoTextInteraction) sel_title.setFrameStyle(QtWidgets.QFrame.NoFrame) # font = self.sel_title.font() # font.setPointSize(12) # self.sel_title.setFont(font) - selected_text = ''' + selected_text = _tr('''

Selected Tab - Choose an Item from Project Tab

Details:
@@ -7220,7 +7239,7 @@ The normal flow when working in FlatCAM is the following:

A list of key shortcuts is available through an menu entry in Help -> Shortcuts List or through it's own key shortcut: F3.

- ''' + ''') sel_title.setText(selected_text) sel_title.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding) @@ -7302,14 +7321,14 @@ The normal flow when working in FlatCAM is the following:

except: # App.log.warning("Failed checking for latest version. Could not connect.") self.log.warning("Failed checking for latest version. Could not connect.") - self.inform.emit("[WARNING_NOTCL] Failed checking for latest version. Could not connect.") + self.inform.emit(_tr("[WARNING_NOTCL] Failed checking for latest version. Could not connect.")) return try: data = json.load(f) except Exception as e: App.log.error("Could not parse information about latest version.") - self.inform.emit("[ERROR_NOTCL] Could not parse information about latest version.") + self.inform.emit(_tr("[ERROR_NOTCL] Could not parse information about latest version.")) App.log.debug("json.load(): %s" % str(e)) f.close() return @@ -7319,16 +7338,15 @@ The normal flow when working in FlatCAM is the following:

### Latest version? if self.version >= data["version"]: App.log.debug("FlatCAM is up to date!") - self.inform.emit("[success] FlatCAM is up to date!") + self.inform.emit(_tr("[success] FlatCAM is up to date!")) return App.log.debug("Newer version available.") self.message.emit( - "Newer Version Available", - str("There is a newer version of FlatCAM " + - "available for download:

" + - "" + data["name"] + "
" + - data["message"].replace("\n", "
")), + _tr("Newer Version Available"), + _tr("There is a newer version of FlatCAM available for download:

%s
%s" % ( + str(data["name"]), str(data["message"])) + ), "info" ) @@ -7348,19 +7366,19 @@ The normal flow when working in FlatCAM is the following:

self.report_usage("disable_all_plots()") self.disable_plots(self.collection.get_list()) - self.inform.emit("[success]All plots disabled.") + self.inform.emit(_tr("[success]All plots disabled.")) def disable_other_plots(self): self.report_usage("disable_other_plots()") self.disable_plots(self.collection.get_non_selected()) - self.inform.emit("[success]All non selected plots disabled.") + self.inform.emit(_tr("[success]All non selected plots disabled.")) def enable_all_plots(self): self.report_usage("enable_all_plots()") self.enable_plots(self.collection.get_list()) - self.inform.emit("[success]All plots enabled.") + self.inform.emit(_tr("[success]All plots enabled.")) # TODO: FIX THIS ''' @@ -7470,13 +7488,13 @@ The normal flow when working in FlatCAM is the following:

""" self.log.debug("save_project()") - with self.proc_container.new("Saving FlatCAM Project") as proc: + with self.proc_container.new(_tr("Saving FlatCAM Project")) as proc: ## Capture the latest changes # Current object try: self.collection.get_active().read_form() except: - self.log.debug("[WARNING] There was no active object") + self.log.debug("There was no active object") pass # Project options self.options_read_form() @@ -7491,13 +7509,13 @@ The normal flow when working in FlatCAM is the following:

g = json.dumps(d, default=to_dict, indent=2, sort_keys=True).encode('utf-8') # # Write f.write(g) - self.inform.emit("[success] Project saved to: %s" % filename) + self.inform.emit(_tr("[success] Project saved to: %s") % filename) else: # Open file try: f = open(filename, 'w') except IOError: - App.log.error("[ERROR] Failed to open file for saving: %s", filename) + App.log.error("Failed to open file for saving: %s", filename) return # Write @@ -7509,22 +7527,22 @@ The normal flow when working in FlatCAM is the following:

try: saved_f = open(filename, 'r') except IOError: - self.inform.emit("[ERROR_NOTCL] Failed to verify project file: %s. Retry to save it." % filename) + self.inform.emit(_tr("[ERROR_NOTCL] Failed to verify project file: %s. Retry to save it.") % filename) return try: saved_d = json.load(saved_f, object_hook=dict2obj) except: self.inform.emit( - "[ERROR_NOTCL] Failed to parse saved project file: %s. Retry to save it." % filename) + _tr("[ERROR_NOTCL] Failed to parse saved project file: %s. Retry to save it.") % filename) f.close() return saved_f.close() if 'version' in saved_d: - self.inform.emit("[success] Project saved to: %s" % filename) + self.inform.emit(_tr("[success] Project saved to: %s") % filename) else: - self.inform.emit("[ERROR_NOTCL] Failed to save project file: %s. Retry to save it." % filename) + self.inform.emit(_tr("[ERROR_NOTCL] Failed to save project file: %s. Retry to save it.") % filename) def on_options_app2project(self): """ @@ -7567,7 +7585,7 @@ The normal flow when working in FlatCAM is the following:

self.options_read_form() obj = self.collection.get_active() if obj is None: - self.inform.emit("WARNING: No object selected.") + self.inform.emit(_tr("[WARNING_NOTCL] No object selected.")) return for option in self.options: if option.find(obj.kind + "_") == 0: @@ -7587,7 +7605,7 @@ The normal flow when working in FlatCAM is the following:

obj = self.collection.get_active() if obj is None: - self.inform.emit("WARNING: No object selected.") + self.inform.emit(_tr("[WARNING_NOTCL] No object selected.")) return obj.read_form() for option in obj.options: @@ -7608,7 +7626,7 @@ The normal flow when working in FlatCAM is the following:

obj = self.collection.get_active() if obj is None: - self.inform.emit("WARNING: No object selected.") + self.inform.emit(_tr("[WARNING_NOTCL] No object selected.")) return obj.read_form() for option in obj.options: @@ -7630,7 +7648,7 @@ The normal flow when working in FlatCAM is the following:

self.defaults_read_form() obj = self.collection.get_active() if obj is None: - self.inform.emit("WARNING: No object selected.") + self.inform.emit(_tr("[WARNING_NOTCL] No object selected.")) return for option in self.defaults: if option.find(obj.kind + "_") == 0: diff --git a/FlatCAMEditor.py b/FlatCAMEditor.py index dc1b75ce..15324f27 100644 --- a/FlatCAMEditor.py +++ b/FlatCAMEditor.py @@ -38,6 +38,13 @@ import FlatCAMTranslation as fcTranslate fcTranslate.apply_language('FlatCAMEditor') +def _tr(text): + try: + return _(text) + except: + return text + + class BufferSelectionTool(FlatCAMTool): """ Simple input for buffer distance. diff --git a/FlatCAMGUI.py b/FlatCAMGUI.py index d012f4c8..8ecf6e0c 100644 --- a/FlatCAMGUI.py +++ b/FlatCAMGUI.py @@ -16,7 +16,14 @@ from FlatCAMEditor import FCShapeTool import gettext import FlatCAMTranslation as fcTranslate -fcTranslate.apply_language('FlatCAMGui') +fcTranslate.apply_language('FlatCAMGUI') + + +def _tr(text): + try: + return _(text) + except: + return text class FlatCAMGUI(QtWidgets.QMainWindow): diff --git a/FlatCAMObj.py b/FlatCAMObj.py index 2a4e028b..c6511f13 100644 --- a/FlatCAMObj.py +++ b/FlatCAMObj.py @@ -27,6 +27,13 @@ import FlatCAMTranslation as fcTranslate fcTranslate.apply_language('FlatCAMObj') +def _tr(text): + try: + return _(text) + except: + return text + + class ObjectDeleted(Exception): # Interrupts plotting process if FlatCAMObj has been deleted pass diff --git a/ObjectCollection.py b/ObjectCollection.py index b3182cdb..78fe321d 100644 --- a/ObjectCollection.py +++ b/ObjectCollection.py @@ -19,6 +19,13 @@ import FlatCAMTranslation as fcTranslate fcTranslate.apply_language('ObjectCollection') +def _tr(text): + try: + return _(text) + except: + return text + + class KeySensitiveListView(QtWidgets.QTreeView): """ QtGui.QListView extended to emit a signal on key press. diff --git a/ObjectUI.py b/ObjectUI.py index 0c2e05d0..88fd8e90 100644 --- a/ObjectUI.py +++ b/ObjectUI.py @@ -10,6 +10,13 @@ import FlatCAMTranslation as fcTranslate fcTranslate.apply_language('ObjectUI') +def _tr(text): + try: + return _(text) + except: + return text + + class ObjectUI(QtWidgets.QWidget): """ Base class for the UI of FlatCAM objects. Deriving classes should diff --git a/README.md b/README.md index 9f2b90c9..8f5bc333 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,12 @@ CAD program, and create G-Code for Isolation routing. ================================================= +8.03.2019 + +- 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 +- + 7.03.2019 - made showing a shape when hovering over objects, optional, by adding a Preferences -> General parameter diff --git a/camlib.py b/camlib.py index 7bee87d7..b54b67fc 100644 --- a/camlib.py +++ b/camlib.py @@ -62,16 +62,25 @@ if platform.architecture()[0] == '64bit': from ortools.constraint_solver import pywrapcp from ortools.constraint_solver import routing_enums_pb2 - log = logging.getLogger('base2') log.setLevel(logging.DEBUG) -# log.setLevel(logging.WARNING) -# log.setLevel(logging.INFO) + formatter = logging.Formatter('[%(levelname)s] %(message)s') handler = logging.StreamHandler() handler.setFormatter(formatter) log.addHandler(handler) +import gettext +import FlatCAMTranslation as fcTranslate +fcTranslate.apply_language('camlib') + + +def _tr(text): + try: + return _(text) + except: + return text + class ParseError(Exception): pass diff --git a/flatcamTools/ToolCalculators.py b/flatcamTools/ToolCalculators.py index 6294a0f6..3f5cbc5d 100644 --- a/flatcamTools/ToolCalculators.py +++ b/flatcamTools/ToolCalculators.py @@ -9,12 +9,19 @@ import FlatCAMTranslation as fcTranslate fcTranslate.apply_language('ToolCalculators') +def _tr(text): + try: + return _(text) + except: + return text + + class ToolCalculator(FlatCAMTool): - toolName = _("Calculators") - v_shapeName = _("V-Shape Tool Calculator") - unitsName = _("Units Calculator") - eplateName = _("ElectroPlating Calculator") + toolName = _tr("Calculators") + v_shapeName = _tr("V-Shape Tool Calculator") + unitsName = _tr("Units Calculator") + eplateName = _tr("ElectroPlating Calculator") def __init__(self, app): FlatCAMTool.__init__(self, app) @@ -55,12 +62,12 @@ class ToolCalculator(FlatCAMTool): self.inch_entry = FCEntry() # self.inch_entry.setFixedWidth(70) self.inch_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) - self.inch_entry.setToolTip(_("Here you enter the value to be converted from INCH to MM")) + self.inch_entry.setToolTip(_tr("Here you enter the value to be converted from INCH to MM")) self.mm_entry = FCEntry() # self.mm_entry.setFixedWidth(130) self.mm_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) - self.mm_entry.setToolTip(_("Here you enter the value to be converted from MM to INCH")) + self.mm_entry.setToolTip(_tr("Here you enter the value to be converted from MM to INCH")) grid_units_layout.addWidget(self.mm_entry, 1, 0) grid_units_layout.addWidget(self.inch_entry, 1, 1) @@ -81,32 +88,32 @@ class ToolCalculator(FlatCAMTool): form_layout = QtWidgets.QFormLayout() self.layout.addLayout(form_layout) - self.tipDia_label = QtWidgets.QLabel(_("Tip Diameter:")) + self.tipDia_label = QtWidgets.QLabel(_tr("Tip Diameter:")) self.tipDia_entry = FCEntry() # self.tipDia_entry.setFixedWidth(70) self.tipDia_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) - self.tipDia_label.setToolTip(_('This is the diameter of the tool tip.\n' + self.tipDia_label.setToolTip(_tr('This is the diameter of the tool tip.\n' 'The manufacturer specifies it.')) self.tipAngle_label = QtWidgets.QLabel("Tip Angle:") self.tipAngle_entry = FCEntry() # self.tipAngle_entry.setFixedWidth(70) self.tipAngle_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) - self.tipAngle_label.setToolTip(_("This is the angle of the tip of the tool.\n" + self.tipAngle_label.setToolTip(_tr("This is the angle of the tip of the tool.\n" "It is specified by manufacturer.")) self.cutDepth_label = QtWidgets.QLabel("Cut Z:") self.cutDepth_entry = FCEntry() # self.cutDepth_entry.setFixedWidth(70) self.cutDepth_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) - self.cutDepth_label.setToolTip(_("This is the depth to cut into the material.\n" + self.cutDepth_label.setToolTip(_tr("This is the depth to cut into the material.\n" "In the CNCJob is the CutZ parameter.")) self.effectiveToolDia_label = QtWidgets.QLabel("Tool Diameter:") self.effectiveToolDia_entry = FCEntry() # self.effectiveToolDia_entry.setFixedWidth(70) self.effectiveToolDia_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) - self.effectiveToolDia_label.setToolTip(_("This is the tool diameter to be entered into\n" + self.effectiveToolDia_label.setToolTip(_tr("This is the tool diameter to be entered into\n" "FlatCAM Gerber section.\n" "In the CNCJob section it is called >Tool dia<.")) # self.effectiveToolDia_entry.setEnabled(False) @@ -118,10 +125,10 @@ class ToolCalculator(FlatCAMTool): form_layout.addRow(self.effectiveToolDia_label, self.effectiveToolDia_entry) ## Buttons - self.calculate_vshape_button = QtWidgets.QPushButton(_("Calculate")) + self.calculate_vshape_button = QtWidgets.QPushButton(_tr("Calculate")) # self.calculate_button.setFixedWidth(70) self.calculate_vshape_button.setToolTip( - _("Calculate either the Cut Z or the effective tool diameter,\n " + _tr("Calculate either the Cut Z or the effective tool diameter,\n " "depending on which is desired and which is known. ") ) self.empty_label = QtWidgets.QLabel(" ") @@ -139,7 +146,7 @@ class ToolCalculator(FlatCAMTool): ## Title of the ElectroPlating Tools Calculator plate_title_label = QtWidgets.QLabel("%s" % self.eplateName) plate_title_label.setToolTip( - _("This calculator is useful for those who plate the via/pad/drill holes,\n" + _tr("This calculator is useful for those who plate the via/pad/drill holes,\n" "using a method like grahite ink or calcium hypophosphite ink or palladium chloride.") ) self.layout.addWidget(plate_title_label) @@ -148,48 +155,48 @@ class ToolCalculator(FlatCAMTool): plate_form_layout = QtWidgets.QFormLayout() self.layout.addLayout(plate_form_layout) - self.pcblengthlabel = QtWidgets.QLabel(_("Board Length:")) + self.pcblengthlabel = QtWidgets.QLabel(_tr("Board Length:")) self.pcblength_entry = FCEntry() # self.pcblengthlabel.setFixedWidth(70) self.pcblength_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) - self.pcblengthlabel.setToolTip(_('This is the board length. In centimeters.')) + self.pcblengthlabel.setToolTip(_tr('This is the board length. In centimeters.')) - self.pcbwidthlabel = QtWidgets.QLabel(_("Board Width:")) + self.pcbwidthlabel = QtWidgets.QLabel(_tr("Board Width:")) self.pcbwidth_entry = FCEntry() # self.pcbwidthlabel.setFixedWidth(70) self.pcbwidth_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) - self.pcbwidthlabel.setToolTip(_('This is the board width.In centimeters.')) + self.pcbwidthlabel.setToolTip(_tr('This is the board width.In centimeters.')) - self.cdensity_label = QtWidgets.QLabel(_("Current Density:")) + self.cdensity_label = QtWidgets.QLabel(_tr("Current Density:")) self.cdensity_entry = FCEntry() # self.cdensity_entry.setFixedWidth(70) self.cdensity_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) - self.cdensity_label.setToolTip(_("Current density to pass through the board. \n" + self.cdensity_label.setToolTip(_tr("Current density to pass through the board. \n" "In Amps per Square Feet ASF.")) - self.growth_label = QtWidgets.QLabel(_("Copper Growth:")) + self.growth_label = QtWidgets.QLabel(_tr("Copper Growth:")) self.growth_entry = FCEntry() # self.growth_entry.setFixedWidth(70) self.growth_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) - self.growth_label.setToolTip(_("How thick the copper growth is intended to be.\n" + self.growth_label.setToolTip(_tr("How thick the copper growth is intended to be.\n" "In microns.")) # self.growth_entry.setEnabled(False) - self.cvaluelabel = QtWidgets.QLabel(_("Current Value:")) + self.cvaluelabel = QtWidgets.QLabel(_tr("Current Value:")) self.cvalue_entry = FCEntry() # self.cvaluelabel.setFixedWidth(70) self.cvalue_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) - self.cvaluelabel.setToolTip(_('This is the current intensity value\n' + self.cvaluelabel.setToolTip(_tr('This is the current intensity value\n' 'to be set on the Power Supply. In Amps.')) self.cvalue_entry.setDisabled(True) - self.timelabel = QtWidgets.QLabel(_("Time:")) + self.timelabel = QtWidgets.QLabel(_tr("Time:")) self.time_entry = FCEntry() # self.timelabel.setFixedWidth(70) self.time_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) - self.timelabel.setToolTip(_('This is the calculated time required for the procedure.\n' + self.timelabel.setToolTip(_tr('This is the calculated time required for the procedure.\n' 'In minutes.')) self.time_entry.setDisabled(True) @@ -201,10 +208,10 @@ class ToolCalculator(FlatCAMTool): plate_form_layout.addRow(self.timelabel, self.time_entry) ## Buttons - self.calculate_plate_button = QtWidgets.QPushButton(_("Calculate")) + self.calculate_plate_button = QtWidgets.QPushButton(_tr("Calculate")) # self.calculate_button.setFixedWidth(70) self.calculate_plate_button.setToolTip( - _("Calculate the current intensity value and the procedure time,\n " + _tr("Calculate the current intensity value and the procedure time,\n " "depending on the parameters above") ) self.empty_label_2 = QtWidgets.QLabel(" ") @@ -291,7 +298,7 @@ class ToolCalculator(FlatCAMTool): try: tip_diameter = float(self.tipDia_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 @@ -302,7 +309,7 @@ class ToolCalculator(FlatCAMTool): try: half_tip_angle = float(self.tipAngle_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 half_tip_angle /= 2 @@ -314,7 +321,7 @@ class ToolCalculator(FlatCAMTool): try: cut_depth = float(self.cutDepth_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 @@ -329,7 +336,7 @@ class ToolCalculator(FlatCAMTool): try: mm_val = float(self.mm_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 self.inch_entry.set_value('%.6f' % (mm_val / 25.4)) @@ -342,7 +349,7 @@ class ToolCalculator(FlatCAMTool): try: inch_val = float(self.inch_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 self.mm_entry.set_value('%.6f' % (inch_val * 25.4)) @@ -356,7 +363,7 @@ class ToolCalculator(FlatCAMTool): try: length = float(self.pcblength_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 @@ -367,7 +374,7 @@ class ToolCalculator(FlatCAMTool): try: width = float(self.pcbwidth_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 @@ -378,7 +385,7 @@ class ToolCalculator(FlatCAMTool): try: density = float(self.cdensity_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 @@ -389,7 +396,7 @@ class ToolCalculator(FlatCAMTool): try: copper = float(self.growth_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 diff --git a/flatcamTools/ToolCutOut.py b/flatcamTools/ToolCutOut.py index 903950cd..449d444e 100644 --- a/flatcamTools/ToolCutOut.py +++ b/flatcamTools/ToolCutOut.py @@ -8,9 +8,16 @@ import FlatCAMTranslation as fcTranslate fcTranslate.apply_language('ToolCutOut') +def _tr(text): + try: + return _(text) + except: + return text + + class CutOut(FlatCAMTool): - toolName = _("Cutout PCB") + toolName = _tr("Cutout PCB") gapFinished = pyqtSignal() def __init__(self, app): @@ -46,9 +53,9 @@ 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(_tr("Obj Type:")) self.type_obj_combo_label.setToolTip( - _("Specify the type of object to be cutout.\n" + _tr("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.") @@ -62,26 +69,26 @@ 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(_tr("Object:")) self.object_label.setToolTip( - _("Object to be cutout. ") + _tr("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(_tr("Tool Dia:")) self.dia_label.setToolTip( - _( "Diameter of the tool used to cutout\n" + _tr( "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(_tr("Margin:")) self.margin_label.setToolTip( - _( "Margin over bounds. A positive value here\n" + _tr( "Margin over bounds. A positive value here\n" "will make the cutout of the PCB further from\n" "the actual PCB border") ) @@ -89,9 +96,9 @@ class CutOut(FlatCAMTool): # Gapsize self.gapsize = FCEntry() - self.gapsize_label = QtWidgets.QLabel(_("Gap size:")) + self.gapsize_label = QtWidgets.QLabel(_tr("Gap size:")) self.gapsize_label.setToolTip( - _( "The size of the bridge gaps in the cutout\n" + _tr( "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).") @@ -107,9 +114,9 @@ class CutOut(FlatCAMTool): # 8 - 2*left + 2*right +2*top + 2*bottom ## Title2 - title_param_label = QtWidgets.QLabel("%s" % _('A. Automatic Bridge Gaps')) + title_param_label = QtWidgets.QLabel("%s" % _tr('A. Automatic Bridge Gaps')) title_param_label.setToolTip( - _("This section handle creation of automatic bridge gaps.") + _tr("This section handle creation of automatic bridge gaps.") ) self.layout.addWidget(title_param_label) @@ -118,9 +125,9 @@ class CutOut(FlatCAMTool): self.layout.addLayout(form_layout_2) # Gaps - gaps_label = QtWidgets.QLabel(_('Gaps:')) + gaps_label = QtWidgets.QLabel(_tr('Gaps:')) gaps_label.setToolTip( - _("Number of gaps used for the Automatic cutout.\n" + _tr("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" @@ -143,18 +150,18 @@ class CutOut(FlatCAMTool): hlay = QtWidgets.QHBoxLayout() self.layout.addLayout(hlay) - title_ff_label = QtWidgets.QLabel("%s" % _('FreeForm:')) + title_ff_label = QtWidgets.QLabel("%s" % _tr('FreeForm:')) title_ff_label.setToolTip( - _("The cutout shape can be of ny shape.\n" + _tr("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(_tr("Generate Geo")) self.ff_cutout_object_btn.setToolTip( - _("Cutout the selected object.\n" + _tr("Cutout the selected object.\n" "The cutout shape can be of any shape.\n" "Useful when the PCB has a non-rectangular shape.") ) @@ -163,18 +170,18 @@ class CutOut(FlatCAMTool): hlay2 = QtWidgets.QHBoxLayout() self.layout.addLayout(hlay2) - title_rct_label = QtWidgets.QLabel("%s" % _('Rectangular:')) + title_rct_label = QtWidgets.QLabel("%s" % _tr('Rectangular:')) title_rct_label.setToolTip( - _("The resulting cutout shape is\n" + _tr("The resulting cutout shape is\n" "always a rectangle shape and it will be\n" "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(_tr("Generate Geo")) self.rect_cutout_object_btn.setToolTip( - _("Cutout the selected object.\n" + _tr("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.") @@ -182,9 +189,9 @@ class CutOut(FlatCAMTool): hlay2.addWidget(self.rect_cutout_object_btn) ## Title5 - title_manual_label = QtWidgets.QLabel("%s" % _('B. Manual Bridge Gaps')) + title_manual_label = QtWidgets.QLabel("%s" % _tr('B. Manual Bridge Gaps')) title_manual_label.setToolTip( - _("This section handle creation of manual bridge gaps.\n" + _tr("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. ") ) @@ -200,9 +207,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(_tr("Geo Obj:")) self.man_object_label.setToolTip( - _("Geometry object used to create the manual cutout.") + _tr("Geometry object used to create the manual cutout.") ) self.man_object_label.setFixedWidth(60) # e_lab_0 = QtWidgets.QLabel('') @@ -213,9 +220,9 @@ class CutOut(FlatCAMTool): hlay3 = QtWidgets.QHBoxLayout() self.layout.addLayout(hlay3) - self.man_geo_label = QtWidgets.QLabel(_("Manual Geo:")) + self.man_geo_label = QtWidgets.QLabel(_tr("Manual Geo:")) self.man_geo_label.setToolTip( - _("If the object to be cutout is a Gerber\n" + _tr("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.") @@ -223,9 +230,9 @@ class CutOut(FlatCAMTool): hlay3.addWidget(self.man_geo_label) hlay3.addStretch() - self.man_geo_creation_btn = QtWidgets.QPushButton(_("Generate Geo")) + self.man_geo_creation_btn = QtWidgets.QPushButton(_tr("Generate Geo")) self.man_geo_creation_btn.setToolTip( - _("If the object to be cutout is a Gerber\n" + _tr("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.") @@ -235,18 +242,18 @@ class CutOut(FlatCAMTool): 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(_tr("Manual Add Bridge Gaps:")) self.man_bridge_gaps_label.setToolTip( - _("Use the left mouse button (LMB) click\n" + _tr("Use the left mouse button (LMB) click\n" "to create a bridge gap to separate the PCB from\n" "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(_tr("Generate Gap")) self.man_gaps_creation_btn.setToolTip( - _("Use the left mouse button (LMB) click\n" + _tr("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" @@ -319,11 +326,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(_tr("[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(_tr("[ERROR_NOTCL]There is no object selected for Cutout.\nSelect one and try again.")) return try: @@ -333,13 +340,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. " + self.app.inform.emit(_tr("[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(_tr("[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: @@ -349,7 +356,7 @@ 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. " + self.app.inform.emit(_tr("[WARNING_NOTCL] Margin value is missing or wrong format. " "Add it and retry.")) return @@ -360,23 +367,23 @@ 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. " + self.app.inform.emit(_tr("[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(_tr("[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. " + self.app.inform.emit(_tr("[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(_tr("[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.")) return @@ -442,7 +449,7 @@ class CutOut(FlatCAMTool): ymax + gapsize) cutout_obj.plot() - self.app.inform.emit(_("[success] Any form CutOut operation finished.")) + self.app.inform.emit(_tr("[success] Any form CutOut operation finished.")) self.app.ui.notebook.setCurrentWidget(self.app.ui.project_tab) self.app.should_we_save = True @@ -458,11 +465,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(_tr("[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(_tr("[ERROR_NOTCL]Object not found: %s") % cutout_obj) try: dia = float(self.dia.get_value()) @@ -471,12 +478,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. " + self.app.inform.emit(_tr("[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(_tr("[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: @@ -486,7 +493,7 @@ 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. " + self.app.inform.emit(_tr("[WARNING_NOTCL] Margin value is missing or wrong format. " "Add it and retry.")) return @@ -497,23 +504,23 @@ 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. " + self.app.inform.emit(_tr("[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(_tr("[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. " + self.app.inform.emit(_tr("[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(_tr("[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.")) return @@ -576,12 +583,12 @@ class CutOut(FlatCAMTool): ymax + gapsize) cutout_obj.plot() - self.app.inform.emit(_("[success] Any form CutOut operation finished.")) + self.app.inform.emit(_tr("[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(_tr("Click on the selected geometry object perimeter to create a bridge gap ...")) self.app.geo_editor.tool_shape.enabled = True try: @@ -591,12 +598,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. " + self.app.inform.emit(_tr("[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(_tr("[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: @@ -606,7 +613,7 @@ 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. " + self.app.inform.emit(_tr("[WARNING_NOTCL] Gap size value is missing or wrong format. " "Add it and retry.")) return @@ -622,7 +629,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(_tr("Making manual bridge gap...")) pos = self.app.plotcanvas.vispy_canvas.translate_coords(event.pos) self.on_manual_cutout(click_pos=pos) @@ -645,11 +652,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(_tr("[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(_tr("[ERROR_NOTCL]Geometry object for manual cutout not found: %s") % cutout_obj) return # use the snapped position as reference @@ -659,7 +666,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(_tr("[success] Added manual Bridge Gap.")) self.app.should_we_save = True @@ -676,16 +683,16 @@ 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(_tr("[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" + self.app.inform.emit(_tr("[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" + self.app.inform.emit(_tr("[ERROR_NOTCL]The selected object has to be of Gerber type.\n" "Select a Gerber file and try again.")) return @@ -696,12 +703,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. " + self.app.inform.emit(_tr("[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(_tr("[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: @@ -711,7 +718,7 @@ 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. " + self.app.inform.emit(_tr("[WARNING_NOTCL] Margin value is missing or wrong format. " "Add it and retry.")) return diff --git a/flatcamTools/ToolDblSided.py b/flatcamTools/ToolDblSided.py index 3e00ffae..3a3d817e 100644 --- a/flatcamTools/ToolDblSided.py +++ b/flatcamTools/ToolDblSided.py @@ -11,9 +11,16 @@ import FlatCAMTranslation as fcTranslate fcTranslate.apply_language('ToolDblSided') +def _tr(text): + try: + return _(text) + except: + return text + + class DblSidedTool(FlatCAMTool): - toolName = _("2-Sided PCB") + toolName = _tr("2-Sided PCB") def __init__(self, app): FlatCAMTool.__init__(self, app) @@ -47,9 +54,9 @@ class DblSidedTool(FlatCAMTool): "Gerber to be mirrored." ) - self.mirror_gerber_button = QtWidgets.QPushButton(_("Mirror")) + self.mirror_gerber_button = QtWidgets.QPushButton(_tr("Mirror")) self.mirror_gerber_button.setToolTip( - _("Mirrors (flips) the specified object around \n" + _tr("Mirrors (flips) the specified object around \n" "the specified axis. Does not create a new \n" "object, but modifies it.") ) @@ -68,12 +75,12 @@ class DblSidedTool(FlatCAMTool): self.excobj_label = QtWidgets.QLabel("EXCELLON:") self.excobj_label.setToolTip( - _("Excellon Object to be mirrored.") + _tr("Excellon Object to be mirrored.") ) - self.mirror_exc_button = QtWidgets.QPushButton(_("Mirror")) + self.mirror_exc_button = QtWidgets.QPushButton(_tr("Mirror")) self.mirror_exc_button.setToolTip( - _("Mirrors (flips) the specified object around \n" + _tr("Mirrors (flips) the specified object around \n" "the specified axis. Does not create a new \n" "object, but modifies it.") ) @@ -92,12 +99,12 @@ class DblSidedTool(FlatCAMTool): self.geoobj_label = QtWidgets.QLabel("GEOMETRY:") self.geoobj_label.setToolTip( - _("Geometry Obj to be mirrored.") + _tr("Geometry Obj to be mirrored.") ) - self.mirror_geo_button = QtWidgets.QPushButton(_("Mirror")) + self.mirror_geo_button = QtWidgets.QPushButton(_tr("Mirror")) self.mirror_geo_button.setToolTip( - _("Mirrors (flips) the specified object around \n" + _tr("Mirrors (flips) the specified object around \n" "the specified axis. Does not create a new \n" "object, but modifies it.") ) @@ -111,9 +118,9 @@ class DblSidedTool(FlatCAMTool): ## Axis self.mirror_axis = RadioSet([{'label': 'X', 'value': 'X'}, {'label': 'Y', 'value': 'Y'}]) - self.mirax_label = QtWidgets.QLabel(_("Mirror Axis:")) + self.mirax_label = QtWidgets.QLabel(_tr("Mirror Axis:")) self.mirax_label.setToolTip( - _("Mirror vertically (X) or horizontally (Y).") + _tr("Mirror vertically (X) or horizontally (Y).") ) # grid_lay.addRow("Mirror Axis:", self.mirror_axis) self.empty_lb1 = QtWidgets.QLabel("") @@ -124,9 +131,9 @@ class DblSidedTool(FlatCAMTool): ## Axis Location self.axis_location = RadioSet([{'label': 'Point', 'value': 'point'}, {'label': 'Box', 'value': 'box'}]) - self.axloc_label = QtWidgets.QLabel(_("Axis Ref:")) + self.axloc_label = QtWidgets.QLabel(_tr("Axis Ref:")) self.axloc_label.setToolTip( - _("The axis should pass through a point or cut\n " + _tr("The axis should pass through a point or cut\n " "a specified box (in a FlatCAM object) through \n" "the center.") ) @@ -139,17 +146,17 @@ class DblSidedTool(FlatCAMTool): ## Point/Box self.point_box_container = QtWidgets.QVBoxLayout() - self.pb_label = QtWidgets.QLabel("%s" % _('Point/Box Reference:')) + self.pb_label = QtWidgets.QLabel("%s" % _tr('Point/Box Reference:')) self.pb_label.setToolTip( - _("If 'Point' is selected above it store the coordinates (x, y) through which\n" + _tr("If 'Point' is selected above it store the coordinates (x, y) through which\n" "the mirroring axis passes.\n" "If 'Box' is selected above, select here a FlatCAM object (Gerber, Exc or Geo).\n" "Through the center of this object pass the mirroring axis selected above.") ) - self.add_point_button = QtWidgets.QPushButton(_("Add")) + self.add_point_button = QtWidgets.QPushButton(_tr("Add")) self.add_point_button.setToolTip( - _("Add the coordinates in format (x, y) through which the mirroring axis \n " + _tr("Add the coordinates in format (x, y) through which the mirroring axis \n " "selected in 'MIRROR AXIS' pass.\n" "The (x, y) coordinates are captured by pressing SHIFT key\n" "and left mouse button click on canvas or you can enter the coords manually.") @@ -169,9 +176,9 @@ class DblSidedTool(FlatCAMTool): self.box_combo.setCurrentIndex(1) self.box_combo_type = QtWidgets.QComboBox() - self.box_combo_type.addItem(_("Gerber Reference Box Object")) - self.box_combo_type.addItem(_("Excellon Reference Box Object")) - self.box_combo_type.addItem(_("Geometry Reference Box Object")) + self.box_combo_type.addItem(_tr("Gerber Reference Box Object")) + self.box_combo_type.addItem(_tr("Excellon Reference Box Object")) + self.box_combo_type.addItem(_tr("Geometry Reference Box Object")) self.point_box_container.addWidget(self.box_combo_type) self.point_box_container.addWidget(self.box_combo) @@ -180,9 +187,9 @@ class DblSidedTool(FlatCAMTool): ## Alignment holes - self.ah_label = QtWidgets.QLabel("" % _('>Alignment Drill Coordinates:')) + self.ah_label = QtWidgets.QLabel("" % _tr('>Alignment Drill Coordinates:')) self.ah_label.setToolTip( - _( "Alignment holes (x1, y1), (x2, y2), ... " + _tr( "Alignment holes (x1, y1), (x2, y2), ... " "on one side of the mirror axis. For each set of (x, y) coordinates\n" "entered here, a pair of drills will be created:\n\n" "- one drill at the coordinates from the field\n" @@ -195,9 +202,9 @@ class DblSidedTool(FlatCAMTool): self.alignment_holes = EvalEntry() - self.add_drill_point_button = QtWidgets.QPushButton(_("Add")) + self.add_drill_point_button = QtWidgets.QPushButton(_tr("Add")) self.add_drill_point_button.setToolTip( - _("Add alignment drill holes coords in the format: (x1, y1), (x2, y2), ... \n" + _tr("Add alignment drill holes coords in the format: (x1, y1), (x2, y2), ... \n" "on one side of the mirror axis.\n\n" "The coordinates set can be obtained:\n" "- press SHIFT key and left mouse clicking on canvas. Then click Add.\n" @@ -211,9 +218,9 @@ class DblSidedTool(FlatCAMTool): grid_lay1.addWidget(self.add_drill_point_button, 0, 3) ## Drill diameter for alignment holes - self.dt_label = QtWidgets.QLabel("%s:" % _('Alignment Drill Diameter')) + self.dt_label = QtWidgets.QLabel("%s:" % _tr('Alignment Drill Diameter')) self.dt_label.setToolTip( - _("Diameter of the drill for the " + _tr("Diameter of the drill for the " "alignment holes.") ) self.layout.addWidget(self.dt_label) @@ -222,27 +229,27 @@ class DblSidedTool(FlatCAMTool): self.layout.addLayout(grid_lay2) self.drill_dia = FCEntry() - self.dd_label = QtWidgets.QLabel(_("Drill diam.:")) + self.dd_label = QtWidgets.QLabel(_tr("Drill diam.:")) self.dd_label.setToolTip( - _("Diameter of the drill for the " + _tr("Diameter of the drill for the " "alignment holes.") ) grid_lay2.addWidget(self.dd_label, 0, 0) grid_lay2.addWidget(self.drill_dia, 0, 1) ## Buttons - self.create_alignment_hole_button = QtWidgets.QPushButton(_("Create Excellon Object")) + self.create_alignment_hole_button = QtWidgets.QPushButton(_tr("Create Excellon Object")) self.create_alignment_hole_button.setToolTip( - _("Creates an Excellon Object containing the\n" + _tr("Creates an Excellon Object containing the\n" "specified alignment holes and their mirror\n" "images.") ) # self.create_alignment_hole_button.setFixedWidth(40) grid_lay2.addWidget(self.create_alignment_hole_button, 1,0, 1, 2) - self.reset_button = QtWidgets.QPushButton(_("Reset")) + self.reset_button = QtWidgets.QPushButton(_tr("Reset")) self.reset_button.setToolTip( - _("Resets all the fields.") + _tr("Resets all the fields.") ) self.reset_button.setFixedWidth(40) grid_lay2.addWidget(self.reset_button, 1, 2) @@ -284,7 +291,7 @@ class DblSidedTool(FlatCAMTool): FlatCAMTool.run(self) self.set_tool_ui() - self.app.ui.notebook.setTabText(2, _("2-Sided Tool")) + self.app.ui.notebook.setTabText(2, _tr("2-Sided Tool")) def set_tool_ui(self): self.reset_fields() @@ -309,7 +316,7 @@ class DblSidedTool(FlatCAMTool): try: px, py = self.point_entry.get_value() except TypeError: - self.app.inform.emit(_("[WARNING_NOTCL] 'Point' reference is selected and 'Point' coordinates " + self.app.inform.emit(_tr("[WARNING_NOTCL] 'Point' reference is selected and 'Point' coordinates " "are missing. Add them and retry.")) return else: @@ -328,7 +335,7 @@ class DblSidedTool(FlatCAMTool): bb_obj = model_index.internalPointer().obj except AttributeError: self.app.inform.emit( - _("[WARNING_NOTCL] There is no Box reference object loaded. Load one and retry.")) + _tr("[WARNING_NOTCL] There is no Box reference object loaded. Load one and retry.")) return xmin, ymin, xmax, ymax = bb_obj.bounds() @@ -345,19 +352,19 @@ class DblSidedTool(FlatCAMTool): dia = float(self.drill_dia.get_value().replace(',', '.')) self.drill_dia.set_value(dia) except ValueError: - self.app.inform.emit(_("[WARNING_NOTCL] Tool diameter value is missing or wrong format. " + self.app.inform.emit(_tr("[WARNING_NOTCL] Tool diameter value is missing or wrong format. " "Add it and retry.")) return if dia is '': - self.app.inform.emit(_("[WARNING_NOTCL]No value or wrong format in Drill Dia entry. Add it and retry.")) + self.app.inform.emit(_tr("[WARNING_NOTCL]No value or wrong format in Drill Dia entry. Add it and retry.")) return tools = {"1": {"C": dia}} # holes = self.alignment_holes.get_value() holes = eval('[{}]'.format(self.alignment_holes.text())) if not holes: - self.app.inform.emit(_("[WARNING_NOTCL] There are no Alignment Drill Coordinates to use. Add them and retry.")) + self.app.inform.emit(_tr("[WARNING_NOTCL] There are no Alignment Drill Coordinates to use. Add them and retry.")) return drills = [] @@ -379,7 +386,7 @@ class DblSidedTool(FlatCAMTool): self.app.new_object("excellon", "Alignment Drills", obj_init) self.drill_values = '' - self.app.inform.emit(_("[success] Excellon object with alignment drills created...")) + self.app.inform.emit(_tr("[success] Excellon object with alignment drills created...")) def on_mirror_gerber(self): selection_index = self.gerber_object_combo.currentIndex() @@ -388,11 +395,11 @@ class DblSidedTool(FlatCAMTool): try: fcobj = model_index.internalPointer().obj except Exception as e: - self.app.inform.emit(_("[WARNING_NOTCL] There is no Gerber object loaded ...")) + self.app.inform.emit(_tr("[WARNING_NOTCL] There is no Gerber object loaded ...")) return if not isinstance(fcobj, FlatCAMGerber): - self.app.inform.emit(_("[ERROR_NOTCL] Only Gerber, Excellon and Geometry objects can be mirrored.")) + self.app.inform.emit(_tr("[ERROR_NOTCL] Only Gerber, Excellon and Geometry objects can be mirrored.")) return axis = self.mirror_axis.get_value() @@ -402,7 +409,7 @@ class DblSidedTool(FlatCAMTool): try: px, py = self.point_entry.get_value() except TypeError: - self.app.inform.emit(_("[WARNING_NOTCL] 'Point' coordinates missing. " + self.app.inform.emit(_tr("[WARNING_NOTCL] 'Point' coordinates missing. " "Using Origin (0, 0) as mirroring reference.")) px, py = (0, 0) @@ -412,7 +419,7 @@ class DblSidedTool(FlatCAMTool): try: bb_obj = model_index_box.internalPointer().obj except Exception as e: - self.app.inform.emit(_("[WARNING_NOTCL] There is no Box object loaded ...")) + self.app.inform.emit(_tr("[WARNING_NOTCL] There is no Box object loaded ...")) return xmin, ymin, xmax, ymax = bb_obj.bounds() @@ -422,7 +429,7 @@ class DblSidedTool(FlatCAMTool): fcobj.mirror(axis, [px, py]) self.app.object_changed.emit(fcobj) fcobj.plot() - self.app.inform.emit(_("[success] Gerber %s was mirrored...") % str(fcobj.options['name'])) + self.app.inform.emit(_tr("[success] Gerber %s was mirrored...") % str(fcobj.options['name'])) def on_mirror_exc(self): selection_index = self.exc_object_combo.currentIndex() @@ -431,11 +438,11 @@ class DblSidedTool(FlatCAMTool): try: fcobj = model_index.internalPointer().obj except Exception as e: - self.app.inform.emit(_("[WARNING_NOTCL] There is no Excellon object loaded ...")) + self.app.inform.emit(_tr("[WARNING_NOTCL] There is no Excellon object loaded ...")) return if not isinstance(fcobj, FlatCAMExcellon): - self.app.inform.emit(_("[ERROR_NOTCL] Only Gerber, Excellon and Geometry objects can be mirrored.")) + self.app.inform.emit(_tr("[ERROR_NOTCL] Only Gerber, Excellon and Geometry objects can be mirrored.")) return axis = self.mirror_axis.get_value() @@ -446,7 +453,7 @@ class DblSidedTool(FlatCAMTool): px, py = self.point_entry.get_value() except Exception as e: log.debug("DblSidedTool.on_mirror_geo() --> %s" % str(e)) - self.app.inform.emit(_("[WARNING_NOTCL] There are no Point coordinates in the Point field. " + self.app.inform.emit(_tr("[WARNING_NOTCL] There are no Point coordinates in the Point field. " "Add coords and try again ...")) return else: @@ -456,7 +463,7 @@ class DblSidedTool(FlatCAMTool): bb_obj = model_index_box.internalPointer().obj except Exception as e: log.debug("DblSidedTool.on_mirror_geo() --> %s" % str(e)) - self.app.inform.emit(_("[WARNING_NOTCL] There is no Box object loaded ...")) + self.app.inform.emit(_tr("[WARNING_NOTCL] There is no Box object loaded ...")) return xmin, ymin, xmax, ymax = bb_obj.bounds() @@ -466,7 +473,7 @@ class DblSidedTool(FlatCAMTool): fcobj.mirror(axis, [px, py]) self.app.object_changed.emit(fcobj) fcobj.plot() - self.app.inform.emit(_("[success] Excellon %s was mirrored...") % str(fcobj.options['name'])) + self.app.inform.emit(_tr("[success] Excellon %s was mirrored...") % str(fcobj.options['name'])) def on_mirror_geo(self): selection_index = self.geo_object_combo.currentIndex() @@ -475,11 +482,11 @@ class DblSidedTool(FlatCAMTool): try: fcobj = model_index.internalPointer().obj except Exception as e: - self.app.inform.emit(_("[WARNING_NOTCL] There is no Geometry object loaded ...")) + self.app.inform.emit(_tr("[WARNING_NOTCL] There is no Geometry object loaded ...")) return if not isinstance(fcobj, FlatCAMGeometry): - self.app.inform.emit(_("[ERROR_NOTCL] Only Gerber, Excellon and Geometry objects can be mirrored.")) + self.app.inform.emit(_tr("[ERROR_NOTCL] Only Gerber, Excellon and Geometry objects can be mirrored.")) return axis = self.mirror_axis.get_value() @@ -493,7 +500,7 @@ class DblSidedTool(FlatCAMTool): try: bb_obj = model_index_box.internalPointer().obj except Exception as e: - self.app.inform.emit(_("[WARNING_NOTCL] There is no Box object loaded ...")) + self.app.inform.emit(_tr("[WARNING_NOTCL] There is no Box object loaded ...")) return xmin, ymin, xmax, ymax = bb_obj.bounds() @@ -503,7 +510,7 @@ class DblSidedTool(FlatCAMTool): fcobj.mirror(axis, [px, py]) self.app.object_changed.emit(fcobj) fcobj.plot() - self.app.inform.emit(_("[success] Geometry %s was mirrored...") % str(fcobj.options['name'])) + self.app.inform.emit(_tr("[success] Geometry %s was mirrored...") % str(fcobj.options['name'])) def on_point_add(self): val = self.app.defaults["global_point_clipboard_format"] % (self.app.pos[0], self.app.pos[1]) diff --git a/flatcamTools/ToolFilm.py b/flatcamTools/ToolFilm.py index 80c77c75..c1e6eb90 100644 --- a/flatcamTools/ToolFilm.py +++ b/flatcamTools/ToolFilm.py @@ -7,9 +7,17 @@ import gettext import FlatCAMTranslation as fcTranslate fcTranslate.apply_language('ToolFilm') + +def _tr(text): + try: + return _(text) + except: + return text + + class Film(FlatCAMTool): - toolName = _("Film PCB") + toolName = _tr("Film PCB") def __init__(self, app): FlatCAMTool.__init__(self, app) @@ -40,9 +48,9 @@ class Film(FlatCAMTool): self.tf_type_obj_combo.setItemIcon(0, QtGui.QIcon("share/flatcam_icon16.png")) self.tf_type_obj_combo.setItemIcon(2, QtGui.QIcon("share/geometry16.png")) - self.tf_type_obj_combo_label = QtWidgets.QLabel(_("Object Type:")) + self.tf_type_obj_combo_label = QtWidgets.QLabel(_tr("Object Type:")) self.tf_type_obj_combo_label.setToolTip( - _("Specify the type of object for which to create the film.\n" + _tr("Specify the type of object for which to create the film.\n" "The object can be of type: Gerber or Geometry.\n" "The selection here decide the type of objects that will be\n" "in the Film Object combobox.") @@ -55,9 +63,9 @@ class Film(FlatCAMTool): self.tf_object_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex())) self.tf_object_combo.setCurrentIndex(1) - self.tf_object_label = QtWidgets.QLabel(_("Film Object:")) + self.tf_object_label = QtWidgets.QLabel(_tr("Film Object:")) self.tf_object_label.setToolTip( - _("Object for which to create the film.") + _tr("Object for which to create the film.") ) tf_form_layout.addRow(self.tf_object_label, self.tf_object_combo) @@ -73,9 +81,9 @@ class Film(FlatCAMTool): self.tf_type_box_combo.setItemIcon(0, QtGui.QIcon("share/flatcam_icon16.png")) self.tf_type_box_combo.setItemIcon(2, QtGui.QIcon("share/geometry16.png")) - self.tf_type_box_combo_label = QtWidgets.QLabel(_("Box Type:")) + self.tf_type_box_combo_label = QtWidgets.QLabel(_tr("Box Type:")) self.tf_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" "film creation. It can be: Gerber or Geometry type." "The selection here decide the type of objects that will be\n" "in the Box Object combobox.") @@ -88,9 +96,9 @@ class Film(FlatCAMTool): self.tf_box_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex())) self.tf_box_combo.setCurrentIndex(1) - self.tf_box_combo_label = QtWidgets.QLabel(_("Box Object:")) + self.tf_box_combo_label = QtWidgets.QLabel(_tr("Box Object:")) self.tf_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 for which we create the film.\n" "Usually it is the PCB outline but it can be also the\n" "same object for which the film is created.") @@ -100,9 +108,9 @@ class Film(FlatCAMTool): # Film Type self.film_type = RadioSet([{'label': 'Positive', 'value': 'pos'}, {'label': 'Negative', 'value': 'neg'}]) - self.film_type_label = QtWidgets.QLabel(_("Film Type:")) + self.film_type_label = QtWidgets.QLabel(_tr("Film Type:")) self.film_type_label.setToolTip( - _("Generate a Positive black film or a Negative film.\n" + _tr("Generate a Positive black film or a Negative film.\n" "Positive means that it will print the features\n" "with black on a white canvas.\n" "Negative means that it will print the features\n" @@ -114,9 +122,9 @@ class Film(FlatCAMTool): # Boundary for negative film generation self.boundary_entry = FCEntry() - self.boundary_label = QtWidgets.QLabel(_("Border:")) + self.boundary_label = QtWidgets.QLabel(_tr("Border:")) self.boundary_label.setToolTip( - _("Specify a border around the object.\n" + _tr("Specify a border around the object.\n" "Only for negative film.\n" "It helps if we use as a Box Object the same \n" "object as in Film Object. It will create a thick\n" @@ -128,9 +136,9 @@ class Film(FlatCAMTool): tf_form_layout.addRow(self.boundary_label, self.boundary_entry) self.film_scale_entry = FCEntry() - self.film_scale_label = QtWidgets.QLabel(_("Scale Stroke:")) + self.film_scale_label = QtWidgets.QLabel(_tr("Scale Stroke:")) self.film_scale_label.setToolTip( - _("Scale the line stroke thickness of each feature in the SVG file.\n" + _tr("Scale the line stroke thickness of each feature in the SVG file.\n" "It means that the line that envelope each SVG feature will be thicker or thinner,\n" "therefore the fine features may be more affected by this parameter.") ) @@ -141,9 +149,9 @@ class Film(FlatCAMTool): self.layout.addLayout(hlay) hlay.addStretch() - self.film_object_button = QtWidgets.QPushButton(_("Save Film")) + self.film_object_button = QtWidgets.QPushButton(_tr("Save Film")) self.film_object_button.setToolTip( - _("Create a Film for the selected object, within\n" + _tr("Create a Film for the selected object, within\n" "the specified box. Does not create a new \n " "FlatCAM object, but directly save it in SVG format\n" "which can be opened with Inkscape.") @@ -184,7 +192,7 @@ class Film(FlatCAMTool): FlatCAMTool.run(self) self.set_tool_ui() - self.app.ui.notebook.setTabText(2, _("Film Tool")) + self.app.ui.notebook.setTabText(2, _tr("Film Tool")) def install(self, icon=None, separator=None, **kwargs): FlatCAMTool.install(self, icon, separator, shortcut='ALT+L', **kwargs) @@ -205,13 +213,13 @@ class Film(FlatCAMTool): try: name = self.tf_object_combo.currentText() except: - self.app.inform.emit(_("[ERROR_NOTCL] No FlatCAM object selected. Load an object for Film and retry.")) + self.app.inform.emit(_tr("[ERROR_NOTCL] No FlatCAM object selected. Load an object for Film and retry.")) return try: boxname = self.tf_box_combo.currentText() except: - self.app.inform.emit(_("[ERROR_NOTCL] No FlatCAM object selected. Load an object for Box and retry.")) + self.app.inform.emit(_tr("[ERROR_NOTCL] No FlatCAM object selected. Load an object for Box and retry.")) return try: @@ -221,51 +229,51 @@ class Film(FlatCAMTool): try: border = float(self.boundary_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 try: scale_stroke_width = int(self.film_scale_entry.get_value()) 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 border is None: border = 0 - self.app.inform.emit(_("Generating Film ...")) + self.app.inform.emit(_tr("Generating Film ...")) if self.film_type.get_value() == "pos": try: filename, _ = QtWidgets.QFileDialog.getSaveFileName( - caption=_("Export SVG positive"), + caption=_tr("Export SVG positive"), directory=self.app.get_last_save_folder() + '/' + name, filter="*.svg") except TypeError: - filename, _ = QtWidgets.QFileDialog.getSaveFileName(caption=_("Export SVG positive")) + filename, _ = QtWidgets.QFileDialog.getSaveFileName(caption=_tr("Export SVG positive")) filename = str(filename) if str(filename) == "": - self.app.inform.emit(_("[WARNING_NOTCL]Export SVG positive cancelled.")) + self.app.inform.emit(_tr("[WARNING_NOTCL]Export SVG positive cancelled.")) return else: self.app.export_svg_black(name, boxname, filename, scale_factor=scale_stroke_width) else: try: filename, _ = QtWidgets.QFileDialog.getSaveFileName( - caption=_("Export SVG negative"), + caption=_tr("Export SVG negative"), directory=self.app.get_last_save_folder() + '/' + name, filter="*.svg") except TypeError: - filename, _ = QtWidgets.QFileDialog.getSaveFileName(caption=_("Export SVG negative")) + filename, _ = QtWidgets.QFileDialog.getSaveFileName(caption=_tr("Export SVG negative")) filename = str(filename) if str(filename) == "": - self.app.inform.emit(_("[WARNING_NOTCL]Export SVG negative cancelled.")) + self.app.inform.emit(_tr("[WARNING_NOTCL]Export SVG negative cancelled.")) return else: self.app.export_svg_negative(name, boxname, filename, border, scale_factor=scale_stroke_width) diff --git a/flatcamTools/ToolImage.py b/flatcamTools/ToolImage.py index a71ab59a..009fe98c 100644 --- a/flatcamTools/ToolImage.py +++ b/flatcamTools/ToolImage.py @@ -7,15 +7,23 @@ import gettext import FlatCAMTranslation as fcTranslate fcTranslate.apply_language('ToolImage') + +def _tr(text): + try: + return _(text) + except: + return text + + class ToolImage(FlatCAMTool): - toolName = _("Image as Object") + toolName = _tr("Image as Object") def __init__(self, app): FlatCAMTool.__init__(self, app) # Title - title_label = QtWidgets.QLabel("%s" % _('Image to PCB')) + title_label = QtWidgets.QLabel("%s" % _tr('Image to PCB')) title_label.setStyleSheet(""" QLabel { @@ -37,9 +45,9 @@ class ToolImage(FlatCAMTool): self.tf_type_obj_combo.setItemIcon(0, QtGui.QIcon("share/flatcam_icon16.png")) self.tf_type_obj_combo.setItemIcon(1, QtGui.QIcon("share/geometry16.png")) - self.tf_type_obj_combo_label = QtWidgets.QLabel(_("Object Type:")) + self.tf_type_obj_combo_label = QtWidgets.QLabel(_tr("Object Type:")) self.tf_type_obj_combo_label.setToolTip( - _( "Specify the type of object to create from the image.\n" + _tr( "Specify the type of object to create from the image.\n" "It can be of type: Gerber or Geometry.") ) @@ -47,16 +55,16 @@ class ToolImage(FlatCAMTool): # DPI value of the imported image self.dpi_entry = IntEntry() - self.dpi_label = QtWidgets.QLabel(_("DPI value:")) + self.dpi_label = QtWidgets.QLabel(_tr("DPI value:")) self.dpi_label.setToolTip( - _( "Specify a DPI value for the image.") + _tr( "Specify a DPI value for the image.") ) ti_form_layout.addRow(self.dpi_label, self.dpi_entry) self.emty_lbl = QtWidgets.QLabel("") self.layout.addWidget(self.emty_lbl) - self.detail_label = QtWidgets.QLabel("%s:" % _('Level of detail')) + self.detail_label = QtWidgets.QLabel("%s:" % _tr('Level of detail')) self.layout.addWidget(self.detail_label) ti2_form_layout = QtWidgets.QFormLayout() @@ -65,18 +73,18 @@ class ToolImage(FlatCAMTool): # Type of image interpretation self.image_type = RadioSet([{'label': 'B/W', 'value': 'black'}, {'label': 'Color', 'value': 'color'}]) - self.image_type_label = QtWidgets.QLabel("%s:" % _('Image type')) + self.image_type_label = QtWidgets.QLabel("%s:" % _tr('Image type')) self.image_type_label.setToolTip( - _("Choose a method for the image interpretation.\n" + _tr("Choose a method for the image interpretation.\n" "B/W means a black & white image. Color means a colored image.") ) ti2_form_layout.addRow(self.image_type_label, self.image_type) # Mask value of the imported image when image monochrome self.mask_bw_entry = IntEntry() - self.mask_bw_label = QtWidgets.QLabel("%s B/W:" % _('Mask value')) + self.mask_bw_label = QtWidgets.QLabel("%s B/W:" % _tr('Mask value')) self.mask_bw_label.setToolTip( - _("Mask for monochrome image.\n" + _tr("Mask for monochrome image.\n" "Takes values between [0 ... 255].\n" "Decides the level of details to include\n" "in the resulting geometry.\n" @@ -87,9 +95,9 @@ class ToolImage(FlatCAMTool): # Mask value of the imported image for RED color when image color self.mask_r_entry = IntEntry() - self.mask_r_label = QtWidgets.QLabel("%s R:" % _('Mask value')) + self.mask_r_label = QtWidgets.QLabel("%s R:" % _tr('Mask value')) self.mask_r_label.setToolTip( - _("Mask for RED color.\n" + _tr("Mask for RED color.\n" "Takes values between [0 ... 255].\n" "Decides the level of details to include\n" "in the resulting geometry.") @@ -98,9 +106,9 @@ class ToolImage(FlatCAMTool): # Mask value of the imported image for GREEN color when image color self.mask_g_entry = IntEntry() - self.mask_g_label = QtWidgets.QLabel("%s G:" % _('Mask value')) + self.mask_g_label = QtWidgets.QLabel("%s G:" % _tr('Mask value')) self.mask_g_label.setToolTip( - _("Mask for GREEN color.\n" + _tr("Mask for GREEN color.\n" "Takes values between [0 ... 255].\n" "Decides the level of details to include\n" "in the resulting geometry.") @@ -109,9 +117,9 @@ class ToolImage(FlatCAMTool): # Mask value of the imported image for BLUE color when image color self.mask_b_entry = IntEntry() - self.mask_b_label = QtWidgets.QLabel("%s B:" % _('Mask value')) + self.mask_b_label = QtWidgets.QLabel("%s B:" % _tr('Mask value')) self.mask_b_label.setToolTip( - _("Mask for BLUE color.\n" + _tr("Mask for BLUE color.\n" "Takes values between [0 ... 255].\n" "Decides the level of details to include\n" "in the resulting geometry.") @@ -123,9 +131,9 @@ class ToolImage(FlatCAMTool): self.layout.addLayout(hlay) hlay.addStretch() - self.import_button = QtWidgets.QPushButton(_("Import image")) + self.import_button = QtWidgets.QPushButton(_tr("Import image")) self.import_button.setToolTip( - _("Open a image of raster type and then import it in FlatCAM.") + _tr("Open a image of raster type and then import it in FlatCAM.") ) hlay.addWidget(self.import_button) @@ -151,7 +159,7 @@ class ToolImage(FlatCAMTool): FlatCAMTool.run(self) self.set_tool_ui() - self.app.ui.notebook.setTabText(2, _("Image Tool")) + self.app.ui.notebook.setTabText(2, _tr("Image Tool")) def install(self, icon=None, separator=None, **kwargs): FlatCAMTool.install(self, icon, separator, **kwargs) @@ -181,10 +189,10 @@ class ToolImage(FlatCAMTool): "Jpeg File (*.JPG);;" \ "All Files (*.*)" try: - filename, _ = QtWidgets.QFileDialog.getOpenFileName(caption=_("Import IMAGE"), + filename, _ = QtWidgets.QFileDialog.getOpenFileName(caption=_tr("Import IMAGE"), directory=self.app.get_last_folder(), filter=filter) except TypeError: - filename, _ = QtWidgets.QFileDialog.getOpenFileName(caption=_("Import IMAGE"), filter=filter) + filename, _ = QtWidgets.QFileDialog.getOpenFileName(caption=_tr("Import IMAGE"), filter=filter) filename = str(filename) type = self.tf_type_obj_combo.get_value().lower() @@ -194,7 +202,7 @@ class ToolImage(FlatCAMTool): self.mask_b_entry.get_value()] if filename == "": - self.app.inform.emit(_("Open cancelled.")) + self.app.inform.emit(_tr("Open cancelled.")) else: self.app.worker_task.emit({'fcn': self.app.import_image, 'params': [filename, type, dpi, mode, mask]}) diff --git a/flatcamTools/ToolMeasurement.py b/flatcamTools/ToolMeasurement.py index caad61c1..0a5a27c2 100644 --- a/flatcamTools/ToolMeasurement.py +++ b/flatcamTools/ToolMeasurement.py @@ -11,9 +11,16 @@ import FlatCAMTranslation as fcTranslate fcTranslate.apply_language('ToolMeasurement') +def _tr(text): + try: + return _(text) + except: + return text + + class Measurement(FlatCAMTool): - toolName = _("Measurement") + toolName = _tr("Measurement") def __init__(self, app): FlatCAMTool.__init__(self, app) @@ -34,51 +41,51 @@ class Measurement(FlatCAMTool): form_layout_child_2 = QtWidgets.QFormLayout() form_layout_child_3 = QtWidgets.QFormLayout() - self.start_label = QtWidgets.QLabel("%s %s:" % (_('Start'), _('Coords'))) - self.start_label.setToolTip(_("This is measuring Start point coordinates.")) + self.start_label = QtWidgets.QLabel("%s %s:" % (_tr('Start'), _tr('Coords'))) + self.start_label.setToolTip(_tr("This is measuring Start point coordinates.")) - self.stop_label = QtWidgets.QLabel("%s %s:" % (_('Stop'), _('Coords'))) - self.stop_label.setToolTip(_("This is the measuring Stop point coordinates.")) + self.stop_label = QtWidgets.QLabel("%s %s:" % (_tr('Stop'), _tr('Coords'))) + self.stop_label.setToolTip(_tr("This is the measuring Stop point coordinates.")) self.distance_x_label = QtWidgets.QLabel("Dx:") - self.distance_x_label.setToolTip(_("This is the distance measured over the X axis.")) + self.distance_x_label.setToolTip(_tr("This is the distance measured over the X axis.")) self.distance_y_label = QtWidgets.QLabel("Dy:") - self.distance_y_label.setToolTip(_("This is the distance measured over the Y axis.")) + self.distance_y_label.setToolTip(_tr("This is the distance measured over the Y axis.")) - self.total_distance_label = QtWidgets.QLabel("%s:" % _('DISTANCE')) - self.total_distance_label.setToolTip(_("This is the point to point Euclidian distance.")) + self.total_distance_label = QtWidgets.QLabel("%s:" % _tr('DISTANCE')) + self.total_distance_label.setToolTip(_tr("This is the point to point Euclidian distance.")) self.units_entry_1 = FCEntry() - self.units_entry_1.setToolTip(_("Those are the units in which the distance is measured.")) + self.units_entry_1.setToolTip(_tr("Those are the units in which the distance is measured.")) self.units_entry_1.setDisabled(True) self.units_entry_1.setFocusPolicy(QtCore.Qt.NoFocus) self.units_entry_1.setFrame(False) self.units_entry_1.setFixedWidth(30) self.units_entry_2 = FCEntry() - self.units_entry_2.setToolTip(_("Those are the units in which the distance is measured.")) + self.units_entry_2.setToolTip(_tr("Those are the units in which the distance is measured.")) self.units_entry_2.setDisabled(True) self.units_entry_2.setFocusPolicy(QtCore.Qt.NoFocus) self.units_entry_2.setFrame(False) self.units_entry_2.setFixedWidth(30) self.units_entry_3 = FCEntry() - self.units_entry_3.setToolTip(_("Those are the units in which the distance is measured.")) + self.units_entry_3.setToolTip(_tr("Those are the units in which the distance is measured.")) self.units_entry_3.setDisabled(True) self.units_entry_3.setFocusPolicy(QtCore.Qt.NoFocus) self.units_entry_3.setFrame(False) self.units_entry_3.setFixedWidth(30) self.units_entry_4 = FCEntry() - self.units_entry_4.setToolTip(_("Those are the units in which the distance is measured.")) + self.units_entry_4.setToolTip(_tr("Those are the units in which the distance is measured.")) self.units_entry_4.setDisabled(True) self.units_entry_4.setFocusPolicy(QtCore.Qt.NoFocus) self.units_entry_4.setFrame(False) self.units_entry_4.setFixedWidth(30) self.units_entry_5 = FCEntry() - self.units_entry_5.setToolTip(_("Those are the units in which the distance is measured.")) + self.units_entry_5.setToolTip(_tr("Those are the units in which the distance is measured.")) self.units_entry_5.setDisabled(True) self.units_entry_5.setFocusPolicy(QtCore.Qt.NoFocus) self.units_entry_5.setFrame(False) @@ -86,32 +93,32 @@ class Measurement(FlatCAMTool): self.start_entry = FCEntry() self.start_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) - self.start_entry.setToolTip(_("This is measuring Start point coordinates.")) + self.start_entry.setToolTip(_tr("This is measuring Start point coordinates.")) self.start_entry.setFixedWidth(100) self.stop_entry = FCEntry() self.stop_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) - self.stop_entry.setToolTip(_("This is the measuring Stop point coordinates.")) + self.stop_entry.setToolTip(_tr("This is the measuring Stop point coordinates.")) self.stop_entry.setFixedWidth(100) self.distance_x_entry = FCEntry() self.distance_x_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) - self.distance_x_entry.setToolTip(_("This is the distance measured over the X axis.")) + self.distance_x_entry.setToolTip(_tr("This is the distance measured over the X axis.")) self.distance_x_entry.setFixedWidth(100) self.distance_y_entry = FCEntry() self.distance_y_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) - self.distance_y_entry.setToolTip(_("This is the distance measured over the Y axis.")) + self.distance_y_entry.setToolTip(_tr("This is the distance measured over the Y axis.")) self.distance_y_entry.setFixedWidth(100) self.total_distance_entry = FCEntry() self.total_distance_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) - self.total_distance_entry.setToolTip(_("This is the point to point Euclidian distance.")) + self.total_distance_entry.setToolTip(_tr("This is the point to point Euclidian distance.")) self.total_distance_entry.setFixedWidth(100) - self.measure_btn = QtWidgets.QPushButton(_("Measure")) + self.measure_btn = QtWidgets.QPushButton(_tr("Measure")) self.measure_btn.setFixedWidth(70) self.layout.addWidget(self.measure_btn) @@ -170,7 +177,7 @@ class Measurement(FlatCAMTool): self.toggle() self.set_tool_ui() - self.app.ui.notebook.setTabText(2, _("Meas. Tool")) + self.app.ui.notebook.setTabText(2, _tr("Meas. Tool")) def install(self, icon=None, separator=None, **kwargs): FlatCAMTool.install(self, icon, separator, shortcut='CTRL+M', **kwargs) @@ -263,7 +270,7 @@ class Measurement(FlatCAMTool): self.units_entry_4.set_value(str(self.units)) self.units_entry_5.set_value(str(self.units)) - self.app.inform.emit(_("MEASURING: Click on the Start point ...")) + self.app.inform.emit(_tr("MEASURING: Click on the Start point ...")) def on_key_release_meas(self, event): if event.key == 'escape': @@ -292,7 +299,7 @@ class Measurement(FlatCAMTool): pos = pos_canvas[0], pos_canvas[1] self.point1 = pos self.start_entry.set_value("(%.4f, %.4f)" % pos) - self.app.inform.emit(_("MEASURING: Click on the Destination point ...")) + self.app.inform.emit(_tr("MEASURING: Click on the Destination point ...")) if self.clicked_meas == 1: try: @@ -313,7 +320,7 @@ class Measurement(FlatCAMTool): self.stop_entry.set_value("(%.4f, %.4f)" % pos) - self.app.inform.emit(_("MEASURING: Result D(x) = %.4f | D(y) = %.4f | Distance = %.4f") % + self.app.inform.emit(_tr("MEASURING: Result D(x) = %.4f | D(y) = %.4f | Distance = %.4f") % (abs(dx), abs(dy), abs(d))) self.distance_x_entry.set_value('%.4f' % abs(dx)) diff --git a/flatcamTools/ToolMove.py b/flatcamTools/ToolMove.py index 321f213c..d1241ff2 100644 --- a/flatcamTools/ToolMove.py +++ b/flatcamTools/ToolMove.py @@ -10,9 +10,16 @@ import FlatCAMTranslation as fcTranslate fcTranslate.apply_language('ToolMove') +def _tr(text): + try: + return _(text) + except: + return text + + class ToolMove(FlatCAMTool): - toolName = _("Move") + toolName = _tr("Move") def __init__(self, app): FlatCAMTool.__init__(self, app) @@ -67,14 +74,14 @@ class ToolMove(FlatCAMTool): self.app.command_active = "Move" if self.app.collection.get_selected(): - self.app.inform.emit(_("MOVE: Click on the Start point ...")) + self.app.inform.emit(_tr("MOVE: Click on the Start point ...")) # draw the selection box self.draw_sel_bbox() else: self.setVisible(False) # signal that there is no command active self.app.command_active = None - self.app.inform.emit(_("[WARNING_NOTCL] MOVE action cancelled. No object(s) to move.")) + self.app.inform.emit(_tr("[WARNING_NOTCL] MOVE action cancelled. No object(s) to move.")) def on_left_click(self, event): # mouse click will be accepted only if the left button is clicked @@ -96,7 +103,7 @@ class ToolMove(FlatCAMTool): else: self.point2 = copy(self.point1) self.point1 = pos - self.app.inform.emit(_("MOVE: Click on the Destination point ...")) + self.app.inform.emit(_tr("MOVE: Click on the Destination point ...")) if self.clicked_move == 1: try: @@ -114,14 +121,14 @@ class ToolMove(FlatCAMTool): dx = pos[0] - self.point1[0] dy = pos[1] - self.point1[1] - proc = self.app.proc_container.new(_("Moving ...")) + proc = self.app.proc_container.new(_tr("Moving ...")) def job_move(app_obj): obj_list = self.app.collection.get_selected() try: if not obj_list: - self.app.inform.emit(_("[WARNING_NOTCL] No object(s) selected.")) + self.app.inform.emit(_tr("[WARNING_NOTCL] No object(s) selected.")) return "fail" else: for sel_obj in obj_list: @@ -144,13 +151,13 @@ class ToolMove(FlatCAMTool): # self.app.collection.set_active(sel_obj.options['name']) except Exception as e: proc.done() - self.app.inform.emit(_('[ERROR_NOTCL] ' + self.app.inform.emit(_tr('[ERROR_NOTCL] ' 'ToolMove.on_left_click() --> %s') % str(e)) return "fail" proc.done() # delete the selection bounding box self.delete_shape() - self.app.inform.emit(_('[success]%s object was moved ...') % + self.app.inform.emit(_tr('[success]%s object was moved ...') % str(sel_obj.kind).capitalize()) self.app.worker_task.emit({'fcn': job_move, 'params': [self]}) @@ -160,7 +167,7 @@ class ToolMove(FlatCAMTool): return except TypeError: - self.app.inform.emit(_('[ERROR_NOTCL] ' + self.app.inform.emit(_tr('[ERROR_NOTCL] ' 'ToolMove.on_left_click() --> Error when mouse left click.')) return @@ -188,7 +195,7 @@ class ToolMove(FlatCAMTool): def on_key_press(self, event): if event.key == 'escape': # abort the move action - self.app.inform.emit(_("[WARNING_NOTCL]Move action cancelled.")) + self.app.inform.emit(_tr("[WARNING_NOTCL]Move action cancelled.")) self.toggle() return @@ -200,7 +207,7 @@ class ToolMove(FlatCAMTool): obj_list = self.app.collection.get_selected() if not obj_list: - self.app.inform.emit(_("[WARNING_NOTCL]Object(s) not selected")) + self.app.inform.emit(_tr("[WARNING_NOTCL]Object(s) not selected")) self.toggle() else: # if we have an object selected then we can safely activate the mouse events diff --git a/flatcamTools/ToolNonCopperClear.py b/flatcamTools/ToolNonCopperClear.py index 26135fc3..d21ab8bd 100644 --- a/flatcamTools/ToolNonCopperClear.py +++ b/flatcamTools/ToolNonCopperClear.py @@ -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('%s' % _('Tools Table')) + self.tools_table_label = QtWidgets.QLabel('%s' % _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:
" + _tr("The Tool Type (TT) can be:
" "- Circular with 1 ... 4 teeth -> it is informative only. Being circular,
" "the cut width in material is exactly the tool diameter.
" "- Ball -> informative only and make reference to the Ball type endmill.
" @@ -104,9 +111,9 @@ class NonCopperClear(FlatCAMTool, Gerber): hlay = QtWidgets.QHBoxLayout() self.tools_box.addLayout(hlay) - self.addtool_entry_lbl = QtWidgets.QLabel('%s:' % _('Tool Dia')) + self.addtool_entry_lbl = QtWidgets.QLabel('%s:' % _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:
" + _tr("Algorithm for non-copper clearing:
" "Standard: Fixed step inwards.
" "Seed-based: Outwards from seed.
" "Line-based: 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) diff --git a/flatcamTools/ToolPaint.py b/flatcamTools/ToolPaint.py index 53170a09..21595dee 100644 --- a/flatcamTools/ToolPaint.py +++ b/flatcamTools/ToolPaint.py @@ -6,9 +6,17 @@ import gettext import FlatCAMTranslation as fcTranslate fcTranslate.apply_language('ToolPaint') + +def _tr(text): + try: + return _(text) + except: + return text + + class ToolPaint(FlatCAMTool, Gerber): - toolName = _("Paint Area") + toolName = _tr("Paint Area") def __init__(self, app): self.app = app @@ -44,18 +52,18 @@ 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(_tr("Geometry:")) self.object_label.setToolTip( - _("Geometry object to be painted. ") + _tr("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('%s' % _('Tools Table')) + self.tools_table_label = QtWidgets.QLabel('%s' % _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 painting.") ) self.tools_box.addWidget(self.tools_table_label) @@ -64,13 +72,13 @@ 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(['#', _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" "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" @@ -78,11 +86,11 @@ class ToolPaint(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:
" + _tr("The Tool Type (TT) can be:
" "- Circular with 1 ... 4 teeth -> it is informative only. Being circular,
" "the cut width in material is exactly the tool diameter.
" "- Ball -> informative only and make reference to the Ball type endmill.
" @@ -101,9 +109,9 @@ class ToolPaint(FlatCAMTool, Gerber): hlay = QtWidgets.QHBoxLayout() self.tools_box.addLayout(hlay) - self.addtool_entry_lbl = QtWidgets.QLabel('%s:' % _('Tool Dia')) + self.addtool_entry_lbl = QtWidgets.QLabel('%s:' % _tr('Tool Dia')) self.addtool_entry_lbl.setToolTip( - _("Diameter for the new tool.") + _tr("Diameter for the new tool.") ) self.addtool_entry = FCEntry() @@ -115,9 +123,9 @@ class ToolPaint(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.") ) @@ -127,9 +135,9 @@ class ToolPaint(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.") ) @@ -144,9 +152,9 @@ class ToolPaint(FlatCAMTool, Gerber): self.tools_box.addLayout(grid3) # Overlap - ovlabel = QtWidgets.QLabel(_('Overlap:')) + ovlabel = QtWidgets.QLabel(_tr('Overlap:')) ovlabel.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" @@ -161,9 +169,9 @@ class ToolPaint(FlatCAMTool, Gerber): grid3.addWidget(self.paintoverlap_entry, 1, 1) # Margin - marginlabel = QtWidgets.QLabel(_('Margin:')) + marginlabel = QtWidgets.QLabel(_tr('Margin:')) marginlabel.setToolTip( - _("Distance by which to avoid\n" + _tr("Distance by which to avoid\n" "the edges of the polygon to\n" "be painted.") ) @@ -172,9 +180,9 @@ class ToolPaint(FlatCAMTool, Gerber): grid3.addWidget(self.paintmargin_entry, 2, 1) # Method - methodlabel = QtWidgets.QLabel(_('Method:')) + methodlabel = QtWidgets.QLabel(_tr('Method:')) methodlabel.setToolTip( - _("Algorithm for non-copper clearing:
" + _tr("Algorithm for non-copper clearing:
" "Standard: Fixed step inwards.
" "Seed-based: Outwards from seed.
" "Line-based: Parallel lines.") @@ -188,27 +196,27 @@ class ToolPaint(FlatCAMTool, Gerber): grid3.addWidget(self.paintmethod_combo, 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.pathconnect_cb = FCCheckBox() grid3.addWidget(self.pathconnect_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.paintcontour_cb = FCCheckBox() grid3.addWidget(self.paintcontour_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" @@ -221,9 +229,9 @@ class ToolPaint(FlatCAMTool, Gerber): grid3.addWidget(self.rest_cb, 6, 1) # Polygon selection - selectlabel = QtWidgets.QLabel(_('Selection:')) + selectlabel = QtWidgets.QLabel(_tr('Selection:')) selectlabel.setToolTip( - _("How to select the polygons to paint.
" + _tr("How to select the polygons to paint.
" "Options:
" "- Single: left mouse click on the polygon to be painted.
" "- All: paint all polygons.") @@ -238,9 +246,9 @@ 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(_tr('Create Paint Geometry')) self.generate_paint_button.setToolTip( - _("After clicking here, click inside
" + _tr("After clicking here, click inside
" "the polygon you wish to be painted if Single is selected.
" "If All is selected then the Paint will start after click.
" "A new Geometry object with the tool
" @@ -321,7 +329,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, _tr("Paint Tool")) def on_radio_selection(self): if self.selectmethod_combo.get_value() == 'single': @@ -518,13 +526,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, " + 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 # construct a list of all 'tooluid' in the self.tools @@ -548,12 +556,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(_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.paint_tools.update({ int(self.tooluid): { 'tooldia': float('%.4f' % tool_dia), @@ -588,7 +596,7 @@ 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, " + self.app.inform.emit(_tr("[ERROR_NOTCL]Wrong value format entered, " "use a number.")) return tooluid = int(self.tools_table.item(row, 3).text()) @@ -596,7 +604,7 @@ class ToolPaint(FlatCAMTool, Gerber): # 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(_tr("[success] Tool from Tool Table was edited.")) self.build_ui() return else: @@ -607,7 +615,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(_tr("[WARNING_NOTCL] Edit cancelled. New diameter value is already in the Tool Table.")) self.build_ui() # def on_tool_copy(self, all=None): @@ -704,18 +712,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(_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_paint_button_click(self): - self.app.report_usage(_("geometry_on_paint_button")) + self.app.report_usage(_tr("geometry_on_paint_button")) - self.app.inform.emit(_("[WARNING_NOTCL]Click inside the desired polygon.")) + self.app.inform.emit(_tr("[WARNING_NOTCL]Click inside the desired polygon.")) try: overlap = float(self.paintoverlap_entry.get_value()) except ValueError: @@ -723,7 +731,7 @@ 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, " + self.app.inform.emit(_tr("[ERROR_NOTCL]Wrong value format entered, " "use a number.")) return @@ -737,17 +745,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(_tr("[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(_tr("[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(_tr("[ERROR_NOTCL] Can't do Paint on MultiGeo geometries ...")) return 'Fail' o_name = '%s_multitool_paint' % (self.obj_name) @@ -760,7 +768,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(_tr("[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())) @@ -769,7 +777,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(_tr("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, @@ -814,17 +822,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, " + self.app.inform.emit(_tr("[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(_tr('[WARNING] No polygon found.')) return - proc = self.app.proc_container.new(_("Painting polygon.")) + proc = self.app.proc_container.new(_tr("Painting polygon.")) name = outname if outname else self.obj_name + "_paint" @@ -866,7 +874,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(_tr('[ERROR_NOTCL] Geometry could not be painted completely')) return None geo_obj.solid_geometry = [] @@ -892,7 +900,7 @@ 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. " + _tr("[ERROR] Could not do Paint. Try a different combination of parameters. " "Or a different strategy of paint\n%s") % str(e)) return @@ -934,13 +942,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(_tr('[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(_tr("Polygon Paint started ...")) # Promise object with the new name self.app.collection.promise(name) @@ -969,11 +977,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, " + self.app.inform.emit(_tr("[ERROR_NOTCL]Wrong value format entered, " "use a number.")) return - proc = self.app.proc_container.new(_("Painting polygon...")) + proc = self.app.proc_container.new(_tr("Painting polygon...")) name = outname if outname else self.obj_name + "_paint" over = overlap conn = connect @@ -1088,7 +1096,7 @@ 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. " + _tr("[ERROR] Could not do Paint All. Try a different combination of parameters. " "Or a different Method of paint\n%s") % str(e)) return @@ -1112,7 +1120,7 @@ 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(_tr("[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.")) return @@ -1121,7 +1129,7 @@ class ToolPaint(FlatCAMTool, Gerber): # print("Indexing...", end=' ') # geo_obj.make_index() - self.app.inform.emit(_("[success] Paint All Done.")) + self.app.inform.emit(_tr("[success] Paint All Done.")) # Initializes the new geometry object def gen_paintarea_rest_machining(geo_obj, app_obj): @@ -1177,7 +1185,7 @@ 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. " + _tr("[ERROR] Could not do Paint All. Try a different combination of parameters. " "Or a different Method of paint\n%s") % str(e)) return @@ -1207,7 +1215,7 @@ 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(_tr("[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.")) return @@ -1216,7 +1224,7 @@ class ToolPaint(FlatCAMTool, Gerber): # print("Indexing...", end=' ') # geo_obj.make_index() - self.app.inform.emit(_("[success] Paint All with Rest-Machining done.")) + self.app.inform.emit(_tr("[success] Paint All with Rest-Machining done.")) def job_thread(app_obj): try: @@ -1232,7 +1240,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(_tr("Polygon Paint started ...")) # Promise object with the new name self.app.collection.promise(name) diff --git a/flatcamTools/ToolPanelize.py b/flatcamTools/ToolPanelize.py index ac847307..78bc680f 100644 --- a/flatcamTools/ToolPanelize.py +++ b/flatcamTools/ToolPanelize.py @@ -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)) diff --git a/flatcamTools/ToolProperties.py b/flatcamTools/ToolProperties.py index d76ed14c..d0127876 100644 --- a/flatcamTools/ToolProperties.py +++ b/flatcamTools/ToolProperties.py @@ -8,9 +8,16 @@ import FlatCAMTranslation as fcTranslate fcTranslate.apply_language('ToolProperties') +def _tr(text): + try: + return _(text) + except: + return text + + class Properties(FlatCAMTool): - toolName = _("Properties") + toolName = _tr("Properties") def __init__(self, app): FlatCAMTool.__init__(self, app) @@ -84,15 +91,15 @@ class Properties(FlatCAMTool): def properties(self): obj_list = self.app.collection.get_selected() if not obj_list: - self.app.inform.emit(_("[ERROR_NOTCL] Properties Tool was not displayed. No object selected.")) - self.app.ui.notebook.setTabText(2, _("Tools")) + self.app.inform.emit(_tr("[ERROR_NOTCL] Properties Tool was not displayed. No object selected.")) + self.app.ui.notebook.setTabText(2, _tr("Tools")) self.properties_frame.hide() self.app.ui.notebook.setCurrentWidget(self.app.ui.project_tab) return for obj in obj_list: self.addItems(obj) - self.app.inform.emit(_("[success] Object Properties are displayed.")) - self.app.ui.notebook.setTabText(2, _("Properties Tool")) + self.app.inform.emit(_tr("[success] Object Properties are displayed.")) + self.app.ui.notebook.setTabText(2, _tr("Properties Tool")) def addItems(self, obj): parent = self.treeWidget.invisibleRootItem() diff --git a/flatcamTools/ToolShell.py b/flatcamTools/ToolShell.py index 6ce45006..4add34c2 100644 --- a/flatcamTools/ToolShell.py +++ b/flatcamTools/ToolShell.py @@ -18,6 +18,13 @@ import FlatCAMTranslation as fcTranslate fcTranslate.apply_language('ToolShell') +def _tr(text): + try: + return _(text) + except: + return text + + class TermWidget(QWidget): """ Widget wich represents terminal. It only displays text and allows to enter text. @@ -62,9 +69,9 @@ class TermWidget(QWidget): self._edit.setTextColor(Qt.white) self._edit.setTextBackgroundColor(Qt.darkGreen) if detail is None: - self._edit.setPlainText(_("...proccessing...")) + self._edit.setPlainText(_tr("...proccessing...")) else: - self._edit.setPlainText(_("...proccessing... [%s]") % detail) + self._edit.setPlainText(_tr("...proccessing... [%s]") % detail) self._edit.setDisabled(True) self._edit.setFocus() diff --git a/flatcamTools/ToolSolderPaste.py b/flatcamTools/ToolSolderPaste.py index 4b6c4f31..ec84cc4e 100644 --- a/flatcamTools/ToolSolderPaste.py +++ b/flatcamTools/ToolSolderPaste.py @@ -22,8 +22,15 @@ import FlatCAMTranslation as fcTranslate fcTranslate.apply_language('ToolSolderPaste') +def _tr(text): + try: + return _(text) + except: + return text + + class SolderPaste(FlatCAMTool): - toolName = _("Solder Paste Tool") + toolName = _tr("Solder Paste Tool") def __init__(self, app): FlatCAMTool.__init__(self, app) @@ -51,14 +58,14 @@ class SolderPaste(FlatCAMTool): self.object_label = QtWidgets.QLabel("Gerber: ") self.object_label.setToolTip( - _("Gerber Solder paste object. ") + _tr("Gerber Solder paste object. ") ) obj_form_layout.addRow(self.object_label, self.obj_combo) #### Tools #### - self.tools_table_label = QtWidgets.QLabel('%s' % _('Tools Table')) + self.tools_table_label = QtWidgets.QLabel('%s' % _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 dispensing solder paste.") ) self.layout.addWidget(self.tools_table_label) @@ -67,29 +74,29 @@ class SolderPaste(FlatCAMTool): self.layout.addWidget(self.tools_table) self.tools_table.setColumnCount(3) - self.tools_table.setHorizontalHeaderLabels(['#', _('Diameter'), '']) + self.tools_table.setHorizontalHeaderLabels(['#', _tr('Diameter'), '']) self.tools_table.setColumnHidden(2, 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" "The solder dispensing will start with the tool with the biggest \n" "diameter, continuing until there are no more Nozzle tools.\n" "If there are no longer tools but there are still pads not covered\n " "with solder paste, the app will issue a warning message box.") ) self.tools_table.horizontalHeaderItem(1).setToolTip( - _( "Nozzle tool Diameter. It's value (in current FlatCAM units)\n" + _tr( "Nozzle tool Diameter. It's value (in current FlatCAM units)\n" "is the width of the solder paste dispensed.")) #### Add a new Tool #### hlay_tools = QtWidgets.QHBoxLayout() self.layout.addLayout(hlay_tools) - self.addtool_entry_lbl = QtWidgets.QLabel('%s:' % _('New Nozzle Tool')) + self.addtool_entry_lbl = QtWidgets.QLabel('%s:' % _tr('New Nozzle Tool')) self.addtool_entry_lbl.setToolTip( - _("Diameter for the new Nozzle tool to add in the Tool Table") + _tr("Diameter for the new Nozzle tool to add in the Tool Table") ) self.addtool_entry = FCEntry() @@ -101,21 +108,21 @@ class SolderPaste(FlatCAMTool): grid0 = QtWidgets.QGridLayout() self.layout.addLayout(grid0) - self.addtool_btn = QtWidgets.QPushButton(_('Add')) + self.addtool_btn = QtWidgets.QPushButton(_tr('Add')) self.addtool_btn.setToolTip( - _("Add a new nozzle tool to the Tool Table\n" + _tr("Add a new nozzle tool to the Tool Table\n" "with the diameter specified above.") ) - 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.") ) - self.soldergeo_btn = QtWidgets.QPushButton(_("Generate Geo")) + self.soldergeo_btn = QtWidgets.QPushButton(_tr("Generate Geo")) self.soldergeo_btn.setToolTip( - _("Generate solder paste dispensing geometry.") + _tr("Generate solder paste dispensing geometry.") ) grid0.addWidget(self.addtool_btn, 0, 0) @@ -128,12 +135,12 @@ class SolderPaste(FlatCAMTool): grid0_1 = QtWidgets.QGridLayout() self.layout.addLayout(grid0_1) - step1_lbl = QtWidgets.QLabel("%s:" % _('STEP 1')) + step1_lbl = QtWidgets.QLabel("%s:" % _tr('STEP 1')) step1_lbl.setToolTip( - _("First step is to select a number of nozzle tools for usage\n" + _tr("First step is to select a number of nozzle tools for usage\n" "and then optionally modify the GCode parameters bellow.") ) - step1_description_lbl = QtWidgets.QLabel(_("Select tools.\n" + step1_description_lbl = QtWidgets.QLabel(_tr("Select tools.\n" "Modify parameters.")) grid0_1.addWidget(step1_lbl, 0, 0, alignment=Qt.AlignTop) @@ -152,120 +159,120 @@ class SolderPaste(FlatCAMTool): # Z dispense start self.z_start_entry = FCEntry() - self.z_start_label = QtWidgets.QLabel(_("Z Dispense Start:")) + self.z_start_label = QtWidgets.QLabel(_tr("Z Dispense Start:")) self.z_start_label.setToolTip( - _("The height (Z) when solder paste dispensing starts.") + _tr("The height (Z) when solder paste dispensing starts.") ) self.gcode_form_layout.addRow(self.z_start_label, self.z_start_entry) # Z dispense self.z_dispense_entry = FCEntry() - self.z_dispense_label = QtWidgets.QLabel(_("Z Dispense:")) + self.z_dispense_label = QtWidgets.QLabel(_tr("Z Dispense:")) self.z_dispense_label.setToolTip( - _("The height (Z) when doing solder paste dispensing.") + _tr("The height (Z) when doing solder paste dispensing.") ) self.gcode_form_layout.addRow(self.z_dispense_label, self.z_dispense_entry) # Z dispense stop self.z_stop_entry = FCEntry() - self.z_stop_label = QtWidgets.QLabel(_("Z Dispense Stop:")) + self.z_stop_label = QtWidgets.QLabel(_tr("Z Dispense Stop:")) self.z_stop_label.setToolTip( - _("The height (Z) when solder paste dispensing stops.") + _tr("The height (Z) when solder paste dispensing stops.") ) self.gcode_form_layout.addRow(self.z_stop_label, self.z_stop_entry) # Z travel self.z_travel_entry = FCEntry() - self.z_travel_label = QtWidgets.QLabel(_("Z Travel:")) + self.z_travel_label = QtWidgets.QLabel(_tr("Z Travel:")) self.z_travel_label.setToolTip( - _( "The height (Z) for travel between pads\n" + _tr( "The height (Z) for travel between pads\n" "(without dispensing solder paste).") ) self.gcode_form_layout.addRow(self.z_travel_label, self.z_travel_entry) # Z toolchange location self.z_toolchange_entry = FCEntry() - self.z_toolchange_label = QtWidgets.QLabel(_("Z Toolchange:")) + self.z_toolchange_label = QtWidgets.QLabel(_tr("Z Toolchange:")) self.z_toolchange_label.setToolTip( - _( "The height (Z) for tool (nozzle) change.") + _tr( "The height (Z) for tool (nozzle) change.") ) self.gcode_form_layout.addRow(self.z_toolchange_label, self.z_toolchange_entry) # X,Y Toolchange location self.xy_toolchange_entry = FCEntry() - self.xy_toolchange_label = QtWidgets.QLabel(_("XY Toolchange:")) + self.xy_toolchange_label = QtWidgets.QLabel(_tr("XY Toolchange:")) self.xy_toolchange_label.setToolTip( - _("The X,Y location for tool (nozzle) change.\n" + _tr("The X,Y location for tool (nozzle) change.\n" "The format is (x, y) where x and y are real numbers.") ) self.gcode_form_layout.addRow(self.xy_toolchange_label, self.xy_toolchange_entry) # Feedrate X-Y self.frxy_entry = FCEntry() - self.frxy_label = QtWidgets.QLabel(_("Feedrate X-Y:")) + self.frxy_label = QtWidgets.QLabel(_tr("Feedrate X-Y:")) self.frxy_label.setToolTip( - _( "Feedrate (speed) while moving on the X-Y plane.") + _tr( "Feedrate (speed) while moving on the X-Y plane.") ) self.gcode_form_layout.addRow(self.frxy_label, self.frxy_entry) # Feedrate Z self.frz_entry = FCEntry() - self.frz_label = QtWidgets.QLabel(_("Feedrate Z:")) + self.frz_label = QtWidgets.QLabel(_tr("Feedrate Z:")) self.frz_label.setToolTip( - _("Feedrate (speed) while moving vertically\n" + _tr("Feedrate (speed) while moving vertically\n" "(on Z plane).") ) self.gcode_form_layout.addRow(self.frz_label, self.frz_entry) # Feedrate Z Dispense self.frz_dispense_entry = FCEntry() - self.frz_dispense_label = QtWidgets.QLabel(_("Feedrate Z Dispense:")) + self.frz_dispense_label = QtWidgets.QLabel(_tr("Feedrate Z Dispense:")) self.frz_dispense_label.setToolTip( - _( "Feedrate (speed) while moving up vertically\n" + _tr( "Feedrate (speed) while moving up vertically\n" " to Dispense position (on Z plane).") ) self.gcode_form_layout.addRow(self.frz_dispense_label, self.frz_dispense_entry) # Spindle Speed Forward self.speedfwd_entry = FCEntry() - self.speedfwd_label = QtWidgets.QLabel(_("Spindle Speed FWD:")) + self.speedfwd_label = QtWidgets.QLabel(_tr("Spindle Speed FWD:")) self.speedfwd_label.setToolTip( - _( "The dispenser speed while pushing solder paste\n" + _tr( "The dispenser speed while pushing solder paste\n" "through the dispenser nozzle.") ) self.gcode_form_layout.addRow(self.speedfwd_label, self.speedfwd_entry) # Dwell Forward self.dwellfwd_entry = FCEntry() - self.dwellfwd_label = QtWidgets.QLabel(_("Dwell FWD:")) + self.dwellfwd_label = QtWidgets.QLabel(_tr("Dwell FWD:")) self.dwellfwd_label.setToolTip( - _("Pause after solder dispensing.") + _tr("Pause after solder dispensing.") ) self.gcode_form_layout.addRow(self.dwellfwd_label, self.dwellfwd_entry) # Spindle Speed Reverse self.speedrev_entry = FCEntry() - self.speedrev_label = QtWidgets.QLabel(_("Spindle Speed REV:")) + self.speedrev_label = QtWidgets.QLabel(_tr("Spindle Speed REV:")) self.speedrev_label.setToolTip( - _( "The dispenser speed while retracting solder paste\n" + _tr( "The dispenser speed while retracting solder paste\n" "through the dispenser nozzle.") ) self.gcode_form_layout.addRow(self.speedrev_label, self.speedrev_entry) # Dwell Reverse self.dwellrev_entry = FCEntry() - self.dwellrev_label = QtWidgets.QLabel(_("Dwell REV:")) + self.dwellrev_label = QtWidgets.QLabel(_tr("Dwell REV:")) self.dwellrev_label.setToolTip( - _("Pause after solder paste dispenser retracted,\n" + _tr("Pause after solder paste dispenser retracted,\n" "to allow pressure equilibrium.") ) self.gcode_form_layout.addRow(self.dwellrev_label, self.dwellrev_entry) # Postprocessors - pp_label = QtWidgets.QLabel(_('PostProcessors:')) + pp_label = QtWidgets.QLabel(_tr('PostProcessors:')) pp_label.setToolTip( - _("Files that control the GCode generation.") + _tr("Files that control the GCode generation.") ) self.pp_combo = FCComboBox() @@ -276,9 +283,9 @@ class SolderPaste(FlatCAMTool): grid1 = QtWidgets.QGridLayout() self.gcode_box.addLayout(grid1) - self.solder_gcode_btn = QtWidgets.QPushButton(_("Generate GCode")) + self.solder_gcode_btn = QtWidgets.QPushButton(_tr("Generate GCode")) self.solder_gcode_btn.setToolTip( - _( "Generate GCode for Solder Paste dispensing\n" + _tr( "Generate GCode for Solder Paste dispensing\n" "on PCB pads.") ) @@ -294,9 +301,9 @@ class SolderPaste(FlatCAMTool): grid2 = QtWidgets.QGridLayout() self.generation_box.addLayout(grid2) - step2_lbl = QtWidgets.QLabel("%s" % _('STEP 2:')) + step2_lbl = QtWidgets.QLabel("%s" % _tr('STEP 2:')) step2_lbl.setToolTip( - _("Second step is to create a solder paste dispensing\n" + _tr("Second step is to create a solder paste dispensing\n" "geometry out of an Solder Paste Mask Gerber file.") ) grid2.addWidget(step2_lbl, 0, 0) @@ -312,9 +319,9 @@ class SolderPaste(FlatCAMTool): self.geo_obj_combo.setRootModelIndex(self.app.collection.index(2, 0, QtCore.QModelIndex())) self.geo_obj_combo.setCurrentIndex(1) - self.geo_object_label = QtWidgets.QLabel(_("Geo Result:")) + self.geo_object_label = QtWidgets.QLabel(_tr("Geo Result:")) self.geo_object_label.setToolTip( - _( "Geometry Solder Paste object.\n" + _tr( "Geometry Solder Paste object.\n" "The name of the object has to end in:\n" "'_solderpaste' as a protection.") ) @@ -323,9 +330,9 @@ class SolderPaste(FlatCAMTool): grid3 = QtWidgets.QGridLayout() self.generation_box.addLayout(grid3) - step3_lbl = QtWidgets.QLabel("%s" % _('STEP 3:')) + step3_lbl = QtWidgets.QLabel("%s" % _tr('STEP 3:')) step3_lbl.setToolTip( - _( "Third step is to select a solder paste dispensing geometry,\n" + _tr( "Third step is to select a solder paste dispensing geometry,\n" "and then generate a CNCJob object.\n\n" "REMEMBER: if you want to create a CNCJob with new parameters,\n" "first you need to generate a geometry with those new params,\n" @@ -345,9 +352,9 @@ class SolderPaste(FlatCAMTool): self.cnc_obj_combo.setRootModelIndex(self.app.collection.index(3, 0, QtCore.QModelIndex())) self.cnc_obj_combo.setCurrentIndex(1) - self.cnc_object_label = QtWidgets.QLabel(_("CNC Result:")) + self.cnc_object_label = QtWidgets.QLabel(_tr("CNC Result:")) self.cnc_object_label.setToolTip( - _( "CNCJob Solder paste object.\n" + _tr( "CNCJob Solder paste object.\n" "In order to enable the GCode save section,\n" "the name of the object has to end in:\n" "'_solderpaste' as a protection.") @@ -357,21 +364,21 @@ class SolderPaste(FlatCAMTool): grid4 = QtWidgets.QGridLayout() self.generation_box.addLayout(grid4) - self.solder_gcode_view_btn = QtWidgets.QPushButton(_("View GCode")) + self.solder_gcode_view_btn = QtWidgets.QPushButton(_tr("View GCode")) self.solder_gcode_view_btn.setToolTip( - _("View the generated GCode for Solder Paste dispensing\n" + _tr("View the generated GCode for Solder Paste dispensing\n" "on PCB pads.") ) - self.solder_gcode_save_btn = QtWidgets.QPushButton(_("Save GCode")) + self.solder_gcode_save_btn = QtWidgets.QPushButton(_tr("Save GCode")) self.solder_gcode_save_btn.setToolTip( - _( "Save the generated GCode for Solder Paste dispensing\n" + _tr( "Save the generated GCode for Solder Paste dispensing\n" "on PCB pads, to a file.") ) - step4_lbl = QtWidgets.QLabel("%s" % _('STEP 4:')) + step4_lbl = QtWidgets.QLabel("%s" % _tr('STEP 4:')) step4_lbl.setToolTip( - _( "Fourth step (and last) is to select a CNCJob made from \n" + _tr( "Fourth step (and last) is to select a CNCJob made from \n" "a solder paste dispensing geometry, and then view/save it's GCode.") ) @@ -399,7 +406,7 @@ class SolderPaste(FlatCAMTool): self.flat_geometry = [] # action to be added in the combobox context menu - self.combo_context_del_action = QtWidgets.QAction(QtGui.QIcon('share/trash16.png'), _("Delete Object")) + self.combo_context_del_action = QtWidgets.QAction(QtGui.QIcon('share/trash16.png'), _tr("Delete Object")) ## Signals self.combo_context_del_action.triggered.connect(self.on_delete_object) @@ -461,9 +468,9 @@ class SolderPaste(FlatCAMTool): self.tools_table.setupContextMenu() self.tools_table.addContextMenu( - _("Add"), lambda: self.on_tool_add(dia=None, muted=None), icon=QtGui.QIcon("share/plus16.png")) + _tr("Add"), lambda: self.on_tool_add(dia=None, muted=None), icon=QtGui.QIcon("share/plus16.png")) self.tools_table.addContextMenu( - _("Delete"), lambda: + _tr("Delete"), lambda: self.on_tool_delete(rows_to_delete=None, all=None), icon=QtGui.QIcon("share/delete32.png")) try: @@ -738,16 +745,16 @@ class SolderPaste(FlatCAMTool): 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.tooltable_tools @@ -771,12 +778,12 @@ class SolderPaste(FlatCAMTool): if float('%.4f' % tool_dia) in tool_dias: if muted is None: - self.app.inform.emit(_("[WARNING_NOTCL] Adding Nozzle tool cancelled. Tool already in Tool Table.")) + self.app.inform.emit(_tr("[WARNING_NOTCL] Adding Nozzle 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 Nozzle tool added to Tool Table.")) + self.app.inform.emit(_tr("[success] New Nozzle tool added to Tool Table.")) self.tooltable_tools.update({ int(self.tooluid): { 'tooldia': float('%.4f' % tool_dia), @@ -809,7 +816,7 @@ class SolderPaste(FlatCAMTool): 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 @@ -818,7 +825,7 @@ class SolderPaste(FlatCAMTool): # identify the tool that was edited and get it's tooluid if new_tool_dia not in tool_dias: self.tooltable_tools[tooluid]['tooldia'] = new_tool_dia - self.app.inform.emit(_("[success] Nozzle tool from Tool Table was edited.")) + self.app.inform.emit(_tr("[success] Nozzle tool from Tool Table was edited.")) self.build_ui() return else: @@ -829,7 +836,7 @@ class SolderPaste(FlatCAMTool): 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): @@ -874,12 +881,12 @@ class SolderPaste(FlatCAMTool): self.tooltable_tools.pop(t, None) except AttributeError: - self.app.inform.emit(_("[WARNING_NOTCL] Delete failed. Select a Nozzle tool to delete.")) + self.app.inform.emit(_tr("[WARNING_NOTCL] Delete failed. Select a Nozzle tool to delete.")) return except Exception as e: log.debug(str(e)) - self.app.inform.emit(_("[success] Nozzle tool(s) deleted from Tool Table.")) + self.app.inform.emit(_tr("[success] Nozzle tool(s) deleted from Tool Table.")) self.build_ui() def on_rmb_combo(self, pos, combo): @@ -934,7 +941,7 @@ class SolderPaste(FlatCAMTool): """ name = self.obj_combo.currentText() if name == '': - self.app.inform.emit(_("[WARNING_NOTCL] No SolderPaste mask Gerber object loaded.")) + self.app.inform.emit(_tr("[WARNING_NOTCL] No SolderPaste mask Gerber object loaded.")) return obj = self.app.collection.get_by_name(name) @@ -951,7 +958,7 @@ class SolderPaste(FlatCAMTool): :param work_object: the source Gerber object from which the geometry is created :return: a Geometry type object """ - proc = self.app.proc_container.new(_("Creating Solder Paste dispensing geometry.")) + proc = self.app.proc_container.new(_tr("Creating Solder Paste dispensing geometry.")) obj = work_object # Sort tools in descending order @@ -963,7 +970,7 @@ class SolderPaste(FlatCAMTool): sorted_tools.sort(reverse=True) if not sorted_tools: - self.app.inform.emit(_("[WARNING_NOTCL] No Nozzle tools in the tool table.")) + self.app.inform.emit(_tr("[WARNING_NOTCL] No Nozzle tools in the tool table.")) return 'fail' def flatten(geometry=None, reset=True, pathonly=False): @@ -1089,16 +1096,16 @@ class SolderPaste(FlatCAMTool): if not geo_obj.tools[tooluid_key]['solid_geometry']: a += 1 if a == len(geo_obj.tools): - self.app.inform.emit(_('[ERROR_NOTCL] Cancelled. Empty file, it has no geometry...')) + self.app.inform.emit(_tr('[ERROR_NOTCL] Cancelled. Empty file, it has no geometry...')) return 'fail' - app_obj.inform.emit(_("[success] Solder Paste geometry generated successfully...")) + app_obj.inform.emit(_tr("[success] Solder Paste geometry generated successfully...")) return # if we still have geometry not processed at the end of the tools then we failed # some or all the pads are not covered with solder paste if work_geo: - app_obj.inform.emit(_("[WARNING_NOTCL] Some or all pads have no solder " + app_obj.inform.emit(_tr("[WARNING_NOTCL] Some or all pads have no solder " "due of inadequate nozzle diameters...")) return 'fail' @@ -1112,7 +1119,7 @@ class SolderPaste(FlatCAMTool): return proc.done() - self.app.inform.emit(_("Generating Solder Paste dispensing geometry...")) + self.app.inform.emit(_tr("Generating Solder Paste dispensing geometry...")) # Promise object with the new name self.app.collection.promise(name) @@ -1132,11 +1139,11 @@ class SolderPaste(FlatCAMTool): obj = self.app.collection.get_by_name(name) if name == '': - self.app.inform.emit(_("[WARNING_NOTCL] There is no Geometry object available.")) + self.app.inform.emit(_tr("[WARNING_NOTCL] There is no Geometry object available.")) return 'fail' if obj.special_group != 'solder_paste_tool': - self.app.inform.emit(_("[WARNING_NOTCL] This Geometry can't be processed. NOT a solder_paste_tool geometry.")) + self.app.inform.emit(_tr("[WARNING_NOTCL] This Geometry can't be processed. NOT a solder_paste_tool geometry.")) return 'fail' a = 0 @@ -1144,7 +1151,7 @@ class SolderPaste(FlatCAMTool): if obj.tools[tooluid_key]['solid_geometry'] is None: a += 1 if a == len(obj.tools): - self.app.inform.emit(_('[ERROR_NOTCL] Cancelled. Empty file, it has no geometry...')) + self.app.inform.emit(_tr('[ERROR_NOTCL] Cancelled. Empty file, it has no geometry...')) return 'fail' # use the name of the first tool selected in self.geo_tools_table which has the diameter passed as tool_dia @@ -1241,7 +1248,7 @@ class SolderPaste(FlatCAMTool): def job_thread(app_obj): with self.app.proc_container.new("Generating CNC Code"): if app_obj.new_object("cncjob", name, job_init) != 'fail': - app_obj.inform.emit(_("[success] ToolSolderPaste CNCjob created: %s") % name) + app_obj.inform.emit(_tr("[success] ToolSolderPaste CNCjob created: %s") % name) app_obj.progress.emit(100) # Create a promise with the name @@ -1273,11 +1280,11 @@ class SolderPaste(FlatCAMTool): try: if obj.special_group != 'solder_paste_tool': - self.app.inform.emit(_("[WARNING_NOTCL] This CNCJob object can't be processed. " + self.app.inform.emit(_tr("[WARNING_NOTCL] This CNCJob object can't be processed. " "NOT a solder_paste_tool CNCJob object.")) return except AttributeError: - self.app.inform.emit(_("[WARNING_NOTCL] This CNCJob object can't be processed. " + self.app.inform.emit(_tr("[WARNING_NOTCL] This CNCJob object can't be processed. " "NOT a solder_paste_tool CNCJob object.")) return @@ -1300,7 +1307,7 @@ class SolderPaste(FlatCAMTool): try: lines = StringIO(gcode) except: - self.app.inform.emit(_("[ERROR_NOTCL] No Gcode in the object...")) + self.app.inform.emit(_tr("[ERROR_NOTCL] No Gcode in the object...")) return try: @@ -1309,7 +1316,7 @@ class SolderPaste(FlatCAMTool): self.app.ui.code_editor.append(proc_line) except Exception as e: log.debug('ToolSolderPaste.on_view_gcode() -->%s' % str(e)) - self.app.inform.emit(_('[ERROR] ToolSolderPaste.on_view_gcode() -->%s') % str(e)) + self.app.inform.emit(_tr('[ERROR] ToolSolderPaste.on_view_gcode() -->%s') % str(e)) return self.app.ui.code_editor.moveCursor(QtGui.QTextCursor.Start) @@ -1328,7 +1335,7 @@ class SolderPaste(FlatCAMTool): obj = self.app.collection.get_by_name(name) if obj.special_group != 'solder_paste_tool': - self.app.inform.emit(_("[WARNING_NOTCL] This CNCJob object can't be processed. " + self.app.inform.emit(_tr("[WARNING_NOTCL] This CNCJob object can't be processed. " "NOT a solder_paste_tool CNCJob object.")) return @@ -1346,7 +1353,7 @@ class SolderPaste(FlatCAMTool): filename, _ = QtWidgets.QFileDialog.getSaveFileName(caption="Export Machine Code ...", filter=_filter_) if filename == '': - self.app.inform.emit(_("[WARNING_NOTCL] Export Machine Code cancelled ...")) + self.app.inform.emit(_tr("[WARNING_NOTCL] Export Machine Code cancelled ...")) return gcode = '(G-CODE GENERATED BY FLATCAM v%s - www.flatcam.org - Version Date: %s)\n' % \ @@ -1372,11 +1379,11 @@ class SolderPaste(FlatCAMTool): for line in lines: f.write(line) except FileNotFoundError: - self.app.inform.emit(_("[WARNING_NOTCL] No such file or directory")) + self.app.inform.emit(_tr("[WARNING_NOTCL] No such file or directory")) return self.app.file_saved.emit("gcode", filename) - self.app.inform.emit(_("[success] Solder paste dispenser GCode file saved to: %s") % filename) + self.app.inform.emit(_tr("[success] Solder paste dispenser GCode file saved to: %s") % filename) def reset_fields(self): self.obj_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex())) diff --git a/flatcamTools/ToolTransform.py b/flatcamTools/ToolTransform.py index 3364c531..4c6328e2 100644 --- a/flatcamTools/ToolTransform.py +++ b/flatcamTools/ToolTransform.py @@ -9,14 +9,21 @@ import FlatCAMTranslation as fcTranslate fcTranslate.apply_language('ToolTransform') +def _tr(text): + try: + return _(text) + except: + return text + + class ToolTransform(FlatCAMTool): - toolName = _("Object Transform") - rotateName = _("Rotate") - skewName = _("Skew/Shear") - scaleName = _("Scale") - flipName = _("Mirror (Flip)") - offsetName = _("Offset") + toolName = _tr("Object Transform") + rotateName = _tr("Rotate") + skewName = _tr("Skew/Shear") + scaleName = _tr("Scale") + flipName = _tr("Mirror (Flip)") + offsetName = _tr("Offset") def __init__(self, app): FlatCAMTool.__init__(self, app) @@ -56,9 +63,9 @@ class ToolTransform(FlatCAMTool): self.transform_lay.addLayout(form_layout) form_child = QtWidgets.QHBoxLayout() - self.rotate_label = QtWidgets.QLabel(_("Angle:")) + self.rotate_label = QtWidgets.QLabel(_tr("Angle:")) self.rotate_label.setToolTip( - _("Angle for Rotation action, in degrees.\n" + _tr("Angle for Rotation action, in degrees.\n" "Float number between -360 and 359.\n" "Positive numbers for CW motion.\n" "Negative numbers for CCW motion.") @@ -70,9 +77,9 @@ class ToolTransform(FlatCAMTool): self.rotate_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) self.rotate_button = FCButton() - self.rotate_button.set_value(_("Rotate")) + self.rotate_button.set_value(_tr("Rotate")) self.rotate_button.setToolTip( - _("Rotate the selected object(s).\n" + _tr("Rotate the selected object(s).\n" "The point of reference is the middle of\n" "the bounding box for all selected objects.") ) @@ -95,9 +102,9 @@ class ToolTransform(FlatCAMTool): form1_child_1 = QtWidgets.QHBoxLayout() form1_child_2 = QtWidgets.QHBoxLayout() - self.skewx_label = QtWidgets.QLabel(_("Angle X:")) + self.skewx_label = QtWidgets.QLabel(_tr("Angle X:")) self.skewx_label.setToolTip( - _("Angle for Skew action, in degrees.\n" + _tr("Angle for Skew action, in degrees.\n" "Float number between -360 and 359.") ) self.skewx_label.setFixedWidth(50) @@ -106,16 +113,16 @@ class ToolTransform(FlatCAMTool): # self.skewx_entry.setFixedWidth(60) self.skewx_button = FCButton() - self.skewx_button.set_value(_("Skew X")) + self.skewx_button.set_value(_tr("Skew X")) self.skewx_button.setToolTip( - _("Skew/shear the selected object(s).\n" + _tr("Skew/shear the selected object(s).\n" "The point of reference is the middle of\n" "the bounding box for all selected objects.")) self.skewx_button.setFixedWidth(60) - self.skewy_label = QtWidgets.QLabel(_("Angle Y:")) + self.skewy_label = QtWidgets.QLabel(_tr("Angle Y:")) self.skewy_label.setToolTip( - _("Angle for Skew action, in degrees.\n" + _tr("Angle for Skew action, in degrees.\n" "Float number between -360 and 359.") ) self.skewy_label.setFixedWidth(50) @@ -124,9 +131,9 @@ class ToolTransform(FlatCAMTool): # self.skewy_entry.setFixedWidth(60) self.skewy_button = FCButton() - self.skewy_button.set_value(_("Skew Y")) + self.skewy_button.set_value(_tr("Skew Y")) self.skewy_button.setToolTip( - _("Skew/shear the selected object(s).\n" + _tr("Skew/shear the selected object(s).\n" "The point of reference is the middle of\n" "the bounding box for all selected objects.")) self.skewy_button.setFixedWidth(60) @@ -152,9 +159,9 @@ class ToolTransform(FlatCAMTool): form2_child_1 = QtWidgets.QHBoxLayout() form2_child_2 = QtWidgets.QHBoxLayout() - self.scalex_label = QtWidgets.QLabel(_("Factor X:")) + self.scalex_label = QtWidgets.QLabel(_tr("Factor X:")) self.scalex_label.setToolTip( - _("Factor for Scale action over X axis.") + _tr("Factor for Scale action over X axis.") ) self.scalex_label.setFixedWidth(50) self.scalex_entry = FCEntry() @@ -162,16 +169,16 @@ class ToolTransform(FlatCAMTool): # self.scalex_entry.setFixedWidth(60) self.scalex_button = FCButton() - self.scalex_button.set_value(_("Scale X")) + self.scalex_button.set_value(_tr("Scale X")) self.scalex_button.setToolTip( - _("Scale the selected object(s).\n" + _tr("Scale the selected object(s).\n" "The point of reference depends on \n" "the Scale reference checkbox state.")) self.scalex_button.setFixedWidth(60) - self.scaley_label = QtWidgets.QLabel(_("Factor Y:")) + self.scaley_label = QtWidgets.QLabel(_tr("Factor Y:")) self.scaley_label.setToolTip( - _("Factor for Scale action over Y axis.") + _tr("Factor for Scale action over Y axis.") ) self.scaley_label.setFixedWidth(50) self.scaley_entry = FCEntry() @@ -179,26 +186,26 @@ class ToolTransform(FlatCAMTool): # self.scaley_entry.setFixedWidth(60) self.scaley_button = FCButton() - self.scaley_button.set_value(_("Scale Y")) + self.scaley_button.set_value(_tr("Scale Y")) self.scaley_button.setToolTip( - _("Scale the selected object(s).\n" + _tr("Scale the selected object(s).\n" "The point of reference depends on \n" "the Scale reference checkbox state.")) self.scaley_button.setFixedWidth(60) self.scale_link_cb = FCCheckBox() self.scale_link_cb.set_value(True) - self.scale_link_cb.setText(_("Link")) + self.scale_link_cb.setText(_tr("Link")) self.scale_link_cb.setToolTip( - _("Scale the selected object(s)\n" + _tr("Scale the selected object(s)\n" "using the Scale Factor X for both axis.")) self.scale_link_cb.setFixedWidth(50) self.scale_zero_ref_cb = FCCheckBox() self.scale_zero_ref_cb.set_value(True) - self.scale_zero_ref_cb.setText(_("Scale Reference")) + self.scale_zero_ref_cb.setText(_tr("Scale Reference")) self.scale_zero_ref_cb.setToolTip( - _("Scale the selected object(s)\n" + _tr("Scale the selected object(s)\n" "using the origin reference when checked,\n" "and the center of the biggest bounding box\n" "of the selected objects when unchecked.")) @@ -226,9 +233,9 @@ class ToolTransform(FlatCAMTool): form3_child_1 = QtWidgets.QHBoxLayout() form3_child_2 = QtWidgets.QHBoxLayout() - self.offx_label = QtWidgets.QLabel(_("Value X:")) + self.offx_label = QtWidgets.QLabel(_tr("Value X:")) self.offx_label.setToolTip( - _("Value for Offset action on X axis.") + _tr("Value for Offset action on X axis.") ) self.offx_label.setFixedWidth(50) self.offx_entry = FCEntry() @@ -236,16 +243,16 @@ class ToolTransform(FlatCAMTool): # self.offx_entry.setFixedWidth(60) self.offx_button = FCButton() - self.offx_button.set_value(_("Offset X")) + self.offx_button.set_value(_tr("Offset X")) self.offx_button.setToolTip( - _("Offset the selected object(s).\n" + _tr("Offset the selected object(s).\n" "The point of reference is the middle of\n" "the bounding box for all selected objects.\n")) self.offx_button.setFixedWidth(60) - self.offy_label = QtWidgets.QLabel(_("Value Y:")) + self.offy_label = QtWidgets.QLabel(_tr("Value Y:")) self.offy_label.setToolTip( - _("Value for Offset action on Y axis.") + _tr("Value for Offset action on Y axis.") ) self.offy_label.setFixedWidth(50) self.offy_entry = FCEntry() @@ -253,9 +260,9 @@ class ToolTransform(FlatCAMTool): # self.offy_entry.setFixedWidth(60) self.offy_button = FCButton() - self.offy_button.set_value(_("Offset Y")) + self.offy_button.set_value(_tr("Offset Y")) self.offy_button.setToolTip( - _("Offset the selected object(s).\n" + _tr("Offset the selected object(s).\n" "The point of reference is the middle of\n" "the bounding box for all selected objects.\n")) self.offy_button.setFixedWidth(60) @@ -283,26 +290,26 @@ class ToolTransform(FlatCAMTool): form4_child_1 = QtWidgets.QHBoxLayout() self.flipx_button = FCButton() - self.flipx_button.set_value(_("Flip on X")) + self.flipx_button.set_value(_tr("Flip on X")) self.flipx_button.setToolTip( - _("Flip the selected object(s) over the X axis.\n" + _tr("Flip the selected object(s) over the X axis.\n" "Does not create a new object.\n ") ) self.flipx_button.setFixedWidth(60) self.flipy_button = FCButton() - self.flipy_button.set_value(_("Flip on Y")) + self.flipy_button.set_value(_tr("Flip on Y")) self.flipy_button.setToolTip( - _("Flip the selected object(s) over the X axis.\n" + _tr("Flip the selected object(s) over the X axis.\n" "Does not create a new object.\n ") ) self.flipy_button.setFixedWidth(60) self.flip_ref_cb = FCCheckBox() self.flip_ref_cb.set_value(True) - self.flip_ref_cb.setText(_("Ref Pt")) + self.flip_ref_cb.setText(_tr("Ref Pt")) self.flip_ref_cb.setToolTip( - _("Flip the selected object(s)\n" + _tr("Flip the selected object(s)\n" "around the point in Point Entry Field.\n" "\n" "The point coordinates can be captured by\n" @@ -313,9 +320,9 @@ class ToolTransform(FlatCAMTool): "Point Entry field and click Flip on X(Y)")) self.flip_ref_cb.setFixedWidth(50) - self.flip_ref_label = QtWidgets.QLabel(_("Point:")) + self.flip_ref_label = QtWidgets.QLabel(_tr("Point:")) self.flip_ref_label.setToolTip( - _("Coordinates in format (x, y) used as reference for mirroring.\n" + _tr("Coordinates in format (x, y) used as reference for mirroring.\n" "The 'x' in (x, y) will be used when using Flip on X and\n" "the 'y' in (x, y) will be used when using Flip on Y and") ) @@ -325,9 +332,9 @@ class ToolTransform(FlatCAMTool): # self.flip_ref_entry.setFixedWidth(60) self.flip_ref_button = FCButton() - self.flip_ref_button.set_value(_("Add")) + self.flip_ref_button.set_value(_tr("Add")) self.flip_ref_button.setToolTip( - _("The point coordinates can be captured by\n" + _tr("The point coordinates can be captured by\n" "left click on canvas together with pressing\n" "SHIFT key. Then click Add button to insert.")) self.flip_ref_button.setFixedWidth(60) @@ -383,7 +390,7 @@ class ToolTransform(FlatCAMTool): FlatCAMTool.run(self) self.set_tool_ui() - self.app.ui.notebook.setTabText(2, _("Transform Tool")) + self.app.ui.notebook.setTabText(2, _tr("Transform Tool")) def install(self, icon=None, separator=None, **kwargs): FlatCAMTool.install(self, icon, separator, shortcut='ALT+T', **kwargs) @@ -453,7 +460,7 @@ class ToolTransform(FlatCAMTool): try: value = float(self.rotate_entry.get_value().replace(',', '.')) except ValueError: - self.app.inform.emit(_("[ERROR_NOTCL]Wrong value format entered for Rotate, " + self.app.inform.emit(_tr("[ERROR_NOTCL]Wrong value format entered for Rotate, " "use a number.")) return self.app.worker_task.emit({'fcn': self.on_rotate_action, @@ -487,7 +494,7 @@ class ToolTransform(FlatCAMTool): try: value = float(self.skewx_entry.get_value().replace(',', '.')) except ValueError: - self.app.inform.emit(_("[ERROR_NOTCL]Wrong value format entered for Skew X, " + self.app.inform.emit(_tr("[ERROR_NOTCL]Wrong value format entered for Skew X, " "use a number.")) return @@ -505,7 +512,7 @@ class ToolTransform(FlatCAMTool): try: value = float(self.skewy_entry.get_value().replace(',', '.')) except ValueError: - self.app.inform.emit(_("[ERROR_NOTCL]Wrong value format entered for Skew Y, " + self.app.inform.emit(_tr("[ERROR_NOTCL]Wrong value format entered for Skew Y, " "use a number.")) return @@ -523,7 +530,7 @@ class ToolTransform(FlatCAMTool): try: xvalue = float(self.scalex_entry.get_value().replace(',', '.')) except ValueError: - self.app.inform.emit(_("[ERROR_NOTCL]Wrong value format entered for Scale X, " + self.app.inform.emit(_tr("[ERROR_NOTCL]Wrong value format entered for Scale X, " "use a number.")) return @@ -557,7 +564,7 @@ class ToolTransform(FlatCAMTool): try: yvalue = float(self.scaley_entry.get_value().replace(',', '.')) except ValueError: - self.app.inform.emit(_("[ERROR_NOTCL]Wrong value format entered for Scale Y, " + self.app.inform.emit(_tr("[ERROR_NOTCL]Wrong value format entered for Scale Y, " "use a number.")) return @@ -586,7 +593,7 @@ class ToolTransform(FlatCAMTool): try: value = float(self.offx_entry.get_value().replace(',', '.')) except ValueError: - self.app.inform.emit(_("[ERROR_NOTCL]Wrong value format entered for Offset X, " + self.app.inform.emit(_tr("[ERROR_NOTCL]Wrong value format entered for Offset X, " "use a number.")) return @@ -604,7 +611,7 @@ class ToolTransform(FlatCAMTool): try: value = float(self.offy_entry.get_value().replace(',', '.')) except ValueError: - self.app.inform.emit(_("[ERROR_NOTCL]Wrong value format entered for Offset Y, " + self.app.inform.emit(_tr("[ERROR_NOTCL]Wrong value format entered for Offset Y, " "use a number.")) return @@ -622,10 +629,10 @@ class ToolTransform(FlatCAMTool): ymaxlist = [] if not obj_list: - self.app.inform.emit(_("[WARNING_NOTCL] No object selected. Please Select an object to rotate!")) + self.app.inform.emit(_tr("[WARNING_NOTCL] No object selected. Please Select an object to rotate!")) return else: - with self.app.proc_container.new(_("Appying Rotate")): + with self.app.proc_container.new(_tr("Appying Rotate")): try: # first get a bounding box to fit all for obj in obj_list: @@ -650,7 +657,7 @@ class ToolTransform(FlatCAMTool): px = 0.5 * (xminimal + xmaximal) py = 0.5 * (yminimal + ymaximal) if isinstance(sel_obj, FlatCAMCNCjob): - self.app.inform.emit(_("CNCJob objects can't be rotated.")) + self.app.inform.emit(_tr("CNCJob objects can't be rotated.")) else: sel_obj.rotate(-num, point=(px, py)) sel_obj.plot() @@ -659,11 +666,11 @@ class ToolTransform(FlatCAMTool): # add information to the object that it was changed and how much sel_obj.options['rotate'] = num - self.app.inform.emit(_('[success]Rotate done ...')) + self.app.inform.emit(_tr('[success]Rotate done ...')) self.app.progress.emit(100) except Exception as e: - self.app.inform.emit(_("[ERROR_NOTCL] Due of %s, rotation movement was not executed.") % str(e)) + self.app.inform.emit(_tr("[ERROR_NOTCL] Due of %s, rotation movement was not executed.") % str(e)) return def on_flip(self, axis): @@ -674,10 +681,10 @@ class ToolTransform(FlatCAMTool): ymaxlist = [] if not obj_list: - self.app.inform.emit(_("[WARNING_NOTCL] No object selected. Please Select an object to flip!")) + self.app.inform.emit(_tr("[WARNING_NOTCL] No object selected. Please Select an object to flip!")) return else: - with self.app.proc_container.new(_("Applying Flip")): + with self.app.proc_container.new(_tr("Applying Flip")): try: # get mirroring coords from the point entry if self.flip_ref_cb.isChecked(): @@ -709,7 +716,7 @@ class ToolTransform(FlatCAMTool): # execute mirroring for obj in obj_list: if isinstance(obj, FlatCAMCNCjob): - self.app.inform.emit(_("CNCJob objects can't be mirrored/flipped.")) + self.app.inform.emit(_tr("CNCJob objects can't be mirrored/flipped.")) else: if axis is 'X': obj.mirror('X', (px, py)) @@ -720,7 +727,7 @@ class ToolTransform(FlatCAMTool): else: obj.options['mirror_y'] = True obj.plot() - self.app.inform.emit(_('[success]Flip on the Y axis done ...')) + self.app.inform.emit(_tr('[success]Flip on the Y axis done ...')) elif axis is 'Y': obj.mirror('Y', (px, py)) # add information to the object that it was changed and how much @@ -730,12 +737,12 @@ class ToolTransform(FlatCAMTool): else: obj.options['mirror_x'] = True obj.plot() - self.app.inform.emit(_('[success]Flip on the X axis done ...')) + self.app.inform.emit(_tr('[success]Flip on the X axis done ...')) self.app.object_changed.emit(obj) self.app.progress.emit(100) except Exception as e: - self.app.inform.emit(_("[ERROR_NOTCL] Due of %s, Flip action was not executed.") % str(e)) + self.app.inform.emit(_tr("[ERROR_NOTCL] Due of %s, Flip action was not executed.") % str(e)) return def on_skew(self, axis, num): @@ -744,10 +751,10 @@ class ToolTransform(FlatCAMTool): yminlist = [] if not obj_list: - self.app.inform.emit(_("[WARNING_NOTCL] No object selected. Please Select an object to shear/skew!")) + self.app.inform.emit(_tr("[WARNING_NOTCL] No object selected. Please Select an object to shear/skew!")) return else: - with self.app.proc_container.new(_("Applying Skew")): + with self.app.proc_container.new(_tr("Applying Skew")): try: # first get a bounding box to fit all for obj in obj_list: @@ -766,7 +773,7 @@ class ToolTransform(FlatCAMTool): for obj in obj_list: if isinstance(obj, FlatCAMCNCjob): - self.app.inform.emit(_("CNCJob objects can't be skewed.")) + self.app.inform.emit(_tr("CNCJob objects can't be skewed.")) else: if axis is 'X': obj.skew(num, 0, point=(xminimal, yminimal)) @@ -778,11 +785,11 @@ class ToolTransform(FlatCAMTool): obj.options['skew_y'] = num obj.plot() self.app.object_changed.emit(obj) - self.app.inform.emit(_('[success]Skew on the %s axis done ...') % str(axis)) + self.app.inform.emit(_tr('[success]Skew on the %s axis done ...') % str(axis)) self.app.progress.emit(100) except Exception as e: - self.app.inform.emit(_("[ERROR_NOTCL] Due of %s, Skew action was not executed.") % str(e)) + self.app.inform.emit(_tr("[ERROR_NOTCL] Due of %s, Skew action was not executed.") % str(e)) return def on_scale(self, axis, xfactor, yfactor, point=None): @@ -793,10 +800,10 @@ class ToolTransform(FlatCAMTool): ymaxlist = [] if not obj_list: - self.app.inform.emit(_("[WARNING_NOTCL] No object selected. Please Select an object to scale!")) + self.app.inform.emit(_tr("[WARNING_NOTCL] No object selected. Please Select an object to scale!")) return else: - with self.app.proc_container.new(_("Applying Scale")): + with self.app.proc_container.new(_tr("Applying Scale")): try: # first get a bounding box to fit all for obj in obj_list: @@ -826,7 +833,7 @@ class ToolTransform(FlatCAMTool): for obj in obj_list: if isinstance(obj, FlatCAMCNCjob): - self.app.inform.emit(_("CNCJob objects can't be scaled.")) + self.app.inform.emit(_tr("CNCJob objects can't be scaled.")) else: obj.scale(xfactor, yfactor, point=(px, py)) # add information to the object that it was changed and how much @@ -834,10 +841,10 @@ class ToolTransform(FlatCAMTool): obj.options['scale_y'] = yfactor obj.plot() self.app.object_changed.emit(obj) - self.app.inform.emit(_('[success] Scale on the %s axis done ...') % str(axis)) + self.app.inform.emit(_tr('[success] Scale on the %s axis done ...') % str(axis)) self.app.progress.emit(100) except Exception as e: - self.app.inform.emit(_("[ERROR_NOTCL] Due of %s, Scale action was not executed.") % str(e)) + self.app.inform.emit(_tr("[ERROR_NOTCL] Due of %s, Scale action was not executed.") % str(e)) return def on_offset(self, axis, num): @@ -846,10 +853,10 @@ class ToolTransform(FlatCAMTool): yminlist = [] if not obj_list: - self.app.inform.emit(_("[WARNING_NOTCL] No object selected. Please Select an object to offset!")) + self.app.inform.emit(_tr("[WARNING_NOTCL] No object selected. Please Select an object to offset!")) return else: - with self.app.proc_container.new(_("Applying Offset")): + with self.app.proc_container.new(_tr("Applying Offset")): try: # first get a bounding box to fit all for obj in obj_list: @@ -867,7 +874,7 @@ class ToolTransform(FlatCAMTool): for obj in obj_list: if isinstance(obj, FlatCAMCNCjob): - self.app.inform.emit(_("CNCJob objects can't be offseted.")) + self.app.inform.emit(_tr("CNCJob objects can't be offseted.")) else: if axis is 'X': obj.offset((num, 0)) @@ -879,11 +886,11 @@ class ToolTransform(FlatCAMTool): obj.options['offset_y'] = num obj.plot() self.app.object_changed.emit(obj) - self.app.inform.emit(_('[success]Offset on the %s axis done ...') % str(axis)) + self.app.inform.emit(_tr('[success]Offset on the %s axis done ...') % str(axis)) self.app.progress.emit(100) except Exception as e: - self.app.inform.emit(_("[ERROR_NOTCL] Due of %s, Offset action was not executed.") % str(e)) + self.app.inform.emit(_tr("[ERROR_NOTCL] Due of %s, Offset action was not executed.") % str(e)) return # end of file