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

from PyQt5.QtCore import pyqtProperty, pyqtSignal, pyqtSlot

from cura.MachineAction import MachineAction
import cura.Settings.CuraContainerRegistry

import UM.Application
import UM.Settings.InstanceContainer
import UM.Settings.DefinitionContainer
import UM.Logger

import UM.i18n
catalog = UM.i18n.i18nCatalog("cura")

class MachineSettingsAction(MachineAction):
    def __init__(self, parent = None):
        super().__init__("MachineSettingsAction", catalog.i18nc("@action", "Machine Settings"))
        self._qml_url = "MachineSettingsAction.qml"

        self._container_index = 0

        self._container_registry = UM.Settings.ContainerRegistry.getInstance()
        self._container_registry.containerAdded.connect(self._onContainerAdded)

    def _reset(self):
        global_container_stack = UM.Application.getInstance().getGlobalContainerStack()
        if not global_container_stack:
            return

        # First check if there is a variant previously generated by this machine
        machine_settings_variant = global_container_stack.findContainer({"type": "variant", "subtype": "machine_settings"})
        if not machine_settings_variant:
            # There may be a variant created by the UMOUpgradeSelection machine action
            machine_settings_variant = global_container_stack.findContainer({"type": "variant", "id": global_container_stack.getName() + "_variant"})

        if not machine_settings_variant:
            variant = global_container_stack.findContainer({"type": "variant"})
            if variant and variant.getId() == "empty_variant":
                # There is an empty variant that we can use to store the machine settings
                container_index = global_container_stack.getContainerIndex(variant)
                machine_settings_variant = self._createMachineSettingsVariant(global_container_stack, container_index)
            else:
                # Add a second variant before the current variant to store the machine settings
                machine_settings_variant = self._createMachineSettingsVariant(global_container_stack)

        # Notify the UI in which container to store the machine settings data<commit_msg>Fix finding existing variant by id<commit_after># Copyright (c) 2016 <NAME>.
# Cura is released under the terms of the AGPLv3 or higher.

from PyQt5.QtCore import pyqtProperty, pyqtSignal, pyqtSlot

from cura.MachineAction import MachineAction
import cura.Settings.CuraContainerRegistry

import UM.Application
import UM.Settings.InstanceContainer
import UM.Settings.DefinitionContainer
import UM.Logger

import UM.i18n
catalog = UM.i18n.i18nCatalog("cura")

class MachineSettingsAction(MachineAction):
    def __init__(self, parent = None):
        super().__init__("MachineSettingsAction", catalog.i18nc("@action", "Machine Settings"))
        self._qml_url = "MachineSettingsAction.qml"

        self._container_index = 0

        self._container_registry = UM.Settings.ContainerRegistry.getInstance()
        self._container_registry.containerAdded.connect(self._onContainerAdded)

    def _reset(self):
        global_container_stack = UM.Application.getInstance().getGlobalContainerStack()
        if not global_container_stack:
            return

        # First check if there is a variant previously generated by this machine
        machine_settings_variant = global_container_stack.findContainer({"type": "variant", "subtype": "machine_settings"})
        if not machine_settings_variant:
            variant = global_container_stack.findContainer({"type": "variant"})
            if variant:
                if variant.getId() == global_container_stack.getName() + "_variant":
                    # There is a variant created by the UMOUpgradeSelection machine action
                    machine_settings_variant = variant
                if variant.getId() == "empty_variant":
                    # There is an empty variant that we can replace to store the machine settings
                    container_index = global_container_stack.getContainerIndex(variant)
                    machine_settings_variant = self._createMachineSettingsVariant(global_container_stack, container_index)

        if not machine_settings_variant:
            # Add a new variant to store the machine settings
            machine_settings_variant = self._createMachineSettingsVariant(global_container_stack)

        # Notify the UI in which container to store the machine settings data
{'fraction_non_alphanumeric': 0.0709437267352748, 'fraction_numerical': 0.006568863586599518, 'mean_word_length': 3.5182987141444113, 'pattern_counts': {'":': 11, '<': 5, '<?xml version=': 0, '>': 5, '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': '2009745', 'n_tokens_mistral': 1160, 'n_tokens_neox': 1101, 'n_words': 318}