Popular recipes tagged "text" but not "python"http://code.activestate.com/recipes/tags/text-python/2017-04-07T12:30:13-07:00ActiveState Code RecipesTag entry for Tkinter like Jquery Tag It (Python) 2017-04-07T12:30:13-07:00Miguel Martínez Lópezhttp://code.activestate.com/recipes/users/4189907/http://code.activestate.com/recipes/580734-tag-entry-for-tkinter-like-jquery-tag-it/ <p style="color: grey"> Python recipe 580734 by <a href="/recipes/users/4189907/">Miguel Martínez López</a> (<a href="/recipes/tags/entry/">entry</a>, <a href="/recipes/tags/megawidget/">megawidget</a>, <a href="/recipes/tags/tag/">tag</a>, <a href="/recipes/tags/text/">text</a>, <a href="/recipes/tags/tkinter/">tkinter</a>). Revision 2. </p> <p>Tag editing widget for tkinter. It's similar to jQuery tag it: <a href="http://aehlke.github.io/tag-it/" rel="nofollow">http://aehlke.github.io/tag-it/</a></p> Text widget width and height in pixels (Tkinter) (Python) 2016-12-11T13:39:08-08:00Miguel Martínez Lópezhttp://code.activestate.com/recipes/users/4189907/http://code.activestate.com/recipes/578887-text-widget-width-and-height-in-pixels-tkinter/ <p style="color: grey"> Python recipe 578887 by <a href="/recipes/users/4189907/">Miguel Martínez López</a> (<a href="/recipes/tags/text/">text</a>, <a href="/recipes/tags/tkinter/">tkinter</a>). Revision 8. </p> <p>The solution consists in putting the Text widget inside a frame, forcing the frame to a fixed size by deactivating size propagation and configuring the Text widget to expand and fill both directions (to stick to the frame borders).</p> <p><a href="https://stackoverflow.com/questions/14887610/how-to-specify-the-dimensions-of-a-tkinter-text-box-in-pixels" rel="nofollow">https://stackoverflow.com/questions/14887610/how-to-specify-the-dimensions-of-a-tkinter-text-box-in-pixels</a></p> Automatic resized Text widget (Tkinter) (Python) 2016-12-10T15:40:25-08:00Miguel Martínez Lópezhttp://code.activestate.com/recipes/users/4189907/http://code.activestate.com/recipes/578886-automatic-resized-text-widget-tkinter/ <p style="color: grey"> Python recipe 578886 by <a href="/recipes/users/4189907/">Miguel Martínez López</a> (<a href="/recipes/tags/autoresize/">autoresize</a>, <a href="/recipes/tags/text/">text</a>, <a href="/recipes/tags/tkinter/">tkinter</a>). Revision 14. </p> <p>The Text widget resize to its contents. Based on this: <a href="https://stackoverflow.com/questions/11544187/tkinter-resize-text-to-contents" rel="nofollow">https://stackoverflow.com/questions/11544187/tkinter-resize-text-to-contents</a></p> <p>But here there is one important improvement: The widget resize first, before a character inclusion.</p> <p>For this trick I have had to use tag bindings.</p> <p>Here there is a practical application of this widget:</p> <p><a href="https://code.activestate.com/recipes/578885-draggable-desktop-note-or-sticky-notes-in-tkinter/" rel="nofollow">https://code.activestate.com/recipes/578885-draggable-desktop-note-or-sticky-notes-in-tkinter/</a></p> Call out to an external editor (Python) 2014-09-01T18:26:51-07:00Steven D'Apranohttp://code.activestate.com/recipes/users/4172944/http://code.activestate.com/recipes/578926-call-out-to-an-external-editor/ <p style="color: grey"> Python recipe 578926 by <a href="/recipes/users/4172944/">Steven D'Aprano</a> (<a href="/recipes/tags/editing/">editing</a>, <a href="/recipes/tags/editor/">editor</a>, <a href="/recipes/tags/external/">external</a>, <a href="/recipes/tags/text/">text</a>). Revision 2. </p> <p>Here's a function that lets you use Python to wrap calls to an external editor. The editor can be an command line editor, like venerable old "ed", or something more powerful like nano, vim or emacs, and even GUI editors. After the editor quits, the text you typed in the editor is returned by the function.</p> <p>A simple example, using the (rather cryptic) 'ed' editor on Linux. For the benefit of those unfamiliar with 'ed', I have annotated the editor session with comments.</p> <pre class="prettyprint"><code>&gt;&gt;&gt; status, text = edit('ed') 0 ## ed prints the initial number of lines a ## start "append" mode Hello World! Goodbye now . ## stop appending w ## write the file to disk 25 ## ed prints the number of bytes written q ## quit ed and return to Python &gt;&gt;&gt; status 0 &gt;&gt;&gt; print text Hello World! Goodbye now </code></pre> Simple Bash Text Mode Sine Curve Generator. (Bash) 2014-08-12T20:57:39-07:00Barry Walkerhttp://code.activestate.com/recipes/users/4177147/http://code.activestate.com/recipes/578921-simple-bash-text-mode-sine-curve-generator/ <p style="color: grey"> Bash recipe 578921 by <a href="/recipes/users/4177147/">Barry Walker</a> (<a href="/recipes/tags/apple/">apple</a>, <a href="/recipes/tags/bash/">bash</a>, <a href="/recipes/tags/cygwin/">cygwin</a>, <a href="/recipes/tags/graph/">graph</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/macbook_pro/">macbook_pro</a>, <a href="/recipes/tags/text/">text</a>). Revision 2. </p> <p>This bash script is a taster for a kids level, audio, text mode, sweep generator. The code just creates a single cycle of a quantised sine curve inside an 80 x 24 bash terminal. This will be the calculator for a sinewave sweep generator from about 50Hz the 12KHz... The code tells you more and the display is in comments at the end...</p> Droids ( a text adventure ) (Python) 2013-07-27T09:44:06-07:00jayhttp://code.activestate.com/recipes/users/4186699/http://code.activestate.com/recipes/578618-droids-a-text-adventure/ <p style="color: grey"> Python recipe 578618 by <a href="/recipes/users/4186699/">jay</a> (<a href="/recipes/tags/beginner/">beginner</a>, <a href="/recipes/tags/commandline/">commandline</a>, <a href="/recipes/tags/game/">game</a>, <a href="/recipes/tags/python3/">python3</a>, <a href="/recipes/tags/text/">text</a>). </p> <p>for beginners.</p> Levenshtein, my love (Python) 2014-01-15T09:14:30-08:00yotahttp://code.activestate.com/recipes/users/4184815/http://code.activestate.com/recipes/578810-levenshtein-my-love/ <p style="color: grey"> Python recipe 578810 by <a href="/recipes/users/4184815/">yota</a> (<a href="/recipes/tags/text/">text</a>). Revision 3. </p> <p><em>be kind and comment, especially if you downvote</em></p> <p><strong>levenshtein_distance()</strong> is an implementation of the iterative algorithm for the levenshtein distance (cf. <a href="http://en.wikipedia.org/wiki/Levenshtein_distance#Iterative_with_full_matrix%29" rel="nofollow">http://en.wikipedia.org/wiki/Levenshtein_distance#Iterative_with_full_matrix)</a></p> <p><strong>levenshtein_sequence()</strong> is an attempt to retrieve one of the levenshtein paths (the one that give priority to substitution, deletion, insertion, in this order). The result is a list of tuples made of:</p> <ol> <li>the operation ( <code>=</code>, <code>-</code>, <code>+</code>, <code>*</code> for respectively keep, delete, insert, substitute)</li> <li>the coordinate in the first</li> <li>and in the second string.</li> </ol> <pre class="prettyprint"><code>&gt;&gt;&gt; levenshtein_sequence('saturday', 'sunday') [('=', 0, 0), ('-', 1, 0), ('-', 2, 0), ('=', 3, 1), ('*', 4, 2), ('=', 5, 3), ('=', 6, 4), ('=', 7, 5)] &gt;&gt;&gt; levenshtein_sequence('kitten', 'sitting') [('*', 0, 0), ('=', 1, 1), ('=', 2, 2), ('=', 3, 3), ('*', 4, 4), ('=', 5, 5), ('+', 5, 6)] </code></pre> <p>This code is part of foreplays, in a plan I have to improve difflib with alternative SequenceMatchers \o/</p> <p><em>/!\ tab indented, as usual.</em></p> Droids 2 ( IF ) (Python) 2013-08-13T09:12:11-07:00jayhttp://code.activestate.com/recipes/users/4186699/http://code.activestate.com/recipes/578636-droids-2-if/ <p style="color: grey"> Python recipe 578636 by <a href="/recipes/users/4186699/">jay</a> (<a href="/recipes/tags/beginner/">beginner</a>, <a href="/recipes/tags/commandline/">commandline</a>, <a href="/recipes/tags/game/">game</a>, <a href="/recipes/tags/if/">if</a>, <a href="/recipes/tags/learning/">learning</a>, <a href="/recipes/tags/python3/">python3</a>, <a href="/recipes/tags/text/">text</a>). Revision 2. </p> <h4 id="-for-learners-and-beginners-like-myself-">-For learner's and beginner's like myself -</h4> <h4 id="-and-for-anyone-who-may-have-enjoyed-droids-">-and for anyone who may have enjoyed Droids. -</h4> Pseudo-3D effect in text mode... (Bash) 2013-09-10T21:23:58-07:00Barry Walkerhttp://code.activestate.com/recipes/users/4177147/http://code.activestate.com/recipes/578655-pseudo-3d-effect-in-text-mode/ <p style="color: grey"> Bash recipe 578655 by <a href="/recipes/users/4177147/">Barry Walker</a> (<a href="/recipes/tags/3d/">3d</a>, <a href="/recipes/tags/apple/">apple</a>, <a href="/recipes/tags/bash/">bash</a>, <a href="/recipes/tags/color/">color</a>, <a href="/recipes/tags/colour/">colour</a>, <a href="/recipes/tags/display/">display</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/macbook_pro/">macbook_pro</a>, <a href="/recipes/tags/text/">text</a>). </p> <p>This is just a simple DEMO to display a pseudo-3D effect using a bash script. It generates a recessed box and a button and writes some thext inside bot.</p> <p>There are two pieces of code, one for Linux, and one for OSX 10.7.5...</p> <p>The Linux version also works on OSX 10.7.5 but is harder to see so a near identical version using the default OSX terminal colours was craeted instead.</p> <p>You will have to split the two code pieces up yourself to run...</p> <p>Enjoy finding simple solutions to often very difficult problems...</p> <p>Bazza...</p> Easy to use, easy to read, python based HTML generation (Python) 2013-06-21T14:47:21-07:00Pavloshttp://code.activestate.com/recipes/users/4185038/http://code.activestate.com/recipes/578436-easy-to-use-easy-to-read-python-based-html-generat/ <p style="color: grey"> Python recipe 578436 by <a href="/recipes/users/4185038/">Pavlos</a> (<a href="/recipes/tags/html/">html</a>, <a href="/recipes/tags/template/">template</a>, <a href="/recipes/tags/text/">text</a>). Revision 4. </p> <p>I was looking for a simple way to generate HTML directly in python that does not require learning a new template 'language' nor requires the installation of a big complex package. Closest thing I found was James Casbon's attempt(https://gist.github.com/1461441). This is my version of the same idea. </p> <p>(2013-04-21) added some simplifications and support for switching off string interpolation. Added to github:</p> <p><a href="https://github.com/pavlos-christoforou/web" rel="nofollow">https://github.com/pavlos-christoforou/web</a></p> For Characters in a String, Replace with Character (Python) 2012-03-23T20:44:23-07:00Andrew Yurisichhttp://code.activestate.com/recipes/users/4180867/http://code.activestate.com/recipes/578086-for-characters-in-a-string-replace-with-character/ <p style="color: grey"> Python recipe 578086 by <a href="/recipes/users/4180867/">Andrew Yurisich</a> (<a href="/recipes/tags/character/">character</a>, <a href="/recipes/tags/replace/">replace</a>, <a href="/recipes/tags/substitute/">substitute</a>, <a href="/recipes/tags/text/">text</a>). Revision 9. </p> <p>Useful if you need to replace many different characters with all of the same character. Can accept an unlimited number of request to replace.</p> <p>Does not work with words, only characters. You can, however, replace single characters with words. I may go back and re-implement it using tuples for the keys, but this would make searching the text for any matches pretty expensive, I'd imagine. At that point, it's mostly a job for a regex, and those tools already exist.</p> Funny text generator (Python) 2011-12-25T11:14:39-08:00Pierre Quentelhttp://code.activestate.com/recipes/users/1552957/http://code.activestate.com/recipes/577988-funny-text-generator/ <p style="color: grey"> Python recipe 577988 by <a href="/recipes/users/1552957/">Pierre Quentel</a> (<a href="/recipes/tags/generation/">generation</a>, <a href="/recipes/tags/random/">random</a>, <a href="/recipes/tags/text/">text</a>). Revision 4. </p> <p>This class takes a text (preferably long enough) and generates another text that "looks like" the original. It won't mean anything, or just by chance ;-)</p> <p>For example, taking Hamlet, Act I, the program generates things like :</p> <p>Hamlet</p> <blockquote> <p>And vanish'd from our watch; <br /> His further. Fare third nights of the flushing immortal as it draw you into the flushing thy complete steel <br /> 'Tis sweet and each new-hatch'd: <br /> A country's father; <br /> To business and is prodigal thee! <br /> Have of crowing more the should I have heaven, <br /> Forward, therefore as ourself in the business it, Horatio <br /> To what is't that your watch, bid this here! </p> </blockquote> <p>Usage :</p> <pre class="prettyprint"><code>generator = TextGenerator(txt) result = generator.random_text(3000) </code></pre> Encrypt and Decrypt Text and Text Files (BETA) Jython GUI (Python) 2011-11-23T05:37:04-08:00Alexander James Wallarhttp://code.activestate.com/recipes/users/4179768/http://code.activestate.com/recipes/577957-encrypt-and-decrypt-text-and-text-files-beta-jytho/ <p style="color: grey"> Python recipe 577957 by <a href="/recipes/users/4179768/">Alexander James Wallar</a> (<a href="/recipes/tags/cryptography/">cryptography</a>, <a href="/recipes/tags/cryptology/">cryptology</a>, <a href="/recipes/tags/decryption/">decryption</a>, <a href="/recipes/tags/encryption/">encryption</a>, <a href="/recipes/tags/encryption_decryption/">encryption_decryption</a>, <a href="/recipes/tags/files/">files</a>, <a href="/recipes/tags/hiding/">hiding</a>, <a href="/recipes/tags/text/">text</a>). Revision 3. </p> <p>This is a Jython GUI of my previous recipe: Encrypt and Decrypt Text and Text Files</p> Remove UTF-8 Byte Order Mark (BOM) from text files (Bash) 2011-10-18T06:37:52-07:00Graham Poulterhttp://code.activestate.com/recipes/users/4172291/http://code.activestate.com/recipes/577912-remove-utf-8-byte-order-mark-bom-from-text-files/ <p style="color: grey"> Bash recipe 577912 by <a href="/recipes/users/4172291/">Graham Poulter</a> (<a href="/recipes/tags/text/">text</a>, <a href="/recipes/tags/unicode/">unicode</a>, <a href="/recipes/tags/utf8/">utf8</a>). </p> <p>Shell script to removes UTF-8 Byte Order Mark (BOM) from text files, where present.</p> Table indentation (Python) 2011-03-18T14:39:59-07:00Jonathan Blakeshttp://code.activestate.com/recipes/users/4177368/http://code.activestate.com/recipes/577615-table-indentation/ <p style="color: grey"> Python recipe 577615 by <a href="/recipes/users/4177368/">Jonathan Blakes</a> (<a href="/recipes/tags/text/">text</a>). </p> <p>A function for pretty-printing a table.</p> Basic Text Editor (Tcl) 2011-03-21T23:10:10-07:00Jonathan Fenechhttp://code.activestate.com/recipes/users/4169413/http://code.activestate.com/recipes/577617-basic-text-editor/ <p style="color: grey"> Tcl recipe 577617 by <a href="/recipes/users/4169413/">Jonathan Fenech</a> (<a href="/recipes/tags/basic/">basic</a>, <a href="/recipes/tags/editor/">editor</a>, <a href="/recipes/tags/text/">text</a>). </p> <p>Text editor with copy,cut and paste functions.</p> Arduino Diecimila Board Access Inside A Linux Bash Shell. (Text) 2011-03-30T18:08:11-07:00Barry Walkerhttp://code.activestate.com/recipes/users/4177147/http://code.activestate.com/recipes/577627-arduino-diecimila-board-access-inside-a-linux-bash/ <p style="color: grey"> Text recipe 577627 by <a href="/recipes/users/4177147/">Barry Walker</a> (<a href="/recipes/tags/access/">access</a>, <a href="/recipes/tags/arduino/">arduino</a>, <a href="/recipes/tags/bash/">bash</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/shell/">shell</a>, <a href="/recipes/tags/text/">text</a>). </p> <p>The "code" in this recipe is a step by step "root" shell command line procedure for testing whether a(n) USB Arduino Dev Board is working or not. To get more recognisable characters displayed it is best to use a potentiometer wired as one end to +5V, the other end to Gnd and thw wiper to ANALOG IN 0. This has been tested on various Linux Distros and kept as simple as possible so that anyone can understand it.</p> <p>The required ?.pde file for the Arduino Board can be found here:-</p> <p><a href="http://code.activestate.com/recipes/577625-arduino-diecimila-board-access-inside-winuae-demo/?in=lang-python" rel="nofollow">http://code.activestate.com/recipes/577625-arduino-diecimila-board-access-inside-winuae-demo/?in=lang-python</a></p> <p>It is issued entirely as Public Domain by B.Walker, G0LCU, 30-03-2011, and you may do with it as you please.</p> <p>Similar assumptions are made as in the URL above.</p> <p>Enjoy finding simple solutions to often very difficult problems... ;o)</p> Komodo JavaScript Macro - wrap the current word under the cursor (JavaScript) 2011-02-02T23:28:37-08:00Todd Whitemanhttp://code.activestate.com/recipes/users/2666241/http://code.activestate.com/recipes/577561-komodo-javascript-macro-wrap-the-current-word-unde/ <p style="color: grey"> JavaScript recipe 577561 by <a href="/recipes/users/2666241/">Todd Whiteman</a> (<a href="/recipes/tags/komodo/">komodo</a>, <a href="/recipes/tags/macro/">macro</a>, <a href="/recipes/tags/text/">text</a>, <a href="/recipes/tags/toddw/">toddw</a>, <a href="/recipes/tags/wrap/">wrap</a>). </p> <p>A <a href="http://www.activestate.com/komodo">Komodo</a> JavaScript macro that can be used to wrap the current word under the cursor position (or current selection) with arbitrary text.</p> <p>For example, if I'm editing a HTML file and have the selected text "This is my heading", I can quickly use this macro to wrap this text into "&lt;h1&gt;This is my heading&lt;/h1&gt;".</p> Convert a transcript with Ansi escape sequences to HTML (Python) 2010-10-09T22:29:42-07:00Muhammad Alkarourihttp://code.activestate.com/recipes/users/4049383/http://code.activestate.com/recipes/577349-convert-a-transcript-with-ansi-escape-sequences-to/ <p style="color: grey"> Python recipe 577349 by <a href="/recipes/users/4049383/">Muhammad Alkarouri</a> (<a href="/recipes/tags/ansi/">ansi</a>, <a href="/recipes/tags/conversion/">conversion</a>, <a href="/recipes/tags/text/">text</a>). Revision 2. </p> <p>This is a stab at converting a transcript generated by the Unix <code>script</code> command that uses ANSI escape sequences, used to colour the terminal, to HTML.</p> Render tables for text interface (Python) 2010-04-20T18:02:51-07:00Denis Barmenkovhttp://code.activestate.com/recipes/users/57155/http://code.activestate.com/recipes/577202-render-tables-for-text-interface/ <p style="color: grey"> Python recipe 577202 by <a href="/recipes/users/57155/">Denis Barmenkov</a> (<a href="/recipes/tags/format/">format</a>, <a href="/recipes/tags/table/">table</a>, <a href="/recipes/tags/text/">text</a>). Revision 2. </p> <p>Sometime pprint module is not enough for formatting data for console or log file output. This module provide function which fill the gap.</p> <p><strong>Sample function call:</strong></p> <pre class="prettyprint"><code>nums = [ '1', '2', '3', '4' ] speeds = [ '100', '10000', '1500', '12' ] desc = [ '', 'label 1', 'none', 'very long description' ] lines = format_table( [(nums, ALIGN_RIGHT|PADDING_ALL, 'NUM'), (speeds, ALIGN_RIGHT|PADDING_ALL, 'SPEED'), (desc, ALIGN_LEFT|PADDING_ALL, 'DESC')] ) </code></pre> <p><strong>Output:</strong></p> <pre class="prettyprint"><code>======================================= | NUM | SPEED | DESC | ======================================= | 1 | 100 | | | 2 | 10000 | label 1 | | 3 | 1500 | none | | 4 | 12 | very long description | ======================================= </code></pre>