self.setLayout(self.layout)
def beginMerge(self):
- print QFileDialog.getExistingDirectory( None, "Pick folder of photos", ".")
+ foldertext = QFileDialog.getExistingDirectory( None, "Pick folder of photos", ".")
+ if not foldertext.isEmpty():
+ print foldertext
+ dir = QDir(foldertext)
+ #dir.setNameFilters(["*.jpg", "*.JPG"])
+ q = QSqlQuery(self.db)
+ q.exec_("SELECT id, netid FROM people WHERE photo IS NULL")
+ rec = q.record()
+ col_id = rec.indexOf("id")
+ col_netid = rec.indexOf("netid")
+ while q.next():
+ # if netid.jpg exists, load it, write it to a QByteArray, bind it, and update that row
+ fileName = q.value(col_netid).toString() + QString(".jpg")
+ if not dir.exists(fileName):
+ fileName = q.value(col_netid).toString() + QString(".JPG")
+ if dir.exists(fileName):
+ image = QImage()
+ image.load(dir.absoluteFilePath(fileName))
+ ba = QByteArray()
+ buffer = QBuffer(ba)
+ buffer.open(QIODevice.WriteOnly)
+ image.save(buffer, "JPG")
+ buffer.close()
+ update_q = QSqlQuery(self.db)
+ update_q.prepare("UPDATE people SET photo=:photo WHERE id=:id")
+ update_q.bindValue(":photo", QVariant(ba))
+ update_q.bindValue(":id", q.value(col_id))
+ update_q.exec_()
+ print "Auto-imported photo for",q.value(col_netid).toString()