Chapter 10 - A Simple Package
This first example will show how to create a package that defines some key bindings and creates a custom personal menu. You will not need to edit a .rvrc.mu file to do this as in previous versions.We’ll be creating a package intended to keep all our personal customizations. To start with we’ll need to make a Mu module that implements a new mode. At first won’t do anything at all: just load at start up. Put the following in to a file called mystuff.mu.
use rvtypes;
use extra_commands;
use commands;
module: mystuff {
class: MyStuffMode : MinorMode
{
method: MyStuffMode (MyStuffMode;)
{
init("mystuff-mode",
nil,
nil,
nil);
}
}
\: createMode (Mode;)
{
return MyStuffMode();
}
} // end module
Now we need to create a PACKAGE file in the same directory before we can create the package zip file. It should look like this:
package: My Stuff
author: M. VFX Artiste
version: 1.0
rv: 3.6
requires: ''
modes:
- file: mystuff
load: immediate
description: |
<p>M. VFX Artiste's Personal RV Customizations</p>
Assuming both files are in the same directory, we create the zip file using this command from the shell:
shell> zip mystuff-1.0.rvpkg PACKAGE mystuff.mu
The file mystuff-1.0.rvpkg should have been created. Now start RV, open the preferences package pane and add the mystuff-1.0.rvpkg package. You should now be able to install it. Make sure the package is both installed and loaded in your home directory’s RV support directory so it’s private to you.At this point, we’ll edit the installed Mu file directly so we can see results faster. When we have something we like, we’ll copy it back to the original mystuff.mu and make the rvpkg file again with the new code. Be careful not to uninstall the mystuff package while we’re working on it or our changes will be lost. Alternately, for the more paranoid (and wiser), we could edit the file elsewhere and simply copy it onto the installed file.To start with let’s add two functions on the ``<’’ and ``>’’ keys to speed up and slow down the playback by increasing and decreasing the FPS. There are two main this we need to do: add two method to the class which implement speeding up and slowing down, and bind those functions to the keys.First let’s add the new methods after the class constructor MyStuffMode() along with two global bindings to the ``<’’ and ``>’’ keys. The class definition should now look like this:
...
class: MyStuffMode : MinorMode
{
method: MyStuffMode (MyStuffMode;)
{
init("mystuff-mode",
[("key-down-->", faster, "speed up fps"),
("key-down--<", slower, "slow down fps")],
nil,
nil);
}
method: faster (void; Event event)
{
setFPS(fps() \* 1.5);
displayFeedback("%g fps" % fps());
}
method: slower (void; Event event)
{
setFPS(fps() \* 1.0/1.5);
displayFeedback("%g fps" % fps());
}
}
The bindings are created by passing a list of tuples to the init function. Each tuple contains three elements: the event name to bind to, the function to call when it is activated, and a single line description of what it does. In Mu a tuple is formed by putting parenthesis around comma separated elements. A list is formed by enclosing its elements in square brackets. So a list of tuples will have the form:
[ (...), (...), ... ]
Where the ``…’’ means ``and so on’’. The first tuple in our list of bindings is:
(key-down-->, faster, speed up fps)
So the event in this case is key-down–> which means the point at which the > key is pressed. The symbol faster is referring to the method we declared above. So faster will be called whenever the key is pressed. Similarily we bind slower (from above as well) to key-down–<.
("key-down--<", slower, "slow down fps")
And to put them in a list requires enclose the two of them in square brackets:
[("key-down-->", faster, "speed up fps"),
("key-down--<", slower, "slow down fps")]
To add more bindings you create more methods to bind and add additional tuples to the list.The python version of above looks like this:
from rv.rvtypes import *
from rv.commands import *
from rv.extra_commands import *
class PyMyStuffMode(MinorMode):
def __init__(self):
MinorMode.__init__(self)
self.init("py-mystuff-mode",
[ ("key-down-->", self.faster, "speed up fps"),
("key-down--<", self.slower, "slow down fps") ],
None,
None)
def faster(self, event):
setFPS(fps() * 1.5)
displayFeedback("%g fps" % fps(), 2.0);
def slower(self, event):
setFPS(fps() * 1.0/1.5)
displayFeedback("%g fps" % fps(), 2.0);
def createMode():
return PyMyStuffMode()
10.3 Finishing up
Finally, we’ll create the final rvpkg package by copying mystuff.mu back to our temporary directory with the PACKAGES file where we originally made the rvpkg file.Next start RV and uninstall and remove the mystuff package so it no longer appears in the package manager UI. Once you’ve done this recreate the rvpkg file from scratch with the new mystuff.mu file and the PACKAGES file:
shell> zip mystuff-1.0.rvpkg PACKAGES mystuff.mu
or if you’re using python:
shell> zip mystuff-1.0.rvpkg PACKAGES mystuff.py
You can now add the latest mysuff-1.0.rvpkg file back to RV and use it. In the future add personal customizations directly to this package and you’ll always have a single file you can install to customize RV.