Exemple #1
0
def refresh_context_mapping(enabled_only = False):
    global context_mapping
    global sorted_context_map_keys
    global show_enabled_contexts_only 
    global cached_window_title

    cached_short_context_names = {}
    show_enabled_contexts_only = enabled_only
    cached_window_title = ui.active_window().title
    active_contexts = registry.active_contexts()

    update_active_contexts_cache(active_contexts)
        
    context_mapping = {}
    for context in registry.contexts.values():
        short_name = str(context).replace('(Context', '').replace(')', '').split('.')[-1].replace('_', " ")
        #print(short_name)
        context_name = str(context)
        if enabled_only and context in active_contexts or not enabled_only:
            context_mapping[context_name] = {}
            for __, val in context.commands_get().items():
                #todo figure out why somethings are functions/list
                if not callable(val.target) and not isinstance(val.target, list):
                    context_mapping[context_name][str(val.rule.rule)] = val.target.code

            if len(context_mapping[context_name]) == 0:
                context_mapping.pop(context_name)
            else: 
                cached_short_context_names[short_name] = context_name

    ctx.lists['self.help_contexts'] = cached_short_context_names
    sorted_context_map_keys = sorted(context_mapping)
Exemple #2
0
def refresh_context_command_map(enabled_only=False):
    global rule_word_map
    global context_command_map
    global context_map
    global sorted_context_map_keys
    global show_enabled_contexts_only
    global cached_window_title
    global context_map

    context_map = {}
    cached_short_context_names = {}
    show_enabled_contexts_only = enabled_only
    cached_window_title = ui.active_window().title
    active_contexts = registry.active_contexts()
    # print(str(active_contexts))
    update_active_contexts_cache(active_contexts)

    context_command_map = {}
    for context_name, context in registry.contexts.items():
        splits = context_name.split(".")
        index = -1
        if "talon" in splits[index]:
            index = -2
            short_name = splits[index].replace("_", " ")
        else:
            short_name = splits[index].replace("_", " ")

        if "mac" == short_name or "win" == short_name or "linux" == short_name:
            index = index - 1
            short_name = splits[index].replace("_", " ")

        # print("short name: " + short_name)
        if short_name in overrides:
            short_name = overrides[short_name]

        if context in active_contexts or not enabled_only:
            context_command_map[context_name] = {}
            for command_alias, val in context.commands.items():
                # print(str(val))
                if command_alias in registry.commands:
                    # print(str(val.rule.rule) + ": " + val.target.code)
                    context_command_map[context_name][
                        str(val.rule.rule)
                    ] = val.target.code
            # print(short_name)
            # print("length: " + str(len(context_command_map[context_name])))

            #if len(context_command_map[context_name]) == 0:
            #    context_command_map.pop(context_name)
            #else:
            #    cached_short_context_names[short_name] = context_name
            #    context_map[context_name] = context
            cached_short_context_names[short_name] = context_name
            context_map[context_name] = context

    refresh_rule_word_map(context_command_map)

    ctx.lists["self.help_contexts"] = cached_short_context_names
    # print(str(ctx.lists["self.help_contexts"]))
    sorted_context_map_keys = sorted(cached_short_context_names)
Exemple #3
0
def refresh_context_command_map(enabled_only=False):
    active_contexts = registry.active_contexts()

    local_context_map = {}
    local_display_name_to_context_name_map = {}
    local_context_command_map = {}
    cached_short_context_names = {}

    for context_name, context in registry.contexts.items():
        splits = context_name.split(".")

        if "talon" == splits[-1]:
            display_name = splits[-2].replace("_", " ")

            short_names = actions.user.create_spoken_forms(
                display_name, generate_subsequences=False,
            )

            if short_names[0] in overrides:
                short_names = [overrides[short_names[0]]]
            elif len(short_names) == 2 and short_names[1] in overrides:
                short_names = [overrides[short_names[1]]]

            if enabled_only and context in active_contexts or not enabled_only:
                local_context_command_map[context_name] = {}
                for command_alias, val in context.commands.items():
                    if command_alias in registry.commands or not enabled_only:
                        local_context_command_map[context_name][
                            str(val.rule.rule)
                        ] = val.target.code
                if len(local_context_command_map[context_name]) == 0:
                    local_context_command_map.pop(context_name)
                else:
                    for short_name in short_names:
                        cached_short_context_names[short_name] = context_name

                    # the last entry will contain no symbols
                    local_display_name_to_context_name_map[display_name] = context_name
                    local_context_map[context_name] = context



    # Update all the global state after we've performed our calculations
    global context_map
    global context_command_map
    global sorted_display_list
    global show_enabled_contexts_only
    global display_name_to_context_name_map
    global rule_word_map

    context_map = local_context_map
    context_command_map = local_context_command_map
    sorted_display_list = sorted(local_display_name_to_context_name_map.keys())
    show_enabled_contexts_only = enabled_only
    display_name_to_context_name_map = local_display_name_to_context_name_map
    rule_word_map = refresh_rule_word_map(local_context_command_map)

    ctx.lists["self.help_contexts"] = cached_short_context_names
    update_active_contexts_cache(active_contexts)
Exemple #4
0
    def help_refresh():
        """Refreshes the help"""
        global show_enabled_contexts_only
        global selected_context

        if gui_context_help.showing:
            if selected_context == None:
                refresh_context_command_map(show_enabled_contexts_only)
            else:
                update_active_contexts_cache(registry.active_contexts())
Exemple #5
0
def update_title():
    global live_update
    global show_enabled_contexts_only

    if live_update:
        if gui_context_help.showing:
            if selected_context == None:
                refresh_context_command_map(show_enabled_contexts_only)
            else:
                update_active_contexts_cache(registry.active_contexts())
Exemple #6
0
def context_active(context):
    """Is `context` currently active?

    WARNING: Only call this on the main thread.

    """
    raise RuntimeError(
        "Don't check for active contexts like this. It can race. Use a tag instead."
    )
    # FIXME: This can race, `active_contexts` changing under us. No idea how to
    #   fix it.
    return context in registry.active_contexts()
Exemple #7
0
def update_title():
    global live_update
    global show_enabled_contexts_only
    global is_context_help_showing
    global cached_window_title

    if live_update:
        if is_context_help_showing:
            if selected_context == None:
                if ui.active_window().title != cached_window_title:
                    refresh_context_mapping(show_enabled_contexts_only)
            else:
                update_active_contexts_cache(registry.active_contexts())
Exemple #8
0
    def help_refresh():
        """Refreshes the help"""
        global is_context_help_showing
        global show_enabled_contexts_only
        global selected_context

        if is_context_help_showing:
            if selected_context == None:
                refresh_context_mapping(show_enabled_contexts_only)
            else:
                update_active_contexts_cache(registry.active_contexts())

            refresh_help_context_indexes()
Exemple #9
0
    def help_selected_context(m: str):
        """Display command info for selected context"""
        global selected_context
        global selected_context_page

        if not gui_context_help.showing:
            reset()
            refresh_context_command_map()
        else:
            selected_context_page = 1
            update_active_contexts_cache(registry.active_contexts())

        selected_context = m
        gui_alphabet.hide()
        gui_context_help.show()
        register_events(True)
        actions.mode.enable("user.help")
Exemple #10
0
def refresh_context_command_map(enabled_only=False):
    global rule_word_map
    global context_command_map
    global context_map
    global sorted_context_map_keys
    global show_enabled_contexts_only
    global cached_window_title
    global context_map

    context_map = {}
    cached_short_context_names = {}
    show_enabled_contexts_only = enabled_only
    cached_window_title = ui.active_window().title
    active_contexts = registry.active_contexts()
    update_active_contexts_cache(active_contexts)

    context_command_map = {}
    for context_name, context in registry.contexts.items():
        splits = context_name.split('.')
        if "talon" in splits[-1]:
            short_name = splits[-2].replace("_", " ")
        else:
            short_name = splits[-1].replace("_", " ")

        #print("short name: " + short_name)
        if short_name in overrides:
            short_name = overrides[short_name]

        if enabled_only and context in active_contexts or not enabled_only:
            context_command_map[context_name] = {}
            for __, val in context.commands_get().items():
                #print(str(val.rule.rule) + ": " + val.target.code)
                context_command_map[context_name][str(
                    val.rule.rule)] = val.target.code
            #print(short_name)
            #print("length: " + str(len(context_command_map[context_name])))
            if len(context_command_map[context_name]) == 0:
                context_command_map.pop(context_name)
            else:
                cached_short_context_names[short_name] = context_name
                context_map[context_name] = context

    refresh_rule_word_map(context_command_map)

    ctx.lists['self.help_contexts'] = cached_short_context_names
    sorted_context_map_keys = sorted(cached_short_context_names)
Exemple #11
0
    def help_selected_context(m: str):
        """Display command info for selected context"""
        global is_context_help_showing
        global selected_context
        global selected_context_page

        if not is_context_help_showing:
            reset()
            refresh_context_mapping()
        else:
            selected_context_page = 1
            update_active_contexts_cache(registry.active_contexts())

        is_context_help_showing = True
        selected_context = m
        gui_alphabet.hide()
        gui_context_help.show()
        register_events(True)
Exemple #12
0
 def debug_active_context():
     """dump out the active contexts"""
     print(registry.active_contexts())
Exemple #13
0
def refresh_context_command_map(enabled_only=False):
    global rule_word_map
    global context_command_map
    global context_map
    global sorted_display_list
    global show_enabled_contexts_only
    global cached_window_title
    global context_map
    global display_name_to_context_name_map

    context_map = {}
    cached_short_context_names = {}
    display_name_to_context_name_map = {}
    show_enabled_contexts_only = enabled_only
    cached_window_title = ui.active_window().title
    active_contexts = registry.active_contexts()
    # print(str(active_contexts))
    update_active_contexts_cache(active_contexts)

    context_command_map = {}
    for context_name, context in registry.contexts.items():
        splits = context_name.split(".")

        if "talon" == splits[-1]:
            display_name = splits[-2].replace("_", " ")

            short_names = actions.user.create_spoken_forms(
                display_name,
                generate_subsequences=False,
            )

            if short_names[0] in overrides:
                short_names = [overrides[short_names[0]]]
            elif len(short_names) == 2 and short_names[1] in overrides:
                short_names = [overrides[short_names[1]]]

            if enabled_only and context in active_contexts or not enabled_only:
                context_command_map[context_name] = {}
                for command_alias, val in context.commands.items():
                    # print(str(val))
                    if command_alias in registry.commands or not enabled_only:
                        # print(str(val.rule.rule) + ": " + val.target.code)
                        context_command_map[context_name][str(
                            val.rule.rule)] = val.target.code
                # print(short_name)
                # print("length: " + str(len(context_command_map[context_name])))
                if len(context_command_map[context_name]) == 0:
                    context_command_map.pop(context_name)
                else:
                    for short_name in short_names:
                        cached_short_context_names[short_name] = context_name

                    # the last entry will contain no symbols
                    display_name_to_context_name_map[
                        display_name] = context_name
                    context_map[context_name] = context

    refresh_rule_word_map(context_command_map)

    ctx.lists["self.help_contexts"] = cached_short_context_names
    # print(str(ctx.lists["self.help_contexts"]))
    sorted_display_list = sorted(display_name_to_context_name_map.keys())