-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
SelectRows: Add calendar popup for TimeVariables #4800
Conversation
Orange/widgets/data/owselectrows.py
Outdated
@@ -68,7 +67,7 @@ def decode_setting(self, setting, value, domain=None): | |||
op, values = condition[-2:] | |||
|
|||
var = attr in domain and domain[attr] | |||
if var and var.is_continuous and not isinstance(var, TimeVariable): | |||
if var and var.is_continuous: |
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.
Be careful when solving the conflict with #4798: there's no var
but just attr
, and it can be a str
or Variable
, so you probably want something like
if isinstance(attr, ContinuousVariable) \
or isinstance(attr, str) and OWSelectRows.AllTypes.get(attr) == CONTINUOUS
@aturanjanin #4798 is now merged, so please rebase this and I will check. Thanks! :) |
Codecov Report
@@ Coverage Diff @@
## master #4800 +/- ##
==========================================
- Coverage 84.20% 84.14% -0.07%
==========================================
Files 282 277 -5
Lines 57342 56633 -709
==========================================
- Hits 48285 47653 -632
+ Misses 9057 8980 -77 |
@ajdapretnar I've just rebased, could you check if everything looks okay? Thanks! |
I have check this and I have a couple of comments.
|
@janezd We're in a pickle here and need your expert opinion/suggestion. ATM, the widget adds dummy date or time to variables, e.g. 1970-01-01 if data has only hours and 00:00:00 if it has only dates. |
I wonder in what sense am I an expert here? I don't use time variables and I never heard about On the first glance, you would need But I'm just reading the docs and guessing -- which about rounds up my expertise. :) |
@aturanjanin, I added a commit that adds time to the popup. Now I leave to you to actually connect it, that is, set defaults and connect the signals so that date changes when the user changes the numbers. |
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.
A general summary: it is better if child widgets know and assume less about parent. And, in particular, it is up to recepient of the signal to connect to the receiver's signal; making a connection is not a task for sender. Also, as I understand, you sometimes call connect
instead of emit
.
Orange/widgets/data/owselectrows.py
Outdated
self.set_format() | ||
self.setSizePolicy( | ||
QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)) | ||
self.dateTimeChanged.connect(parent._invalidate_dates) |
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.
Not like this. The idea of signals is that the object that needs to be informed about something "subscribes" to the signal. Remove this line and instead connect to the signal when you construct the widget, e.g.
w = DateTimeWidget(self, var_idx, datetime_format)
w.dateTimeChanged.connect(self._invalidate_dates)
As it is now, this widget assumes that the parent has a method _invalidate_dates
(and, besides, it starts with underscore, so it's kind of private). With the signals, method naming is up to parent. And nobody touches its private methods.
Orange/widgets/data/owselectrows.py
Outdated
self.setDate(datetime if datetime else self.min_datetime) | ||
elif not self.have_date and self.have_time: | ||
self.setTime(datetime if datetime else self.min_datetime) | ||
self.dateTimeChanged.connect(self.parent.conditions_changed) |
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.
Did you mean to connect the signal or emit it? I suppose you wanted to do this:
self.dateTimeChanged.emit()
To call (or connect) the proper method is up to the parent widget.
Orange/widgets/data/owselectrows.py
Outdated
self.timeedit.dateTimeChanged.connect(self.set_time) | ||
|
||
def set_time(self): | ||
self.parent.set_datetime(self.parent.date(), self.timeedit.time()) |
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.
Don't call parent's methods. It's better to emit signals and let the parent connect to them. This way, the widget doesn't have to make assumptions about its parent and the parent's methods.
Orange/widgets/data/owselectrows.py
Outdated
sublay.addWidget(self.timeedit) | ||
sublay.addStretch(1) | ||
self.layout().addLayout(sublay) | ||
self.parent = self.parent() |
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.
Don't store the parent. First, it is accessible as self.parent()
. Second, you don't need it if you use signals instead (see below).
Orange/widgets/data/owselectrows.py
Outdated
elif vtype == 3: # string: | ||
box.controls = [add_textual(lc[0])] | ||
if oper in [6, 7]: | ||
gui.widgetLabel(box, " and ") | ||
box.controls.append(add_textual(lc[1])) | ||
elif vtype == 4: # time: | ||
datetime_format = (var.have_date, var.have_time) | ||
w = DateTimeWidget(self, var_idx, datetime_format) |
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.
Here, connect w
's signals to _invalidate_dates
. (See the bottom of the file for a longer comment.)
Orange/widgets/data/owselectrows.py
Outdated
self._box = box | ||
if oper > 5: | ||
gui.widgetLabel(box, " and ") | ||
w_ = DateTimeWidget(self, var_idx, datetime_format) |
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.
Same here.
Orange/widgets/data/owselectrows.py
Outdated
w_ = self._box.controls[1] | ||
if w.dateTime() > w_.dateTime(): | ||
w_.setDateTime(w.dateTime()) | ||
w_.dateTimeChanged.connect(self.conditions_changed) |
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.
Huh, this reconnects the signal at every change?! You wanted to connect the method or to just call it?
Orange/widgets/data/owselectrows.py
Outdated
def __init__(self, parent, col_idx, datetime_format): | ||
QDateTimeEdit.__init__(self, parent) | ||
|
||
self.parent = parent |
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.
If you use signals, you won't need to store self.parent
.
Orange/widgets/data/owselectrows.py
Outdated
self.parent = parent | ||
self.format = datetime_format | ||
self.have_date, self.have_time = datetime_format[0], datetime_format[1] | ||
self.column = parent.data[:, col_idx] |
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.
I'd be happier if column
was passed as an argument, so the widget wouldn't need to assume how the parent stores data.
I apologize for doing it instead of showing you what to do. I just wanted to fix some issues reported by lint. One of them was that attribute However, instead of defining I recommend that you check this code, you may find the trick useful. |
b70c44b
to
5cb0af0
Compare
Orange now crashes (after this PR was merged) when using Select Rows and selecting a Time variable from metas (but not if the time var is a feature or class...). To reproduce: |
It would be better if you wrote this as an issue, we'll ovelook it here. (I'll do it.) |
Issue
Fixes #4676.
Description of changes
Calendar popup added when setting dates for TimeVariables filtering.
Includes