Skip to content

Commit

Permalink
Merge pull request certbot#3268 from jsachs/dialog-autosize
Browse files Browse the repository at this point in the history
Set dialog widgets to use autowidgetsize
  • Loading branch information
SwartzCr authored Aug 15, 2016
2 parents 91aaabd + 64012a6 commit ed6b6e2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 19 deletions.
21 changes: 7 additions & 14 deletions certbot/display/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class NcursesDisplay(object):

def __init__(self, width=WIDTH, height=HEIGHT):
super(NcursesDisplay, self).__init__()
self.dialog = dialog.Dialog()
self.dialog = dialog.Dialog(autowidgetsize=True)
assert OK == self.dialog.DIALOG_OK, "What kind of absurdity is this?"
self.width = width
self.height = height
Expand All @@ -102,7 +102,7 @@ def notification(self, message, height=10, pause=False):
:param bool pause: Not applicable to NcursesDisplay
"""
self.dialog.msgbox(message, height, width=self.width)
self.dialog.msgbox(message)

def menu(self, message, choices, ok_label="OK", cancel_label="Cancel",
help_label="", **unused_kwargs):
Expand Down Expand Up @@ -171,11 +171,7 @@ def input(self, message, **unused_kwargs):
`string` - input entered by the user
"""
sections = message.split("\n")
# each section takes at least one line, plus extras if it's longer than self.width
wordlines = [1 + (len(section) / self.width) for section in sections]
height = 6 + sum(wordlines) + len(sections)
return _clean(self.dialog.inputbox(message, width=self.width, height=height))
return self.dialog.inputbox(message)

def yesno(self, message, yes_label="Yes", no_label="No", **unused_kwargs):
"""Display a Yes/No dialog box.
Expand All @@ -192,8 +188,7 @@ def yesno(self, message, yes_label="Yes", no_label="No", **unused_kwargs):
"""
return self.dialog.DIALOG_OK == self.dialog.yesno(
message, self.height, self.width,
yes_label=yes_label, no_label=no_label)
message, yes_label=yes_label, no_label=no_label)

def checklist(self, message, tags, default_status=True, **unused_kwargs):
"""Displays a checklist.
Expand All @@ -211,8 +206,7 @@ def checklist(self, message, tags, default_status=True, **unused_kwargs):
"""
choices = [(tag, "", default_status) for tag in tags]
return _clean(self.dialog.checklist(
message, width=self.width, height=self.height, choices=choices))
return self.dialog.checklist(message, choices=choices)

def directory_select(self, message, **unused_kwargs):
"""Display a directory selection screen.
Expand All @@ -225,9 +219,8 @@ def directory_select(self, message, **unused_kwargs):
"""
root_directory = os.path.abspath(os.sep)
return _clean(self.dialog.dselect(
filepath=root_directory, width=self.width,
height=self.height, help_button=True, title=message))
return self.dialog.dselect(
filepath=root_directory, help_button=True, title=message)


@zope.interface.implementer(interfaces.IDisplay)
Expand Down
7 changes: 2 additions & 5 deletions certbot/tests/display/util_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ def test_yesno(self, mock_yesno):
self.assertTrue(self.displayer.yesno("message"))

mock_yesno.assert_called_with(
"message", display_util.HEIGHT, display_util.WIDTH,
yes_label="Yes", no_label="No")
"message", yes_label="Yes", no_label="No")

@mock.patch("certbot.display.util."
"dialog.Dialog.checklist")
Expand All @@ -121,9 +120,7 @@ def test_checklist(self, mock_checklist):
(TAGS[1], "", True),
(TAGS[2], "", True),
]
mock_checklist.assert_called_with(
"message", width=display_util.WIDTH, height=display_util.HEIGHT,
choices=choices)
mock_checklist.assert_called_with("message", choices=choices)

@mock.patch("certbot.display.util.dialog.Dialog.dselect")
def test_directory_select(self, mock_dselect):
Expand Down

0 comments on commit ed6b6e2

Please sign in to comment.