Esempio n. 1
0
def reenable_close_window():
    if pywin32_installed:
        try: # reenable console windows close button (useful if called command line or batch file)
            hwnd = win32console.GetConsoleWindow()
            hMenu = win32gui.GetSystemMenu(hwnd, False)
            win32gui.EnableMenuItem(hMenu, win32con.SC_CLOSE, win32con.MF_ENABLED)        
        except: pass #silent
Esempio n. 2
0
 def Enable(self, id, enable=True):
     flags = win32con.MF_BYCOMMAND
     if not enable:
         flags |= win32con.MF_DISABLED
     item = self._menuitems[id]
     win32gui.EnableMenuItem(self.hmenu, item.Id, flags)
     item.Enabled = enable
def EnableTitlebarIcon(hWnd, icon=0, enable=True):
    """
	Greys out titlebar icons
	
	icon - is:
		0 - close icon
		1 - maximize icon
		2 - minimize icon
	
	NOTE: Only works with windows
	NOTE: Only works while mainloop() is running 
		therefore immediately before mainloop() you may want to:
			root.after(50,EnableTitlebarIcon,root.winfo_id(),enable)
	"""
    import win32gui
    SC_MINIMIZE = 0xF020
    SC_MAXIMIZE = 0xF030
    SC_CLOSE = 0xF060
    MF_ENABLED = 0x00000000
    MF_GRAYED = 0x00000001
    MF_DISABLED = 0x00000002
    control = [SC_CLOSE, SC_MAXIMIZE, SC_MINIMIZE][icon]
    while True:
        hMenu = win32gui.GetSystemMenu(hWnd, 0)
        if hMenu != 0:
            break
        parent = win32gui.GetParent(hWnd)
        if parent == 0:
            msg = [
                'ERR: Top-level parent has no system menu.', '',
                'NOTE: Only works while mainloop() is running',
                '	therefore immediately before mainloop() you may want to:',
                '		root.after(50,EnableTitlebarCloseIcon,root.winfo_id(),enable)'
            ]
            raise Exception('\n'.join(msg))
        hWnd = parent
    if enable:
        #print 'enabling',hWnd,hMenu
        win32gui.EnableMenuItem(hMenu, control, MF_ENABLED)
    else:
        #print 'disabling',hWnd,hMenu
        win32gui.EnableMenuItem(hMenu, control, MF_GRAYED)
Esempio n. 4
0
def exit(code):
    # cleanup
    try:
        shutil.rmtree(tempdir)
    except:
        pass  # silent
    if pywin32_installed:
        try:  # reenable console windows close button (useful if called command line or batch file)
            hwnd = win32console.GetConsoleWindow()
            hMenu = win32gui.GetSystemMenu(hwnd, False)
            win32gui.EnableMenuItem(hMenu, win32con.SC_CLOSE,
                                    win32con.MF_ENABLED)
        except:
            pass  #silent
    sys.exit(code)
Esempio n. 5
0
    sys.version_info[1]) + '.' + str(sys.version_info[2])
# sys.platform = [linux2, win32, cygwin, darwin, os2, os2emx, riscos, atheos, freebsd7, freebsd8]
if sys.platform == "win32":
    os.system("title " + Program_name)
    try:
        resourcedir = sys._MEIPASS + slash  # when on PyInstaller
    except:  # in plain python this is where the script was run from
        resourcedir = os.path.abspath(os.path.dirname(sys.argv[0])) + slash
    command = 'attrib'
    parameters = ' +H "' + tempdir[:len(tempdir) - 1] + '"'
    run(command, parameters)  # hide tempdir
    if pywin32_installed:
        try:  # disable console windows close button (substitutes catch shell exit under linux)
            hwnd = win32console.GetConsoleWindow()
            hMenu = win32gui.GetSystemMenu(hwnd, False)
            win32gui.EnableMenuItem(hMenu, win32con.SC_CLOSE,
                                    win32con.MF_GRAYED)
        except:
            pass  #silent
else:
    resourcedir = os.path.abspath(os.path.dirname(sys.argv[0])) + slash
if TK_installed:
    TKwindows = tk.Tk()
    TKwindows.withdraw()  #hiding tkinter window
    TKwindows.update()
    # the following tries to disable showing hidden files/folders under linux
    try:
        TKwindows.tk.call('tk_getOpenFile', '-foobarz')
    except:
        pass
    try:
        TKwindows.tk.call('namespace', 'import', '::tk::dialog::file::')
Esempio n. 6
0
 def restore_close_button():
     win32gui.EnableMenuItem(hMenu, win32con.SC_CLOSE,
                             win32con.MF_BYCOMMAND |
                             win32con.MF_ENABLED)
Esempio n. 7
0
        excepthook.exception = True
        sys.exit(*args, **kwargs)
else:
    exit = sys.exit

if platform.system() == 'Windows':
    import win32console, win32gui, win32con

    hwnd = win32console.GetConsoleWindow()

    if hwnd:
        hMenu = win32gui.GetSystemMenu(hwnd, False)

        if hMenu:
            win32gui.EnableMenuItem(hMenu, win32con.SC_CLOSE,
                                    win32con.MF_BYCOMMAND |
                                    win32con.MF_DISABLED |
                                    win32con.MF_GRAYED)

            def restore_close_button():
                win32gui.EnableMenuItem(hMenu, win32con.SC_CLOSE,
                                        win32con.MF_BYCOMMAND |
                                        win32con.MF_ENABLED)

            atexit.register(restore_close_button)


def extract(data, *keys, default=None):
    for key in keys:
        if not isinstance(data, dict) or key not in data:
            return default
        data = data[key]