<commit_before>"""
Utility dialogs for starcheat itself
"""

import os, sys, platform, subprocess
from PyQt5.QtWidgets import QDialog, QFileDialog, QMessageBox
from PyQt5.QtWidgets import QListWidgetItem, QProgressDialog
from PyQt5 import QtGui, QtCore

import saves, assets, logging, config
import qt_options, qt_openplayer, qt_about
from config import Config
from gui.common import preview_icon

# TODO: there are way too many html templates and message text in here now
# it should all be moved to a templates file or something

# TODO: we can use this for rebuild db but have to skip the sys.exit and
# file remove calls
def build_assets_db(parent):
    assets_db_file = Config().read("assets_db")
    starbound_folder = Config().read("starbound_folder")
    assets_db = assets.Assets(assets_db_file, starbound_folder)

    missing_assets_text = """<html><body>
    <p>starcheat couldn't find any Starbound assets. You should double check:</p>
    <ol>
    <li>You selected the right Starbound folder.</li>
    <li>The assets you want to use have been unpacked. Instructions are
    <a href="https://github.com/wizzomafizzo/starcheat#unpacking-starbound-assets">here</a>
    and this includes vanilla Starbound assets.</li>
    </ol>
    <p>Once that's done, try restart starcheat to run the setup again.</p>
    </body></html>"""

    def bad_asset_dialog():
        dialog = QMessageBox()
        dialog.setText("Unable to index assets.")
        dialog.setInformativeText(missing_assets_text)
        dialog.setIcon(QMessageBox.Critical)
        dialog.exec()
        assets_db.db.close()
        os.remove(assets_db_file)

    assets_db.init_db()
    asset_files = assets_db.find_assets()
    total = 0
    progress = QProgressDialog("Indexing Starbound assets...",
                               "Cancel", 0, len(asset_files),
                               parent)
    progress.setWindowModality(QtCore.Qt.WindowModal)
    progress.forceShow()

    for i in assets_db.create_index():
        total += 1
        progress.setValue(total)
        if progress.wasCanceled():
            assets_db.db.close()
            os.remove(assets_db_file)
            return False

    progress.hide()
    if total == 0:
        bad_asset_dialog()
        return False
    else:
        return True

def save_modified_dialog():<commit_msg>Make index progress dialog application modal<commit_after>"""
Utility dialogs for starcheat itself
"""

import os, sys, platform, subprocess
from PyQt5.QtWidgets import QDialog, QFileDialog, QMessageBox
from PyQt5.QtWidgets import QListWidgetItem, QProgressDialog
from PyQt5 import QtGui, QtCore

import saves, assets, logging, config
import qt_options, qt_openplayer, qt_about
from config import Config
from gui.common import preview_icon

# TODO: there are way too many html templates and message text in here now
# it should all be moved to a templates file or something

# TODO: we can use this for rebuild db but have to skip the sys.exit and
# file remove calls
def build_assets_db(parent):
    assets_db_file = Config().read("assets_db")
    starbound_folder = Config().read("starbound_folder")
    assets_db = assets.Assets(assets_db_file, starbound_folder)

    missing_assets_text = """<html><body>
    <p>starcheat couldn't find any Starbound assets. You should double check:</p>
    <ol>
    <li>You selected the right Starbound folder.</li>
    <li>The assets you want to use have been unpacked. Instructions are
    <a href="https://github.com/wizzomafizzo/starcheat#unpacking-starbound-assets">here</a>
    and this includes vanilla Starbound assets.</li>
    </ol>
    <p>Once that's done, try restart starcheat to run the setup again.</p>
    </body></html>"""

    def bad_asset_dialog():
        dialog = QMessageBox()
        dialog.setText("Unable to index assets.")
        dialog.setInformativeText(missing_assets_text)
        dialog.setIcon(QMessageBox.Critical)
        dialog.exec()
        assets_db.db.close()
        os.remove(assets_db_file)

    assets_db.init_db()
    asset_files = assets_db.find_assets()
    total = 0
    progress = QProgressDialog("Indexing Starbound assets...",
                               "Cancel", 0, len(asset_files),
                               parent)
    progress.setWindowModality(QtCore.Qt.ApplicationModal)
    progress.forceShow()

    for i in assets_db.create_index():
        total += 1
        progress.setValue(total)
        if progress.wasCanceled():
            assets_db.db.close()
            os.remove(assets_db_file)
            return False

    progress.hide()
    if total == 0:
        bad_asset_dialog()
        return False
    else:
        return True

def save_modified_dialog():
{'fraction_non_alphanumeric': 0.09179770505737357, 'fraction_numerical': 0.0029749256268593286, 'mean_word_length': 3.0788561525129983, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2935792', 'n_tokens_mistral': 1392, 'n_tokens_neox': 1359, 'n_words': 404}