def setupStartupVariables(self): """ Each program starts with a set of workflow variables that are defined by where the program is executed from and potentially a set of environment variables. """ # The current session gets a "binary directory" variable depends_variables.add('DEPENDS_DIR') depends_variables.setx('DEPENDS_DIR', os.path.dirname(os.path.realpath(__file__)), readOnly=True) # ...And a path that points to where the nodes are loaded from depends_variables.add('NODE_PATH') if not os.environ.get('DEPENDS_NODE_PATH'): depends_variables.setx('NODE_PATH', os.path.join(depends_variables.value('DEPENDS_DIR'), 'nodes'), readOnly=True) else: depends_variables.setx('NODE_PATH', os.environ.get('DEPENDS_NODE_PATH'), readOnly=True)
def setupStartupVariables(self): """ Each program starts with a set of workflow variables that are defined by where the program is executed from and potentially a set of environment variables. """ # The current session gets a "binary directory" variable depends_variables.add('DEPENDS_DIR') depends_variables.setx('DEPENDS_DIR', os.path.dirname(os.path.realpath(__file__)), readOnly=True) # ...And a path that points to where the nodes are loaded from depends_variables.add('NODE_PATH') if not os.environ.get('DEPENDS_NODE_PATH'): depends_variables.setx('NODE_PATH', os.path.join( depends_variables.value('DEPENDS_DIR'), 'nodes'), readOnly=True) else: depends_variables.setx('NODE_PATH', os.environ.get('DEPENDS_NODE_PATH'), readOnly=True)
def __init__(self, startFile="", parent=None): """ """ QtGui.QMainWindow.__init__(self, parent) # Add the DAG widget self.graphicsViewWidget = depends_graphics_widgets.GraphicsViewWidget( self) self.graphicsScene = self.graphicsViewWidget.scene() self.setCentralWidget(self.graphicsViewWidget) # Create the docking widget for the properties dialog self.propDock = QtGui.QDockWidget() self.propDock.setObjectName('propDock') self.propDock.setAllowedAreas(QtCore.Qt.RightDockWidgetArea | QtCore.Qt.LeftDockWidgetArea) self.propDock.setWindowTitle("Properties") self.addDockWidget(QtCore.Qt.RightDockWidgetArea, self.propDock) # Create and add the properties dialog to the dock widget self.propWidget = depends_property_widget.PropWidget(self) self.propDock.setWidget(self.propWidget) # Create the docking widget for the variable dialog self.variableDock = QtGui.QDockWidget() self.variableDock.setObjectName('variableDock') self.variableDock.setAllowedAreas(QtCore.Qt.RightDockWidgetArea | QtCore.Qt.LeftDockWidgetArea) self.variableDock.setWindowTitle("Variables") self.addDockWidget(QtCore.Qt.RightDockWidgetArea, self.variableDock) # Create and add the variable dialog to the dock widget self.variableWidget = depends_variable_widget.VariableWidget(self) self.variableDock.setWidget(self.variableWidget) self.variableWidget.rebuild(depends_variables.variableSubstitutions) # self.variableDock.hide() # Set some locals self.dag = None self.undoStack = QtGui.QUndoStack(self) # Undo and Redo have built-in ways to create their menus undoAction = self.undoStack.createUndoAction(self, "&Undo") undoAction.setShortcuts(QtGui.QKeySequence.Undo) redoAction = self.undoStack.createRedoAction(self, "&Redo") redoAction.setShortcuts(QtGui.QKeySequence.Redo) # Application settings self.settings = QtCore.QSettings('vcl', 'depends', self) self.restoreSettings() # Create the menu bar fileMenu = self.menuBar().addMenu("&File") fileMenu.addAction( QtGui.QAction("&Open DAG...", self, shortcut="Ctrl+O", triggered=self.openDialog)) self.recentMenu = fileMenu.addMenu('Recent Files') self.rebuildRecentMenu() fileMenu.addAction( QtGui.QAction("&Save DAG", self, shortcut="Ctrl+S", triggered=lambda: self.save(self.workingFilename))) #fileMenu.addAction(QtGui.QAction("Save DAG &Version Up", self, shortcut="Ctrl+Space", triggered=self.saveVersionUp)) fileMenu.addAction( QtGui.QAction("Save DAG &As...", self, shortcut="Ctrl+Shift+S", triggered=self.saveAs)) fileMenu.addAction( QtGui.QAction("&Quit...", self, shortcut="Ctrl+Q", triggered=self.close)) editMenu = self.menuBar().addMenu("&Edit") editMenu.addAction(undoAction) editMenu.addAction(redoAction) editMenu.addSeparator() createMenu = self.menuBar().addMenu("&Nodes") editMenu.addAction( QtGui.QAction("&Delete Node(s)", self, shortcut="Delete", triggered=self.deleteSelectedNodes)) editMenu.addAction( QtGui.QAction("&Shake Node(s)", self, shortcut="Backspace", triggered=self.shakeSelectedNodes)) editMenu.addAction( QtGui.QAction("D&uplicate Node", self, shortcut="Ctrl+D", triggered=self.duplicateSelectedNodes)) editMenu.addSeparator() editMenu.addAction( QtGui.QAction("&Group Nodes", self, shortcut="Ctrl+G", triggered=self.groupSelectedNodes)) editMenu.addAction( QtGui.QAction("&Ungroup Nodes", self, shortcut="Ctrl+Shift+G", triggered=self.ungroupSelectedNodes)) executeMenu = self.menuBar().addMenu("E&xecute") executeMenu.addAction( QtGui.QAction("Execute &Selected Node", self, shortcut="Ctrl+Shift+E", triggered=lambda: self.executeSelected( executeImmediately=True))) recipeMenu = executeMenu.addMenu("&Output Recipe") executeMenu.addSeparator() executeMenu.addAction( QtGui.QAction("Version &Up outputs", self, shortcut="Ctrl+U", triggered=self.versionUpSelectedOutputFilenames)) #executeMenu.addAction(QtGui.QAction("&Test Menu Item", self, shortcut= "Ctrl+T", triggered=self.testMenuItem)) executeMenu.addSeparator() executeMenu.addAction( QtGui.QAction("&Reload plugins", self, shortcut="Ctrl+0", triggered=self.reloadPlugins)) windowMenu = self.menuBar().addMenu("&Window") windowMenu.addAction(self.propDock.toggleViewAction()) windowMenu.addAction(self.variableDock.toggleViewAction()) # Setup the variables, load the plugins, and auto-generate the read dag nodes self.setupStartupVariables() depends_node.loadChildNodesFromPaths( depends_variables.value('NODE_PATH').split(':')) # Generate the Create menu. Must be done after plugins are loaded. menuActions = self.createCreateMenuActions() for action in menuActions: cat = None for eAct in createMenu.actions(): if eAct.menu(): if eAct.text() == action.category: cat = eAct.menu() break if not cat: cat = QtGui.QMenu(createMenu) cat.setTitle(action.category) createMenu.addMenu(cat) cat.addAction(action) # Load the starting filename or create a new DAG self.workingFilename = startFile self.dag = depends_dag.DAG() self.graphicsScene.setDag(self.dag) if not self.open(self.workingFilename): self.setWindowTitle("Depends") self.undoStack.setClean() # This is a small workaround to insure the properties dialog doesn't # try to redraw twice when two nodes are rapidly selected # (within a frame of eachother). There's a good chance the way I # construct a property dialog is strange, but a twice-at-once redraw # was making the entire UI destroy itself and spawn a temporary child # window that had the same name as the program 'binary'. self.selectionTimer = QtCore.QTimer(self) self.selectionTimer.setInterval(0) self.selectionTimer.timeout.connect(self.selectionRefresh) # Hook up some signals self.graphicsViewWidget.createNode.connect(self.createNode) self.graphicsScene.selectionChanged.connect(self.selectionChanged) self.graphicsScene.nodesDisconnected.connect(self.nodesDisconnected) self.graphicsScene.nodesConnected.connect(self.nodesConnected) self.propWidget.attrChanged.connect(self.propertyEdited) self.variableWidget.addVariable.connect(depends_variables.add) self.variableWidget.setVariable.connect(depends_variables.setx) self.variableWidget.removeVariable.connect(depends_variables.remove) self.undoStack.cleanChanged.connect(self.setWindowTitleClean)
def __init__(self, startFile="", parent=None): """ """ QtGui.QMainWindow.__init__(self, parent) # Add the DAG widget self.graphicsViewWidget = depends_graphics_widgets.GraphicsViewWidget(self) self.graphicsScene = self.graphicsViewWidget.scene() self.setCentralWidget(self.graphicsViewWidget) # Create the docking widget for the properties dialog self.propDock = QtGui.QDockWidget() self.propDock.setObjectName('propDock') self.propDock.setAllowedAreas(QtCore.Qt.RightDockWidgetArea | QtCore.Qt.LeftDockWidgetArea) self.propDock.setWindowTitle("Properties") self.addDockWidget(QtCore.Qt.RightDockWidgetArea, self.propDock) # Create and add the properties dialog to the dock widget self.propWidget = depends_property_widget.PropWidget(self) self.propDock.setWidget(self.propWidget) # Create the docking widget for the variable dialog self.variableDock = QtGui.QDockWidget() self.variableDock.setObjectName('variableDock') self.variableDock.setAllowedAreas(QtCore.Qt.RightDockWidgetArea | QtCore.Qt.LeftDockWidgetArea) self.variableDock.setWindowTitle("Variables") self.addDockWidget(QtCore.Qt.RightDockWidgetArea, self.variableDock) # Create and add the variable dialog to the dock widget self.variableWidget = depends_variable_widget.VariableWidget(self) self.variableDock.setWidget(self.variableWidget) self.variableWidget.rebuild(depends_variables.variableSubstitutions) # self.variableDock.hide() # Set some locals self.dag = None self.undoStack = QtGui.QUndoStack(self) # Undo and Redo have built-in ways to create their menus undoAction = self.undoStack.createUndoAction(self, "&Undo") undoAction.setShortcuts(QtGui.QKeySequence.Undo) redoAction = self.undoStack.createRedoAction(self, "&Redo") redoAction.setShortcuts(QtGui.QKeySequence.Redo) # Application settings self.settings = QtCore.QSettings('vcl', 'depends', self) self.restoreSettings() # Create the menu bar fileMenu = self.menuBar().addMenu("&File") fileMenu.addAction(QtGui.QAction("&Open DAG...", self, shortcut="Ctrl+O", triggered=self.openDialog)) self.recentMenu = fileMenu.addMenu('Recent Files') self.rebuildRecentMenu() fileMenu.addAction(QtGui.QAction("&Save DAG", self, shortcut="Ctrl+S", triggered=lambda: self.save(self.workingFilename))) #fileMenu.addAction(QtGui.QAction("Save DAG &Version Up", self, shortcut="Ctrl+Space", triggered=self.saveVersionUp)) fileMenu.addAction(QtGui.QAction("Save DAG &As...", self, shortcut="Ctrl+Shift+S", triggered=self.saveAs)) fileMenu.addAction(QtGui.QAction("&Quit...", self, shortcut="Ctrl+Q", triggered=self.close)) editMenu = self.menuBar().addMenu("&Edit") editMenu.addAction(undoAction) editMenu.addAction(redoAction) editMenu.addSeparator() createMenu = self.menuBar().addMenu("&Nodes") editMenu.addAction(QtGui.QAction("&Delete Node(s)", self, shortcut="Delete", triggered=self.deleteSelectedNodes)) editMenu.addAction(QtGui.QAction("&Shake Node(s)", self, shortcut="Backspace", triggered=self.shakeSelectedNodes)) editMenu.addAction(QtGui.QAction("D&uplicate Node", self, shortcut="Ctrl+D", triggered=self.duplicateSelectedNodes)) editMenu.addSeparator() editMenu.addAction(QtGui.QAction("&Group Nodes", self, shortcut="Ctrl+G", triggered=self.groupSelectedNodes)) editMenu.addAction(QtGui.QAction("&Ungroup Nodes", self, shortcut="Ctrl+Shift+G", triggered=self.ungroupSelectedNodes)) executeMenu = self.menuBar().addMenu("E&xecute") executeMenu.addAction(QtGui.QAction("Execute &Selected Node", self, shortcut= "Ctrl+Shift+E", triggered=lambda: self.executeSelected(executeImmediately=True))) recipeMenu = executeMenu.addMenu("&Output Recipe") executeMenu.addSeparator() executeMenu.addAction(QtGui.QAction("Version &Up outputs", self, shortcut= "Ctrl+U", triggered=self.versionUpSelectedOutputFilenames)) #executeMenu.addAction(QtGui.QAction("&Test Menu Item", self, shortcut= "Ctrl+T", triggered=self.testMenuItem)) executeMenu.addSeparator() executeMenu.addAction(QtGui.QAction("&Reload plugins", self, shortcut= "Ctrl+0", triggered=self.reloadPlugins)) windowMenu = self.menuBar().addMenu("&Window") windowMenu.addAction(self.propDock.toggleViewAction()) windowMenu.addAction(self.variableDock.toggleViewAction()) # Setup the variables, load the plugins, and auto-generate the read dag nodes self.setupStartupVariables() depends_node.loadChildNodesFromPaths(depends_variables.value('NODE_PATH').split(':')) # Generate the Create menu. Must be done after plugins are loaded. menuActions = self.createCreateMenuActions() for action in menuActions: cat = None for eAct in createMenu.actions(): if eAct.menu(): if eAct.text() == action.category: cat = eAct.menu() break if not cat: cat = QtGui.QMenu(createMenu) cat.setTitle(action.category) createMenu.addMenu(cat) cat.addAction(action) # Load the starting filename or create a new DAG self.workingFilename = startFile self.dag = depends_dag.DAG() self.graphicsScene.setDag(self.dag) if not self.open(self.workingFilename): self.setWindowTitle("Depends") self.undoStack.setClean() # This is a small workaround to insure the properties dialog doesn't # try to redraw twice when two nodes are rapidly selected # (within a frame of eachother). There's a good chance the way I # construct a property dialog is strange, but a twice-at-once redraw # was making the entire UI destroy itself and spawn a temporary child # window that had the same name as the program 'binary'. self.selectionTimer = QtCore.QTimer(self) self.selectionTimer.setInterval(0) self.selectionTimer.timeout.connect(self.selectionRefresh) # Hook up some signals self.graphicsViewWidget.createNode.connect(self.createNode) self.graphicsScene.selectionChanged.connect(self.selectionChanged) self.graphicsScene.nodesDisconnected.connect(self.nodesDisconnected) self.graphicsScene.nodesConnected.connect(self.nodesConnected) self.propWidget.attrChanged.connect(self.propertyEdited) self.variableWidget.addVariable.connect(depends_variables.add) self.variableWidget.setVariable.connect(depends_variables.setx) self.variableWidget.removeVariable.connect(depends_variables.remove) self.undoStack.cleanChanged.connect(self.setWindowTitleClean)