Example #1
0
 def initialize(self):
     """
     @summary: Initialize plugin.
     """
     from DateOperation import Operation
     from DateOperation.Operation import Rotate
     gettext.bindtextdomain(camimgpluginName, __LOCALE_FOLDER__)
     Operations.addOperation(Operation.OPERATION, Rotate)
Example #2
0
    def load(fi):
        """
        @summary: Load item from a file.
        @param fi: File where item is saved.
        @return: item loaded. 
        """
        path = cPickle.load(fi)
        target = cPickle.load(fi)
        length = cPickle.load(fi)
        item = CamItem(path, target)

        while length > 0:
            keyOp = cPickle.load(fi)
            parameters = cPickle.load(fi)
            classname = Operations.getOperation(name)
            op = classname(keyOp, parameters)
            item.addOperation(keyOp, op)
            length -= 1

        __log__.debug("Item %s saved." % self.__path__)

        return item
Example #3
0
    def doOperation (self, name, parameters={}, description="", gtkLock=True):
        """
        @summary: Do operation on selected items.
        @param name: New size for images.
        @param parameters: Dictionary with parameters and their values.
        @param description: Description of operation. 
        @param gtkLock: True to do a lock on gtk loop.
        """      
        __log__.debug("Begin %s operation..." % name)
        paths = self.getSelection()
        if (paths == None):
            __log__.error("It can not recover tree selection. Abort %s operation." % name)
            return
        iNImages = len(paths)
        __log__.debug("Images to %s: %d" % (name, iNImages))
        
        iterOp = None
        operations = RegOperations()
        if (operations != None):
            opData = operations.getDataOperation(name, description, iNImages)
            iterOp = operations.addOperation(opData)        
        
        for path in paths:
            __log__.debug("Do %s on %s" % (name, path))
            if (iterOp != None):
                operations.stepOperation(iterOp)
            # Add selected files from files TreeView
            iter = self.__model__.get_iter(path)
            if (iter != None):
                file = self.__model__.get_value(iter, self.COLUMN_SOURCE)
            else:
                __log__.warn("It can not recover an iter from path %s. Skip it" % path)
                continue

            item = self.__core__.getItem(file)
            if (item != None):
                __log__.debug("Get item %s from file %s" % (item, file))
                op = item.getOperation(name)
                if (op == None):
                    classname = Operations.getOperation(name)
                    op = classname()
                    item.addOperation(name, op)
                
                if (op != None):
                    # the value of dictionary is a tuple that contains, new value
                    # and a callback to do before assignment. (newValue, callback)
                    # callback must be return new value, and accept two parameters.
                    # old value and new value.
                    for keyParam, tupleParam in parameters.iteritems():
                        valueParam, callbackParam = tupleParam
                        oldValue = op.getParameter(keyParam)
                        if ((callbackParam != None) and (oldValue != None)):
                            op.setParameter(keyParam, callbackParam(oldValue, valueParam))
                        else:
                            op.setParameter(keyParam, valueParam)
                    
                __log__.info("File %s done %s operation." % (file, name))
                self.updateItem(iter, item, gtkLock=gtkLock)
                __log__.debug("File %s updated" % file)
            else:
                __log__.warning("Core does not have file %s" % file)
        
        if (iterOp != None):
            operations.removeOperation(iterOp)