Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Beginner PyGTK and MySQL abuse request

Reply
Thread Tools

Beginner PyGTK and MySQL abuse request

 
 
Tom Wesley
Guest
Posts: n/a
 
      02-27-2005
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 adodb

class 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 0

if __name__ == "__main__":
AddressSearch()
main()
---end---


Cheers,
Tom
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Request.Form abuse Mark Rae ASP .Net 23 10-24-2006 01:09 PM
Abuse of the Net/Abuse on the Net Dr Wankfest Computer Support 14 07-19-2006 10:31 PM
request for abuse (critique a site) rossz HTML 31 09-25-2005 10:15 PM
Fighting abuse with abuse Mara Computer Support 70 03-24-2005 08:30 PM
Re: Fighting abuse with abuse Peter =?UTF-8?B?S8O2aGxtYW5u?= Computer Information 0 03-22-2005 10:31 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57