def load_plugin():
    if os.environ.get("PGZERO_MODE", "False").lower() == "false":
        return

    get_backend().add_ast_postprocessor(augment_ast)
    MainCPythonBackend._original_editor_autocomplete = MainCPythonBackend._cmd_editor_autocomplete
    MainCPythonBackend._cmd_editor_autocomplete = patched_editor_autocomplete
def load_plugin():
    try:
        os.environ["OUTDATED_IGNORE"] = "1"
        # TODO: it would be good to do this here, but it's slow
        # import birdseye.bird  # need to import at plugin load time, because later it may not be in path
    except ImportError:
        pass
    get_backend().add_command("Birdseye", _cmd_Birdseye)
def on_configure(event):
    global _last_pos, _notification_is_sent
    pos = event.x, event.y
    if pos != _last_pos:
        get_backend().set_option(_LAST_POS_SETTING, pos)

    if not _notification_is_sent:
        get_backend().send_message(BackendEvent("UserWindowAppeared"))
        _notification_is_sent = True
def patch_turtle(module):
    # Turtle needs more tweaking because it later overrides the position set in the Tk constructor
    turtle_config = getattr(module, "_CFG", None)
    if isinstance(turtle_config, dict):
        last_pos = get_backend().get_option(_LAST_POS_SETTING)
        if isinstance(last_pos, tuple):
            turtle_config["leftright"], turtle_config["topbottom"] = last_pos
def patched_editor_autocomplete(self, cmd):
    # Make extra builtins visible for Jedi
    prefix = "from pgzero.builtins import *\n"
    cmd["source"] = prefix + cmd["source"]
    cmd["row"] = cmd["row"] + 1

    result = get_backend()._original_editor_autocomplete(cmd)
    result["row"] = result["row"] - 1
    result["source"] = result["source"][len(prefix) :]

    return result
    def patched_Tk_constructor(self, *args, **kw):
        original_constructor(self, *args, **kw)

        try:
            # move window to the same place it was previously
            last_pos = get_backend().get_option(_LAST_POS_SETTING)
            if isinstance(last_pos, tuple):
                self.geometry("+%d+%d" % last_pos)

            self.wm_attributes("-topmost", 1)
            # self.overrideredirect(1)

            # I'm using bind_class because turtle._Screen later overwrites the bind handler
            self.bind_class("Tk", "<Configure>", on_configure, True)
        except Exception:
            # expected to fail when constructing Tcl for _cmd_process_gui_events
            pass
Ejemplo n.º 7
0
def load_plugin():
    if platform.system() == "Darwin":
        # https://github.com/thonny/thonny/issues/676
        backend = get_backend()
        backend.add_import_handler("matplotlib", set_default_backend)
def _cmd_Birdseye(cmd):
    backend = get_backend()
    backend.switch_env_to_script_mode(cmd)
    return backend._execute_file(cmd, BirdsEyeRunner)
def load_plugin():
    if os.environ.get("DOCK_USER_WINDOWS", "False").lower() == "true":
        backend = get_backend()
        backend.add_import_handler("tkinter", patch_tkinter)
        backend.add_import_handler("turtle", patch_turtle)
Ejemplo n.º 10
0
def load_plugin():
    get_backend().add_source_preprocessor(augment_source)