Popular recipes by s_h_a_i_o http://code.activestate.com/recipes/users/4177334/2011-09-30T10:46:21-07:00ActiveState Code RecipesConvert Image Format (Python)
2011-09-30T10:46:21-07:00s_h_a_i_ohttp://code.activestate.com/recipes/users/4177334/http://code.activestate.com/recipes/577886-convert-image-format/
<p style="color: grey">
Python
recipe 577886
by <a href="/recipes/users/4177334/">s_h_a_i_o</a>
(<a href="/recipes/tags/convert/">convert</a>, <a href="/recipes/tags/format/">format</a>, <a href="/recipes/tags/image/">image</a>).
Revision 2.
</p>
<p>Simple GUI to allow converting images from one format to another. Available formats are: .gif .jpg .png .tif .bmp Uses PIL.</p>
<p>This is short and direct enhancement from recipe <a href="http://code.activestate.com/recipes/180801-convert-image-format" rel="nofollow">http://code.activestate.com/recipes/180801-convert-image-format</a>. Two new features added:</p>
<ul>
<li>Optional deletion of the original image files.</li>
<li>Optional recursive file selection. Implemented using <a href="http://code.activestate.com/recipes/577230-file-path-generator-from-path-patterns/" rel="nofollow">http://code.activestate.com/recipes/577230-file-path-generator-from-path-patterns/</a></li>
</ul>
<p><strong>note</strong> This assumes recipe/577230 is located in filePattern.py (see first import below)</p>
Conditionnal Breakpoint (Python)
2011-09-20T18:49:23-07:00s_h_a_i_ohttp://code.activestate.com/recipes/users/4177334/http://code.activestate.com/recipes/577874-conditionnal-breakpoint/
<p style="color: grey">
Python
recipe 577874
by <a href="/recipes/users/4177334/">s_h_a_i_o</a>
(<a href="/recipes/tags/breakpoint/">breakpoint</a>, <a href="/recipes/tags/debug/">debug</a>).
Revision 2.
</p>
<p>Decorates a class so that it encounters a breakpoint for any call to class.method_name(self,<em>args,</em>*kwargs), where</p>
<ul>
<li>method_name is given by string</li>
<li>only if arguments meet a test: arg_test(self,<em>args,</em>*kwargs) -> bool [default -> True]</li>
</ul>
<p>Behaviour easily changed for other actions than breakpoint (logging,...)</p>
edit dictionary values (possibly restrained) with Tkinter (Python)
2011-03-15T21:37:54-07:00s_h_a_i_ohttp://code.activestate.com/recipes/users/4177334/http://code.activestate.com/recipes/577611-edit-dictionary-values-possibly-restrained-with-tk/
<p style="color: grey">
Python
recipe 577611
by <a href="/recipes/users/4177334/">s_h_a_i_o</a>
(<a href="/recipes/tags/edit/">edit</a>, <a href="/recipes/tags/gui/">gui</a>, <a href="/recipes/tags/in/">in</a>, <a href="/recipes/tags/options/">options</a>).
</p>
<p>The behaviour of applications sometimes depends on various parameters that can be chosen by the user through some GUI. Quite often, these parameters need take value in a predefined set. Parameters include for instance:</p>
<ul>
<li>The number of replications for a simulator.</li>
<li>Dates of beginning/end of sample for time series access/plot.</li>
<li>Log writing</li>
</ul>
<p>This recipe assumes that</p>
<ul>
<li>Such parameters are stored in a dictionary. Values in the dictionnary are used as initial values for the parameters.</li>
<li>Values are "singleton", i.e non iterable (although they may be strings).</li>
<li>When a value is a list instance, its content represent the set of possible values
The recipe offers a simple way to edit the values in a Tkinter Frame, by adding proper widget to it (constrained value are menubutton while unconstrained values are edit widgets).</li>
</ul>
<p>This is done by the function apply(frame,dict,position), which adds to the Tkinter frame the necessary widgets to edit the dictionary dict. Widgets are placed using grid (hence the frame needs use grid() too) and span on two columns. topleft position (x,y) in grid is specified using position= (x,y,0,0)</p>