Revision a26ae008
b/image_creator/dialog_main.py | ||
---|---|---|
46 | 46 |
import textwrap |
47 | 47 |
import signal |
48 | 48 |
import optparse |
49 |
import types |
|
49 | 50 |
|
50 | 51 |
from image_creator import __version__ as version |
51 | 52 |
from image_creator.util import FatalError |
... | ... | |
163 | 164 |
return media |
164 | 165 |
|
165 | 166 |
|
167 |
def _dialog_form(self, text, height=20, width=60, form_height=15, fields=[], |
|
168 |
**kwargs): |
|
169 |
"""Display a form box. |
|
170 |
|
|
171 |
fields is in the form: [(label1, item1, item_length1), ...] |
|
172 |
""" |
|
173 |
|
|
174 |
cmd = ["--form", text, str(height), str(width), str(form_height)] |
|
175 |
|
|
176 |
label_len = 0 |
|
177 |
for field in fields: |
|
178 |
if len(field[0]) > label_len: |
|
179 |
label_len = len(field[0]) |
|
180 |
|
|
181 |
input_len = width - label_len - 2 |
|
182 |
|
|
183 |
line = 1 |
|
184 |
for field in fields: |
|
185 |
label = field[0] |
|
186 |
item = field[1] |
|
187 |
item_len = field[2] |
|
188 |
cmd.extend((label, str(line), str(1), item, str(line), |
|
189 |
str(label_len + 2), str(input_len), str(item_len))) |
|
190 |
line += 1 |
|
191 |
|
|
192 |
code, output = self._perform(*(cmd,), **kwargs) |
|
193 |
|
|
194 |
if not output: |
|
195 |
return (code, []) |
|
196 |
|
|
197 |
return (code, output.splitlines()) |
|
198 |
|
|
199 |
|
|
166 | 200 |
def main(): |
167 | 201 |
|
168 | 202 |
d = dialog.Dialog(dialog="dialog") |
... | ... | |
181 | 215 |
dialog._common_args_syntax["no_label"] = \ |
182 | 216 |
lambda string: ("--no-label", string) |
183 | 217 |
|
218 |
# Monkey-patch pythondialog to include support for form dialog boxes |
|
219 |
if not hasattr(dialog, 'form'): |
|
220 |
d.form = types.MethodType(_dialog_form, d) |
|
221 |
|
|
184 | 222 |
usage = "Usage: %prog [options] [<input_media>]" |
185 | 223 |
parser = optparse.OptionParser(version=version, usage=usage) |
186 | 224 |
parser.add_option("-l", "--logfile", type="string", dest="logfile", |
Also available in: Unified diff