Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Interactive Applications using Matplotlib

You're reading from   Interactive Applications using Matplotlib

Arrow left icon
Product type Paperback
Published in Mar 2015
Publisher
ISBN-13 9781783988846
Length 174 pages
Edition 1st Edition
Languages
Arrow right icon
Toc

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...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image