def CheckList(column_names, data, title=None): """Present a list of items to select. Args: column_names(list[str]): A list containing the names of the columns. data(list[str]]): A list that contains, for each cell in the row, its selected status, and the value. For example: ['True', 'field1', 'False', 'Field2'] title(str): The title of the dialog box. Returns: list[str]: the selected fields. """ zenity_binary = Which('zenity') command = [zenity_binary, '--list', '--checklist', '--editable=False'] for column in column_names: command.append('--column="{2:s}"'.format(column)) if title: command.append('--title="{0:s}"'.format(title)) command = command + data process = subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE) if process.wait() == 0: return process.stdout.read().strip().split('|') return []
def GetYesNo(text): """Ask user a Yes/No question. Args: text(str): The message to display. Returns: bool: the user's answer. """ zenity_binary = Which('zenity') process = subprocess.Popen( [zenity_binary, '--question', '--text="{0:s}"'.format(text)], stdin=subprocess.PIPE, stdout=subprocess.PIPE) return process.wait() == 0
def GetText(text): """Ask user for a string. Args: text(str): The message to display. Returns: str: the user input. """ zenity_binary = Which('zenity') process = subprocess.Popen( [zenity_binary, '--entry', '--text="{0:s}"'.format(text)], stdin=subprocess.PIPE, stdout=subprocess.PIPE) if process.wait() == 0: return process.stdout.read()[:-1] return ''