From: <pki...@us...> - 2008-07-25 05:01:23
|
Revision: 5866 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5866&view=rev Author: pkienzle Date: 2008-07-25 05:01:18 +0000 (Fri, 25 Jul 2008) Log Message: ----------- mouse wheel support for tk backend Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/backends/backend_tkagg.py Modified: trunk/matplotlib/lib/matplotlib/backends/backend_tkagg.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backends/backend_tkagg.py 2008-07-25 03:55:16 UTC (rev 5865) +++ trunk/matplotlib/lib/matplotlib/backends/backend_tkagg.py 2008-07-25 05:01:18 UTC (rev 5866) @@ -164,10 +164,19 @@ self._tkcanvas.bind("<KeyRelease>", self.key_release) for name in "<Button-1>", "<Button-2>", "<Button-3>": self._tkcanvas.bind(name, self.button_press_event) - for name in "<ButtonRelease-1>", "<ButtonRelease-2>", "<ButtonRelease-3>": self._tkcanvas.bind(name, self.button_release_event) + # Mouse wheel on Linux generates button 4/5 events + for name in "<Button-4>", "<Button-5>": + self._tkcanvas.bind(name, self.scroll_event) + # Mouse wheel for windows goes to the window with the focus. + # Since the canvas won't usually have the focus, bind the + # event to the window containing the canvas instead. + # See http://wiki.tcl.tk/3893 (mousewheel) for details + root = self._tkcanvas.winfo_toplevel() + root.bind("<MouseWheel>", self.scroll_event_windows) + self._master = master self._tkcanvas.focus_set() @@ -265,6 +274,26 @@ FigureCanvasBase.button_release_event(self, x, y, num, guiEvent=event) + def scroll_event(self, event): + x = event.x + y = self.figure.bbox.height - event.y + num = getattr(event, 'num', None) + if num==4: step = -1 + elif num==5: step = +1 + else: step = 0 + + FigureCanvasBase.scroll_event(self, x, y, step, guiEvent=event) + + def scroll_event_windows(self, event): + """MouseWheel event processor""" + # need to find the window that contains the mouse + w = event.widget.winfo_containing(event.x_root, event.y_root) + if w == self._tkcanvas: + x = event.x_root - w.winfo_rootx() + y = event.y_root - w.winfo_rooty() + step = event.delta/120. + FigureCanvasBase.scroll_event(self, x, y, step, guiEvent=event) + def _get_key(self, event): val = event.keysym_num if self.keyvald.has_key(val): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pki...@us...> - 2008-07-25 06:30:54
|
Revision: 5867 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5867&view=rev Author: pkienzle Date: 2008-07-25 06:30:52 +0000 (Fri, 25 Jul 2008) Log Message: ----------- tk mouse wheel: y values start from the top of the screen Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/backends/backend_tkagg.py Modified: trunk/matplotlib/lib/matplotlib/backends/backend_tkagg.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backends/backend_tkagg.py 2008-07-25 05:01:18 UTC (rev 5866) +++ trunk/matplotlib/lib/matplotlib/backends/backend_tkagg.py 2008-07-25 06:30:52 UTC (rev 5867) @@ -291,6 +291,7 @@ if w == self._tkcanvas: x = event.x_root - w.winfo_rootx() y = event.y_root - w.winfo_rooty() + y = self.figure.bbox.height - y step = event.delta/120. FigureCanvasBase.scroll_event(self, x, y, step, guiEvent=event) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lee...@us...> - 2010-01-11 19:54:40
|
Revision: 8077 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8077&view=rev Author: leejjoon Date: 2010-01-11 19:54:32 +0000 (Mon, 11 Jan 2010) Log Message: ----------- Tk backend supports Figure.set_size_inches with the forward parameter. Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/backends/backend_tkagg.py Modified: trunk/matplotlib/lib/matplotlib/backends/backend_tkagg.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backends/backend_tkagg.py 2010-01-11 19:23:13 UTC (rev 8076) +++ trunk/matplotlib/lib/matplotlib/backends/backend_tkagg.py 2010-01-11 19:54:32 UTC (rev 8077) @@ -367,11 +367,24 @@ self.canvas.figure.show = lambda *args: self.show() - def resize(self, event): - width, height = event.width, event.height - self.toolbar.configure(width=width) # , height=height) + def resize(self, width, height=None): + # before 09-12-22, the resize method takes a single *event* + # parameter. On the other hand, the resize method of other + # FigureManager class takes *width* and *height* parameter, + # which is used to change the size of the window. For the + # Figure.set_size_inches with forward=True work with Tk + # backend, I changed the function signature but tried to keep + # it backward compatible. -JJL + # when a single parameter is given, consider it as a event + if height is None: + width = width.width + else: + self.canvas._tkcanvas.master.geometry("%dx%d" % (width, height)) + self.toolbar.configure(width=width) + + def show(self): """ this function doesn't segfault but causes the This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ry...@us...> - 2010-04-20 19:43:07
|
Revision: 8254 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8254&view=rev Author: ryanmay Date: 2010-04-20 19:43:01 +0000 (Tue, 20 Apr 2010) Log Message: ----------- Add TimerTk and new_timer() method. Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/backends/backend_tkagg.py Modified: trunk/matplotlib/lib/matplotlib/backends/backend_tkagg.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backends/backend_tkagg.py 2010-04-20 19:42:29 UTC (rev 8253) +++ trunk/matplotlib/lib/matplotlib/backends/backend_tkagg.py 2010-04-20 19:43:01 UTC (rev 8254) @@ -13,7 +13,7 @@ import matplotlib from matplotlib.cbook import is_string_like from matplotlib.backend_bases import RendererBase, GraphicsContextBase, \ - FigureManagerBase, FigureCanvasBase, NavigationToolbar2, cursors + FigureManagerBase, FigureCanvasBase, NavigationToolbar2, cursors, TimerBase from matplotlib.figure import Figure from matplotlib._pylab_helpers import Gcf @@ -95,6 +95,42 @@ return figManager +class TimerTk(TimerBase): + ''' + Subclass of :class:`backend_bases.TimerBase` that uses Tk's timer events. + + Attributes: + * interval: The time between timer events in milliseconds. Default + is 1000 ms. + * single_shot: Boolean flag indicating whether this timer should + operate as single shot (run once and then stop). Defaults to False. + * callbacks: Stores list of (func, args) tuples that will be called + upon timer events. This list can be manipulated directly, or the + functions add_callback and remove_callback can be used. + ''' + def __init__(self, parent): + TimerBase.__init__(self) + self.parent = parent + + def _timer_start(self): + self._timer = self.parent.after(self._interval, self._on_timer) + + def _timer_stop(self): + if self._timer is not None: + self.parent.after_cancel(self._timer) + self._timer = None + + def _on_timer(self): + TimerBase._on_timer(self) + + # Tk after() is only a single shot, so we need to add code here to + # reset the timer if we're not operating in single shot mode. + if not self._single and len(self.callbacks) > 0: + self._timer = self.parent.after(self._interval, _self._on_timer) + else: + self._timer = None + + class FigureCanvasTkAgg(FigureCanvasAgg): keyvald = {65507 : 'control', 65505 : 'shift', @@ -322,6 +358,14 @@ key = self._get_key(event) FigureCanvasBase.key_release_event(self, key, guiEvent=event) + def new_timer(self): + """ + Creates a new backend-specific subclass of + :class:`backend_bases.TimerBase`. This is useful for getting periodic + events through the backend's native event loop. + """ + return TimerTk() + def flush_events(self): self._master.update() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ef...@us...> - 2010-06-12 22:08:23
|
Revision: 8420 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8420&view=rev Author: efiring Date: 2010-06-12 22:08:16 +0000 (Sat, 12 Jun 2010) Log Message: ----------- backend_tkagg: show() gets an experimental kwarg for testing blocking mode. By default, the behavior of show() is unchanged--it does not block, and it forces interactive mode on. show(block=True) is intended to make it behave the same as in the other common backends, blocking until all figures have been closed. Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/backends/backend_tkagg.py Modified: trunk/matplotlib/lib/matplotlib/backends/backend_tkagg.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backends/backend_tkagg.py 2010-06-12 21:30:38 UTC (rev 8419) +++ trunk/matplotlib/lib/matplotlib/backends/backend_tkagg.py 2010-06-12 22:08:16 UTC (rev 8420) @@ -3,17 +3,20 @@ from __future__ import division import os, sys, math +import os.path import Tkinter as Tk, FileDialog -import tkagg # Paint image to Tk photo blitter extension -from backend_agg import FigureCanvasAgg -import os.path +# Paint image to Tk photo blitter extension +import import matplotlib.backends.tkagg as tkagg +from matplotlib.backends.backend_agg import FigureCanvasAgg + import matplotlib from matplotlib.cbook import is_string_like -from matplotlib.backend_bases import RendererBase, GraphicsContextBase, \ - FigureManagerBase, FigureCanvasBase, NavigationToolbar2, cursors, TimerBase +from matplotlib.backend_bases import RendererBase, GraphicsContextBase +from matplotlib.backend_bases import FigureManagerBase, FigureCanvasBase, +from matplotlib.backend_bases import NavigationToolbar2, cursors, TimerBase from matplotlib.figure import Figure from matplotlib._pylab_helpers import Gcf @@ -61,25 +64,43 @@ figManager.show() -def show(): +def show(block=False): """ - Show all the figures and enter the gtk mainloop + Show all figures. - This should be the last line of your script. This function sets - interactive mode to True, as detailed on - http://matplotlib.sf.net/interactive.html + Temporary, experimental kwarg *block* defaults to False to + provide the behavior present throughout mpl history to date: + interactive mode is forced on, and show does not block. + + Set *block* to True to test the proposed new behavior, + consistent with other backends, in which show does not affect + interactive mode, and always blocks until all figures are closed. + In addition, the rcParam['tk.pythoninspect'] is ignored. + + Use this kwarg only for testing; other backends do not accept + a kwarg to show, and might never do so. """ for manager in Gcf.get_all_fig_managers(): manager.show() - import matplotlib - matplotlib.interactive(True) - if rcParams['tk.pythoninspect']: - os.environ['PYTHONINSPECT'] = '1' - if show._needmain: + if block: + # proposed new behavior; seems to make this backend consistent + # with others, with no drawbacks identified yet. Tk.mainloop() - show._needmain = False -show._needmain = True + else: + # long-time behavior: non-blocking, forces interactive mode + import matplotlib + matplotlib.interactive(True) + if rcParams['tk.pythoninspect']: + os.environ['PYTHONINSPECT'] = '1' + if show._needmain: + Tk.mainloop() + show._needmain = False +show._needmain = True # This can go away if we eliminate block=False option. + + + + def new_figure_manager(num, *args, **kwargs): """ Create a new figure manager instance @@ -98,7 +119,7 @@ class TimerTk(TimerBase): ''' Subclass of :class:`backend_bases.TimerBase` that uses Tk's timer events. - + Attributes: * interval: The time between timer events in milliseconds. Default is 1000 ms. @@ -213,7 +234,7 @@ root = self._tkcanvas.winfo_toplevel() root.bind("<MouseWheel>", self.scroll_event_windows) - # Can't get destroy events by binding ot _tkcanvas. Therefore, bind + # Can't get destroy events by binding to _tkcanvas. Therefore, bind # to the window and filter. def filter_destroy(evt): if evt.widget is self._tkcanvas: @@ -363,9 +384,9 @@ Creates a new backend-specific subclass of :class:`backend_bases.Timer`. This is useful for getting periodic events through the backend's native event loop. Implemented only for backends with GUIs. - + optional arguments: - + *interval* Timer interval in milliseconds *callbacks* @@ -449,17 +470,15 @@ this function doesn't segfault but causes the PyEval_RestoreThread: NULL state bug on win32 """ - - def destroy(*args): - self.window = None - Gcf.destroy(self._num) - - if not self._shown: self.canvas._tkcanvas.bind("<Destroy>", destroy) _focus = windowing.FocusManager() if not self._shown: + def destroy(*args): + self.window = None + Gcf.destroy(self._num) + self.canvas._tkcanvas.bind("<Destroy>", destroy) self.window.deiconify() # anim.py requires this - if sys.platform=='win32' : self.window.update() + self.window.update() else: self.canvas.draw_idle() self._shown = True This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ef...@us...> - 2010-06-12 22:32:24
|
Revision: 8421 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8421&view=rev Author: efiring Date: 2010-06-12 22:32:18 +0000 (Sat, 12 Jun 2010) Log Message: ----------- backend_tkagg: fix major typo from last commit Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/backends/backend_tkagg.py Modified: trunk/matplotlib/lib/matplotlib/backends/backend_tkagg.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backends/backend_tkagg.py 2010-06-12 22:08:16 UTC (rev 8420) +++ trunk/matplotlib/lib/matplotlib/backends/backend_tkagg.py 2010-06-12 22:32:18 UTC (rev 8421) @@ -8,7 +8,7 @@ import Tkinter as Tk, FileDialog # Paint image to Tk photo blitter extension -import import matplotlib.backends.tkagg as tkagg +import matplotlib.backends.tkagg as tkagg from matplotlib.backends.backend_agg import FigureCanvasAgg This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ef...@us...> - 2010-06-12 23:08:17
|
Revision: 8422 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8422&view=rev Author: efiring Date: 2010-06-12 23:08:11 +0000 (Sat, 12 Jun 2010) Log Message: ----------- backend_tkagg: one more typo from commit before last Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/backends/backend_tkagg.py Modified: trunk/matplotlib/lib/matplotlib/backends/backend_tkagg.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backends/backend_tkagg.py 2010-06-12 22:32:18 UTC (rev 8421) +++ trunk/matplotlib/lib/matplotlib/backends/backend_tkagg.py 2010-06-12 23:08:11 UTC (rev 8422) @@ -15,7 +15,7 @@ import matplotlib from matplotlib.cbook import is_string_like from matplotlib.backend_bases import RendererBase, GraphicsContextBase -from matplotlib.backend_bases import FigureManagerBase, FigureCanvasBase, +from matplotlib.backend_bases import FigureManagerBase, FigureCanvasBase from matplotlib.backend_bases import NavigationToolbar2, cursors, TimerBase from matplotlib.figure import Figure This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ef...@us...> - 2010-10-10 20:30:43
|
Revision: 8739 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8739&view=rev Author: efiring Date: 2010-10-10 20:30:37 +0000 (Sun, 10 Oct 2010) Log Message: ----------- backend_tkagg: delete dead code Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/backends/backend_tkagg.py Modified: trunk/matplotlib/lib/matplotlib/backends/backend_tkagg.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backends/backend_tkagg.py 2010-10-09 01:15:06 UTC (rev 8738) +++ trunk/matplotlib/lib/matplotlib/backends/backend_tkagg.py 2010-10-10 20:30:37 UTC (rev 8739) @@ -213,18 +213,6 @@ self._master = master self._tkcanvas.focus_set() - # a dict from func-> cbook.Scheduler threads - self.sourced = dict() - - # call the idle handler - def on_idle(*ignore): - self.idle_event() - return True - - # disable until you figure out how to handle threads and interrupts - #t = cbook.Idle(on_idle) - #self._tkcanvas.after_idle(lambda *ignore: t.start()) - def resize(self, event): width, height = event.width, event.height if self._resize_callback is not None: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ry...@us...> - 2011-01-12 03:18:08
|
Revision: 8905 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8905&view=rev Author: ryanmay Date: 2011-01-12 03:18:02 +0000 (Wed, 12 Jan 2011) Log Message: ----------- Prevent double start of timer. Thanks to Michiel de Hoon for finding the problem. Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/backends/backend_tkagg.py Modified: trunk/matplotlib/lib/matplotlib/backends/backend_tkagg.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backends/backend_tkagg.py 2011-01-12 01:16:17 UTC (rev 8904) +++ trunk/matplotlib/lib/matplotlib/backends/backend_tkagg.py 2011-01-12 03:18:02 UTC (rev 8905) @@ -101,8 +101,10 @@ def __init__(self, parent, *args, **kwargs): TimerBase.__init__(self, *args, **kwargs) self.parent = parent + self._timer = None def _timer_start(self): + self._timer_stop() self._timer = self.parent.after(self._interval, self._on_timer) def _timer_stop(self): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |