-
Notifications
You must be signed in to change notification settings - Fork 2
issue 14: Multi dims horizontal labels #63
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
Open
alixdamman
wants to merge
2
commits into
larray-project:master
Choose a base branch
from
alixdamman:multi_dims_xlabels_14
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -125,7 +125,8 @@ class LabelsArrayModel(AbstractArrayModel): | |
font : QFont, optional | ||
Font. Default is `Calibri` with size 11. | ||
""" | ||
def __init__(self, parent=None, data=None, readonly=False, font=None): | ||
def __init__(self, parent=None, data=None, readonly=False, font=None, orientation=Qt.Horizontal): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it turns out to be indeed necessary to differentiate on the orientation (I am unsure about this), then having two different subclasses of LabelsArrayModel depending on the orientation would make things cleaner. |
||
self.orientation = orientation | ||
AbstractArrayModel.__init__(self, parent, data, readonly, font) | ||
self.font.setBold(True) | ||
|
||
|
@@ -136,28 +137,39 @@ def _set_data(self, data, changes=None): | |
QMessageBox.critical(self.dialog, "Error", "Expected list or tuple.") | ||
data = [[]] | ||
self._data = data | ||
self.total_rows = len(data[0]) | ||
self.total_cols = len(data) if self.total_rows > 0 else 0 | ||
if self.orientation == Qt.Horizontal: | ||
self.total_rows = len(data) if self.total_cols > 0 else 0 | ||
self.total_cols = len(data[0]) | ||
else: | ||
self.total_rows = len(data[0]) | ||
self.total_cols = len(data) if self.total_rows > 0 else 0 | ||
self._compute_rows_cols_loaded() | ||
|
||
def flags(self, index): | ||
"""Set editable flag""" | ||
return Qt.ItemIsEnabled | ||
|
||
def get_value(self, index): | ||
i = index.row() | ||
j = index.column() | ||
# we need to inverse column and row because of the way ylabels are generated | ||
return str(self._data[j][i]) | ||
if self.orientation == Qt.Horizontal: | ||
i, j = index.row(), index.column() | ||
else: | ||
i, j = index.column(), index.row() | ||
return str(self._data[i][j]) | ||
|
||
# XXX: I wonder if we shouldn't return a 2D Numpy array of strings? | ||
def get_values(self, left=0, top=0, right=None, bottom=None): | ||
if right is None: | ||
right = self.total_rows | ||
if bottom is None: | ||
bottom = self.total_cols | ||
values = [list(line[left:right]) for line in self._data[top:bottom]] | ||
return values | ||
if self.orientation == Qt.Horizontal: | ||
if right is None: | ||
right = self.total_cols | ||
if bottom is None: | ||
bottom = self.total_rows | ||
return [list(line[left:right]) for line in self._data[top:bottom]] | ||
else: | ||
if right is None: | ||
right = self.total_rows | ||
if bottom is None: | ||
bottom = self.total_cols | ||
return [list(line[top:bottom]) for line in self._data[left:right]] | ||
|
||
def data(self, index, role=Qt.DisplayRole): | ||
# print('data', index.column(), index.row(), self.rowCount(), self.columnCount(), '\n', self._data) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems odd. I would have thought vlabels would get the extra/fake axis instead of hlabels and that the condition would be nb_dims_vlabels == 0, not nb_dims_vlabels > 0???