Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: browser to viewer #185

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 10 additions & 60 deletions buttleofx/MainWindow.qml
Original file line number Diff line number Diff line change
Expand Up @@ -381,18 +381,8 @@ ApplicationWindow {
text: object.pluginLabel

onTriggered: {
_buttleData.currentGraphIsGraph()
_buttleData.currentGraphWrapper = _buttleData.graphWrapper

// If before the viewer was showing an image from the brower, we change the currentView
if (_buttleData.currentViewerIndex > 9) {
_buttleData.currentViewerIndex = player.lastView
if (player.lastNodeWrapper != undefined)
_buttleData.currentViewerNodeWrapper = player.lastNodeWrapper
player.changeViewer(player.lastView)
}

_buttleManager.nodeManager.creationNode("_buttleData.graph", object.pluginType, 0, 0)
_buttleData.setActiveGraphId("graphEditor")
_buttleManager.nodeManager.creationNode("graphEditor", object.pluginType, 0, 0)
}
}

Expand All @@ -415,18 +405,8 @@ ApplicationWindow {
text: object.pluginLabel

onTriggered: {
_buttleData.currentGraphIsGraph()
_buttleData.currentGraphWrapper = _buttleData.graphWrapper

// If before the viewer was showing an image from the brower, we change the currentView
if (_buttleData.currentViewerIndex > 9) {
_buttleData.currentViewerIndex = player.lastView
if (player.lastNodeWrapper != undefined)
_buttleData.currentViewerNodeWrapper = player.lastNodeWrapper
player.changeViewer(player.lastView)
}

_buttleManager.nodeManager.creationNode("_buttleData.graph", object.pluginType, 0, 0)
_buttleData.setActiveGraphId("graphEditor")
_buttleManager.nodeManager.creationNode("graphEditor", object.pluginType, 0, 0)
}
}

Expand All @@ -449,18 +429,8 @@ ApplicationWindow {
text: object.pluginLabel

onTriggered: {
_buttleData.currentGraphIsGraph()
_buttleData.currentGraphWrapper = _buttleData.graphWrapper

// If before the viewer was showing an image from the brower, we change the currentView
if (_buttleData.currentViewerIndex > 9) {
_buttleData.currentViewerIndex = player.lastView
if (player.lastNodeWrapper != undefined)
_buttleData.currentViewerNodeWrapper = player.lastNodeWrapper
player.changeViewer(player.lastView)
}

_buttleManager.nodeManager.creationNode("_buttleData.graph", object.pluginType, 0, 0)
_buttleData.setActiveGraphId("graphEditor")
_buttleManager.nodeManager.creationNode("graphEditor", object.pluginType, 0, 0)
}
}

Expand All @@ -483,18 +453,8 @@ ApplicationWindow {
text: object.pluginLabel

onTriggered: {
_buttleData.currentGraphIsGraph()
_buttleData.currentGraphWrapper = _buttleData.graphWrapper

// If before the viewer was showing an image from the brower, we change the currentView
if (_buttleData.currentViewerIndex > 9) {
_buttleData.currentViewerIndex = player.lastView
if (player.lastNodeWrapper != undefined)
_buttleData.currentViewerNodeWrapper = player.lastNodeWrapper
player.changeViewer(player.lastView)
}

_buttleManager.nodeManager.creationNode("_buttleData.graph", object.pluginType, 0, 0)
_buttleData.setActiveGraphId("graphEditor")
_buttleManager.nodeManager.creationNode("graphEditor", object.pluginType, 0, 0)
}
}

Expand All @@ -517,18 +477,8 @@ ApplicationWindow {
text: object.pluginLabel

onTriggered: {
_buttleData.currentGraphIsGraph()
_buttleData.currentGraphWrapper = _buttleData.graphWrapper

// If before the viewer was showing an image from the brower, we change the currentView
if (_buttleData.currentViewerIndex > 9) {
_buttleData.currentViewerIndex = player.lastView
if (player.lastNodeWrapper != undefined)
_buttleData.currentViewerNodeWrapper = player.lastNodeWrapper
player.changeViewer(player.lastView)
}

_buttleManager.nodeManager.creationNode("_buttleData.graph", object.pluginType, 0, 0)
_buttleData.setActiveGraphId("graphEditor")
_buttleManager.nodeManager.creationNode("graphEditor", object.pluginType, 0, 0)
}
}

Expand Down
66 changes: 39 additions & 27 deletions buttleofx/core/graph/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,40 +97,38 @@ def createConnection(self, clipOut, clipIn):

def createNode(self, nodeType, x=20, y=20):
"""
Adds a node from the node list when a node is created.
Add a node from the node list when a node is created.
"""
cmdCreateNode = CmdCreateNode(self, nodeType, x, y)
cmdManager = globalCommandManager
return cmdManager.push(cmdCreateNode)

def createReaderNode(self, url, x, y):
"""
Creates a reader node when an image has been dropped in the graph.
Create a reader node from an image url to specific coordinates.
"""
(_, extension) = os.path.splitext(url)
try:
nodeType = tuttle.getBestReader(extension)
except Exception:
logging.debug("Unknown format. Can't create the reader node for extension '%s'.", extension)
return
return None

# We create the node.
# We can't use a group of commands because we need the tuttle node to set the value, and this tuttle node is
# created in the function doCmd() of the cmdCreateNode. So we use a special command CmdCreateReaderNode which
# creates a new node and set its value with the correct url.
# See the definition of the class CmdCreateReaderNode.
cmdCreateReaderNode = CmdCreateReaderNode(self, nodeType, x, y, url)
cmdManager = globalCommandManager
return cmdManager.push(cmdCreateReaderNode)
return globalCommandManager.push(cmdCreateReaderNode)

def deleteConnection(self, connection):
"""
Removes a connection.
Pushes a command in the CommandManager.
"""
cmdDeleteConnection = CmdDeleteConnection(self, connection)
cmdManager = globalCommandManager
cmdManager.push(cmdDeleteConnection)
globalCommandManager.push(cmdDeleteConnection)

def deleteNodeConnections(self, nodeName):
"""
Expand All @@ -147,8 +145,7 @@ def deleteNodes(self, nodes):
Pushes a command in the CommandManager.
"""
cmdDeleteNodes = CmdDeleteNodes(self, nodes)
cmdManager = globalCommandManager
cmdManager.push(cmdDeleteNodes)
globalCommandManager.push(cmdDeleteNodes)

# ## Others ## #

Expand All @@ -174,44 +171,59 @@ def nodesConnected(self, clipOut, clipIn):
return True
return False

def nodeMoved(self, nodeName, newX, newY):
def moveSelectedNodes(self, offsetX, offsetY):
"""
This function pushes a cmdMoved in the globalCommandManager.
Move all selected nodes with an offset.
"""
from buttleofx.data import globalButtleData
node = globalButtleData.getCurrentGraph().getNode(nodeName)
if not node:
logging.debug("no nodes nodeMoved -- graph : %s", globalButtleData.getCurrentGraph())

# What is the value of the movement (compared to the old position)?
oldX, oldY = node.getOldCoord()
xMovement = newX - oldX
yMovement = newY - oldY

print(oldX, oldY)
print(newX, newY)

# If the node didn't really move, nothing is done
if (xMovement, xMovement) == (0, 0):
if (offsetX, offsetY) == (0, 0):
return

commands = []

# We create a GroupUndoableCommands of CmdSetCoord for each selected node
for selectedNodeWrapper in globalButtleData.getCurrentSelectedNodeWrappers():
# We get the needed informations for this node
# We get the needed information for this node
selectedNode = selectedNodeWrapper.getNode()
selectedNodeName = selectedNode.getName()
oldX, oldY = selectedNode.getOldCoord()

# We set the new coordinates of the node (each selected node is doing the same movement)
cmdMoved = CmdSetCoord(self, selectedNodeName, (oldX + xMovement, oldY + yMovement))
cmdMoved = CmdSetCoord(self, selectedNodeName, (oldX + offsetX, oldY + offsetY))

commands.append(cmdMoved)

# Then we push the group of commands
globalCommandManager.push(GroupUndoableCommands(commands, "Move nodes"))

def moveNode(self, nodeName, newX, newY):
"""
Move all selected nodes to get nodeName at a specific position.
"""
from buttleofx.data import globalButtleData
node = globalButtleData.getActiveGraph().getNode(nodeName)
if not node:
logging.debug("no nodes moveNode -- graph : %s", globalButtleData.getActiveGraph())
return

# What is the value of the movement (compared to the old position)?
oldX, oldY = node.getOldCoord()

logging.debug("Move node from (%s, %s) to (%s, %s)", oldX, oldY, newX, newY)

self.moveSelectedNodes(newX - oldX, newY - oldY)

def hardClear(self):
"""
Clear all nodes and connections.
Also remove all the nodes from the TuttleGraph.
:warning: that can break the undo stack.
"""
self._graphTuttle.clear()
self._nodes = []
self._connections = []

def object_to_dict(self):
"""
Convert the graph to a dictionary of his representation.
Expand Down Expand Up @@ -258,7 +270,7 @@ def dict_to_object(self, graphData):
def __str__(self):
"""
Displays on terminal some data.
Usefull to debug the class.
Useful to debug the class.
"""
str_list = []

Expand Down
Loading