Top-rated recipes tagged "gui"http://code.activestate.com/recipes/tags/gui/top/2015-07-06T23:15:31-07:00ActiveState Code RecipesRun asynchronous tasks using coroutines (Python)
2010-08-06T16:16:20-07:00Arnau Sanchezhttp://code.activestate.com/recipes/users/4173270/http://code.activestate.com/recipes/577129-run-asynchronous-tasks-using-coroutines/
<p style="color: grey">
Python
recipe 577129
by <a href="/recipes/users/4173270/">Arnau Sanchez</a>
(<a href="/recipes/tags/coroutine/">coroutine</a>, <a href="/recipes/tags/event/">event</a>, <a href="/recipes/tags/generator/">generator</a>, <a href="/recipes/tags/gobject/">gobject</a>, <a href="/recipes/tags/gtk/">gtk</a>, <a href="/recipes/tags/gui/">gui</a>, <a href="/recipes/tags/network/">network</a>, <a href="/recipes/tags/nonblocking/">nonblocking</a>, <a href="/recipes/tags/pygtk/">pygtk</a>).
Revision 20.
</p>
<p>This recipe shows a simple, transparent (and hopefully pythonic) way of running asynchronous tasks when writing a event-driven application (i.e. GUI). The aim is to allow a programmer to write time-consuming functions (usually IO-bound, but not only) with sequential-looking code, instead of scattering the logic over a bunch of callbacks. We will take advantage of the coroutines introduced in Python 2.5 (see <a href="http://www.python.org/dev/peps/pep-0342" rel="nofollow">http://www.python.org/dev/peps/pep-0342</a>). </p>
<p>The goal: wouldn't it be great if we could write something like this?</p>
<pre class="prettyprint"><code>def myjob(entry, arg1, arg2, arg3):
result1 = function_that_takes_eons_to_complete(arg1, arg2)
result2 = another_function_that_downloads_a_big_really_big_file(result1, arg3)
entry.set_text("The result is: %d" % result2)
def on_start_button___clicked(button, entry):
myjob(entry, 1, 2, 3)
...
gtk.main()
</code></pre>
<p>Indeed, but we can't! The GUI will hang until the job is done and the user will be rightfully angry. Coroutines to the rescue: the absolute minimal change we can make to this code is transforming <em>myjob</em> into a coroutine and yield every time we do blocking stuff:</p>
<pre class="prettyprint"><code>def myjob(entry, arg1, arg2, arg3):
result1 = yield some_task(arg1, arg2)
result2 = yield some_other_task(result1, arg3)
entry.set_text("The result is: %d" % result2)
def on_start__clicked(button, entry):
start_job(myjob(entry, 1, 2, 3))
</code></pre>
<p><em>some_task</em> and <em>some_other_task</em> are here the asynchronous implementation of the sequential tasks used in the first fragment, and <em>start_job</em> the wrapper around the coroutine. Note that we still have to implement non-blocking versions of the tasks, but they are usually pretty generic (wait some time, download a file, ...) and can be re-used. If you happen to have a CPU-bound function or even a IO-bound code you cannot split (<em>urllib2</em> anyone?), you can always use a generic threaded task (granted, the whole point of using co-routines should be avoiding threads, but there is no alternative here).</p>
<p>At the end, all the plumbing we need to make it work is just 1 function: <em>start_job</em> (wrapper around the job to manage the flow of the coroutine). The rest of the code -two asynchronous tasks (<em>sleep_task</em>, <em>threaded_task</em>) and a demo app- are shown solely as an example.</p>
bookmarks browser for firefox (Python)
2015-07-06T23:15:31-07:00Anton Vredegoorhttp://code.activestate.com/recipes/users/2667360/http://code.activestate.com/recipes/579077-bookmarks-browser-for-firefox/
<p style="color: grey">
Python
recipe 579077
by <a href="/recipes/users/2667360/">Anton Vredegoor</a>
(<a href="/recipes/tags/bookmarks/">bookmarks</a>, <a href="/recipes/tags/firefox/">firefox</a>, <a href="/recipes/tags/gui/">gui</a>, <a href="/recipes/tags/tkinter/">tkinter</a>).
</p>
<p>a small tkinter gui to browse the .json type bookmark files firefox automatically generates each day. It's meant to be run from a terminal. If a tree item is doubleclicked it prints the uri.</p>
A Phone Book GUI Built in wxPython Connected To Database Using Data Grid View (Python)
2013-09-29T19:25:23-07:00toufic zaarourhttp://code.activestate.com/recipes/users/4187866/http://code.activestate.com/recipes/578676-a-phone-book-gui-built-in-wxpython-connected-to-da/
<p style="color: grey">
Python
recipe 578676
by <a href="/recipes/users/4187866/">toufic zaarour</a>
(<a href="/recipes/tags/database/">database</a>, <a href="/recipes/tags/datagridview/">datagridview</a>, <a href="/recipes/tags/graphical/">graphical</a>, <a href="/recipes/tags/gui/">gui</a>, <a href="/recipes/tags/interface/">interface</a>).
</p>
<p>this GUI as simple as it is explains some basic but important graphical database interfacing; "Add", "Edit","Delete","Search" and few others along with a data grid view. in order to work create an sqlite3 database as follows:</p>
<p>data table : Phone,
column 1 : ID,
column 2 : name,
column 3 : surname,
column 4 : telephone.</p>
<p>save the sqlite3 file as file.db in a folder called Data and place it in the same directory as your python script.</p>
<p>if you want to create the sqlite3 database graphically use my previous post : <a href="http://code.activestate.com/recipes/578665-a-wxpython-gui-to-create-sqlite3-databases/" rel="nofollow">http://code.activestate.com/recipes/578665-a-wxpython-gui-to-create-sqlite3-databases/</a></p>
<p>Also there is more: I did not use auto-number for 'id' because I also wanted to include in the code a renumbering script.</p>
<p>I am pleased to receive all the suggestions and improvements on this site or to my e-mail directly if this is convenient to you.</p>
<p>note: if you don't like the database table name, and columns name create your own but make sure to change them in the code as well! in the end life is great! remember that!</p>
Patch/diff file viewer with highlighting (Python)
2010-10-29T10:48:15-07:00Anton Butanaevhttp://code.activestate.com/recipes/users/4175501/http://code.activestate.com/recipes/577436-patchdiff-file-viewer-with-highlighting/
<p style="color: grey">
Python
recipe 577436
by <a href="/recipes/users/4175501/">Anton Butanaev</a>
(<a href="/recipes/tags/cvs/">cvs</a>, <a href="/recipes/tags/diff/">diff</a>, <a href="/recipes/tags/git/">git</a>, <a href="/recipes/tags/gui/">gui</a>).
Revision 4.
</p>
<p>diff shows difference in files in whole lines. Sometimes those lines are very similar, only one or two words changed. This script compares changed lines by characters and highlights actual differences in them.</p>
Multiplication Table (Python)
2009-07-22T15:25:39-07:00joedaviscpahttp://code.activestate.com/recipes/users/4170361/http://code.activestate.com/recipes/576851-multiplication-table/
<p style="color: grey">
Python
recipe 576851
by <a href="/recipes/users/4170361/">joedaviscpa</a>
(<a href="/recipes/tags/binding_widgets/">binding_widgets</a>, <a href="/recipes/tags/event_handler_arguments/">event_handler_arguments</a>, <a href="/recipes/tags/gui/">gui</a>, <a href="/recipes/tags/tkinter/">tkinter</a>).
Revision 4.
</p>
<p>This is a GUI multiplication table. The labels and buttons are created in loops, yet each button has an associated value. </p>
A Simple Calculator (Tcl)
2014-09-06T13:36:35-07:00Mike Manilonehttp://code.activestate.com/recipes/users/4190728/http://code.activestate.com/recipes/578929-a-simple-calculator/
<p style="color: grey">
Tcl
recipe 578929
by <a href="/recipes/users/4190728/">Mike Manilone</a>
(<a href="/recipes/tags/calculator/">calculator</a>, <a href="/recipes/tags/gui/">gui</a>).
</p>
<p>A simple calculator. Calculation is done by [expr].</p>
Stopwatch in 26 lines (Tcl)
2014-09-05T13:33:13-07:00Mike Manilonehttp://code.activestate.com/recipes/users/4190728/http://code.activestate.com/recipes/578927-stopwatch-in-26-lines/
<p style="color: grey">
Tcl
recipe 578927
by <a href="/recipes/users/4190728/">Mike Manilone</a>
(<a href="/recipes/tags/gui/">gui</a>, <a href="/recipes/tags/time/">time</a>).
</p>
<p>This stopwatch works on Tcl/Tk 8.5 and higher. It makes use of the [clock] command and reduced the amount of code by -textvariable. A simple one, indeed. Nevertheless, it is still easy-to-read and easy-to-understand and it does show the power that Tcl has.</p>
Accordion Widget (Tkinter) (Python)
2014-07-18T11:39:51-07:00Peter Mojeikohttp://code.activestate.com/recipes/users/4190241/http://code.activestate.com/recipes/578911-accordion-widget-tkinter/
<p style="color: grey">
Python
recipe 578911
by <a href="/recipes/users/4190241/">Peter Mojeiko</a>
(<a href="/recipes/tags/gui/">gui</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/tkinter/">tkinter</a>).
</p>
<p>An expanding/collapsing widget for Tkinter.</p>
<p>usage:</p>
<pre class="prettyprint"><code>from accordion import Accordion, Chord
root = Tk()
accordion = Accordion(root)
accordion.pack()
chord1 = Chord(accordion, title='Chord')
# create widgets and give them chord1 as parent
accordion.append_chords([chord1])
root.mainloop()
</code></pre>
<p>There's a more detailed example at the bottom of the file.</p>
All in one Area Calculator (Python)
2014-07-03T09:16:14-07:00karimhttp://code.activestate.com/recipes/users/4190244/http://code.activestate.com/recipes/578901-all-in-one-area-calculator/
<p style="color: grey">
Python
recipe 578901
by <a href="/recipes/users/4190244/">karim</a>
(<a href="/recipes/tags/calculator/">calculator</a>, <a href="/recipes/tags/circlearea/">circlearea</a>, <a href="/recipes/tags/gui/">gui</a>, <a href="/recipes/tags/python3/">python3</a>, <a href="/recipes/tags/tkinter/">tkinter</a>, <a href="/recipes/tags/tranglearea/">tranglearea</a>, <a href="/recipes/tags/trianglearea/">trianglearea</a>).
Revision 2.
</p>
<p>Its a python 3 based All in one Area Calculator.you can calculate Area of Rectangle,Area of Triangle and Area of Circle</p>
Use Gtk.TreeView to browse MySql databases (Python)
2013-11-27T14:06:20-08:00Anonimistahttp://code.activestate.com/recipes/users/4188571/http://code.activestate.com/recipes/578775-use-gtktreeview-to-browse-mysql-databases/
<p style="color: grey">
Python
recipe 578775
by <a href="/recipes/users/4188571/">Anonimista</a>
(<a href="/recipes/tags/gui/">gui</a>, <a href="/recipes/tags/mysqldb/">mysqldb</a>, <a href="/recipes/tags/user_interface/">user_interface</a>).
</p>
<p>Use Gtk.TreeView to browse MySql database structure from database to tables and views and to columns</p>
List MySql databases in a Gtk.TreeView (Python)
2013-11-27T14:03:21-08:00Anonimistahttp://code.activestate.com/recipes/users/4188571/http://code.activestate.com/recipes/578774-list-mysql-databases-in-a-gtktreeview/
<p style="color: grey">
Python
recipe 578774
by <a href="/recipes/users/4188571/">Anonimista</a>
(<a href="/recipes/tags/database/">database</a>, <a href="/recipes/tags/gtk/">gtk</a>, <a href="/recipes/tags/gui/">gui</a>, <a href="/recipes/tags/mysqldb/">mysqldb</a>, <a href="/recipes/tags/user_interface/">user_interface</a>).
</p>
<p>List MySql databases in a Gtk.TreeView</p>
Delete a Gtk.TreeView row (Python)
2013-11-27T13:59:58-08:00Anonimistahttp://code.activestate.com/recipes/users/4188571/http://code.activestate.com/recipes/578773-delete-a-gtktreeview-row/
<p style="color: grey">
Python
recipe 578773
by <a href="/recipes/users/4188571/">Anonimista</a>
(<a href="/recipes/tags/gtk/">gtk</a>, <a href="/recipes/tags/gui/">gui</a>).
</p>
<p>Delete a Gtk.TreeView row</p>
Music Downloader with Wx GUI! (Python)
2013-11-05T02:52:29-08:00Christian Careagahttp://code.activestate.com/recipes/users/4186639/http://code.activestate.com/recipes/578681-music-downloader-with-wx-gui/
<p style="color: grey">
Python
recipe 578681
by <a href="/recipes/users/4186639/">Christian Careaga</a>
(<a href="/recipes/tags/beautifulsoup/">beautifulsoup</a>, <a href="/recipes/tags/downloader/">downloader</a>, <a href="/recipes/tags/gui/">gui</a>, <a href="/recipes/tags/music/">music</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/urllib/">urllib</a>, <a href="/recipes/tags/urllib2/">urllib2</a>, <a href="/recipes/tags/wxpyton/">wxpyton</a>).
</p>
<p>Just type in a song and the artist and the program will get the YouTube video, convert it to an mp3 then download it!
It has a high quality function and a medium quality function and also the user can choose the directory and name they want the file to be saved to!</p>
<p>It is the first time I've used threads and my second time with WxPython! I used BeautifulSoup for the scraping and I'm pretty familiar with that.just thought id share it with you guys and see if you have any feedback or suggestions!</p>
<p>also you may get an error saying self.convhtml doesn't exist just wait then retry</p>
<p>Here is a link to an screenshot:</p>
<p><a href="http://adf.ly/XJaoU" rel="nofollow">http://adf.ly/XJaoU</a></p>
<p>if you want you can checkout the Github page:</p>
<p><a href="http://adf.ly/XGL6P" rel="nofollow">http://adf.ly/XGL6P</a></p>
<p>also you will need to make a folder called Files and put a file called dir.txt and in the file write /Files. this is where the music will be downloaded to!</p>
<p>I just made the .exe so you can just use that and its easier!
Here:
<a href="http://adf.ly/XRjRH" rel="nofollow">http://adf.ly/XRjRH</a></p>
A wxPython GUI To Create Sqlite3 Databases (Python)
2013-09-18T23:05:51-07:00toufic zaarourhttp://code.activestate.com/recipes/users/4187866/http://code.activestate.com/recipes/578665-a-wxpython-gui-to-create-sqlite3-databases/
<p style="color: grey">
Python
recipe 578665
by <a href="/recipes/users/4187866/">toufic zaarour</a>
(<a href="/recipes/tags/gui/">gui</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/sqlite/">sqlite</a>, <a href="/recipes/tags/wxpython/">wxpython</a>).
Revision 2.
</p>
<p>A GUI built around wxPython in a way that will allow you to add to this application other forms and functionalities. The main DialogBox is to create,in a fast way, Sqlite3 databases that are used for web or applications development. In order to work properly, save the script in a separate directory.There is also more; each time you create a database a text file named "CreationLog.txt" will be created (for the first time you use the application or if it is not there) and updated, describing when and where was your database created and with what SQL query. I am pleased to receive all the suggestions and improvements on this site or to my e-mail directly if this is convenient to you.</p>
Typing skills meter (Python)
2012-11-02T12:29:25-07:00Pierre Quentelhttp://code.activestate.com/recipes/users/1552957/http://code.activestate.com/recipes/578318-typing-skills-meter/
<p style="color: grey">
Python
recipe 578318
by <a href="/recipes/users/1552957/">Pierre Quentel</a>
(<a href="/recipes/tags/gui/">gui</a>, <a href="/recipes/tags/typing/">typing</a>).
</p>
<p>A Tkinter-based program that shows your typing skills (speed and error rate) in the form of a car dashboard</p>
<p>The text to type is displayed in a text zone, the cursor and the dashboard needles progress as you type the letters. Text can be copied-pasted, or loaded from a file that users can store in the subfolder "texts"</p>
<p>The interface language can be configured (in this version, only French-English, but easily extendable to other languages)</p>
Color Study 1 (Python)
2011-04-05T23:35:32-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/577636-color-study-1/
<p style="color: grey">
Python
recipe 577636
by <a href="/recipes/users/2608421/">Stephen Chappell</a>
(<a href="/recipes/tags/color/">color</a>, <a href="/recipes/tags/example/">example</a>, <a href="/recipes/tags/experiment/">experiment</a>, <a href="/recipes/tags/gui/">gui</a>, <a href="/recipes/tags/sandbox/">sandbox</a>).
</p>
<p>The following program was written to understand how two different color systems related to each other, RGB and HSV. The recipe could be better written and extended further to support other color systems in addition to the two it already uses, but it is a simple example of how one might go about to understand what others speak of when talking about color. The GUI is simple to use and responsive, and the code is a good demonstration of what may need to be written to produce a demonstration such as this one.</p>
<p>If you have suggestions or would like to vote this recipe down, please provide an explanation of the problem along with a solution that you would propose and implement to improve upon what is presented.</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>
Quiz Me 2.5 (main) (Python)
2011-01-09T21:14:04-08:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/577525-quiz-me-25-main/
<p style="color: grey">
Python
recipe 577525
by <a href="/recipes/users/2608421/">Stephen Chappell</a>
(<a href="/recipes/tags/gui/">gui</a>, <a href="/recipes/tags/program/">program</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/quiz/">quiz</a>).
Revision 2.
</p>
<p>Before discovering <a href="http://quizlet.com/" rel="nofollow">http://quizlet.com/</a>, the following program was developed for running custom quizzes to help with studying for college courses. The program is not very advanced, but it works reasonably well for what it was designed to do. If the program were developed further, it would need greater capabilities than it currently has and would require a secondary system for actually creating the quizzes (currently, they are hand-typed). Quiz Me could be a starting point for anyone who wishes to actually write a program such as this and inspire others to write much better programs than what this recipe currently offers.</p>
<p>This is the main entry point to the Quiz Me program. It creates the GUI context and sets the program up for automatic error logging. Experimental threading support is provided but unused in the program. Since the main application subclasses a frame, it can easily be embedded in another application without much difficulty. Quiz Me is entirely event based and has an event runner in the very last method shown here.</p>
Terminal directory changer (GUI) (Python)
2010-10-21T18:58:04-07:00Anton Vredegoorhttp://code.activestate.com/recipes/users/2667360/http://code.activestate.com/recipes/577435-terminal-directory-changer-gui/
<p style="color: grey">
Python
recipe 577435
by <a href="/recipes/users/2667360/">Anton Vredegoor</a>
(<a href="/recipes/tags/cd/">cd</a>, <a href="/recipes/tags/gui/">gui</a>, <a href="/recipes/tags/python_scripts/">python_scripts</a>, <a href="/recipes/tags/terminal/">terminal</a>, <a href="/recipes/tags/utility/">utility</a>).
Revision 2.
</p>
<p>Start this script from a terminal to change the terminal itself to a new directory, using a graphical tree view.</p>
Using proxy connection for QWebView (Python)
2009-10-02T02:32:51-07:00Keisuke URAGOhttp://code.activestate.com/recipes/users/668964/http://code.activestate.com/recipes/576921-using-proxy-connection-for-qwebview/
<p style="color: grey">
Python
recipe 576921
by <a href="/recipes/users/668964/">Keisuke URAGO</a>
(<a href="/recipes/tags/browser/">browser</a>, <a href="/recipes/tags/gui/">gui</a>, <a href="/recipes/tags/pyqt/">pyqt</a>, <a href="/recipes/tags/qt4/">qt4</a>, <a href="/recipes/tags/web/">web</a>).
Revision 4.
</p>
<p>QWebView is powerful web browser. This script can use a http-proxy host.
Log file name is minibrowser.log in same directory.</p>