Popular recipes tagged "meta:loc=72"http://code.activestate.com/recipes/tags/meta:loc=72/2017-05-05T20:33:31-07:00ActiveState Code Recipesbind all tkinter "bug" (Python)
2017-05-05T20:33:31-07:00Miguel Martínez Lópezhttp://code.activestate.com/recipes/users/4189907/http://code.activestate.com/recipes/580795-bind-all-tkinter-bug/
<p style="color: grey">
Python
recipe 580795
by <a href="/recipes/users/4189907/">Miguel Martínez López</a>
(<a href="/recipes/tags/all/">all</a>, <a href="/recipes/tags/bind/">bind</a>, <a href="/recipes/tags/binding/">binding</a>, <a href="/recipes/tags/tkinter/">tkinter</a>).
Revision 3.
</p>
<p>This recipes tries to solve the problem of bind_all and unbind_all for tkinter.</p>
<p>When a callback is registered using bind_all method and later it's unregistered using unbind_all, all the callbacks are deleted for the "all" tag event. This makes difficult to register and unregister only one callback at a time. This recipes tries to solve this problem.</p>
<p>Observe the difference between the code below and the recipe. With the code below, when the user clicks nothing happens. But with my recipe it's possible to bind and unbind specific callbacks.</p>
<pre class="prettyprint"><code>try:
from Tkinter import Tk, Frame
except ImportError:
from tkinter import Tk, Frame
root = Tk()
f = Frame(root, width= 300, height=300)
f.pack()
def callback1(event):
print("callback1")
def callback2(event):
print("callback2")
def callback3(event):
print("callback3")
root.bind_all("<1>", callback1, add="+")
f.bind_all("<1>", callback2, add="+")
f.bind_all("<1>", callback3, add="+")
f.unbind_all("<1>")
root.mainloop()
</code></pre>
A command-line musical alarm clock (Python)
2016-12-30T19:06:32-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580739-a-command-line-musical-alarm-clock/
<p style="color: grey">
Python
recipe 580739
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/alarm/">alarm</a>, <a href="/recipes/tags/audio/">audio</a>, <a href="/recipes/tags/clock/">clock</a>, <a href="/recipes/tags/multimedia/">multimedia</a>, <a href="/recipes/tags/music/">music</a>, <a href="/recipes/tags/playsound/">playsound</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/time/">time</a>, <a href="/recipes/tags/utilities/">utilities</a>, <a href="/recipes/tags/utility/">utility</a>).
</p>
<p>This is a simple musical alarm clock in Python. You pass a command-line argument specifying the time in minutes after which the alarm should go off. When that time arrives, it plays a musical sound.</p>
Analog clock (Python)
2013-10-11T05:25:34-07:00greg zakharovhttp://code.activestate.com/recipes/users/4184115/http://code.activestate.com/recipes/578683-analog-clock/
<p style="color: grey">
Python
recipe 578683
by <a href="/recipes/users/4184115/">greg zakharov</a>
(<a href="/recipes/tags/analog/">analog</a>, <a href="/recipes/tags/clock/">clock</a>).
</p>
<p>Analog clock with Qt4</p>
Youtube Playlist Parser/Extractor (Python)
2014-07-30T07:23:36-07:00p@ntut$http://code.activestate.com/recipes/users/4183895/http://code.activestate.com/recipes/578284-youtube-playlist-parserextractor/
<p style="color: grey">
Python
recipe 578284
by <a href="/recipes/users/4183895/">p@ntut$</a>
(<a href="/recipes/tags/extractor/">extractor</a>, <a href="/recipes/tags/playlist/">playlist</a>, <a href="/recipes/tags/youtube/">youtube</a>).
Revision 18.
</p>
<p>Parse/extract URLs from playlist in youtube (User's videos not favorites)
Link: <a href="http://pantuts.com/2013/02/16/youparse-extract-urls-from-youtube/" rel="nofollow">http://pantuts.com/2013/02/16/youparse-extract-urls-from-youtube/</a></p>
Immutable Type Hierarchies (Python)
2010-10-11T23:32:31-07:00Aaron Sterlinghttp://code.activestate.com/recipes/users/4174675/http://code.activestate.com/recipes/577424-immutable-type-hierarchies/
<p style="color: grey">
Python
recipe 577424
by <a href="/recipes/users/4174675/">Aaron Sterling</a>
(<a href="/recipes/tags/abc/">abc</a>, <a href="/recipes/tags/hierarchy/">hierarchy</a>, <a href="/recipes/tags/immutable/">immutable</a>).
Revision 4.
</p>
<p>Allows for type hierarchies of immutable types by faking inheritance using dict updates and abc's.</p>
Snowflake Fractal Applet using Cellular Automaton (Java)
2010-07-17T00:42:13-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/577311-snowflake-fractal-applet-using-cellular-automaton/
<p style="color: grey">
Java
recipe 577311
by <a href="/recipes/users/4172570/">FB36</a>
(<a href="/recipes/tags/applet/">applet</a>, <a href="/recipes/tags/fractal/">fractal</a>, <a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/math/">math</a>).
</p>
<p>Snowflake fractal applet using Cellular Automaton (2d CA). </p>
Path entire split & commonprefix (Python)
2011-04-06T20:29:46-07:00Maxime Fontenierhttp://code.activestate.com/recipes/users/4172150/http://code.activestate.com/recipes/577016-path-entire-split-commonprefix/
<p style="color: grey">
Python
recipe 577016
by <a href="/recipes/users/4172150/">Maxime Fontenier</a>
(<a href="/recipes/tags/commonprefix/">commonprefix</a>, <a href="/recipes/tags/path/">path</a>, <a href="/recipes/tags/split/">split</a>).
Revision 5.
</p>
<p>This recipe is a kind of extension to os.path
It offers an entire split function and a true commonprefix for paths.</p>
Low level inotify wrapper (Python)
2013-08-12T14:39:57-07:00Louis RIVIEREhttp://code.activestate.com/recipes/users/4035877/http://code.activestate.com/recipes/576375-low-level-inotify-wrapper/
<p style="color: grey">
Python
recipe 576375
by <a href="/recipes/users/4035877/">Louis RIVIERE</a>
(<a href="/recipes/tags/ctypes/">ctypes</a>, <a href="/recipes/tags/inotify/">inotify</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/system/">system</a>).
Revision 10.
</p>
<p>This module is meant to be as simple and straightforward as it gets.</p>
Indirect insertion of value to a list (Python)
2008-03-29T21:20:52-07:00Ernesto Adoriohttp://code.activestate.com/recipes/users/2765793/http://code.activestate.com/recipes/552742-indirect-insertion-of-value-to-a-list/
<p style="color: grey">
Python
recipe 552742
by <a href="/recipes/users/2765793/">Ernesto Adorio</a>
(<a href="/recipes/tags/algorithms/">algorithms</a>).
</p>
<p>The code to insert a value to a list indirectly ordered by an extra index list is useful by itself.</p>
Simple file ziping utility (Python)
2007-11-06T04:45:50-08:00trevellyon newellhttp://code.activestate.com/recipes/users/4097787/http://code.activestate.com/recipes/534157-simple-file-ziping-utility/
<p style="color: grey">
Python
recipe 534157
by <a href="/recipes/users/4097787/">trevellyon newell</a>
(<a href="/recipes/tags/files/">files</a>).
</p>
<p>After searching the web, ASPN and not finding a simple example of using gzip to zip a file. I created this little gem. it is a little rough at the edges, ie it does not check to see if the file it is zipping to is there (it will over write it, you have been warned).</p>
Walker encapsulates os.walk for easy reuse (Python)
2007-08-29T15:07:29-07:00Jack Trainorhttp://code.activestate.com/recipes/users/4076953/http://code.activestate.com/recipes/528904-walker-encapsulates-oswalk-for-easy-reuse/
<p style="color: grey">
Python
recipe 528904
by <a href="/recipes/users/4076953/">Jack Trainor</a>
(<a href="/recipes/tags/files/">files</a>).
Revision 2.
</p>
<p>Walker encapsulates os.walk's directory traversal as an object with the added features of excluded directories and a hook for calling an outside function to act on each file.</p>
<p>Walker can easily be subclassed for more functionality, as with ReWalker which filters filenames in traversal by a regular expression.</p>
Ordered Dictionary that works (Python)
2007-06-07T03:43:09-07:00Anand Chitipothuhttp://code.activestate.com/recipes/users/4060561/http://code.activestate.com/recipes/521893-ordered-dictionary-that-works/
<p style="color: grey">
Python
recipe 521893
by <a href="/recipes/users/4060561/">Anand Chitipothu</a>
.
</p>
<p>A dictionary in which the insertion order of items is preserved.</p>
<p>Based on Doug Winter's recipe <a href="http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/438823" rel="nofollow">http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/438823</a></p>
recursively update a dictionary without hitting "Python recursion limit" (Python)
2006-12-21T10:28:56-08:00Robin Brycehttp://code.activestate.com/recipes/users/4020598/http://code.activestate.com/recipes/499335-recursively-update-a-dictionary-without-hitting-py/
<p style="color: grey">
Python
recipe 499335
by <a href="/recipes/users/4020598/">Robin Bryce</a>
.
Revision 3.
</p>
<p>This function recursively walks the items and values of two dict like objects. At each level when a key exists in both, and each value is a dict, then the destination dict is updated from the source dict usiing the builtin dict.update method. After the operation all keys and values from the source, at any level, will be referenced in the destination.</p>
Rich iterator wrapper (Python)
2006-11-19T00:03:21-08:00George Sakkishttp://code.activestate.com/recipes/users/2591466/http://code.activestate.com/recipes/498272-rich-iterator-wrapper/
<p style="color: grey">
Python
recipe 498272
by <a href="/recipes/users/2591466/">George Sakkis</a>
(<a href="/recipes/tags/oop/">oop</a>).
</p>
<p>This recipe may be of interest to those who make heavy use of the itertools module. It provides a wrapper class that exposes most itertools functions as methods, plus a few more. Moreover, two frequently used itertools functions, chain and islice, are conveniently exposed as addition and slicing operators, respectively.</p>
Sudoku Solver (Python)
2006-03-14T07:52:29-08:00Raymond Hettingerhttp://code.activestate.com/recipes/users/178123/http://code.activestate.com/recipes/473893-sudoku-solver/
<p style="color: grey">
Python
recipe 473893
by <a href="/recipes/users/178123/">Raymond Hettinger</a>
(<a href="/recipes/tags/algorithms/">algorithms</a>).
Revision 5.
</p>
<p>Yet another solver. Uses knowns to eliminate possibilities, then tries assumptions from remaining possibilities (depth-first search with heuristic to first explore cells with the fewest unknowns).</p>
fancy rich comparisons and MAXIMUM ANY and MINIMUM objects... (Python)
2004-10-28T00:37:49-07:00Alex Naanouhttp://code.activestate.com/recipes/users/104183/http://code.activestate.com/recipes/325394-fancy-rich-comparisons-and-maximum-any-and-minimum/
<p style="color: grey">
Python
recipe 325394
by <a href="/recipes/users/104183/">Alex Naanou</a>
(<a href="/recipes/tags/algorithms/">algorithms</a>).
Revision 3.
</p>
<p>here we will see an example of template comparisons based on a logical ANY object.
also this recipe provides alternative implementations of the absolute maximum and minimum objects (for more details on them see PEP326 <a href="http://www.python.org/peps/pep-0326.html%29." rel="nofollow">http://www.python.org/peps/pep-0326.html).</a></p>
bubblebabble (Python)
2004-08-10T16:34:30-07:00Ralf Schmitthttp://code.activestate.com/recipes/users/1416275/http://code.activestate.com/recipes/299133-bubblebabble/
<p style="color: grey">
Python
recipe 299133
by <a href="/recipes/users/1416275/">Ralf Schmitt</a>
.
</p>
<p>This module provides a bubblebabble function, which computes a (somewhat more) human readable format for message digests.</p>
Caching and aliasing with descriptors (Python)
2004-04-05T03:59:01-07:00Denis Otkidachhttp://code.activestate.com/recipes/users/1732285/http://code.activestate.com/recipes/276643-caching-and-aliasing-with-descriptors/
<p style="color: grey">
Python
recipe 276643
by <a href="/recipes/users/1732285/">Denis Otkidach</a>
(<a href="/recipes/tags/oop/">oop</a>).
</p>
<p>A few simple discriptor classes to compute and cache attribute value on demand and to define attribute as alias to other.</p>
Install bound methods in an instance (Python)
2003-09-19T02:05:17-07:00john mclaughlinhttp://code.activestate.com/recipes/users/1376161/http://code.activestate.com/recipes/223613-install-bound-methods-in-an-instance/
<p style="color: grey">
Python
recipe 223613
by <a href="/recipes/users/1376161/">john mclaughlin</a>
.
</p>
<p>Python has an extremely flexible object model that allows for assignment of arbitrary objects to arbitrary attributes of instances. I would like to do something like this:
def button( self ): print "Pressed!"
and then assign it to an instance:
mywidget.bigred = button
and call it:
mywidget.bigred()</p>
<p>However this doesn't work because the attribute needs to be a bound method, not a function. Also, the name of the installed function remains button (eg. in stack traces), when we would like it to be bigred.</p>
<p>This recipe provides the installmethod() and renamefunction() functions to solve this problem.</p>
Making Date Input more interactive Variables for MySQL (PHP)
2003-06-30T14:04:56-07:00imam feriantohttp://code.activestate.com/recipes/users/633541/http://code.activestate.com/recipes/208104-making-date-input-more-interactive-variables-for-m/
<p style="color: grey">
PHP
recipe 208104
by <a href="/recipes/users/633541/">imam ferianto</a>
.
</p>
<p>If we want to store date_column in MySQL we must using
format 'YYYY-MM-DD' but we can build input form for this
tipe. Currenly I making this in Indonesian date but you
can modify your self.</p>