Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2d20c75

Browse files
committed
added glade example
svn path=/trunk/matplotlib/; revision=32
1 parent 551fc92 commit 2d20c75

3 files changed

Lines changed: 330 additions & 1 deletion

File tree

examples/mpl_with_glade.glade

Lines changed: 258 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,258 @@
1+
<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
2+
<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">
3+
4+
<glade-interface>
5+
6+
<widget class="GtkWindow" id="windowMain">
7+
<property name="visible">True</property>
8+
<property name="title" translatable="yes">window1</property>
9+
<property name="type">GTK_WINDOW_TOPLEVEL</property>
10+
<property name="window_position">GTK_WIN_POS_NONE</property>
11+
<property name="modal">False</property>
12+
<property name="resizable">True</property>
13+
<property name="destroy_with_parent">False</property>
14+
15+
<child>
16+
<widget class="GtkVBox" id="vboxMain">
17+
<property name="border_width">4</property>
18+
<property name="visible">True</property>
19+
<property name="homogeneous">False</property>
20+
<property name="spacing">2</property>
21+
22+
<child>
23+
<widget class="GtkMenuBar" id="menubar1">
24+
<property name="visible">True</property>
25+
26+
<child>
27+
<widget class="GtkMenuItem" id="menuitem1">
28+
<property name="visible">True</property>
29+
<property name="label" translatable="yes">_File</property>
30+
<property name="use_underline">True</property>
31+
32+
<child>
33+
<widget class="GtkMenu" id="menu1">
34+
35+
<child>
36+
<widget class="GtkImageMenuItem" id="new1">
37+
<property name="visible">True</property>
38+
<property name="label">gtk-new</property>
39+
<property name="use_stock">True</property>
40+
<signal name="activate" handler="on_new1_activate" last_modification_time="Wed, 01 Oct 2003 13:32:18 GMT"/>
41+
</widget>
42+
</child>
43+
44+
<child>
45+
<widget class="GtkImageMenuItem" id="open1">
46+
<property name="visible">True</property>
47+
<property name="label">gtk-open</property>
48+
<property name="use_stock">True</property>
49+
<signal name="activate" handler="on_open1_activate" last_modification_time="Wed, 01 Oct 2003 13:32:18 GMT"/>
50+
</widget>
51+
</child>
52+
53+
<child>
54+
<widget class="GtkImageMenuItem" id="save1">
55+
<property name="visible">True</property>
56+
<property name="label">gtk-save</property>
57+
<property name="use_stock">True</property>
58+
<signal name="activate" handler="on_save1_activate" last_modification_time="Wed, 01 Oct 2003 13:32:18 GMT"/>
59+
</widget>
60+
</child>
61+
62+
<child>
63+
<widget class="GtkImageMenuItem" id="save_as1">
64+
<property name="visible">True</property>
65+
<property name="label">gtk-save-as</property>
66+
<property name="use_stock">True</property>
67+
<signal name="activate" handler="on_save_as1_activate" last_modification_time="Wed, 01 Oct 2003 13:32:18 GMT"/>
68+
</widget>
69+
</child>
70+
71+
<child>
72+
<widget class="GtkSeparatorMenuItem" id="separatormenuitem1">
73+
<property name="visible">True</property>
74+
</widget>
75+
</child>
76+
77+
<child>
78+
<widget class="GtkImageMenuItem" id="quit1">
79+
<property name="visible">True</property>
80+
<property name="label">gtk-quit</property>
81+
<property name="use_stock">True</property>
82+
<signal name="activate" handler="on_quit1_activate" last_modification_time="Wed, 01 Oct 2003 13:32:18 GMT"/>
83+
</widget>
84+
</child>
85+
</widget>
86+
</child>
87+
</widget>
88+
</child>
89+
90+
<child>
91+
<widget class="GtkMenuItem" id="menuitem2">
92+
<property name="visible">True</property>
93+
<property name="label" translatable="yes">_Edit</property>
94+
<property name="use_underline">True</property>
95+
96+
<child>
97+
<widget class="GtkMenu" id="menu2">
98+
99+
<child>
100+
<widget class="GtkImageMenuItem" id="cut1">
101+
<property name="visible">True</property>
102+
<property name="label">gtk-cut</property>
103+
<property name="use_stock">True</property>
104+
<signal name="activate" handler="on_cut1_activate" last_modification_time="Wed, 01 Oct 2003 13:32:18 GMT"/>
105+
</widget>
106+
</child>
107+
108+
<child>
109+
<widget class="GtkImageMenuItem" id="copy1">
110+
<property name="visible">True</property>
111+
<property name="label">gtk-copy</property>
112+
<property name="use_stock">True</property>
113+
<signal name="activate" handler="on_copy1_activate" last_modification_time="Wed, 01 Oct 2003 13:32:18 GMT"/>
114+
</widget>
115+
</child>
116+
117+
<child>
118+
<widget class="GtkImageMenuItem" id="paste1">
119+
<property name="visible">True</property>
120+
<property name="label">gtk-paste</property>
121+
<property name="use_stock">True</property>
122+
<signal name="activate" handler="on_paste1_activate" last_modification_time="Wed, 01 Oct 2003 13:32:18 GMT"/>
123+
</widget>
124+
</child>
125+
126+
<child>
127+
<widget class="GtkImageMenuItem" id="delete1">
128+
<property name="visible">True</property>
129+
<property name="label">gtk-delete</property>
130+
<property name="use_stock">True</property>
131+
<signal name="activate" handler="on_delete1_activate" last_modification_time="Wed, 01 Oct 2003 13:32:18 GMT"/>
132+
</widget>
133+
</child>
134+
</widget>
135+
</child>
136+
</widget>
137+
</child>
138+
139+
<child>
140+
<widget class="GtkMenuItem" id="menuitem3">
141+
<property name="visible">True</property>
142+
<property name="label" translatable="yes">_View</property>
143+
<property name="use_underline">True</property>
144+
145+
<child>
146+
<widget class="GtkMenu" id="menu3">
147+
</widget>
148+
</child>
149+
</widget>
150+
</child>
151+
152+
<child>
153+
<widget class="GtkMenuItem" id="menuitem4">
154+
<property name="visible">True</property>
155+
<property name="label" translatable="yes">_Help</property>
156+
<property name="use_underline">True</property>
157+
158+
<child>
159+
<widget class="GtkMenu" id="menu4">
160+
161+
<child>
162+
<widget class="GtkMenuItem" id="about1">
163+
<property name="visible">True</property>
164+
<property name="label" translatable="yes">_About</property>
165+
<property name="use_underline">True</property>
166+
<signal name="activate" handler="on_about1_activate" last_modification_time="Wed, 01 Oct 2003 13:32:18 GMT"/>
167+
</widget>
168+
</child>
169+
</widget>
170+
</child>
171+
</widget>
172+
</child>
173+
</widget>
174+
<packing>
175+
<property name="padding">0</property>
176+
<property name="expand">False</property>
177+
<property name="fill">False</property>
178+
</packing>
179+
</child>
180+
181+
<child>
182+
<placeholder/>
183+
</child>
184+
185+
<child>
186+
<widget class="GtkButton" id="buttonClickMe">
187+
<property name="visible">True</property>
188+
<property name="can_focus">True</property>
189+
<property name="relief">GTK_RELIEF_NORMAL</property>
190+
<signal name="clicked" handler="on_buttonClickMe_clicked" last_modification_time="Wed, 01 Oct 2003 13:50:20 GMT"/>
191+
192+
<child>
193+
<widget class="GtkAlignment" id="alignment1">
194+
<property name="visible">True</property>
195+
<property name="xalign">0.5</property>
196+
<property name="yalign">0.5</property>
197+
<property name="xscale">0</property>
198+
<property name="yscale">0</property>
199+
200+
<child>
201+
<widget class="GtkHBox" id="hbox1">
202+
<property name="visible">True</property>
203+
<property name="homogeneous">False</property>
204+
<property name="spacing">2</property>
205+
206+
<child>
207+
<widget class="GtkImage" id="image1">
208+
<property name="visible">True</property>
209+
<property name="stock">gtk-dialog-info</property>
210+
<property name="icon_size">4</property>
211+
<property name="xalign">0.5</property>
212+
<property name="yalign">0.5</property>
213+
<property name="xpad">0</property>
214+
<property name="ypad">0</property>
215+
</widget>
216+
<packing>
217+
<property name="padding">0</property>
218+
<property name="expand">False</property>
219+
<property name="fill">False</property>
220+
</packing>
221+
</child>
222+
223+
<child>
224+
<widget class="GtkLabel" id="label1">
225+
<property name="visible">True</property>
226+
<property name="label" translatable="yes">Click Me!</property>
227+
<property name="use_underline">True</property>
228+
<property name="use_markup">False</property>
229+
<property name="justify">GTK_JUSTIFY_LEFT</property>
230+
<property name="wrap">False</property>
231+
<property name="selectable">False</property>
232+
<property name="xalign">0.5</property>
233+
<property name="yalign">0.5</property>
234+
<property name="xpad">0</property>
235+
<property name="ypad">0</property>
236+
</widget>
237+
<packing>
238+
<property name="padding">0</property>
239+
<property name="expand">False</property>
240+
<property name="fill">False</property>
241+
</packing>
242+
</child>
243+
</widget>
244+
</child>
245+
</widget>
246+
</child>
247+
</widget>
248+
<packing>
249+
<property name="padding">0</property>
250+
<property name="expand">False</property>
251+
<property name="fill">False</property>
252+
</packing>
253+
</child>
254+
</widget>
255+
</child>
256+
</widget>
257+
258+
</glade-interface>

examples/mpl_with_glade.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import matplotlib
2+
matplotlib.use('GTK')
3+
4+
from matplotlib.backends import Figure
5+
from matplotlib.axes import Subplot
6+
from matplotlib.backends.backend_gtk import NavigationToolbar
7+
8+
from Numeric import arange, sin, pi
9+
import gtk
10+
import gtk.glade
11+
12+
13+
def simple_msg(msg, parent=None, title=None):
14+
dialog = gtk.MessageDialog(
15+
parent = None,
16+
type = gtk.MESSAGE_INFO,
17+
buttons = gtk.BUTTONS_OK,
18+
message_format = msg)
19+
if parent is not None:
20+
dialog.set_transient_for(parent)
21+
if title is not None:
22+
dialog.set_title(title)
23+
dialog.show()
24+
dialog.run()
25+
dialog.destroy()
26+
return None
27+
28+
29+
30+
class GladeHandlers:
31+
def on_buttonClickMe_clicked(event):
32+
simple_msg('Nothing to say, really',
33+
parent=widgets['windowMain'],
34+
title='Thanks!')
35+
36+
class WidgetsWrapper:
37+
def __init__(self):
38+
self.widgets = gtk.glade.XML('mpl_with_glade.glade')
39+
self.widgets.signal_autoconnect(GladeHandlers.__dict__)
40+
41+
self.figure = Figure(figsize=(5,4), dpi=100)
42+
self.figure.show()
43+
self.axis = Subplot(111)
44+
self.figure.add_axis(self.axis)
45+
t = arange(0.0,3.0,0.01)
46+
s = sin(2*pi*t)
47+
self.axis.plot(t,s)
48+
self.axis.set_xlabel('time (s)')
49+
self.axis.set_ylabel('voltage')
50+
51+
self['vboxMain'].pack_start(self.figure, gtk.TRUE, gtk.TRUE)
52+
53+
# below is optional if you want the navigation toolbar
54+
self.navToolbar = NavigationToolbar(self.figure, self['windowMain'])
55+
self.navToolbar.lastDir = '/var/tmp/'
56+
self['vboxMain'].pack_start(self.navToolbar)
57+
self.navToolbar.show()
58+
59+
sep = gtk.HSeparator()
60+
sep.show()
61+
self['vboxMain'].pack_start(sep, gtk.TRUE, gtk.TRUE)
62+
63+
64+
self['vboxMain'].reorder_child(self['buttonClickMe'],-1)
65+
66+
def __getitem__(self, key):
67+
return self.widgets.get_widget(key)
68+
69+
widgets = WidgetsWrapper()
70+
gtk.mainloop ()

examples/scatter_demo.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
y = 0.9*rand(30)
55
s = 0.1*rand(30)
66
c = rand(30)
7-
scatter(x,y,s,'b')
7+
scatter(x,y,s,c)
88
#axis([0, 1, 0, 1])
9+
savefig('scatter_demo')
910
show()

0 commit comments

Comments
 (0)