- some PEP8 cleanup in FlatCAMApp.py
This commit is contained in:
283
FlatCAMApp.py
283
FlatCAMApp.py
@@ -1,10 +1,10 @@
|
|||||||
############################################################
|
# ###########################################################
|
||||||
# FlatCAM: 2D Post-processing for Manufacturing #
|
# FlatCAM: 2D Post-processing for Manufacturing #
|
||||||
# http://flatcam.org #
|
# http://flatcam.org #
|
||||||
# Author: Juan Pablo Caram (c) #
|
# Author: Juan Pablo Caram (c) #
|
||||||
# Date: 2/5/2014 #
|
# Date: 2/5/2014 #
|
||||||
# MIT Licence #
|
# MIT Licence #
|
||||||
############################################################
|
# ###########################################################
|
||||||
|
|
||||||
import urllib.request, urllib.parse, urllib.error
|
import urllib.request, urllib.parse, urllib.error
|
||||||
import getopt
|
import getopt
|
||||||
@@ -25,9 +25,9 @@ import gc
|
|||||||
|
|
||||||
from xml.dom.minidom import parseString as parse_xml_string
|
from xml.dom.minidom import parseString as parse_xml_string
|
||||||
|
|
||||||
########################################
|
# #######################################
|
||||||
## Imports part of FlatCAM ##
|
# # Imports part of FlatCAM ##
|
||||||
########################################
|
# #######################################
|
||||||
from ObjectCollection import *
|
from ObjectCollection import *
|
||||||
from FlatCAMObj import *
|
from FlatCAMObj import *
|
||||||
from flatcamGUI.PlotCanvas import *
|
from flatcamGUI.PlotCanvas import *
|
||||||
@@ -52,15 +52,15 @@ import tclCommands
|
|||||||
|
|
||||||
import gettext
|
import gettext
|
||||||
import FlatCAMTranslation as fcTranslate
|
import FlatCAMTranslation as fcTranslate
|
||||||
|
import builtins
|
||||||
|
|
||||||
fcTranslate.apply_language('strings')
|
fcTranslate.apply_language('strings')
|
||||||
import builtins
|
|
||||||
if '_' not in builtins.__dict__:
|
if '_' not in builtins.__dict__:
|
||||||
_ = gettext.gettext
|
_ = gettext.gettext
|
||||||
|
|
||||||
########################################
|
# #######################################
|
||||||
## App ##
|
# # App ##
|
||||||
########################################
|
# #######################################
|
||||||
|
|
||||||
|
|
||||||
class App(QtCore.QObject):
|
class App(QtCore.QObject):
|
||||||
@@ -120,9 +120,9 @@ class App(QtCore.QObject):
|
|||||||
# flag is True if saving action has been triggered
|
# flag is True if saving action has been triggered
|
||||||
save_in_progress = False
|
save_in_progress = False
|
||||||
|
|
||||||
##################
|
# #################
|
||||||
## Signals ##
|
# # Signals ##
|
||||||
##################
|
# #################
|
||||||
|
|
||||||
# Inform the user
|
# Inform the user
|
||||||
# Handled by:
|
# Handled by:
|
||||||
@@ -191,9 +191,9 @@ class App(QtCore.QObject):
|
|||||||
|
|
||||||
self.main_thread = QtWidgets.QApplication.instance().thread()
|
self.main_thread = QtWidgets.QApplication.instance().thread()
|
||||||
|
|
||||||
###################
|
# ##################
|
||||||
### OS-specific ###
|
# ## OS-specific ###
|
||||||
###################
|
# ##################
|
||||||
|
|
||||||
# Folder for user settings.
|
# Folder for user settings.
|
||||||
if sys.platform == 'win32':
|
if sys.platform == 'win32':
|
||||||
@@ -209,9 +209,9 @@ class App(QtCore.QObject):
|
|||||||
self.data_path = os.path.expanduser('~') + '/.FlatCAM'
|
self.data_path = os.path.expanduser('~') + '/.FlatCAM'
|
||||||
self.os = 'unix'
|
self.os = 'unix'
|
||||||
|
|
||||||
###############################
|
# ##############################
|
||||||
### Setup folders and files ###
|
# ## Setup folders and files ###
|
||||||
###############################
|
# ##############################
|
||||||
|
|
||||||
if not os.path.exists(self.data_path):
|
if not os.path.exists(self.data_path):
|
||||||
os.makedirs(self.data_path)
|
os.makedirs(self.data_path)
|
||||||
@@ -272,9 +272,9 @@ class App(QtCore.QObject):
|
|||||||
# variable to store mouse coordinates
|
# variable to store mouse coordinates
|
||||||
self.mouse = [0, 0]
|
self.mouse = [0, 0]
|
||||||
|
|
||||||
####################
|
# ###################
|
||||||
## Initialize GUI ##
|
# # Initialize GUI ##
|
||||||
####################
|
# ###################
|
||||||
|
|
||||||
# FlatCAM colors used in plotting
|
# FlatCAM colors used in plotting
|
||||||
self.FC_light_green = '#BBF268BF'
|
self.FC_light_green = '#BBF268BF'
|
||||||
@@ -285,16 +285,15 @@ class App(QtCore.QObject):
|
|||||||
QtCore.QObject.__init__(self)
|
QtCore.QObject.__init__(self)
|
||||||
self.ui = FlatCAMGUI(self.version, self.beta, self)
|
self.ui = FlatCAMGUI(self.version, self.beta, self)
|
||||||
|
|
||||||
|
|
||||||
# self.connect(self.ui,
|
# self.connect(self.ui,
|
||||||
# QtCore.SIGNAL("geomUpdate(int, int, int, int, int)"),
|
# QtCore.SIGNAL("geomUpdate(int, int, int, int, int)"),
|
||||||
# self.save_geometry) PyQt4
|
# self.save_geometry) PyQt4
|
||||||
self.ui.geom_update[int, int, int, int, int].connect(self.save_geometry)
|
self.ui.geom_update[int, int, int, int, int].connect(self.save_geometry)
|
||||||
self.ui.final_save.connect(self.final_save)
|
self.ui.final_save.connect(self.final_save)
|
||||||
|
|
||||||
##############
|
# #############
|
||||||
#### Data ####
|
# ### Data ####
|
||||||
##############
|
# #############
|
||||||
self.recent = []
|
self.recent = []
|
||||||
self.clipboard = QtWidgets.QApplication.clipboard()
|
self.clipboard = QtWidgets.QApplication.clipboard()
|
||||||
self.proc_container = FCVisibleProcessContainer(self.ui.activity_view)
|
self.proc_container = FCVisibleProcessContainer(self.ui.activity_view)
|
||||||
@@ -567,9 +566,9 @@ class App(QtCore.QObject):
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#############################
|
# ############################
|
||||||
#### LOAD POSTPROCESSORS ####
|
# ### LOAD POSTPROCESSORS ####
|
||||||
#############################
|
# ############################
|
||||||
|
|
||||||
self.postprocessors = load_postprocessors(self)
|
self.postprocessors = load_postprocessors(self)
|
||||||
|
|
||||||
@@ -586,9 +585,9 @@ class App(QtCore.QObject):
|
|||||||
|
|
||||||
self.ui.excellon_defaults_form.excellon_opt_group.pp_excellon_name_cb.addItem(name)
|
self.ui.excellon_defaults_form.excellon_opt_group.pp_excellon_name_cb.addItem(name)
|
||||||
|
|
||||||
#############################
|
# ############################
|
||||||
#### LOAD LANGUAGES ####
|
# ### LOAD LANGUAGES ####
|
||||||
#############################
|
# ############################
|
||||||
|
|
||||||
self.languages = fcTranslate.load_languages()
|
self.languages = fcTranslate.load_languages()
|
||||||
for name in sorted(self.languages.values()):
|
for name in sorted(self.languages.values()):
|
||||||
@@ -644,7 +643,7 @@ class App(QtCore.QObject):
|
|||||||
"global_background_timeout": 300000, # Default value is 5 minutes
|
"global_background_timeout": 300000, # Default value is 5 minutes
|
||||||
"global_verbose_error_level": 0, # Shell verbosity 0 = default
|
"global_verbose_error_level": 0, # Shell verbosity 0 = default
|
||||||
# (python trace only for unknown errors),
|
# (python trace only for unknown errors),
|
||||||
# 1 = show trace(show trace allways),
|
# 1 = show trace(show trace always),
|
||||||
# 2 = (For the future).
|
# 2 = (For the future).
|
||||||
|
|
||||||
# Persistence
|
# Persistence
|
||||||
@@ -881,16 +880,16 @@ class App(QtCore.QObject):
|
|||||||
"tools_solderpaste_pp": 'Paste_1'
|
"tools_solderpaste_pp": 'Paste_1'
|
||||||
})
|
})
|
||||||
|
|
||||||
###############################
|
# ##############################
|
||||||
### Load defaults from file ###
|
# ## Load defaults from file ###
|
||||||
###############################
|
# ##############################
|
||||||
|
|
||||||
if user_defaults:
|
if user_defaults:
|
||||||
self.load_defaults(filename='current_defaults')
|
self.load_defaults(filename='current_defaults')
|
||||||
|
|
||||||
############################
|
# ###########################
|
||||||
##### APPLY APP LANGUAGE ###
|
# #### APPLY APP LANGUAGE ###
|
||||||
############################
|
# ###########################
|
||||||
|
|
||||||
ret_val = fcTranslate.apply_language('strings')
|
ret_val = fcTranslate.apply_language('strings')
|
||||||
|
|
||||||
@@ -903,9 +902,9 @@ class App(QtCore.QObject):
|
|||||||
log.debug("App.__init__() --> Applied %s language." % str(ret_val).capitalize())
|
log.debug("App.__init__() --> Applied %s language." % str(ret_val).capitalize())
|
||||||
|
|
||||||
|
|
||||||
###################################
|
# ##################################
|
||||||
### CREATE UNIQUE SERIAL NUMBER ###
|
# ## CREATE UNIQUE SERIAL NUMBER ###
|
||||||
###################################
|
# ##################################
|
||||||
|
|
||||||
chars = 'abcdefghijklmnopqrstuvwxyz0123456789'
|
chars = 'abcdefghijklmnopqrstuvwxyz0123456789'
|
||||||
if self.defaults['global_serial'] == 0 or len(str(self.defaults['global_serial'])) < 10:
|
if self.defaults['global_serial'] == 0 or len(str(self.defaults['global_serial'])) < 10:
|
||||||
@@ -1172,14 +1171,14 @@ class App(QtCore.QObject):
|
|||||||
self.tools_form = None
|
self.tools_form = None
|
||||||
self.on_options_combo_change(0) # Will show the initial form
|
self.on_options_combo_change(0) # Will show the initial form
|
||||||
|
|
||||||
### Define OBJECT COLLECTION ###
|
# ## Define OBJECT COLLECTION ###
|
||||||
self.collection = ObjectCollection(self)
|
self.collection = ObjectCollection(self)
|
||||||
self.ui.project_tab_layout.addWidget(self.collection.view)
|
self.ui.project_tab_layout.addWidget(self.collection.view)
|
||||||
###
|
# ##
|
||||||
|
|
||||||
self.log.debug("Finished creating Object Collection.")
|
self.log.debug("Finished creating Object Collection.")
|
||||||
|
|
||||||
### Initialize the color box's color in Preferences -> Global -> Color
|
# ## Initialize the color box's color in Preferences -> Global -> Color
|
||||||
# Init Plot Colors
|
# Init Plot Colors
|
||||||
self.ui.general_defaults_form.general_gui_group.pf_color_entry.set_value(self.defaults['global_plot_fill'])
|
self.ui.general_defaults_form.general_gui_group.pf_color_entry.set_value(self.defaults['global_plot_fill'])
|
||||||
self.ui.general_defaults_form.general_gui_group.pf_color_button.setStyleSheet(
|
self.ui.general_defaults_form.general_gui_group.pf_color_button.setStyleSheet(
|
||||||
@@ -1242,10 +1241,9 @@ class App(QtCore.QObject):
|
|||||||
self.defaults['global_proj_item_dis_color'])
|
self.defaults['global_proj_item_dis_color'])
|
||||||
self.ui.general_defaults_form.general_gui_group.proj_color_dis_button.setStyleSheet(
|
self.ui.general_defaults_form.general_gui_group.proj_color_dis_button.setStyleSheet(
|
||||||
"background-color:%s" % str(self.defaults['global_proj_item_dis_color'])[:7])
|
"background-color:%s" % str(self.defaults['global_proj_item_dis_color'])[:7])
|
||||||
|
# ### End of Data ####
|
||||||
|
|
||||||
#### End of Data ####
|
# ### Plot Area ####
|
||||||
|
|
||||||
#### Plot Area ####
|
|
||||||
start_plot_time = time.time() # debug
|
start_plot_time = time.time() # debug
|
||||||
self.plotcanvas = PlotCanvas(self.ui.right_layout, self)
|
self.plotcanvas = PlotCanvas(self.ui.right_layout, self)
|
||||||
|
|
||||||
@@ -1272,28 +1270,27 @@ class App(QtCore.QObject):
|
|||||||
end_plot_time = time.time()
|
end_plot_time = time.time()
|
||||||
self.log.debug("Finished Canvas initialization in %s seconds." % (str(end_plot_time - start_plot_time)))
|
self.log.debug("Finished Canvas initialization in %s seconds." % (str(end_plot_time - start_plot_time)))
|
||||||
|
|
||||||
### EDITOR section
|
# ## EDITOR section
|
||||||
self.geo_editor = FlatCAMGeoEditor(self, disabled=True)
|
self.geo_editor = FlatCAMGeoEditor(self, disabled=True)
|
||||||
self.exc_editor = FlatCAMExcEditor(self)
|
self.exc_editor = FlatCAMExcEditor(self)
|
||||||
self.grb_editor = FlatCAMGrbEditor(self)
|
self.grb_editor = FlatCAMGrbEditor(self)
|
||||||
|
|
||||||
#### Adjust tabs width ####
|
# ### Adjust tabs width ####
|
||||||
# self.collection.view.setMinimumWidth(self.ui.options_scroll_area.widget().sizeHint().width() +
|
# self.collection.view.setMinimumWidth(self.ui.options_scroll_area.widget().sizeHint().width() +
|
||||||
# self.ui.options_scroll_area.verticalScrollBar().sizeHint().width())
|
# self.ui.options_scroll_area.verticalScrollBar().sizeHint().width())
|
||||||
self.collection.view.setMinimumWidth(290)
|
self.collection.view.setMinimumWidth(290)
|
||||||
|
|
||||||
self.log.debug("Finished adding FlatCAM Editor's.")
|
self.log.debug("Finished adding FlatCAM Editor's.")
|
||||||
|
|
||||||
#### Worker ####
|
# ### Worker ####
|
||||||
if self.defaults["global_worker_number"]:
|
if self.defaults["global_worker_number"]:
|
||||||
self.workers = WorkerStack(workers_number=int(self.defaults["global_worker_number"]))
|
self.workers = WorkerStack(workers_number=int(self.defaults["global_worker_number"]))
|
||||||
else:
|
else:
|
||||||
self.workers = WorkerStack(workers_number=2)
|
self.workers = WorkerStack(workers_number=2)
|
||||||
self.worker_task.connect(self.workers.add_task)
|
self.worker_task.connect(self.workers.add_task)
|
||||||
|
|
||||||
|
# ## Signal handling ###
|
||||||
### Signal handling ###
|
# ## Custom signals
|
||||||
## Custom signals
|
|
||||||
self.inform.connect(self.info)
|
self.inform.connect(self.info)
|
||||||
self.app_quit.connect(self.quit_application)
|
self.app_quit.connect(self.quit_application)
|
||||||
self.message.connect(self.message_dialog)
|
self.message.connect(self.message_dialog)
|
||||||
@@ -1306,9 +1303,8 @@ class App(QtCore.QObject):
|
|||||||
self.file_opened.connect(lambda kind, filename: self.register_folder(filename))
|
self.file_opened.connect(lambda kind, filename: self.register_folder(filename))
|
||||||
self.file_saved.connect(lambda kind, filename: self.register_save_folder(filename))
|
self.file_saved.connect(lambda kind, filename: self.register_save_folder(filename))
|
||||||
|
|
||||||
|
# ## Standard signals
|
||||||
## Standard signals
|
# ## Menu
|
||||||
# Menu
|
|
||||||
self.ui.menufilenewproject.triggered.connect(self.on_file_new_click)
|
self.ui.menufilenewproject.triggered.connect(self.on_file_new_click)
|
||||||
self.ui.menufilenewgeo.triggered.connect(self.new_geometry_object)
|
self.ui.menufilenewgeo.triggered.connect(self.new_geometry_object)
|
||||||
self.ui.menufilenewgrb.triggered.connect(self.new_gerber_object)
|
self.ui.menufilenewgrb.triggered.connect(self.new_gerber_object)
|
||||||
@@ -1448,19 +1444,19 @@ class App(QtCore.QObject):
|
|||||||
self.ui.pref_export_button.clicked.connect(self.on_export_preferences)
|
self.ui.pref_export_button.clicked.connect(self.on_export_preferences)
|
||||||
self.ui.pref_open_button.clicked.connect(self.on_preferences_open_folder)
|
self.ui.pref_open_button.clicked.connect(self.on_preferences_open_folder)
|
||||||
|
|
||||||
###############################
|
# ##############################
|
||||||
### GUI PREFERENCES SIGNALS ###
|
# ## GUI PREFERENCES SIGNALS ###
|
||||||
###############################
|
# ##############################
|
||||||
self.ui.general_options_form.general_app_group.units_radio.group_toggle_fn = self.on_toggle_units
|
self.ui.general_options_form.general_app_group.units_radio.group_toggle_fn = self.on_toggle_units
|
||||||
self.ui.general_defaults_form.general_app_group.language_apply_btn.clicked.connect(
|
self.ui.general_defaults_form.general_app_group.language_apply_btn.clicked.connect(
|
||||||
lambda: fcTranslate.on_language_apply_click(self, restart=True)
|
lambda: fcTranslate.on_language_apply_click(self, restart=True)
|
||||||
)
|
)
|
||||||
self.ui.general_defaults_form.general_app_group.units_radio.activated_custom.connect(
|
self.ui.general_defaults_form.general_app_group.units_radio.activated_custom.connect(
|
||||||
lambda :self.on_toggle_units(no_pref=False))
|
lambda: self.on_toggle_units(no_pref=False))
|
||||||
|
|
||||||
###############################
|
# ##############################
|
||||||
### GUI PREFERENCES SIGNALS ###
|
# ## GUI PREFERENCES SIGNALS ###
|
||||||
###############################
|
# ##############################
|
||||||
|
|
||||||
# Setting plot colors signals
|
# Setting plot colors signals
|
||||||
self.ui.general_defaults_form.general_gui_group.pf_color_entry.editingFinished.connect(
|
self.ui.general_defaults_form.general_gui_group.pf_color_entry.editingFinished.connect(
|
||||||
@@ -1562,21 +1558,20 @@ class App(QtCore.QObject):
|
|||||||
else:
|
else:
|
||||||
self.ui.splitter.setSizes([0, 1])
|
self.ui.splitter.setSizes([0, 1])
|
||||||
|
|
||||||
|
# ###################
|
||||||
####################
|
# ## Other setups ###
|
||||||
### Other setups ###
|
# ###################
|
||||||
####################
|
|
||||||
# Sets up FlatCAMObj, FCProcess and FCProcessContainer.
|
# Sets up FlatCAMObj, FCProcess and FCProcessContainer.
|
||||||
self.setup_obj_classes()
|
self.setup_obj_classes()
|
||||||
|
|
||||||
self.setup_recent_items()
|
self.setup_recent_items()
|
||||||
self.setup_component_editor()
|
self.setup_component_editor()
|
||||||
|
|
||||||
#############
|
# ############
|
||||||
### Shell ###
|
# ## Shell ###
|
||||||
#############
|
# ############
|
||||||
|
|
||||||
###
|
# ##
|
||||||
# Auto-complete KEYWORDS
|
# Auto-complete KEYWORDS
|
||||||
self.tcl_commands_list = ['add_circle', 'add_poly', 'add_polygon', 'add_polyline', 'add_rectangle',
|
self.tcl_commands_list = ['add_circle', 'add_poly', 'add_polygon', 'add_polyline', 'add_rectangle',
|
||||||
'aligndrill', 'clear',
|
'aligndrill', 'clear',
|
||||||
@@ -1589,18 +1584,18 @@ class App(QtCore.QObject):
|
|||||||
'open_gerber', 'open_project', 'options', 'paint', 'pan', 'panel', 'panelize', 'plot',
|
'open_gerber', 'open_project', 'options', 'paint', 'pan', 'panel', 'panelize', 'plot',
|
||||||
'save', 'save_project', 'save_sys', 'scale', 'set_active', 'set_sys', 'setsys',
|
'save', 'save_project', 'save_sys', 'scale', 'set_active', 'set_sys', 'setsys',
|
||||||
'skew', 'subtract_poly', 'subtract_rectangle', 'version', 'write_gcode'
|
'skew', 'subtract_poly', 'subtract_rectangle', 'version', 'write_gcode'
|
||||||
]
|
]
|
||||||
|
|
||||||
self.ordinary_keywords = ['name', 'center_x', 'center_y', 'radius', 'x0', 'y0', 'x1', 'y1', 'box', 'axis',
|
self.ordinary_keywords = ['name', 'center_x', 'center_y', 'radius', 'x0', 'y0', 'x1', 'y1', 'box', 'axis',
|
||||||
'holes','grid', 'minoffset', 'gridoffset','axisoffset', 'dia', 'dist', 'gridoffsetx',
|
'holes', 'grid', 'minoffset', 'gridoffset', 'axisoffset', 'dia', 'dist',
|
||||||
'gridoffsety', 'columns', 'rows', 'z_cut', 'z_move', 'feedrate', 'feedrate_rapid',
|
'gridoffsetx', 'gridoffsety', 'columns', 'rows', 'z_cut', 'z_move', 'feedrate',
|
||||||
'tooldia', 'multidepth', 'extracut', 'depthperpass', 'ppname_g', 'outname', 'margin',
|
'feedrate_rapid', 'tooldia', 'multidepth', 'extracut', 'depthperpass', 'ppname_g',
|
||||||
'gaps', 'gapsize', 'tools', 'drillz', 'travelz', 'spindlespeed', 'toolchange',
|
'outname', 'margin', 'gaps', 'gapsize', 'tools', 'drillz', 'travelz', 'spindlespeed',
|
||||||
'toolchangez', 'endz', 'ppname_e', 'opt_type', 'preamble', 'postamble', 'filename',
|
'toolchange', 'toolchangez', 'endz', 'ppname_e', 'opt_type', 'preamble', 'postamble',
|
||||||
'scale_factor', 'type', 'passes', 'overlap', 'combine', 'use_threads', 'x', 'y',
|
'filename', 'scale_factor', 'type', 'passes', 'overlap', 'combine', 'use_threads',
|
||||||
'follow', 'all', 'spacing_columns', 'spacing_rows', 'factor', 'value', 'angle_x',
|
'x', 'y', 'follow', 'all', 'spacing_columns', 'spacing_rows', 'factor', 'value',
|
||||||
'angle_y', 'gridx', 'gridy', 'True', 'False'
|
'angle_x', 'angle_y', 'gridx', 'gridy', 'True', 'False'
|
||||||
]
|
]
|
||||||
|
|
||||||
self.tcl_keywords = [
|
self.tcl_keywords = [
|
||||||
"after", "append", "apply", "array", "auto_execok", "auto_import", "auto_load", "auto_mkindex",
|
"after", "append", "apply", "array", "auto_execok", "auto_import", "auto_load", "auto_mkindex",
|
||||||
@@ -1813,14 +1808,31 @@ class App(QtCore.QObject):
|
|||||||
else:
|
else:
|
||||||
self.ui.shell_dock.hide()
|
self.ui.shell_dock.hide()
|
||||||
|
|
||||||
#########################
|
# ########################
|
||||||
### Tools and Plugins ###
|
# ## Tools and Plugins ###
|
||||||
#########################
|
# ########################
|
||||||
|
|
||||||
|
self.dblsidedtool = None
|
||||||
|
self.measurement_tool = None
|
||||||
|
self.panelize_tool = None
|
||||||
|
self.film_tool = None
|
||||||
|
self.paste_tool = None
|
||||||
|
self.calculator_tool = None
|
||||||
|
self.sub_tool = None
|
||||||
|
self.move_tool = None
|
||||||
|
self.cutout_tool = None
|
||||||
|
self.ncclear_tool = None
|
||||||
|
self.paint_tool = None
|
||||||
|
self.transform_tool = None
|
||||||
|
self.properties_tool = None
|
||||||
|
self.pdf_tool = None
|
||||||
|
self.image_tool = None
|
||||||
|
self.pcb_wizard_tool = None
|
||||||
|
|
||||||
# always install tools only after the shell is initialized because the self.inform.emit() depends on shell
|
# always install tools only after the shell is initialized because the self.inform.emit() depends on shell
|
||||||
self.install_tools()
|
self.install_tools()
|
||||||
|
|
||||||
### System Font Parsing ###
|
# ## System Font Parsing ###
|
||||||
# self.f_parse = ParseFont(self)
|
# self.f_parse = ParseFont(self)
|
||||||
# self.parse_system_fonts()
|
# self.parse_system_fonts()
|
||||||
|
|
||||||
@@ -1834,9 +1846,9 @@ class App(QtCore.QObject):
|
|||||||
print("ERROR: ", ext)
|
print("ERROR: ", ext)
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
||||||
###########################
|
# ##########################
|
||||||
#### Check for updates ####
|
# ### Check for updates ####
|
||||||
###########################
|
# ##########################
|
||||||
|
|
||||||
# Separate thread (Not worker)
|
# Separate thread (Not worker)
|
||||||
# Check for updates on startup but only if the user consent and the app is not in Beta version
|
# Check for updates on startup but only if the user consent and the app is not in Beta version
|
||||||
@@ -1849,10 +1861,9 @@ class App(QtCore.QObject):
|
|||||||
'params': []})
|
'params': []})
|
||||||
self.thr2.start(QtCore.QThread.LowPriority)
|
self.thr2.start(QtCore.QThread.LowPriority)
|
||||||
|
|
||||||
|
# ###################################
|
||||||
####################################
|
# ### Variables for global usage ####
|
||||||
#### Variables for global usage ####
|
# ###################################
|
||||||
####################################
|
|
||||||
|
|
||||||
# coordinates for relative position display
|
# coordinates for relative position display
|
||||||
self.rel_point1 = (0, 0)
|
self.rel_point1 = (0, 0)
|
||||||
@@ -1907,8 +1918,9 @@ class App(QtCore.QObject):
|
|||||||
]
|
]
|
||||||
self.exc_list = ['drl', 'txt', 'xln', 'drd', 'tap', 'exc', 'ncd']
|
self.exc_list = ['drl', 'txt', 'xln', 'drd', 'tap', 'exc', 'ncd']
|
||||||
self.gcode_list = ['nc', 'ncc', 'tap', 'gcode', 'cnc', 'ecs', 'fnc', 'dnc', 'ncg', 'gc', 'fan', 'fgc', 'din',
|
self.gcode_list = ['nc', 'ncc', 'tap', 'gcode', 'cnc', 'ecs', 'fnc', 'dnc', 'ncg', 'gc', 'fan', 'fgc', 'din',
|
||||||
'xpi', 'hnc', 'h', 'i', 'ncp', 'min', 'gcd', 'rol', 'mpr', 'ply', 'out', 'eia', 'plt', 'sbp',
|
'xpi', 'hnc', 'h', 'i', 'ncp', 'min', 'gcd', 'rol', 'mpr', 'ply', 'out', 'eia', 'plt', 'sbp',
|
||||||
'mpf']
|
'mpf'
|
||||||
|
]
|
||||||
self.svg_list = ['svg']
|
self.svg_list = ['svg']
|
||||||
self.dxf_list = ['dxf']
|
self.dxf_list = ['dxf']
|
||||||
self.pdf_list = ['pdf']
|
self.pdf_list = ['pdf']
|
||||||
@@ -1923,8 +1935,8 @@ class App(QtCore.QObject):
|
|||||||
self.isHovering = False
|
self.isHovering = False
|
||||||
self.notHovering = True
|
self.notHovering = True
|
||||||
|
|
||||||
### Save defaults to factory_defaults.FlatConfig file ###
|
# ## Save defaults to factory_defaults.FlatConfig file ###
|
||||||
### It's done only once after install #############
|
# ## It's done only once after install #############
|
||||||
factory_file = open(self.data_path + '/factory_defaults.FlatConfig')
|
factory_file = open(self.data_path + '/factory_defaults.FlatConfig')
|
||||||
fac_def_from_file = factory_file.read()
|
fac_def_from_file = factory_file.read()
|
||||||
factory_defaults = json.loads(fac_def_from_file)
|
factory_defaults = json.loads(fac_def_from_file)
|
||||||
@@ -2000,8 +2012,8 @@ class App(QtCore.QObject):
|
|||||||
for option in self.defaults_form_fields:
|
for option in self.defaults_form_fields:
|
||||||
try:
|
try:
|
||||||
self.defaults[option] = self.defaults_form_fields[option].get_value()
|
self.defaults[option] = self.defaults_form_fields[option].get_value()
|
||||||
except:
|
except Exception as e:
|
||||||
pass
|
log.debug("App.defaults_read_form() --> %s" % str(e))
|
||||||
|
|
||||||
def defaults_write_form(self, factor=None):
|
def defaults_write_form(self, factor=None):
|
||||||
for option in self.defaults:
|
for option in self.defaults:
|
||||||
@@ -2019,9 +2031,8 @@ class App(QtCore.QObject):
|
|||||||
self.defaults_form_fields[field].set_value(self.defaults[field])
|
self.defaults_form_fields[field].set_value(self.defaults[field])
|
||||||
else:
|
else:
|
||||||
self.defaults_form_fields[field].set_value(self.defaults[field] * factor)
|
self.defaults_form_fields[field].set_value(self.defaults[field] * factor)
|
||||||
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
#self.log.debug("defaults_write_form(): No field for: %s" % option)
|
# self.log.debug("defaults_write_form(): No field for: %s" % option)
|
||||||
# TODO: Rethink this?
|
# TODO: Rethink this?
|
||||||
pass
|
pass
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
@@ -2055,7 +2066,6 @@ class App(QtCore.QObject):
|
|||||||
self.calculator_tool = ToolCalculator(self)
|
self.calculator_tool = ToolCalculator(self)
|
||||||
self.calculator_tool.install(icon=QtGui.QIcon('share/calculator24.png'))
|
self.calculator_tool.install(icon=QtGui.QIcon('share/calculator24.png'))
|
||||||
|
|
||||||
|
|
||||||
self.sub_tool = ToolSub(self)
|
self.sub_tool = ToolSub(self)
|
||||||
self.sub_tool.install(icon=QtGui.QIcon('share/sub32.png'), pos=self.ui.menuedit_convert,
|
self.sub_tool.install(icon=QtGui.QIcon('share/sub32.png'), pos=self.ui.menuedit_convert,
|
||||||
before=self.ui.menuedit_convert_sg2mg)
|
before=self.ui.menuedit_convert_sg2mg)
|
||||||
@@ -2070,11 +2080,11 @@ class App(QtCore.QObject):
|
|||||||
|
|
||||||
self.ncclear_tool = NonCopperClear(self)
|
self.ncclear_tool = NonCopperClear(self)
|
||||||
self.ncclear_tool.install(icon=QtGui.QIcon('share/ncc16.png'), pos=self.ui.menutool,
|
self.ncclear_tool.install(icon=QtGui.QIcon('share/ncc16.png'), pos=self.ui.menutool,
|
||||||
before=self.measurement_tool.menuAction, separator=True)
|
before=self.measurement_tool.menuAction, separator=True)
|
||||||
|
|
||||||
self.paint_tool = ToolPaint(self)
|
self.paint_tool = ToolPaint(self)
|
||||||
self.paint_tool.install(icon=QtGui.QIcon('share/paint16.png'), pos=self.ui.menutool,
|
self.paint_tool.install(icon=QtGui.QIcon('share/paint16.png'), pos=self.ui.menutool,
|
||||||
before=self.measurement_tool.menuAction, separator=True)
|
before=self.measurement_tool.menuAction, separator=True)
|
||||||
|
|
||||||
self.transform_tool = ToolTransform(self)
|
self.transform_tool = ToolTransform(self)
|
||||||
self.transform_tool.install(icon=QtGui.QIcon('share/transform.png'), pos=self.ui.menuoptions, separator=True)
|
self.transform_tool.install(icon=QtGui.QIcon('share/transform.png'), pos=self.ui.menuoptions, separator=True)
|
||||||
@@ -2247,7 +2257,6 @@ class App(QtCore.QObject):
|
|||||||
# do not update a geometry or excellon object unless it comes out of an editor
|
# do not update a geometry or excellon object unless it comes out of an editor
|
||||||
if self.call_source != 'app':
|
if self.call_source != 'app':
|
||||||
edited_obj = self.collection.get_active()
|
edited_obj = self.collection.get_active()
|
||||||
obj_type = ""
|
|
||||||
|
|
||||||
if cleanup is None:
|
if cleanup is None:
|
||||||
msgbox = QtWidgets.QMessageBox()
|
msgbox = QtWidgets.QMessageBox()
|
||||||
@@ -2381,7 +2390,7 @@ class App(QtCore.QObject):
|
|||||||
self.defaults['global_stats'][resource] = 1
|
self.defaults['global_stats'][resource] = 1
|
||||||
|
|
||||||
def init_tcl(self):
|
def init_tcl(self):
|
||||||
if hasattr(self,'tcl'):
|
if hasattr(self, 'tcl'):
|
||||||
# self.tcl = None
|
# self.tcl = None
|
||||||
# TODO we need to clean non default variables and procedures here
|
# TODO we need to clean non default variables and procedures here
|
||||||
# new object cannot be used here as it will not remember values created for next passes,
|
# new object cannot be used here as it will not remember values created for next passes,
|
||||||
@@ -2395,7 +2404,7 @@ class App(QtCore.QObject):
|
|||||||
# TODO: This shouldn't be here.
|
# TODO: This shouldn't be here.
|
||||||
class TclErrorException(Exception):
|
class TclErrorException(Exception):
|
||||||
"""
|
"""
|
||||||
this exception is deffined here, to be able catch it if we sucessfully handle all errors from shell command
|
this exception is defined here, to be able catch it if we ssuccessfully handle all errors from shell command
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -2406,6 +2415,9 @@ class App(QtCore.QObject):
|
|||||||
:param msg: Message to display.
|
:param msg: Message to display.
|
||||||
:param show: Opens the shell.
|
:param show: Opens the shell.
|
||||||
:param error: Shows the message as an error.
|
:param error: Shows the message as an error.
|
||||||
|
:param warning: Shows the message as an warning.
|
||||||
|
:param warning: Shows the message as an success.
|
||||||
|
:param selected: Indicate that something was selected on canvas
|
||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
if show:
|
if show:
|
||||||
@@ -2440,14 +2452,15 @@ class App(QtCore.QObject):
|
|||||||
|
|
||||||
def display_tcl_error(self, error, error_info=None):
|
def display_tcl_error(self, error, error_info=None):
|
||||||
"""
|
"""
|
||||||
escape bracket [ with \ otherwise there is error
|
Escape bracket [ with '\' otherwise there is error
|
||||||
"ERROR: missing close-bracket" instead of real error
|
"ERROR: missing close-bracket" instead of real error
|
||||||
|
|
||||||
:param error: it may be text or exception
|
:param error: it may be text or exception
|
||||||
|
:param error_info: Some informations about the error
|
||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if isinstance(error, Exception):
|
if isinstance(error, Exception):
|
||||||
|
|
||||||
exc_type, exc_value, exc_traceback = error_info
|
exc_type, exc_value, exc_traceback = error_info
|
||||||
if not isinstance(error, self.TclErrorException):
|
if not isinstance(error, self.TclErrorException):
|
||||||
show_trace = 1
|
show_trace = 1
|
||||||
@@ -2459,22 +2472,19 @@ class App(QtCore.QObject):
|
|||||||
trc_formated = []
|
trc_formated = []
|
||||||
for a in reversed(trc):
|
for a in reversed(trc):
|
||||||
trc_formated.append(a.replace(" ", " > ").replace("\n", ""))
|
trc_formated.append(a.replace(" ", " > ").replace("\n", ""))
|
||||||
text = "%s\nPython traceback: %s\n%s" % (exc_value,
|
text = "%s\nPython traceback: %s\n%s" % (exc_value, exc_type, "\n".join(trc_formated))
|
||||||
exc_type,
|
|
||||||
"\n".join(trc_formated))
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
text = "%s" % error
|
text = "%s" % error
|
||||||
else:
|
else:
|
||||||
text = error
|
text = error
|
||||||
|
|
||||||
text = text.replace('[', '\\[').replace('"', '\\"')
|
text = text.replace('[', '\\[').replace('"', '\\"')
|
||||||
|
|
||||||
self.tcl.eval('return -code error "%s"' % text)
|
self.tcl.eval('return -code error "%s"' % text)
|
||||||
|
|
||||||
def raise_tcl_error(self, text):
|
def raise_tcl_error(self, text):
|
||||||
"""
|
"""
|
||||||
this method pass exception from python into TCL as error, so we get stacktrace and reason
|
This method pass exception from python into TCL as error, so we get stacktrace and reason
|
||||||
|
|
||||||
:param text: text of error
|
:param text: text of error
|
||||||
:return: raise exception
|
:return: raise exception
|
||||||
"""
|
"""
|
||||||
@@ -2495,8 +2505,7 @@ class App(QtCore.QObject):
|
|||||||
|
|
||||||
result = self.exec_command_test(text, False)
|
result = self.exec_command_test(text, False)
|
||||||
|
|
||||||
#MS: added this method call so the geometry is updated once the TCL
|
# MS: added this method call so the geometry is updated once the TCL command is executed
|
||||||
#command is executed
|
|
||||||
self.plot_all()
|
self.plot_all()
|
||||||
|
|
||||||
return result
|
return result
|
||||||
@@ -2579,7 +2588,7 @@ class App(QtCore.QObject):
|
|||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Type of message in brackets at the begining of the message.
|
# Type of message in brackets at the beginning of the message.
|
||||||
match = re.search("\[([^\]]+)\](.*)", msg)
|
match = re.search("\[([^\]]+)\](.*)", msg)
|
||||||
if match:
|
if match:
|
||||||
level = match.group(1)
|
level = match.group(1)
|
||||||
@@ -2708,9 +2717,11 @@ class App(QtCore.QObject):
|
|||||||
filter = "Config File (*.FlatConfig);;All Files (*.*)"
|
filter = "Config File (*.FlatConfig);;All Files (*.*)"
|
||||||
try:
|
try:
|
||||||
filename, _f = QtWidgets.QFileDialog.getOpenFileName(caption=_("Import FlatCAM Preferences"),
|
filename, _f = QtWidgets.QFileDialog.getOpenFileName(caption=_("Import FlatCAM Preferences"),
|
||||||
directory=self.data_path, filter=filter)
|
directory=self.data_path,
|
||||||
|
filter=filter)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
filename, _f = QtWidgets.QFileDialog.getOpenFileName(caption=_("Import FlatCAM Preferences"), filter=filter)
|
filename, _f = QtWidgets.QFileDialog.getOpenFileName(caption=_("Import FlatCAM Preferences"),
|
||||||
|
filter=filter)
|
||||||
|
|
||||||
filename = str(filename)
|
filename = str(filename)
|
||||||
|
|
||||||
@@ -2741,14 +2752,18 @@ class App(QtCore.QObject):
|
|||||||
self.report_usage("on_export_preferences")
|
self.report_usage("on_export_preferences")
|
||||||
App.log.debug("on_export_preferences()")
|
App.log.debug("on_export_preferences()")
|
||||||
|
|
||||||
|
defaults_file_content = None
|
||||||
|
|
||||||
filter = "Config File (*.FlatConfig);;All Files (*.*)"
|
filter = "Config File (*.FlatConfig);;All Files (*.*)"
|
||||||
try:
|
try:
|
||||||
filename, _f = QtWidgets.QFileDialog.getSaveFileName(
|
filename, _f = QtWidgets.QFileDialog.getSaveFileName(
|
||||||
caption=_("Export FlatCAM Preferences"),
|
caption=_("Export FlatCAM Preferences"),
|
||||||
directory=self.data_path + '/preferences_' + self.date, filter=filter
|
directory=self.data_path + '/preferences_' + self.date,
|
||||||
|
filter=filter
|
||||||
)
|
)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
filename, _f = QtWidgets.QFileDialog.getSaveFileName(caption=_("Export FlatCAM Preferences"), filter=filter)
|
filename, _f = QtWidgets.QFileDialog.getSaveFileName(caption=_("Export FlatCAM Preferences"),
|
||||||
|
filter=filter)
|
||||||
|
|
||||||
filename = str(filename)
|
filename = str(filename)
|
||||||
defaults_from_file = {}
|
defaults_from_file = {}
|
||||||
@@ -2845,16 +2860,10 @@ class App(QtCore.QObject):
|
|||||||
self.inform.emit(_('[ERROR_NOTCL] Failed to open recent files file for writing.'))
|
self.inform.emit(_('[ERROR_NOTCL] Failed to open recent files file for writing.'))
|
||||||
return
|
return
|
||||||
|
|
||||||
#try:
|
|
||||||
json.dump(self.recent, f, default=to_dict, indent=2, sort_keys=True)
|
json.dump(self.recent, f, default=to_dict, indent=2, sort_keys=True)
|
||||||
# except:
|
|
||||||
# App.log.error("Failed to write to recent items file.")
|
|
||||||
# self.inform.emit('ERROR: Failed to write to recent items file.')
|
|
||||||
# f.close()
|
|
||||||
|
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
# Re-buid the recent items menu
|
# Re-build the recent items menu
|
||||||
self.setup_recent_items()
|
self.setup_recent_items()
|
||||||
|
|
||||||
def new_object(self, kind, name, initialize, active=True, fit=True, plot=True, autoselected=True):
|
def new_object(self, kind, name, initialize, active=True, fit=True, plot=True, autoselected=True):
|
||||||
@@ -2868,14 +2877,12 @@ class App(QtCore.QObject):
|
|||||||
when appending it to the collection. There is no need to handle
|
when appending it to the collection. There is no need to handle
|
||||||
name conflicts here.
|
name conflicts here.
|
||||||
|
|
||||||
:param kind: The kind of object to create. One of 'gerber',
|
:param kind: The kind of object to create. One of 'gerber', 'excellon', 'cncjob' and 'geometry'.
|
||||||
'excellon', 'cncjob' and 'geometry'.
|
|
||||||
:type kind: str
|
:type kind: str
|
||||||
:param name: Name for the object.
|
:param name: Name for the object.
|
||||||
:type name: str
|
:type name: str
|
||||||
:param initialize: Function to run after creation of the object
|
:param initialize: Function to run after creation of the object but before it is attached to the application.
|
||||||
but before it is attached to the application. The function is
|
The function is called with 2 parameters: the new object and the App instance.
|
||||||
called with 2 parameters: the new object and the App instance.
|
|
||||||
:type initialize: function
|
:type initialize: function
|
||||||
:return: None
|
:return: None
|
||||||
:rtype: None
|
:rtype: None
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ CAD program, and create G-Code for Isolation routing.
|
|||||||
|
|
||||||
- fixed bug in Gerber editor FCDisk and FCSemiDisc that the resulting geometry was not stored into the '0' aperture where all the solids are stored
|
- fixed bug in Gerber editor FCDisk and FCSemiDisc that the resulting geometry was not stored into the '0' aperture where all the solids are stored
|
||||||
- fixed minor issue in Gerber Editor where apertures were included in the saved object even if there was no geometric data for that aperture
|
- fixed minor issue in Gerber Editor where apertures were included in the saved object even if there was no geometric data for that aperture
|
||||||
|
- some PEP8 cleanup in FlatCAMApp.py
|
||||||
|
|
||||||
22.05.2019
|
22.05.2019
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user