Skip to content

Commit

Permalink
Merge pull request #223 from robotools/toolbarPriority
Browse files Browse the repository at this point in the history
add support for toolbar priority
  • Loading branch information
typesupply authored Mar 5, 2025
2 parents 25ef265 + e3f5949 commit ca1968c
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion Lib/vanilla/vanillaWindows.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
NSToolbarSizeModeDefault,
NSToolbarSizeModeRegular,
NSToolbarSizeModeSmall,
NSMenu
NSMenu,
NSToolbarItemVisibilityPriorityLow,
NSToolbarItemVisibilityPriorityHigh
)
from objc import python_method
from objc import super
Expand Down Expand Up @@ -771,6 +773,9 @@ def addToolbar(self, toolbarIdentifier, toolbarItems, addStandardItems=True, dis
| | If the item should be added to the toolbar only through the customization |
| | palette, use a value of _False_. Defaults to _True_. |
+---------------------------------+---------------------------------------------------------------------------+
| *priority* (optional) | A `string`, the display priority associated with the toolbar item. |
| | Options are `"high"` or `"low"`. Defaults to *None*. |
+---------------------------------+---------------------------------------------------------------------------+
.. _NSImage: https://developer.apple.com/documentation/appkit/nsimage?language=objc
Expand Down Expand Up @@ -953,6 +958,8 @@ def _createToolbarItem(self, itemData):
imageObject = itemData.get("imageObject")
imageTemplate = itemData.get("imageTemplate")
view = itemData.get("view")
priority = itemData.get("priority")

menuRepresentation = itemData.get("menuRepresentation")
callback = itemData.get("callback", None)
# create the NSImage if needed
Expand Down Expand Up @@ -983,6 +990,10 @@ def _createToolbarItem(self, itemData):
VanillaMenuBuilder(self, [menuRepresentation], dummyMenu)
menuRepresentation = dummyMenu.itemAtIndex_(0)
toolbarItem.setMenuFormRepresentation_(menuRepresentation)
if priority == "low":
toolbarItem.setVisibilityPriority_(NSToolbarItemVisibilityPriorityLow)
elif priority == "high":
toolbarItem.setVisibilityPriority_(NSToolbarItemVisibilityPriorityHigh)
if callback is not None:
target = VanillaCallbackWrapper(callback)
toolbarItem.setTarget_(target)
Expand Down

0 comments on commit ca1968c

Please sign in to comment.