Hans Petter Langtangen 11 jaren geleden
bovenliggende
commit
e2ff1cfa82

BIN
doc/src/tut/src-tut/test/tmp_Arc.png


BIN
doc/src/tut/src-tut/test/tmp_Axis.png


BIN
doc/src/tut/src-tut/test/tmp_Dashpot.png


BIN
doc/src/tut/src-tut/test/tmp_Distance_wText.png


BIN
doc/src/tut/src-tut/test/tmp_Rectangle.png


BIN
doc/src/tut/src-tut/test/tmp_Spring.png


BIN
doc/src/tut/src-tut/test/tmp_Triangle.png


+ 5 - 4
pysketcher/MatplotlibDraw.py

@@ -57,7 +57,7 @@ class MatplotlibDraw:
         self.ax.set_ylim(minmax['ymin']-y_space/2., minmax['ymax']+y_space/2.)
 
     def set_coordinate_system(self, xmin, xmax, ymin, ymax, axis=False,
-                              instruction_file=None):
+                              instruction_file=None, new_figure=True):
         """
         Define the drawing area [xmin,xmax]x[ymin,ymax].
         axis: None or False means that axes with tickmarks
@@ -111,7 +111,7 @@ mpl.ion()  # for interactive drawing
         self.set_fontsize(14)
         self.arrow_head_width = 0.2*self.xrange/16
 
-        self._make_axes(new_figure=True)
+        self._make_axes(new_figure=new_figure)
 
         manager = self.mpl.get_current_fig_manager()
         manager.window.wm_geometry(geometry)
@@ -323,14 +323,15 @@ self.ax.plot(x, y, linewidth=%d, color='gray',
 
 
 
-    def display(self, title=None):
+    def display(self, title=None, show=True):
         """Display the figure."""
         if title is not None:
             self.mpl.title(title)
             if self.instruction_file:
                 self.instruction_file.write('mpl.title("%s")\n' % title)
 
-        self.mpl.draw()
+        if show:
+            self.mpl.draw()
 
         if self.instruction_file:
             self.instruction_file.write('mpl.draw()\n')

+ 19 - 3
pysketcher/shapes.py

@@ -98,7 +98,9 @@ def is_sequence(*sequences, **kwargs):
 
 
 def animate(fig, time_points, action, moviefiles=False,
-            pause_per_frame=0.5, **action_kwargs):
+            pause_per_frame=0.5, show_screen_graphics=True,
+            title=None,
+            **action_kwargs):
     if moviefiles:
         # Clean up old frame files
         framefilestem = 'tmp_frame_'
@@ -119,7 +121,7 @@ def animate(fig, time_points, action, moviefiles=False,
         #        '(a Shape object with the whole figure)')
 
         fig.draw()
-        drawing_tool.display()
+        drawing_tool.display(title=title, show=show_screen_graphics)
 
         if moviefiles:
             drawing_tool.savefig('%s%04d.png' % (framefilestem, n))
@@ -183,7 +185,21 @@ class Shape:
                             (name, self.__class__.__name__))
                     return self.shapes[shape][name]
         else:
-            raise Exception('This is a bug')
+            raise Exception('This is a bug in __getitem__')
+
+    def __setitem__(self, name, value):
+        """
+        Allow assignment like::
+
+           obj1['name1']['name2'] = value
+
+        all the way down to ``Curve`` or ``Point`` (``Text``)
+        objects.
+        """
+        if hasattr(self, 'shapes'):
+            self.shapes[name] = value
+        else:
+            raise Exception('Cannot assign')
 
 
     def _for_all_shapes(self, func, *args, **kwargs):