473,394 Members | 1,645 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

matplotlib, wxPanel inside a wxPanel

Sam
Hello,

I'm currently creating a GUI, which consists of a main frame that
contains a menu bar,a toolbar and an empty panel, let's call it
main_panel.
Ideally, I'd like the following functionality: upon choosing an item
from the menu bar, a particular graph will be displayed inside
main_panel.

Now I've taken a look at the 'embedding_in_wx' example files that come
with matplotlib. Using this example, I can place a graph in a panel
(let's call it graph_panel), and display this in a frame. I can also
get NavigationToolbar2 to work completely.

On the other hand, when i create graph_panel and put this inside of
main_panel, NavigationToolbar2 does not work. The graph and toolbar are
both displayed, but none of the buttons on the toolbar do anything.

I'm beginning to think that what i'm trying to do isn't actually
possible, and that i'll need to put it in a frame instead, which is a
pity.

Can anyone please advise if what i'm trying to do is possible and if
so, provide a small example? I'm running windows XP, python 2.4,
wxpython 2.6.

Aug 12 '06 #1
3 2556
Sam wrote:
Hello,
Hi there Sam :)
I'm beginning to think that what i'm trying to do isn't actually
possible, and that i'll need to put it in a frame instead, which is a
pity.
Indeed, if that is the case... as I'll need to do exactly that! But see
below ;)
On the other hand, when i create graph_panel and put this inside of
main_panel, NavigationToolbar2 does not work. The graph and toolbar are
both displayed, but none of the buttons on the toolbar do anything.
I've been bitten by things that sounded similar to this and were
related to sloppy cut'n'paste that resulted in different hierarchies of
wx elements. If you post your code we can try to spot mistakes like
those.

As a general advice, go for a clean frame with a main_panel, a
graph_panel and sprinkle "print" statements (specially around events)
to find out what is happening.
Can anyone please advise if what i'm trying to do is possible and if
so, provide a small example? I'm running windows XP, python 2.4,
wxpython 2.6.
I'll try to get around that one later today, but on win98 :)

Daniel

Aug 12 '06 #2
It seems to work (only tested with embedding_in_wx4.py). I guess it's
something related to things nesting in a slightly wrong way, right
enough to show up but wrong enough to only show up :)

I hope this helps.
Daniel

Substitute embedding_in_wx4.py's CanvasFrame with:

class CanvasFrame(wxFrame):
def __init__(self):
# Begin just like embedding_in_wx4.py
wxFrame.__init__(self,None,-1,
'CanvasFrame',size=(550,350))

self.figure = Figure(figsize=(5,4), dpi=100)
self.axes = self.figure.add_subplot(111)
t = range(0,30)
s = [randint(1, 30)* random() * x for x in t]
self.axes.plot(t,s)
# Add panels from deepest level
self.main_panel = wxPanel(self, -1)
# Parent is main_panel:
self.graph_panel = wxPanel(self.main_panel, -1)
# self.canvas is child of graph_panel...
self.canvas = FigureCanvas(self.graph_panel, -1, self.figure)
# ... as is textgraph
self.text_graph = wxTextCtrl(self.graph_panel, -1, "Hello!\n" +
"I'm in graph_panel",
style=wxTE_MULTILINE)
self.toolbar = MyNavigationToolbar(self.canvas, True)
self.toolbar.Realize()
self.graph_panel_sizer = wxBoxSizer(wxVERTICAL)

tw, th = self.toolbar.GetSizeTuple()
fw, fh = self.canvas.GetSizeTuple()
self.toolbar.SetSize(wxSize(fw, th))
self.graph_panel_sizer.Add(self.toolbar, 0, wxEXPAND)

# After the toolbar, add its siblings to graph_panel_sizer
self.graph_panel_sizer.Add(self.canvas, 1, wxEXPAND)
self.graph_panel_sizer.Add(self.text_graph)
self.graph_panel.SetSizer(self.graph_panel_sizer)
self.graph_panel.Fit()
# graph_panel is done, just add it to main_panel's sizer.

self.main_panel_sizer = wxBoxSizer(wxVERTICAL)
self.text_in = wxTextCtrl(self.main_panel, -1,
"Inside main_panel",
style=wxTE_MULTILINE)
# Here:
self.main_panel_sizer.Add(self.graph_panel,1, wxEXPAND)
self.main_panel_sizer.Add(self.text_in,0, wxEXPAND)
self.main_panel.SetSizer(self.main_panel_sizer)
self.main_panel.Fit()

self.sizer = wxBoxSizer(wxVERTICAL)
self.sizer.Add(self.main_panel, 1, wxEXPAND)
self.sizer_text = wxBoxSizer(wxHORIZONTAL)
self.text_hi = wxTextCtrl(self, -1, "Hello :)",
style=wxTE_MULTILINE)
self.text_out = wxTextCtrl(self, -1,"Outside main_panel",
style=wxTE_MULTILINE|wxEXPAND)

self.sizer_text.Add(self.text_hi, 0, wxEXPAND)
self.sizer_text.Add(self.text_out, 0, wxEXPAND)
self.sizer.Add(self.sizer_text, 0, wxEXPAND)
EVT_PAINT(self, self.OnPaint)
self.toolbar.update()
self.SetSizer(self.sizer)
self.Fit()

def OnPaint(self, event):
self.canvas.draw()
event.Skip()

Aug 12 '06 #3
Sam
Hi Daniel,

Thanks very much for your quick response! You're right, it was a case
of the cut-and-paste blues, and me not really knowing what each part of
the code in the examples was actually doing.
A couple of things caught me out: first of all, i wasn't calling
SetSizer and Fit on the right panels...
Secondly, I stuffed up when trying to give graph_panel a parent of
main_panel. It turns out I was actually never doing this, so the
toolbar would appear, but none of the buttons would work.

Thanks again for your comments, they were very helpful,
Cheers
Sam

Aug 13 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Piet | last post by:
Hello, I am still struggling with a dynamic dialog box. I have created a dialog box that will show a variable number of controls depending on a selection made in a ComboBox also present in the...
3
by: John Hunter | last post by:
matplotlib is a 2D plotting library for python. You can use matplotlib interactively from a python shell or IDE, or embed it in GUI applications (WX, GTK, and Tkinter). matplotlib supports many...
1
by: phark52 | last post by:
I have a wxFrame. On it is a wxNotebook, the Notebook ctrl has 5 tabs (Each one is a wxPanel.) On one of the tab pages (panels) I want to add another notebook ctrl. I get no errors but nothing...
2
by: CYBER | last post by:
Is this possible to create 1 wxFrame and register more than 1 wxPanel in it. And select the one you want to show at the moment ? I'm trying to implement a multistep wizard under wxPython. I...
5
by: Enigma Curry | last post by:
I'm playing around with matplotlib for the first time. I'm trying to make a very simple histogram of values 1-6 and how many times they occur in a sequence. However, after about an hour of...
0
by: spross | last post by:
hi all i have to use matplotlib on mac os x. on the official site of matplotlib, i found a link to precompiled python packages for mac os x: http://pythonmac.org/packages/py24-fat/index.html ...
3
by: vajratkarviraj | last post by:
i hav python2.5, matplotlib0.90.1, and py2exe for python 2.5 all on windows xp... i hav a python program(letsc.py) which uses the matplotlib package... and i want 2 make an exe of it for distribution...
4
by: John Henry | last post by:
Has anybody been able to create an exe of their python applications involving matplotlib using pyinstall (ver 1.3)? I am getting a: RuntimeError: Could not find the matplotlib data files when...
0
by: PamMish1982 | last post by:
Hi all, I have recently started using Python and I am trying to make a GUI out of Tkinter. I am using matplotlib for the graphic purposes. I have to make a exe file from this code. I use py2exe...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.