Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Console Interpreter: Changed how console splitter size are reused on show #3016

Merged
merged 3 commits into from
Apr 6, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 42 additions & 4 deletions openpype/modules/python_console_interpreter/window/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,8 @@ def __init__(self, parent=None):

self._append_lines([openpype_art])

self.setStyleSheet(load_stylesheet())
self._first_show = True
self._splitter_size_ratio = None

self._init_from_registry()

Expand All @@ -416,9 +417,9 @@ def _init_from_registry(self):
self.resize(width, height)

try:
sizes = setting_registry.get_item("splitter_sizes")
if len(sizes) == len(self._widgets_splitter.sizes()):
self._widgets_splitter.setSizes(sizes)
self._splitter_size_ratio = (
setting_registry.get_item("splitter_sizes")
)

except ValueError:
pass
Expand Down Expand Up @@ -627,8 +628,45 @@ def add_tab(self, tab_name, index=None):
def showEvent(self, event):
self._line_check_timer.start()
super(PythonInterpreterWidget, self).showEvent(event)
# First show setup
if self._first_show:
self._first_show = False
self._on_first_show()

self._output_widget.scroll_to_bottom()

def _on_first_show(self):
# Change stylesheet
self.setStyleSheet(load_stylesheet())
# Check if splitter size raio is set
iLLiCiTiT marked this conversation as resolved.
Show resolved Hide resolved
# - first store value to local variable and then unset it
splitter_size_ratio = self._splitter_size_ratio
self._splitter_size_ratio = None
Comment on lines +643 to +644
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does seem weird that we're storing this value to self just so it's used this one time on first show and only then. I understand the init_from_registry() takes all settings from registry but nonetheless this feels odd.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does seem weird that we're storing this value to self just so it's used this one time on first show and only then.

I agree but at the same time loading the data from registry twice is weirder. Since splitter sizes must be set after show and window resize must happen before show, it's just decision.

# Skip if is not set
if not splitter_size_ratio:
return

# Skip if number of size items does not match to splitter
splitters_count = len(self._widgets_splitter.sizes())
if len(splitter_size_ratio) != splitters_count:
return

# Don't use absolute sizes but ratio of last stored sizes
ratio_sum = sum(splitter_size_ratio)
sizes = []
max_size = self._widgets_splitter.height()
cur_size = 0
ratio = max_size / ratio_sum
for size in splitter_size_ratio:
item_size = int(ratio * size)
cur_size += item_size
if cur_size > max_size:
item_size -= cur_size - max_size
if not item_size:
item_size = 1
iLLiCiTiT marked this conversation as resolved.
Show resolved Hide resolved
sizes.append(item_size)
self._widgets_splitter.setSizes(sizes)

def closeEvent(self, event):
self.save_registry()
super(PythonInterpreterWidget, self).closeEvent(event)
Expand Down