def do_paste_cmd(words, words_eol, userdata, *args, **kwargs): # IDEA/TODO: Paster object to store options and argparser? # Example: # /fc_paste -fb -n "Paste name" -p pb -e "1 week" -s text -x unlisted -S # /fc_paste -tc "command" Paste content goes here # /fc_paste -fb -ti -C # /fc_paste -h parsed_args = kwargs.get("parsed_args") print_debug("words", words) for w in words_eol: print_debug("words_eol:", w) if parsed_args is None: parsed_args, content = find_content_in_args(words, words_eol, argparser) if parsed_args is None: print_debug("parsed_args is None even after find_content_in_args") return parsed_args['content'] = content if parsed_args['guard_inputbox_cmd'] and parsed_args[ 'source'] == "inputbox": # TODO: could split into separate function and also use in do_paste doprocess, message, fullcommand, _ = preprocess_inputbox(ibx.get()) if doprocess: parsed_args['guard_inputbox_cmd'] = fullcommand, message else: parsed_args['guard_inputbox_cmd'] = False print_debug("parsed", parsed_args) do_paste(**parsed_args)
def do_paste_cmd(words, words_eol, userdata, *args, **kwargs): # IDEA/TODO: Paster object to store options and argparser? # Example: # /fc_paste -fb -n "Paste name" -p pb -e "1 week" -s text -x unlisted -S # /fc_paste -tc "command" Paste content goes here # /fc_paste -fb -ti -C # /fc_paste -h parsed_args = kwargs.get("parsed_args") print_debug("words", words) for w in words_eol: print_debug("words_eol:", w) if parsed_args is None: parsed_args, content = find_content_in_args(words, words_eol, argparser) parsed_args['content'] = content if parsed_args['guard_inputbox_cmd'] and parsed_args['source'] == "inputbox": # TODO: could split into separate function and also use in do_paste doprocess, message, fullcommand, _ = preprocess_inputbox(ibx.get()) if doprocess: parsed_args['guard_inputbox_cmd'] = fullcommand, message else: parsed_args['guard_inputbox_cmd'] = False print_debug("parsed", parsed_args) do_paste(**parsed_args)
def get_input_from_argparse(callback, parsed_args): print_debug(parsed_args) parsed_args = parsed_args.copy() source = parsed_args.get('source') print_debug("get_input args", parsed_args) if parsed_args.get("confirm"): del parsed_args['confirm'] def confirmed_cb(b): if b: get_input_from_argparse(callback, parsed_args) if is_mainthread(): send_getbool_to_callback(confirmed_cb) else: hexchat.hook_timer(20, send_getbool_to_callback, confirmed_cb) return if source == "inputbox": if not parsed_args['guard_inputbox_cmd']: callback(ibx.get()) else: callback(parsed_args['guard_inputbox_cmd'][1]) elif source == "clipboard" and HAVE_XEROX: callback(xerox.paste()) elif source == "window": # Ask main thread to getstr and then give it to our callback. if is_mainthread(): send_getstr_to_callback(callback) else: hexchat.hook_timer(20, send_getstr_to_callback, callback) else: raise FloodcontrolError("Could not get input. Requested source: {}".format(source))
def inputbox_autopaste_on_limit(*args): if len(args) < 4: doprocess, message, fullcommand, cmd_length = preprocess_inputbox(ibx.get()) else: doprocess, message, fullcommand, cmd_length = args options = {"guard_inputbox_cmd": (fullcommand, message), "source": "inputbox", "to_inputbox": True} do_paste(**options)
def inputbox_autopaste_on_limit(*args): if len(args) < 4: doprocess, message, fullcommand, cmd_length = preprocess_inputbox( ibx.get()) else: doprocess, message, fullcommand, cmd_length = args options = { "guard_inputbox_cmd": (fullcommand, message), "source": "inputbox", "to_inputbox": True } do_paste(**options)
def get_input_from_argparse(callback, parsed_args): print_debug(parsed_args) parsed_args = parsed_args.copy() source = parsed_args.get('source') print_debug("get_input args", parsed_args) if parsed_args.get("confirm"): del parsed_args['confirm'] def confirmed_cb(b): if b: get_input_from_argparse(callback, parsed_args) if is_mainthread(): send_getbool_to_callback(confirmed_cb) else: hexchat.hook_timer(20, send_getbool_to_callback, confirmed_cb) return if source == "inputbox": if not parsed_args['guard_inputbox_cmd']: callback(ibx.get()) else: callback(parsed_args['guard_inputbox_cmd'][1]) elif source == "clipboard" and HAVE_XEROX: callback(xerox.paste()) elif source == "window": # Ask main thread to getstr and then give it to our callback. if is_mainthread(): send_getstr_to_callback(callback) else: hexchat.hook_timer(20, send_getstr_to_callback, callback) elif parsed_args['content']: callback(parsed_args['content']) else: raise FloodcontrolError( "Could not get input. Requested source: {}".format(source))