- refactored some of the code in the App class and created a new Tcl Command named Help

This commit is contained in:
Marius Stanciu
2020-04-22 23:00:54 +03:00
committed by Marius
parent 66d9ddd402
commit a1499158c2
10 changed files with 551 additions and 459 deletions

View File

@@ -159,7 +159,7 @@ class DblSidedTool(FlatCAMTool):
self.param_label = QtWidgets.QLabel("<b>%s:</b>" % _("Mirror Parameters"))
self.param_label.setToolTip('%s.' % _("Parameters for the mirror operation"))
grid_lay1.addWidget(self.param_label, 0, 0, 1, 3)
grid_lay1.addWidget(self.param_label, 0, 0, 1, 2)
# ## Axis
self.mirax_label = QtWidgets.QLabel('%s:' % _("Mirror Axis"))

View File

@@ -14,6 +14,8 @@ from flatcamGUI.GUIElements import _BrowserTextEdit, _ExpandableTextEdit
import html
import sys
import tkinter as tk
import gettext
import FlatCAMTranslation as fcTranslate
import builtins
@@ -227,6 +229,12 @@ class TermWidget(QWidget):
class FCShell(TermWidget):
def __init__(self, sysShell, version, *args):
"""
:param sysShell: When instantiated the sysShell will be actually the FlatCAMApp.App() class
:param version: FlatCAM version string
:param args: Parameters passed to the TermWidget parent class
"""
TermWidget.__init__(self, version, *args)
self._sysShell = sysShell
@@ -246,4 +254,94 @@ class FCShell(TermWidget):
return True
def child_exec_command(self, text):
self._sysShell.exec_command(text)
self.exec_command(text)
def exec_command(self, text, no_echo=False):
"""
Handles input from the shell. See FlatCAMApp.setup_shell for shell commands.
Also handles execution in separated threads
:param text: FlatCAM TclCommand with parameters
:param no_echo: If True it will not try to print to the Shell because most likely the shell is hidden and it
will create crashes of the _Expandable_Edit widget
:return: output if there was any
"""
self._sysShell.report_usage('exec_command')
return self.exec_command_test(text, False, no_echo=no_echo)
def exec_command_test(self, text, reraise=True, no_echo=False):
"""
Same as exec_command(...) with additional control over exceptions.
Handles input from the shell. See FlatCAMApp.setup_shell for shell commands.
:param text: Input command
:param reraise: Re-raise TclError exceptions in Python (mostly for unittests).
:param no_echo: If True it will not try to print to the Shell because most likely the shell is hidden and it
will create crashes of the _Expandable_Edit widget
:return: Output from the command
"""
tcl_command_string = str(text)
try:
if no_echo is False:
self.open_processing() # Disables input box.
result = self._sysShell.tcl.eval(str(tcl_command_string))
if result != 'None' and no_echo is False:
self.append_output(result + '\n')
except tk.TclError as e:
# This will display more precise answer if something in TCL shell fails
result = self._sysShell.tcl.eval("set errorInfo")
self._sysShell.log.error("Exec command Exception: %s" % (result + '\n'))
if no_echo is False:
self.append_error('ERROR: ' + result + '\n')
# Show error in console and just return or in test raise exception
if reraise:
raise e
finally:
if no_echo is False:
self.close_processing()
pass
return result
# """
# Code below is unsused. Saved for later.
# """
# parts = re.findall(r'([\w\\:\.]+|".*?")+', text)
# parts = [p.replace('\n', '').replace('"', '') for p in parts]
# self.log.debug(parts)
# try:
# if parts[0] not in commands:
# self.shell.append_error("Unknown command\n")
# return
#
# #import inspect
# #inspect.getargspec(someMethod)
# if (type(commands[parts[0]]["params"]) is not list and len(parts)-1 != commands[parts[0]]["params"]) or \
# (type(commands[parts[0]]["params"]) is list and len(parts)-1 not in commands[parts[0]]["params"]):
# self.shell.append_error(
# "Command %s takes %d arguments. %d given.\n" %
# (parts[0], commands[parts[0]]["params"], len(parts)-1)
# )
# return
#
# cmdfcn = commands[parts[0]]["fcn"]
# cmdconv = commands[parts[0]]["converters"]
# if len(parts) - 1 > 0:
# retval = cmdfcn(*[cmdconv[i](parts[i + 1]) for i in range(len(parts)-1)])
# else:
# retval = cmdfcn()
# retfcn = commands[parts[0]]["retfcn"]
# if retval and retfcn(retval):
# self.shell.append_output(retfcn(retval) + "\n")
#
# except Exception as e:
# #self.shell.append_error(''.join(traceback.format_exc()))
# #self.shell.append_error("?\n")
# self.shell.append_error(str(e) + "\n")

View File

@@ -33,8 +33,6 @@ class ToolTransform(FlatCAMTool):
FlatCAMTool.__init__(self, app)
self.decimals = self.app.decimals
self.transform_lay = QtWidgets.QVBoxLayout()
self.layout.addLayout(self.transform_lay)
# ## Title
title_label = QtWidgets.QLabel("%s" % self.toolName)
title_label.setStyleSheet("""
@@ -44,12 +42,12 @@ class ToolTransform(FlatCAMTool):
font-weight: bold;
}
""")
self.transform_lay.addWidget(title_label)
self.transform_lay.addWidget(QtWidgets.QLabel(''))
self.layout.addWidget(title_label)
self.layout.addWidget(QtWidgets.QLabel(''))
# ## Layout
grid0 = QtWidgets.QGridLayout()
self.transform_lay.addLayout(grid0)
self.layout.addLayout(grid0)
grid0.setColumnStretch(0, 0)
grid0.setColumnStretch(1, 1)
grid0.setColumnStretch(2, 0)
@@ -206,7 +204,7 @@ class ToolTransform(FlatCAMTool):
self.ois_scale = OptionalInputSection(self.scale_link_cb, [self.scaley_entry, self.scaley_button], logic=False)
grid0.addWidget(self.scale_link_cb, 10, 0)
grid0.addWidget(self.scale_zero_ref_cb, 10, 1)
grid0.addWidget(self.scale_zero_ref_cb, 10, 1, 1, 2)
separator_line = QtWidgets.QFrame()
separator_line.setFrameShape(QtWidgets.QFrame.HLine)
@@ -395,7 +393,7 @@ class ToolTransform(FlatCAMTool):
grid0.addWidget(QtWidgets.QLabel(''), 26, 0, 1, 3)
self.transform_lay.addStretch()
self.layout.addStretch()
# ## Reset Tool
self.reset_button = QtWidgets.QPushButton(_("Reset Tool"))
@@ -408,7 +406,7 @@ class ToolTransform(FlatCAMTool):
font-weight: bold;
}
""")
self.transform_lay.addWidget(self.reset_button)
self.layout.addWidget(self.reset_button)
# ## Signals
self.rotate_button.clicked.connect(self.on_rotate)