Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 96d1814

Browse filesBrowse files
committed
Merge pull request #1007 from JackKelly/master
modifying GTK3 example to use pygobject, and adding a simple example to demonstrate NavigationToolbar in GTK3
2 parents c721cf0 + 9f067e4 commit 96d1814
Copy full SHA for 96d1814

File tree

Expand file treeCollapse file tree

3 files changed

+49
-15
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+49
-15
lines changed

‎.gitignore

Copy file name to clipboardExpand all lines: .gitignore
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*~
66
*$
77
*.bak
8+
.project
9+
.pydevproject
810

911
# Compiled source #
1012
###################
+10-15Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
#!/usr/bin/env python
22
"""
3-
demonstrate adding a FigureCanvasGTK/GTKAgg widget to a gtk.ScrolledWindow
3+
demonstrate adding a FigureCanvasGTK3Agg widget to a Gtk.ScrolledWindow
4+
using GTK3 accessed via pygobject
45
"""
56

6-
import gtk
7+
from gi.repository import Gtk
78

89
from matplotlib.figure import Figure
910
from numpy import arange, sin, pi
11+
from matplotlib.backends.backend_gtk3agg import FigureCanvasGTK3Agg as FigureCanvas
1012

11-
# uncomment to select /GTK/GTKAgg/GTKCairo
12-
#from matplotlib.backends.backend_gtk import FigureCanvasGTK as FigureCanvas
13-
from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg as FigureCanvas
14-
#from matplotlib.backends.backend_gtkcairo import FigureCanvasGTKCairo as FigureCanvas
15-
16-
win = gtk.Window()
17-
win.connect("destroy", lambda x: gtk.main_quit())
13+
win = Gtk.Window()
14+
win.connect("delete-event", Gtk.main_quit )
1815
win.set_default_size(400,300)
1916
win.set_title("Embedding in GTK")
2017

@@ -24,17 +21,15 @@
2421
s = sin(2*pi*t)
2522
a.plot(t,s)
2623

27-
sw = gtk.ScrolledWindow()
24+
sw = Gtk.ScrolledWindow()
2825
win.add (sw)
2926
# A scrolled window border goes outside the scrollbars and viewport
3027
sw.set_border_width (10)
31-
# policy: ALWAYS, AUTOMATIC, NEVER
32-
sw.set_policy (hscrollbar_policy=gtk.POLICY_AUTOMATIC,
33-
vscrollbar_policy=gtk.POLICY_ALWAYS)
3428

35-
canvas = FigureCanvas(f) # a gtk.DrawingArea
29+
canvas = FigureCanvas(f) # a Gtk.DrawingArea
3630
canvas.set_size_request(800,600)
3731
sw.add_with_viewport (canvas)
3832

3933
win.show_all()
40-
gtk.main()
34+
Gtk.main()
35+
+37Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env python
2+
"""
3+
demonstrate NavigationToolbar with GTK3 accessed via pygobject
4+
"""
5+
6+
from gi.repository import Gtk
7+
8+
from matplotlib.figure import Figure
9+
from numpy import arange, sin, pi
10+
from matplotlib.backends.backend_gtk3agg import FigureCanvasGTK3Agg as FigureCanvas
11+
from matplotlib.backends.backend_gtk3 import NavigationToolbar2GTK3 as NavigationToolbar
12+
13+
win = Gtk.Window()
14+
win.connect("delete-event", Gtk.main_quit )
15+
win.set_default_size(400,300)
16+
win.set_title("Embedding in GTK")
17+
18+
f = Figure(figsize=(5,4), dpi=100)
19+
a = f.add_subplot(1,1,1)
20+
t = arange(0.0,3.0,0.01)
21+
s = sin(2*pi*t)
22+
a.plot(t,s)
23+
24+
vbox = Gtk.VBox()
25+
win.add(vbox)
26+
27+
# Add canvas to vbox
28+
canvas = FigureCanvas(f) # a Gtk.DrawingArea
29+
vbox.pack_start(canvas, True, True, 0)
30+
31+
# Create toolbar
32+
toolbar = NavigationToolbar(canvas, win)
33+
vbox.pack_start(toolbar, False, False, 0)
34+
35+
win.show_all()
36+
Gtk.main()
37+

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.