diff --git a/image_creator/dialog_main.py b/image_creator/dialog_main.py index d8e86b1ba1d7991d37997e4d6b7cc19f3646ef12..e0e4e04551149956b7d9310fac364e0b1cdcf2f3 100644 --- a/image_creator/dialog_main.py +++ b/image_creator/dialog_main.py @@ -46,6 +46,7 @@ import stat import textwrap import signal import optparse +import types from image_creator import __version__ as version from image_creator.util import FatalError @@ -163,6 +164,39 @@ def select_file(d, media): return media +def _dialog_form(self, text, height=20, width=60, form_height=15, fields=[], + **kwargs): + """Display a form box. + + fields is in the form: [(label1, item1, item_length1), ...] + """ + + cmd = ["--form", text, str(height), str(width), str(form_height)] + + label_len = 0 + for field in fields: + if len(field[0]) > label_len: + label_len = len(field[0]) + + input_len = width - label_len - 2 + + line = 1 + for field in fields: + label = field[0] + item = field[1] + item_len = field[2] + cmd.extend((label, str(line), str(1), item, str(line), + str(label_len + 2), str(input_len), str(item_len))) + line += 1 + + code, output = self._perform(*(cmd,), **kwargs) + + if not output: + return (code, []) + + return (code, output.splitlines()) + + def main(): d = dialog.Dialog(dialog="dialog") @@ -181,6 +215,10 @@ def main(): dialog._common_args_syntax["no_label"] = \ lambda string: ("--no-label", string) + # Monkey-patch pythondialog to include support for form dialog boxes + if not hasattr(dialog, 'form'): + d.form = types.MethodType(_dialog_form, d) + usage = "Usage: %prog [options] [<input_media>]" parser = optparse.OptionParser(version=version, usage=usage) parser.add_option("-l", "--logfile", type="string", dest="logfile",