Skip to content

fix #43 (autoresize) #81

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 4 additions & 3 deletions larray_editor/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,13 +339,14 @@ def restore_display_hook():
[ '', 1664780726569649730, -9196963249083393206, -7664327348053294350]])

# test autoresizing
arr8 = la.zeros('a=a_long_label,another_long_label')
long_labels = la.zeros('a=a_long_label,another_long_label; b=this_is_a_label,this_is_another_one')
long_axes_names = la.zeros('first_axis=a0,a1; second_axis=b0,b1')

# compare(arr3, arr4, arr5, arr6)

# view(la.stack((arr3, arr4), la.Axis('arrays=arr3,arr4')))
ses = la.Session(arr2=arr2, arr3=arr3, arr4=arr4, arr5=arr5, arr6=arr6, arr7=arr7, arr8=arr8,
data2=data2, data3=data3)
ses = la.Session(arr2=arr2, arr3=arr3, arr4=arr4, arr5=arr5, arr6=arr6, arr7=arr7, long_labels=long_labels,
long_axes_names=long_axes_names, data2=data2, data3=data3)

# from larray.tests.common import abspath
# file = abspath('test_session.xlsx')
Expand Down
32 changes: 26 additions & 6 deletions larray_editor/arraywidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,8 +537,10 @@ def __init__(self, parent, data, readonly=False, bg_value=None, bg_gradient=None
self.view_xlabels.horizontalHeader().sectionResized.connect(self.view_data.updateSectionWidth)
self.view_ylabels.verticalHeader().sectionResized.connect(self.view_data.updateSectionHeight)
# Synchronize auto-resizing
self.view_xlabels.horizontalHeader().sectionHandleDoubleClicked.connect(self.resizeColumnToContents)
self.view_ylabels.verticalHeader().sectionHandleDoubleClicked.connect(self.resizeRowToContents)
self.view_axes.horizontalHeader().sectionHandleDoubleClicked.connect(self.resize_axes_column_to_contents)
self.view_xlabels.horizontalHeader().sectionHandleDoubleClicked.connect(self.resize_xlabels_column_to_contents)
self.view_axes.verticalHeader().sectionHandleDoubleClicked.connect(self.resize_axes_row_to_contents)
self.view_ylabels.verticalHeader().sectionHandleDoubleClicked.connect(self.resize_ylabels_row_to_contents)

# synchronize specific methods
self.view_axes.allSelected.connect(self.view_data.selectAll)
Expand Down Expand Up @@ -718,6 +720,7 @@ def set_data(self, data, bg_gradient=None, bg_value=None):
self.data_adapter.update_filtered_data({})

# reset default size
self.view_axes.set_default_size()
self.view_ylabels.set_default_size()
self.view_xlabels.set_default_size()
self.view_data.set_default_size()
Expand Down Expand Up @@ -841,20 +844,37 @@ def _data_digits(self, data, maxdigits=6):
return maxdigits

def autofit_columns(self):
self.view_axes.autofit_columns()
for column in range(self.model_axes.columnCount()):
self.resize_axes_column_to_contents(column)
self.view_xlabels.autofit_columns()
for column in range(self.model_xlabels.columnCount()):
self.resizeColumnToContents(column)
self.resize_xlabels_column_to_contents(column)

def resizeColumnToContents(self, column):
def resize_axes_column_to_contents(self, column):
# must be connected to view_axes.horizontalHeader().sectionHandleDoubleClicked signal
width = max(self.view_axes.horizontalHeader().sectionSize(column),
self.view_ylabels.sizeHintForColumn(column))
# no need to call resizeSection on view_ylabels (see synchronization lines in init)
self.view_axes.horizontalHeader().resizeSection(column, width)

def resize_xlabels_column_to_contents(self, column):
# must be connected to view_labels.horizontalHeader().sectionHandleDoubleClicked signal
width = max(self.view_xlabels.horizontalHeader().sectionSize(column),
self.view_data.sizeHintForColumn(column))
# no need to call resizeSection on view_data (see synchronization lines in init)
self.view_xlabels.horizontalHeader().resizeSection(column, width)

def resizeRowToContents(self, row):
def resize_axes_row_to_contents(self, row):
# must be connected to view_axes.verticalHeader().sectionHandleDoubleClicked
height = max(self.view_axes.verticalHeader().sectionSize(row),
self.view_xlabels.sizeHintForRow(row))
# no need to call resizeSection on view_xlabels (see synchronization lines in init)
self.view_axes.verticalHeader().resizeSection(row, height)

def resize_ylabels_row_to_contents(self, row):
# must be connected to view_labels.verticalHeader().sectionHandleDoubleClicked
height = max(self.view_xlabels.verticalHeader().sectionSize(row),
height = max(self.view_ylabels.verticalHeader().sectionSize(row),
self.view_data.sizeHintForRow(row))
# no need to call resizeSection on view_data (see synchronization lines in init)
self.view_ylabels.verticalHeader().resizeSection(row, height)
Expand Down