Skip to content

Commit

Permalink
gui/fup: Add operand autocompletion
Browse files Browse the repository at this point in the history
Issue mbuesch#23

Signed-off-by: Michael Buesch <[email protected]>
  • Loading branch information
mbuesch committed Feb 29, 2020
1 parent 4733a72 commit 4412243
Show file tree
Hide file tree
Showing 4 changed files with 325 additions and 48 deletions.
1 change: 0 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
* Add feature: Exchange elements
* Add feature: Live view of signal states (online diagnosis)
* Add feature: find/replace for FUP editor
* Add feature: Auto completion for operands (Issue #23)

## FBD / FUP compiler

Expand Down
27 changes: 10 additions & 17 deletions awlsim/gui/fup/fup_elemoperand.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# AWL simulator - FUP - Operand element classes
#
# Copyright 2016-2018 Michael Buesch <[email protected]>
# Copyright 2016-2020 Michael Buesch <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand All @@ -27,6 +27,7 @@

from awlsim.gui.fup.fup_base import *
from awlsim.gui.fup.fup_elem import *
from awlsim.gui.opereditwidget import *


class FupElem_OPERAND_factory(FupElem_factory):
Expand Down Expand Up @@ -219,22 +220,14 @@ def draw(self, painter):

# Overridden method. For documentation see base class.
def edit(self, parentWidget):
text, ok = QInputDialog.getText(parentWidget,
"Change operand",
"Change operand",
QLineEdit.Normal,
self.contentText)
if ok:
# Try to find the field in the interface and use the
# actual interface field name. But only do this, if
# the name does not start with a space. This way the user
# can disable this automatic matching.
if not text.startswith(" "):
field = self.grid.interfDef.findByName(text)
if field:
# Found it. Use the actual name.
text = "#" + field.name
self.contentText = text
if not self.grid:
return False
dlg = OperEditDialog(parent=parentWidget,
interfDef=self.grid.interfDef,
symTabSources=self.grid.symTabSources,
text=self.contentText)
if dlg.exec_() == dlg.Accepted:
self.contentText = dlg.getText()
return True
return False

Expand Down
68 changes: 38 additions & 30 deletions awlsim/gui/fup/fupdrawwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -1015,36 +1015,44 @@ def wheelEvent(self, ev):
QWidget.wheelEvent(self, ev)

def keyPressEvent(self, event):
if event.matches(QKeySequence.Delete):
self.removeElems()
event.accept()
return
elif (event.matches(QKeySequence.Cancel) or
event.matches(QKeySequence.Deselect)):
self.__grid.deselectAllElems()
self.__selectionChanged()
self.repaint()
event.accept()
return
elif event.matches(QKeySequence.SelectAll):
for elem in self.__grid.elems:
self.__grid.selectElem(elem)
self.__selectionChanged()
self.repaint()
event.accept()
return
elif event.matches(QKeySequence.Copy):
self.clipboardCopy()
event.accept()
return
elif event.matches(QKeySequence.Cut):
self.clipboardCut()
event.accept()
return
elif event.matches(QKeySequence.Paste):
self.clipboardPaste()
event.accept()
return
grid = self.__grid
if grid:
if event.matches(QKeySequence.Delete):
self.removeElems()
event.accept()
return
elif (event.matches(QKeySequence.Cancel) or
event.matches(QKeySequence.Deselect)):
self.__grid.deselectAllElems()
self.__selectionChanged()
self.repaint()
event.accept()
return
elif event.matches(QKeySequence.SelectAll):
for elem in self.__grid.elems:
self.__grid.selectElem(elem)
self.__selectionChanged()
self.repaint()
event.accept()
return
elif event.matches(QKeySequence.Copy):
self.clipboardCopy()
event.accept()
return
elif event.matches(QKeySequence.Cut):
self.clipboardCut()
event.accept()
return
elif event.matches(QKeySequence.Paste):
self.clipboardPaste()
event.accept()
return

if event.key() in (Qt.Key_Enter, Qt.Key_Return):
if len(grid.selectedElems) == 1:
self.editElems()
event.accept()
return

QWidget.keyPressEvent(self, event)

Expand Down
Loading

0 comments on commit 4412243

Please sign in to comment.