- fixed an issue in old default file detection and in saving the factory defaults file

- in Preferences window removed the Import/Export Preferences buttons because they are redundant with the entries in the File -> Menu -> Backup. and added a button to Restore Defaults
- when in Basic mode the Tool type of the tool in the Geometry UI Tool Table after isolating a Gerber object is automatically selected as 'C1'
- let the multiprocessing Pool have as many processes as needed
- added a new Preferences setting allowing a custom mouse line width (to make it thicker or thinner)
This commit is contained in:
Marius Stanciu 2019-12-25 17:51:37 +02:00 committed by Marius
parent 448235b84a
commit fcc52a2682
15 changed files with 167 additions and 102 deletions

View File

@ -512,6 +512,7 @@ class App(QtCore.QObject):
"global_layout": "compact",
"global_cursor_type": "small",
"global_cursor_size": 20,
"global_cursor_width": 2,
# Gerber General
"gerber_plot": True,
@ -993,7 +994,7 @@ class App(QtCore.QObject):
# ##################### CREATE MULTIPROCESSING POOL ###########################
# #############################################################################
self.pool = Pool(processes=cpu_count())
self.pool = Pool()
# ##########################################################################
# ################## Setting the Splash Screen #############################
@ -1136,6 +1137,7 @@ class App(QtCore.QObject):
"global_delete_confirmation": self.ui.general_defaults_form.general_gui_set_group.delete_conf_cb,
"global_cursor_type": self.ui.general_defaults_form.general_gui_set_group.cursor_radio,
"global_cursor_size": self.ui.general_defaults_form.general_gui_set_group.cursor_size_entry,
"global_cursor_width": self.ui.general_defaults_form.general_gui_set_group.cursor_width_entry,
# Gerber General
"gerber_plot": self.ui.gerber_defaults_form.gerber_gen_group.plot_cb,
@ -1548,6 +1550,30 @@ class App(QtCore.QObject):
# When the self.defaults dictionary changes will update the Preferences GUI forms
self.defaults.set_change_callback(self.on_defaults_dict_change)
# ##############################################################################
# ########################## FIRST RUN SECTION #################################
# ##################### It's done only once after install ####################
# ##############################################################################
if self.defaults["first_run"] is True:
self.save_factory_defaults(silent_message=False)
# and then make the factory_defaults.FlatConfig file read_only so it can't be modified after creation.
filename_factory = self.data_path + '/factory_defaults.FlatConfig'
os.chmod(filename_factory, S_IREAD | S_IRGRP | S_IROTH)
# ONLY AT FIRST STARTUP INIT THE GUI LAYOUT TO 'COMPACT'
initial_lay = 'compact'
self.on_layout(lay=initial_lay)
# Set the combobox in Preferences to the current layout
idx = self.ui.general_defaults_form.general_gui_set_group.layout_combo.findText(initial_lay)
self.ui.general_defaults_form.general_gui_set_group.layout_combo.setCurrentIndex(idx)
# after the first run, this object should be False
self.defaults["first_run"] = False
self.save_defaults(silent=True)
# #############################################################################
# ############################## Data #########################################
# #############################################################################
@ -1953,8 +1979,7 @@ class App(QtCore.QObject):
self.ui.pref_apply_button.clicked.connect(lambda: self.on_save_button(save_to_file=False))
self.ui.pref_close_button.clicked.connect(self.on_pref_close_button)
self.ui.pref_import_button.clicked.connect(self.on_import_preferences)
self.ui.pref_export_button.clicked.connect(self.on_export_preferences)
self.ui.pref_defaults_button.clicked.connect(self.on_restore_defaults_preferences)
self.ui.pref_open_button.clicked.connect(self.on_preferences_open_folder)
# #############################################################################
@ -2645,35 +2670,6 @@ class App(QtCore.QObject):
from flatcamGUI.PlotCanvasLegacy import ShapeCollectionLegacy
self.tool_shapes = ShapeCollectionLegacy(obj=self, app=self, name="tool")
# ###############################################################################
# ############# Save defaults to factory_defaults.FlatConfig file ###############
# ############# It's done only once after install ###############
# ###############################################################################
factory_file = open(self.data_path + '/factory_defaults.FlatConfig')
fac_def_from_file = factory_file.read()
factory_defaults = json.loads(fac_def_from_file)
# if the file contain an empty dictionary then save the factory defaults into the file
if self.defaults["first_run"] is True:
self.save_factory_defaults(silent_message=False)
# ONLY AT FIRST STARTUP INIT THE GUI LAYOUT TO 'COMPACT'
initial_lay = 'compact'
self.on_layout(lay=initial_lay)
# Set the combobox in Preferences to the current layout
idx = self.ui.general_defaults_form.general_gui_set_group.layout_combo.findText(initial_lay)
self.ui.general_defaults_form.general_gui_set_group.layout_combo.setCurrentIndex(idx)
factory_file.close()
# and then make the factory_defaults.FlatConfig file read_only so it can't be modified after creation.
filename_factory = self.data_path + '/factory_defaults.FlatConfig'
os.chmod(filename_factory, S_IREAD | S_IRGRP | S_IROTH)
# after the first run, this object should be False
self.defaults["first_run"] = False
# ###############################################################################
# ################# ADDING FlatCAM EDITORS section ##############################
# ###############################################################################
@ -3856,42 +3852,84 @@ class App(QtCore.QObject):
self.inform.emit('[ERROR] %s' % _("Failed to parse defaults file."))
return
if 'version' not in defaults or defaults['version'] != self.defaults['version']:
for k, v in defaults.items():
if k in self.defaults and k != 'version':
self.defaults[k] = v
if defaults:
if 'version' not in defaults or defaults['version'] != self.defaults['version']:
for k, v in defaults.items():
if k in self.defaults and k != 'version':
self.defaults[k] = v
# delete old factory defaults
try:
fact_def_file_path = os.path.join(self.data_path, 'factory_defaults.FlatConfig')
os.chmod(fact_def_file_path, stat.S_IRWXO | stat.S_IWRITE | stat.S_IWGRP)
os.remove(fact_def_file_path)
# delete old factory defaults
try:
fact_def_file_path = os.path.join(self.data_path, 'factory_defaults.FlatConfig')
os.chmod(fact_def_file_path, stat.S_IRWXO | stat.S_IWRITE | stat.S_IWGRP)
os.remove(fact_def_file_path)
# recreate a new factory defaults file and save the factory defaults data into it
f_f_def_s = open(self.data_path + "/factory_defaults.FlatConfig", "w")
json.dump(self.defaults, f_f_def_s, default=to_dict, indent=2, sort_keys=True)
f_f_def_s.close()
# recreate a new factory defaults file and save the factory defaults data into it
f_f_def_s = open(self.data_path + "/factory_defaults.FlatConfig", "w")
json.dump(self.defaults, f_f_def_s, default=to_dict, indent=2, sort_keys=True)
f_f_def_s.close()
# and then make the factory_defaults.FlatConfig file read_only so it can't be modified after creation.
os.chmod(fact_def_file_path, S_IREAD | S_IRGRP | S_IROTH)
except Exception as e:
log.debug("App.load_defaults() -> deleting old factory defaults file -> %s" % str(e))
# and then make the factory_defaults.FlatConfig file read_only so it can't be modified after creation.
os.chmod(fact_def_file_path, S_IREAD | S_IRGRP | S_IROTH)
except Exception as e:
log.debug("App.load_defaults() -> deleting old factory defaults file -> %s" % str(e))
self.old_defaults_found = True
else:
self.old_defaults_found = False
self.defaults.update(defaults)
self.old_defaults_found = True
else:
self.defaults.update(defaults)
log.debug("FlatCAM defaults loaded from: %s" % filename)
def on_import_preferences(self):
def on_restore_defaults_preferences(self):
"""
Loads the aplication's factory default settings from factory_defaults.FlatConfig into
Loads the application's factory default settings from factory_defaults.FlatConfig into
``self.defaults``.
:return: None
"""
App.log.debug("App.on_restore_defaults_preferences()")
filename = self.data_path + '/factory_defaults.FlatConfig'
if filename == "":
self.inform.emit('[WARNING_NOTCL] %s' % _("Preferences default restore was cancelled."))
else:
try:
f = open(filename)
options = f.read()
f.close()
except IOError:
self.log.error("Could not load factory defaults file.")
self.inform.emit('[ERROR_NOTCL] %s' % _("Could not load factory defaults file."))
return
try:
defaults_from_file = json.loads(options)
except Exception:
e = sys.exc_info()[0]
App.log.error(str(e))
self.inform.emit('[ERROR_NOTCL] %s' % _("Failed to parse factory defaults file."))
return
self.defaults.update(defaults_from_file)
# update the dict that is used to restore the values in the defaults form if Cancel is clicked in the
# Preferences window
self.current_defaults.update(defaults_from_file)
self.on_preferences_edited()
self.inform.emit('[success] %s' % _("Preferences default values are restored."))
def on_import_preferences(self):
"""
Loads the application default settings from a saved file into
``self.defaults`` dictionary.
:return: None
"""
self.report_usage("on_import_preferences")
App.log.debug("on_import_preferences()")
App.log.debug("App.on_import_preferences()")
filter_ = "Config File (*.FlatConfig);;All Files (*.*)"
try:
@ -3905,8 +3943,7 @@ class App(QtCore.QObject):
filename = str(filename)
if filename == "":
self.inform.emit('[WARNING_NOTCL] %s' %
_("FlatCAM preferences import cancelled."))
self.inform.emit('[WARNING_NOTCL] %s' % _("FlatCAM preferences import cancelled."))
else:
try:
f = open(filename)
@ -3914,8 +3951,7 @@ class App(QtCore.QObject):
f.close()
except IOError:
self.log.error("Could not load defaults file.")
self.inform.emit('[ERROR_NOTCL] %s' %
_("Could not load defaults file."))
self.inform.emit('[ERROR_NOTCL] %s' % _("Could not load defaults file."))
return
try:
@ -3923,8 +3959,7 @@ class App(QtCore.QObject):
except Exception:
e = sys.exc_info()[0]
App.log.error(str(e))
self.inform.emit('[ERROR_NOTCL] %s' %
_("Failed to parse defaults file."))
self.inform.emit('[ERROR_NOTCL] %s' % _("Failed to parse defaults file."))
return
self.defaults.update(defaults_from_file)
# update the dict that is used to restore the values in the defaults form if Cancel is clicked in the
@ -3932,8 +3967,7 @@ class App(QtCore.QObject):
self.current_defaults.update(defaults_from_file)
self.on_preferences_edited()
self.inform.emit('[success] %s: %s' %
(_("Imported Defaults from"), filename))
self.inform.emit('[success] %s: %s' % (_("Imported Defaults from"), filename))
def on_export_preferences(self):
"""
@ -3965,8 +3999,7 @@ class App(QtCore.QObject):
defaults_from_file = {}
if filename == "":
self.inform.emit('[WARNING_NOTCL] %s' %
_("FlatCAM preferences export cancelled."))
self.inform.emit('[WARNING_NOTCL] %s' % _("FlatCAM preferences export cancelled."))
return
else:
try:
@ -3987,8 +4020,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] %s' %
_("Could not load preferences file."))
self.inform.emit('[ERROR_NOTCL] %s' % _("Could not load preferences file."))
return
try:
@ -4007,14 +4039,12 @@ class App(QtCore.QObject):
json.dump(defaults_from_file, f, default=to_dict, indent=2, sort_keys=True)
f.close()
except Exception:
self.inform.emit('[ERROR_NOTCL] %s' %
_("Failed to write defaults to file."))
self.inform.emit('[ERROR_NOTCL] %s' % _("Failed to write defaults to file."))
return
if self.defaults["global_open_style"] is False:
self.file_opened.emit("preferences", filename)
self.file_saved.emit("preferences", filename)
self.inform.emit('[success] %s: %s' %
(_("Exported preferences to"), filename))
self.inform.emit('[success] %s: %s' % (_("Exported preferences to"), filename))
def on_preferences_open_folder(self):
"""
@ -7532,6 +7562,7 @@ class App(QtCore.QObject):
# Update cursor
self.app_cursor.set_data(np.asarray([(location[0], location[1])]),
symbol='++', edge_color=self.cursor_color_3D,
edge_width=self.defaults["global_cursor_width"],
size=self.defaults["global_cursor_size"])
# Set the position label
@ -8686,6 +8717,7 @@ class App(QtCore.QObject):
# Update cursor
self.app_cursor.set_data(np.asarray([(pos[0], pos[1])]),
symbol='++', edge_color=self.cursor_color_3D,
edge_width=self.defaults["global_cursor_width"],
size=self.defaults["global_cursor_size"])
else:
pos = (pos_canvas[0], pos_canvas[1])

View File

@ -738,6 +738,10 @@ class FlatCAMGerber(FlatCAMObj, Gerber):
self.ui.tool_type_label.hide()
self.ui.tool_type_radio.hide()
# override the Preferences Value; in Basic mode the Tool Type is always Circular ('C1')
self.ui.tool_type_radio.set_value('circular')
self.ui.tipdialabel.hide()
self.ui.tipdia_spinner.hide()
self.ui.tipanglelabel.hide()
@ -1436,7 +1440,10 @@ class FlatCAMGerber(FlatCAMObj, Gerber):
def iso_init(geo_obj, app_obj):
# Propagate options
geo_obj.options["cnctooldia"] = str(self.options["isotooldia"])
geo_obj.tool_type = self.ui.tool_type_radio.get_value().upper()
if self.ui.tool_type_radio.get_value() == 'v':
geo_obj.tool_type = 'V'
else:
geo_obj.tool_type = 'C1'
# if milling type is climb then the move is counter-clockwise around features
mill_t = 1 if milling_type == 'cl' else 0

View File

@ -9,6 +9,14 @@ CAD program, and create G-Code for Isolation routing.
=================================================
25.12.2019
- fixed an issue in old default file detection and in saving the factory defaults file
- in Preferences window removed the Import/Export Preferences buttons because they are redundant with the entries in the File -> Menu -> Backup. and added a button to Restore Defaults
- when in Basic mode the Tool type of the tool in the Geometry UI Tool Table after isolating a Gerber object is automatically selected as 'C1'
- let the multiprocessing Pool have as many processes as needed
- added a new Preferences setting allowing a custom mouse line width (to make it thicker or thinner)
24.12.2019
- edited some icons so they don't contain white background

View File

@ -3690,6 +3690,7 @@ class FlatCAMExcEditor(QtCore.QObject):
# Update cursor
self.app.app_cursor.set_data(np.asarray([(x, y)]), symbol='++', edge_color=self.app.cursor_color_3D,
edge_width=self.app.defaults["global_cursor_width"],
size=self.app.defaults["global_cursor_size"])
self.snap_x = x
@ -3739,6 +3740,7 @@ class FlatCAMExcEditor(QtCore.QObject):
# Update cursor
self.app.app_cursor.set_data(np.asarray([(x, y)]), symbol='++', edge_color=self.app.cursor_color_3D,
edge_width=self.app.defaults["global_cursor_width"],
size=self.app.defaults["global_cursor_size"])
def on_canvas_key_release(self, event):

View File

@ -3831,6 +3831,7 @@ class FlatCAMGeoEditor(QtCore.QObject):
# Update cursor
self.app.app_cursor.set_data(np.asarray([(x, y)]), symbol='++', edge_color=self.app.cursor_color_3D,
edge_width=self.app.defaults["global_cursor_width"],
size=self.app.defaults["global_cursor_size"])
self.snap_x = x

View File

@ -4543,6 +4543,7 @@ class FlatCAMGrbEditor(QtCore.QObject):
# Update cursor
self.app.app_cursor.set_data(np.asarray([(x, y)]), symbol='++', edge_color=self.app.cursor_color_3D,
edge_width=self.app.defaults["global_cursor_width"],
size=self.app.defaults["global_cursor_size"])
self.snap_x = x

View File

@ -1211,23 +1211,13 @@ class FlatCAMGUI(QtWidgets.QMainWindow):
self.pref_tab_bottom_layout_1.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter)
self.pref_tab_bottom_layout.addLayout(self.pref_tab_bottom_layout_1)
self.pref_import_button = QtWidgets.QPushButton()
self.pref_import_button.setText(_("Import Preferences"))
self.pref_import_button.setMinimumWidth(130)
self.pref_import_button.setToolTip(
_("Import a full set of FlatCAM settings from a file\n"
"previously saved on HDD.\n\n"
"FlatCAM automatically save a 'factory_defaults' file\n"
"on the first start. Do not delete that file."))
self.pref_tab_bottom_layout_1.addWidget(self.pref_import_button)
self.pref_export_button = QtWidgets.QPushButton()
self.pref_export_button.setText(_("Export Preferences"))
self.pref_export_button.setMinimumWidth(130)
self.pref_export_button.setToolTip(
_("Export a full set of FlatCAM settings in a file\n"
"that is saved on HDD."))
self.pref_tab_bottom_layout_1.addWidget(self.pref_export_button)
self.pref_defaults_button = QtWidgets.QPushButton()
self.pref_defaults_button.setText(_("Restore Defaults"))
self.pref_defaults_button.setMinimumWidth(130)
self.pref_defaults_button.setToolTip(
_("Restore the entire set of default valaues\n"
"to the initial values loaded after first launch."))
self.pref_tab_bottom_layout_1.addWidget(self.pref_defaults_button)
self.pref_open_button = QtWidgets.QPushButton()
self.pref_open_button.setText(_("Open Pref Folder"))

View File

@ -310,6 +310,7 @@ class PlotCanvas(QtCore.QObject, VisPyCanvas):
# Update cursor
self.fcapp.app_cursor.set_data(np.asarray([(pos[0], pos[1])]),
symbol='++', edge_color=self.fcapp.cursor_color_3D,
edge_width=self.fcapp.defaults["global_cursor_width"],
size=self.fcapp.defaults["global_cursor_size"])
def new_text_group(self, collection=None):

View File

@ -375,16 +375,19 @@ class PlotCanvasLegacy(QtCore.QObject):
pass
# log.debug("Cache updated the screen!")
def new_cursor(self, axes=None, big=None):
def new_cursor(self, axes=None, big=None, color=None):
# if axes is None:
# c = MplCursor(axes=self.axes, color='black', linewidth=1)
# else:
# c = MplCursor(axes=axes, color='black', linewidth=1)
if self.app.defaults['global_theme'] == 'white':
color = '#000000'
if color:
color = color
else:
color = '#FFFFFF'
if self.app.defaults['global_theme'] == 'white':
color = '#000000'
else:
color = '#FFFFFF'
if big is True:
self.big_cursor = True
@ -398,7 +401,7 @@ class PlotCanvasLegacy(QtCore.QObject):
return c
def draw_cursor(self, x_pos, y_pos):
def draw_cursor(self, x_pos, y_pos, color=None):
"""
Draw a cursor at the mouse grid snapped position
@ -408,10 +411,13 @@ class PlotCanvasLegacy(QtCore.QObject):
"""
# there is no point in drawing mouse cursor when panning as it jumps in a confusing way
if self.app.app_cursor.enabled is True and self.panning is False:
if self.app.defaults['global_theme'] == 'white':
color = '#000000'
if color:
color = color
else:
color = '#FFFFFF'
if self.app.defaults['global_theme'] == 'white':
color = '#000000'
else:
color = '#FFFFFF'
if self.big_cursor is False:
try:
@ -421,10 +427,11 @@ class PlotCanvasLegacy(QtCore.QObject):
# The size of the cursor is multiplied by 1.65 because that value made the cursor similar with the
# one in the OpenGL(3D) graphic engine
pointer_size = int(float(self.app.defaults["global_cursor_size"] ) * 1.65)
elements = self.axes.plot(x, y, '+', color=color, ms=pointer_size, mew=1, animated=True)
elements = self.axes.plot(x, y, '+', color=color, ms=pointer_size,
mew=self.app.defaults["global_cursor_width"], animated=True)
for el in elements:
self.axes.draw_artist(el)
except Exception as e:
except Exception:
# this happen at app initialization since self.app.geo_editor does not exist yet
# I could reshuffle the object instantiating order but what's the point?
# I could crash something else and that's pythonic, too

View File

@ -1009,6 +1009,18 @@ class GeneralGUISetGroupUI(OptionsGroupUI):
grid0.addWidget(self.cursor_size_lbl, 21, 0)
grid0.addWidget(self.cursor_size_entry, 21, 1)
self.cursor_width_lbl = QtWidgets.QLabel('%s:' % _('Mouse Cursor Width'))
self.cursor_width_lbl.setToolTip(
_("Set the line width of the mouse cursor, in pixels.")
)
self.cursor_width_entry = FCSpinner()
self.cursor_width_entry.set_range(1, 10)
self.cursor_width_entry.setWrapping(True)
grid0.addWidget(self.cursor_width_lbl, 22, 0)
grid0.addWidget(self.cursor_width_entry, 22, 1)
# Delete confirmation
self.delete_conf_cb = FCCheckBox(_('Delete object confirmation'))
self.delete_conf_cb.setToolTip(
@ -1016,7 +1028,7 @@ class GeneralGUISetGroupUI(OptionsGroupUI):
"whenever the Delete object(s) event is triggered, either by\n"
"menu shortcut or key shortcut.")
)
grid0.addWidget(self.delete_conf_cb, 22, 0, 1, 2)
grid0.addWidget(self.delete_conf_cb, 23, 0, 1, 2)
self.layout.addStretch()

View File

@ -50,7 +50,7 @@ def apply_patches():
try:
self._update_child_widget_dim()
except Exception as e:
print(e)
print("VisPyPatches.apply_patches._update_clipper() -> %s" % str(e))
Grid._prepare_draw = _prepare_draw
Grid._update_clipper = _update_clipper
@ -72,7 +72,7 @@ def apply_patches():
if GL:
GL.glDisable(GL.GL_LINE_SMOOTH)
GL.glLineWidth(1.0)
GL.glLineWidth(2.0)
if self._changed['pos']:
self.pos_buf.set_data(self._pos)

View File

@ -902,6 +902,7 @@ class ToolCopperThieving(FlatCAMTool):
self.app.app_cursor.set_data(np.asarray([(curr_pos[0], curr_pos[1])]),
symbol='++', edge_color=self.app.cursor_color_3D,
edge_width=self.app.defaults["global_cursor_width"],
size=self.app.defaults["global_cursor_size"])
# update the positions on status bar

View File

@ -396,6 +396,7 @@ class Distance(FlatCAMTool):
# Update cursor
self.app.app_cursor.set_data(np.asarray([(pos[0], pos[1])]),
symbol='++', edge_color=self.app.cursor_color_3D,
edge_width=self.app.defaults["global_cursor_width"],
size=self.app.defaults["global_cursor_size"])
else:
pos = (pos_canvas[0], pos_canvas[1])

View File

@ -1349,6 +1349,7 @@ class NonCopperClear(FlatCAMTool, Gerber):
self.app.app_cursor.set_data(np.asarray([(curr_pos[0], curr_pos[1])]),
symbol='++', edge_color=self.app.cursor_color_3D,
edge_width=self.app.defaults["global_cursor_width"],
size=self.app.defaults["global_cursor_size"])
# update the positions on status bar

View File

@ -1290,6 +1290,7 @@ class ToolPaint(FlatCAMTool, Gerber):
self.app.app_cursor.set_data(np.asarray([(curr_pos[0], curr_pos[1])]),
symbol='++', edge_color=self.app.cursor_color_3D,
edge_width=self.app.defaults["global_cursor_width"],
size=self.app.defaults["global_cursor_size"])
# update the positions on status bar