def ubbaddkvp(btn, self, vbx): """add a key-value pair to vbx""" hbx = flauxtext.gtk.HBox() hbx.show() vbx.pack_start(hbx) k = flauxtext.gtk.Entry() k.show() k.grab_focus() hbx.pack_start(k) v = flauxtext.gtk.Entry() v.show() hbx.pack_start(v) k.connect('focus-out-event', lambda wid, evt=None: [v.set_text(self.ubbpostdata[kee]) for kee in [k.get_text()] if k.get_text() in self.ubbpostdata.keys()]) # when you tab out of the key Entry widget, try to set the value Entry widget's value to its previous value v.connect("focus-out-event", lambda wid, evt=None: self.ubbpostdata.update({k.get_text(): v.get_text()})) # when you tab out of the value Entry widget, update self.ubbpostdata with the key-value pair you entered k.grab_focus() def ubbpost(*a, **kw): ''' opens a dialog asking for name, pass, and a url containing either 1 or 2 instances of '%s', which will be replaced with forum number and/or thread number also provides the options for specifying a subject, and adding as many other name:value pairs as desired http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/305288 ''' d = flauxtext.gtk.Dialog("spam?", flauxtext.self.w, flauxtext.gtk.DIALOG_NO_SEPARATOR, (flauxtext.gtk.STOCK_OK, 1, flauxtext.gtk.STOCK_CANCEL, 0)) self.response_on_esc(d) t = flauxtext.gtk.Table(5, 2) d.vbox.pack_start(t) t.attach(flauxtext.gtk.Label('form url'), 0, 1, 0, 1) formurl = flauxtext.gtk.Entry() formurl.set_text(self.ubbpostdata['formurl']) formurl.connect('focus-out-event', lambda wid, evt: self.ubbpostdata.update({'formurl':formurl.get_text()})) t.attach(formurl, 1, 2, 0, 1) t.attach(flauxtext.gtk.Label('handle'), 0, 1, 1, 2) nym = flauxtext.gtk.Entry() nym.set_text(self.ubbpostdata['name']) nym.connect('focus-out-event', lambda wid, evt: self.ubbpostdata.update({'name':nym.get_text()})) t.attach(nym, 1, 2, 1, 2) t.attach(flauxtext.gtk.Label('pass'), 0, 1, 2, 3) pw = flauxtext.gtk.Entry() t.attach(pw, 1, 2, 2, 3) pw.set_text(self.ubbpostdata['pass']) pw.connect('focus-out-event', lambda wid, evt: self.ubbpostdata.update({'pass':pw.get_text()})) t.attach(flauxtext.gtk.Label('text val'), 0, 1, 3, 4) txtn = flauxtext.gtk.Entry() txtn.set_text(self.ubbpostdata['txtn']) txtn.connect('focus-out-event', lambda wid, evt: self.ubbpostdata.update({'txtn':txtn.get_text()})) t.attach(txtn, 1, 2, 3, 4) mkkvbtn = flauxtext.gtk.Button('add a key-value pair') mkkvbtn.connect('clicked', ubbaddkvp, self, d.vbox) t.attach(mkkvbtn, 0, 2, 4, 5) d.show_all() r = d.run() d.destroy() if r: flauxtext.imp0rt('httplib') fields = [('','')] host = 'fauxlkner.sf.net' selector = host+'/index.html' BOUNDARY = '----------you-SHALL-NOT-PASS-the-XMZTEIU------------$' # rot13+atbash that mess CRLF = body = '\r\n' for (k, v) in fields: body += '--' + BOUNDARY + CRLF + ('Content-Disposition: form-data; name="%s"' % key) + CRLF*2 + value + CRLF body += '--' + BOUNDARY + '--' + CRLF h = flauxtext.httplib.HTTPConnection(host) headers = {'User-Agent': 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.10) Gecko/20050916 Firefox/1.0.6', 'Content-Type': 'multipart/form-data; boundary=' + BOUNDARY} print repr(body), '\n'*5, headers, '\n', selector h.request('POST', selector, body, headers) res = h.getresponse() d = flauxtext.gtk.Dialog('re: your post', self.w, flauxtext.gtk.DIALOG_NO_SEPARATOR|flauxtext.gtk.DIALOG_DESTROY_WITH_PARENT, (flauxtext.gtk.STOCK_OK, 0)) d.vbox.pack_start(flauxtext.gtk.Label('\n'.join([res.status, res.reason, res.read()]))) d.show_all() d.run() d.destroy()