Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
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
Ejemplo n.º 3
0
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
Ejemplo n.º 4
0
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
Ejemplo n.º 5
0
    def patched_Tk_constructor(self, *args, **kw):
        original_constructor(self, *args, **kw)

        # 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)
Ejemplo n.º 6
0
def load_plugin():
    get_vm().add_source_preprocessor(augment_source)
Ejemplo n.º 7
0
def _cmd_Birdseye(cmd):
    vm = get_vm()
    vm.switch_env_to_script_mode(cmd)
    return vm._execute_file(cmd, BirdsEyeRunner)
Ejemplo n.º 8
0
def load_plugin():
    get_vm().add_command("Birdseye", _cmd_Birdseye)
Ejemplo n.º 9
0
def load_plugin():
    if platform.system() == "Darwin":
        # https://github.com/thonny/thonny/issues/676
        vm = get_vm()
        vm.add_import_handler("matplotlib", set_default_backend)
Ejemplo n.º 10
0
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)