<div dir="ltr"><div class="markdown-here-wrapper" data-md-url="groups.google.com" id="markdown-here-wrapper-999072" data-md-original="Nadav%2C%C2%A0%3Cdiv%3E%3Cbr%3E%3C%2Fdiv%3E%3Cdiv%3EThe%20canvas%20itself%20is%20a%20%60matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg%60.%20%26nbsp%3BIf%20you%20wanted%2C%20you%20could%20subclass%20that%20class%20and%20provide%20your%20own%20%60mousePressEvent%60%20and%20friends.%20%26nbsp%3BSomething%20like%3A%3C%2Fdiv%3E%3Cdiv%3E%3Cbr%3E%3C%2Fdiv%3E%3Cdiv%3E%3C%2Fdiv%3E%3Cdiv%3E%60%60%60python%3C%2Fdiv%3E%3Cdiv%3Efrom%20matplotlib.backends.backend_qt4agg%20import%20FigureCanvasQTAgg%3C%2Fdiv%3E%3Cdiv%3Eimport%20matplotlib.pyplot%20as%20plt%3C%2Fdiv%3E%3Cdiv%3E%3Cspan%20style%3D%22line-height%3A%2018px%3B%22%3Efrom%20skimage%20import%20data%3C%2Fspan%3E%3C%2Fdiv%3E%3Cdiv%3E%0A%3Cp%20style%3D%22margin-bottom%3A%200px%3B%22%3E%3Cbr%3E%3C%2Fp%3E%3Cp%20style%3D%22margin-bottom%3A%200px%3B%22%3Eclass%20MyCanvas(FigureCanvasQtAgg)%3A%3C%2Fp%3E%3Cp%20style%3D%22margin-bottom%3A%200px%3B%22%3E%3Cbr%3E%3C%2Fp%3E%3Cp%20style%3D%22margin-bottom%3A%200px%3B%22%3E%26nbsp%3B%20%26nbsp%3B%20def%20mousePressEvent(self%2C%20event)%3A%3C%2Fp%3E%3Cp%20style%3D%22margin-bottom%3A%200px%3B%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20pass%3C%2Fp%3E%3Cp%20style%3D%22margin-bottom%3A%200px%3B%22%3E%3Cbr%3E%3C%2Fp%3E%3Cp%20style%3D%22margin-bottom%3A%200px%3B%22%3Edef%20main()%3A%3C%2Fp%3E%0A%3Cp%20style%3D%22margin-bottom%3A%200px%3B%22%3E%26nbsp%3B%20%26nbsp%3B%20image%20%3D%20data.camera()%3C%2Fp%3E%0A%3Cp%20style%3D%22margin-bottom%3A%200px%3B%22%3E%26nbsp%3B%20%26nbsp%3B%20f%2C%20ax%20%3D%20plt.subplots()%3C%2Fp%3E%3Cp%20style%3D%22margin-bottom%3A%200px%3B%22%3E%26nbsp%3B%20%26nbsp%3B%20f.canvas%20%3D%20MyCanvas()%3C%2Fp%3E%0A%3Cp%20style%3D%22margin-bottom%3A%200px%3B%22%3E%26nbsp%3B%20%26nbsp%3B%20ax.imshow(image%2C%20interpolation%3D'nearest')%3C%2Fp%3E%0A%3Cp%20style%3D%22margin-bottom%3A%200px%3B%22%3E%26nbsp%3B%20%26nbsp%3B%20h%2C%20w%20%3D%20image.shape%3C%2Fp%3E%0A%3Cp%20style%3D%22margin-bottom%3A%200px%3B%22%3E%26nbsp%3B%20%26nbsp%3B%20plt.show()%3C%2Fp%3E%3Cp%20style%3D%22margin-bottom%3A%200px%3B%22%3E%60%60%60%3C%2Fp%3E%3C%2Fdiv%3E%3Cdiv%3E%3Cp%20style%3D%22margin-bottom%3A%200px%3B%22%3E%3C%2Fp%3E%3C%2Fdiv%3E%3Cdiv%3E%3Cbr%3EOn%20Wednesday%2C%20December%2018%2C%202013%202%3A13%3A02%20AM%20UTC-6%2C%20Nadav%20Horesh%20wrote%3A%3Cblockquote%20class%3D%22gmail_quote%22%20style%3D%22margin%3A%200%3Bmargin-left%3A%200.8ex%3Bborder-left%3A%201px%20%23ccc%20solid%3Bpadding-left%3A%201ex%3B%22%3EI%0A%3Cbr%3EI%20started%20to%20build%20an%20interactive%20image%20exploration%20utility%20based%20on%0A%3Cbr%3Ematplotlib.%20%26nbsp%3BRecently%2C%20following%20a%20link%20on%20this%20list%2C%20I%20encountered%0A%3Cbr%3Eskimage.viewer%2C%20and%20found%20that%20the%20plugins%20architecture%20matches%20my%20needs.%0A%3Cbr%3EI%20could%20not%20find%20how%20to%20link%20keyboard%20and%20mouse%20events%20(and%20maybe%20buttons)%0A%3Cbr%3Eto%20plugins.%20Any%20suggestions%3F%0A%3Cbr%3E%0A%3Cbr%3EI%20am%20using%20version%200.93%20on%20linux%20(I%20can%20install%20the%20pre%200.10%2C%20if%20needed)%0A%3Cbr%3E%0A%3Cbr%3E%26nbsp%3BThanks%2C%0A%3Cbr%3E%0A%3Cbr%3E%26nbsp%3B%20%26nbsp%3B%20Nadav%0A%3Cbr%3E%3C%2Fblockquote%3E%3C%2Fdiv%3E" style="font-size: 1em; font-family: Helvetica, arial, freesans, clean, sans-serif; color: rgb(34, 34, 34); background-color: rgb(255, 255, 255); border: none; line-height: 1.2;"><p style="margin: 1em 0px;">Nadav, </p>
<p style="margin: 1em 0px;">The canvas itself is a <code style="font-size: 0.85em; font-family: Consolas, Inconsolata, Courier, monospace;margin: 0px 0.15em; padding: 0px 0.3em; white-space: nowrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; display: inline;">matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg</code>.  If you wanted, you could subclass that class and provide your own <code style="font-size: 0.85em; font-family: Consolas, Inconsolata, Courier, monospace;margin: 0px 0.15em; padding: 0px 0.3em; white-space: nowrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; display: inline;">mousePressEvent</code> and friends.  Something like:</p>
<pre style="font-size: 0.85em; font-family: Consolas, Inconsolata, Courier, monospace;font-size: 1em; line-height: 1.2em; overflow: auto;margin: 1em 0px;"><code class="language-python" style="font-size: 0.85em; font-family: Consolas, Inconsolata, Courier, monospace;margin: 0px 0.15em; padding: 0px 0.3em; white-space: nowrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; display: inline;white-space: pre; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; border: 1px solid rgb(204, 204, 204); padding: 0.5em 0.7em;display: block; padding: 0.5em; color: rgb(51, 51, 51); background-color: rgb(248, 248, 255); background-position: initial initial; background-repeat: initial initial;"><span class="keyword" style="color: rgb(51, 51, 51); font-weight: bold;">from</span> matplotlib.backends.backend_qt4agg <span class="keyword" style="color: rgb(51, 51, 51); font-weight: bold;">import</span> FigureCanvasQTAgg
<span class="keyword" style="color: rgb(51, 51, 51); font-weight: bold;">import</span> matplotlib.pyplot <span class="keyword" style="color: rgb(51, 51, 51); font-weight: bold;">as</span> plt
<span class="keyword" style="color: rgb(51, 51, 51); font-weight: bold;">from</span> skimage <span class="keyword" style="color: rgb(51, 51, 51); font-weight: bold;">import</span> data


<span class="class" style="color: rgb(68, 85, 136); font-weight: bold;"><span class="keyword" style="color: rgb(51, 51, 51); font-weight: bold;">class</span> <span class="title" style="color: rgb(153, 0, 0); font-weight: bold;color: rgb(68, 85, 136); font-weight: bold;">MyCanvas</span><span class="params">(FigureCanvasQtAgg)</span>:</span>

    <span class="function"><span class="keyword" style="color: rgb(51, 51, 51); font-weight: bold;">def</span> <span class="title" style="color: rgb(153, 0, 0); font-weight: bold;">mousePressEvent</span><span class="params">(self, event)</span>:</span>
        <span class="keyword" style="color: rgb(51, 51, 51); font-weight: bold;">pass</span>

<span class="function"><span class="keyword" style="color: rgb(51, 51, 51); font-weight: bold;">def</span> <span class="title" style="color: rgb(153, 0, 0); font-weight: bold;">main</span><span class="params">()</span>:</span> 
    image = data.camera() 
    f, ax = plt.subplots()
    f.canvas = MyCanvas() 
    ax.imshow(image, interpolation=<span class="string" style="color: rgb(221, 17, 68);">'nearest'</span>) 
    h, w = image.shape 
    plt.show()</code></pre>
<p style="margin: 1em 0px;">On Wednesday, December 18, 2013 2:13:02 AM UTC-6, Nadav Horesh wrote:</p>
<p style="margin: 1em 0px;"></p><div class="markdown-here-exclude"><p></p><blockquote class="gmail_quote" style="margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">I
<br>I started to build an interactive image exploration utility based on
<br>matplotlib.  Recently, following a link on this list, I encountered
<br>skimage.viewer, and found that the plugins architecture matches my needs.
<br>I could not find how to link keyboard and mouse events (and maybe buttons)
<br>to plugins. Any suggestions?
<br>
<br>I am using version 0.93 on linux (I can install the pre 0.10, if needed)
<br>
<br> Thanks,
<br>
<br>    Nadav
<br></blockquote><p></p></div><p style="margin: 1em 0px;"></p>
</div></div>