<commit_before>import itertools
import gobject

import libqtile.hook
from libqtile.config import Key
from libqtile.command import lazy

def simple_key_binder(mod, keynames=None):
    """
        Bind keys to mod+group position or to the keys specified as
        second argument.
    """
    def func(dgroup):
        # unbind all
        for key in dgroup.keys[:]:
            dgroup.qtile.unmapKey(key)
            dgroup.keys.remove(key)

        if keynames:
            keys = keynames
        else:
            # keys 1 to 9 and 0
            keys = map(str, range(1, 10) + [0])

        # bind all keys
        for keyname, group in zip(keys, dgroup.qtile.groups):
            name = group.name
            key = Key([mod], keyname, lazy.group[name].toscreen())
            key_s = Key([mod, "shift"], keyname, lazy.window.togroup(name))
            key_c = Key([mod, "control"], keyname,
                    lazy.group.switch_groups(name))
            dgroup.keys.append(key)
            dgroup.keys.append(key_s)
            dgroup.keys.append(key_c)
            dgroup.qtile.mapKey(key)
            dgroup.qtile.mapKey(key_s)
            dgroup.qtile.mapKey(key_c)

    return func

class Rule(object):
    """ A Rule contains a Match object, and a specification about what to do
    when that object is matched. """
    def __init__(self, match, group=None, float=False, intrusive=False):
        """
        :param match: ``Match`` object associated with this ``Rule``
        :param float: auto float this window?
        :param intrusive: override the group's exclusive setting?
        """
        self.match = match
        self.group = group
        self.float = float
        self.intrusive = intrusive

    def matches(self, w):
        return self.match.compare(w)

class DGroups(object):
    ''' Dynamic Groups '''
    def __init__(self, qtile, dgroups, key_binder=None, delay=1):
        self.qtile = qtile

        self.groups = dgroups
        self.groupMap = {}
        for group in self.groups:
            self.groupMap[group.name] = group

        self.rules = list(itertools.chain.from_iterable([g.rules for g in dgroups]))

        for group in dgroups:
            rules = [Rule(m, group=group.name) for m in group.matches]
            self.rules.extend(rules)

        self.keys = []

        self.key_binder = key_binder

        self._setup_hooks()
        self._setup_groups()

        self.delay = delay

        self.timeout = {}

    def _setup_groups(self):
        for group in self.groups:
            if group.init:
                self.qtile.addGroup(group.name)

            if group.spawn and not self.qtile.no_spawn:<commit_msg>move dgroups inizialitation to a method, to allow dynamic adding<commit_after>import itertools
import gobject

import libqtile.hook
from libqtile.config import Key
from libqtile.command import lazy

def simple_key_binder(mod, keynames=None):
    """
        Bind keys to mod+group position or to the keys specified as
        second argument.
    """
    def func(dgroup):
        # unbind all
        for key in dgroup.keys[:]:
            dgroup.qtile.unmapKey(key)
            dgroup.keys.remove(key)

        if keynames:
            keys = keynames
        else:
            # keys 1 to 9 and 0
            keys = map(str, range(1, 10) + [0])

        # bind all keys
        for keyname, group in zip(keys, dgroup.qtile.groups):
            name = group.name
            key = Key([mod], keyname, lazy.group[name].toscreen())
            key_s = Key([mod, "shift"], keyname, lazy.window.togroup(name))
            key_c = Key([mod, "control"], keyname,
                    lazy.group.switch_groups(name))
            dgroup.keys.append(key)
            dgroup.keys.append(key_s)
            dgroup.keys.append(key_c)
            dgroup.qtile.mapKey(key)
            dgroup.qtile.mapKey(key_s)
            dgroup.qtile.mapKey(key_c)

    return func

class Rule(object):
    """ A Rule contains a Match object, and a specification about what to do
    when that object is matched. """
    def __init__(self, match, group=None, float=False, intrusive=False):
        """
        :param match: ``Match`` object associated with this ``Rule``
        :param float: auto float this window?
        :param intrusive: override the group's exclusive setting?
        """
        self.match = match
        self.group = group
        self.float = float
        self.intrusive = intrusive

    def matches(self, w):
        return self.match.compare(w)

class DGroups(object):
    ''' Dynamic Groups '''
    def __init__(self, qtile, dgroups, key_binder=None, delay=1):
        self.qtile = qtile

        self.groups = dgroups
        self.groupMap = {}
        self.rules = list(itertools.chain.from_iterable([g.rules for g in self.groups]))

        self.keys = []

        self.key_binder = key_binder

        self._setup_hooks()
        self._setup_groups()

        self.delay = delay

        self.timeout = {}

    def add_dgroup(self, group, start=False):
        self.groupMap[group.name] = group
        rules = [Rule(m, group=group.name) for m in group.matches]
        self.rules.extend(rules)
        if start:
            self.qtile.addGroup(group.name)

    def _setup_groups(self):
        for group in self.groups:
            self.add_dgroup(group, group.init)

            if group.spawn and not self.qtile.no_spawn:
{'fraction_non_alphanumeric': 0.10414354421013688, 'fraction_numerical': 0.0029596744358120607, 'mean_word_length': 2.0410573678290214, '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': '5282552', 'n_tokens_mistral': 1650, 'n_tokens_neox': 1619, 'n_words': 426}