Skip to content

Commit

Permalink
ENH: dynamically increasing height of edit to display full output path
Browse files Browse the repository at this point in the history
  • Loading branch information
leloup314 committed Dec 4, 2017
1 parent 9a688db commit 1fd82b4
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions testbeam_analysis/gui/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ def _setup(self):
sl_1 = QtWidgets.QHBoxLayout()
sl_1.addSpacing(h_space)
layout_out = QtWidgets.QVBoxLayout()
self.edit_output = QtWidgets.QTextEdit(self.output_path)
self.edit_output = QtWidgets.QTextEdit()
self.edit_output.setReadOnly(True)
self.edit_output.show()
height = self.edit_output.document().size().height()
self.edit_output.setFixedHeight(height)
self.edit_output.document().contentsChanged.connect(self._set_edit_height)
self.edit_output.setText(self.output_path)
self.edit_output.setLineWrapMode(QtWidgets.QTextEdit.WidgetWidth)
button_out = QtWidgets.QPushButton('Set output folder')
button_out.setToolTip('Set output older')
Expand Down Expand Up @@ -143,6 +143,22 @@ def _setup(self):
layout_widget.addWidget(widget_splitter)
self.setLayout(layout_widget)

def _set_edit_height(self):
"""
Dynamically change size of edit up to 1/3 of self.height
"""

# Set size first
self.edit_output.setFixedHeight(
self.edit_output.document().size().height() +
self.edit_output.contentsMargins().top() +
self.edit_output.contentsMargins().bottom()
)

# Set fixed size if gets too big
if self.edit_output.height() >= self.height() / 3 >= 100: # 100 arbitrary value for first size setting
self.edit_output.setFixedHeight(self.height() / 3)

def _get_output_folder(self):
"""
Get output folder and display path in QTextEdit
Expand Down

0 comments on commit 1fd82b4

Please sign in to comment.