2 Copyright (C) 1997-2017 JDERobot Developers Team 4 This program is free software; you can redistribute it and/or modify 5 it under the terms of the GNU General Public License as published by 6 the Free Software Foundation; either version 2 of the License, or 7 (at your option) any later version. 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU Library General Public License for more details. 14 You should have received a copy of the GNU General Public License 15 along with this program; if not, see <http://www.gnu.org/licenses/>. 17 Authors : Okan Asik (asik.okan@gmail.com) 20 from PyQt5.QtCore
import Qt, pyqtSignal
21 from PyQt5.QtGui
import QPainter, QPixmap
22 from PyQt5.QtWidgets
import QMainWindow, QDockWidget, QTreeView, QGraphicsView, \
23 QWidget, QLabel, QVBoxLayout, QPushButton, QGraphicsItem, \
25 from visualstates.gui.tree.treemodel
import TreeModel
26 from visualstates.core.state
import State
27 from visualstates.core.transition
import Transition
28 from visualstates.configs.rospackage
import getPackagePath
33 activeStateChanged = pyqtSignal(int)
34 runningStateChanged = pyqtSignal(int)
35 loadFromRoot = pyqtSignal(int)
40 self.setWindowTitle(
"VisualStates RunTime GUI")
50 self.setGeometry(0, 0, 800, 600)
63 dockWidget = QDockWidget()
64 dockWidget.setAllowedAreas(Qt.LeftDockWidgetArea)
65 dockWidget.setFeatures(QDockWidget.NoDockWidgetFeatures)
66 dockWidget.setTitleBarWidget(QWidget())
73 logoPixmap = QPixmap(
getPackagePath() +
'/share/resources/jderobot.png')
74 self.logo.setPixmap(logoPixmap)
77 self.upButton.setText(
'Up')
80 leftContainer = QWidget()
81 leftLayout = QVBoxLayout()
84 leftLayout.addWidget(self.
logo)
85 leftContainer.setLayout(leftLayout)
87 dockWidget.setWidget(leftContainer)
88 self.addDockWidget(Qt.LeftDockWidgetArea, dockWidget)
93 self.scene.setSceneRect(0, 0, 2000, 2000)
96 self.stateCanvas.setScene(self.
scene)
97 self.stateCanvas.setRenderHint(QPainter.Antialiasing)
100 def addState(self, id, name, initial, x, y, parentId):
101 if parentId
is not None:
103 self.
states[id] = State(id, name, initial,
None, self.
states[parentId])
110 self.
states[id] = State(id, name, initial,
None)
114 self.
states[id].setPos(x, y)
121 self.runningStateChanged.emit(id)
133 if self.
states[id].parent
is None:
138 if self.
states[id].parent.id == self.activeState.id:
141 for childState
in self.
states[id].parent.getChildren():
142 if childState.getRunning()
and childState.id != id:
143 childState.setRunning(
False)
147 elif childState.id == id:
148 childState.setRunning(
True)
153 if self.
states[id].parent
is not None:
154 self.treeModel.setAllBackgroundByParentId(Qt.white, self.
states[id].parent.id)
155 self.treeModel.setBackgroundById(id, Qt.green)
158 self.activeStateChanged.emit(id)
166 if self.activeState.id == id:
171 for childState
in self.activeState.getChildren():
172 childState.resetGraphicsItem()
173 for childTransition
in childState.getOriginTransitions():
174 childTransition.resetGraphicsItem()
178 for childState
in self.activeState.getChildren():
180 for childTransition
in childState.getOriginTransitions():
181 gtItem = childTransition.getGraphicsItem()
182 gtItem.disableInteraction()
183 self.scene.addItem(gtItem)
186 self.loadFromRoot.emit(0)
189 self.treeModel.loadFromRoot(self.
states[id])
190 self.
states[id].setRunning(
True)
191 for child
in self.
states[id].getChildren():
193 child.setRunning(
True)
194 self.treeModel.setBackgroundById(child.id, Qt.green)
198 if len(stateGraphicsItem.stateData.getChildren()) > 0:
203 if self.activeState.parent
is not None:
211 for child
in state.getChildren():
213 if result
is not None:
218 id = index.internalPointer().id
220 if len(self.
states[id].getChildren()) > 0:
224 if len(state.getChildren()) > 0:
225 stateList.append(state)
227 for s
in state.getChildren():
231 gsItem = state.getGraphicsItem()
232 gsItem.setAcceptHoverEvents(
False)
233 gsItem.setFlag(QGraphicsItem.ItemIsMovable,
False)
235 gsItem.disableInteraction()
236 self.scene.addItem(gsItem)
239 gsItem = state.getGraphicsItem()
240 if gsItem
in self.scene.items():
241 gsItem.doubleClicked.disconnect()
242 self.scene.removeItem(gsItem)
243 state.resetGraphicsItem()
def emitLoadFromRoot(self)
def upButtonClicked(self)
def addTransition(self, id, name, originId, destinationId, x, y)
def __init__(self, parent=None)
def getStateList(self, state, stateList)
def createStateCanvas(self)
def addState(self, id, name, initial, x, y, parentId)
def addStateGraphicsItem(self, state)
def emitRunningStateById(self, id)
def getStateById(self, state, id)
def activeStateChangedHandle(self, id)
def treeItemClicked(self, index)
def stateDoubleClicked(self, stateGraphicsItem)
def removeStateGraphicsItem(self, state)
def runningStateChangedHandle(self, id)
def emitActiveStateById(self, id)
def loadFromRootHandle(self, id)