Python-Code-1

=Python Code 1=

Tutorials
Python 101 - http://www.rexx.com/~dkuhlman/python_101/python_101.html Intro to Python - @http://www.penzilla.net/tutorials/python/functions/ PyGTK Tutorial - @http://www.pygtk.org/pygtktutorial/ Python Docs Tutorial - @http://docs.python.org/tutorial/ Great tutorial - Python 101 - http://www.rexx.com/~dkuhlman/python_101/python_101.html Python Tutorial - @http://www.tutorialspoint.com/python/python_overview.htm Python Style Guide - @http://www.python.org/dev/peps/pep-0008/

GTK Constants - @http://www.pygtk.org/docs/pygtk/gtk-constants.html GTK Stock Items - @http://www.pygtk.org/docs/pygtk/gtk-stock-items.html Python Strings - @http://www.tutorialspoint.com/python/python_strings.htm Efficient String Concatenation in Python - http://skymind.com/~ocrow/python_string/ Radio Buttons - @http://www.pygtk.org/pygtk2tutorial/sec-RadioButtons.html Using a Treeview (wine app) - @http://www.pygtk.org/articles/application-pygtk-glade/Building_an_Application_with_PyGTK_and_Glade.htm PyGTK FAQ - @http://faq.pygtk.org/index.py?req=index Using TreeStores/ListStores - http://www.pygtk.org/pygtk2tutorial/sec-TreeModelInterface.html#sec-ReferringToTreeModelRows The TreeModel Interface and Data Stores - @http://www.pygtk.org/pygtk2tutorial/sec-TreeModelInterface.html PyGTK Pango Markup Language - @http://www.pygtk.org/docs/pygtk/pango-markup-language.html

Update a gtk.VBox dynamically - @http://www.devcomments.com/q524281/update-gtk-VBox-dynamically

Using ConfigParser - @http://docs.python.org/library/configparser.html

Gtk.Assistant Example - @http://pastebin.com/m19964865 PyWine Examples - @http://www.pygtk.org/articles/application-pygtk-glade/Building_an_Application_with_PyGTK_and_Glade.htm Embedding a Virtual Terminal in a GTK widget with python vte library - @http://coding.debuntu.org/python-embedding-virtual-terminal-gtk-widget-python-vte-library ComboBox - @http://python.developpez.com/cours/pygtktutorial/php/pygtken/sec-ComboBoxAndComboboxEntry.php

List only top-level directories
code format="python" [ name for name in os.listdir(thedir) if os.path.isdir(os.path.join(thedir, name)) ]

code **Download files via http** code format="python" import urllib2 u = urllib2.urlopen('http://server.com/file.html') localFile = open('file.html', 'w') localFile.write(u.read) localFile.close code **Download files via http with Progressbar** code format="python" import urllib2

url = "http://download.thinkbroadband.com/10MB.zip"

file_name = url.split('/')[-1] u = urllib2.urlopen(url) f = open(file_name, 'w') meta = u.info file_size = int(meta.getheaders("Content-Length")[0]) print "Downloading: %s Bytes: %s" % (file_name, file_size)

file_size_dl = 0 block_sz = 8192 while True: buffer = u.read(block_sz) if not buffer: break

file_size_dl += block_sz f.write(buffer) status = r"%10d [%3.2f%%]" % (file_size_dl, file_size_dl * 100. / file_size) status = status + chr(8)*(len(status)+1) print status,

f.close code

Classes Take Arguments
code format="python" Code:

class Person(object): def __init__(self, name, age): self.name = name self.age = age

person = Person("Joe", 25) print "%s is %s years old." % (person.name, person.age)

Here, the __init__ method of the Person class takes two arguments that allow you to customize the object. code

Set Custom Toolbar Image
code format="python" self.menuUpdate = builder.get_object("menuUpdate") self.menuUpdate.connect("activate", self.UpdateWiiTDB) img = gtk.Image img.set_from_file(path + '/images/wiitdb.png') self.menuUpdate.set_image(img)

code

Check if Image is valid picture
code format="python" import Image try: im = Image.open(filename) # do stuff except IOError: # filename not an image file code

Use ESC (escape) to close a window)
from @http://dwiel.net/blog/python-gtk-close-on-escape-key/ code format="python" def __init__(self): self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) self.window.connect("key-press-event", self.keypress) self.window.show

def keypress(self, widget, event) : if event.keyval == gtk.keysyms.Escape: gtk.main_quit

code

x