<commit_before>#!/usr/bin/env python3
import os
import logging

from gi.repository import Gtk
import lib.connection as Connection

from lib.config import Config
from vocto.composite_commands import CompositeCommand
from lib.toolbar.buttons import Buttons
from lib.uibuilder import UiBuilder


class PreviewToolbarController(object):
    """Manages Accelerators and Clicks on the Preview Composition Toolbar-Buttons"""

    def __init__(self, win, uibuilder):
        self.initialized = False

        self.log = logging.getLogger('PreviewToolbarController')

        accelerators = Gtk.AccelGroup()
        win.add_accel_group(accelerators)

        self.sourcesA = Buttons(Config['toolbar.sources.a'])
        self.sourcesB = Buttons(Config['toolbar.sources.b'])
        self.targets = Buttons(Config['toolbar.targets'])
        self.mods = Buttons(Config['toolbar.mods'])

        toolbar_composites = uibuilder.find_widget_recursive(
            win, 'toolbar_preview_composite')
        toolbar_a = uibuilder.find_widget_recursive(win, 'toolbar_preview_a')
        toolbar_b = uibuilder.find_widget_recursive(win, 'toolbar_preview_b')
        toolbar_mods = uibuilder.find_widget_recursive(
            win, 'toolbar_preview_mod')

        self.targets.create(toolbar_composites,accelerators, self.on_btn_toggled)
        self.sourcesA.create(toolbar_a, accelerators, self.on_btn_toggled)
        self.sourcesB.create(toolbar_b, accelerators, self.on_btn_toggled)
        self.mods.create(toolbar_mods, accelerators, self.on_btn_toggled, group=False)

        # initialize source buttons
        self.sourceA = None
        self.sourceB = None
        self.target = None

        self.modstates = dict()
        for id in self.mods.ids:
            self.modstates[id] = False

        self.initialized = True

    def on_btn_toggled(self, btn):
        if not self.initialized:
            return

        id = btn.get_name()
        if btn.get_active():
            # sources button toggled?
            if id in self.sourcesA or id in self.sourcesB:
                # check for A and B switch to the same source and fix it
                if self.sourcesA[id]['button'] == btn:
                    if self.sourcesB[id]['button'].get_active():
                        self.sourceB = None
                        self.sourcesB[self.sourceA]['button'].set_active(True)
                    self.sourceA = id
                    self.log.info(
                        "Selected '%s' for preview source A", self.sourceA)
                elif self.sourcesB[id]['button'] == btn:
                    if self.sourcesA[id]['button'].get_active():
                        self.sourceA = None<commit_msg>Revert "vocotgui: minor code reading"<commit_after>#!/usr/bin/env python3
import os
import logging

from gi.repository import Gtk
import lib.connection as Connection

from lib.config import Config
from vocto.composite_commands import CompositeCommand
from lib.toolbar.buttons import Buttons
from lib.uibuilder import UiBuilder


class PreviewToolbarController(object):
    """Manages Accelerators and Clicks on the Preview Composition Toolbar-Buttons"""

    def __init__(self, win, uibuilder):
        self.initialized = False

        self.log = logging.getLogger('PreviewToolbarController')

        accelerators = Gtk.AccelGroup()
        win.add_accel_group(accelerators)

        self.sourcesA = Buttons(Config['toolbar.sources.a'])
        self.sourcesB = Buttons(Config['toolbar.sources.b'])
        self.targets = Buttons(Config['toolbar.targets'])
        self.mods = Buttons(Config['toolbar.mods'])

        toolbar_composites = uibuilder.find_widget_recursive(
            win, 'toolbar_preview_composite')
        toolbar_a = uibuilder.find_widget_recursive(win, 'toolbar_preview_a')
        toolbar_b = uibuilder.find_widget_recursive(win, 'toolbar_preview_b')
        toolbar_mods = uibuilder.find_widget_recursive(
            win, 'toolbar_preview_mod')

        self.targets.create(toolbar_composites,accelerators, self.on_btn_toggled)
        self.sourcesA.create(toolbar_a, accelerators, self.on_btn_toggled)
        self.sourcesB.create(toolbar_b, accelerators, self.on_btn_toggled)
        self.mods.create(toolbar_mods, accelerators, self.on_btn_toggled, group=False)

        # initialize source buttons
        self.sourceA = self.sourcesA.ids[0]
        self.sourceB = self.sourcesB.ids[1]
        self.sourcesA[self.sourceA]['button'].set_active(True)
        self.sourcesB[self.sourceB]['button'].set_active(True)

        self.target = self.targets.ids[0]
        self.targets[self.target]['button'].set_active(True)

        self.modstates = dict()
        for id in self.mods.ids:
            self.modstates[id] = False

        self.initialized = True

    def on_btn_toggled(self, btn):
        if not self.initialized:
            return

        id = btn.get_name()
        if btn.get_active():
            # sources button toggled?
            if id in self.sourcesA or id in self.sourcesB:
                # check for A and B switch to the same source and fix it
                if self.sourcesA[id]['button'] == btn:
                    if self.sourcesB[id]['button'].get_active():
                        self.sourceB = None
                        self.sourcesB[self.sourceA]['button'].set_active(True)
                    self.sourceA = id
                    self.log.info(
                        "Selected '%s' for preview source A", self.sourceA)
                elif self.sourcesB[id]['button'] == btn:
                    if self.sourcesA[id]['button'].get_active():
                        self.sourceA = None
{'fraction_non_alphanumeric': 0.09761273209549072, 'fraction_numerical': 0.0008841732979664014, 'mean_word_length': 2.4699386503067484, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3199721', 'n_tokens_mistral': 1679, 'n_tokens_neox': 1629, 'n_words': 336}