Changeset 1619 for branches/alma
- Timestamp:
- 08/15/09 18:33:15 (15 years ago)
- Location:
- branches/alma/python
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/alma/python/asaplotgui.py
r1603 r1619 56 56 self.window.lift() 57 57 58 def position(self):59 """60 Use the mouse to get a position from a graph.61 """58 # def position(self): 59 # """ 60 # Use the mouse to get a position from a graph. 61 # """ 62 62 63 def position_disable(event):64 self.register('button_press', None)65 print '%.4f, %.4f' % (event.xdata, event.ydata)63 # def position_disable(event): 64 # self.register('button_press', None) 65 # print '%.4f, %.4f' % (event.xdata, event.ydata) 66 66 67 print 'Press any mouse button...'68 self.register('button_press', position_disable)67 # print 'Press any mouse button...' 68 # self.register('button_press', position_disable) 69 69 70 70 … … 76 76 77 77 78 def region(self):79 """80 Use the mouse to get a rectangular region from a plot.78 # def region(self): 79 # """ 80 # Use the mouse to get a rectangular region from a plot. 81 81 82 The return value is [x0, y0, x1, y1] in world coordinates.83 """82 # The return value is [x0, y0, x1, y1] in world coordinates. 83 # """ 84 84 85 def region_start(event):86 height = self.canvas.figure.bbox.height()87 self.rect = {'fig': None, 'height': height,88 'x': event.x, 'y': height - event.y,89 'world': [event.xdata, event.ydata,90 event.xdata, event.ydata]}91 self.register('button_press', None)92 self.register('motion_notify', region_draw)93 self.register('button_release', region_disable)85 # def region_start(event): 86 # height = self.canvas.figure.bbox.height() 87 # self.rect = {'fig': None, 'height': height, 88 # 'x': event.x, 'y': height - event.y, 89 # 'world': [event.xdata, event.ydata, 90 # event.xdata, event.ydata]} 91 # self.register('button_press', None) 92 # self.register('motion_notify', region_draw) 93 # self.register('button_release', region_disable) 94 94 95 def region_draw(event):96 self.canvas._tkcanvas.delete(self.rect['fig'])97 self.rect['fig'] = self.canvas._tkcanvas.create_rectangle(98 self.rect['x'], self.rect['y'],99 event.x, self.rect['height'] - event.y)95 # def region_draw(event): 96 # self.canvas._tkcanvas.delete(self.rect['fig']) 97 # self.rect['fig'] = self.canvas._tkcanvas.create_rectangle( 98 # self.rect['x'], self.rect['y'], 99 # event.x, self.rect['height'] - event.y) 100 100 101 def region_disable(event):102 self.register('motion_notify', None)103 self.register('button_release', None)101 # def region_disable(event): 102 # self.register('motion_notify', None) 103 # self.register('button_release', None) 104 104 105 self.canvas._tkcanvas.delete(self.rect['fig'])105 # self.canvas._tkcanvas.delete(self.rect['fig']) 106 106 107 self.rect['world'][2:4] = [event.xdata, event.ydata]108 print '(%.2f, %.2f) (%.2f, %.2f)' % (self.rect['world'][0],109 self.rect['world'][1], self.rect['world'][2],110 self.rect['world'][3])107 # self.rect['world'][2:4] = [event.xdata, event.ydata] 108 # print '(%.2f, %.2f) (%.2f, %.2f)' % (self.rect['world'][0], 109 # self.rect['world'][1], self.rect['world'][2], 110 # self.rect['world'][3]) 111 111 112 self.register('button_press', region_start)112 # self.register('button_press', region_start) 113 113 114 # This has to be modified to block and return the result (currently115 # printed by region_disable) when that becomes possible in matplotlib.114 # # This has to be modified to block and return the result (currently 115 # # printed by region_disable) when that becomes possible in matplotlib. 116 116 117 return [0.0, 0.0, 0.0, 0.0]117 # return [0.0, 0.0, 0.0, 0.0] 118 118 119 119 120 def register(self, type=None, func=None):121 """122 Register, reregister, or deregister events of type 'button_press',123 'button_release', or 'motion_notify'.120 # def register(self, type=None, func=None): 121 # """ 122 # Register, reregister, or deregister events of type 'button_press', 123 # 'button_release', or 'motion_notify'. 124 124 125 The specified callback function should have the following signature:125 # The specified callback function should have the following signature: 126 126 127 def func(event)127 # def func(event) 128 128 129 where event is an MplEvent instance containing the following data:129 # where event is an MplEvent instance containing the following data: 130 130 131 name # Event name.132 canvas # FigureCanvas instance generating the event.133 x = None # x position - pixels from left of canvas.134 y = None # y position - pixels from bottom of canvas.135 button = None # Button pressed: None, 1, 2, 3.136 key = None # Key pressed: None, chr(range(255)), shift,137 win, or control138 inaxes = None # Axes instance if cursor within axes.139 xdata = None # x world coordinate.140 ydata = None # y world coordinate.131 # name # Event name. 132 # canvas # FigureCanvas instance generating the event. 133 # x = None # x position - pixels from left of canvas. 134 # y = None # y position - pixels from bottom of canvas. 135 # button = None # Button pressed: None, 1, 2, 3. 136 # key = None # Key pressed: None, chr(range(255)), shift, 137 # win, or control 138 # inaxes = None # Axes instance if cursor within axes. 139 # xdata = None # x world coordinate. 140 # ydata = None # y world coordinate. 141 141 142 For example:142 # For example: 143 143 144 def mouse_move(event):145 print event.xdata, event.ydata144 # def mouse_move(event): 145 # print event.xdata, event.ydata 146 146 147 a = asaplot()148 a.register('motion_notify', mouse_move)147 # a = asaplot() 148 # a.register('motion_notify', mouse_move) 149 149 150 If func is None, the event is deregistered.150 # If func is None, the event is deregistered. 151 151 152 Note that in TkAgg keyboard button presses don't generate an event.153 """152 # Note that in TkAgg keyboard button presses don't generate an event. 153 # """ 154 154 155 if not self.events.has_key(type): return155 # if not self.events.has_key(type): return 156 156 157 if func is None:158 if self.events[type] is not None:159 # It's not clear that this does anything.160 self.canvas.mpl_disconnect(self.events[type])161 self.events[type] = None157 # if func is None: 158 # if self.events[type] is not None: 159 # # It's not clear that this does anything. 160 # self.canvas.mpl_disconnect(self.events[type]) 161 # self.events[type] = None 162 162 163 # It seems to be necessary to return events to the toolbar.164 if type == 'motion_notify':165 self.canvas.mpl_connect(type + '_event',166 self.figmgr.toolbar.mouse_move)167 elif type == 'button_press':168 self.canvas.mpl_connect(type + '_event',169 self.figmgr.toolbar.press)170 elif type == 'button_release':171 self.canvas.mpl_connect(type + '_event',172 self.figmgr.toolbar.release)163 # # It seems to be necessary to return events to the toolbar. 164 # if type == 'motion_notify': 165 # self.canvas.mpl_connect(type + '_event', 166 # self.figmgr.toolbar.mouse_move) 167 # elif type == 'button_press': 168 # self.canvas.mpl_connect(type + '_event', 169 # self.figmgr.toolbar.press) 170 # elif type == 'button_release': 171 # self.canvas.mpl_connect(type + '_event', 172 # self.figmgr.toolbar.release) 173 173 174 else:175 self.events[type] = self.canvas.mpl_connect(type + '_event', func)174 # else: 175 # self.events[type] = self.canvas.mpl_connect(type + '_event', func) 176 176 177 177 -
branches/alma/python/asaplotgui_gtk.py
r1153 r1619 57 57 #self.window.lift() 58 58 59 def position(self):60 """61 Use the mouse to get a position from a graph.62 """63 64 def position_disable(event):65 self.register('button_press', None)66 print '%.4f, %.4f' % (event.xdata, event.ydata)67 68 print 'Press any mouse button...'69 self.register('button_press', position_disable)59 # def position(self): 60 # """ 61 # Use the mouse to get a position from a graph. 62 # """ 63 64 # def position_disable(event): 65 # self.register('button_press', None) 66 # print '%.4f, %.4f' % (event.xdata, event.ydata) 67 68 # print 'Press any mouse button...' 69 # self.register('button_press', position_disable) 70 70 71 71 … … 77 77 78 78 79 def region(self):80 """81 Use the mouse to get a rectangular region from a plot.82 83 The return value is [x0, y0, x1, y1] in world coordinates.84 """85 86 def region_start(event):87 height = self.canvas.figure.bbox.height()88 self.rect = {'fig': None, 'height': height,89 'x': event.x, 'y': height - event.y,90 'world': [event.xdata, event.ydata,91 event.xdata, event.ydata]}92 self.register('button_press', None)93 self.register('motion_notify', region_draw)94 self.register('button_release', region_disable)95 96 def region_draw(event):97 self.canvas._tkcanvas.delete(self.rect['fig'])98 self.rect['fig'] = self.canvas._tkcanvas.create_rectangle(99 self.rect['x'], self.rect['y'],100 event.x, self.rect['height'] - event.y)101 102 def region_disable(event):103 self.register('motion_notify', None)104 self.register('button_release', None)105 106 self.canvas._tkcanvas.delete(self.rect['fig'])107 108 self.rect['world'][2:4] = [event.xdata, event.ydata]109 print '(%.2f, %.2f) (%.2f, %.2f)' % (self.rect['world'][0],110 self.rect['world'][1], self.rect['world'][2],111 self.rect['world'][3])112 113 self.register('button_press', region_start)114 115 # This has to be modified to block and return the result (currently116 # printed by region_disable) when that becomes possible in matplotlib.117 118 return [0.0, 0.0, 0.0, 0.0]119 120 121 def register(self, type=None, func=None):122 """123 Register, reregister, or deregister events of type 'button_press',124 'button_release', or 'motion_notify'.125 126 The specified callback function should have the following signature:127 128 def func(event)129 130 where event is an MplEvent instance containing the following data:131 132 name # Event name.133 canvas # FigureCanvas instance generating the event.134 x = None # x position - pixels from left of canvas.135 y = None # y position - pixels from bottom of canvas.136 button = None # Button pressed: None, 1, 2, 3.137 key = None # Key pressed: None, chr(range(255)), shift,138 win, or control139 inaxes = None # Axes instance if cursor within axes.140 xdata = None # x world coordinate.141 ydata = None # y world coordinate.142 143 For example:144 145 def mouse_move(event):146 print event.xdata, event.ydata147 148 a = asaplot()149 a.register('motion_notify', mouse_move)150 151 If func is None, the event is deregistered.152 153 Note that in TkAgg keyboard button presses don't generate an event.154 """155 156 if not self.events.has_key(type): return157 158 if func is None:159 if self.events[type] is not None:160 # It's not clear that this does anything.161 self.canvas.mpl_disconnect(self.events[type])162 self.events[type] = None163 164 # It seems to be necessary to return events to the toolbar.165 if type == 'motion_notify':166 self.canvas.mpl_connect(type + '_event',167 self.figmgr.toolbar.mouse_move)168 elif type == 'button_press':169 self.canvas.mpl_connect(type + '_event',170 self.figmgr.toolbar.press)171 elif type == 'button_release':172 self.canvas.mpl_connect(type + '_event',173 self.figmgr.toolbar.release)174 175 else:176 self.events[type] = self.canvas.mpl_connect(type + '_event', func)79 # def region(self): 80 # """ 81 # Use the mouse to get a rectangular region from a plot. 82 83 # The return value is [x0, y0, x1, y1] in world coordinates. 84 # """ 85 86 # def region_start(event): 87 # height = self.canvas.figure.bbox.height() 88 # self.rect = {'fig': None, 'height': height, 89 # 'x': event.x, 'y': height - event.y, 90 # 'world': [event.xdata, event.ydata, 91 # event.xdata, event.ydata]} 92 # self.register('button_press', None) 93 # self.register('motion_notify', region_draw) 94 # self.register('button_release', region_disable) 95 96 # def region_draw(event): 97 # self.canvas._tkcanvas.delete(self.rect['fig']) 98 # self.rect['fig'] = self.canvas._tkcanvas.create_rectangle( 99 # self.rect['x'], self.rect['y'], 100 # event.x, self.rect['height'] - event.y) 101 102 # def region_disable(event): 103 # self.register('motion_notify', None) 104 # self.register('button_release', None) 105 106 # self.canvas._tkcanvas.delete(self.rect['fig']) 107 108 # self.rect['world'][2:4] = [event.xdata, event.ydata] 109 # print '(%.2f, %.2f) (%.2f, %.2f)' % (self.rect['world'][0], 110 # self.rect['world'][1], self.rect['world'][2], 111 # self.rect['world'][3]) 112 113 # self.register('button_press', region_start) 114 115 # # This has to be modified to block and return the result (currently 116 # # printed by region_disable) when that becomes possible in matplotlib. 117 118 # return [0.0, 0.0, 0.0, 0.0] 119 120 121 # def register(self, type=None, func=None): 122 # """ 123 # Register, reregister, or deregister events of type 'button_press', 124 # 'button_release', or 'motion_notify'. 125 126 # The specified callback function should have the following signature: 127 128 # def func(event) 129 130 # where event is an MplEvent instance containing the following data: 131 132 # name # Event name. 133 # canvas # FigureCanvas instance generating the event. 134 # x = None # x position - pixels from left of canvas. 135 # y = None # y position - pixels from bottom of canvas. 136 # button = None # Button pressed: None, 1, 2, 3. 137 # key = None # Key pressed: None, chr(range(255)), shift, 138 # win, or control 139 # inaxes = None # Axes instance if cursor within axes. 140 # xdata = None # x world coordinate. 141 # ydata = None # y world coordinate. 142 143 # For example: 144 145 # def mouse_move(event): 146 # print event.xdata, event.ydata 147 148 # a = asaplot() 149 # a.register('motion_notify', mouse_move) 150 151 # If func is None, the event is deregistered. 152 153 # Note that in TkAgg keyboard button presses don't generate an event. 154 # """ 155 156 # if not self.events.has_key(type): return 157 158 # if func is None: 159 # if self.events[type] is not None: 160 # # It's not clear that this does anything. 161 # self.canvas.mpl_disconnect(self.events[type]) 162 # self.events[type] = None 163 164 # # It seems to be necessary to return events to the toolbar. 165 # if type == 'motion_notify': 166 # self.canvas.mpl_connect(type + '_event', 167 # self.figmgr.toolbar.mouse_move) 168 # elif type == 'button_press': 169 # self.canvas.mpl_connect(type + '_event', 170 # self.figmgr.toolbar.press) 171 # elif type == 'button_release': 172 # self.canvas.mpl_connect(type + '_event', 173 # self.figmgr.toolbar.release) 174 175 # else: 176 # self.events[type] = self.canvas.mpl_connect(type + '_event', func) 177 177 178 178
Note:
See TracChangeset
for help on using the changeset viewer.