3.4. MyConfiguration

MyConfiguration is a class which contains methods (functions) that return sets of bindings. Each method corresponds to a different screen or window area. For example, defaultAllDecor() registers bindings for all window decorations, and root() registers bindings for your root window (AKA desktop).

The MyConfiguration class itself contains no such code for registering bindings; it is rather dumb. Instead, you pass an instance of MyConfiguration to the install function (remember him? :). This is done near the bottom of userconfig.py.

Some things to note about MyConfiguration:

Most of your bindings will probably go into either globalKeyBindings() (for global bindings), or defaultAllWindows() (for window bindings). As previously mentioned, all of these methods return sets of bindings. A set in vague terms just means a list or array of things. In Python, it would be either a list or a tuple. The default uses lists, since they are easier for beginners to use (tuples have weird syntax when they only contain zero or one items). A list is just some square brackets, with items inside, delimited by commas. A simple Python list would be [1,2,3,4].

Now, with that in mind, we're going to set up some bindings, using what we learned previously about bindings and events and actions and whatnot. We will set up the following bindings:

The first item is a root window binding. So what we do is have the root() method in MyConfiguration return this binding:

def root(self):
  """
  The stuff in these quotes is inline documentation, AKA a "docstring."
  It does not affect your code at all.  You can delete it if it isn't
  useful to you.
  """
  # this is a comment

  # now here is our double click aterm!
  return [ (DoubleClick("Button1"), "{aterm}") ]

Ok, that wasn't bad. Now onto the Super + M mazimize binding. This is a window binding, so it goes into defaultAllWindows().

def defaultAllWindows(self):
  return [ (KeyPress(Super, "M"), "Mazimize") ]

Pretty similar to the last one. Now let's do two at once.

def globalKeyBindings(self):
return [

  # Indentation is important in Python, but once we type an opening
  # brace or parentheses, we can pretty much indent stuff however
  # we want.

  (KeyPress(Ctrl+Alt, "Z"), "{mozilla}"),  # If you have more than one binding,
                                           # always remember the commas in between!  

  (KeyPress(C+A, "g"), "{gimp}")           # C is an alias for Ctrl, and A is an alias
                                           # for Alt (remember? :). capitalization of the
                                           # key names doesn't matter.  G == g

] # we are free to put the ending bracket pretty much anywhere