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 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
5 changes: 3 additions & 2 deletions larray_editor/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,12 +339,13 @@ def restore_display_hook():
[ '', 1664780726569649730, -9196963249083393206, -7664327348053294350]])

# test autoresizing
arr8 = la.zeros('a=a_long_label,another_long_label')
arr8 = la.zeros('a=a_long_label,another_long_label; b=this_is_a_label,this_is_another_one')
Copy link
Collaborator

Choose a reason for hiding this comment

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

it would be nice to give meaningful names to those arrays: either what do they test, or what is their "special" characteristic, eg:

>>> test_column_resize1 = la.zeros('a=a_long_label,another_long_label; b=this_is_a_label,this_is_another_one')
>>> # or
>>> long_labels = la.zeros('a=a_long_label,another_long_label; b=this_is_a_label,this_is_another_one')

arr9 = la.zeros('a=a0,a1; long_name_axis=this_is_a_label,this_is_another_one')

# 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,
ses = la.Session(arr2=arr2, arr3=arr3, arr4=arr4, arr5=arr5, arr6=arr6, arr7=arr7, arr8=arr8, arr9=arr9,
data2=data2, data3=data3)

# from larray.tests.common import abspath
Expand Down
30 changes: 25 additions & 5 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.resizeAxesColumnToContents)
self.view_xlabels.horizontalHeader().sectionHandleDoubleClicked.connect(self.resizeDataColumnToContents)
self.view_axes.verticalHeader().sectionHandleDoubleClicked.connect(self.resizeAxesRowToContents)
self.view_ylabels.verticalHeader().sectionHandleDoubleClicked.connect(self.resizeDataRowToContents)

# 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,18 +844,35 @@ 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.resizeAxesColumnToContents(column)
self.view_xlabels.autofit_columns()
for column in range(self.model_xlabels.columnCount()):
self.resizeColumnToContents(column)
self.resizeDataColumnToContents(column)

def resizeColumnToContents(self, column):
def resizeAxesColumnToContents(self, column):
Copy link
Collaborator

Choose a reason for hiding this comment

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

rename to resize_axes_column_to_contents?

# 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 resizeDataColumnToContents(self, column):
Copy link
Collaborator

Choose a reason for hiding this comment

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

rename to resize_xlabels_column_to_contents because this works first on the view_xlabels not view_data?

  • to be consistent with resizeAxes... which works on view_axes
  • to respect python naming conventions (this is not an overridden method name)

# 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 resizeAxesRowToContents(self, row):
Copy link
Collaborator

Choose a reason for hiding this comment

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

rename to resize_axes_row_to_contents?

# 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 resizeDataRowToContents(self, row):
Copy link
Collaborator

Choose a reason for hiding this comment

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

idem

# must be connected to view_labels.verticalHeader().sectionHandleDoubleClicked
height = max(self.view_xlabels.verticalHeader().sectionSize(row),
self.view_data.sizeHintForRow(row))
Expand Down