Popular recipes tagged "meta:loc=88"http://code.activestate.com/recipes/tags/meta:loc=88/2017-04-10T01:07:11-07:00ActiveState Code Recipestkinter custom fonts (Python) 2017-04-10T01:07:11-07:00Miguel Martínez Lópezhttp://code.activestate.com/recipes/users/4189907/http://code.activestate.com/recipes/580778-tkinter-custom-fonts/ <p style="color: grey"> Python recipe 580778 by <a href="/recipes/users/4189907/">Miguel Martínez López</a> (<a href="/recipes/tags/font/">font</a>, <a href="/recipes/tags/tkinter/">tkinter</a>). Revision 2. </p> <p>One Windows the best solution is to use the trick explained here:</p> <p><a href="http://stackoverflow.com/a/30631309" rel="nofollow">http://stackoverflow.com/a/30631309</a></p> <p>Another possibility is to use PIL. creating an image with the text and a specific font.</p> <p>I provide 2 classes: <em>CustomFont_Label</em> and <em>CustomFont_Message</em>.</p> <p><em>CustomFont_Message</em> displays multilines but requires the <em>width</em> parameter.</p> Tkinter buddies or shorcuts (Python) 2017-04-07T11:45:19-07:00Miguel Martínez Lópezhttp://code.activestate.com/recipes/users/4189907/http://code.activestate.com/recipes/580775-tkinter-buddies-or-shorcuts/ <p style="color: grey"> Python recipe 580775 by <a href="/recipes/users/4189907/">Miguel Martínez López</a> (<a href="/recipes/tags/accelerator/">accelerator</a>, <a href="/recipes/tags/buddies/">buddies</a>, <a href="/recipes/tags/buddy/">buddy</a>, <a href="/recipes/tags/shorcut/">shorcut</a>, <a href="/recipes/tags/tkinter/">tkinter</a>). Revision 2. </p> <p>I provide two convenience functions to create shorcuts. <em>create_buddy</em> creates a buddy for the provided label.A buddy establish a connection between a label and a related widget. It provides a quick keyboard shorcut to focus its partner widget. (Buddy is a terminology used in PyQt).</p> <p><em>create_shortcut_to_button</em> creates a shorcut to invoke a button.</p> <p>I bind to toplevel containing the widget. This way, when the dialog is closed all the bindings disappear.</p> <p>All shorcuts are of this form: Alt + letter</p> <p>Buddies and shorcuts enriches the user experience providing new ways to navigate and interact quickly with the application.</p> data_dump.py, like the Unix od (octal dump) command (Python) 2015-11-01T12:43:38-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/579120-data_dumppy-like-the-unix-od-octal-dump-command/ <p style="color: grey"> Python recipe 579120 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/data/">data</a>, <a href="/recipes/tags/dump/">dump</a>, <a href="/recipes/tags/hexadecimal/">hexadecimal</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/octal/">octal</a>, <a href="/recipes/tags/od/">od</a>, <a href="/recipes/tags/representation/">representation</a>, <a href="/recipes/tags/unix/">unix</a>, <a href="/recipes/tags/utility/">utility</a>, <a href="/recipes/tags/windows/">windows</a>). </p> <p>This recipe implements a simple data dump tool, roughly like the od command of Unix, which stands for octal dump (though od can also dump data in hex and other formats). This tool dumps data in character and hex formats, in this version. This is data_dump.py version 1.</p> Plain Text Editor in Python (Python) 2013-06-18T15:33:01-07:00Captain DeadBoneshttp://code.activestate.com/recipes/users/4184772/http://code.activestate.com/recipes/578568-plain-text-editor-in-python/ <p style="color: grey"> Python recipe 578568 by <a href="/recipes/users/4184772/">Captain DeadBones</a> (<a href="/recipes/tags/editor/">editor</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/text/">text</a>, <a href="/recipes/tags/text_processing/">text_processing</a>). </p> <p>Just a simple text editor written in Python with Tk for graphics. </p> <p>Check out my blog <a href="http://thelivingpearl.com/">Captain DeadBones Chronicles</a></p> A Script that Adds a Directory to sys.path Permanently (Python) 2012-02-16T23:15:11-08:00Eric Snowhttp://code.activestate.com/recipes/users/4177816/http://code.activestate.com/recipes/578043-a-script-that-adds-a-directory-to-syspath-permanen/ <p style="color: grey"> Python recipe 578043 by <a href="/recipes/users/4177816/">Eric Snow</a> (<a href="/recipes/tags/script/">script</a>, <a href="/recipes/tags/sys_path/">sys_path</a>). </p> <p>This script takes advantage of PEP 370, "Per user site-packages directory". It manages .pth files, which are are non-volatile (unlike manually adding to sys.path). See <a href="http://docs.python.org/library/site.html." rel="nofollow">http://docs.python.org/library/site.html.</a></p> class matrix (Python) 2011-04-27T15:06:13-07:00Hamidreza Joshaghanihttp://code.activestate.com/recipes/users/4177804/http://code.activestate.com/recipes/577678-class-matrix/ <p style="color: grey"> Python recipe 577678 by <a href="/recipes/users/4177804/">Hamidreza Joshaghani</a> . </p> <p>to calculate determinant and manipulate matrices.</p> Self Extracting Archiver (Python) 2012-06-20T22:32:01-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/577485-self-extracting-archiver/ <p style="color: grey"> Python recipe 577485 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/archive/">archive</a>, <a href="/recipes/tags/python/">python</a>). Revision 6. </p> <p>This is a command-line tool for making self-extracting file archives in Python.</p> Image Downloader (Python) 2014-02-24T03:49:51-08:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/577385-image-downloader/ <p style="color: grey"> Python recipe 577385 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/html/">html</a>, <a href="/recipes/tags/http/">http</a>, <a href="/recipes/tags/url/">url</a>, <a href="/recipes/tags/urllib2/">urllib2</a>, <a href="/recipes/tags/web/">web</a>). Revision 4. </p> <p>Finds and downloads all images from any given URL.</p> <p>Important note:</p> <p>If your download location path has spaces then put quotes around it!</p> M2Crypto-compatible root certificate list generator (Python) 2010-08-25T00:49:48-07:00Mike Ivanovhttp://code.activestate.com/recipes/users/4169853/http://code.activestate.com/recipes/577370-m2crypto-compatible-root-certificate-list-generato/ <p style="color: grey"> Python recipe 577370 by <a href="/recipes/users/4169853/">Mike Ivanov</a> (<a href="/recipes/tags/authority/">authority</a>, <a href="/recipes/tags/certificate/">certificate</a>, <a href="/recipes/tags/cryptography/">cryptography</a>, <a href="/recipes/tags/https/">https</a>, <a href="/recipes/tags/pem/">pem</a>, <a href="/recipes/tags/ssl/">ssl</a>). </p> <p>This modified version of the Heikki Toivonen's certdata2pem script automatically downloads the freshest certdata.txt file and converts it to PEM format. Requires M2Crypto. </p> Pi_Approximation (Python) 2010-02-25T04:50:58-08:00Fouad Teniouhttp://code.activestate.com/recipes/users/4155345/http://code.activestate.com/recipes/577066-pi_approximation/ <p style="color: grey"> Python recipe 577066 by <a href="/recipes/users/4155345/">Fouad Teniou</a> (<a href="/recipes/tags/mathematics/">mathematics</a>). </p> <p>Pi is a constant, an irrational number and its notation represent the sixteenth letter of the Greek alphabet, though its value is equal to the ratio of a circle’s circumference to its diameter.</p> <p>However,<strong>a Muslim scientist Abu-Abdullah Muhammad Ibn Musa al-Khwarizmi</strong> the founder of algebra ( derived from the Arabic word El-Jabr ), arithmetic, and trigonometry, an astronomer, and a geographer C850 studied and proved Pi’s irrationality.(algorithm is derived from his name Khwarizmi ).</p> <p>I used the circle equation x²+y² = 1 of radius 1 centred at (0,0) and the circle area’s formula to approximate Pi value. y²= 1-x² and y = square-root(1-x²) is the upper semicircle which will extend from x = -1 to x = 1 and the rectangle method is used to approximate this area of an interval [-1,1].</p> <p>The area of a circle is A = π r², thus the semicircle of radius 1 will have an area A = ½ π(1²).</p> <p>Using my Pi_Approximation program allows you to represent Pi to infinity of digits, and this will depend of the project type and the precision needed, though space programs require to approximate pi at its maximum precision.</p> <p>And my Pi_Approximation program allows you to make a better Pi’s approximation than the scientific Calculators </p> python jasperreport integration. It is obsolete (Python) 2009-11-28T10:36:21-08:00Martchenkohttp://code.activestate.com/recipes/users/4172446/http://code.activestate.com/recipes/576969-python-jasperreport-integration-it-is-obsolete/ <p style="color: grey"> Python recipe 576969 by <a href="/recipes/users/4172446/">Martchenko</a> (<a href="/recipes/tags/jasperreports/">jasperreports</a>, <a href="/recipes/tags/jasperserver/">jasperserver</a>, <a href="/recipes/tags/jpype/">jpype</a>). Revision 2. </p> <p>short python jasperreport integration example</p> WSGI option parsing & type conversion (Python) 2009-05-28T16:32:11-07:00Brendan O'Connorhttp://code.activestate.com/recipes/users/4170520/http://code.activestate.com/recipes/576784-wsgi-option-parsing-type-conversion/ <p style="color: grey"> Python recipe 576784 by <a href="/recipes/users/4170520/">Brendan O'Connor</a> (<a href="/recipes/tags/option_parsing/">option_parsing</a>, <a href="/recipes/tags/wsgi/">wsgi</a>). Revision 2. </p> <p>fetches named parameters from the WSGI querystring, plus defaults for missing values, and type conversions so you dont accidentally have strings when you want numbers.</p> Adaptive Replacement Cache in python (Python) 2008-10-08T12:24:40-07:00eric casteleijnhttp://code.activestate.com/recipes/users/4167234/http://code.activestate.com/recipes/576532-adaptive-replacement-cache-in-python/ <p style="color: grey"> Python recipe 576532 by <a href="/recipes/users/4167234/">eric casteleijn</a> (<a href="/recipes/tags/caching/">caching</a>, <a href="/recipes/tags/decorators/">decorators</a>). </p> <p>Python implementation of an adaptive replacement cache, as described in:</p> <p><a href="http://en.wikipedia.org/wiki/Adaptive_Replacement_Cache" rel="nofollow">http://en.wikipedia.org/wiki/Adaptive_Replacement_Cache</a></p> <p>Caveat: This may or may not be under patent by IBM, beware of putting it in production code. I implemented it as an experiment, and since I'm in Europe I do not believe a software patent can apply to anything I write.</p> Version-specific import (Python) 2008-09-17T11:25:48-07:00Michaelhttp://code.activestate.com/recipes/users/4166101/http://code.activestate.com/recipes/576508-version-specific-import/ <p style="color: grey"> Python recipe 576508 by <a href="/recipes/users/4166101/">Michael</a> (<a href="/recipes/tags/import/">import</a>, <a href="/recipes/tags/versioning/">versioning</a>, <a href="/recipes/tags/versions/">versions</a>). Revision 5. </p> <p>Let's say you're at a company and you're deploying a package called "tools" on all production boxes. Normally, code on these boxes could "import tools" to use this package.</p> <p>However, over time the API to tools will evolve as you release new versions that add functionality and fix bugs. If there's lots of company code that "imports tools", then you're stuck with backward compatibility forever.</p> <p>This recipe presents a method for letting client code specify on one line which version of "tools" they wish to use -- and then import from the tools package as normal. Behind the scenes, the recipe is making sure that the client works with the version of the package that they requested. If the client ever wants to change versions, it's a one-line change at the top of their code.</p> Customizing Distutils to Recognize Subversion Committed Revision Numbers (Python) 2008-12-18T14:03:51-08:00Chad Strykerhttp://code.activestate.com/recipes/users/2009905/http://code.activestate.com/recipes/573449-customizing-distutils-to-recognize-subversion-comm/ <p style="color: grey"> Python recipe 573449 by <a href="/recipes/users/2009905/">Chad Stryker</a> . Revision 3. </p> <p>The script shows how the standard Distutils module can be easily customized to add new features. In this example, a typical "setup.py" file is configured to extract revision information from a Subversion (revision control repository) database and use the information to set the version of the distribution.</p> Enhanced Complex Number Type (Python) 2008-01-05T18:03:37-08:00cesar oterohttp://code.activestate.com/recipes/users/2790742/http://code.activestate.com/recipes/541103-enhanced-complex-number-type/ <p style="color: grey"> Python recipe 541103 by <a href="/recipes/users/2790742/">cesar otero</a> . </p> <p>Python offers a powerful data type for complex numbers in Cartesian form. Unfortunately, python does not offer support for complex numbers in polar form. This recipe contains a class that supports complex numbers in both Cartesian and polar form, and allows for arithmetic that mixes both forms.</p> WalkRecursiveGenerators (Python) 2007-11-29T19:20:33-08:00Shannon -jj Behrenshttp://code.activestate.com/recipes/users/2269827/http://code.activestate.com/recipes/535145-walkrecursivegenerators/ <p style="color: grey"> Python recipe 535145 by <a href="/recipes/users/2269827/">Shannon -jj Behrens</a> (<a href="/recipes/tags/algorithms/">algorithms</a>). Revision 3. </p> <p>Walk a tree of generators without yielding things recursively. Check out the docstring. It has an example ;)</p> Readable switch construction without lambdas or dictionaries (Python) 2005-04-26T10:51:04-07:00Brian Beckhttp://code.activestate.com/recipes/users/2425329/http://code.activestate.com/recipes/410692-readable-switch-construction-without-lambdas-or-di/ <p style="color: grey"> Python recipe 410692 by <a href="/recipes/users/2425329/">Brian Beck</a> (<a href="/recipes/tags/extending/">extending</a>). Revision 8. </p> <p>Python's lack of a 'switch' statement has garnered much discussion and even a PEP. The most popular substitute uses dictionaries to map cases to functions, which requires lots of defs or lambdas. While the approach shown here may be O(n) for cases, it aims to duplicate C's original 'switch' functionality and structure with reasonable accuracy.</p> Workaround for missed SIGINT in multithreaded programs (Python) 2006-05-24T09:19:44-07:00Allen Downeyhttp://code.activestate.com/recipes/users/2523263/http://code.activestate.com/recipes/496735-workaround-for-missed-sigint-in-multithreaded-prog/ <p style="color: grey"> Python recipe 496735 by <a href="/recipes/users/2523263/">Allen Downey</a> (<a href="/recipes/tags/sysadmin/">sysadmin</a>). </p> <p>Multithreaded Python programs often ignore the SIGINT generated by a Keyboard Interrupt, especially if the thread that gets the signal is waiting or sleeping. This module provides a workaround by forking a child process that executes the rest of the program while the parent process waits for signals and kills the child process.</p> Constellation Finder (Python) 2006-04-06T22:42:16-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/483735-constellation-finder/ <p style="color: grey"> Python recipe 483735 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/algorithms/">algorithms</a>). Revision 2. </p> <p>The following recipe demonstrates the use of SETs in Python. The scenario that this was written for is as follows:</p> <p>A star map is given according to the format X,Y,Z|...|X,Y,Z: X represents the X coordinate of the star (which may be any real integer). Y represents the Y coordinate on the star (which may be any real integer). Z represents the color of the star (which may be any real integer larger than 0). | separates the stars (strings represented by X,Y,Z). , separates the numbers describing the stars (X,Y,Z). : represents the end of the star map. ... is an arbitrary number of X,Y,Z strings with appropriate pipes.</p> <p>As an extention to the original problem that this code was written for, constellation definitions can follow the colon. The constellation string that might follow is described by the following:</p> <p>:C!D#...#D|...|C!D#...#D : represents the beginning of the constellation definitions. C!D#...#D represents one constellation definition. | is the constellation definition separator. C is a number that identifies what constellation is being defined. D can be repesented as X,Y;X,Y or X,Y. X would be the X coordinate of a star defined in the star map. Y would be the Y coordinate of a star defined in the star map. , would be the coordinate separator. ; would be the star separator. ... would be an arbitrary number of D string with appropriate # signs. ... would be an arbitrary number of constellation definitions.</p> <p>The explanation for D is that if two stars are listed, they are joined together with a line segment; but if there is one star, it is only highlighted.</p> <p>In this updated version of the code, there is a key object that has constellations already identified and a stars object that contains the stars in the sky. Keys are used to unlocks the stars and the results are printed out for the user of the program.</p>