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 26th, 2010  |  syntax: Python  |  size: 1.96 KB  |  views: 139  |  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.2
  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.  
  9. import sublime, sublimeplugin, os
  10. from ctypes import *
  11.  
  12. firstRun = 1
  13. needSave = 1
  14. show  = 1
  15. hwnd  = windll.User32.GetActiveWindow()
  16. hmenu = windll.User32.GetMenu(hwnd)
  17.  
  18.  
  19. def loadGlobals():
  20.         if os.path.isfile(sublime.packagesPath()+"\\User\\toggleMenubar.tmp"):
  21.                 file = open(sublime.packagesPath()+"\\User\\toggleMenubar.tmp", 'r')
  22.                 try:
  23.                         globals()["hmenu"] = int(file.readline())
  24.                         globals()["hwnd"]  = int(file.readline())
  25.                         globals()["show"]  = int(file.readline())
  26.                 except:
  27.                         pass
  28.                 file.close()
  29.                 os.remove("toggleMenubar.tmp")
  30.         else:
  31.                 globals()["hwnd"]  = windll.User32.GetActiveWindow()
  32.                 globals()["hmenu"]  = windll.User32.GetMenu(globals()["hwnd"])
  33.  
  34. class toggleMenubarCommand(sublimeplugin.TextCommand):
  35.         def run(self, view, args):
  36.                 if globals()["firstRun"]:
  37.                         globals()["firstRun"] = 0
  38.                         globals()["show"]  = 1
  39.                         globals()["hwnd"]  = windll.User32.GetActiveWindow()
  40.                         globals()["hmenu"] = windll.User32.GetMenu(globals()["hwnd"])
  41.  
  42.                 if globals()["hmenu"] == 0 or globals()["hwnd"] == 0:
  43.                         loadGlobals()
  44.  
  45.                 newMenu = windll.User32.GetMenu(hwnd)
  46.                 if newMenu != 0 and newMenu != globals()["hmenu"]:
  47.                         globals()["hmenu"] = newMenu
  48.                
  49.                 if show:
  50.                         windll.User32.SetMenu(globals()["hwnd"], 0)
  51.                         globals()["show"] = 0
  52.                 else:
  53.                         windll.User32.SetMenu(globals()["hwnd"], globals()["hmenu"])
  54.                         globals()["show"] = 1
  55.  
  56.                 globals()["needSave"] = 1
  57.                        
  58. class toggleMenubarSecure(sublimeplugin.Plugin):
  59.         def onPreSave(self, view):
  60.                 if globals()["needSave"] == 1:
  61.                         globals()["needSave"] = 0
  62.                         file = open(sublime.packagesPath()+"\\User\\toggleMenubar.tmp", 'w')
  63.  
  64.                         file.write(str(globals()["hmenu"]))
  65.                         file.write("\n")
  66.                
  67.                         file.write(str(globals()["hwnd"]))
  68.                         file.write("\n")
  69.                
  70.                         file.write(str(globals()["show"]))
  71.                         file.close()
clone this paste RAW Paste Data