示例#1
0
    def doOperationOnItem (self, name, parameters={}, description="", gtkLock=True):
        """
        @summary: Do operation on properties of item.
        @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)        
        
        count = 0
        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))
                
                for keyProperty, parameter in parameters.iteritems():
                    # 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 four parameters.
                    # item: pycamimg.core.CamItem, iter: GtkTreeIter, count: int, newValue.
                    valueProperty, functionProperty = parameter
                    if (functionProperty != None):
                        item.setProperty(keyProperty, functionProperty(item, iter, count, keyProperty, valueProperty))
                    else:
                        item.setProperty(keyProperty, valueProperty)
                    
                __log__.info("File %s done %s operation." % (file, name))
                self.updateItem(iter, item, updateImage=False, gtkLock=gtkLock)
                __log__.debug("File %s updated" % file)
            else:
                __log__.warning("Core does not have file %s" % file)
            
            count += 1
        
        if (iterOp != None):
            operations.removeOperation(iterOp)
示例#2
0
    def addTargetFiles(self,
                       files,
                       iter=None,
                       position=gtk.TREE_VIEW_DROP_AFTER,
                       gtkLock=True):
        """
        @summary: Add a file list into target view.
        @param files:  A list of files to add.
        @param iter: Iter that it will use as reference to insert new files.
        @param position: Position over iter.    
        @param gtkLock: True to do a lock on gtk loop.    
        """
        if (self.__core__ == None):
            __log__.debug("There is not a project in tabproject")
            return
        
        if (files != None):
            iNImages = len(files)
            __log__.debug("Adding new %d images" % iNImages)
            
            operations = RegOperations()
            iterOp = None
            if (operations != None):
                opData = operations.getDataOperation("AddImg",
                                                     _("Adding images..."),
                                                     iNImages)
                # Add new operation to operation treeview
                iterOp = operations.addOperation(opData)
                
            # Gets pixbuf file 
            icon = FactoryControls.getPixbufFromStock(gtk.STOCK_FILE)

            self.__addTargetFiles__(files, icon, iterOp,
                                    iter=iter, position=position,
                                    gtkLock=gtkLock)

            if (iterOp != None):
                operations.removeOperation(iterOp)
        else:
            __log__.debug("There are not files to insert")
示例#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)