<commit_before>import time

# start an Xvfb virtual display if we can (if xvfbwrapper is installed)
try:
    from xvfbwrapper import Xvfb
except (ModuleNotFoundError, ImportError):
    print("Using physical display")
    vdisplay = None
else:
    print("Using Xvfb virtual display")
    vdisplay = Xvfb(width=1024, height=768, colordepth=24)
    vdisplay.start()
    # wait a bit to make sure the virtual display is ready
    time.sleep(1)

try:
    import pathlib
    import tempfile
    import threading

    import gi

    gi.require_version("Gtk", "3.0")
    gi.require_version("PangoCairo", "1.0")
    from gi.repository import GLib
    from gnuradio import gr
    from gnuradio.grc.gui.Platform import Platform
    from gnuradio.grc.gui.Application import Actions, Application

    # include the necessary boilerplate from grc's main function to create the app
    platform = Platform(
        version=gr.version(),
        version_parts=(gr.major_version(), gr.api_version(), gr.minor_version()),
        prefs=gr.prefs(),
        install_prefix=gr.prefix(),
    )
    platform.build_library()

    # pick an example that runs a bunch of qt-gui sinks
    example_grc_path = (
        pathlib.Path(gr.prefix())
        / "share"
        / "gnuradio"
        / "examples"
        / "qt-gui"
        / "qtgui_multi_input.grc"
    )
    app = Application((example_grc_path,), platform)

    # script what we want to try out with the app
    def script(app):
        # ensure the app is initialized before proceeding
        while not app.init:
            time.sleep(1)
        # add a block and undo it
        win = app.get_active_window()
        GLib.idle_add(win.vars.emit, "create_new_block", "analog_noise_source_x")
        GLib.idle_add(Actions.FLOW_GRAPH_UNDO)
        # save the flowgraph to a temporary directory
        file_path = str(pathlib.Path(tempfile.gettempdir(), "grc-test.grc"))
        win.current_page.file_path = file_path
        GLib.idle_add(Actions.FLOW_GRAPH_SAVE)
        # trigger the menu and then cancel it
        GLib.idle_add(win.menu_bar.select_first, False)
        time.sleep(1)
        GLib.idle_add(win.menu_bar.cancel)
        # execute the flowgraph and stop it after some time
        GLib.idle_add(Actions.FLOW_GRAPH_EXEC)
        time.sleep(10)
        GLib.idle_add(Actions.FLOW_GRAPH_KILL)
        time.sleep(1)
        # finally, quit the application
        GLib.idle_add(Actions.APPLICATION_QUIT)

    # start the script in a separate thread
    thread = threading.Thread(target=script, args=(app,))
    # make it a daemon thread so we don't have to wait for it to exit the main thread
    thread.daemon = True
    thread.start()

    app.run()
finally:
    # clean up the virtual display if we used one
    print("cleanup")
    if vdisplay is not None:
        vdisplay.stop()<commit_msg>Status printing for run_grc_test.py, and trigger menu with F10 instead.<commit_after>import time

# start an Xvfb virtual display if we can (if xvfbwrapper is installed)
try:
    from xvfbwrapper import Xvfb
except (ModuleNotFoundError, ImportError):
    print("**** Using physical display")
    vdisplay = None
else:
    print("**** Using Xvfb virtual display")
    vdisplay = Xvfb(width=1024, height=768, colordepth=24)
    vdisplay.start()
    # wait a bit to make sure the virtual display is ready
    time.sleep(1)

try:
    import pathlib
    import tempfile
    import threading

    import gi

    gi.require_version("Gtk", "3.0")
    gi.require_version("PangoCairo", "1.0")
    from gi.repository import GLib, Gtk, Gdk
    from gnuradio import gr
    from gnuradio.grc.gui.Platform import Platform
    from gnuradio.grc.gui.Application import Actions, Application

    # include the necessary boilerplate from grc's main function to create the app
    platform = Platform(
        version=gr.version(),
        version_parts=(gr.major_version(), gr.api_version(), gr.minor_version()),
        prefs=gr.prefs(),
        install_prefix=gr.prefix(),
    )
    platform.build_library()

    # pick an example that runs a bunch of qt-gui sinks
    example_grc_path = (
        pathlib.Path(gr.prefix())
        / "share"
        / "gnuradio"
        / "examples"
        / "qt-gui"
        / "qtgui_multi_input.grc"
    )
    app = Application((example_grc_path,), platform)

    # script what we want to try out with the app
    def script(app):
        # ensure the app is initialized before proceeding
        print("**** Waiting for GRC to init")
        while not app.init:
            time.sleep(1)
        # add a block and undo it
        print("**** Adding a block")
        win = app.get_active_window()
        GLib.idle_add(win.vars.emit, "create_new_block", "analog_noise_source_x")
        print("**** Undoing adding a block")
        GLib.idle_add(Actions.FLOW_GRAPH_UNDO)
        # save the flowgraph to a temporary directory
        print("**** Saving the flowgraph")
        file_path = str(pathlib.Path(tempfile.gettempdir(), "grc-test.grc"))
        win.current_page.file_path = file_path
        GLib.idle_add(Actions.FLOW_GRAPH_SAVE)
        # trigger the menu and then cancel it
        print("**** Triggering the menu")
        disp = win.get_screen().get_display()
        seat = disp.get_default_seat()
        keyboard = seat.get_keyboard()
        keymap = Gdk.Keymap.get_for_display(disp)
        _, keys = keymap.get_entries_for_keyval(Gdk.KEY_F10)
        press_event = Gdk.Event.new(Gdk.EventType.KEY_PRESS)
        press_event.set_device(keyboard)
        press_event.window = win.get_window()
        press_event.hardware_keycode = keys[0].keycode
        press_event.keyval = Gdk.KEY_F10
        press_event.send_event = True
        press_event.state = 0
        press_event.time = Gdk.CURRENT_TIME
        GLib.idle_add(Gtk.main_do_event, press_event)
        release_event = Gdk.Event.new(Gdk.EventType.KEY_RELEASE)
        release_event.set_device(keyboard)
        release_event.window = win.get_window()
        release_event.hardware_keycode = keys[0].keycode
        release_event.keyval = Gdk.KEY_F10
        release_event.send_event = True
        release_event.state = 0
        release_event.time = Gdk.CURRENT_TIME
        GLib.idle_add(Gtk.main_do_event, release_event)
        #GLib.idle_add(win.menu_bar.select_first, False)
        time.sleep(1)
        print("**** Canceling menu")
        GLib.idle_add(Gtk.main_do_event, press_event)
        GLib.idle_add(Gtk.main_do_event, release_event)
        #GLib.idle_add(win.menu_bar.cancel)
        # execute the flowgraph and stop it after some time
        print("**** Executing flowgraph")
        GLib.idle_add(Actions.FLOW_GRAPH_EXEC)
        time.sleep(10)
        print("**** Killing flowgraph")
        GLib.idle_add(Actions.FLOW_GRAPH_KILL)
        time.sleep(1)
        # finally, quit the application
        print("**** Quitting GRC")
        GLib.idle_add(Actions.APPLICATION_QUIT)

    # start the script in a separate thread
    thread = threading.Thread(target=script, args=(app,))
    # make it a daemon thread so we don't have to wait for it to exit the main thread
    thread.daemon = True
    thread.start()

    app.run()
finally:
    # clean up the virtual display if we used one
    print("cleanup")
    if vdisplay is not None:
        vdisplay.stop()
{'fraction_non_alphanumeric': 0.09601201857416007, 'fraction_numerical': 0.0068287353182190655, 'mean_word_length': 2.711606690319311, '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': '2321859', 'n_tokens_mistral': 2364, 'n_tokens_neox': 2319, 'n_words': 587}