def createNode(self, nodeType, x = 20, y = 20): """ Adds a node from the node list when a node is created. """ cmdCreateNode = CmdCreateNode(self, nodeType, x, y) cmdManager = CommandManager() return cmdManager.push(cmdCreateNode)
def createNode(self, nodeType, x=20, y=20): """ Adds a node from the node list when a node is created. """ cmdCreateNode = CmdCreateNode(self, nodeType, x, y) cmdManager = CommandManager() return cmdManager.push(cmdCreateNode)
def saveData(self, url='buttleofx/backup/data.bofx'): """ Saves all data in a json file (default file : buttleofx/backup/data.bofx) """ with io.open(url, 'w', encoding='utf-8') as f: dictJson = { "date": {}, "window": {}, "graph": {}, "paramEditor": {}, "viewer": { "other_views": {}, "current_view": {} } } # date today = datetime.today().strftime("%A, %d. %B %Y %I:%M%p") dictJson["date"]["creation"] = today # graph dictJson["graph"] = self.getGraph().object_to_dict() # graph : currentSeletedNodes for node in self.getGraph().getNodes(): if node.getName() in self.getCurrentSelectedNodeNames(): dictJson["graph"]["currentSelectedNodes"].append( node.getName()) # paramEditor : currentParamNodeName dictJson["paramEditor"] = self.getCurrentParamNodeName() # viewer : currentViewerNodeName for num_view, view in self._mapViewerIndextoNodeName.iteritems(): if view is not None: (nodeName, frame) = view if self.getCurrentViewerNodeName() == nodeName: dictJson["viewer"]["current_view"][str(num_view)] = {} dictJson["viewer"]["current_view"][str( num_view)]["nodeName"] = nodeName dictJson["viewer"]["current_view"][str( num_view)]["frame"] = frame else: dictJson["viewer"]["other_views"][str(num_view)] = {} dictJson["viewer"]["other_views"][str( num_view)]["nodeName"] = nodeName dictJson["viewer"]["other_views"][str( num_view)]["frame"] = frame # write dictJson in a file f.write( unicode( json.dumps(dictJson, sort_keys=True, indent=2, ensure_ascii=False))) f.closed # Finally we update the savedGraphIndex of the CommandManager : it must be equal to the current index CommandManager().setSavedGraphIndex(CommandManager().getIndex())
def createReaderNode(self, url, x, y): """ Creates a reader node when an image has been dropped in the graph. """ extension = url.split(".")[-1].lower() if extension in ['jpeg', 'jpg', 'jpe', 'jfif', 'jfi']: nodeType = 'tuttle.jpegreader' elif extension == 'png': nodeType = 'tuttle.pngreader' elif extension in ['mkv', 'mpeg', 'mp4', 'avi', 'mov', 'aac', 'ac3', 'adf', 'adx', 'aea', 'ape', 'apl', 'mac', 'bin', 'bit', 'bmv', 'cdg', 'cdxl', 'xl', '302', 'daud', 'dts', 'dv', 'dif', 'cdata', 'eac3', 'flm', 'flac', 'flv', 'g722', '722', 'tco', 'rco', 'g723_1', 'g729', 'gsm', 'h261', 'h26l', 'h264', '264', 'idf', 'cgi', 'latm', 'm4v', 'mjpg', 'mjpeg', 'mpo', 'mlp', 'mp2', 'mp3', 'm2a', 'mpc', 'mvi', 'mxg', 'v', 'nut', 'ogg', 'oma', 'omg', 'aa3', 'al', 'ul', 'sw', 'sb', 'uw', 'ub', 'yuv', 'cif', 'qcif', 'rgb', 'rt', 'rso', 'smi', 'sami', 'sbg', 'shn', 'vb', 'son', 'mjpg', 'sub', 'thd', 'tta', 'ans', 'art', 'asc', 'diz', 'ice', 'nfo', 'txt', 'vt', 'vc1', 'vqf', 'vql', 'vqe', 'vtt', 'yop', 'y4m']: nodeType = 'tuttle.ffmpegreader' elif extension in ['3fr', 'ari', 'arw', 'bay', 'crw', 'cr2', 'cap', 'dng', 'dcs', 'dcr', 'dng', 'drf', 'eip', 'erf', 'fff', 'iiq', 'k25', 'kdc', 'mef', 'mos', 'mrw', 'nef', 'nrw', 'obm', 'orf', 'pef', 'ptx', 'pxn', 'r3d', 'rad', 'raf', 'rw2', 'raw', 'rwl', 'rwz', 'srf', 'sr2', 'srw', 'x3f']: nodeType = 'tuttle.rawreader' elif extension in ['aai', 'art', 'arw', 'avi', 'avs', 'bmp', 'bmp2', 'bmp3', 'cals', 'cgm', 'cin', 'cmyk', 'cmyka', 'cr2', 'crw', 'cur', 'cut', 'dcm', 'dcr', 'dcx', 'dib', 'djvu', 'dng', 'dot', 'dpx', 'emf', 'epdf', 'epi', 'eps', 'eps2', 'eps3', 'epsf', 'epsi', 'ept', 'exr', 'fax', 'fig', 'fits', 'fpx', 'gif', 'gplt', 'gray', 'hdr', 'hpgl', 'hrz', 'html', 'ico', 'info', 'inline', 'jbig', 'jng', 'jp2', 'jpc', 'jpg', 'jpeg', 'man', 'mat', 'miff', 'mono', 'mng', 'm2v', 'mpeg', 'mpc', 'mpr', 'mrw', 'msl', 'mtv', 'mvg', 'nef', 'orf', 'otb', 'p7', 'palm', 'pam', 'pbm', 'pcd', 'pcds', 'pcl', 'pcx', 'pdb', 'pdf', 'pef', 'pfa', 'pfb', 'pfm', 'pgm', 'picon', 'pict', 'pix', 'png', 'png8', 'png16', 'png32', 'pnm', 'ppm', 'ps', 'ps2', 'ps3', 'psb', 'psd', 'ptif', 'pwp', 'rad', 'rgb', 'rgba', 'rla', 'rle', 'sct', 'sfw', 'sgi', 'shtml', 'sid', 'mrsid', 'sun', 'svg', 'tga', 'tiff', 'tim', 'tif', 'txt', 'uil', 'uyvy', 'vicar', 'viff', 'wbmp', 'webp', 'wmf', 'wpg', 'x', 'xbm', 'xcf', 'xpm', 'xwd', 'x3f', 'ycbcr', 'ycbcra', 'yuv']: nodeType = 'tuttle.imagemagickreader' elif extension in ['bmp', 'cin', 'dds', 'dpx', 'exr', 'fits', 'hdr', 'ico', 'j2k', 'j2c', 'jp2', 'jpeg', 'jpg', 'jpe', 'jfif', 'jfi', 'pbm', 'pgm', 'png', 'pnm', 'ppm', 'pic', 'psd', 'rgbe', 'sgi', 'tga', 'tif', 'tiff', 'tpic', 'tx', 'webp']: nodeType = 'tuttle.oiioreader' else: logging.debug("Unknown format. Can't create reader node.") return #use exception ! # 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 = CommandManager() return cmdManager.push(cmdCreateReaderNode)
def setValue1(self, value): if(self.getDefaultValue1() != value): self.setValue1HasChanged(True) if value != self.getValue1(): # Push the command cmdUpdate = CmdSetParamND(self, (value, self.getValue2())) cmdManager = CommandManager() cmdManager.push(cmdUpdate)
def deleteNodes(self, nodes): """ Removes a node in the node list when a node is deleted. Pushes a command in the CommandManager. """ cmdDeleteNodes = CmdDeleteNodes(self, nodes) cmdManager = CommandManager() cmdManager.push(cmdDeleteNodes)
def createConnection(self, clipOut, clipIn): """ Adds a connection in the connection list when a connection is created. Pushes a command in the CommandManager. """ cmdCreateConnection = CmdCreateConnection(self, clipOut, clipIn) cmdManager = CommandManager() return cmdManager.push(cmdCreateConnection)
def deleteConnection(self, connection): """ Removes a connection. Pushes a command in the CommandManager. """ cmdDeleteConnection = CmdDeleteConnection(self, connection) cmdManager = CommandManager() cmdManager.push(cmdDeleteConnection)
def setValue2(self, value): if (self.getDefaultValue2() != value): self.setValue2HasChanged(True) if value != self.getValue2(): # Set the command cmdUpdate = CmdSetParamND(self, (self.getValue1(), value)) cmdManager = CommandManager() cmdManager.push(cmdUpdate)
def setValue1(self, value): # if the value which is setting is different of the default value, # so the value has changed and title of param is displayed in bold in qml if(self.getDefaultValue1() != value): self.setValue1HasChanged(True) if value != self.getValue1(): # Push the command cmdUpdate = CmdSetParamND(self, (value, self.getValue2(), self.getValue3())) cmdManager = CommandManager() cmdManager.push(cmdUpdate)
def setValue1(self, value): # if the value which is setting is different of the default value, # so the value has changed and title of param is displayed in bold in qml if (self.getDefaultValue1() != value): self.setValue1HasChanged(True) if value != self.getValue1(): # Push the command cmdUpdate = CmdSetParamND(self, (value, self.getValue2())) cmdManager = CommandManager() cmdManager.push(cmdUpdate)
def redo(self): """ Calls the cmdManager to redo the last command. """ cmdManager = CommandManager() cmdManager.redo() # emit undo/redo display self.emitUndoRedoChanged() # if we need to update params or viewer buttleData = ButtleDataSingleton().get() buttleData.currentParamNodeChanged.emit() buttleData.currentViewerNodeChanged.emit()
def nodeMoved(self, nodeName, newX, newY): """ This function pushes a cmdMoved in the CommandManager. """ from buttleofx.data import ButtleDataSingleton buttleData = ButtleDataSingleton().get() node = buttleData.getGraph().getNode(nodeName) # What is the value of the movement (compared to the old position) ? oldX, oldY = node.getOldCoord() xMovement = newX - oldX yMovement = newY - oldY # if the node did'nt really move, nothing is done if (xMovement, xMovement) == (0, 0): return commands = [] # we create a GroupUndoableCommands of CmdSetCoord for each selected node for selectedNodeWrapper in buttleData.getCurrentSelectedNodeWrappers(): # we get the needed informations 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)) commands.append(cmdMoved) # then we push the group of commands CommandManager().push(GroupUndoableCommands(commands))
def pushValue(self, newValue): if newValue != self.getOldValue(): # push the command cmdUpdate = CmdSetParamString(self, str(newValue)) cmdManager = CommandManager() cmdManager.push(cmdUpdate)
def canRedo(self): """ Calls the cmdManager to return if we can redo or not. """ cmdManager = CommandManager() return cmdManager.canRedo()
#connections from buttleofx.gui.graph.connection import LineItem currentFilePath = os.path.dirname(os.path.abspath(__file__)) if __name__ == '__main__': QtDeclarative.qmlRegisterType(LineItem, "ConnectionLineItem", 1, 0, "ConnectionLine") app = QtGui.QApplication(sys.argv) view = QtDeclarative.QDeclarativeView() rc = view.rootContext() # create undo-redo context cmdManager = CommandManager() cmdManager.setActive() cmdManager.clean() # data buttleData = ButtleData().init(view) # expose to QML rc.setContextProperty("_buttleData", buttleData) view.setWindowTitle("Graph editor") view.setSource(os.path.join(currentFilePath, "qml/GraphEditor.qml")) view.setResizeMode(QtDeclarative.QDeclarativeView.SizeRootObjectToView) view.show() app.exec_()
def main(argv): #preload Tuttle tuttle.core().preload() # give to QML acces to TimerPlayer defined in buttleofx/gui/viewer QtDeclarative.qmlRegisterType(TimerPlayer, "TimerPlayer", 1, 0, "TimerPlayer") # add new QML type QtDeclarative.qmlRegisterType(Finder, "FolderListViewItem", 1, 0, "FolderListView") if tuttleofx_installed: QtDeclarative.qmlRegisterType(GLViewport_tuttleofx, "Viewport", 1, 0, "GLViewport") else: QtDeclarative.qmlRegisterType(GLViewport_pil, "Viewport", 1, 0, "GLViewport") # init undo_redo contexts cmdManager = CommandManager() cmdManager.setActive() cmdManager.clean() # create QApplication app = ButtleApp(argv) # create the declarative view view = QtDeclarative.QDeclarativeView() view.setViewport(QtOpenGL.QGLWidget()) view.setViewportUpdateMode(QtDeclarative.QDeclarativeView.FullViewportUpdate) # data buttleData = ButtleDataSingleton().get().init(view, currentFilePath) # manager buttleManager = ButtleManagerSingleton().get().init() # event buttleEvent = ButtleEventSingleton().get() # Menus fileMenu = MenuWrapper("file", 0, view, app) editMenu = MenuWrapper("edit", 0, view, app) addMenu = MenuWrapper("buttle/", 1, view, app) # expose data to QML rc = view.rootContext() rc.setContextProperty("_buttleApp", app) rc.setContextProperty("_buttleData", buttleData) rc.setContextProperty("_buttleManager", buttleManager) rc.setContextProperty("_buttleEvent", buttleEvent) rc.setContextProperty("_fileMenu", fileMenu) rc.setContextProperty("_editMenu", editMenu) rc.setContextProperty("_addMenu", addMenu) # set the view view.setSource(os.path.join(currentFilePath, "MainWindow.qml")) view.setResizeMode(QtDeclarative.QDeclarativeView.SizeRootObjectToView) view.setWindowTitle("ButtleOFX") view.setWindowIcon(QtGui.QIcon("blackMosquito.png")) view.setWindowIconText("ButtleOFX") view.setVisible(True) # Declare we are using instant coding tool on this view qic = QmlInstantCoding(view, verbose=True) # Add any source file (.qml and .js by default) in current working directory qic.addFilesFromDirectory(os.getcwd(), recursive=True) #add._menu.popup(view.mapToGlobal(QtCore.QPoint(0, 0))) view.show() app.exec_()
def pushValue(self, newValue): if newValue != self.getOldValue(): # push the command cmdUpdate = CmdSetParamDouble(self, float(newValue)) cmdManager = CommandManager() cmdManager.push(cmdUpdate)
def pushValue(self, value): if value != self.getOldValue(): # push the command cmdUpdate = CmdSetParamChoice(self, str(value)) cmdManager = CommandManager() cmdManager.push(cmdUpdate)
def createReaderNode(self, url, x, y): """ Creates a reader node when an image has been dropped in the graph. """ extension = url.split(".")[-1].lower() if extension in ['jpeg', 'jpg', 'jpe', 'jfif', 'jfi']: nodeType = 'tuttle.jpegreader' elif extension == 'png': nodeType = 'tuttle.pngreader' elif extension in [ 'mkv', 'mpeg', 'mp4', 'avi', 'mov', 'aac', 'ac3', 'adf', 'adx', 'aea', 'ape', 'apl', 'mac', 'bin', 'bit', 'bmv', 'cdg', 'cdxl', 'xl', '302', 'daud', 'dts', 'dv', 'dif', 'cdata', 'eac3', 'flm', 'flac', 'flv', 'g722', '722', 'tco', 'rco', 'g723_1', 'g729', 'gsm', 'h261', 'h26l', 'h264', '264', 'idf', 'cgi', 'latm', 'm4v', 'mjpg', 'mjpeg', 'mpo', 'mlp', 'mp2', 'mp3', 'm2a', 'mpc', 'mvi', 'mxg', 'v', 'nut', 'ogg', 'oma', 'omg', 'aa3', 'al', 'ul', 'sw', 'sb', 'uw', 'ub', 'yuv', 'cif', 'qcif', 'rgb', 'rt', 'rso', 'smi', 'sami', 'sbg', 'shn', 'vb', 'son', 'mjpg', 'sub', 'thd', 'tta', 'ans', 'art', 'asc', 'diz', 'ice', 'nfo', 'txt', 'vt', 'vc1', 'vqf', 'vql', 'vqe', 'vtt', 'yop', 'y4m' ]: nodeType = 'tuttle.ffmpegreader' elif extension in [ '3fr', 'ari', 'arw', 'bay', 'crw', 'cr2', 'cap', 'dng', 'dcs', 'dcr', 'dng', 'drf', 'eip', 'erf', 'fff', 'iiq', 'k25', 'kdc', 'mef', 'mos', 'mrw', 'nef', 'nrw', 'obm', 'orf', 'pef', 'ptx', 'pxn', 'r3d', 'rad', 'raf', 'rw2', 'raw', 'rwl', 'rwz', 'srf', 'sr2', 'srw', 'x3f' ]: nodeType = 'tuttle.rawreader' elif extension in [ 'aai', 'art', 'arw', 'avi', 'avs', 'bmp', 'bmp2', 'bmp3', 'cals', 'cgm', 'cin', 'cmyk', 'cmyka', 'cr2', 'crw', 'cur', 'cut', 'dcm', 'dcr', 'dcx', 'dib', 'djvu', 'dng', 'dot', 'dpx', 'emf', 'epdf', 'epi', 'eps', 'eps2', 'eps3', 'epsf', 'epsi', 'ept', 'exr', 'fax', 'fig', 'fits', 'fpx', 'gif', 'gplt', 'gray', 'hdr', 'hpgl', 'hrz', 'html', 'ico', 'info', 'inline', 'jbig', 'jng', 'jp2', 'jpc', 'jpg', 'jpeg', 'man', 'mat', 'miff', 'mono', 'mng', 'm2v', 'mpeg', 'mpc', 'mpr', 'mrw', 'msl', 'mtv', 'mvg', 'nef', 'orf', 'otb', 'p7', 'palm', 'pam', 'pbm', 'pcd', 'pcds', 'pcl', 'pcx', 'pdb', 'pdf', 'pef', 'pfa', 'pfb', 'pfm', 'pgm', 'picon', 'pict', 'pix', 'png', 'png8', 'png16', 'png32', 'pnm', 'ppm', 'ps', 'ps2', 'ps3', 'psb', 'psd', 'ptif', 'pwp', 'rad', 'rgb', 'rgba', 'rla', 'rle', 'sct', 'sfw', 'sgi', 'shtml', 'sid', 'mrsid', 'sun', 'svg', 'tga', 'tiff', 'tim', 'tif', 'txt', 'uil', 'uyvy', 'vicar', 'viff', 'wbmp', 'webp', 'wmf', 'wpg', 'x', 'xbm', 'xcf', 'xpm', 'xwd', 'x3f', 'ycbcr', 'ycbcra', 'yuv' ]: nodeType = 'tuttle.imagemagickreader' elif extension in [ 'bmp', 'cin', 'dds', 'dpx', 'exr', 'fits', 'hdr', 'ico', 'j2k', 'j2c', 'jp2', 'jpeg', 'jpg', 'jpe', 'jfif', 'jfi', 'pbm', 'pgm', 'png', 'pnm', 'ppm', 'pic', 'psd', 'rgbe', 'sgi', 'tga', 'tif', 'tiff', 'tpic', 'tx', 'webp' ]: nodeType = 'tuttle.oiioreader' else: logging.debug("Unknown format. Can't create reader node.") return #use exception ! # 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 = CommandManager() return cmdManager.push(cmdCreateReaderNode)
def pushValue(self, newValue): if newValue != self.getOldValue(): # Push the command cmdUpdate = CmdSetParamInt(self, int(newValue)) cmdManager = CommandManager() cmdManager.push(cmdUpdate)
def pushValue(self, value): # Push the command cmdUpdate = CmdSetParamBoolean(self, value) cmdManager = CommandManager() cmdManager.push(cmdUpdate)