Andere Methode um zu überprüfen, ob eine CD im Laufwerk ist
This commit is contained in:
parent
1c9ffcf342
commit
1943f7d3dc
@ -1,3 +1,4 @@
|
||||
PyQt6
|
||||
pydicom
|
||||
pyinstaller
|
||||
wmi
|
||||
|
190
warchive.py
190
warchive.py
@ -6,6 +6,7 @@ import pydicom
|
||||
import shutil
|
||||
import random
|
||||
import ctypes
|
||||
import wmi
|
||||
from registry import Registry
|
||||
from PyQt6.QtWidgets import QDialog
|
||||
from PyQt6.QtWidgets import QLabel
|
||||
@ -44,41 +45,46 @@ class wArchive(QDialog):
|
||||
self.lLine3.setGeometry(10, 50, column1w, 20)
|
||||
self.tLine3 = QLabel("", self)
|
||||
self.tLine3.setGeometry(column2s, 50, column2w, 20)
|
||||
|
||||
|
||||
self.lLine3a = QLabel("CD im Laufwerk:", self)
|
||||
self.lLine3a.setGeometry(10, 70, column1w, 20)
|
||||
self.tLine3a = QLabel("", self)
|
||||
self.tLine3a.setGeometry(column2s, 70, column2w, 20)
|
||||
|
||||
self.lLine4 = QLabel("DICOMDIR-Datei gefunden:", self)
|
||||
self.lLine4.setGeometry(10, 70, column1w, 20)
|
||||
self.lLine4.setGeometry(10, 90, column1w, 20)
|
||||
self.tLine4 = QLabel("", self)
|
||||
self.tLine4.setGeometry(column2s, 70, column2w, 20)
|
||||
self.tLine4.setGeometry(column2s, 90, column2w, 20)
|
||||
|
||||
self.lLine5 = QLabel("DICOM-Verzeichnis gefunden:", self)
|
||||
self.lLine5.setGeometry(10, 90, column1w, 20)
|
||||
self.lLine5.setGeometry(10, 110, column1w, 20)
|
||||
self.tLine5 = QLabel("", self)
|
||||
self.tLine5.setGeometry(column2s, 90, column2w, 20)
|
||||
self.tLine5.setGeometry(column2s, 110, column2w, 20)
|
||||
|
||||
self.lLine6 = QLabel("Archiv beschreibbar:", self)
|
||||
self.lLine6.setGeometry(10, 110, column1w, 20)
|
||||
self.lLine6.setGeometry(10, 130, column1w, 20)
|
||||
self.tLine6 = QLabel("", self)
|
||||
self.tLine6.setGeometry(column2s, 110, column2w, 20)
|
||||
self.tLine6.setGeometry(column2s, 130, column2w, 20)
|
||||
|
||||
self.lLine7 = QLabel("DICOM-Dateien gefunden:", self)
|
||||
self.lLine7.setGeometry(10, 130, column1w, 20)
|
||||
self.lLine7.setGeometry(10, 150, column1w, 20)
|
||||
self.tLine7 = QLabel("", self)
|
||||
self.tLine7.setGeometry(column2s, 130, column2w, 20)
|
||||
self.tLine7.setGeometry(column2s, 150, column2w, 20)
|
||||
|
||||
self.lLine8 = QLabel("Name:", self)
|
||||
self.lLine8.setGeometry(10, 150, column1w, 20)
|
||||
self.lLine8.setGeometry(10, 170, column1w, 20)
|
||||
self.tLine8 = QLabel("", self)
|
||||
self.tLine8.setGeometry(column2s, 150, column2w, 20)
|
||||
self.tLine8.setGeometry(column2s, 170, column2w, 20)
|
||||
|
||||
self.lLine9 = QLabel("Geburtsdatum:", self)
|
||||
self.lLine9.setGeometry(10, 170, column1w, 20)
|
||||
self.lLine9.setGeometry(10, 190, column1w, 20)
|
||||
self.tLine9 = QLabel("", self)
|
||||
self.tLine9.setGeometry(column2s, 170, column2w, 20)
|
||||
self.tLine9.setGeometry(column2s, 190, column2w, 20)
|
||||
|
||||
self.lLine10 = QLabel("Dateien:", self)
|
||||
self.lLine10.setGeometry(10, 190, column1w, 20)
|
||||
self.lLine10.setGeometry(10, 210, column1w, 20)
|
||||
self.tLine10 = QLabel("", self)
|
||||
self.tLine10.setGeometry(column2s, 190, column2w, 20)
|
||||
self.tLine10.setGeometry(column2s, 210, column2w, 20)
|
||||
|
||||
self.bArchive = QPushButton("Archivieren", self)
|
||||
self.bArchive.setGeometry(10, 350, 380, 40)
|
||||
@ -107,83 +113,98 @@ class wArchive(QDialog):
|
||||
self.tLine3.setText(self.CDRomPath + ":\\")
|
||||
|
||||
# Logic
|
||||
cd_check = False
|
||||
dicomfile = False
|
||||
dicomdir = False
|
||||
target_writable = False
|
||||
has_dicom_files = False
|
||||
has_pName = False
|
||||
has_pBirth = False
|
||||
|
||||
# Check if DICOMDIR file exists
|
||||
if os.path.isfile(os.path.join(self.CDRomPath + ":", os.sep, "DICOMDIR")):
|
||||
dicomfile = True
|
||||
self.tLine4.setText(okay)
|
||||
self.tLine4.setStyleSheet("color: green")
|
||||
else:
|
||||
self.tLine4.setText(notokay)
|
||||
self.tLine4.setStyleSheet("color: red")
|
||||
|
||||
# Check if DICOM directory exists
|
||||
if os.path.isdir(os.path.join(self.CDRomPath + ":", os.sep, "DICOM")):
|
||||
dicomdir = True
|
||||
self.tLine5.setText(okay)
|
||||
self.tLine5.setStyleSheet("color: green")
|
||||
else:
|
||||
self.tLine5.setText(notokay)
|
||||
self.tLine5.setStyleSheet("color: red")
|
||||
# Check CD drive
|
||||
cds = wmi.WMI()
|
||||
for cd in cds.Win32_CDROMDrive():
|
||||
if cd.MediaLoaded:
|
||||
cd_check = True
|
||||
|
||||
# Check if ArchivePath is writable
|
||||
if os.access(self.ArchivePath, os.W_OK) is True:
|
||||
target_writable = True
|
||||
self.tLine6.setText(okay)
|
||||
self.tLine6.setStyleSheet("color: green")
|
||||
if cd_check:
|
||||
self.tLine3a.setText(okay)
|
||||
self.tLine3a.setStyleSheet("color: green")
|
||||
else:
|
||||
self.tLine6.setText(notokay)
|
||||
self.tLine6.setStyleSheet("color: red")
|
||||
|
||||
# List of all files under DICOM directory
|
||||
path = os.path.join(self.CDRomPath + ":", os.sep, "DICOM")
|
||||
self.files = []
|
||||
for x in os.walk(path):
|
||||
for y in glob.glob(os.path.join(x[0], "*")):
|
||||
if os.path.isfile(y):
|
||||
self.files.append(y)
|
||||
|
||||
# Get PatientsName from first file
|
||||
self.pName = ""
|
||||
self.pBirth = ""
|
||||
|
||||
try:
|
||||
dicom = pydicom.read_file(self.files[0])
|
||||
self.pName = str(dicom.PatientName)
|
||||
self.pBirth = str(dicom.PatientBirthDate)
|
||||
has_dicom_files = True
|
||||
has_pName = True
|
||||
has_pBirth = True
|
||||
self.tLine7.setText(okay)
|
||||
self.tLine7.setStyleSheet("color: green")
|
||||
except:
|
||||
self.tLine7.setText(notokay)
|
||||
self.tLine7.setStyleSheet("color: red")
|
||||
|
||||
# Output pName and pBirth
|
||||
if self.pName and self.pBirth:
|
||||
self.tLine8.setText(self.pName)
|
||||
self.tLine8.setStyleSheet("color: green")
|
||||
self.tLine9.setText(self.pBirth)
|
||||
self.tLine9.setStyleSheet("color: green")
|
||||
else:
|
||||
self.tLine8.setText(notokay)
|
||||
self.tLine8.setStyleSheet("color: red")
|
||||
self.tLine9.setText(notokay)
|
||||
self.tLine9.setStyleSheet("color: red")
|
||||
|
||||
# Output file count
|
||||
self.tLine10.setText(str(len(self.files)))
|
||||
self.tLine3a.setText(notokay)
|
||||
self.tLine3a.setStyleSheet("color: red")
|
||||
|
||||
# Activate bArchive and show progress bar
|
||||
if dicomfile and dicomdir and target_writable and has_dicom_files and has_pBirth and has_pName:
|
||||
self.bArchive.setEnabled(True)
|
||||
if cd_check:
|
||||
# Check if DICOMDIR file exists
|
||||
if os.path.isfile(os.path.join(self.CDRomPath + ":", os.sep, "DICOMDIR")):
|
||||
dicomfile = True
|
||||
self.tLine4.setText(okay)
|
||||
self.tLine4.setStyleSheet("color: green")
|
||||
else:
|
||||
self.tLine4.setText(notokay)
|
||||
self.tLine4.setStyleSheet("color: red")
|
||||
|
||||
# Check if DICOM directory exists
|
||||
if os.path.isdir(os.path.join(self.CDRomPath + ":", os.sep, "DICOM")):
|
||||
dicomdir = True
|
||||
self.tLine5.setText(okay)
|
||||
self.tLine5.setStyleSheet("color: green")
|
||||
else:
|
||||
self.tLine5.setText(notokay)
|
||||
self.tLine5.setStyleSheet("color: red")
|
||||
|
||||
# Check if ArchivePath is writable
|
||||
if os.access(self.ArchivePath, os.W_OK) is True:
|
||||
target_writable = True
|
||||
self.tLine6.setText(okay)
|
||||
self.tLine6.setStyleSheet("color: green")
|
||||
else:
|
||||
self.tLine6.setText(notokay)
|
||||
self.tLine6.setStyleSheet("color: red")
|
||||
|
||||
# List of all files under DICOM directory
|
||||
path = os.path.join(self.CDRomPath + ":", os.sep, "DICOM")
|
||||
self.files = []
|
||||
for x in os.walk(path):
|
||||
for y in glob.glob(os.path.join(x[0], "*")):
|
||||
if os.path.isfile(y):
|
||||
self.files.append(y)
|
||||
|
||||
# Get PatientsName from first file
|
||||
self.pName = ""
|
||||
self.pBirth = ""
|
||||
|
||||
try:
|
||||
dicom = pydicom.read_file(self.files[0])
|
||||
self.pName = str(dicom.PatientName)
|
||||
self.pBirth = str(dicom.PatientBirthDate)
|
||||
has_dicom_files = True
|
||||
has_pName = True
|
||||
has_pBirth = True
|
||||
self.tLine7.setText(okay)
|
||||
self.tLine7.setStyleSheet("color: green")
|
||||
except:
|
||||
self.tLine7.setText(notokay)
|
||||
self.tLine7.setStyleSheet("color: red")
|
||||
|
||||
# Output pName and pBirth
|
||||
if self.pName and self.pBirth:
|
||||
self.tLine8.setText(self.pName)
|
||||
self.tLine8.setStyleSheet("color: green")
|
||||
self.tLine9.setText(self.pBirth)
|
||||
self.tLine9.setStyleSheet("color: green")
|
||||
else:
|
||||
self.tLine8.setText(notokay)
|
||||
self.tLine8.setStyleSheet("color: red")
|
||||
self.tLine9.setText(notokay)
|
||||
self.tLine9.setStyleSheet("color: red")
|
||||
|
||||
# Output file count
|
||||
self.tLine10.setText(str(len(self.files)))
|
||||
|
||||
# Activate bArchive and show progress bar
|
||||
if dicomfile and dicomdir and target_writable and has_dicom_files and has_pBirth and has_pName:
|
||||
self.bArchive.setEnabled(True)
|
||||
|
||||
def copyDataThread(self):
|
||||
threads = []
|
||||
@ -197,7 +218,8 @@ class wArchive(QDialog):
|
||||
threads.append(self.copyDataThread)
|
||||
self.copyDataThread.start()
|
||||
|
||||
class copyData():
|
||||
|
||||
class copyData:
|
||||
def __init__(self, warchive, barchive, progressbar, files, archivepath, pname, pbirth):
|
||||
self.warchive = warchive
|
||||
self.barchive = barchive
|
||||
@ -229,7 +251,7 @@ class copyData():
|
||||
self.barchive.setEnabled(True)
|
||||
self.warchive.hide()
|
||||
|
||||
@staticmethod
|
||||
|
||||
def randomString(length):
|
||||
string = ""
|
||||
chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
|
||||
|
Loading…
Reference in New Issue
Block a user