From 9bee2c4a9d6f761faaa9f6a2af6dbaf9b7c6e0e1 Mon Sep 17 00:00:00 2001 From: James Boisture Date: Tue, 03 Aug 2010 19:55:24 +0000 Subject: added to the upload code so that it now checks if the file is to big to be uploaded. if it is it resizes the image until it is not too big. --- (limited to 'turtleart.py') diff --git a/turtleart.py b/turtleart.py index 57c34df..ee17366 100755 --- a/turtleart.py +++ b/turtleart.py @@ -477,7 +477,7 @@ class TurtleMain(): self.pop_up = gtk.Window() self.pop_up.set_default_size(600, 400) self.pop_up.connect('delete_event', self._stop_uploading) - table = gtk.Table(False, 1, 8) + table = gtk.Table( 1, 8,False) self.pop_up.add(table) login_label = gtk.Label(_('You must have an account at \ http://turtleartsite.sugarlabs.org to upload your project.')) @@ -553,7 +553,12 @@ http://turtleartsite.sugarlabs.org to upload your project.')) description = self.description_entry.get_buffer().get_text( *self.description_entry.get_buffer().get_bounds()) tafile, imagefile = self.tw.save_for_upload(title) - + if int(os.path.getsize(imagefile))> 950000: + import Image + while int(os.path.getsize(imagefile))>950000: + im = Image.open(imagefile) + out = im.resize((int(.9*im.size[0]),int(.9*im.size[1])),Image.ANTIALIAS) + out.save(imagefile,quatlity = 100) c = pycurl.Curl() c.setopt(c.POST, 1) c.setopt(c.FOLLOWLOCATION, 1) @@ -565,18 +570,18 @@ http://turtleartsite.sugarlabs.org to upload your project.')) ('title', title), ('description', description), ('upload_key',key), ('_formname', - 'image_create')]) + 'image_create')]) c.perform() error_code = c.getinfo(c.HTTP_CODE) c.close os.remove(imagefile) os.remove(tafile) if error_code == 400: - self.login_message.set_text(_('Failed to upload!')) + self.login_message.set_text(_('Failed to upload!')) else: - self.pop_up.hide() - self.uploading = False - + self.pop_up.hide() + self.uploading = False + if __name__ == "__main__": TurtleMain() -- cgit v0.9.1