This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Sublime text toggle menu plugin with ctypes

By: a guest on Mar 24th, 2010  |  syntax: Python  |  size: 1.82 KB  |  views: 245  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. # toggleMenubar plugin v1.0.0
  2. #
  3. # example keybinding:
  4. # <binding key="leftalt+m" command="toggleMenubar"/>
  5. #
  6. # Known issues:
  7. #       menu hidden by fullscreen mode can't be shown again
  8. #       saving any file makes toggleMenubar backup hwnd, hmenu and show
  9.  
  10. import sublime, sublimeplugin, os
  11. from ctypes import *
  12.  
  13. firstRun = 1
  14. show  = 1
  15. hwnd  = windll.User32.GetActiveWindow()
  16. hmenu = windll.User32.GetMenu(hwnd)
  17.  
  18. def loadGlobals():
  19.         if os.path.isfile("toggleMenubar.tmp"):
  20.                 file = open("toggleMenubar.tmp", 'r')
  21.                 try:
  22.                         globals()["hmenu"] = int(file.readline())
  23.                         globals()["hwnd"]  = int(file.readline())
  24.                         globals()["show"]  = int(file.readline())
  25.                 except:
  26.                         pass
  27.                 file.close()
  28.                 os.remove("toggleMenubar.tmp")
  29.         else:
  30.                 globals()["hwnd"]  = windll.User32.GetActiveWindow()
  31.                 globals()["hmenu"]  = windll.User32.GetMenu(globals()["hwnd"])
  32.  
  33. class toggleMenubarCommand(sublimeplugin.TextCommand):
  34.         def run(self, view, args):
  35.                 if globals()["firstRun"]:
  36.                         globals()["firstRun"] = 0
  37.                         globals()["show"]  = 1
  38.                         globals()["hwnd"]  = windll.User32.GetActiveWindow()
  39.                         globals()["hmenu"] = windll.User32.GetMenu(globals()["hwnd"])
  40.  
  41.                 if globals()["hmenu"] == 0 or globals()["hwnd"] == 0:
  42.                         loadGlobals()
  43.  
  44.                 newMenu = windll.User32.GetMenu(hwnd)
  45.                 if newMenu != 0 and newMenu != globals()["hmenu"]:
  46.                         globals()["hmenu"] = newMenu
  47.                
  48.                 if show:
  49.                         windll.User32.SetMenu(globals()["hwnd"], 0)
  50.                         globals()["show"] = 0
  51.                 else:
  52.                         windll.User32.SetMenu(globals()["hwnd"], globals()["hmenu"])
  53.                         globals()["show"] = 1
  54.  
  55. class toggleMenubarSecure(sublimeplugin.Plugin):
  56.         def onPreSave(self, view):
  57.                 file = open("toggleMenubar.tmp", 'w')
  58.  
  59.                 file.write(str(globals()["hmenu"]))
  60.                 file.write("\n")
  61.                
  62.                 file.write(str(globals()["hwnd"]))
  63.                 file.write("\n")
  64.                
  65.                 file.write(str(globals()["show"]))
  66.                 file.close()
clone this paste RAW Paste Data