Keymapping
We can see that our application is going to grow in complexity very soon add we continue to add features. Our current manner of keymapping is probably not going to be easily maintainable as the number of actions increase. Let's take a moment to implement something better. The most essential feature of a keymap is to tie a predefined action to an arbitrary key or key combination. This seems like the perfect job for a dictionary. Furthermore, as the keymap grows, it will become important to be able to display the keymap in a helpful manner to your users. Each key/action pair will need to come with a description that can later be displayed on demand. Also, keeping in mind that our ControlSys
class is likely to grow in complexity soon, let's implement this keymap feature as a separate class that ControlSys
will inherit. The code is as follows:
Source: chp2/stormcell_anim_with_keymap.py
class KeymapControl: def __init__(self, fig): self.fig = fig # Deactivate the...