-
Notifications
You must be signed in to change notification settings - Fork 659
Allow controlling paragraph bullets #1060
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
Touzen
wants to merge
19
commits into
scanny:master
Choose a base branch
from
Touzen:paragraph-bulletstyle
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
Conversation
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
Using ``False`` (but not ``True``), ``None``, and ``MSO_NUMBERED_BULLET_STYLE`` felt a bit messy. ``True`` (as in, use a default bullet) would be nice, but there is currently no way to infer what bullet to use. From my understanding, determining the bullet would requireus to parse the slide master and layout. Setting a "global" default could cause unexpected behaviour, and it is better that users explicitly choose a bullet.
They don't do very much now that the interaction is done by passing `BulletStyle` objects.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Attempt to implement: #100
This change allows the bullet of a paragraph to be controlled. It can be explicitly set to a string, as an entry in a numbered list, or it can be disabled. There is also functionality to set the bullet to the slide's default. Controlling the bullet is done by setting the new
paragraph.bulletproperty to aBulletStyle.BulletStyleis introduced inpptx.utiland, as the name implies, is the class that is passed to set the bullet style.BulletStyle.NO_BULLETexplicitly disables bullets by inserting an<a:buNone />element.BulletStyle.custom(string)sets the bullet to whatever string is passed by created an<a:buChar char="string" />element.BulletStyle.numbered(style)sets the bullet to whatever numbering style is passed by creating an<a:buAutoNum type="style" />element.BulletStyle.DEFAULTremoves any bullet styling from the paragraph and reverts to the default in the slide. This means that any<a:buNone />,<a:buChar />or<a:buAutoNum />elements is removed from the paragraph.The numbered styles are defined in the new enum
MSO_NUMBERED_BULLET_STYLEinpptx.enum.textand are taken from: https://learn.microsoft.com/en-us/office/vba/api/office.msonumberedbulletstyleI have added tests for the new additions and also verified manually that the code works as expected. I have done my best to follow the code style and naming conventions, but some adjustment is most likely needed.
Thoughts on simpler implementations
In #100 , there was an idea to simply toggle the bullet. This can technically be done in this implementation. However, I intentionally did not set a default bullet character. I took inspiration from @zackmdavis (c2e1643) who used
u"\u2022"as the default. but realized that, in some cases, the default bullet will not beu"\u2022". In those cases, we will change the formatting of the slide in an unexpected way. To handle this situation, the user instead needs to explicitly decide what the bullet should be. The default defined for the slide may or may not be a bullet.Initially (up until f88aecb), the bullet was set to
u"\u2022"(as in c2e1643) which will in many cases be the default bullet character. Ideally, one would like to extract information about which bullet style is the default. However, this would involve a lot of new parsing to find the relevant properties.The previous implementation also led to quite messy method signatures, especially if support for numbered bullets should be added. Introducing
BulletStyle, in my opinion, leads to a cleaner interface and can be more extendible if other aspects of bullet styling (fonts, size, etc) are to be added.