Commit a8a64d89 authored by Maxime Perrotin's avatar Maxime Perrotin

Make data dictionary follow cursor

When user moves cursor on a new word, and this work is a variable,
select it in the data dictionary, to allow easy retrieval of the
corresponding type
parent aa81a087
......@@ -7,7 +7,7 @@
- Syntax highlighing
- Automatic placement
Copyright (c) 2012-2014 European Space Agency
Copyright (c) 2012-2019 European Space Agency
Designed and implemented by Maxime Perrotin for the TASTE project
......@@ -17,7 +17,7 @@
import string
import logging
from PySide.QtCore import Qt, QRegExp, Slot
from PySide.QtCore import Qt, QRegExp, Slot, Signal
from PySide.QtGui import(QGraphicsTextItem, QGraphicsProxyWidget, QListWidget,
QStringListModel, QCompleter, QListWidgetItem, QFont,
......@@ -139,6 +139,7 @@ class EditableText(QGraphicsTextItem, object):
'''
default_cursor = Qt.IBeamCursor
hasParent = False
word_under_cursor = Signal(str)
def __init__(self, parent, text='...', hyperlink=None):
super(EditableText, self).__init__(parent)
......@@ -162,6 +163,7 @@ class EditableText(QGraphicsTextItem, object):
self.highlighter = Highlighter(
self.document(), parent.blackbold, parent.redbold)
self.completion_prefix = ''
self.old_word = '' # needed to detect change of word under cursor
#self.set_textbox_position()
self.set_text_alignment()
# Increase the Z value of the text area so that the autocompleter
......@@ -294,6 +296,11 @@ class EditableText(QGraphicsTextItem, object):
text_cursor.select(QTextCursor.WordUnderCursor)
self.completion_prefix = text_cursor.selectedText()
# "self.completion_prefix" is the complete word under the cursor
if self.completion_prefix != self.old_word:
self.word_under_cursor.emit(self.completion_prefix)
self.old_word = self.completion_prefix
self.context_completion_list(force=(event.key()==Qt.Key_F8))
completion_count = self.completer.set_completion_prefix(
......
......@@ -41,7 +41,7 @@
For a complete example, look at the "sdlSymbols.py" module, that
provide symbol definitions that correspond to an SDL editor.
Copyright (c) 2012-2013 European Space Agency
Copyright (c) 2012-2019 European Space Agency
Designed and implemented by Maxime Perrotin for the TASTE project
......@@ -82,6 +82,7 @@ class Symbol(QObject, QGraphicsPathItem, object):
# Emit a signal when the symbol moved - can be caught by connectors to
# adjust connection points if the symbol is not the connection parent
moved = Signal(float, float)
# when editing text, signal is emitted when the word under cursor changes
# Symbols of a given type share a text-autocompletion list:
completion_list = set()
# Flexible lists of symbol types that can be set as child of this symbol
......
......@@ -376,6 +376,7 @@ class SDL_Scene(QtGui.QGraphicsScene, object):
# Signal to be emitted when the scene is left (e.g. UP button)
scene_left = QtCore.Signal()
context_change = QtCore.Signal()
word_under_cursor = QtCore.Signal(str)
def __init__(self, context='process', readonly=False):
''' Create a Scene for a given context:
......@@ -724,6 +725,8 @@ class SDL_Scene(QtGui.QGraphicsScene, object):
#symbol.set_textbox_position()
symbol.try_resize()
symbol.set_text_alignment()
# connect the signal that is emitted when text edit changes word
symbol.word_under_cursor.connect(self.word_under_cursor.emit)
for symbol in self.visible_symb:
symbol.update_connections()
......@@ -1211,6 +1214,7 @@ class SDL_Scene(QtGui.QGraphicsScene, object):
subscene.messages_window = self.messages_window
subscene.parent_scene = parent
subscene.context_change.connect(self.context_change.emit)
subscene.word_under_cursor.connect(self.word_under_cursor.emit)
return subscene
......@@ -2487,6 +2491,7 @@ class OG_MainWindow(QtGui.QMainWindow, object):
scene.undo_stack.indexChanged.connect(lambda idx :
self.view.change_cleanliness(idx))
scene.context_change.connect(self.update_datadict_window)
scene.word_under_cursor.connect(self.select_in_datadict_window)
def start(self, options):
''' Initializes all objects to start the application '''
......@@ -2732,6 +2737,20 @@ class OG_MainWindow(QtGui.QMainWindow, object):
item_constants.setExpanded(True)
self.datadict.resizeColumnToContents(0)
def select_in_datadict_window(self, str):
''' This function is called upon reception of a signal emitted by
text boxes when the current word under the cursor has changed. This
function then looks in the data dictionary and if the text is found,
the relevant row is selected. This allows user to easily retrieve
the type of a variable for instance '''
(in_sig, out_sig, states, labels,
dcl, timers) = [self.datadict.topLevelItem(i) for i in range(2, 8)]
for idx in xrange(dcl.childCount()):
child = dcl.child(idx)
if child.text(0).lower() == str.lower():
child.treeWidget().setCurrentItem(child)
child.treeWidget().scrollToItem(child)
def update_datadict_window(self):
''' Update the tree in the data dictionary based on the AST '''
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment