<commit_before>from enthought.pyface.api import GUI, ApplicationWindow
from enthought.traits.api import HasTraits, Int
from enthought.traits.ui.api import toolkit
from enthought.etsconfig.api import ETSConfig

# Globals.
# The GUI instance.
_gui = None

def is_ui_running():
    """Returns True if the UI event loop is running."""
    tk = ETSConfig.toolkit
    if tk == 'wx':
        import wx
        return wx.App.IsMainLoopRunning()
    elif tk == 'qt4':
        from PyQt4 import QtGui
        app = QtGui.QApplication.instance()
        if app is not None:
            # Hack gleaned from enthought.traits.ui.qt4.view_application
            if hasattr(app, '_in_event_loop'):
                if _gui is None:
                    return True
                else:
                    return _gui.started

    return False


def show(func):
    """Decorator to run something which requires a UI.   If the GUI
    event loop is already running it simply runs the function.  If not
    the event loop is started and function is run in the toolkit's event
    loop.  The choice of UI is via `ETSConfig.toolkit`.  
    """
    def wrapper(*args, **kw):
        """Wrapper function to run given function inside the GUI event
        loop.
        """
        global _gui
        tk = ETSConfig.toolkit<commit_msg>ENH: Updated so show also works as a standalone function (and not a decorator) and does the right thing for the most part.<commit_after>from enthought.pyface.api import GUI, ApplicationWindow
from enthought.traits.api import HasTraits, Int
from enthought.traits.ui.api import toolkit
from enthought.etsconfig.api import ETSConfig

# Globals.
# The GUI instance.
_gui = None

def is_ui_running():
    """Returns True if the UI event loop is running."""
    tk = ETSConfig.toolkit
    if tk == 'wx':
        import wx
        return wx.App.IsMainLoopRunning()
    elif tk == 'qt4':
        from PyQt4 import QtGui
        app = QtGui.QApplication.instance()
        if app is not None:
            # Hack gleaned from enthought.traits.ui.qt4.view_application
            if hasattr(app, '_in_event_loop'):
                if _gui is None:
                    return True
                else:
                    return _gui.started

    return False


def show(func=None):
    """By default, this function simply creates a GUI and starts its
    event loop if needed.
    
    If it is used as a decorator, then it may be used to decorate a
    function which requires a UI.   If the GUI event loop is already
    running it simply runs the function.  If not the event loop is
    started and function is run in the toolkit's event loop.  The choice
    of UI is via `ETSConfig.toolkit`.  

    """
    global _gui
    if func is None:
        if not is_ui_running():
            g = GUI()
            _gui = g
            g.start_event_loop()
        return

    def wrapper(*args, **kw):
        """Wrapper function to run given function inside the GUI event
        loop.
        """
        global _gui
        tk = ETSConfig.toolkit
{'fraction_non_alphanumeric': 0.07051492292554937, 'fraction_numerical': 0.0019678583142013774, 'mean_word_length': 2.1475748194014446, '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': '7223875', 'n_tokens_mistral': 894, 'n_tokens_neox': 848, 'n_words': 343}