dodano py6 app

This commit is contained in:
mpabi 2024-06-24 20:25:59 +00:00
parent 0b77052943
commit d5d251a738
3 changed files with 136 additions and 17 deletions

110
py6/app.py Normal file
View File

@ -0,0 +1,110 @@
import sys
from PySide6.QtWidgets import (QApplication, QMainWindow, QWidget, QVBoxLayout, QHBoxLayout, QFormLayout, QLineEdit, QPushButton, QLabel, QMessageBox, QFileDialog)
from PySide6.QtCore import Qt
from PySide6.QtGui import QPixmap
import requests
class PassportForm(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("PAssportForms")
self.main_layout = QHBoxLayout()
self.form_layout = QVBoxLayout()
self.data_layout = QFormLayout()
self.number_input = QLineEdit()
self.name_input = QLineEdit()
self.surname_input = QLineEdit()
self.gender_input = QLineEdit()
self.fingerprint_url_input = QLineEdit()
self.photo_url_input = QLineEdit()
self.data_layout.addRow("Passport Number", self.number_input)
self.data_layout.addRow("Name", self.name_input)
self.data_layout.addRow("Surname", self.surname_input)
self.data_layout.addRow("Gender", self.gender_input)
self.data_layout.addRow("Fingerprint URL", self.fingerprint_url_input)
self.data_layout.addRow("Photo URL", self.photo_url_input)
self.load_button = QPushButton("Load Data")
self.load_button.clicked.connect(self.load_data)
self.submit_button = QPushButton("Submit")
self.submit_button.clicked.connect(self.submit_form)
self.form_layout.addLayout(self.data_layout)
self.form_layout.addWidget(self.load_button)
self.form_layout.addWidget(self.submit_button)
self.image_layout = QVBoxLayout()
self.photo_label = QLabel("Photo")
self.photo_label.setFixedSize(200, 200)
self.photo_label.setStyleSheet("border: 1px solid black;")
self.photo_label.setAlignment(Qt.AlignCenter)
self.fingerprint_label = QLabel("Fingerprint")
self.fingerprint_label.setFixedSize(200, 200)
self.fingerprint_label.setStyleSheet("border: 1px solid black;")
self.fingerprint_label.setAlignment(Qt.AlignCenter)
self.image_layout.addWidget(self.photo_label)
self.image_layout.addWidget(self.fingerprint_label)
self.main_layout.addLayout(self.form_layout)
self.main_layout.addLayout(self.image_layout)
self.setLayout(self.main_layout)
def load_data(self):
passport_number = self.number_input.text()
response = requests.get(f"http://localhost:9999/passport/{passport_number}")
if response.status_code == 200:
data = response.json()
self.name_input.setText(data['name'])
self.surname_input.setText(data['surname'])
self.gender_input.setText(data['gender'])
self.fingerprint_url_input.setText(data['fingerprint_url'])
self.photo_url_input.setText(data['photo_url'])
self.load_image(self.photo_label, f"http://localhost:9999/static/imgs/data/{passport_number}-zdjecie.jpg")
self.load_image(self.fingerprint_label, f"http://localhost:9999/static/imgs/data/{passport_number}-odcisk.jpg")
else:
QMessageBox.critical(self, "Error", "Failed to load passport data")
def load_image(self, label, url):
response = requests.get(url)
if response.status_code == 200:
pixmap = QPixmap()
pixmap.loadFromData(response.content)
label.setPixmap(pixmap.scaled(label.size(), Qt.KeepAspectRatio))
else:
label.setText("Image not found")
def submit_form(self):
passport_data = {
"number": self.number_input.text(),
"name": self.name_input.text(),
"surname": self.surname_input.text(),
"gender": self.gender_input.text(),
"fingerprint_url": self.fingerprint_url_input.text(),
"photo_url": self.photo_url_input.text()
}
response = requests.post("http://localhost:9999/passport/", json=passport_data)
if response.status_code == 200:
QMessageBox.information(self, "Success", "Passport data submitted successfully")
else:
QMessageBox.critical(self, "Error", "Failed to submit passport data")
if __name__ == "__main__":
app = QApplication(sys.argv)
window = PassportForm()
window.show()
sys.exit(app.exec())

View File

@ -1,24 +1,33 @@
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
.passport-form {
display: flex;
justify-content: center;
align-items: flex-start;
margin-top: 20px;
}
nav {
margin-bottom: 20px;
.form-container {
display: flex;
flex-direction: column;
align-items: flex-start;
margin-right: 20px;
}
button {
padding: 10px 20px;
margin: 5px;
cursor: pointer;
.form-field {
margin-bottom: 10px;
}
button.active {
background-color: #2c3e50;
color: white;
.form-field label {
margin-right: 10px;
}
.images-container {
display: flex;
flex-direction: column;
align-items: flex-start;
}
.images-container img {
max-width: 200px;
margin-bottom: 10px;
}