Side Projects:

Facedetection
Source Magic
Intrusion Detection System
Issue Tracker
Searchengine
RemindMe
Open API

Impressum
Andreas Beder 2012


Python QT GUI zur OpenAPI (Website Thumbnailer)

Ein guter Freund von mir war so freundlich, ein Python QT Interface zu meiner Website Thumbnailer API zu bauen.

Screenshot | Download

Hier der Sourcecode:

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtNetwork import *

from designs.FetchDialog import Ui_FetchDialog

import os,sys



class MainClass(QDialog):
    def __init__(self, parent = None):
        super(QDialog, self).__init__()
        
        QApplication.setStyle(QStyleFactory.create('plastique'))
        
        self.layout = Ui_FetchDialog()
        self.layout.setupUi(self)
        
        self.layout.progress.hide()
        self.layout.btn_save.hide()
        self.layout.pic.hide()
        
        self.connect(self.layout.btn_save, SIGNAL("pressed()"), self.saveDownloadedImage)
        self.connect(self.layout.btn_get, SIGNAL("pressed()"), self.progressDownload)
        
    def progressDownload(self):
        self.layout.progress.setValue(0)
        self.layout.progress.show()
        
        self.networkmanager = QNetworkAccessManager();

        request = QNetworkRequest()
        url = "http://codejungle.org/api/thumb_get.php?url=%s" % self.layout.url.text()

        request.setUrl(QUrl(url))
        
        self.reply = self.networkmanager.get(request)
        self.connect(self.reply, SIGNAL("downloadProgress(qint64,qint64)"), self.updateProgressBar)
        self.connect(self.networkmanager, SIGNAL("finished(QNetworkReply *)"), self.showThumbnail)
    
    def showThumbnail(self, replyFromServer):
        if(replyFromServer.isFinished() == True):
            imageData = replyFromServer.readAll()
            
            if(imageData.size() == None):
                print "Error while reading image!"
            
            pixmap = QPixmap()
            pixmap.loadFromData(imageData)
            
            self.originalPixmap = pixmap
            
            if(pixmap.width() > 800):
                pixmap = pixmap.scaledToWidth(800)

            self.layout.pic.setPixmap(pixmap)
            self.layout.pic.setMaximumHeight(600)
            self.layout.pic.setMaximumWidth(800)
            
            
            self.layout.pic.show()
            self.layout.btn_save.show()
            
            replyFromServer.deleteLater()
            
    def saveDownloadedImage(self):
        saveTo = QFileDialog.getSaveFileNameAndFilter(parent=None, caption=QString(), directory = QString(), filter = "Images (*.png)")
              
        if(self.originalPixmap.save(saveTo[0], "png")):
            QMessageBox.information(self, "Success!", "Your image is now saved!")
            
            self.layout.pic.hide()
            self.layout.btn_save.hide()
            self.resize(530, 132)

    def updateProgressBar(self, bytesRecieved, bytesTotal):
        self.layout.progress.setMaximum(bytesTotal)
        self.layout.progress.setValue(bytesRecieved)
        
        if(self.layout.progress.value() == bytesTotal):
            self.layout.progress.hide()
    
if __name__ == "__main__":
    app = QApplication([])
    software = MainClass()
    software.show()
    app.exec_()



Known Bugs:

Vielen Dank an Mario (www.unite-it.at) an dieser Stelle.

Andreas