def get_string(**options): """Get a string using dialog Accepts `title` and `prompt` strings, and returns the string entered by the user. """ # Set defaults and get options: if not options.has_key('title'): options['title']='Enter String' if not options.has_key('prompt'): options['prompt']='String:' plist = to_plist(options) # Run dialog, piping our plist in, and reading the output: nib = nib_path + '/RequestString' proc = subprocess.Popen([dialog, '-cm', nib], stdout=subprocess.PIPE, stdin=subprocess.PIPE) proc.stdin.write(plist) output, _ = proc.communicate() # Extract exit value: result = from_plist(output) if not 'result' in result: return None else: return result['result'].get('returnArgument')
def menu(options): """ Accepts a list and causes TextMate to show an inline menu. If options is a list of strings, will return the selected index. If options is a list of (key, value) tuples, will display "key" and return "value". Note that we don't use dicts, so that key-value options can be ordered. If you want to use a dict, try dict.items(). In either input case, a list item with value `None` causes tm_dialog to display a separator for that index. """ hashed_options = False if not options: return None menu = dict(menuItems=[item(thing) for thing in options]) if all_are_instance(options, (tuple, NoneType)): hashed_options = True plist = to_plist(menu) proc = subprocess.Popen([dialog, '-u'], stdout=subprocess.PIPE, stdin=subprocess.PIPE) proc.stdin.write(plist) output, _ = proc.communicate() result = from_plist(output) if not 'selectedIndex' in result: return None index = int(result['selectedIndex']) if hashed_options: return options[index][1] return options[index]
def menu(options): """ Accepts a list and causes TextMate to show an inline menu. If options is a list of strings, will return the selected index. If options is a list of (key, value) tuples, will return value of the selected key. Note that we don't use dicts, so that key-value options can be ordered. If you want to use a dict, try dict.items(). In either input case, a list item with value `None` causes tm_dialog to separator for that index. """ hashed_options = False if not options: return None if all_are_instance(options, (unicode, str, NoneType)): menu = dict(menuItems=[item(val) for val in options]) elif all_are_instance(options, (tuple, NoneType)): hashed_options = True menu = dict(menuItems=[item(pair) for pair in options]) plist = to_plist(menu) cmd = 'bash -c "%s -up %s"' % (sh_escape(dialog), sh_escape(plist)) result = from_plist(sh(cmd)) if not 'selectedIndex' in result: return None index = int(result['selectedIndex']) if hashed_options: return options[index][1] return options[index]
def get_string(**options): """Get a string using dialog Accepts: - `title` - The string to show in the title bar - `prompt` - The label for the text field - `string` - The default value inside the text field Returns: - The string entered by the user. """ # Set defaults and get options: if 'title' not in options: options['title']='Enter String' if 'prompt' not in options: options['prompt']='String:' if 'string' not in options: options['string']='' plist = to_plist(options) # Run dialog, piping our plist in, and reading the output: nib = nib_path + '/RequestString' proc = subprocess.Popen([dialog, '-cm', nib], stdout=subprocess.PIPE, stdin=subprocess.PIPE) proc.stdin.write(plist) output, _ = proc.communicate() # Extract exit value: result = from_plist(output) if not 'result' in result: return None else: return result['result'].get('returnArgument')
def get_string(**options): """Get a string using dialog Accepts: - `title` - The string to show in the title bar - `prompt` - The label for the text field - `string` - The default value inside the text field Returns: - The string entered by the user. """ # Set defaults and get options: if not options.has_key('title'): options['title'] = 'Enter String' if not options.has_key('prompt'): options['prompt'] = 'String:' if not options.has_key('string'): options['string'] = '' plist = to_plist(options) # Run dialog, piping our plist in, and reading the output: nib = nib_path + '/RequestString' proc = subprocess.Popen([dialog, '-cm', nib], stdout=subprocess.PIPE, stdin=subprocess.PIPE) proc.stdin.write(plist) output, _ = proc.communicate() # Extract exit value: result = from_plist(output) if not 'result' in result: return None else: return result['result'].get('returnArgument')
def call_dialog(command, options=None, shell=True): popen = subprocess.Popen( command, stdin=subprocess.PIPE, stdout=subprocess.PIPE,shell=shell) if options: out, _ = popen.communicate(to_plist(options)) else: out, _ = popen.communicate() return out
def call_dialog(command, options=None, shell=True): # command += " --suggestions '(%s)'" % to_plist(options) popen = subprocess.Popen( command, stdin=subprocess.PIPE, stdout=subprocess.PIPE,shell=shell) # options = None if options: out, _ = popen.communicate(to_plist(options)) else: out, _ = popen.communicate() return out
def call_dialog(command, options=None, shell=True): if shell: command = shlex.split(command) popen = subprocess.Popen( command, stdin=subprocess.PIPE, stdout=subprocess.PIPE) if options: out, _ = popen.communicate(to_plist(options).encode("utf-8")) else: out, _ = popen.communicate() return out
def call_dialog(command, options=None, shell=True): if shell: command = shlex.split(command) popen = subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE) if options: out, _ = popen.communicate(to_plist(options)) else: out, _ = popen.communicate() return out