Adding Your Own Modules to Métamorphose 2

Adding Your Own Modules to Métamorphose 2

With Métamorphose 2, you can make your own modules and have them appear as operations in the -Renamer- panel. This is usefull if you have some specific renaming requirements that are not implemented in Métamorphose, while still allowing you to use the full capabilities of the renaming engine. Indeed, any functionality already present can be intergrated into your custom module.

Note: All steps documented here are already made for you, including the example module.
Just uncomment the lines described here and you're good to go.



First step is to create the 'YourModuleName.py' file containing a wx.Panel class with the GUI stuff and the renaming operation.
You should save it in the 'operations/' directory.
You will need to import utils for the renaming to work.

Your panel class should be called 'OpPanel' otherwise it will not work properly.
Your panel should be initialised like so:

def __init__(self, parent, main_window):
    global main
    main = main_window 
    global parent
    parent = prnt    
    self.opsApply = [parent.applyName.GetValue(),
                     parent.applyExtension.GetValue()]
To rename, you must make a function in your panel class that has these characteristics:
# the renaming function
def renameItem(self, path, name, ext, original):
    newName = utils.joinExt(self.opsApply,name,ext)
    if not newName:
        return path,name,ext
        
    #== your code START ====================#
        
    newName = u"it worked"
    
    #== your code END ======================#
        
    # apply to name and/or ext
    name,ext = utils.splitExt(self.opsApply,newName,name,ext)
    
    return path, name, ext
path is the path as returned by os.path.split()[0].
name is the name as returned by os.path.split()[1].
ext is the file extension.
original is the full path name of the item, before any renaming operations.

newName will be either name or name+'.'+ext

Input will all be in Unicode, you MUST output to Unicode!


If you want to have autopreview, link the following function to an event (or function) you wish to trigger a preview action:

# make event a wx.Event or an integer value of 1 or 0
main.showPreview(event)


OK, now to add your module to the application.

First step is to import YourModuleName in 'operations/__init__.py'.

Still in __init__.py, add your module's information to the defs dictionary as follows:
The key is the name of the operation as you want it to appear to the user, the value is a tuple, the first value is the name of the module, the second is a description that appears to the user.
The _() wrapper is for the GETTEXT translation system.

_(u"your module") : (u"YourModuleName", _(u"Your module's description"))

That's it, I'll take care of the rest ;-)



Thou shall not enslave my free program!
Remember, Métamorphose is licensed under GNU-GPL v3, so if you plan to distribute any modules you make, they must be released under the same license. Personal or organization-internal modifications or additions are exempt from this.
See 'License' in the 'About' dialog for full legal information.

If you would like me to include your module in the main Métamorphose2 distribution, let me know.
Infinite fame and glory surely await those that do.


Ianaré Sévi
ianare@gmail.com



This document is released under the GNU Free Documentation License v1.2.
Last modified: 2007-09-01 20:17:17