Skip to content

Conversation

@Touzen
Copy link

@Touzen Touzen commented Apr 30, 2025

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.bullet property to a BulletStyle.

BulletStyle is introduced in pptx.util and, as the name implies, is the class that is passed to set the bullet style.

  • BulletStyle.NO_BULLET explicitly 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.DEFAULT removes 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_STYLE in pptx.enum.text and are taken from: https://learn.microsoft.com/en-us/office/vba/api/office.msonumberedbulletstyle

I 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 be u"\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.

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.

1 participant