Window Minimizer for Usability
From ICELabWiki
[edit] Required Files
If you are missing an MFC DLL file, follow this link: http://python.net/crew/mhammond/win32/
[edit] Code
Use (and modify) the following script to get unwanted windows out of the way. You may minimize or totally hide windows depending on which function you call.
# AG-minimizer.py
# Code by Keith Simmons
# http://ITartist.com
# Created 10/08/2007
# * Updated 10/16/2007: Added sleep argument (first command line argument in seconds)
# * Added RAT on top function which also disables RAT (X) button
# Adapted from http://mail.python.org/pipermail/python-list/2007-May/440884.html
import time
import sys
from win32gui import GetWindowText, EnumWindows, ShowWindow, EnumWindows, GetClassName, EnumChildWindows, SetWindowPos, EnableMenuItem, GetSystemMenu, DrawMenuBar
from win32con import SW_MINIMIZE, SW_HIDE, SW_SHOW, HWND_TOPMOST, SWP_NOMOVE, SWP_NOSIZE, SC_CLOSE, MF_GRAYED, MF_BYPOSITION
from win32ui import CreateWindowFromHandle, MessageBox
def toplevelWindows(a_title_str):
res = []
def callback(hwnd, arg):
name = GetClassName(hwnd)
w = CreateWindowFromHandle(hwnd)
title = w.GetWindowText()
#print name + " ::: " + title
if a_title_str in title: #or name=='PuTTY':
res.append(w)
EnumWindows(callback, 0)
return res
def listWindowsHandles():
res = []
def callback(hwnd, arg):
res.append(hwnd)
EnumWindows(callback, 0)
return res
def listWindowsNames():
return (map(GetWindowText, listWindowsHandles()))
def minimizeWindow(a_Title):
a_hwnd = listWindowsHandles()[listWindowsNames().index(a_Title)]
ShowWindow(a_hwnd, SW_SHOW)
ShowWindow(a_hwnd, SW_MINIMIZE)
def permaFloatWindow(a_Title):
a_hwnd = listWindowsHandles()[listWindowsNames().index(a_Title)]
SetWindowPos(a_hwnd, HWND_TOPMOST, 0,0,0,0, SWP_NOMOVE | SWP_NOSIZE)
EnableMenuItem(GetSystemMenu(a_hwnd, 0), SC_CLOSE, MF_GRAYED)
#EnableMenuItem(GetSystemMenu(a_hwnd, 0), 6, MF_BYPOSITION | MF_GRAYED)
def hideWindow(a_Title):
a_hwnd = listWindowsHandles()[listWindowsNames().index(a_Title)]
ShowWindow(a_hwnd, SW_HIDE)
def cleanUpWindows():
winList = toplevelWindows("STREAM") # Windows with STREAM in title
for hwnd in winList:
minimizeWindow(hwnd.GetWindowText())
#hideWindow(hwnd.GetWindowText())
#print hwnd.GetWindowText()
def ratOnTop():
winList = toplevelWindows("RAT") # Windows with RAT in title
for hwnd in winList:
permaFloatWindow(hwnd.GetWindowText())
#hideWindow(hwnd.GetWindowText())
#print hwnd.GetWindowText()
def hideFirstDVTS():
winList = toplevelWindows("DVTS")
minimizeWindow(winList[0].GetWindowText())
#hideWindow(winList[0].GetWindowText())
if ( len(sys.argv) > 1 ):
time.sleep (float(sys.argv[1]))
ratOnTop()
cleanUpWindows()
hideFirstDVTS()

