diff python/apps/diagrameditor.py @ 93:f7ec7517cabb

edits
author windel
date Mon, 24 Dec 2012 12:52:13 +0100
parents 0c4bdbf0aead
children
line wrap: on
line diff
--- a/python/apps/diagrameditor.py	Sat Dec 15 23:56:26 2012 +0100
+++ b/python/apps/diagrameditor.py	Mon Dec 24 12:52:13 2012 +0100
@@ -6,6 +6,7 @@
 
 from diagramitems import Connection, ResizeSelectionHandle, Block, DiagramScene, CodeBlock
 from icons import newicon, saveicon, loadicon
+import diagramitems
 
 """
  Author: Windel Bouwman
@@ -112,19 +113,22 @@
       self.scale(sx, sx)
       event.accept()
    def dragEnterEvent(self, event):
-      if event.mimeData().hasFormat('component/name'): event.accept()
+      if event.mimeData().hasFormat('component/name'):
+         event.accept()
    def dragMoveEvent(self, event):
       if event.mimeData().hasFormat('component/name'): event.accept()
    def dropEvent(self, event):
       if event.mimeData().hasFormat('component/name'):
          name = bytes(event.mimeData().data('component/name')).decode()
+         kind, name = name.split(':')
          pos = self.mapToScene(event.pos())
          s = self.scene()
-         b = CodeBlock(s.uniqify(name))
+         print(kind, 'name:', name)
+         kind = getattr(diagramitems, kind)
+         print(kind)
+         b = kind(s.uniqify(name))
          b.setPos(pos)
          s.addItem(b)
-         # TODO: do this in a cleaner way:
-         self.model.modelReset.emit()
 
 class LibraryModel(QStandardItemModel):
    mimeTypes = lambda self: ['component/name']
@@ -140,10 +144,10 @@
    def __init__(self):
       super(ModelHierarchyModel, self).__init__()
       self.rootDiagram = DiagramScene()
-      self.rootDiagram.changed.connect(self.cha)
+      self.rootDiagram.structureChanged.connect(self.handlechange)
       self.filename = None
-   def cha(self, region):
-      print(region)
+   def handlechange(self):
+      self.modelReset.emit()
    def setDict(self, d):
       self.rootDiagram.Dict = d
       self.modelReset.emit()
@@ -174,6 +178,7 @@
          if block.scene() == self.rootDiagram:
             return QModelIndex()
          else:
+            print(block)
             outerBlock = block.scene().containingBlock
             return outerBlock.index
       print('parent: No valid index')
@@ -220,7 +225,7 @@
       painter.drawEllipse(20, 20, 20, 20)
       painter.end()
       # Fill library:
-      for name in ['Block', 'Uber unit', 'Device']:
+      for name in ['CodeBlock:codeBlock', 'DiagramBlock:submod', 'Block:blk']:
          self.libraryModel.appendRow(QStandardItem(QIcon(pixmap), name))
       self.setModel(self.libraryModel)
       self.setViewMode(self.IconMode)