SF.net SVN: matplotlib:[8441] trunk/matplotlib/lib/matplotlib

2010-06-19 Thread efiring
Revision: 8441
  http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8441&view=rev
Author:   efiring
Date: 2010-06-19 23:46:47 + (Sat, 19 Jun 2010)

Log Message:
---
[1530104, 3017380] slider grabs mouse; patch by C. Gohlke and baxissimo

Modified Paths:
--
trunk/matplotlib/lib/matplotlib/backend_bases.py
trunk/matplotlib/lib/matplotlib/widgets.py

Modified: trunk/matplotlib/lib/matplotlib/backend_bases.py
===
--- trunk/matplotlib/lib/matplotlib/backend_bases.py2010-06-17 17:45:38 UTC 
(rev 8440)
+++ trunk/matplotlib/lib/matplotlib/backend_bases.py2010-06-19 23:46:47 UTC 
(rev 8441)
@@ -1122,7 +1122,10 @@
 return
 
 # Find all axes containing the mouse
-axes_list = [a for a in self.canvas.figure.get_axes() if 
a.in_axes(self)]
+if self.canvas.mouse_grabber is None:
+axes_list = [a for a in self.canvas.figure.get_axes() if 
a.in_axes(self)]
+else:
+axes_list = [self.canvas.mouse_grabber]
 
 if len(axes_list) == 0: # None found
 self.inaxes = None
@@ -1332,6 +1335,7 @@
 self._lastx, self._lasty = None, None
 self.button_pick_id = self.mpl_connect('button_press_event',self.pick)
 self.scroll_pick_id = self.mpl_connect('scroll_event',self.pick)
+self.mouse_grabber = None # the axes currently grabbing mouse
 
 if False:
 ## highlight the artists that are hit
@@ -1610,6 +1614,26 @@
 event = IdleEvent(s, self, guiEvent=guiEvent)
 self.callbacks.process(s, event)
 
+def grab_mouse(self, ax):
+"""
+Set the child axes which are currently grabbing the mouse events.
+Usually called by the widgets themselves.
+It is an error to call this if the mouse is already grabbed by
+another axes.
+"""
+if self.mouse_grabber not in (None, ax):
+raise RuntimeError('two different attempted to grab mouse input')
+self.mouse_grabber = ax
+
+def release_mouse(self, ax):
+"""
+Release the mouse grab held by the axes, ax.
+Usually called by the widgets.
+It is ok to call this even if you ax doesn't have the mouse grab 
currently.
+"""
+if self.mouse_grabber is ax:
+self.mouse_grabber = None
+
 def draw(self, *args, **kwargs):
 """
 Render the :class:`~matplotlib.figure.Figure`

Modified: trunk/matplotlib/lib/matplotlib/widgets.py
===
--- trunk/matplotlib/lib/matplotlib/widgets.py  2010-06-17 17:45:38 UTC (rev 
8440)
+++ trunk/matplotlib/lib/matplotlib/widgets.py  2010-06-19 23:46:47 UTC (rev 
8441)
@@ -106,6 +106,7 @@
 
 
 ax.figure.canvas.mpl_connect('button_press_event', self._click)
+ax.figure.canvas.mpl_connect('button_release_event', self._release)
 ax.figure.canvas.mpl_connect('motion_notify_event', self._motion)
 ax.set_navigate(False)
 ax.set_axis_bgcolor(color)
@@ -117,8 +118,21 @@
 self._lastcolor = color
 
 def _click(self, event):
-if event.inaxes != self.ax: return
-if not self.eventson: return
+if event.inaxes != self.ax:
+return
+if not self.eventson:
+return
+if event.canvas.mouse_grabber != self.ax:
+event.canvas.grab_mouse(self.ax)
+
+def _release(self, event):
+if event.canvas.mouse_grabber != self.ax:
+return
+event.canvas.release_mouse(self.ax)
+if not self.eventson:
+return
+if event.inaxes != self.ax: 
+return
 for cid, func in self.observers.items():
 func(event)
 
@@ -209,6 +223,7 @@
 ax.set_navigate(False)
 
 ax.figure.canvas.mpl_connect('button_press_event', self._update)
+ax.figure.canvas.mpl_connect('button_release_event', self._update)
 if dragging:
 ax.figure.canvas.mpl_connect('motion_notify_event', self._update)
 self.label = ax.text(-0.02, 0.5, label, transform=ax.transAxes,
@@ -227,14 +242,35 @@
 self.closedmax = closedmax
 self.slidermin = slidermin
 self.slidermax = slidermax
+self.drag_active  = False
 
 def _update(self, event):
 'update the slider position'
-if event.button !=1: return
-if event.inaxes != self.ax: return
+if event.button != 1:
+return
+
+if event.name == 'button_press_event' and event.inaxes == self.ax:
+self.drag_active = True
+event.canvas.grab_mouse(self.ax)
+
+if not self.drag_active: 
+return
+
+elif ((event.name == 'button_release_event') 
+ or (event.name == 'button_press_event' and event.inaxes != 
self.ax)):
+self.drag_active = False
+ 

SF.net SVN: matplotlib:[8442] trunk/matplotlib/lib/matplotlib/backends/ backend_wx.py

2010-06-19 Thread efiring
Revision: 8442
  http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8442&view=rev
Author:   efiring
Date: 2010-06-20 01:34:30 + (Sun, 20 Jun 2010)

Log Message:
---
[2564093] backend_wx: don't initialize printer by default; deprecate Printer*

Modified Paths:
--
trunk/matplotlib/lib/matplotlib/backends/backend_wx.py

Modified: trunk/matplotlib/lib/matplotlib/backends/backend_wx.py
===
--- trunk/matplotlib/lib/matplotlib/backends/backend_wx.py  2010-06-19 
23:46:47 UTC (rev 8441)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_wx.py  2010-06-20 
01:34:30 UTC (rev 8442)
@@ -754,7 +754,11 @@
 
 self.macros = {} # dict from wx id to seq of macros
 
-self.Printer_Init()
+# printer attributes and methods deprecated, 2010/06/19
+self._printerData = None
+self._printerPageData = None
+self.printer_width = 5.5
+self.printer_margin = 0.5
 
 def Destroy(self, *args, **kwargs):
 wx.Panel.Destroy(self, *args, **kwargs)
@@ -769,7 +773,12 @@
 wx.TheClipboard.Close()
 
 def Printer_Init(self):
-"""initialize printer settings using wx methods"""
+"""
+initialize printer settings using wx methods
+
+Deprecated.
+"""
+warnings.warn("Printer* methods will be removed", DeprecationWarning)
 self.printerData = wx.PrintData()
 self.printerData.SetPaperId(wx.PAPER_LETTER)
 self.printerData.SetPrintMode(wx.PRINT_MODE_PRINTER)
@@ -781,14 +790,37 @@
 self.printer_width = 5.5
 self.printer_margin= 0.5
 
+def _get_printerData(self):
+if self._printerData is None:
+warnings.warn("Printer* methods will be removed", 
DeprecationWarning)
+self._printerData = wx.PrintData()
+self._printerData.SetPaperId(wx.PAPER_LETTER)
+self._printerData.SetPrintMode(wx.PRINT_MODE_PRINTER)
+return self._printerData
+printerData = property(_get_printerData)
+
+def _get_printerPageData(self):
+if self._printerPageData is None:
+warnings.warn("Printer* methods will be removed", 
DeprecationWarning)
+self._printerPageData= wx.PageSetupDialogData()
+self._printerPageData.SetMarginBottomRight((25,25))
+self._printerPageData.SetMarginTopLeft((25,25))
+self._printerPageData.SetPrintData(self.printerData)
+return self._printerPageData
+printerPageData = property(_get_printerPageData)
+
 def Printer_Setup(self, event=None):
-"""set up figure for printing.  The standard wx Printer
+"""
+set up figure for printing.  The standard wx Printer
 Setup Dialog seems to die easily. Therefore, this setup
-simply asks for image width and margin for printing. """
+simply asks for image width and margin for printing.
+Deprecated.
+"""
 
 dmsg = """Width of output figure in inches.
 The current aspect ratio will be kept."""
 
+warnings.warn("Printer* methods will be removed", DeprecationWarning)
 dlg = wx.Dialog(self, -1, 'Page Setup for Printing' , (-1,-1))
 df = dlg.GetFont()
 df.SetWeight(wx.NORMAL)
@@ -844,9 +876,14 @@
 return
 
 def Printer_Setup2(self, event=None):
-"""set up figure for printing.  Using the standard wx Printer
-Setup Dialog. """
+"""
+set up figure for printing.  Using the standard wx Printer
+Setup Dialog.
 
+Deprecated.
+"""
+
+warnings.warn("Printer* methods will be removed", DeprecationWarning)
 if hasattr(self, 'printerData'):
 data = wx.PageSetupDialogData()
 data.SetPrintData(self.printerData)
@@ -865,7 +902,12 @@
 dlg.Destroy()
 
 def Printer_Preview(self, event=None):
-""" generate Print Preview with wx Print mechanism"""
+"""
+generate Print Preview with wx Print mechanism
+
+Deprecated.
+"""
+warnings.warn("Printer* methods will be removed", DeprecationWarning)
 po1  = PrintoutWx(self, width=self.printer_width,
   margin=self.printer_margin)
 po2  = PrintoutWx(self, width=self.printer_width,
@@ -886,7 +928,12 @@
 self.gui_repaint()
 
 def Printer_Print(self, event=None):
-""" Print figure using wx Print mechanism"""
+"""
+Print figure using wx Print mechanism
+
+Deprecated.
+"""
+warnings.warn("Printer* methods will be removed", DeprecationWarning)
 pdd = wx.PrintDialogData()
 # SetPrintData for 2.4 combatibility
 pdd.SetPrintData(self.printerData)


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

---