Popular recipes tagged "meta:loc=161"http://code.activestate.com/recipes/tags/meta:loc=161/2017-04-08T12:27:36-07:00ActiveState Code RecipesTkinter search box (Python)
2017-04-08T12:27:36-07:00Miguel Martínez Lópezhttp://code.activestate.com/recipes/users/4189907/http://code.activestate.com/recipes/580773-tkinter-search-box/
<p style="color: grey">
Python
recipe 580773
by <a href="/recipes/users/4189907/">Miguel Martínez López</a>
(<a href="/recipes/tags/entry/">entry</a>, <a href="/recipes/tags/search/">search</a>, <a href="/recipes/tags/searchbox/">searchbox</a>, <a href="/recipes/tags/tkinter/">tkinter</a>).
Revision 9.
</p>
<p>Instead of using two colors for active background and normal background, I use only one color and opacity parameter.</p>
<p>I trigger the feeling of a button using different colors when the mouse is and isn't over. Many modern HTML search boxes uses the same approach.</p>
<p>Command function receives text of entry box when button is pressed.</p>
strsignal (Python)
2014-06-29T15:47:24-07:00Zack Weinberghttp://code.activestate.com/recipes/users/4190298/http://code.activestate.com/recipes/578899-strsignal/
<p style="color: grey">
Python
recipe 578899
by <a href="/recipes/users/4190298/">Zack Weinberg</a>
(<a href="/recipes/tags/signals/">signals</a>).
</p>
<p>This is an emulation of the standard (POSIX.1-2008) C library function <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/strsignal.html"><code>strsignal()</code></a>, which should be in the <a href="https://docs.python.org/3/library/signal.html"><code>signal</code> module</a>, but isn't.</p>
<p>If possible, it uses <a href="https://docs.python.org/3/library/ctypes.html"><code>ctypes</code></a> to call the C library function; otherwise, it tries to build a reverse mapping of the <code>SIG*</code> constants in the signal module; if that doesn't work either, it just produces <code>"signal %d"</code> where <code>%d</code> is the decimal signal number.</p>
<p>If invoked as a script, will test all of the strategies and print the results.</p>
<p>Tested in 2.7 and 3.4; <em>should</em> work with 2.6 and 3.3 as well.</p>
Tracking and Manipulating the Python Import State (Python)
2012-04-22T07:27:29-07:00Eric Snowhttp://code.activestate.com/recipes/users/4177816/http://code.activestate.com/recipes/578107-tracking-and-manipulating-the-python-import-state/
<p style="color: grey">
Python
recipe 578107
by <a href="/recipes/users/4177816/">Eric Snow</a>
(<a href="/recipes/tags/import/">import</a>).
</p>
<p>This is a rough analog to the import engine described in PEP 406. Here I've called it ImportState.The focus here is on using it as a context manager to limit changes to the import state to a block of code (in a with statement). Differences from PEP 406 are described below.</p>
SimpleTron3x.py "Game" To DEMO XY Drawing Using The Keyboard In Standard Text Mode Python. (Python)
2011-05-29T14:28:19-07:00Barry Walkerhttp://code.activestate.com/recipes/users/4177147/http://code.activestate.com/recipes/577728-simpletron3xpy-game-to-demo-xy-drawing-using-the-k/
<p style="color: grey">
Python
recipe 577728
by <a href="/recipes/users/4177147/">Barry Walker</a>
(<a href="/recipes/tags/anim/">anim</a>, <a href="/recipes/tags/demo/">demo</a>, <a href="/recipes/tags/display/">display</a>, <a href="/recipes/tags/game/">game</a>, <a href="/recipes/tags/linux/">linux</a>).
</p>
<p>SimpleTron3x.py.</p>
<p>This code is a FUN program only to DEMO how to draw in a text mode Python shell.</p>
<p>There is an inkey() "function" extracted from a "class" recipe on this site.
See code for more information.</p>
<p>This was tested on PCLinuxOS 2009 with Python 3.0.x and Debian 6.0.0 with Python 3.1.x.</p>
<p>This ASSUMES an 80 x 24 Python shell window.</p>
<p>Issued as Public Domain, you may do as you like with this code.</p>
<p>Enjoy finding simple solutions to often very difficult problems.</p>
<p>Bazza...</p>
Bitset (Python)
2009-05-04T16:37:02-07:00geremy condrahttp://code.activestate.com/recipes/users/4170000/http://code.activestate.com/recipes/576738-bitset/
<p style="color: grey">
Python
recipe 576738
by <a href="/recipes/users/4170000/">geremy condra</a>
(<a href="/recipes/tags/bits/">bits</a>, <a href="/recipes/tags/bytes/">bytes</a>).
</p>
<p>This is a simple Bitset type for Python. It implements the Sequence interface plus __setitem__, the set operations, and string and integer conversions.</p>
Fix invalid mail headers when moving from Thunderbird to IMAP (Python)
2008-08-30T20:08:02-07:00Krys Wilkenhttp://code.activestate.com/recipes/users/4166805/http://code.activestate.com/recipes/576471-fix-invalid-mail-headers-when-moving-from-thunderb/
<p style="color: grey">
Python
recipe 576471
by <a href="/recipes/users/4166805/">Krys Wilken</a>
(<a href="/recipes/tags/cyrus/">cyrus</a>, <a href="/recipes/tags/header/">header</a>, <a href="/recipes/tags/imap/">imap</a>, <a href="/recipes/tags/invalid/">invalid</a>, <a href="/recipes/tags/mail/">mail</a>, <a href="/recipes/tags/maildir/">maildir</a>, <a href="/recipes/tags/mbox/">mbox</a>, <a href="/recipes/tags/thunderbird/">thunderbird</a>).
</p>
<p>Removes ">From" and "From " lines from mail headers.</p>
<p>Thunderbird adds invalid mail headers to it's local folders. Cyrus IMAP is strict about them. This script walks through all files in the given directories and removes any line that starts with ">From" or "From " (note the space and no colon).</p>
<p>Requires Python 2.5+.</p>
pypopper - Python POP3 Server (Python)
2007-10-24T18:52:39-07:00Daniel Millerhttp://code.activestate.com/recipes/users/4016391/http://code.activestate.com/recipes/534131-pypopper-python-pop3-server/
<p style="color: grey">
Python
recipe 534131
by <a href="/recipes/users/4016391/">Daniel Miller</a>
(<a href="/recipes/tags/programs/">programs</a>).
</p>
<p>While developing <a href="http://pieces.openpolitics.com/thunderbayes/">ThunderBayes</a> (an extension for Thunderbird) I wrote this simple POP3 server to serve a message to my ThunderBayes test setup.</p>
Summarizing XHTML (Python)
2006-12-19T05:19:49-08:00Marek Baczynskihttp://code.activestate.com/recipes/users/2236925/http://code.activestate.com/recipes/499336-summarizing-xhtml/
<p style="color: grey">
Python
recipe 499336
by <a href="/recipes/users/2236925/">Marek Baczynski</a>
(<a href="/recipes/tags/web/">web</a>).
</p>
<p>This module provides a function to summarize a XHTML string - that is, shorten it so it is has no more than a given amount of words while keeping XHTML (or, hopefully, any XML) tags intact.</p>
<p>No third-party packages are required (as of Python 2.4, but should work in earlier versions.)</p>
Self-managing, maintenance-free Signals implementation (Python)
2005-08-18T14:21:18-07:00Patrick Chascohttp://code.activestate.com/recipes/users/2557549/http://code.activestate.com/recipes/439356-self-managing-maintenance-free-signals-implementat/
<p style="color: grey">
Python
recipe 439356
by <a href="/recipes/users/2557549/">Patrick Chasco</a>
(<a href="/recipes/tags/oop/">oop</a>).
Revision 3.
</p>
<p>This is a signals implementation for python. It is similar to the pydispatch module. This implementation enables you to create Signals as members of classes, as globals, or as locals. You may connect any number of functions or class methods to any signal. Connections manage themselves with the weakref module. Signals may also have arguments as long as all connected functions are callable with the same arguments.</p>
ReseekFile (Python)
2003-01-09T16:09:13-08:00Andrew Dalkehttp://code.activestate.com/recipes/users/912777/http://code.activestate.com/recipes/173071-reseekfile/
<p style="color: grey">
Python
recipe 173071
by <a href="/recipes/users/912777/">Andrew Dalke</a>
.
</p>
<p>Wrap a file handle to allow seeks back to the beginning</p>
<p>Sometimes data coming from a socket or other input file handle isn't
what it was supposed to be. For example, suppose you are reading from
a buggy server which is supposed to return an XML stream but can also
return an unformatted error message. (This often happens because the
server doesn't handle incorrect input very well.)</p>
<p>A ReseekFile helps solve this problem. It is a wrapper to the
original input stream but provides a buffer. Read requests to the
ReseekFile get forwarded to the input stream, appended to a buffer,
then returned to the caller. The buffer contains all the data read so
far.</p>
<p>The ReseekFile can be told to reseek to the start position. The next
read request will come from the buffer, until the buffer has been
read, in which case it gets the data from the input stream. This
newly read data is also appended to the buffer.</p>
<p>When buffering is no longer needed, use the 'nobuffer()' method. This
tells the ReseekFile that once it has read from the buffer it should
throw the buffer away. After nobuffer is called, the behaviour of
'seek' is no longer defined.</p>
<p>For example, suppose you have the server as above which either
gives an error message is of the form:</p>
<p> ERROR: cannot do that</p>
<p>or an XML data stream, starting with "<?xml".</p>
<p> infile = urllib2.urlopen("http://somewhere/")
infile = ReseekFile.ReseekFile(infile)
s = infile.readline()
if s.startswith("ERROR:"):
raise Exception(s[:-1])
infile.seek(0)
infile.nobuffer() # Don't buffer the data
... process the XML from infile ...</p>
<p>This module also implements 'prepare_input_source(source)' modeled on
xml.sax.saxutils.prepare_input_source. This opens a URL and if the
input stream is not already seekable, wraps it in a ReseekFile.</p>