Beginner PyGTK and MySQL abuse request

Discussion in 'Python' started by Tom Wesley, Feb 27, 2005.

  1. Tom Wesley

    Tom Wesley Guest

    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
    Tom Wesley, Feb 27, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. rossz
    Replies:
    31
    Views:
    1,015
    Rincewind
    Sep 25, 2005
  2. Kal Iyer
    Replies:
    10
    Views:
    646
    Victor Bazarov
    Dec 9, 2004
  3. Mark Rae

    Request.Form abuse

    Mark Rae, Oct 21, 2006, in forum: ASP .Net
    Replies:
    23
    Views:
    878
    Kevin Spencer
    Oct 24, 2006
  4. Mark Rae

    Preventing Request.Form abuse

    Mark Rae, Oct 24, 2006, in forum: ASP .Net
    Replies:
    12
    Views:
    507
    Mark Rae
    Oct 27, 2006
  5. Robb Meade
    Replies:
    7
    Views:
    147
Loading...

Share This Page