Skip to content

Adding HorizontalRule and VerticalRule widgets#3060

Closed
scriptogre wants to merge 2 commits intoTextualize:mainfrom
scriptogre:main
Closed

Adding HorizontalRule and VerticalRule widgets#3060
scriptogre wants to merge 2 commits intoTextualize:mainfrom
scriptogre:main

Conversation

@scriptogre
Copy link
Copy Markdown

@scriptogre scriptogre commented Aug 4, 2023

Status: this PR is stale but close to being finished.

This PR introduces two new widgets, HorizontalRule and VerticalRule, into the Textual library.

I've opted for two distinct classes instead of a single Rule class to improve intuitiveness and readability. A base Rule class encapsulates common functionality, and HorizontalRule and VerticalRule extend from this.

Both widgets are defined in _rule.py, akin to the multi-class file _tabbed_content.py. To work with the widget lazy loading mechanism in widgets/__init__.py, I created _horizontal_rule.py and _vertical_rule.py. I've also updated widgets/__init__.pyi accordingly.

Despite these efforts, I'm facing import issues in _rules.py when trying to run docs/examples/widgets/rules.py.

Any insights into the potential cause or solutions would be appreciated!

I have not forgotten about documentation and tests, but I wish to solve this issue first.

Related to #2982

Please review the following checklist.

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

- Added a new file `_rules.py` in the `src/textual/widgets` directory to define the base `Rule` widget and the `HorizontalRule` and `VerticalRule` widgets.
- Modified the `__init__.py` and `__init__.pyi` files in the `src/textual/widgets` directory to import and include the `HorizontalRule` and `VerticalRule` widgets.

The purpose of these changes is to provide support for the `HorizontalRule` and `VerticalRule` widgets in the `textual` library. These widgets allow for the creation of horizontal and vertical lines, similar to the `<hr>` HTML tag.

Related to Textualize#2982
@rodrigogiraoserrao
Copy link
Copy Markdown
Contributor

rodrigogiraoserrao commented Aug 8, 2023

Hey Chris, I've gone through your code (only briefly) and I think I found the issue.

If you take your PR as it stands, right now, and if you try to run your file _rules.py or try to import something from it, it will fail.
For example, if you run python -m textual.widgets._rules, it should exit silently.
Instead, it raises an error.

Another thing you can try is adding a if __name__ == "__main__": print("hello world") to the bottom of the file _rules.py and then run python src/textual/widgets/_rules.py and see it will fail with the exact same error.

So, the importing issue you are seeing isn't really an issue with the imports.
If you can fix the problem with the _rules.py file, everything should fall in place.

Spoiler for the issue

The problem is in how you defined Rule.rule_extent with both @abstractmethod and @property. You may want to look into @abstractproperty from the module abc (only for a hint on how to solve your issue, but then don't use it because it's deprecated!)

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.

2 participants