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

    get_vm().add_ast_postprocessor(augment_ast)
    VM._original_editor_autocomplete = VM._cmd_editor_autocomplete
    VM._cmd_editor_autocomplete = patched_editor_autocomplete
def on_configure(event):
    global _last_pos, _notification_is_sent
    pos = event.x, event.y
    if pos != _last_pos:
        get_vm().set_option(_LAST_POS_SETTING, pos)

    if not _notification_is_sent:
        get_vm().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_vm().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_vm()._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_vm().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
def load_plugin():
    if os.environ.get("DOCK_USER_WINDOWS", "False").lower() == "true":
        vm = get_vm()
        vm.add_import_handler("tkinter", patch_tkinter)
        vm.add_import_handler("turtle", patch_turtle)
def load_plugin():
    if platform.system() == "Darwin":
        # https://github.com/ynnoht/ynnoht/issues/676
        vm = get_vm()
        vm.add_import_handler("matplotlib", set_default_backend)
Esempio n. 8
0
def load_plugin():
    get_vm().add_source_preprocessor(augment_source)