From c9126ae19622eb22659f9e190080467ad4eb3d58 Mon Sep 17 00:00:00 2001 From: Kilian Valkhof Date: Wed, 31 Mar 2010 17:44:29 +0200 Subject: [PATCH] compress image, remove unneeded code, add more docstrings --- src/trimage/trimage.py | 34 +++++++--------------------------- website/ubuntu.png | Bin 1101 -> 1088 bytes 2 files changed, 7 insertions(+), 27 deletions(-) diff --git a/src/trimage/trimage.py b/src/trimage/trimage.py index 216ea26..7df6cf4 100755 --- a/src/trimage/trimage.py +++ b/src/trimage/trimage.py @@ -281,18 +281,20 @@ class TriTableModel(QAbstractTableModel): class Image: def __init__(self, fullpath): + """ gather image information. """ self.valid = False self.fullpath = fullpath - if path.isfile(self.fullpath): + if path.isfile(self.fullpath): self.filetype = determinetype(self.fullpath) if self.filetype in ["jpeg", "png"]: oldfile = QFileInfo(self.fullpath) self.shortname = oldfile.fileName() - self.oldfilesize = oldfile.size() - self.icon = QIcon(self.fullpath) + self.oldfilesize = oldfile.size() + self.icon = QIcon(self.fullpath) self.valid = True def _determinetype(self): + """ Determine the filetype of the file using imghdr. """ filetype=determinetype(self.fullpath) if filetype in ["jpeg", "png"]: self.filetype=filetype @@ -301,6 +303,7 @@ class Image: return self.filetype def compress(self): + """ Compress the image and return it to the thread. """ if not self.valid: raise "Tried to compress invalid image (unsupported format or not file)" runString = { @@ -346,7 +349,7 @@ class Worker(QThread): # append current image to list for i, listitem in enumerate(self.imagelist): - if listitem[4] == image: + if listitem[4] == image: self.imagelist.remove(listitem) self.imagelist.insert(i, (image.shortname, oldfilesizestr, newfilesizestr, ratiostr, image.fullpath, image.icon)) @@ -361,29 +364,6 @@ class Worker(QThread): else: print >>sys.stderr, u"[error] %s could not be compressed" % image.fullpath - -class TrimageTableView(QTableView): - """Init the table drop event.""" - def __init__(self, parent=None): - super(TrimageTableView, self).__init__(parent) - self.setAcceptDrops(True) - - def dragEnterEvent(self, event): - if event.mimeData().hasFormat("text/uri-list"): - event.accept() - else: - event.ignore() - - def dragMoveEvent(self, event): - event.accept() - - def dropEvent(self, event): - files = str(event.mimeData().data("text/uri-list")).strip().split() - for i, file in enumerate(files): - files[i] = QUrl(QString(file)).toLocalFile() - files=[i.toUtf8().decode("utf-8") for i in files] - self.emit(SIGNAL("fileDropEvent"), (files)) - if __name__ == "__main__": app = QApplication(sys.argv) myapp = StartQT4() diff --git a/website/ubuntu.png b/website/ubuntu.png index 0b2e82c8d04cfba0a449f55819093156c3583c05..3e77ad4940ef22aa903766ffff2c7810747cd707 100644 GIT binary patch delta 438 zcmX@hae!mPRHpiAo-U3d8t0P}6hwWtmc=!CuWRq0=$T=<>&3cvYfgOVVXivfFQ4A& zJ~`Voa1wLV&0`Lp*HlDS{^Xg><4{yIQ8DrcW>DJ*+2C9k)R$VE?s}9VuJur%#{mFWVEohHpw~ z%SXOrOsd6#Y)2VXO~smKM)S*_`}T<|vTH(2vWmKTJX6Y>&EXf;-4S~`wdakUe`x5_ z1ckXACQj9nt>Jc?o-Fiz9hS#_$xmVb*^F;mE}WCTzP|pREhx3Cs3tHw)X7Gk#WBSXcCpUrx*uMU%a($a9ARK;i%7a9kbLWofbidhmtHF$I`s0KH z`PZ+!*e`fAJ-AQzA=~M~tNQCRZ}iM-v9UNfY1!&Ud-go~w&=9kO|NbaZ@(8TR(j{M yjhM?Wyyxw?Gt)w)f64D3PYfQgbc;1>GO(I8inY(;WoBStVDNPHb6Mw<&;$U9_RISK delta 451 zcmX@Wah7AlRHpjHo-U3d6}P5d_-P&*D01NAU!UtX(|;-@w`rUd2vpiO{pHkCr>C?m zIyr%dlT&kZNXCSK7ow>>i+22<_IBO7>h!%^@A2>3|7P>`^tqo8H`bb$7$rtcx7|MF z<;`;qVXI@!*T-o6Ep`!LX|B=Dwyx_~?skZScRk~6>lyq{ziYkTAXcBk9X-ita`kzC_qJ9%oXnQq|8Y;XsI1u|8zy-@t&JQrf@*5^h?sD{ z>^yKXYR}g*0{ ziGQl>hWWA4(Mhpy-p;AAo+y>jxKdp-@Lv@BKkbR9PdlbRmOr|Yo7JpQETSUd1p@;E NgQu&X%Q~loCIGp$+WP