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 get_input(title="Input",default=""): if os.environ.get('TM_RopeMate_HUD', False): nib = os.environ['TM_BUNDLE_SUPPORT']+"/input_hud" else: nib = os.environ['TM_BUNDLE_SUPPORT']+"/input" out = call_dialog([TM_DIALOG, '-cm', nib], {'title':title, 'result':default}, False) if not out: return None return from_plist(out).get('result', None)
def get_input(title="Input", default=""): if os.environ.get('TM_RopeMate_HUD', False): nib = os.environ['TM_BUNDLE_SUPPORT'] + "/input_hud" else: nib = os.environ['TM_BUNDLE_SUPPORT'] + "/input" out = call_dialog([TM_DIALOG, '-cm', nib], { 'title': title, 'result': default }, False) if not out: return None return from_plist(out).get('result', None)
def get_confirmation(title_text='', body_text=''): """Use dialog2 to ask for confirmation Returns `True` to indicate confirmation. Returns `None` to indicate an error. """ dtype = 'alert' style = '--alertStyle warning' title = "--title '%s'" % title_text or 'Confirm file deletion' body = "--body '%s'" % body_text or 'Confirm file deletion:' buttons = "--button1 Delete --button2 Cancel" args = ' '.join(["'%s'" % dialog, dtype, style, title, body, buttons]) output = os.popen(args, 'r').read() result = from_plist(output) if not 'buttonClicked' in result: return None return int(result['buttonClicked']) == 0
def get_confirmation(title_text='', body_text='' ): """Use dialog2 to ask for confirmation Returns `True` to indicate confirmation. Returns `None` to indicate an error. """ dtype = 'alert' style = '--alertStyle warning' title = "--title '%s'" % title_text or 'Confirm file deletion' body = "--body '%s'" % body_text or 'Confirm file deletion:' buttons = "--button1 Delete --button2 Cancel" args = ' '.join(["'%s'" % dialog, dtype, style, title, body, buttons]) output = os.popen(args, 'r').read() result = from_plist(output) if not 'buttonClicked' in result: return None return int(result['buttonClicked']) == 0