Skip to content

Commit fe79c36

Browse files
committed
Wrap dialogs to multiple lines automatically.
Update issue 1405 status: done Implemented on both jython and python. Also added note to docs about wrapping with newline.
1 parent 29b3aa6 commit fe79c36

4 files changed

Lines changed: 22 additions & 8 deletions

File tree

atest/testdata/standard_libraries/dialogs/dialogs.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
*** Settings ***
22
Library Dialogs
33

4+
*** Variable ***
5+
${FILLER} = wrapped${SPACE}
6+
7+
48
*** Test Cases ***
59
Pause Execution
610
Pause Execution Press OK.
711

812
Pause Execution With Long Line
9-
Pause Execution Verify that this pretty long text is displayed nicely. And then press OK.
13+
Pause Execution Verify that the long text below is wrapped nicely.\n\n${FILLER*200}\n\nAnd then press OK.
1014

1115
Pause Execution With Multiple Lines
12-
Pause Execution And verify that\nthis pretty\nlong text\nis displayed\nnicely.\n\nAnd then press OK.
16+
Pause Execution Verify that\nthis multi\nline text\nis displayed\nnicely.\n\nAnd then press OK.
1317

1418
Execute Manual Step Passing
1519
Execute Manual Step Press PASS.

src/robot/libraries/Dialogs.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
dialogs are slightly different depending on are tests run on Python or
2020
Jython but they provide the same functionality.
2121
22+
Long lines in the provided messages are wrapped automatically since
23+
Robot Framework 2.8. If you want to wrap lines manually, you can add
24+
newlines using \\n character sequence.
25+
2226
The library has following two limitations:
2327
- It is not compatible with IronPython.
2428
- It cannot be used with timeouts on Python.

src/robot/libraries/dialogs_jy.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,23 @@ def _get_value(self, pane):
4141
return value if value != UNINITIALIZED_VALUE else None
4242

4343

44+
class WrappedOptionPane(JOptionPane):
45+
46+
def getMaxCharactersPerLineCount(self):
47+
return 120
48+
49+
4450
class MessageDialog(_SwingDialog):
4551

4652
def __init__(self, message):
47-
pane = JOptionPane(message, PLAIN_MESSAGE, DEFAULT_OPTION)
53+
pane = WrappedOptionPane(message, PLAIN_MESSAGE, DEFAULT_OPTION)
4854
_SwingDialog.__init__(self, pane)
4955

5056

5157
class InputDialog(_SwingDialog):
5258

5359
def __init__(self, message, default):
54-
pane = JOptionPane(message, PLAIN_MESSAGE, OK_CANCEL_OPTION)
60+
pane = WrappedOptionPane(message, PLAIN_MESSAGE, OK_CANCEL_OPTION)
5561
pane.setWantsInput(True)
5662
pane.setInitialSelectionValue(default)
5763
_SwingDialog.__init__(self, pane)
@@ -60,7 +66,7 @@ def __init__(self, message, default):
6066
class SelectionDialog(_SwingDialog):
6167

6268
def __init__(self, message, options):
63-
pane = JOptionPane(message, PLAIN_MESSAGE, OK_CANCEL_OPTION)
69+
pane = WrappedOptionPane(message, PLAIN_MESSAGE, OK_CANCEL_OPTION)
6470
pane.setWantsInput(True)
6571
pane.setSelectionValues(options)
6672
_SwingDialog.__init__(self, pane)
@@ -69,8 +75,8 @@ def __init__(self, message, options):
6975
class PassFailDialog(_SwingDialog):
7076

7177
def __init__(self, message):
72-
pane = JOptionPane(message, PLAIN_MESSAGE, YES_NO_OPTION,
73-
None, ['PASS', 'FAIL'], 'PASS')
78+
pane = WrappedOptionPane(message, PLAIN_MESSAGE, YES_NO_OPTION,
79+
None, ['PASS', 'FAIL'], 'PASS')
7480
_SwingDialog.__init__(self, pane)
7581

7682
def _get_value(self, pane):

src/robot/libraries/dialogs_py.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def _bring_to_front(self):
6565

6666
def _create_body(self, message, value):
6767
frame = Frame(self)
68-
Label(frame, text=message, anchor=W, justify=LEFT).pack(fill=BOTH)
68+
Label(frame, text=message, anchor=W, justify=LEFT, wraplength=800).pack(fill=BOTH)
6969
selector = self._create_selector(frame, value)
7070
if selector:
7171
selector.pack(fill=BOTH)

0 commit comments

Comments
 (0)