Guest User

Untitled

a guest
Mar 18th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. # fix the Extentions menu sorting in macOS High Sierra in Robofont 1.8
  2. # (set this up as a start up script and you're good to go)
  3.  
  4. # This is just a hack, you should really check out RoboFont 3
  5.  
  6.  
  7. from AppKit import *
  8. from lib.doodleMenus import BaseMenu
  9.  
  10. # ----------------------------------------
  11.  
  12. def sort_menu_items(menu):
  13. controller = BaseMenu()
  14.  
  15. # collect the different sub parts
  16. parts = []
  17. sub_parts = []
  18. for i in menu.itemArray():
  19. if i.hasSubmenu():
  20. sort_menu_items(i.submenu())
  21. if i.isSeparatorItem():
  22. sub_parts.append(i)
  23. parts.append(sub_parts)
  24. sub_parts = []
  25. else:
  26. sub_parts.append(i)
  27. parts.append(sub_parts)
  28.  
  29. # sort the menu items
  30. sorted_parts = []
  31. for sub_parts in parts:
  32.  
  33. # get the separator out
  34. if len(sub_parts) > 0 and sub_parts[-1].isSeparatorItem():
  35. sep = sub_parts.pop(-1)
  36. else:
  37. sep = None
  38.  
  39. # keep alternates together with their parent when applicable
  40. sub_parts_with_alternates = []
  41. for p in sub_parts:
  42. if not p.isAlternate():
  43. sub_parts_with_alternates.append([p])
  44. else:
  45. sub_parts_with_alternates[-1].append(p)
  46. # sort
  47. sub_parts_with_alternates.sort(key=lambda alts: alts[0].title())
  48. # flatten the [parent, alternate] couples
  49. sub_parts_flat = [item for sublist in sub_parts_with_alternates for item in sublist]
  50.  
  51. # and put the separator back in
  52. if sep:
  53. sub_parts_flat.append(sep)
  54.  
  55. sorted_parts += sub_parts_flat
  56.  
  57. # rebuild the menu
  58. menu.removeAllItems()
  59. controller.buildAdditionContextualMenuItems(menu, sorted_parts)
  60.  
  61. # ----------------------------------------
  62.  
  63. menuBar = NSApp().mainMenu()
  64. ExtMenu = menuBar.itemWithTitle_("Extensions")
  65. menu = ExtMenu.submenu()
  66. sort_menu_items(menu)
Add Comment
Please, Sign In to add comment