Commit 92aa8929 authored by Michael Büsch's avatar Michael Büsch

gui: Add symbol handling to library

Signed-off-by: Michael Büsch's avatarMichael Buesch <m@bues.ch>
parent c850fe73
......@@ -33,6 +33,9 @@ from awlsim.library import *
class GenericActionWidget(QWidget):
# Signal: Code paste request.
paste = Signal(str)
# Signal: Add a symbol to the symbol table
# Arguments: symbolName, address, dataType, comment
addSymbol = Signal(str, str, str, str)
# Signal: Finish the library selection
finish = Signal()
......@@ -136,11 +139,14 @@ class SysActionWidget(GenericActionWidget):
self.finish.emit()
def __pasteCallSym(self):
#TODO add the symbol to the symbol table
blockNumber, symbolName, blockDesc = self.systemBlockCls.name
self._pasteCallGeneric('"%s"' % symbolName,
self.systemBlockCls.isFB,
self.systemBlockCls.interfaceFields)
self.addSymbol.emit(symbolName,
"%s %s" % (self.blockPrefix, blockNumber),
"%s %s" % (self.blockPrefix, blockNumber),
blockDesc)
self.finish.emit()
def defaultPaste(self):
......@@ -207,6 +213,10 @@ class LibActionWidget(GenericActionWidget):
def __pasteCodeSym(self):
self.paste.emit(self.libEntryCls().getCode(True))
self.addSymbol.emit(self.libEntryCls.symbolName,
self.blockName,
self.blockName,
self.libEntryCls.description)
self.finish.emit()
def __pasteCall(self):
......@@ -216,10 +226,13 @@ class LibActionWidget(GenericActionWidget):
self.finish.emit()
def __pasteCallSym(self):
#TODO add the symbol to the symbol table
self._pasteCallGeneric('"%s"' % self.libEntryCls.symbolName,
self.libEntryCls.isFB,
self.libEntryCls.interfaceFields)
self.addSymbol.emit(self.libEntryCls.symbolName,
self.blockName,
self.blockName,
self.libEntryCls.description)
self.finish.emit()
def defaultPaste(self):
......@@ -232,14 +245,17 @@ class LibraryDialog(QDialog):
BLOCK_OFFSET = QListWidgetItem.UserType + 0xFFFF
def __init__(self, withExtensions, parent=None):
def __init__(self, project, parent=None):
QDialog.__init__(self, parent)
self.setLayout(QGridLayout())
self.setWindowTitle("AWL/STL - Standard library")
self.setWindowIcon(getIcon("stdlib"))
self.withExtensions = withExtensions
self.project = project
self.pasteText = None
self.pasteSymbol = None
self.currentActionWidget = None
self.__nr2lib = {}
self.__nr2entry = {}
......@@ -281,8 +297,10 @@ class LibraryDialog(QDialog):
self.libElemList.currentItemChanged.connect(self.__libElemItemChanged)
self.libElemList.itemDoubleClicked.connect(self.__libElemDoubleClicked)
self.sysAction.paste.connect(self.__actionPaste)
self.sysAction.addSymbol.connect(self.__actionAddSym)
self.sysAction.finish.connect(self.accept)
self.libAction.paste.connect(self.__actionPaste)
self.libAction.addSymbol.connect(self.__actionAddSym)
self.libAction.finish.connect(self.accept)
self.libList.setCurrentRow(0)
......@@ -316,7 +334,7 @@ class LibraryDialog(QDialog):
if blockCls.broken:
continue
number, name, desc = blockCls.name
if number < 0 and not self.withExtensions:
if number < 0 and not self.project.getExtInsnsEn():
continue
absName = "%s %d" % (prefix, number)
......@@ -390,4 +408,9 @@ class LibraryDialog(QDialog):
self.currentActionWidget.defaultPaste()
def __actionPaste(self, text):
assert(self.pasteText is None)
self.pasteText = text
def __actionAddSym(self, symbolName, address, dataType, comment):
assert(self.pasteSymbol is None)
self.pasteSymbol = (symbolName, address, dataType, comment)
......@@ -219,13 +219,63 @@ class ProjectWidget(QTabWidget):
def __pasteAwlText(self, text):
if self.currentWidget() == self.awlTabs:
self.awlTabs.pasteText(text)
return True
QMessageBox.information(self,
"Please select AWL/STL source",
"Can not paste template.\n\n"
"Please move the text cursor to the place "
"in the AWL/STL code where you want to paste "
"the template to.")
return False
def __addSymbolToTabWidget(self, tabWidget, symbol):
tabWidget.model().beginResetModel()
tabWidget.getSymTab().add(symbol)
tabWidget.model().revert()
tabWidget.model().endResetModel()
def __pasteSymbol(self, symbolName, address, dataType, comment):
# Check if we already have this symbol.
for tabWidget in self.symTabs.allTabWidgets():
symTable = tabWidget.getSymTab()
symbols = tuple(symTable.findByName(symbolName))
if symbols:
# We already have it.
return True
# We don't have this symbol, yet. Parse it.
try:
p = SymTabParser(self.__project.getCpuSpecs().getConfiguredMnemonics())
symbol = p.parseSym(symbolName, address,
dataType, comment, 0)
except AwlSimError as e:
MessageBox.handleAwlSimError(self,
"Library symbol error", e)
return False
assert(self.symTabs.count() >= 1)
if self.symTabs.count() == 1:
# We only have one table. Add the symbol.
self.__addSymbolToTabWidget(self.symTabs.widget(0),
symbol)
else:
QMessageBox.information(self,
"Please select AWL/STL source",
"Can not paste template.\n\n"
"Please move the text cursor to the place "
"in the AWL/STL code where you want to paste "
"the template to.")
# Ask which table to add the symbol to.
tabWidgets = tuple(self.symTabs.allTabWidgets())
entries = []
for i, tabWidget in enumerate(tabWidgets):
entries.append("%d: %s" %\
(i + 1, tabWidget.getSource().name))
entry, ok = QInputDialog.getItem(self,
"Select symbol table",
"Please select the symbol table "\
"where to add the symbol to:"
"\n%s \"%s\"" %\
(address, symbolName),
entries, 0, False)
if not ok or not entry:
return False
selIndex = int(entry.split(":")[0]) - 1
tabWidget = tabWidgets[selIndex]
self.__addSymbolToTabWidget(tabWidget, symbol)
return True
def insertOB(self):
dlg = TemplateDialog("OB", parent=self)
......@@ -278,7 +328,15 @@ class ProjectWidget(QTabWidget):
dlg.getVerbose()))
def openLibrary(self):
dlg = LibraryDialog(self.__project.getExtInsnsEn(), self)
dlg = LibraryDialog(self.__project, self)
if dlg.exec_() == QDialog.Accepted:
if dlg.pasteText:
self.__pasteAwlText(dlg.pasteText)
# Paste the code.
if not self.__pasteAwlText(dlg.pasteText):
return
if dlg.pasteSymbol:
# Add a symbol to a symbol table.
symbolName, address, dataType, comment = dlg.pasteSymbol
if not self.__pasteSymbol(symbolName, address,
dataType, comment):
return
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