From: Marinescu Bogdan-b. <bog...@fr...> - 2004-07-22 07:02:03
|
Hi John, Thanks for the quick reply, I was really happy to download the snapshot and see that it works. I tested in on wxPython 2.5.1.5 without problems, it would probably work the same on 2.4.2.4. I'm not quite familiar with the toolbar functions, so I don't know if the results I'm getting are right. The "home" button seems to do something, I can see a visual indication of the repaint when I press it. On the other hand, the "pan" button seems to be disabled; even if I can press it, I'm unable to select it (or it isn't supposed to be selectable?) Maybe this is normal for the example that you sent in your e-mail? Because of this, I can't test the functionality of the back/forward buttons. The "zoom to rect" button also seems to be disable, probably because I didn't use the zoom function, which is also related to the "pan" button, if I understand it correctly. The "save" button worked when trying to save a PNG image, but the program exited with a "Do not know know to handle extension *.jpg" message printed on the console when trying to save a JPG image. Again, I don't know if this behavior is correct or not, I'm just posting my results. I don't plan on using the toolbar in my application, I have another (specialized) toolbar and I'll be using its functions. The new event handling mechanism is great and it's exactly what I needed. However, I have a couple of fresh new questions for you :) The first one was also present in my previous e-mail. When I create the plot it has very large margins to the parent frame. This is not convenient to me, as I'd like to have a plot that is as large as possible and margins as small as possible. Is there a way to modify these margins? The other one is really new and it is related to printing. Is there a way to print directly from the library? I'm aware of the image save/image print combo and I can use it if I have no other option. However, at this point my application (which is quite critical) blocks every task switching combination (ctrl+atl+del included, together with alt+tab and all the others) in order to force the user to use this application and ONLY this application. If I choose the "image save" option I'll be forced to give up this feature, and I don't want that, as I _KNOW_ that they'll start to play starcraft in a flash :) Unless there is some Python source somewhere that can send an image to the printer. I've been searching for it, but never found it. I also had this problem with PyPlot, that offers printing functions, but they don't seem to work :( (this was tested on two different printers). Then again, the "Print framework" sample from the wxPython 2.5.1.5 demo also crashed when trying to print, so I imagine that the printing support in wxPython is not at its best at this point :( If anybody has a solution for this, please let me know. Thank you all for your help. Bogdan >>>>> "Bogdan" == Bogdan Marinescu <bogdanal@b.astral.ro> writes: Bogdan> Hello all, First I want to apologize for sending this Bogdan> message to both lists, but I couldn't decide which one is Bogdan> more appropriate and I would like to have an answer as Bogdan> soon as possible. Hi Bogdan, Either list is appropriate for this kind of post. I think the users is slightly better because then other users who may have seen the error will get the benefit of the post and response. cross-posting will not speed up the response, but may delay it :-) Bogdan> I discovered matplotlib some while ago, but it wasn't Bogdan> until recently when I decided to integrate it into one of Bogdan> my programs, trying to replace PyPlot that doesn't have Bogdan> enough features for me. I downloaded and installed version Bogdan> 0.60.2. Your library seemed perfect, until I discovered Bogdan> some strange problems that prevented me from using it as Bogdan> this point :( Specifically, I'm reffering to the Bogdan> embedding_in_wx2.py example that I found in the 'examples' Bogdan> directory. I modified it as follows (sorry for inlining, Bogdan> but I don't know if the listserver accepts any Bogdan> attachements at all, I didn't use it before): Thanks for your example. I was able to trace the segfault (exposed on win32 but not linux in my tests) to agg.tostring_rgb, as you noted. On window maximizing, there was an uncaught memory allocation error because I was allocating on the stack rather than the heap. This is fixed, and your (modified) example now runs fine for me on win32. I've built a snapshot of matplotlib-0.61 for you and uploaded it to http://nitace.bsd.uchicago.edu:8080/files/share/matplotlib-0.61.0a.win32-py2 .3.exe You'll notice a few changes: a new navigation toolbar - see http://sourceforge.net/mailarchive/forum.php?thread_id=5173059&forum_id=3618 7 for a discussion of the new icons, what they do, and how to get the old toolbar if you want it. As before, you can also just comment out the set_toolbar line to remove the toolbar completely. Also, the event handling mechanism has been changed as part of the process of making this more generic and useful. You now call mpl_connect rather than connect and your callback takes a single argument. For example, if you want to know where the user clicks a mouse on your figure, you define a function def click(event): print 'you clicked', event.x, event.y and register this function with the event handler canvas.mpl_connect('button_press_event', click) Then whenever the user clicks anywhere on the figure canvas, your function will be called and passed a matplotlib.backend_bases.MplEvent instance. The event instance has the following attributes defined. name # the event name canvas # the FigureCanvas instance generating the event x # x position - pixels from left of canvas y # y position - pixels from bottom of canvas button # button pressed None, 1, 2, 3 inaxes # the Axes instance if mouse us over axes xdata # x coord of mouse in data coords ydata # y coord of mouse in data coords You can currently connect to the following events: 'button_press_event', button_release_event', 'motion_notify_event' and I plan to add key press. Below is your example, modified to work with 0.61. I fixed the event handling and took out the onpaint connection from init (this did some funky things in my win32 tests) Let me know how it goes: you're the first 0.61 crash test dummy. Anyone else who wants to try this please feel free - the new toolbar only works with GTK* and WX* in this snapshot. #!/usr/bin/env python """ An example of how to use wx or wxagg in an application w. or w/o the toolbar """ import matplotlib matplotlib.use('WXAgg') from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas from matplotlib.backends.backend_wx import NavigationToolbar2Wx from matplotlib.figure import Figure from matplotlib.numerix import arange, sin, pi from wxPython.wx import * class Cursor: def __init__(self, canvas, ax): self.canvas = canvas self.ax = ax def mouse_move(self, event): x, y = event.x, event.y if event.inaxes: ax = event.inaxes minx, maxx = ax.get_xlim() miny, maxy = ax.get_ylim() print 'x=%1.2f, y=%1.2f'%(event.xdata, event.ydata) class CanvasFrame(wxFrame): def __init__(self): wxFrame.__init__(self,None,-1, 'CanvasFrame',size=( 900,900 ) ) self.SetBackgroundColour(wxNamedColor("WHITE")) self.figure = Figure( ) self.axes = self.figure.add_subplot(111) t = arange(0.0,3.0,0.01) s = sin(2*pi*t) c = sin(4*pi*t) p = self.axes.fill(t,s,'b',t,c,'g') p[ 0 ].set_alpha( 0.2 ) p[ 1 ].set_alpha( 0.2 ) #p = self.axes.fill(t,s,'b') #p[ 0 ].set_alpha( 0.2 ) #p[ 1 ].set_alpha( 0.2 ) #self.axes.plot(t,c,'g') self.axes.vlines( [1.5], -1.0, 1.0 ) self.canvas = FigureCanvas(self, -1, self.figure) self.sizer = wxBoxSizer(wxVERTICAL) self.sizer.Add(self.canvas, 1, wxTOP | wxLEFT | wxEXPAND) self.SetSizer(self.sizer) self.SetAutoLayout( True ) self.sizer.Fit( self ) cursor = Cursor(self.canvas, self.axes) #cursor = SnaptoCursor(canvas, ax, t, s) self.canvas.mpl_connect('motion_notify_event', cursor.mouse_move) self.add_toolbar() # comment this out for no toolbar # Capture the paint message #EVT_PAINT(self, self.OnPaint) EVT_SIZE( self, self.OnSize) def add_toolbar(self): self.toolbar = NavigationToolbar2Wx(self.canvas) self.toolbar.Realize() if wxPlatform == '__WXMAC__': # Mac platform (OSX 10.3, MacPython) does not seem to cope with # having a toolbar in a sizer. This work-around gets the buttons # back, but at the expense of having the toolbar at the top self.SetToolBar(self.toolbar) else: # On Windows platform, default window size is incorrect, so set # toolbar width to figure width. tw, th = self.toolbar.GetSizeTuple() fw, fh = self.canvas.GetSizeTuple() # By adding toolbar in sizer, we are able to put it at the bottom # of the frame - so appearance is closer to GTK version. # As noted above, doesn't work for Mac. self.toolbar.SetSize(wxSize(fw, th)) self.sizer.Add(self.toolbar, 0, wxLEFT | wxEXPAND) # update the axes menu on the toolbar self.toolbar.update() def OnSize( self, event ): print "OnSize" print event.GetSize() event.Skip() # event.Skip() class App(wxApp): def OnInit(self): 'Create the main window and insert the custom frame' frame = CanvasFrame() frame.Show(true) return true app = App(0) app.MainLoop() |
From: John H. <jdh...@ac...> - 2004-07-22 12:48:24
|
>>>>> "Marinescu" == Marinescu Bogdan-bmarine1 <bog...@fr...> writes: Marinescu> Hi John, Thanks for the quick reply, I was really Marinescu> happy to download the snapshot and see that it works. I Marinescu> tested in on wxPython 2.5.1.5 without problems, it Marinescu> would probably work the same on 2.4.2.4. I'm not quite Marinescu> familiar with the toolbar functions, so I don't know if Marinescu> the results I'm getting are right. The "home" button Marinescu> seems to do something, I can see a visual indication of Marinescu> the repaint when I press it. On the other hand, the Marinescu> "pan" button seems to be disabled; even if I can press Marinescu> it, I'm unable to select it (or it isn't supposed to be Marinescu> selectable?) Maybe this is normal for the example that Marinescu> you sent in your e-mail? Because of this, I can't test Marinescu> the functionality of the back/forward buttons. The Marinescu> "zoom to rect" button also seems to be disable, Marinescu> probably because I didn't use the zoom function, which Marinescu> is also related to the "pan" button, if I understand it Marinescu> correctly. The "save" button worked when trying to save Marinescu> a PNG image, but the program exited with a "Do not know Marinescu> know to handle extension *.jpg" message printed on the Marinescu> console when trying to save a JPG image. Again, I don't Marinescu> know if this behavior is correct or not, I'm just Marinescu> posting my results. These buttons don't do what you think they do because they all work very differently from the classic matplotlib toolbar (else why introduce a new one!) The Forward and Back buttons are akin to the web browser forward and back buttons. They are used to navigate back and forth between previously defined views. They have no meaning unless you have already navigated somewhere else using the pan and zoom buttons. This is analogous to trying to click 'back' on your web browser before visiting a new page. Nothing happens. 'Home' always takes you to the first view. For Home, Forward and Back, think web browser where data views are web pages. Use the pan and zoom to rectangle to define new views. The "Pan" button has two modes: pan and zoom. Click this toolbar button to activate this mode. Then put your mouse somewhere over an axes. Mode 1: Press the left mouse button and hold it, dragging it to a new position. When you release it, the data under the point where you pressed will be moved to the point where you released. Mode 2: Press the right mouse button, dragging it to a new position. The x axis will be zoomed in proportionate to the rightward movement and zoomed out proportionate to the leftward movement. Ditto for the yaxis and up/down motions. The Zoom to rectangle button: Click this toolbar button to activate this mode. Put your mouse somewhere over and axes and press the left mouse button. Drag the mouse while holding the button to a new location and release. The axes view limits will be zoomed to the rectangle you have defined. Save: click this button to launch a file save dialog. All the *Agg backends know how to save the following image types: PNG, PS, EPS, SVG. There is no support currently in Agg for writing to JPEG, TIFF (the regular wx and gtk backends handle these types). It is possible to use matplotlib/agg + PIL to convert agg images to one of these other formats if required. I can provide a recipe for you. I prefer PNG over JPG and TIFF, which is why I haven't worked too hard to include these other image formats in agg. Marinescu> I don't plan on using the toolbar Marinescu> in my application, I have another (specialized) toolbar Marinescu> and I'll be using its functions. OK, perhaps you could give it one more time just to make sure my instructions above are clear and that it is working fine on your system? Marinescu> The new event handling mechanism is great and it's Marinescu> exactly what I needed. However, I have a couple of Marinescu> fresh new questions for you :) The first one was also Marinescu> present in my previous e-mail. When I create the plot Marinescu> it has very large margins to the parent frame. This is Marinescu> not convenient to me, as I'd like to have a plot that Marinescu> is as large as possible and margins as small as Marinescu> possible. Is there a way to modify these margins? Yes, you can position axes anywhere you want in any size using the axes command. See http://matplotlib.sf.net/matplotlib.matlab.html#-axes and the example http://matplotlib.sf.net/examples/axes_demo.py. Marinescu> The other one is really new and it is related to Marinescu> printing. Is there a way to print directly from the Marinescu> library? I'm aware of the image save/image print combo Marinescu> and I can use it if I have no other option. However, at Marinescu> this point my application (which is quite critical) Marinescu> blocks every task switching combination (ctrl+atl+del Marinescu> included, together with alt+tab and all the others) in Marinescu> order to force the user to use this application and Marinescu> ONLY this application. If I choose the "image save" Marinescu> option I'll be forced to give up this feature, and I Marinescu> don't want that, as I _KNOW_ that they'll start to play Marinescu> starcraft in a flash :) Unless there is some Python Marinescu> source somewhere that can send an image to the Marinescu> printer. I've been searching for it, but never found Marinescu> it. I also had this problem with PyPlot, that offers Marinescu> printing functions, but they don't seem to work :( Marinescu> (this was tested on two different printers). Then Marinescu> again, the "Print framework" sample from the wxPython Marinescu> 2.5.1.5 demo also crashed when trying to print, so I Marinescu> imagine that the printing support in wxPython is not at Marinescu> its best at this point :( If anybody has a solution for Marinescu> this, please let me know. Thank you all for your help. cross platform printing is pretty hard, and cross-gui/cross-platform printing is event harder. If you get wx printing figured out and want to submit some code, I'd be happy to include it. When I was initially trying to decide on a GUI for my own application work, poor printing support in wx the thing that initially steered me to GTK. JDH |
From: Bogdan M. <bog...@gm...> - 2004-07-22 13:18:16
|
Ok, I tested the toolbar again and this time everything is fine. I guess that I was distracted by the fact that the "Pan" and "Zoom to rectangle" buttons don't look as they are pressed when I press them :) I mean, they don't change their visual appearance. They look like normal buttons, but they should probably be toggle buttons. Apart from that, everything else is fine. I don't need a recipe for JPG, i also prefer PNG, i just signaled this because I thought it was a problem. For printing ... I don't know :( I'll try to post a question to the wx list and come back to you all if I receive a solution. Thank you very much for your support. Yes, again :) Bogdan On Thu, 22 Jul 2004 07:24:21 -0500, John Hunter <jdh...@ac...> wrote: > >>>>> "Marinescu" == Marinescu Bogdan-bmarine1 <bog...@fr...> writes: > > Marinescu> Hi John, Thanks for the quick reply, I was really > Marinescu> happy to download the snapshot and see that it works. I > Marinescu> tested in on wxPython 2.5.1.5 without problems, it > Marinescu> would probably work the same on 2.4.2.4. I'm not quite > Marinescu> familiar with the toolbar functions, so I don't know if > Marinescu> the results I'm getting are right. The "home" button > Marinescu> seems to do something, I can see a visual indication of > Marinescu> the repaint when I press it. On the other hand, the > Marinescu> "pan" button seems to be disabled; even if I can press > Marinescu> it, I'm unable to select it (or it isn't supposed to be > Marinescu> selectable?) Maybe this is normal for the example that > Marinescu> you sent in your e-mail? Because of this, I can't test > Marinescu> the functionality of the back/forward buttons. The > Marinescu> "zoom to rect" button also seems to be disable, > Marinescu> probably because I didn't use the zoom function, which > Marinescu> is also related to the "pan" button, if I understand it > Marinescu> correctly. The "save" button worked when trying to save > Marinescu> a PNG image, but the program exited with a "Do not know > Marinescu> know to handle extension *.jpg" message printed on the > Marinescu> console when trying to save a JPG image. Again, I don't > Marinescu> know if this behavior is correct or not, I'm just > Marinescu> posting my results. > > These buttons don't do what you think they do because they all work > very differently from the classic matplotlib toolbar (else why > introduce a new one!) > > The Forward and Back buttons are akin to the web browser forward and > back buttons. They are used to navigate back and forth between > previously defined views. They have no meaning unless you have > already navigated somewhere else using the pan and zoom buttons. This > is analogous to trying to click 'back' on your web browser before > visiting a new page. Nothing happens. 'Home' always takes you to the > first view. For Home, Forward and Back, think web browser where data > views are web pages. Use the pan and zoom to rectangle to define new > views. > > The "Pan" button has two modes: pan and zoom. Click this toolbar > button to activate this mode. Then put your mouse somewhere over an > axes. Mode 1: Press the left mouse button and hold it, dragging it to > a new position. When you release it, the data under the point where > you pressed will be moved to the point where you released. Mode 2: > Press the right mouse button, dragging it to a new position. The x > axis will be zoomed in proportionate to the rightward movement and > zoomed out proportionate to the leftward movement. Ditto for the > yaxis and up/down motions. > > The Zoom to rectangle button: Click this toolbar button to activate > this mode. Put your mouse somewhere over and axes and press the left > mouse button. Drag the mouse while holding the button to a new > location and release. The axes view limits will be zoomed to the > rectangle you have defined. > > Save: click this button to launch a file save dialog. All the *Agg > backends know how to save the following image types: PNG, PS, EPS, > SVG. There is no support currently in Agg for writing to JPEG, TIFF > (the regular wx and gtk backends handle these types). It is possible > to use matplotlib/agg + PIL to convert agg images to one of these > other formats if required. I can provide a recipe for you. I prefer > PNG over JPG and TIFF, which is why I haven't worked too hard to > include these other image formats in agg. > > Marinescu> I don't plan on using the toolbar > Marinescu> in my application, I have another (specialized) toolbar > Marinescu> and I'll be using its functions. > > OK, perhaps you could give it one more time just to make sure my > instructions above are clear and that it is working fine on your > system? > > Marinescu> The new event handling mechanism is great and it's > Marinescu> exactly what I needed. However, I have a couple of > Marinescu> fresh new questions for you :) The first one was also > Marinescu> present in my previous e-mail. When I create the plot > Marinescu> it has very large margins to the parent frame. This is > Marinescu> not convenient to me, as I'd like to have a plot that > Marinescu> is as large as possible and margins as small as > Marinescu> possible. Is there a way to modify these margins? > > Yes, you can position axes anywhere you want in any size using the > axes command. See > http://matplotlib.sf.net/matplotlib.matlab.html#-axes and the example > http://matplotlib.sf.net/examples/axes_demo.py. > > Marinescu> The other one is really new and it is related to > Marinescu> printing. Is there a way to print directly from the > Marinescu> library? I'm aware of the image save/image print combo > Marinescu> and I can use it if I have no other option. However, at > Marinescu> this point my application (which is quite critical) > Marinescu> blocks every task switching combination (ctrl+atl+del > Marinescu> included, together with alt+tab and all the others) in > Marinescu> order to force the user to use this application and > Marinescu> ONLY this application. If I choose the "image save" > Marinescu> option I'll be forced to give up this feature, and I > Marinescu> don't want that, as I _KNOW_ that they'll start to play > Marinescu> starcraft in a flash :) Unless there is some Python > Marinescu> source somewhere that can send an image to the > Marinescu> printer. I've been searching for it, but never found > Marinescu> it. I also had this problem with PyPlot, that offers > Marinescu> printing functions, but they don't seem to work :( > Marinescu> (this was tested on two different printers). Then > Marinescu> again, the "Print framework" sample from the wxPython > Marinescu> 2.5.1.5 demo also crashed when trying to print, so I > Marinescu> imagine that the printing support in wxPython is not at > Marinescu> its best at this point :( If anybody has a solution for > Marinescu> this, please let me know. Thank you all for your help. > > cross platform printing is pretty hard, and cross-gui/cross-platform > printing is event harder. If you get wx printing figured out and want > to submit some code, I'd be happy to include it. When I was initially > trying to decide on a GUI for my own application work, poor printing > support in wx the thing that initially steered me to GTK. > > JDH > > ------------------------------------------------------- > This SF.Net email is sponsored by BEA Weblogic Workshop > FREE Java Enterprise J2EE developer tools! > Get your free copy of BEA WebLogic Workshop 8.1 today. > http://ads.osdn.com/?ad_id=4721&alloc_id=10040&op=click > _______________________________________________ > Matplotlib-users mailing list > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > -- Bogdan |