Changeset 2df0b74 in sasview for src/sas/plottools/canvas.py
- Timestamp:
- Mar 5, 2015 11:17:05 AM (10 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 3477478
- Parents:
- dca6188
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/plottools/canvas.py
r79492222 r2df0b74 5 5 import wx 6 6 import sys 7 import logging 7 8 from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg 8 from matplotlib.backends.backend_wxagg import _convert_agg_to_wx_bitmap9 from matplotlib.backends.backend_agg import FigureCanvasAgg10 9 from matplotlib.backend_bases import MouseEvent, RendererBase 11 10 from matplotlib.backends.backend_wx import GraphicsContextWx, PrintoutWx … … 48 47 dc = self.GetDC() 49 48 try: 50 (ppw, pph) = self.GetPPIPrinter() 49 (ppw, pph) = self.GetPPIPrinter() # printer's pixels per in 51 50 except: 52 51 ppw = 1 53 52 pph = 1 54 (pgw, pgh) = self.GetPageSizePixels() # page size in pixels55 (dcw, dch) = dc.GetSize()56 (grw, grh) = self.canvas.GetSizeTuple()53 (pgw, _) = self.GetPageSizePixels() # page size in pixels 54 (dcw, _) = dc.GetSize() 55 (grw, _) = self.canvas.GetSizeTuple() 57 56 58 57 # save current figure dpi resolution and bg color, … … 78 77 page_scale = 1.0 79 78 if self.IsPreview(): 80 page_scale = float(dcw) /pgw79 page_scale = float(dcw) / pgw 81 80 82 81 # get margin in pixels = (margin in in) * (pixels/in) … … 97 96 dc.DrawBitmap(self.canvas.bitmap, (0, 0)) 98 97 except: 99 pass98 logging.error(sys.exc_value) 100 99 101 100 # restore original figure resolution 102 101 self.canvas.figure.set_facecolor(bgcolor) 103 # # used to be self.canvas.figure.dpi.set( fig_dpi)102 # # used to be self.canvas.figure.dpi.set( fig_dpi) 104 103 self.canvas.figure.dpi = fig_dpi 105 104 self.canvas.draw() … … 121 120 super(FigureCanvas, self).__init__(*args, **kw) 122 121 self._isRendered = False 123 122 124 123 # Create an timer for handling draw_idle requests 125 124 # If there are events pending when the timer is … … 136 135 # Support for mouse wheel 137 136 self.Bind(wx.EVT_MOUSEWHEEL, self._onMouseWheel) 138 137 139 138 def set_panel(self, panel): 140 139 """ … … 146 145 self.xaxis = panel.subplot.xaxis 147 146 self.yaxis = panel.subplot.yaxis 148 147 149 148 def draw_idle(self, *args, **kwargs): 150 149 """ … … 165 164 self.draw(*args, **kwargs) 166 165 self.resizing = False 167 166 168 167 def _get_axes_switch(self): 169 168 """ … … 184 183 # set the resizing back to default= False 185 184 self.set_resizing(False) 186 185 187 186 def set_resizing(self, resizing=False): 188 187 """ … … 191 190 self.resizing = resizing 192 191 self.panel.set_resizing(False) 193 192 194 193 def draw(self, drawDC=None): 195 194 """ … … 203 202 self._isRendered = True 204 203 self._get_axes_switch() 205 # import time206 # st = time.time()204 # import time 205 # st = time.time() 207 206 try: 208 207 fig.draw(self) 209 208 except ValueError: 210 pass 211 #self.bitmap = _convert_agg_to_wx_bitmap(self.get_renderer(), None) 212 #self.gui_repaint(drawDC=drawDC) 213 #print "time", time.time() - st 209 logging.error(sys.exc_value) 214 210 else: 215 211 self._isRendered = False 216 212 if self.ndraw <= 1: 217 213 self.ndraw += 1 218 214 219 215 def _onMouseWheel(self, evt): 220 216 """Translate mouse wheel events into matplotlib events""" 221 217 # Determine mouse location 222 w, h = self.figure.canvas.get_width_height()218 _, h = self.figure.canvas.get_width_height() 223 219 x = evt.GetX() 224 220 y = h - evt.GetY() … … 228 224 rotation = evt.GetWheelRotation() 229 225 rate = evt.GetLinesPerAction() 230 # print "delta,rotation,rate",delta,rotation,rate226 # print "delta,rotation,rate",delta,rotation,rate 231 227 step = rate * float(rotation) / delta 232 228 … … 249 245 if step != 0: 250 246 self.panel.is_zoomed = True 251 247 252 248 def _onRightButtonDown(self, evt): 253 249 """ 254 250 Overload the right button down call back to avoid a problem 255 251 with the context menu over matplotlib plots on linux. 256 252 257 253 :TODO: Investigate what the root cause of the problem is. 258 254 259 255 """ 260 256 if sys.platform == 'linux2' or self.panel.dimension == 3: … … 271 267 def _onLeave(self, evt): 272 268 if self.HasCapture(): self.ReleaseMouse() 273 super(FigureCanvas, self)._onLeave(evt)269 super(FigureCanvas, self)._onLeave(evt)
Note: See TracChangeset
for help on using the changeset viewer.