Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

modifying GTK3 example to use pygobject, and adding a simple example to demonstrate NavigationToolbar in GTK3 #1007

Merged
merged 3 commits into from

4 participants

@JackKelly

Hi there,

Great work with matplotlib - it's such a joy to use.

I'm developing an app using GTK3 accessed using pygobject (instead of pygtk). Whilst learning how to use matplotlib with pygobject, I updated the embedding_in_gtk3.py example and I also added a very simple example demonstrating the use of the NavigationToolbar within GTK3.

(This is my first pull request. And I'm rather new to matplotlib and Python so forgive me if I've done this all wrong!)

Thanks,
Jack

@WeatherGod WeatherGod commented on the diff
.gitignore
@@ -5,6 +5,8 @@
*~
*$
*.bak
+.project
+.pydevproject
@WeatherGod Collaborator

are these necessary? Running the example doesn't appear to produce these files, I don't think.

@efiring Owner
efiring added a note

Neither necessary nor relevant--but entirely harmless, and presumably useful if a developer uses eclipse/pydev (which I do not).

Exactly as efiring says: these files are neither necessary nor relevant but they are helpful for folks like me who use Pydev (Pydev creates a .project and .pydevproject file for each "project"). Sorry, I must admit that I'm still very much a newbie when it comes to pull requests; I had assumed that only my first commit (the GTK3 example code) would be part of the pull request, not my additions to .gitignore. But, a efiring says, these additions to .gitignore should be entirely harmless for folks who don't use PyDev and will be useful for those who do use PyDev.

@pelson Collaborator
pelson added a note

These files should be added to the .gitignore file rather than being part of the repository (otherwise, simply changing the interpreter used in the pydev project, as one may do to test different python versions with mpl, would trigger an unnecessary source change).

Hi pelson. I could be wrong but I think I have added these files to. gitignore

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@efiring efiring merged commit 96d1814 into matplotlib:master
@efiring
Owner

I think the net effect of the pull request is fine; the examples run, and nothing seems to have gotten changed that shouldn't have. For future pull requests, however, please use something closer to the procedure described in the matplotlib docs, http://matplotlib.sourceforge.net/devel/gitwash/index.html. Specifically, make a feature branch for your feature, and make the pull request be from that. Don't merge from upstream or anywhere else. I think the third commit in the present pull request simply makes the history more confusing.

@JackKelly

Cool, thanks loads for taking the time to review this pull request and merge my modifications. Also, thank you for pointing me to the relevant documentation - I'll make sure I do it correctly next time! Thanks loads. Jack

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 11, 2012
  1. modifying GTK3 example to use pygobject, and adding a simple example …

    Jack (aka Daniel) Kelly authored
    …to demonstrate NavigationToolbar in GTK3
Commits on Jul 12, 2012
  1. @JackKelly

    ignore Eclipse PyDev files

    JackKelly authored
Commits on Jul 19, 2012
  1. @JackKelly
This page is out of date. Refresh to see the latest.
View
2  .gitignore
@@ -5,6 +5,8 @@
*~
*$
*.bak
+.project
+.pydevproject
@WeatherGod Collaborator

are these necessary? Running the example doesn't appear to produce these files, I don't think.

@efiring Owner
efiring added a note

Neither necessary nor relevant--but entirely harmless, and presumably useful if a developer uses eclipse/pydev (which I do not).

Exactly as efiring says: these files are neither necessary nor relevant but they are helpful for folks like me who use Pydev (Pydev creates a .project and .pydevproject file for each "project"). Sorry, I must admit that I'm still very much a newbie when it comes to pull requests; I had assumed that only my first commit (the GTK3 example code) would be part of the pull request, not my additions to .gitignore. But, a efiring says, these additions to .gitignore should be entirely harmless for folks who don't use PyDev and will be useful for those who do use PyDev.

@pelson Collaborator
pelson added a note

These files should be added to the .gitignore file rather than being part of the repository (otherwise, simply changing the interpreter used in the pydev project, as one may do to test different python versions with mpl, would trigger an unnecessary source change).

Hi pelson. I could be wrong but I think I have added these files to. gitignore

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
# Compiled source #
###################
View
25 examples/user_interfaces/embedding_in_gtk3.py
@@ -1,20 +1,17 @@
#!/usr/bin/env python
"""
-demonstrate adding a FigureCanvasGTK/GTKAgg widget to a gtk.ScrolledWindow
+demonstrate adding a FigureCanvasGTK3Agg widget to a Gtk.ScrolledWindow
+using GTK3 accessed via pygobject
"""
-import gtk
+from gi.repository import Gtk
from matplotlib.figure import Figure
from numpy import arange, sin, pi
+from matplotlib.backends.backend_gtk3agg import FigureCanvasGTK3Agg as FigureCanvas
-# uncomment to select /GTK/GTKAgg/GTKCairo
-#from matplotlib.backends.backend_gtk import FigureCanvasGTK as FigureCanvas
-from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg as FigureCanvas
-#from matplotlib.backends.backend_gtkcairo import FigureCanvasGTKCairo as FigureCanvas
-
-win = gtk.Window()
-win.connect("destroy", lambda x: gtk.main_quit())
+win = Gtk.Window()
+win.connect("delete-event", Gtk.main_quit )
win.set_default_size(400,300)
win.set_title("Embedding in GTK")
@@ -24,17 +21,15 @@
s = sin(2*pi*t)
a.plot(t,s)
-sw = gtk.ScrolledWindow()
+sw = Gtk.ScrolledWindow()
win.add (sw)
# A scrolled window border goes outside the scrollbars and viewport
sw.set_border_width (10)
-# policy: ALWAYS, AUTOMATIC, NEVER
-sw.set_policy (hscrollbar_policy=gtk.POLICY_AUTOMATIC,
- vscrollbar_policy=gtk.POLICY_ALWAYS)
-canvas = FigureCanvas(f) # a gtk.DrawingArea
+canvas = FigureCanvas(f) # a Gtk.DrawingArea
canvas.set_size_request(800,600)
sw.add_with_viewport (canvas)
win.show_all()
-gtk.main()
+Gtk.main()
+
View
37 examples/user_interfaces/embedding_in_gtk3_panzoom.py
@@ -0,0 +1,37 @@
+#!/usr/bin/env python
+"""
+demonstrate NavigationToolbar with GTK3 accessed via pygobject
+"""
+
+from gi.repository import Gtk
+
+from matplotlib.figure import Figure
+from numpy import arange, sin, pi
+from matplotlib.backends.backend_gtk3agg import FigureCanvasGTK3Agg as FigureCanvas
+from matplotlib.backends.backend_gtk3 import NavigationToolbar2GTK3 as NavigationToolbar
+
+win = Gtk.Window()
+win.connect("delete-event", Gtk.main_quit )
+win.set_default_size(400,300)
+win.set_title("Embedding in GTK")
+
+f = Figure(figsize=(5,4), dpi=100)
+a = f.add_subplot(1,1,1)
+t = arange(0.0,3.0,0.01)
+s = sin(2*pi*t)
+a.plot(t,s)
+
+vbox = Gtk.VBox()
+win.add(vbox)
+
+# Add canvas to vbox
+canvas = FigureCanvas(f) # a Gtk.DrawingArea
+vbox.pack_start(canvas, True, True, 0)
+
+# Create toolbar
+toolbar = NavigationToolbar(canvas, win)
+vbox.pack_start(toolbar, False, False, 0)
+
+win.show_all()
+Gtk.main()
+
Something went wrong with that request. Please try again.