class LocationWidget(ToolWidget): def __init__(self, filename, parent=None): super(LocationWidget, self).__init__(parent) self.temp_dir = QTemporaryDir() if self.temp_dir.isValid(): with exiftool.ExifTool(exiftool_exe()) as et: temp_file = os.path.join(self.temp_dir.path(), "geo.html") metadata = et.get_metadata(filename) try: lat = metadata["Composite:GPSLatitude"] long = metadata["Composite:GPSLongitude"] except KeyError: label = QLabel(self.tr("Geolocation data not found!")) modify_font(label, bold=True) label.setStyleSheet("color: #FF0000") label.setAlignment(Qt.AlignCenter) layout = QVBoxLayout() layout.addWidget(label) self.setLayout(layout) return html = '<iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d2948.532014673314!2d{}!3d{}!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x0%3A0x0!2zNDLCsDIxJzA5LjAiTiA3McKwMDUnMjguMiJX!5e0!3m2!1sit!2sit!4v1590074026898!5m2!1sit!2sit" width="600" height="450" frameborder="0" style="border:0;" allowfullscreen="" aria-hidden="false" tabindex="0"></iframe>'.format( long, lat) with open(temp_file, "w") as file: file.write(html) web_view = QWebEngineView() web_view.load(QUrl("file://" + temp_file)) layout = QVBoxLayout() layout.addWidget(web_view) self.setLayout(layout)
def ssimul(x, y): try: exe = ssimul_exe() if exe is None: raise FileNotFoundError temp_dir = QTemporaryDir() if temp_dir.isValid(): filename1 = os.path.join(temp_dir.path(), 'img1.png') cv.imwrite(filename1, x) filename2 = os.path.join(temp_dir.path(), 'img2.png') cv.imwrite(filename2, y) p = run([exe, filename1, filename2], stdout=PIPE) value = float(p.stdout) return value except FileNotFoundError: return -1
def butter(x, y): try: exe = butter_exe() if exe is None: raise FileNotFoundError temp_dir = QTemporaryDir() if temp_dir.isValid(): filename1 = os.path.join(temp_dir.path(), 'img1.png') cv.imwrite(filename1, x) filename2 = os.path.join(temp_dir.path(), 'img2.png') cv.imwrite(filename2, y) filename3 = os.path.join(temp_dir.path(), 'map.ppm') p = run([exe, filename1, filename2, filename3], stdout=PIPE) value = float(p.stdout) heatmap = cv.imread(filename3, cv.IMREAD_COLOR) return value, heatmap except FileNotFoundError: return -1, cv.cvtColor(np.full_like(x, 127), cv.COLOR_GRAY2BGR)
def testQSaveFile(self): dir = QTemporaryDir(QDir.tempPath() + "/XXXXXX.dir") self.assertTrue(dir.isValid()) saveFile = QSaveFile(dir.path() + "/test.dat") self.assertTrue(saveFile.open(QIODevice.WriteOnly)) saveFile.write(py3k.b("Test")) self.assertTrue(saveFile.commit()) self.assertTrue( os.path.exists(QDir.toNativeSeparators(saveFile.fileName())))
def ssimul(x, y): try: exe = ssimul_exe() if exe is None: raise FileNotFoundError temp_dir = QTemporaryDir() if temp_dir.isValid(): filename1 = os.path.join(temp_dir.path(), "img1.png") cv.imwrite(filename1, x) filename2 = os.path.join(temp_dir.path(), "img2.png") cv.imwrite(filename2, y) p = run([exe, filename1, filename2], stdout=PIPE) if p.returncode == 0: value = float(p.stdout) else: raise ValueError return value except (FileNotFoundError, ValueError) as _: return -1
class StructureWidget(ToolWidget): def __init__(self, filename, parent=None): super(StructureWidget, self).__init__(parent) self.temp_dir = QTemporaryDir() if self.temp_dir.isValid(): temp_file = os.path.join(self.temp_dir.path(), 'structure.html') p = run([exiftool_exe(), '-htmldump0', filename], stdout=PIPE) with open(temp_file, 'w') as file: file.write(p.stdout.decode('utf-8')) web_view = QWebEngineView() web_view.load(QUrl('file://' + temp_file)) layout = QVBoxLayout() layout.addWidget(web_view) self.setLayout(layout)
class HeaderWidget(ToolWidget): def __init__(self, filename, parent=None): super(HeaderWidget, self).__init__(parent) self.temp_dir = QTemporaryDir() if self.temp_dir.isValid(): temp_file = os.path.join(self.temp_dir.path(), "structure.html") p = run([exiftool_exe(), "-htmldump0", filename], stdout=PIPE) with open(temp_file, "w") as file: file.write(p.stdout.decode("utf-8")) web_view = QWebEngineView() web_view.load(QUrl("file://" + temp_file)) layout = QVBoxLayout() layout.addWidget(web_view) self.setLayout(layout) self.setMinimumWidth(900)