Hey,
I've spent far too long being spoilt by a relatively simplistic "just do it" style of database application in use at work and have decided to try my hand at some Python + MySQL + GTK over the next few days.
I've managed to steal/write a short script that asks for some input and searches a database and print the results and was wondering if people would have the time to suggest better ways of doing the limited set of things it does?
---search.py--- #!/usr/bin/env python
import pygtk
pygtk.require('2.0')
import gtk
import adodbclass AddressSearch:
def delete_event(self, widget, data=None):
gtk.main_quit()
return gtk.FALSE
def btn_search(self, widget, data=None):
conn = adodb.NewADOConnection('mysql')
conn.Connect('localhost','root','','rtl')
sql = "select * from address where match(Address1, Address2, Address3, Address4, Address5) against('+" + self.entry_address1.get_text() + "+" + self.entry_address2.get_text() + "+" + self.entry_address3.get_text() + "' in boolean mode);"
print sql
cursor = conn.Execute(sql)
while not cursor.EOF:
arr = cursor.GetRowAssoc(0)
print arr['rtlforename'], arr['rtlsurname']
cursor.MoveNext()
cursor.Close()
conn.Close()
def __init__(self):
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.set_title("Address search")
self.window.connect("delete_event", self.delete_event)
self.window.set_border_width(20) table = gtk.Table(5, 2, gtk.TRUE)
self.window.add(table) label = gtk.Label("Address:")
table.attach(label, 0, 1, 1, 5)
self.entry_address1 = gtk.Entry(max=80)
table.attach(self.entry_address1, 1, 2, 0, 1)
self.entry_address2 = gtk.Entry(max=80)
table.attach(self.entry_address2, 1, 2, 1, 2)
self.entry_address3 = gtk.Entry(max=80)
table.attach(self.entry_address3, 1, 2, 2, 3) button = gtk.Button(label='Search', stock=gtk.STOCK_OK)
button.connect("clicked", self.btn_search)
table.attach(button, 0, 1, 3, 4) button = gtk.Button(label="Quit", stock=gtk.STOCK_QUIT)
button.connect("clicked", self.delete_event)
table.attach(button, 1, 2, 3, 4)self.window.show_all()
def main():
gtk.main()
return 0if __name__ == "__main__":
AddressSearch()
main()
---end---
Cheers, Tom -- http://mail.python.org/mailman/listinfo/python-list
