本文整理汇总了Python中weechat.hook_timer函数的典型用法代码示例。如果您正苦于以下问题:Python hook_timer函数的具体用法?Python hook_timer怎么用?Python hook_timer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了hook_timer函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_invite
def add_invite(server, channel):
servbuf = _server_buffer(server)
if servbuf not in queue:
queue[servbuf] = [channel]
weechat.hook_timer(1000, 0, 1, "timer_cb", servbuf)
else:
queue[servbuf].append(channel)
示例2: main
def main():
if weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, SCRIPT_DESC, "", ""):
version = int(weechat.info_get("version_number", "")) or 0
# unset unused setting from older versions of script
if weechat.config_is_set_plugin("display_unit"):
weechat.prnt("", "Option plugins.var.python.bandwidth.display_unit no longer used, removing.")
weechat.config_unset_plugin("display_unit")
# set default settings
for option in SCRIPT_SETTINGS.iterkeys():
if not weechat.config_is_set_plugin(option):
weechat.config_set_plugin(option, SCRIPT_SETTINGS[option][0])
if version >= 0x00030500:
weechat.config_set_desc_plugin(option, SCRIPT_SETTINGS[option][1])
# ensure sane refresh_rate setting
if int(weechat.config_get_plugin("refresh_rate")) < 1:
weechat.prnt(
"",
"{}Invalid value for option plugins.var.python.bandwidth.refresh_rate, setting to default of {}".format(
weechat.prefix("error"), SCRIPT_SETTINGS["refresh_rate"][0]
),
)
weechat.config_set_plugin("refresh_rate", SCRIPT_SETTINGS["refresh_rate"][0])
# create the bandwidth monitor bar item
weechat.bar_item_new("bandwidth", "bandwidth_item_cb", "")
# update it every plugins.var.python.bandwidth.refresh_rate seconds
weechat.hook_timer(int(weechat.config_get_plugin("refresh_rate")) * 1000, 0, 0, "bandwidth_timer_cb", "")
示例3: a_notify
def a_notify(bname, nclass, title, description, priority=pynotify.URGENCY_LOW):
'''Creates or updates the notification'''
is_away = STATE['is_away']
icon = STATE['icon']
time_out = int(weechat.config_get_plugin("timeout"))
cur_time = time.time()
threshold = 1.0
refresh = 0.01
try:
BUFFERS[bname].append(
description,
merge=weechat.config_get_plugin("merge") == "on",
)
except KeyError:
BUFFERS[bname] = BufferState(
title,
threshold,
refresh,
icon=icon,
priority=priority,
timeout=time_out,
)
BUFFERS[bname].append(
description,
merge=weechat.config_get_plugin("merge") == "on",
)
weechat.hook_timer(500, 0, 1, "cb_buffer_start", bname)
示例4: main
def main():
'''Sets up WeeChat notifications.'''
# Initialize options.
for option, value in SETTINGS.items():
if not weechat.config_is_set_plugin(option):
weechat.config_set_plugin(option, value)
# Initialize.
name = "WeeChat"
icon = "/usr/share/pixmaps/weechat.xpm"
notifications = [
'Public',
'Private',
'Action',
'Notice',
'Invite',
'Highlight',
'Server',
'Channel',
'DCC',
'WeeChat'
]
STATE['icon'] = icon
# Register hooks.
weechat.hook_signal(
'irc_server_connected',
'cb_irc_server_connected',
'')
weechat.hook_signal(
'irc_server_disconnected',
'cb_irc_server_disconnected',
'')
weechat.hook_signal('upgrade_ended', 'cb_upgrade_ended', '')
weechat.hook_print('', '', '', 1, 'cb_process_message', '')
weechat.hook_timer(1000, 1, 65535, "cb_buffer_tick", "")
pynotify.init(name)
示例5: conf_update_cb
def conf_update_cb(data, option, value):
#Commit data if not part of ignore list.
if weechat.config_get_plugin("commit_each_change") == "true" and not option in weechat.config_get_plugin("auto_commit_ignore").split(","):
#Call use pause else /save will be called before the config is actually saved to disc
#This is kinda hack but better input would be appricated.
weechat.hook_timer(500, 0, 1, "commit_cb", "")
return weechat.WEECHAT_RC_OK
示例6: cb_update_line_numbers
def cb_update_line_numbers(data, signal, signal_data):
"""Call `cb_timer_update_line_numbers()` when switching buffers.
A timer is required because the bar item is refreshed before the new buffer
is actually displayed, so ``win_chat_height`` would refer to the old
buffer. Using a timer refreshes the item after the new buffer is displayed.
"""
weechat.hook_timer(10, 0, 1, "cb_timer_update_line_numbers", "")
return weechat.WEECHAT_RC_OK
示例7: send_typing
def send_typing(nick, level):
if not channel_has_nick(bitlbee_server_name, bitlbee_channel, nick):
return
cookie = sending_typing.get(nick, 1) + 1
if not sending_typing.get(nick, None):
send_typing_ctcp(nick, level)
sending_typing[nick] = cookie
w.hook_timer(4000, 0, 1, "typing_disable_timer", "%s:%i" % (nick, cookie))
示例8: on_signal
def on_signal(*args, **kwargs):
global timer
''' Called whenever the buffer list changes. '''
if timer is not None:
weechat.unhook(timer)
timer = None
weechat.hook_timer(config.signal_delay, 0, 1, "on_timeout", "")
return weechat.WEECHAT_RC_OK
示例9: Winner
def Winner(self, winner):
self.trivial['state'] = 0
if self.trivial['main_timer']:
weechat.unhook(self.trivial['main_timer'])
self.Show_Awards(winner)
self.Register_Question(winner)
self.Show_Session_Awards(winner)
self.Show_Ranking()
interval = int(self.opts['time_wait'])
weechat.hook_timer(interval * 1000, 0, 1, 'Wait_Next_Round_cb', self.TrivId)
示例10: modifier_cb
def modifier_cb(data,modifier,modifier_data,string):
global bufp,linetosay
if len(string)<2 or (string[0]=="/" and string[1]!="/"): return string
bufp=modifier_data
linetosay=intlmakeEline(string)
if linetosay==None: return string
weechat.hook_timer(10,0,1,"timer_cb","")
return string
示例11: cb_buffer_tick
def cb_buffer_tick(arg, remaining_calls):
for buf in list(BUFFERS.keys()):
if not BUFFERS[buf].tick():
# weechat.prnt('', 'anotify: removing notifier {0}'.format(BUFFERS[buf]._window))
BUFFERS.pop(buf)
if remaining_calls == 0:
weechat.hook_timer(1000, 1, 65535, "cb_buffer_tick", arg)
return weechat.WEECHAT_RC_OK
示例12: serverConnected
def serverConnected(data, buffer, args):
global start_time_sec
start_time_sec = readTimer()
global connectedState
connectedState = 1
# POSIX of the start of the session
global session_start_time
session_start_time = time.time()
weechat.hook_timer(1000,1,0,'updateTimer','')
return weechat.WEECHAT_RC_OK
示例13: pressed_keys_check
def pressed_keys_check(data, remaining_calls):
"""Check the pressed keys and changes modes or detects bound keys
accordingly.
"""
global pressed_keys, mode, vi_buffer, esc_pressed
# If the last pressed key was Escape, this one will be detected as an arg
# as Escape acts like a modifier (pressing Esc, then pressing i is detected
# as pressing meta-i). We'll emulate it being pressed again, so that the
# user's input is actually processed normally.
if esc_pressed is True:
esc_pressed = False
weechat.hook_timer(50, 0, 1, "handle_esc", pressed_keys[-1])
if mode == "INSERT":
# Ctrl + Space, or Escape
if pressed_keys == "@" or pressed_keys == "[":
set_mode("NORMAL")
if pressed_keys == "[":
esc_pressed = True
elif mode == "NORMAL":
# We strip all numbers and check if the the combo is recognized below,
# then extract the numbers, if any, and pass them as the repeat factor.
buffer_stripped = re.sub(num, '', vi_buffer)
if vi_buffer in ['i', 'a', 'A']:
set_mode("INSERT")
if vi_buffer == 'a':
weechat.command('', "/input move_next_char")
elif vi_buffer == 'A':
weechat.command('', "/input move_end_of_line")
# Pressing '0' should not be detected as a repeat count.
elif vi_buffer == '0':
weechat.command('', vi_keys['0'])
# Quick way to detect repeats (e.g. d5w). This isn't perfect, as things
# like "5d2w1" are detected as "dw" repeated 521 times, but it should
# be alright as long as the user doesn't try to break it on purpose.
# Maximum number of repeats performed is 10000.
elif buffer_stripped in vi_keys:
repeat = ''.join(re.findall(num, vi_buffer))
if len(repeat) > 0:
repeat = min([int(repeat), 10000])
else:
repeat = 0
if isinstance(vi_keys[buffer_stripped], str):
for _ in range(1 if repeat == 0 else repeat):
weechat.command('', vi_keys[re.sub(num, '', vi_buffer)])
else:
buf = weechat.current_buffer()
input_line = weechat.buffer_get_string(buf, 'input')
cur = weechat.buffer_get_integer(buf, "input_pos")
vi_keys[buffer_stripped](buf, input_line, cur, repeat)
else:
return weechat.WEECHAT_RC_OK
clear_vi_buffers()
return weechat.WEECHAT_RC_OK
示例14: send_typing
def send_typing(nick, level):
if level == 0 and nick in sending_typing:
send_typing_ctcp(nick, 0)
del sending_typing[nick]
elif level > 0 :
if nick not in sending_typing:
send_typing_ctcp(nick, level)
cookie = sending_typing.get(nick, 0) + 1
sending_typing[nick] = cookie
w.hook_timer( int(1000 * float(w.config_get_plugin('timeout'))), 0, 1,
"typing_disable_timer", "%s:%i" % (nick, cookie))
示例15: modifier_cb
def modifier_cb(data,modifier,modifier_data,string):
global nrip
bufplugin,bufname=modifier_data.split(";")[0:2]
fullname=bufplugin+"."+bufname
if fullname.lower()!=BUFFERNAME.lower():
return string
# weechat.prnt("",dashprefix+"[rip] SR=<"+str(SEARCHREGEX)+"> string=<"+string+">")
if re.search(SEARCHREGEX,string,re.IGNORECASE):
nrip+=1
weechat.hook_timer(10,0,1,"timer_cb","")
return string