当前位置: 首页>>代码示例>>Python>>正文


Python weechat.hook_command_run函数代码示例

本文整理汇总了Python中weechat.hook_command_run函数的典型用法代码示例。如果您正苦于以下问题:Python hook_command_run函数的具体用法?Python hook_command_run怎么用?Python hook_command_run使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了hook_command_run函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

def main():
    """ Entry point, initializes everything  """

    weechat.register(
        SCRIPT_NAME,
        SCRIPT_AUTHOR,
        SCRIPT_VERSION,
        SCRIPT_LICENSE,
        SCRIPT_DESCRIPTION,
        "", # Shutdown callback function
        "", # Charset (blank for utf-8)
    )

    # Default values for settings
    default_settings = {
        'dbfile': os.path.join(
            weechat.info_get("weechat_dir", ""), "emojis-db.dat")
    }

    # Apply default configuration values if anything is unset
    for option, default in default_settings.items():
        if not weechat.config_is_set_plugin(option):
            weechat.config_set_plugin(option, default)

    # Hook callbacks
    weechat.hook_config("plugins.var.python." + SCRIPT_NAME + ".*",
        "configuration_cb", "")
    weechat.hook_command_run("/input return", "transform_cb", "")
    weechat.hook_command_run("/input complete*", "complete_cb", "")
    #weechat.hook_modifier("input_text_display", "collapse_cb", "")

    # Command callbacks
    weechat.hook_command(  # command name
                           SCRIPT_NAME,
                           # description
                           " display :common_name: with its emoji equivalent",
                           # arguments
                           "reload"
                           " || add <name> <emoji>"
                           " || show <emoji>",
                           # description of arguments
                           " name: emoji name, sans colons\n"
                           "emoji: text that replaces :name:\n",
                           # completions
                           "reload || add || show %(emoji_name)", "emojis_cb", "")
    weechat.hook_completion("emoji_name", "Emoji name", "emoji_name_completion_cb", "")

    dbfile = weechat.config_get_plugin("dbfile")

    weechat.prnt("", "%s: Loading emojis from %s" % (SCRIPT_NAME, dbfile))

    try:
        load_emojis(dbfile)
    except IOError as e:
        weechat.prnt("",
            "%s%s: Database file %s is missing or inaccessible." \
                    % (weechat.prefix("error"), SCRIPT_NAME, dbfile))
        raise e # TODO: handle this better instead of brutally aborting
开发者ID:flowbish,项目名称:weechat-emojis,代码行数:58,代码来源:emojis.py

示例2: _create

 def _create(self):
     buffer = Buffer._create(self)
     weechat.buffer_set(buffer, 'nicklist', '0')
     weechat.buffer_set(buffer, 'time_for_each_line', '0')
     weechat.buffer_set(buffer, 'localvar_set_no_log', '1')
     self.color_input = weechat.color('green')
     self.color_exc = weechat.color('red')
     self.color_call = weechat.color('cyan')
     weechat.hook_command_run('/input return', callback(self.input_return), buffer)
     # print python and WeeChat version
     prnt(buffer, "Python %s" % sys.version.split(None, 1)[0])
     prnt(buffer, "WeeChat %s" % weechat.info_get('version', ''))
     return buffer
开发者ID:DarkDefender,项目名称:scripts,代码行数:13,代码来源:pybuffer.py

示例3: main

def main():
    """ Entry point, initializes everything  """

    weechat.register(
        SCRIPT_NAME,
        SCRIPT_AUTHOR,
        SCRIPT_VERSION,
        SCRIPT_LICENSE,
        SCRIPT_DESCRIPTION,
        "",  # Shutdown callback function
        "",  # Charset (blank for utf-8)
    )

    # Default values for settings
    default_settings = {
        'dbfile': os.path.join(
            weechat.info_get("weechat_dir", ""), "emojis-db.dat")
    }

    # Apply default configuration values if anything is unset
    for option, default in default_settings.items():
        if not weechat.config_is_set_plugin(option):
            weechat.config_set_plugin(option, default)

    # Hook callbacks
    weechat.hook_config(
        "plugins.var.python." + SCRIPT_NAME + ".*",
        "configuration_cb", "")
    weechat.hook_command_run("/input return", "transform_cb", "")
    weechat.hook_command_run("/input complete*", "complete_cb", "")

    # Command callbacks
    weechat.hook_command(
        "reloademojis", "reload emojis from file",
        "", "", "", "reload_emojis_cb", "")

    dbfile = weechat.config_get_plugin("dbfile")

    weechat.prnt("", "%s: Loading emojis from %s" % (SCRIPT_NAME, dbfile))

    try:
        load_emojis(dbfile)
    except IOError as e:
        weechat.prnt(
            "",
            "%s%s: Database file %s is missing or inaccessible."
            % (weechat.prefix("error"), SCRIPT_NAME, dbfile))
        raise e  # TODO: handle this better instead of brutally aborting
开发者ID:OliverUv,项目名称:weechat-emojis,代码行数:48,代码来源:emojis.py

示例4: hook_all

def hook_all():
    """ Hook command_run and modifier """
    global hook_command_run, hooks
    for hook, value in hook_command_run.iteritems():
        if hook not in hooks:
            hooks[hook] = weechat.hook_command_run(value[0], value[1], "")
    if "modifier" not in hooks:
        hooks["modifier"] = weechat.hook_modifier("input_text_display_with_cursor", "input_modifier", "")
开发者ID:ronin13,项目名称:seed,代码行数:8,代码来源:go.py

示例5: toggle_refresh

def toggle_refresh(pointer, name, value):
    global OPTIONS
    option = name[len("plugins.var.python." + SCRIPT_NAME + ".") :]  # get optionname
    OPTIONS[option] = value  # save new value

    if OPTIONS["catch_input_completion"].lower() == "off":
        if Hooks["catch_input_completion"]:
            weechat.unhook(Hooks["catch_input_completion"])
            Hooks["catch_input_completion"] = ""
            weechat.unhook(Hooks["catch_input_return"])
            Hooks["catch_input_return"] = ""
    elif OPTIONS["catch_input_completion"].lower() == "on":
        if not Hooks["catch_input_completion"]:
            Hooks["catch_input_completion"] = weechat.hook_command_run("/input complete*", "input_complete_cb", "")
            Hooks["catch_input_return"] = weechat.hook_command_run("/input return", "input_return_cb", "")

    return weechat.WEECHAT_RC_OK
开发者ID:Ratler,项目名称:weechatter-weechat-scripts,代码行数:17,代码来源:spell_correction.py

示例6: toggle_refresh

def toggle_refresh(pointer, name, value):
    global OPTIONS
    option = name[len('plugins.var.python.' + SCRIPT_NAME + '.'):]        # get optionname
    OPTIONS[option] = value                                               # save new value

    if OPTIONS['catch_input_completion'].lower() == "off":
        if Hooks['catch_input_completion']:
            weechat.unhook(Hooks['catch_input_completion'])
            Hooks['catch_input_completion'] = ''
            weechat.unhook(Hooks['catch_input_return'])
            Hooks['catch_input_return'] = ''
    elif OPTIONS['catch_input_completion'].lower() == "on":
        if not Hooks['catch_input_completion']:
            Hooks['catch_input_completion'] = weechat.hook_command_run('/input complete*', 'input_complete_cb', '')
            Hooks['catch_input_return'] = weechat.hook_command_run('/input return', 'input_return_cb', '')

    return weechat.WEECHAT_RC_OK
开发者ID:FiXato,项目名称:weechat-scripts,代码行数:17,代码来源:spell_correction.py

示例7: main

def main():
    at_config('load')
    # hook our config
    weechat.hook_config(STRIP_VAR+'*','at_config','')
    # hook the nick complete
    weechat.hook_command_run('/input complete_next', 'at_completion', '')
    # hook the /atcomplete
    weechat.hook_command('atcomplete','manage @nick completion plugin',
        '[enable|disable|toggle] '
        ' | [servers [list | add name | del name]]'
        ' | [buffers [list | add name | del name]]',
        'args desc',
        'status %-'
        ' || enable %-'
        ' || disable %-'
        ' || toggle %-'
        ' || server list|add|del %(buffers_names)'
        ' || buffer list|add|del %(buffers_names)'
        ,
        'at_control','')
    # hook the completetion for /atcomplete
    weechat.hook_completion('plugin_at_completion','@nick completion','at_complete','')
开发者ID:WarheadsSE,项目名称:weechat-atcompletion,代码行数:22,代码来源:at_completion.py

示例8: main

def main():
        version = weechat.info_get('version_number', '') or 0

        if int(version) < 0x00030600:
            print_error('script needs version 0.3.6 or higher')
            weechat.command('', "/wait 1ms /python unload %s" % SCRIPT_NAME)
            return

        init_config()

        description = """
{script_name} can make sure that when switching to a buffer it appears only in a particular window.
To trigger this behaviour set the localvar 'stick_buffer_to_window' to the desired window number.

You will need the script 'buffer_autoset.py' installed to make local variables persistent; see the
examples below.

Examples:
 Temporarily stick the current buffer to window 3:
   /buffer set localvar_set_stick_buffer_to_window 3
 Stick buffer #weechat to window 2:
   /buffer #weechat
   /buffer set localvar_set_stick_buffer_to_window 2
   /buffer_autoset add irc.freenode.#weechat stick_buffer_to_window 2
 Set the default stick-to window to window 5:
   /set plugins.var.python.{script_name}.default_stick_window 5
 List buffers with persistent stickiness:
   /{script_name} list
 Show this help:
   /{script_name} help
 Display local variables for current buffer:
   /buffer localvar
""".format(script_name = SCRIPT_NAME)

        weechat.hook_command(SCRIPT_NAME, SCRIPT_DESC, 'list', description, 'list %-', 'cmd_cb', '')

        weechat.hook_command_run('/buffer *', 'buffer_switch_cb', '')
        weechat.hook_command_run('/input jump_smart', 'buffer_switch_cb', '')
开发者ID:DarkDefender,项目名称:scripts,代码行数:38,代码来源:stick_buffer.py

示例9: hook_all

def hook_all():
    """ Hook command_run and modifier """
    global hook_command_run, hooks
    priority = ""
    version = weechat.info_get("version_number", "") or 0
    # use high priority for hook to prevent conflict with other plugins/scripts
    # (WeeChat >= 0.3.4 only)
    if int(version) >= 0x00030400:
        priority = "2000|"
    for hook, value in hook_command_run.items():
        if hook not in hooks:
            hooks[hook] = weechat.hook_command_run("%s%s" % (priority, value[0]), value[1], "")
    if "modifier" not in hooks:
        hooks["modifier"] = weechat.hook_modifier("input_text_display_with_cursor", "input_modifier", "")
开发者ID:thisismiller,项目名称:dotfiles,代码行数:14,代码来源:go.py

示例10: config_cb

def config_cb(data, option, value):
    """Called when a script option is changed."""
    global cmdhelp_settings, cmdhelp_hooks
    pos = option.rfind('.')
    if pos > 0:
        name = option[pos+1:]
        if name in cmdhelp_settings:
            cmdhelp_settings[name] = value
            if name == 'stop_on_enter':
                if value == 'on' and not cmdhelp_hooks['command_run']:
                    cmdhelp_hooks['command_run'] = weechat.hook_command_run(
                        '/input return', 'command_run_cb', '')
                elif value != 'on' and cmdhelp_hooks['command_run']:
                    unhook(('command_run',))
    return weechat.WEECHAT_RC_OK
开发者ID:DarkDefender,项目名称:scripts,代码行数:15,代码来源:cmd_help.py

示例11: go_hook_all

def go_hook_all():
    """Hook command_run and modifier."""
    global hooks
    priority = ''
    version = weechat.info_get('version_number', '') or 0
    # use high priority for hook to prevent conflict with other plugins/scripts
    # (WeeChat >= 0.3.4 only)
    if int(version) >= 0x00030400:
        priority = '2000|'
    for hook, value in HOOK_COMMAND_RUN.items():
        if hook not in hooks:
            hooks[hook] = weechat.hook_command_run(
                '%s%s' % (priority, value[0]),
                value[1], '')
    if 'modifier' not in hooks:
        hooks['modifier'] = weechat.hook_modifier(
            'input_text_display_with_cursor', 'go_input_modifier', '')
开发者ID:gilbertw1,项目名称:scripts,代码行数:17,代码来源:go.py

示例12: test_hooks

def test_hooks():
    """Test function hook_command."""
    # hook_completion / hook_completion_args / and hook_command
    hook_cmplt = weechat.hook_completion('SCRIPT_NAME', 'description',
                                         'completion_cb', 'completion_data')
    hook_cmd = weechat.hook_command('cmd' + 'SCRIPT_NAME', 'description',
                                    'arguments', 'description arguments',
                                    '%(' + 'SCRIPT_NAME' + ')',
                                    'command_cb', 'command_data')
    weechat.command('', '/input insert /cmd' + 'SCRIPT_NAME' + ' w')
    weechat.command('', '/input complete_next')
    # hook_command_run
    hook_cmd_run = weechat.hook_command_run('/cmd' + 'SCRIPT_NAME' + '*',
                                            'command_run_cb', 'command_run_data')
    weechat.command('', '/input return')
    weechat.unhook(hook_cmd_run)
    weechat.unhook(hook_cmd)
    weechat.unhook(hook_cmplt)
开发者ID:weechat,项目名称:weechat,代码行数:18,代码来源:testapi.py

示例13: int

                cmdhelp_settings[option] = weechat.config_get_plugin(option)
            else:
                weechat.config_set_plugin(option, value[0])
                cmdhelp_settings[option] = value[0]
            if int(version) >= 0x00030500:
                weechat.config_set_desc_plugin(
                    option,
                    '%s (default: "%s")' % (value[1], value[0]))

        # detect config changes
        weechat.hook_config('plugins.var.python.%s.*' % SCRIPT_NAME,
                            'config_cb', '')

        # add hook to catch "enter" key
        if cmdhelp_settings['stop_on_enter'] == 'on':
            cmdhelp_hooks['command_run'] = weechat.hook_command_run(
                '/input return', 'command_run_cb', '')

        # add command
        weechat.hook_command(
            SCRIPT_COMMAND,
            'Contextual command line help.',
            '',
            'This comand toggles help on command line.\n\n'
            'It is recommended to bind this command on a key, for example '
            'F1:\n'
            '  /key bind <press alt-k> <press F1> /cmd_help\n'
            'which will give, according to your terminal something like:\n'
            '      /key bind meta-OP /cmd_help\n'
            '    or:\n'
            '      /key bind meta2-11~ /cmd_help\n\n'
            'To try: type "/server" (without pressing enter) and press F1 '
开发者ID:DarkDefender,项目名称:scripts,代码行数:32,代码来源:cmd_help.py

示例14: command_run_input

SCRIPT_AUTHOR = "Ben Hughes <[email protected]>"
SCRIPT_VERSION = "0.2"
SCRIPT_LICENSE = "BSD"
SCRIPT_DESC = "Stops you being yubikeyed"


if w.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE,
              SCRIPT_DESC, "", ""):

    # Hooks we want to hook
    hook_command_run = {
        "input": ("/input return",  "command_run_input"),
    }
    # Hook all hooks !
    for hook, value in hook_command_run.iteritems():
        w.hook_command_run(value[0], value[1], "")


def command_run_input(data, buffer, command):
    """ Function called when a command "/input xxxx" is run """
    if command == "/input return":  # As in enter was pressed.

        # Get input contents
        input_s = w.buffer_get_string(buffer, 'input')

        # Skip modification of settings
        if input_s.startswith('/'):
            return w.WEECHAT_RC_OK

        yubistring = w.config_get_plugin('yubistring')
开发者ID:barn,项目名称:weechat-yubi,代码行数:30,代码来源:yubi.py

示例15: config_changed

def config_changed(data, option, value):
    init_config()
    return w.WEECHAT_RC_OK

def tc_action_cb():
    global tc_options
    if tc_options['warn_command']:
        if tc_options['warn_command'] == '$bell':
            f = open('/dev/tty', 'w')
            f.write('\a')
            f.close()
        else:
            os.system(tc_options['warn_command'])
    return w.WEECHAT_RC_OK

if __name__ == "__main__" and import_ok:
    if w.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION,
                  SCRIPT_LICENSE, SCRIPT_DESC,
                  "", ""):
        version = w.info_get("version_number", "") or 0
        init_config() # read configuration
        tc_bar_item_update() # update status bar display

        w.hook_signal('input_text_changed', 'tc_bar_item_update', '')
        w.hook_signal('input_text_cursor_moved','tc_bar_item_update','')
        w.hook_command_run('/input move_previous_char','command_run_cb','')
        w.hook_command_run('/input delete_previous_char','command_run_cb','')
        w.hook_signal('buffer_switch','tc_bar_item_update','')
        w.hook_config('plugins.var.python.' + SCRIPT_NAME + ".*", "config_changed", "")
        w.bar_item_new('tc', 'tc_bar_item', '')
开发者ID:MatthewCox,项目名称:dotfiles,代码行数:30,代码来源:typing_counter.py


注:本文中的weechat.hook_command_run函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。