Created
August 4, 2010 12:57
-
-
Save odebeir/508087 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from enthought.enable.api import ComponentEditor, BaseTool | |
from enthought.chaco.api import ArrayPlotData, Plot, jet, gray, PlotGraphicsContext | |
from enthought.traits.api import HasTraits, Instance, Enum, Range, Dict, Button, Int, Bool, Str, Property,Event, Array, DelegatesTo, on_trait_change,List, Tuple | |
from enthought.traits.ui.api import Item, Group, View, InstanceEditor | |
def draw_plot(filename, container,size=(800,600)): | |
"""Render a plot to file""" | |
container.outer_bounds = list(size) | |
container.do_layout(force=True) | |
gc = PlotGraphicsContext(size, dpi=150) | |
gc.render_component(container) | |
gc.save(filename) | |
return | |
class GrabTool(HasTraits): | |
size = Tuple(799,599) | |
dpi = Range(10,600,72) | |
format = Str('snap%04d.png') | |
path = Str('../test/') | |
button_snap = Button('Snap !') | |
auto = Bool(False) | |
no = Int(0) | |
traits_view = View(Group( | |
Item("size"), | |
Item("dpi"), | |
Item("format"), | |
Item("path"), | |
Item("auto"), | |
Item("button_snap"),show_border = True | |
) | |
) | |
def __init__(self,container): | |
"""container is the plot to copy | |
""" | |
super(GrabTool,self).__init__() | |
self.container = container | |
def update(self,no): | |
self.no = no | |
if self.auto: | |
self._button_snap_changed() | |
def _button_snap_changed(self): | |
print 'snap' | |
filename = '%s'%self.path+self.format%self.no | |
container = self.container | |
size = self.size | |
bu = container.outer_bounds | |
container.outer_bounds = list(size) | |
container.do_layout(force=True) | |
gc = PlotGraphicsContext(size, dpi=self.dpi) | |
gc.render_component(container) | |
gc.save(filename) | |
container.outer_bounds = bu | |
container.do_layout(force=True) | |
gc.render_component(container) | |
if __name__ == '__main__': | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment