On Sat, 2004年08月14日 at 11:42, mat...@li... wrote: > Hi, I searched for material related to this, but didn't find any, so I > hope this isn't a repeat. One feature that has been missing from > matplotlib that I find really useful is to print my graphs (I generate a > lot, and generally want a hard copy, but not a lot of random files lying > around). While on a unix system this is easy to do, I realize it is > rather difficult to make crossplatform. So instead I've been hacking the > source and adding my own button in. However, with each release this can > get a bit tiresome, so the idea occured to me that it would be nice if I > have a function to add buttons to the toolbar that could then run > arbritrary code. > > I can submit my code if anyone is interested (it's a very rough hack, > and only for the GTK backend), but the idea is that in my own code I can > just do: > > def myprint(*args, **kwargs): > fd, path = tempfile.mkstemp(suffix=".eps", dir="/tmp") > > savefig(path) > print "lpr %s" % path > os.system("lpr %s" % path) > > os.close(fd) > os.unlink(path) > > > and later on: > > add_toolbar_button("print", "prints figure", gtk.STOCK_PRINT, myprint) > > I was curious as to what other people thought of this, and whether it > had a chance of ending up in matplotlib (being able to add other widgets > besides buttons would be extra cool). Perhaps the .matplotlibrc file could have lines like printcommand: None printcommand: '"lpr %s" % path' And if printcommand is not None an extra toolbar button is created which calls os.system(printcommand) to print the file. Steve
>>>>> "Steve" == Steve Chaplin <ste...@ya...> writes: Steve> Perhaps the .matplotlibrc file could have lines like Steve> printcommand: None printcommand: '"lpr %s" % path' And if Steve> printcommand is not None an extra toolbar button is created Steve> which calls os.system(printcommand) to print the file. This is a good idea, perhaps the rc param should be savefig.printcommand. There was a post on the users list which contained some help on how to print from wx on win32. Anyone want to take the lead here? JDH
What might be a cool extension on this idea, would be the ability to specify 'plugin' actions to add to the toolbar: toolbar.buttons : (name, tooltip, image, function), (name, tooltip, image, function) The difficulty would specifying which modules to load. One simple approach might be to have a directory called 'plugins', in which all modules automatically get loaded. I think this would take about the same amount of code as hard-coding a single printer option in, and might allow more flexibility (easier to add/remove buttons, and easier to change what action they perform). I wrote a quick patch (attached to the email) which allows for two new rc params: plugins.directory : <directory> any file in this directory ending in '.py' is automatically imported toolbars.buttons: (name, tooltip, image, function), ... a list of the tuples is created I didn't edit any of the backend code yet, but it should be trivial (at least in the case of the gtk backend) to convert 'toolitems' to an array, and then "if matplotlib.rcParams['toolbar.buttons']: toolitems.extend(matplotlib.rcParams['toolbar.buttons'])" Abe John Hunter wrote: >>>>>>"Steve" == Steve Chaplin <ste...@ya...> writes: >>>>>> >>>>>> > > Steve> Perhaps the .matplotlibrc file could have lines like > Steve> printcommand: None printcommand: '"lpr %s" % path' And if > Steve> printcommand is not None an extra toolbar button is created > Steve> which calls os.system(printcommand) to print the file. > >This is a good idea, perhaps the rc param should be >savefig.printcommand. There was a post on the users list which >contained some help on how to print from wx on win32. > >Anyone want to take the lead here? > >JDH > > >------------------------------------------------------- >SF.Net email is sponsored by Shop4tech.com-Lowest price on Blank Media >100pk Sonic DVD-R 4x for only 29ドル -100pk Sonic DVD+R for only 33ドル >Save 50% off Retail on Ink & Toner - Free Shipping and Free Gift. >http://www.shop4tech.com/z/Inkjet_Cartridges/9_108_r285 >_______________________________________________ >Matplotlib-devel mailing list >Mat...@li... >https://lists.sourceforge.net/lists/listinfo/matplotlib-devel > >
Abraham Schneider wrote: > What might be a cool extension on this idea, would be the ability to > specify 'plugin' actions to add to the toolbar: > > toolbar.buttons : (name, tooltip, image, function), (name, tooltip, > image, function) > > The difficulty would specifying which modules to load. One simple > approach might be to have a directory called 'plugins', in which all > modules automatically get loaded. +1 Note that this should be specifyable as a colon-separated search path where matplotlib can look for all available plugins. This allows users to extend their local installation with custom things which survive across system-wide upgrades. I recently patched MayaVi to do exactly this with Filters and Modules (it's in the mayavi CVS already), and it's extremely useful. In mayavi, any directory in the mayavi search path is scanned for a subdir called Filters/ and one called Modules/. Any .py file found there is added to the User submenu of Mayavi's main Filters and Modules menus. With this system, local user extensions become automatically available to the GUI. In scripts, they can be loaded with a prepended 'User.' string: load_module('Glyphs') -> loads MayaVi's Glyphs module load_module('User.Glyphs') -> loads a users's customized Glyphs module, without clashing with the system-wide one. I think this approach is very useful, esp. because it allows research groups to have directories of common functionality useful to their projects, and individual users can still add their own particular Filters/Modules. Best, f