почему код приведенный ниже завершается с ошибкой -1073740791 (0xC0000409)
import os
import json
import subprocess
from PyQt5.QtWidgets import (
QApplication, QWidget, QLabel, QPushButton, QVBoxLayout, QHBoxLayout,
QLineEdit, QFileDialog, )
import webbrowser
def _run_exiftool(filename):
cmd = ['exiftool', '-j', filename]
result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
return json.loads(result.stdout)
class MyWidget(QWidget):
def __init__(self):
super().__init__()
self.input_line_edit = QLineEdit()
self.input_button = QPushButton("Выбрать файл")
self.datetime_label = QLabel("Дата и время: ")
self.show_datetime_button = QPushButton("Дата и время")
self.map_button = QPushButton("Показать на карте")
self.clear_button = QPushButton("Очистить метаданные")
self.save_button = QPushButton("Сохранить")
input_layout = QHBoxLayout()
input_layout.addWidget(self.input_line_edit, 2)
input_layout.addWidget(self.input_button, 1, )
function_layout = QHBoxLayout()
function_layout.addWidget(self.show_datetime_button, 1)
function_layout.addWidget(self.map_button, 1)
function_layout.addWidget(self.clear_button, 1)
function_layout.addWidget(self.save_button, 1)
main_layout = QVBoxLayout()
main_layout.addLayout(input_layout)
main_layout.addWidget(self.datetime_label, 1)
main_layout.addLayout(function_layout)
self.setLayout(main_layout)
self.input_button.clicked.connect(self.select_file)
self.show_datetime_button.clicked.connect(self.show_datetime)
self.map_button.clicked.connect(self.show_map)
self.clear_button.clicked.connect(self.clear_metadata)
self.save_button.clicked.connect(self.save_photo)
def select_file(self):
filename, _ = QFileDialog.getOpenFileName(
self, "Выберите фотографию", os.path.expanduser("~"),
"Image files (*.png *.jpg *.jpeg *.heic);;Video files (*.mp4)")
self.input_line_edit.setText(filename)
def show_datetime(self):
filename = self.input_line_edit.text()
metadata = _run_exiftool(filename)[0]
date_time = metadata.get("ModifyDate")
if date_time:
self.datetime_label.setText("Дата и время: " + date_time)
else:
self.datetime_label.setText("Метаданные не обнаружены")
def show_map(self):
filename = self.input_line_edit.text()
metadata = _run_exiftool(filename)[0]
lat = metadata.get("GPSLatitude")
lon = metadata.get("GPSLongitude")
if lat and lon:
url = f"
https://google.com/maps/search/{lat},{lon}"
webbrowser.open(url)
else:
self.datetime_label.setText("Данных о геолокации не обнаружено")
def clear_metadata(self):
filename = self.input_line_edit.text()
if not filename:
subprocess.run(["exiftool", "-overwrite_original", "-all=", filename])
def save_photo(self):
input_filename = self.input_line_edit.text()
if input_filename:
save_filename, _ = QFileDialog.getSaveFileName(
self, "Сохранить фото", os.path.expanduser("~"), "Image files (*.png *.jpg *.jpeg)")
if save_filename:
subprocess.run(
["exiftool", "-overwrite_original", "-all=", "-tagsfromfile", input_filename, save_filename])
def run(self):
self.show()
QApplication.exec_()
if __name__ == '__main__':
app = QApplication([])
widget = MyWidget()
widget.run()