- added autocomplete for Code editor; TODO: needs to be enabled only when doing Scripts, right now is available for everyone.
This commit is contained in:
parent
e57b913b7f
commit
bebb827bd2
|
@ -1502,6 +1502,7 @@ class App(QtCore.QObject):
|
||||||
|
|
||||||
self.shell = FCShell(self, version=self.version)
|
self.shell = FCShell(self, version=self.version)
|
||||||
self.shell._edit.set_model_data(self.myKeywords)
|
self.shell._edit.set_model_data(self.myKeywords)
|
||||||
|
self.ui.code_editor.set_model_data(self.myKeywords)
|
||||||
self.shell.setWindowIcon(self.ui.app_icon)
|
self.shell.setWindowIcon(self.ui.app_icon)
|
||||||
self.shell.setWindowTitle("FlatCAM Shell")
|
self.shell.setWindowTitle("FlatCAM Shell")
|
||||||
self.shell.resize(*self.defaults["global_shell_shape"])
|
self.shell.resize(*self.defaults["global_shell_shape"])
|
||||||
|
@ -2645,6 +2646,7 @@ class App(QtCore.QObject):
|
||||||
# update the SHELL auto-completer model with the name of the new object
|
# update the SHELL auto-completer model with the name of the new object
|
||||||
self.myKeywords.append(obj.options['name'])
|
self.myKeywords.append(obj.options['name'])
|
||||||
self.shell._edit.set_model_data(self.myKeywords)
|
self.shell._edit.set_model_data(self.myKeywords)
|
||||||
|
self.ui.code_editor.set_model_data(self.myKeywords)
|
||||||
|
|
||||||
if autoselect:
|
if autoselect:
|
||||||
# select the just opened object but deselect the previous ones
|
# select the just opened object but deselect the previous ones
|
||||||
|
|
|
@ -186,6 +186,7 @@ class FlatCAMObj(QtCore.QObject):
|
||||||
self.app.myKeywords.remove(old_name)
|
self.app.myKeywords.remove(old_name)
|
||||||
self.app.myKeywords.append(new_name)
|
self.app.myKeywords.append(new_name)
|
||||||
self.app.shell._edit.set_model_data(self.app.myKeywords)
|
self.app.shell._edit.set_model_data(self.app.myKeywords)
|
||||||
|
self.app.ui.code_editor.set_model_data(self.app.myKeywords)
|
||||||
except:
|
except:
|
||||||
log.debug("on_name_activate() --> Could not remove the old object name from auto-completer model list")
|
log.debug("on_name_activate() --> Could not remove the old object name from auto-completer model list")
|
||||||
|
|
||||||
|
|
|
@ -394,6 +394,7 @@ class ObjectCollection(QtCore.QAbstractItemModel):
|
||||||
self.app.myKeywords.remove(old_name)
|
self.app.myKeywords.remove(old_name)
|
||||||
self.app.myKeywords.append(new_name)
|
self.app.myKeywords.append(new_name)
|
||||||
self.app.shell._edit.set_model_data(self.app.myKeywords)
|
self.app.shell._edit.set_model_data(self.app.myKeywords)
|
||||||
|
self.app.ui.code_editor.set_model_data(self.app.myKeywords)
|
||||||
except:
|
except:
|
||||||
log.debug(
|
log.debug(
|
||||||
"setData() --> Could not remove the old object name from auto-completer model list")
|
"setData() --> Could not remove the old object name from auto-completer model list")
|
||||||
|
@ -550,6 +551,7 @@ class ObjectCollection(QtCore.QAbstractItemModel):
|
||||||
try:
|
try:
|
||||||
self.app.myKeywords.remove(name)
|
self.app.myKeywords.remove(name)
|
||||||
self.app.shell._edit.set_model_data(self.app.myKeywords)
|
self.app.shell._edit.set_model_data(self.app.myKeywords)
|
||||||
|
self.app.ui.code_editor.set_model_data(self.app.myKeywords)
|
||||||
except:
|
except:
|
||||||
log.debug(
|
log.debug(
|
||||||
"delete_active() --> Could not remove the old object name from auto-completer model list")
|
"delete_active() --> Could not remove the old object name from auto-completer model list")
|
||||||
|
|
|
@ -9,6 +9,10 @@ CAD program, and create G-Code for Isolation routing.
|
||||||
|
|
||||||
=================================================
|
=================================================
|
||||||
|
|
||||||
|
19.03.2019
|
||||||
|
|
||||||
|
- added autocomplete for Code editor; TODO: needs to be enabled only when doing Scripts, right now is available for everyone.
|
||||||
|
|
||||||
18.03.2019
|
18.03.2019
|
||||||
|
|
||||||
- added ability to create new scripts and open scripts in FlatCAM Script Editor
|
- added ability to create new scripts and open scripts in FlatCAM Script Editor
|
||||||
|
|
|
@ -494,6 +494,29 @@ class FCTextAreaExtended(QtWidgets.QTextEdit):
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
super(FCTextAreaExtended, self).__init__(parent)
|
super(FCTextAreaExtended, self).__init__(parent)
|
||||||
|
|
||||||
|
self.completer = MyCompleter()
|
||||||
|
|
||||||
|
self.model = QtCore.QStringListModel()
|
||||||
|
self.completer.setModel(self.model)
|
||||||
|
self.set_model_data(keyword_list=[])
|
||||||
|
self.completer.insertText.connect(self.insertCompletion)
|
||||||
|
|
||||||
|
def set_model_data(self, keyword_list):
|
||||||
|
self.model.setStringList(keyword_list)
|
||||||
|
|
||||||
|
def insertCompletion(self, completion):
|
||||||
|
tc = self.textCursor()
|
||||||
|
extra = (len(completion) - len(self.completer.completionPrefix()))
|
||||||
|
tc.movePosition(QTextCursor.Left)
|
||||||
|
tc.movePosition(QTextCursor.EndOfWord)
|
||||||
|
tc.insertText(completion[-extra:])
|
||||||
|
self.setTextCursor(tc)
|
||||||
|
self.completer.popup().hide()
|
||||||
|
|
||||||
|
def focusInEvent(self, event):
|
||||||
|
if self.completer:
|
||||||
|
self.completer.setWidget(self)
|
||||||
|
QTextEdit.focusInEvent(self, event)
|
||||||
def set_value(self, val):
|
def set_value(self, val):
|
||||||
self.setText(val)
|
self.setText(val)
|
||||||
|
|
||||||
|
@ -531,7 +554,26 @@ class FCTextAreaExtended(QtWidgets.QTextEdit):
|
||||||
clip_text = clip_text.replace('\\', '/')
|
clip_text = clip_text.replace('\\', '/')
|
||||||
self.insertPlainText(clip_text)
|
self.insertPlainText(clip_text)
|
||||||
|
|
||||||
|
tc = self.textCursor()
|
||||||
|
if event.key() == Qt.Key_Tab and self.completer.popup().isVisible():
|
||||||
|
self.completer.insertText.emit(self.completer.getSelected())
|
||||||
|
self.completer.setCompletionMode(QCompleter.PopupCompletion)
|
||||||
|
return
|
||||||
|
|
||||||
super(FCTextAreaExtended, self).keyPressEvent(event)
|
super(FCTextAreaExtended, self).keyPressEvent(event)
|
||||||
|
tc.select(QTextCursor.WordUnderCursor)
|
||||||
|
cr = self.cursorRect()
|
||||||
|
|
||||||
|
if len(tc.selectedText()) > 0:
|
||||||
|
self.completer.setCompletionPrefix(tc.selectedText())
|
||||||
|
popup = self.completer.popup()
|
||||||
|
popup.setCurrentIndex(self.completer.completionModel().index(0, 0))
|
||||||
|
|
||||||
|
cr.setWidth(self.completer.popup().sizeHintForColumn(0)
|
||||||
|
+ self.completer.popup().verticalScrollBar().sizeHint().width())
|
||||||
|
self.completer.complete(cr)
|
||||||
|
else:
|
||||||
|
self.completer.popup().hide()
|
||||||
|
|
||||||
|
|
||||||
class FCComboBox(QtWidgets.QComboBox):
|
class FCComboBox(QtWidgets.QComboBox):
|
||||||
|
@ -1280,6 +1322,7 @@ class FCTable(QtWidgets.QTableWidget):
|
||||||
self.addAction(action)
|
self.addAction(action)
|
||||||
action.triggered.connect(call_function)
|
action.triggered.connect(call_function)
|
||||||
|
|
||||||
|
|
||||||
class FCSpinner(QtWidgets.QSpinBox):
|
class FCSpinner(QtWidgets.QSpinBox):
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
super(FCSpinner, self).__init__(parent)
|
super(FCSpinner, self).__init__(parent)
|
||||||
|
|
Loading…
Reference in New Issue