Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
snf-image-creator
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
itminedu
snf-image-creator
Commits
a26ae008
Commit
a26ae008
authored
11 years ago
by
Nikos Skalkotos
Browse files
Options
Downloads
Patches
Plain Diff
Monkey-patch pythondialog to support form boxes
parent
121f3bc0
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
image_creator/dialog_main.py
+38
-0
38 additions, 0 deletions
image_creator/dialog_main.py
with
38 additions
and
0 deletions
image_creator/dialog_main.py
+
38
−
0
View file @
a26ae008
...
...
@@ -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
"
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment