- 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:
Marius Stanciu 2019-03-19 03:05:00 +02:00
parent e57b913b7f
commit bebb827bd2
5 changed files with 52 additions and 0 deletions

View File

@ -1502,6 +1502,7 @@ class App(QtCore.QObject):
self.shell = FCShell(self, version=self.version)
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.setWindowTitle("FlatCAM Shell")
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
self.myKeywords.append(obj.options['name'])
self.shell._edit.set_model_data(self.myKeywords)
self.ui.code_editor.set_model_data(self.myKeywords)
if autoselect:
# select the just opened object but deselect the previous ones

View File

@ -186,6 +186,7 @@ class FlatCAMObj(QtCore.QObject):
self.app.myKeywords.remove(old_name)
self.app.myKeywords.append(new_name)
self.app.shell._edit.set_model_data(self.app.myKeywords)
self.app.ui.code_editor.set_model_data(self.app.myKeywords)
except:
log.debug("on_name_activate() --> Could not remove the old object name from auto-completer model list")

View File

@ -394,6 +394,7 @@ class ObjectCollection(QtCore.QAbstractItemModel):
self.app.myKeywords.remove(old_name)
self.app.myKeywords.append(new_name)
self.app.shell._edit.set_model_data(self.app.myKeywords)
self.app.ui.code_editor.set_model_data(self.app.myKeywords)
except:
log.debug(
"setData() --> Could not remove the old object name from auto-completer model list")
@ -550,6 +551,7 @@ class ObjectCollection(QtCore.QAbstractItemModel):
try:
self.app.myKeywords.remove(name)
self.app.shell._edit.set_model_data(self.app.myKeywords)
self.app.ui.code_editor.set_model_data(self.app.myKeywords)
except:
log.debug(
"delete_active() --> Could not remove the old object name from auto-completer model list")

View File

@ -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
- added ability to create new scripts and open scripts in FlatCAM Script Editor

View File

@ -494,6 +494,29 @@ class FCTextAreaExtended(QtWidgets.QTextEdit):
def __init__(self, parent=None):
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):
self.setText(val)
@ -531,7 +554,26 @@ class FCTextAreaExtended(QtWidgets.QTextEdit):
clip_text = clip_text.replace('\\', '/')
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)
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):
@ -1280,6 +1322,7 @@ class FCTable(QtWidgets.QTableWidget):
self.addAction(action)
action.triggered.connect(call_function)
class FCSpinner(QtWidgets.QSpinBox):
def __init__(self, parent=None):
super(FCSpinner, self).__init__(parent)