import logging
import os
import subprocess
import sys
from pathlib import Path

from PyQt6 import QtWidgets

import flandre
from flandre.config import C
from flandre.nodes.MainUI import MainUI


def kde_pyqt6_mainui():
    subprocess.run(['python', __file__, *sys.argv[1:]],
                   env=dict(XDG_CURRENT_DESKTOP="KDE",
                            XDG_RUNTIME_DIR="/run/user/1000",
                            XDG_SESSION_TYPE="wayland",
                            PYTHONPATH=os.environ.get('PYTHONPATH', flandre.MODULE_FOLDER.parent))
                   )


if __name__ == '__main__':
    if '--dev' in sys.argv:
        print('qt styles:',QtWidgets.QStyleFactory.keys())
    try:
        idx = sys.argv.index('--data_folder')
        C.data_folder = Path(sys.argv[idx + 1])
    except ValueError:
        pass

    logging.basicConfig(level=logging.INFO)
    MainUI()()
