<commit_before>"""
Created on May 2, 2014

@author: Steve
"""

import maya.cmds as cmds
import mGui.events as events
import mGui.properties as properties


class ScriptJobEvent(events.Event):
    """
    A derivative of the Event class that is attached to a Maya scriptJob

    Typical usage:

        def handle_new_object(*args, **kwargs):
            # do something for new object
            print "new object!"
            print args, kwargs

       sj = ScriptJobEvent("e", "DagObjectCreated")
       sj += handle_new_object
       sj.start(protected = True)

    to find out if the scriptJob is still running:

        if sj.running:
            print 'scriptjob is still running'

    to stop a scriptJob:

        sj.kill()

    Run conditions (such as -runOnce, -parent,  or -protected) should be specificied when the scriptJob is started.
    """


    def __init__(self, scriptJobFlag, eventType, **kwargs):
        self.ScriptFlag = scriptJobFlag
        self.EventType = eventType
        super(ScriptJobEvent, self).__init__(**kwargs)
        self.Data['scriptJob'] = -1

    def start(self, **sjFlags):
        kwargs = {self.ScriptFlag: (self.EventType, self)}
        kwargs.update(sjFlags)
        self.Data['scriptJob'] = cmds.scriptJob(**kwargs)

    def kill(self):
        if self.Data.get('scriptJob') > 0:
            cmds.scriptJob(k=self.Data['scriptJob'])
            self.Data['scriptJob'] = -1

    @property
    def running(self):
        sid = self.Data['scriptJob']
        return sid != -1 and cmds.scriptJob(exists=sid)


# ======================================================================================================================
# Attribute  based script jobs
#
# See maya docs for more on the distinction between scriptJob -e, scriptJob -ct , etc
# ======================================================================================================================

class AttributeChange(ScriptJobEvent):
    def __init__(self, attrib, **kwargs):
        super(AttributeChanged, self).__init__("attributeChange", attrib, **kwargs)
        self.attribute = attrib


class AttributeAdded(ScriptJobEvent):
    def __init__(self, attrib, **kwargs):
        super(AttributeAdded, self).__init__("attributeAdded", attrib, **kwargs)
        self.attribute = attrib


class AttributeDeleted(ScriptJobEvent):
    def __init__(self, attrib, **kwargs):
        super(AttributeDeleted, self).__init__("attributeDeleted", attrib, **kwargs)
        self.attribute = attrib


# ======================================================================================================================
# Event based script jobs
#
# See maya docs for more on the distinction between scriptJob -e, scriptJob -ct , etc
# ======================================================================================================================

class ScriptJobE(ScriptJobEvent):
    EVENT = ""

    def __init__(self, **kwargs):
        super(ScriptJobE, self).__init__("e", self.EVENT, **kwargs)


class LinearUnitChanged(ScriptJobE):<commit_msg>reflect actual (inconsitent!)_ maya terminology<commit_after>"""
Created on May 2, 2014

@author: Steve
"""

import maya.cmds as cmds
import mGui.events as events
import mGui.properties as properties


class ScriptJobEvent(events.Event):
    """
    A derivative of the Event class that is attached to a Maya scriptJob

    Typical usage:

        def handle_new_object(*args, **kwargs):
            # do something for new object
            print "new object!"
            print args, kwargs

       sj = ScriptJobEvent("e", "DagObjectCreated")
       sj += handle_new_object
       sj.start(protected = True)

    to find out if the scriptJob is still running:

        if sj.running:
            print 'scriptjob is still running'

    to stop a scriptJob:

        sj.kill()

    Run conditions (such as -runOnce, -parent,  or -protected) should be specificied when the scriptJob is started.
    """


    def __init__(self, scriptJobFlag, eventType, **kwargs):
        self.ScriptFlag = scriptJobFlag
        self.EventType = eventType
        super(ScriptJobEvent, self).__init__(**kwargs)
        self.Data['scriptJob'] = -1

    def start(self, **sjFlags):
        kwargs = {self.ScriptFlag: (self.EventType, self)}
        kwargs.update(sjFlags)
        self.Data['scriptJob'] = cmds.scriptJob(**kwargs)

    def kill(self):
        if self.Data.get('scriptJob') > 0:
            cmds.scriptJob(k=self.Data['scriptJob'])
            self.Data['scriptJob'] = -1

    @property
    def running(self):
        sid = self.Data['scriptJob']
        return sid != -1 and cmds.scriptJob(exists=sid)


# ======================================================================================================================
# Attribute  based script jobs
#
# See maya docs for more on the distinction between scriptJob -e, scriptJob -ct , etc
# ======================================================================================================================

class AttributeChange(ScriptJobEvent):
    def __init__(self, attrib, **kwargs):
        super(AttributeChange, self).__init__("attributeChange", attrib, **kwargs)
        self.attribute = attrib


class AttributeAdded(ScriptJobEvent):
    def __init__(self, attrib, **kwargs):
        super(AttributeAdded, self).__init__("attributeAdded", attrib, **kwargs)
        self.attribute = attrib


class AttributeDeleted(ScriptJobEvent):
    def __init__(self, attrib, **kwargs):
        super(AttributeDeleted, self).__init__("attributeDeleted", attrib, **kwargs)
        self.attribute = attrib


# ======================================================================================================================
# Event based script jobs
#
# See maya docs for more on the distinction between scriptJob -e, scriptJob -ct , etc
# ======================================================================================================================

class ScriptJobE(ScriptJobEvent):
    EVENT = ""

    def __init__(self, **kwargs):
        super(ScriptJobE, self).__init__("e", self.EVENT, **kwargs)


class LinearUnitChanged(ScriptJobE):
{'fraction_non_alphanumeric': 0.24615633597669526, 'fraction_numerical': 0.0029130927334520148, 'mean_word_length': 3.7283856159143074, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1310997', 'n_tokens_mistral': 1643, 'n_tokens_neox': 1539, 'n_words': 443}