auto detection of the QT enviroment
All checks were successful
Build MuCaPy Executable / build-and-package (push) Successful in 1m43s

This commit is contained in:
rattatwinko
2025-06-07 22:46:14 +02:00
parent 562e2958b1
commit 9f5c3f014c

View File

@@ -2226,16 +2226,55 @@ class MainWindow(QMainWindow):
self.start_btn.setEnabled(False) self.start_btn.setEnabled(False)
self.stop_btn.setEnabled(False) self.stop_btn.setEnabled(False)
class initQT():
def __init__(self):
self.session_type = None # This is for QT #
#--------------------#
self.env = os.environ.copy() # This is for CV2 #
def getenv(self):
# If the OS is Linux get Qts Session Type
if platform.system() == "Linux":
self.session_type = os.getenv("XDG_SESSION_TYPE")
print(f"got {self.session_type} ")
else:
# If theres no Type then Exit 1
print(
"No XDG Session Type found!" \
"echo $XDG_SESSION_TYPE" \
"Run this command in bash!"
)
exit(1)
def setenv(self):
# Set the Session Type to the one it got
if self.session_type:
os.environ["XDG_SESSION_TYPE"] = self.session_type
print(f"set the ENVVAR to {self.session_type}")
else:
# If this fails then just exit with 1
print(
"Setting the XDG_SESSION_TYPE failed!" \
f"export XDG_SESSION_TYPE={self.session_type}" \
"run this command in bash"
)
exit(1)
def shutupCV(self):
# This needs some fixing as this only works before importing CV2 ; too much refactoring work tho!
os.environ["OPENCV_LOG_LEVEL"] = "ERROR"
if __name__ == "__main__": if __name__ == "__main__":
# Set the env # Initialize Qt
os.environ["XDG_SESSION_TYPE"] = "xcb" qt = initQT()
qt.getenv()
qt.setenv()
qt.shutupCV()
app = QApplication(sys.argv) app = QApplication(sys.argv)
# Set application style to Fusion for better dark mode support # Set application style to Fusion for better dark mode support
app.setStyle("Fusion") app.setStyle("Fusion")
window = MainWindow() window = MainWindow()
window.show() window.show()