source: branches/alma/python/asaplotgui_gtk.py@ 1726

Last change on this file since 1726 was 1619, checked in by Kana Sugimoto, 15 years ago

New Development: No

JIRA Issue: No

Ready to Release: Yes

Interface Changes: No

What Interface Changed:

Test Programs:

Put in Release Notes: No

Module(s):

Description:

Removed the backend independent methods from codes,
because these codes are to handle backend dependent parts.
The removed methods have not actually been working and useless
since they are overloaded by same methods in asaplotbase.

File size: 6.9 KB
RevLine 
[1089]1"""
2ASAP plotting class based on matplotlib.
3"""
4
5from asap.asaplotbase import *
6# Force use of the newfangled toolbar.
7import gtk
8import matplotlib
9from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg as FigureCanvas
[1153]10from matplotlib.backends.backend_gtkagg import FigureManagerGTKAgg
[1089]11matplotlib.use("GTkAgg")
12matplotlib.rcParams['toolbar'] = 'toolbar2'
[1153]13from matplotlib.backends.backend_gtk import NavigationToolbar2GTK as NavigationToolbar
[1089]14
15class asaplotgui(asaplotbase):
16 """
17 ASAP plotting class based on matplotlib.
18 """
19
20 def __init__(self, rows=1, cols=0, title='', size=(8,6), buffering=False):
21 """
22 Create a new instance of the ASAPlot plotting class.
23
24 If rows < 1 then a separate call to set_panels() is required to define
25 the panel layout; refer to the doctext for set_panels().
26 """
27 v = vars()
28 del v['self']
29
30 asaplotbase.__init__(self, **v)
[1153]31 matplotlib.interactive = True
32 self.canvas = FigureCanvas(self.figure)
33 # Simply instantiating this is enough to get a working toolbar.
34 self.figmgr = FigureManagerGTKAgg(self.canvas, 1)
[1089]35 def dest_callback(val):
36 self.is_dead = True
[1153]37 self.figmgr.window.destroy()
38 self.window = self.figmgr.window
[1089]39 self.window.connect("destroy", dest_callback )
[1153]40 self.window.set_title('ASAP Plotter - GTK')
[1089]41 self.events = {'button_press':None,
42 'button_release':None,
43 'motion_notify':None}
44
45 self.buffering = buffering
[1153]46 matplotlib.rcParams['interactive'] = True
47 #self.canvas.set_size_request(800,600)
[1089]48
[1153]49 #self.canvas.show()
[1089]50
51 def map(self):
52 """
53 Reveal the ASAPlot graphics window and bring it to the top of the
54 window stack.
55 """
56 self.window.deiconify()
57 #self.window.lift()
58
[1619]59# def position(self):
60# """
61# Use the mouse to get a position from a graph.
62# """
[1089]63
[1619]64# def position_disable(event):
65# self.register('button_press', None)
66# print '%.4f, %.4f' % (event.xdata, event.ydata)
[1089]67
[1619]68# print 'Press any mouse button...'
69# self.register('button_press', position_disable)
[1089]70
71
72 def quit(self):
73 """
74 Destroy the ASAPlot graphics window.
75 """
76 self.window.destroy()
77
78
[1619]79# def region(self):
80# """
81# Use the mouse to get a rectangular region from a plot.
[1089]82
[1619]83# The return value is [x0, y0, x1, y1] in world coordinates.
84# """
[1089]85
[1619]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)
[1089]95
[1619]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)
[1089]101
[1619]102# def region_disable(event):
103# self.register('motion_notify', None)
104# self.register('button_release', None)
[1089]105
[1619]106# self.canvas._tkcanvas.delete(self.rect['fig'])
[1089]107
[1619]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])
[1089]112
[1619]113# self.register('button_press', region_start)
[1089]114
[1619]115# # This has to be modified to block and return the result (currently
116# # printed by region_disable) when that becomes possible in matplotlib.
[1089]117
[1619]118# return [0.0, 0.0, 0.0, 0.0]
[1089]119
120
[1619]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'.
[1089]125
[1619]126# The specified callback function should have the following signature:
[1089]127
[1619]128# def func(event)
[1089]129
[1619]130# where event is an MplEvent instance containing the following data:
[1089]131
[1619]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.
[1089]142
[1619]143# For example:
[1089]144
[1619]145# def mouse_move(event):
146# print event.xdata, event.ydata
[1089]147
[1619]148# a = asaplot()
149# a.register('motion_notify', mouse_move)
[1089]150
[1619]151# If func is None, the event is deregistered.
[1089]152
[1619]153# Note that in TkAgg keyboard button presses don't generate an event.
154# """
[1089]155
[1619]156# if not self.events.has_key(type): return
[1089]157
[1619]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
[1089]163
[1619]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)
[1089]174
[1619]175# else:
176# self.events[type] = self.canvas.mpl_connect(type + '_event', func)
[1089]177
178
[1153]179 def show(self, hardrefresh=True):
[1089]180 """
181 Show graphics dependent on the current buffering state.
182 """
183 if not self.buffering:
[1153]184 if hardrefresh:
185 asaplotbase.show(self, hardrefresh)
[1089]186 self.window.deiconify()
187 self.canvas.draw()
188 self.window.show_all()
189
190 def terminate(self):
191 """
192 Clear the figure.
193 """
194 self.window.destroy()
195
196 def unmap(self):
197 """
198 Hide the ASAPlot graphics window.
199 """
200 self.window.wm_withdraw()
Note: See TracBrowser for help on using the repository browser.