-
from win32gui import EnumWindows, GetClassName, FindWindow, SetWindowPos, GetDesktopWindow, GetWindowRect
-
import os, time, sys, argparse
-
-
screen = 0
-
tbar = 1
-
paths = ['c:\\', 'c:\\']
-
-
def main():
-
global screen, tbar, paths
-
parser = argparse.ArgumentParser(description='Open 2 explorer side by side. (j2.nete(at)gmail.com)')
-
parser.add_argument('paths', metavar='path', nargs='*', help='The initilize paths of 2 explorer.')
-
parser.add_argument('-s', '--screen', nargs='?', type=int, choices=[-1,0,1], default=0, help='Screen want to show the explorers; -1 is left screen, 0 is default screen, 1 is right screen.')
-
parser.add_argument('-t', '--tbar', nargs='?', type=int, choices=[1,0], default=1, help='Minus taskbar area or not.')
-
args = parser.parse_args(sys.argv[1:])
-
if args.paths : paths = args.paths
-
screen = args.screen
-
tbar = args.tbar
-
-
def enumWindowsProc(hwnd, list):
-
if GetClassName(hwnd) == 'CabinetWClass':
-
list.append(hwnd)
-
-
def getExplorers():
-
list = []
-
EnumWindows(enumWindowsProc, list)
-
return list
-
-
def showWindow(hwnd, size):
-
SetWindowPos(hwnd,-1,size[0],size[1],size[2],size[3],0x40)
-
SetWindowPos(hwnd,-2,size[0],size[1],size[2],size[3],0x40)
-
-
def calcRect(r1, r2):
-
return(r2[1]>r1[0] and r2[1]<r1[1] and r2[1] or r1[0], r2[0]>r1[0] and r2[0]<r1[1] and r2[0] or r1[1])
-
-
def getAllSize():
-
(dl, dt, dr, db) = GetWindowRect(GetDesktopWindow())
-
if tbar:
-
(tl, tt, tr, tb) = GetWindowRect(FindWindow('Shell_traywnd', None))
-
-
(top, bottom) = calcRect((dt, db), (tt, tb))
-
(left, right) = calcRect((dl, dr), (tl, tr))
-
return(left, top, right-left, bottom-top)
-
else:
-
return(dl, dt, dr, db)
-
-
def openExplorer(path):
-
os.system('explorer.exe ' + path)
-
-
if __name__ == "__main__":
-
main()
-
-
wlist = getExplorers()
-
if len(wlist) < 2:
-
if len(wlist) == 0:
-
openExplorer(paths[0])
-
while FindWindow('CabinetWClass',None) != 0:
-
time.sleep(0.2)
-
openExplorer(paths[1])
-
while len(wlist)<2:
-
wlist = getExplorers()
-
time.sleep(0.2)
-
time.sleep(1)
-
-
(x, y, w, h) = getAllSize()
-
x += screen*w
-
-
showWindow(wlist[0],(x,y,w/2,h))
-
showWindow(wlist[1],(x+w/2,y,w/2,h))
-