Skip to content
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

Add DigitDisplay widget #2995

Closed

Conversation

eliasdorneles
Copy link

@eliasdorneles eliasdorneles commented Jul 23, 2023

This supersedes: #2990

Please review the following checklist.

  • Docstrings on all new or modified functions / classes
  • Updated documentation
  • Updated CHANGELOG.md (where appropriate)

@eliasdorneles eliasdorneles changed the title Add digit display Add DigitDisplay widget Jul 23, 2023
@@ -10,7 +10,7 @@ unit-test:

.PHONY: test-snapshot-update
test-snapshot-update:
$(run) pytest --cov-report term-missing --cov=textual tests/ -vv --snapshot-update
$(run) pytest --cov-report term-missing --cov=textual tests/ -vv --snapshot-update $(PYTEST_ARGS)
Copy link
Author

Choose a reason for hiding this comment

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

Note to reviewer: I took the liberty to add this snippet, which let you do things like: make PYTEST_ARGS="-k digit_display" test-snapshot-update while developing.
Let me know if you prefer that I remove this.

@eliasdorneles
Copy link
Author

Screenshot (on Ubuntu - Terminator):

image

There are two example apps:

  • Static examples: textual run docs/examples/widgets/digit_display.py
  • Reactive example, w/ input to try things dynamically: textual run docs/examples/widgets/digit_display_reacting.py

@rodrigogiraoserrao @willmcgugan what do you think?

@eliasdorneles eliasdorneles mentioned this pull request Jul 23, 2023
3 tasks
Copy link
Contributor

@rodrigogiraoserrao rodrigogiraoserrao left a comment

Choose a reason for hiding this comment

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

Excellent work!

I've left some questions, comments, and suggestions in your code.

One general thing I'd like to ask is for docstrings in methods and etc to follow the format you can find elsewhere in the code.

Looking forward to merging this!

docs/examples/widgets/digit_display.py Outdated Show resolved Hide resolved
docs/widgets/digit_display.md Show resolved Hide resolved
docs/widgets/digit_display.md Outdated Show resolved Hide resolved
docs/widgets/digit_display.md Outdated Show resolved Hide resolved
docs/widgets/digit_display.md Outdated Show resolved Hide resolved
src/textual/widgets/_digit_display.py Show resolved Hide resolved
src/textual/widgets/_digit_display.py Outdated Show resolved Hide resolved
src/textual/widgets/_digit_display.py Outdated Show resolved Hide resolved
src/textual/widgets/_digit_display.py Outdated Show resolved Hide resolved
src/textual/widgets/_digit_display.py Outdated Show resolved Hide resolved
@eliasdorneles
Copy link
Author

@rodrigogiraoserrao thanks for the review! I've updated it taking into account your comments, also improved the screenshot of the reactive example by adding a few keys pressed =)

Copy link
Contributor

@rodrigogiraoserrao rodrigogiraoserrao left a comment

Choose a reason for hiding this comment

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

It's looking good to me.

You left two of my comments without a response; I'm not sure if it is because you disagree (which is fine, please argue against me) or if you just missed them.

@willmcgugan will take a look and then we'll get back to you :)

@eliasdorneles
Copy link
Author

You left two of my comments without a response; I'm not sure if it is because you disagree (which is fine, please argue against me) or if you just missed them.

Oops, i think i missed them, lemme check again!
I didn't do "resolve conversation" cause i didn't want to forget anything, but clearly i got lost 😅

@eliasdorneles
Copy link
Author

Updated, I think I got everything now, lemme know if there is still something missing.

}
"""

def __init__(self, initial_value=" ", **kwargs):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Typing please.

}
"""

def __init__(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Docstring por favor

}


class _SingleDigitDisplay(Static):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Docstring please (we like them for private classes also).

}


class _SingleDigitDisplay(Static):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Cat you add get_content_width and get_content_height methods. This allows "auto" dimensions pick a more optimal code path. There should be plenty of examples in other widgets...

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the review!
I've updated following up to your other comments, and added an implementation of the methods you mention here.
I'm not sure how best to test the "auto dimensions" thing you mention, can you have a look?

Copy link
Author

Choose a reason for hiding this comment

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

Hello @willmcgugan 👋
Were you able to have a look at this?

Copy link
Collaborator

Choose a reason for hiding this comment

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

If you set your widget to width: auto; and height: auto it should call get_content_width etc.

@eliasdorneles
Copy link
Author

Just rebased, to be synced w/ latest code.

Copy link
Collaborator

@willmcgugan willmcgugan left a comment

Choose a reason for hiding this comment

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

Just a comment for now. This is looking good! :)

A little swamped, will test soon.

self.update(content)

def get_content_width(self, container: Size, viewport: Size) -> int:
return self._content_width
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are all the digits not the same size? If so, could we just return 3 here?

Copy link
Author

Choose a reason for hiding this comment

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

I was trying to make the dot and comma to change width to 2, but in the end it's simpler to have every digit the same size indeed 👍
Lemme update this!

Copy link
Author

Choose a reason for hiding this comment

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

updated!

@willmcgugan
Copy link
Collaborator

Hi @eliasdorneles

Thanks for your work on this! We've decided to go with a slightly different implementation here (#3073).

It's not a reflection on your work (which is excellent) -- we've taken a different approach to the design. We used this PR as inspiration...

Thanks for joining in the sprint!

Will

@eliasdorneles
Copy link
Author

Hi @willmcgugan,

No worries, I understand.

I admit I do feel a bit disappointed that my work hasn't made the cut. At the same time, it's very interesting for me to see the differences between our designs and to learn from yours. 🤓

Anyway, I've got some experience working on open source projects, enough to understand your position, I know that it's important for a maintainer to know how to say no. You did that gently and kindly, thank you for that! 💜

Have a good day and keep up the great work! ☀️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants