Exemple #1
0
 def _dialogThread(clazz, hDesk, resultObj, backgroundImg, safetyTimeout,
                   frameClass, *frameClassParams, **frameClassNamedParams):
     # keep a link to the current desktop so we can get back
     hDeskInputOld = win32service.OpenInputDesktop(
         0, False, win32con.DESKTOP_SWITCHDESKTOP)
     oldWallpaper = clazz._getDesktopWallpaper()
     try:
         # set the ui desktop of this thread to the new desktop
         # so that our windows go to the right place!
         hDesk.SetThreadDesktop()
         clazz._setDesktopWallpaper('')  # make sure the background is black
         # visually switch to the new desktop
         hDesk.SwitchDesktop()
         try:
             # run the TK dialog
             root = tkinter.Tk()
             app = SysmodalDialog(root, resultObj, backgroundImg,
                                  safetyTimeout, frameClass,
                                  *frameClassParams,
                                  **frameClassNamedParams)
             app.mainloop()
         finally:
             # switch back to the original desktop
             hDeskInputOld.SwitchDesktop()
     finally:
         clazz._setDesktopWallpaper(oldWallpaper)
         # be a good citizen and release our link to the current desktop
         SysmodalBase._closeDesktop(hDeskInputOld)
Exemple #2
0
 def _dialogThread(clazz,
                   hDesk,
                   title,
                   message,
                   mbType,
                   resultObj,
                   backgroundImg=None,
                   safetyTimeout=None):
     # keep a link to the current desktop so we can get back
     hDeskInputOld = win32service.OpenInputDesktop(
         0, False, win32con.DESKTOP_SWITCHDESKTOP)
     try:
         # set the ui desktop of this thread to the new desktop
         # so that our windows go to the right place!
         hDesk.SetThreadDesktop()
         # visually switch to the new desktop
         hDesk.SwitchDesktop()
         try:
             # run the TK dialog
             root = tkinter.Tk()
             app = SysmodalMessageBox(root, title, message, mbType,
                                      resultObj, backgroundImg,
                                      safetyTimeout)
             app.mainloop()
         finally:
             # switch back to the original desktop
             hDeskInputOld.SwitchDesktop()
     finally:
         # be a good citizen and release our link to the current desktop
         SysmodalBase._closeDesktop(hDeskInputOld)
def icon_wndproc(hwnd, msg, wp, lp):
    """Window proc for the tray icons"""
    if lp == win32con.WM_LBUTTONDOWN:
        ## popup menu won't disappear if you don't do this
        win32gui.SetForegroundWindow(hwnd)

        curr_desktop = win32service.OpenInputDesktop(0, True, win32con.MAXIMUM_ALLOWED)
        curr_desktop_name = win32service.GetUserObjectInformation(
            curr_desktop, win32con.UOI_NAME
        )
        winsta = win32service.GetProcessWindowStation()
        desktops = winsta.EnumDesktops()
        m = win32gui.CreatePopupMenu()
        desktop_cnt = len(desktops)
        ## *don't* create an item 0
        for d in range(1, desktop_cnt + 1):
            mf_flags = win32con.MF_STRING
            ## if you switch to winlogon yourself, there's nothing there and you're stuck
            if desktops[d - 1].lower() in ("winlogon", "disconnect"):
                mf_flags = mf_flags | win32con.MF_GRAYED | win32con.MF_DISABLED
            if desktops[d - 1] == curr_desktop_name:
                mf_flags = mf_flags | win32con.MF_CHECKED
            win32gui.AppendMenu(m, mf_flags, d, desktops[d - 1])
        win32gui.AppendMenu(m, win32con.MF_STRING, desktop_cnt + 1, "Create new ...")
        win32gui.AppendMenu(m, win32con.MF_STRING, desktop_cnt + 2, "Exit")

        x, y = win32gui.GetCursorPos()
        d = win32gui.TrackPopupMenu(
            m,
            win32con.TPM_LEFTBUTTON | win32con.TPM_RETURNCMD | win32con.TPM_NONOTIFY,
            x,
            y,
            0,
            hwnd,
            None,
        )
        win32gui.PumpWaitingMessages()
        win32gui.DestroyMenu(m)
        if d == desktop_cnt + 1:  ## Create new
            get_new_desktop_name(hwnd)
        elif d == desktop_cnt + 2:  ## Exit
            win32gui.PostQuitMessage(0)
            win32gui.Shell_NotifyIcon(win32gui.NIM_DELETE, window_info[hwnd])
            del window_info[hwnd]
            origin_desktop.SwitchDesktop()
        elif d > 0:
            hdesk = win32service.OpenDesktop(
                desktops[d - 1], 0, 0, win32con.MAXIMUM_ALLOWED
            )
            hdesk.SwitchDesktop()
        return 0
    else:
        return win32gui.DefWindowProc(hwnd, msg, wp, lp)
Exemple #4
0
def SetInputDesktop():
    global current_desktop_name

    hWinSta0 = win32service.OpenWindowStation("WinSta0", True,
                                              win32con.MAXIMUM_ALLOWED)
    hWinSta0.SetProcessWindowStation()
    hdesk = win32service.OpenInputDesktop(0, True, win32con.MAXIMUM_ALLOWED)

    hdesk_name = GetDesktopName(hdesk).upper()

    print("current desktop : " + hdesk_name)
    if (current_desktop_name == hdesk_name):
        return

    hdesk.SetThreadDesktop()

    print("changed desktop to : " + hdesk_name)
    current_desktop_name = hdesk_name
Exemple #5
0
        if d==desktop_cnt+1:      ## Create new
            get_new_desktop_name(hwnd)
        elif d==desktop_cnt+2:    ## Exit
            win32gui.PostQuitMessage(0)
            win32gui.Shell_NotifyIcon(win32gui.NIM_DELETE, window_info[hwnd])
            del window_info[hwnd]
            origin_desktop.SwitchDesktop()
        elif d>0:
            hdesk=win32service.OpenDesktop(desktops[d-1],0,0,win32con.MAXIMUM_ALLOWED)
            hdesk.SwitchDesktop()
        return 0
    else:
        return win32gui.DefWindowProc(hwnd, msg, wp, lp)

window_info={}
origin_desktop=win32service.OpenInputDesktop(0, True, win32con.MAXIMUM_ALLOWED)
origin_desktop_name=win32service.GetUserObjectInformation(origin_desktop, win32service.UOI_NAME)

hinst=win32api.GetModuleHandle(None)
try:
    hicon=win32gui.LoadIcon(hinst, 1)    ## python.exe and pythonw.exe
except win32gui.error:
    hicon=win32gui.LoadIcon(hinst, 135)  ## pythonwin's icon
id=0

create_desktop(str(origin_desktop_name),0)

## wait for first thread to initialize its icon
while not window_info:
    time.sleep(1)