Strange problem with Tkinter... photos don't show on first iteration.
Hi all. Just having a weird problem with tkinter. I'm trying to make a gui that shows results from an image search, with a forward and back button so the user can compare results from different pages. All that's working fine... The problem I'm having is that the images don't show onscreen the first time the first page of results shows up. When I click the search again button, and have more than the original results page to toggle between, the images __do__ show up on the first page of results. (and on the second, etc, etc.) Which is to say, there's no error messages, and on the first page, the first time it's shown, the Toplevel formats correctly, and there are spaces where the images should be that are the correct size, just... no images. It's baffling me. Perhaps someone can help. Cheers, Al. Script attached (apologies for it not being as neat as it probably should be... :) from Tkinter import * import sys import cPickle #opens gui and displays returned image thumbnails class Im_Res1: def __init__(self, master, lof, pageno): self.master = root root.withdraw() nav_child(master, lof, pageno) self.master.mainloop() # the child window class class nav_child: def __init__(self, master, lof, pageno): self.slave = Toplevel(master) self.slave.grid() self.slave.title(Image Results) self.picts = [] lif = lof[pageno] lenlif = len(lif) for r in range(lenlif): j = lif[r] f = j[2] self.img = PhotoImage(file = f) self.picts.append(self.img) print self.picts = , self.picts for g in range(lenlif): text = (lif[g])[1]# label text def callback(text=text): x=win32com.client.Dispatch('InternetExplorer.Application.1') x.Visible=1 x.Navigate(text) p = open(VerRes.txt, 'w') p.write(text) p.close() root.destroy() if 0= g 6: buttonx = Button(self.slave, text=(text), height=1, width=23, command=callback) buttonx.grid(row=3, column=g) Label(self.slave, text=((lif[g])[0])).grid(row=2, column=g) self.Im = self.picts[g] Label(self.slave, image=self.Im).grid(row=1, column=g) elif 6= g 12: buttonx = Button(self.slave, text=(text), height=1, width=23, command=callback) buttonx.grid(row=6, column=(g-6)) Label(self.slave, text=((lif[g])[0])).grid(row=5, column=(g-6)) self.Im = self.picts[g] Label(self.slave, image=self.Im).grid(row=4, column=(g-6)) elif 12= g 18: buttonx = Button(self.slave, text=(text), height=1, width=23, command=callback) buttonx.grid(row=9, column=(g-12)) Label(self.slave, text=((lif[g])[0])).grid(row=8, column=(g-12)) self.Im = self.picts[g] Label(self.slave, image=self.Im).grid(row=7, column=(g-12)) elif 18= g 24: buttonx = Button(self.slave, text=(text), height=1, width=23, command=callback) buttonx.grid(row=12, column=(g-18)) Label(self.slave, text=((lif[g])[0])).grid(row=11, column=(g-18)) self.Im = self.picts[g] Label(self.slave, image=self.Im).grid(row=10, column=(g-18)) def search_again(lof=lof, pageno=pageno): p = open(VerRes.txt, 'w') pageno = pageno + 1 reslist = [pageno, 1, lof] cPickle.dump(reslist, p) p.close() root.destroy() SearchAgain = Button(self.slave, text='Search Again.', fg=blue, command=search_again) SearchAgain.grid(row=13, column=2, columnspan=2) if pageno 0: def Back_Cmd(lof=lof, pageno=pageno): pageno = pageno - 1 nav_child(master, lof, pageno) self.slave.destroy() backbutton = Button(self.slave, text=Previous Page, height=1, width=23, command=Back_Cmd) backbutton.grid(row=13, column=0) if pageno (len(lof) - 1): def Fwd_Cmd(lof=lof, pageno=pageno): pageno = pageno + 1 nav_child(master, lof, pageno) self.slave.destroy() fwdbutton = Button(self.slave, text=Next Page, height=1, width=23, command=Fwd_Cmd) fwdbutton.grid(row=13, column=5) def Quit_Search(): root.destroy() sys.exit(0) quitbutton = Button(self.slave, text='QUIT', fg=red, command=Quit_Search) quitbutton.grid(row=14, column=2, columnspan=2) # lof is nested lists 'cos there's more than one page of more than one image- Images don't show on the first results page... *sigh* Obviously,
Re: Strange problem with Tkinter... photos don't show on first iteration.
Yup, That's the problem. Can't thank you enough. I'd read about Tkinter garbage collection, but, like car crashes and lung cancer, you never think it's going to happen to you... thanks once again. Cheers, Al. Fredrik Lundh wrote: [EMAIL PROTECTED] wrote: Just having a weird problem with tkinter. I'm trying to make a gui that shows results from an image search, with a forward and back button so the user can compare results from different pages. All that's working fine... The problem I'm having is that the images don't show onscreen the first time the first page of results shows up. When I click the search again button, and have more than the original results page to toggle between, the images __do__ show up on the first page of results. (and on the second, etc, etc.) Which is to say, there's no error messages, and on the first page, the first time it's shown, the Toplevel formats correctly, and there are spaces where the images should be that are the correct size, just... no images. It's baffling me. Perhaps someone can help. this is explained in the Python FAQ, and also in the note at the bottom of this page: http://effbot.org/tkinterbook/photoimage.htm /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Strange problem with Tkinter... photos don't show on first iteration.
And I say once again: I can't thank you enough. YOU ROCK! cheers, al. (Just changed the code in my main program, and it WORKS! The previous thankyou was only a preliminary.) ps I really like python, too. :) [EMAIL PROTECTED] wrote: Yup, That's the problem. Can't thank you enough. I'd read about Tkinter garbage collection, but, like car crashes and lung cancer, you never think it's going to happen to you... thanks once again. Cheers, Al. Fredrik Lundh wrote: [EMAIL PROTECTED] wrote: Just having a weird problem with tkinter. I'm trying to make a gui that shows results from an image search, with a forward and back button so the user can compare results from different pages. All that's working fine... The problem I'm having is that the images don't show onscreen the first time the first page of results shows up. When I click the search again button, and have more than the original results page to toggle between, the images __do__ show up on the first page of results. (and on the second, etc, etc.) Which is to say, there's no error messages, and on the first page, the first time it's shown, the Toplevel formats correctly, and there are spaces where the images should be that are the correct size, just... no images. It's baffling me. Perhaps someone can help. this is explained in the Python FAQ, and also in the note at the bottom of this page: http://effbot.org/tkinterbook/photoimage.htm /F -- http://mail.python.org/mailman/listinfo/python-list
Is it possible to get image size before/without downloading?
Hi there: a bit of a left-field question, I think. I'm writing a program that analyses image files downloaded with a basic crawler, and it's slow, mainly because I only want to analyse files within a certain size range, and I'm having to download all the files on the page, open them, get their size, and then only analyse the ones that are in that size range. Is there a way (in python, of course!) to get the size of images before or without downloading them? I've checked around, and I can't seem to find anything promising... Anybody got any clues? Cheers, Al. -- http://mail.python.org/mailman/listinfo/python-list
Re: Is it possible to get image size before/without downloading?
Thanks Josiah I thought as much... Still, it'll help me immensely to cut the downloads from a page to only those that are within a file-size range, even if this gets me some images that are out-of-spec dimensionally. Cheers, Al. (Oh, and if anyone still has a bright idea about how to get image dimensions without downloading, it'd be great to hear!) Josiah Manson wrote: In the head of an HTTP response, most servers will specify a Content-Length that is the number of bytes in the body of the response. Normally, when using the GET method, the header is returned with the body following. It is possible to make a HEAD request to the server that will only return header information that will hopefully tell you the file size. If you want to know the actual dimensions of the image, I don't know of anything in HTTP that will tell you. You will probably just have to download the image to find that out. Relevant HTTP specs below if you care. http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html The above is true regardless of language. In python it appears there an httplib module. I would call request using the method head. http://docs.python.org/lib/httpconnection-objects.html [EMAIL PROTECTED] wrote: Hi there: a bit of a left-field question, I think. I'm writing a program that analyses image files downloaded with a basic crawler, and it's slow, mainly because I only want to analyse files within a certain size range, and I'm having to download all the files on the page, open them, get their size, and then only analyse the ones that are in that size range. Is there a way (in python, of course!) to get the size of images before or without downloading them? I've checked around, and I can't seem to find anything promising... Anybody got any clues? Cheers, Al. -- http://mail.python.org/mailman/listinfo/python-list
Re: blob problems in pysqlite
Excellent. Got that working. Now, how to get the pickled data out of the database? I'm trying to use cPickle.loads(data) (code attached), and I get a: TypeError: loads() argument 1 must be string, not list Is there a workaround for this? I've tried converting the List of files to a String before cPickling it, but the same result (expected). I've read, in a post of Gerhard's somewhere, about marshal, but I don't see how this would work for the HTML. (where I have the same problem.) Cheers, Al. ps. Tim: Your clean take on my code made me realise that I had stupidly included quotes in the URL argument passed to sqlite, ie I'd ended up with, effectively, DBURL= 'http://www.myhomepage.com;', rather than = 'http://www.myhomepage.com'. It's the little things that matter... Thanks for your help. Oh, and your 'representative samples' are spot on! #code starts URL = http://www.myhomepage.com; db = sqlite.connect(ImageInfoDatabase.db) c = db.cursor() DBURL = str(URL) print DBURL c.execute(select Images from FileURLInfo where URL= ?;, (DBURL,)) KnownFilesResult = c.fetchall() print KnownFilesResult#where I get a r/w buffer, as expected cPickle.loads(KnownFilesResult)#where I get the error described above. #code ends. -- http://mail.python.org/mailman/listinfo/python-list
Re: blob problems in pysqlite
Woohoo! You rock, Gerhard. That's inspired. I'm sure I can sort this out now. Both you and Tim have been an enormous help. Cheers, Al. (Oh, and Tim: tip noted. I feel bad about not posting complete code- I do normally (not in python), but can't for this one. Thanks for wading your way through it anyway.) -- http://mail.python.org/mailman/listinfo/python-list
blob problems in pysqlite
Hi there. I'm a long-time lurker and (I think) first time poster. Only relatively new to python, and I'm trying to get pysqlite to work with binary data, and having a tough time of it. I want to set up a table with: - a URL, - some filenames related to that URL, - and some simple generated HTML. Problem is, when I try to do this, and query, say, the filenames from the filename field 'Images', I'm not getting a result. Just []... I've been googling this one for days (documentation for this seems really scant), and I've tried a whole bunch of things, but my code as it is now is attached. Can anyone give me some idea what i'm doing wrong (or if this is indeed possible)? Any and all help much appreciated. Cheers, Al. #script starts from pysqlite2 import dbapi2 as sqlite HTMLoutputFile = open('ImageResults.html', 'wb') cPickle.dump(OutputHTML, HTMLoutputFile) # outputHTML is a standard html page HTMLoutputFile.close() DBfilelistFile = open('DBFilesList.txt', 'wb') cPickle.dump(DBfilelist, DBfilelistFile) # DBfileList is a list of filenames in the form ['XXX.jpg', 'XXX.jpg' etc] DBfilelistFile.close() DBURL = 'http://www.myhomepage.html' blobdata = open('ImageResults.html', 'rb').read() blobfiles = open('DBFilesList.txt', 'rb').read() db = sqlite.connect(ImageInfoDatabase.db) c = db.cursor() try: c.execute(create table FileURLInfo (URL CHAR(100), Images, HTML)) except: print 'database exists' c.execute(INSERT INTO FileURLInfo VALUES (?,?,?);, (DBURL, sqlite.Binary(blobfiles), sqlite.Binary(blobdata)),) c.execute(select Images from FileURLInfo where URL = 'http://www.myhomepage.html',) DBImageResult = c.fetchall() print DBImageResult #script ends -- http://mail.python.org/mailman/listinfo/python-list