-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add View Options (title and axis titles) to Distributions widget #7302
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
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,8 +5,9 @@ | |
|
|
||
| import numpy as np | ||
|
|
||
| from AnyQt.QtWidgets import QGridLayout, QLabel, QLineEdit, QSizePolicy, QWidget | ||
| from AnyQt.QtCore import Qt | ||
| from AnyQt.QtWidgets import QFrame, QGridLayout, QLabel, QLineEdit, \ | ||
| QSizePolicy, QWidget, QScrollArea | ||
| from AnyQt.QtCore import Qt, QTimer | ||
|
|
||
| from Orange.data import StringVariable, DiscreteVariable, Domain | ||
| from Orange.data.table import Table | ||
|
|
@@ -227,6 +228,8 @@ class Outputs: | |
|
|
||
| want_main_area = False | ||
| buttons_area_orientation = Qt.Vertical | ||
| #: Max pixel height of the rules area before it scrolls instead of | ||
| MAX_RULES_AREA_HEIGHT = 360 | ||
|
|
||
| settingsHandler = DomainContextHandler() | ||
| attribute = ContextSetting(None) | ||
|
|
@@ -269,6 +272,9 @@ def __init__(self): | |
| self.remove_buttons = [] | ||
| #: list of list of QLabel: pairs of labels with counts | ||
| self.counts = [] | ||
| #: bool: set by add_row, tells _refit_rules_area to scroll down | ||
| # once the new row's height has been applied | ||
| self._scroll_to_bottom_pending = False | ||
|
|
||
| gui.lineEdit( | ||
| self.controlArea, self, "class_name", | ||
|
|
@@ -301,9 +307,15 @@ def __init__(self): | |
| rules_box.addWidget(QLabel("Count"), 0, 3, 1, 2) | ||
| self.update_rules() | ||
|
|
||
| widg = QWidget(patternbox) | ||
| self._rules_widget = widg = QWidget() | ||
| widg.setLayout(rules_box) | ||
| patternbox.layout().addWidget(widg) | ||
|
|
||
| self._rules_scroll = scroll = QScrollArea() | ||
| scroll.setWidget(widg) | ||
| scroll.setWidgetResizable(True) | ||
| scroll.setFrameShape(QFrame.NoFrame) | ||
| scroll.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) | ||
| patternbox.layout().addWidget(scroll) | ||
|
|
||
| box = gui.hBox(patternbox) | ||
| gui.rubber(box) | ||
|
|
@@ -331,6 +343,8 @@ def __init__(self): | |
| # TODO: Resizing upon changing the number of rules does not work | ||
|
Contributor
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. Removed the comment. |
||
| self.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Maximum) | ||
|
|
||
|
Contributor
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. Remove the extra blank lines. |
||
|
|
||
|
|
||
| @property | ||
| def active_rules(self): | ||
| """ | ||
|
|
@@ -427,9 +441,33 @@ def _fix_tab_order(): | |
| _remove_line() | ||
| _fix_tab_order() | ||
|
|
||
| QTimer.singleShot(0, self._refit_rules_area) | ||
|
|
||
| def _refit_rules_area(self): | ||
| """Size the rules scroll area to its contents, but never taller than | ||
| MAX_RULES_AREA_HEIGHT (beyond that it scrolls, so the Apply button | ||
| stays on screen), then re-fit the window to its new contents.""" | ||
|
Contributor
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. Remove the docstring. It's not needed for the protected function, besides the name of the function is representative enough. |
||
| content_height = self._rules_widget.sizeHint().height() | ||
| needs_scroll = content_height > self.MAX_RULES_AREA_HEIGHT | ||
| self._rules_scroll.setVerticalScrollBarPolicy( | ||
| Qt.ScrollBarAlwaysOn if needs_scroll else Qt.ScrollBarAlwaysOff) | ||
|
Contributor
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. This line is not needed. The |
||
| self._rules_scroll.setFixedHeight( | ||
| min(content_height, self.MAX_RULES_AREA_HEIGHT)) | ||
| self.adjustSize() | ||
|
|
||
| if self._scroll_to_bottom_pending: | ||
| self._scroll_to_bottom_pending = False | ||
| QTimer.singleShot(0, self._scroll_rules_to_bottom) | ||
|
|
||
| def _scroll_rules_to_bottom(self): | ||
| """Scroll the rules area down so a newly added row is visible.""" | ||
| bar = self._rules_scroll.verticalScrollBar() | ||
| bar.setValue(bar.maximum()) | ||
|
|
||
| def add_row(self): | ||
| """Append a new row at the end.""" | ||
| self.active_rules.append(["", ""]) | ||
| self._scroll_to_bottom_pending = True | ||
| self.adjust_n_rule_rows() | ||
| self.update_counts() | ||
|
|
||
|
|
||
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.
The comment is incomplete.