Commit a26ae008 authored by Nikos Skalkotos's avatar Nikos Skalkotos
Browse files

Monkey-patch pythondialog to support form boxes

parent 121f3bc0
......@@ -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",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment