<commit_before># Copyright (c) 2015 <NAME>.
# Uranium is released under the terms of the AGPLv3 or higher.

from PyQt5.QtCore import pyqtSlot, pyqtProperty, pyqtSignal, QObject, QVariant, QUrl

from UM.Application import Application
from UM.PluginRegistry import PluginRegistry

from . import ContainerProxy

import copy

class ActiveProfileProxy(QObject):
    def __init__(self, parent = None):
        super().__init__(parent)
        self._setting_values = {}
        self._container_proxy = ContainerProxy.ContainerProxy(self._setting_values)
        self._active_profile = None
        self._manager = Application.getInstance().getMachineManager()
        self._manager.activeProfileChanged.connect(self._onActiveProfileChanged)
        self._onActiveProfileChanged()

    activeProfileChanged = pyqtSignal()

    @pyqtProperty(bool, notify = activeProfileChanged)
    def valid(self):
        return self._active_profile != None

    ## Check if the currently selected profile (not the working profile) is readonly
    @pyqtProperty(bool, notify = activeProfileChanged)
    def readOnly(self):
        profile = self._manager.getActiveProfile()
        if profile:
            return profile.isReadOnly()

    settingValuesChanges = pyqtSignal()

    @pyqtProperty(bool, notify = settingValuesChanges)
    def hasCustomisedValues(self):
        return self._active_profile.hasChangedSettings() == True

    @pyqtProperty(QObject, notify = settingValuesChanges)
    def settingValues(self):
        return self._container_proxy

    @pyqtSlot(str, "QVariant")
    def setSettingValue(self, key, value):
        self._active_profile.setSettingValue(key, value)

    ## Show any settings that have a value in the current profile but are not visible.
    @pyqtSlot(str)
    def showHiddenValues(self, category_id):
        category = Application.getInstance().getMachineManager().getActiveMachineInstance().getMachineDefinition().getSettingsCategory(category_id)
        for setting in category.getAllSettings():
            if not setting.isVisible() and self._active_profile.hasSettingValue(setting.getKey(), filter_defaults = False):
                setting.setVisible(True)
        category.visibleChanged.emit(category)

    ## Reload a clean copy of the currently selected profile.
    @pyqtSlot()
    def discardChanges(self):
        self._active_profile.setChangedSettings({})
        self._manager.setActiveProfile(self._manager.getActiveProfile(), force = True)

    ## Update the currently selected profile with the settings from the working profile and reselect it.
    @pyqtSlot()
    def updateProfile(self):
        changed_settings = copy.deepcopy(self._active_profile.getChangedSettings())
        self._manager.getActiveProfile().setChangedSettings(changed_settings)
        self._active_profile.setChangedSettings({})
        self._manager.setActiveProfile(self._manager.getActiveProfile(), force = True)

    def _onActiveProfileChanged(self):
        if self._active_profile:<commit_msg>Use more specific import<commit_after># Copyright (c) 2015 Ultimaker B.V.
# Uranium is released under the terms of the AGPLv3 or higher.

from PyQt5.QtCore import pyqtSlot, pyqtProperty, pyqtSignal, QObject, QVariant, QUrl

from UM.Application import Application
from UM.PluginRegistry import PluginRegistry

from . import ContainerProxy

from copy import deepcopy

class ActiveProfileProxy(QObject):
    def __init__(self, parent = None):
        super().__init__(parent)
        self._setting_values = {}
        self._container_proxy = ContainerProxy.ContainerProxy(self._setting_values)
        self._active_profile = None
        self._manager = Application.getInstance().getMachineManager()
        self._manager.activeProfileChanged.connect(self._onActiveProfileChanged)
        self._onActiveProfileChanged()

    activeProfileChanged = pyqtSignal()

    @pyqtProperty(bool, notify = activeProfileChanged)
    def valid(self):
        return self._active_profile != None

    ## Check if the currently selected profile (not the working profile) is readonly
    @pyqtProperty(bool, notify = activeProfileChanged)
    def readOnly(self):
        profile = self._manager.getActiveProfile()
        if profile:
            return profile.isReadOnly()

    settingValuesChanges = pyqtSignal()

    @pyqtProperty(bool, notify = settingValuesChanges)
    def hasCustomisedValues(self):
        return self._active_profile.hasChangedSettings() == True

    @pyqtProperty(QObject, notify = settingValuesChanges)
    def settingValues(self):
        return self._container_proxy

    @pyqtSlot(str, "QVariant")
    def setSettingValue(self, key, value):
        self._active_profile.setSettingValue(key, value)

    ## Show any settings that have a value in the current profile but are not visible.
    @pyqtSlot(str)
    def showHiddenValues(self, category_id):
        category = Application.getInstance().getMachineManager().getActiveMachineInstance().getMachineDefinition().getSettingsCategory(category_id)
        for setting in category.getAllSettings():
            if not setting.isVisible() and self._active_profile.hasSettingValue(setting.getKey(), filter_defaults = False):
                setting.setVisible(True)
        category.visibleChanged.emit(category)

    ## Reload a clean copy of the currently selected profile.
    @pyqtSlot()
    def discardChanges(self):
        self._active_profile.setChangedSettings({})
        self._manager.setActiveProfile(self._manager.getActiveProfile(), force = True)

    ## Update the currently selected profile with the settings from the working profile and reselect it.
    @pyqtSlot()
    def updateProfile(self):
        changed_settings = deepcopy(self._active_profile.getChangedSettings())
        self._manager.getActiveProfile().setChangedSettings(changed_settings)
        self._active_profile.setChangedSettings({})
        self._manager.setActiveProfile(self._manager.getActiveProfile(), force = True)

    def _onActiveProfileChanged(self):
        if self._active_profile:
{'fraction_non_alphanumeric': 0.08530335592659943, 'fraction_numerical': 0.001983798975037196, 'mean_word_length': 3.8829701372074252, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, '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': '2998030', 'n_tokens_mistral': 1569, 'n_tokens_neox': 1532, 'n_words': 387}