def flash(ttl): """Flash the caption and taskbar icon""" cur_win = wg.FindWindow(None, ttl) wg.FlashWindowEx(cur_win, wc.FLASHW_STOP, 0, 0) cur_foreground = wg.GetForegroundWindow() if cur_win == cur_foreground: taskbar = wg.FindWindow("Shell_TrayWnd", None) wg.SetForegroundWindow(taskbar) wg.FlashWindowEx(cur_win, wc.FLASHW_ALL | wc.FLASHW_TIMERNOFG, 0, 0)
def flash(self, ttl): 'Flash the caption and taskbar icon' ID = wg.FindWindow(None, ttl) wg.FlashWindowEx(ID, wc.FLASHW_STOP, 0, 0) cur_foreground = wg.GetForegroundWindow() if ID == cur_foreground: taskbar = wg.FindWindow("Shell_TrayWnd", None) wg.SetForegroundWindow(taskbar) wg.FlashWindowEx(ID, wc.FLASHW_ALL | wc.FLASHW_TIMERNOFG, 0, 0)
def _window_enum_callback(self, hwnd, size): """ Method for callback from win32gui.EnumWindows. Used to find the powerpoint presentation window and stop it flashing in the taskbar. """ # Get the size of the current window and if it matches the size of our main display we assume # it is the powerpoint presentation window. (left, top, right, bottom) = win32gui.GetWindowRect(hwnd) window_title = win32gui.GetWindowText(hwnd) log.debug('window size: left={left:d}, top={top:d}, ' 'right={right:d}, bottom={bottom:d}'.format(left=left, top=top, right=right, bottom=bottom)) log.debug( 'compare size: {y:d} and {top:d}, {height:d} and {vertical:d}, ' '{x:d} and {left}, {width:d} and {horizontal:d}'.format( y=size.y(), top=top, height=size.height(), vertical=(bottom - top), x=size.x(), left=left, width=size.width(), horizontal=(right - left))) log.debug('window title: {title}'.format(title=window_title)) filename_root, filename_ext = os.path.splitext( os.path.basename(self.file_path)) if size.y() == top and size.height() == (bottom - top) and size.x() == left and \ size.width() == (right - left) and filename_root in window_title: log.debug('Found a match and will save the handle') self.presentation_hwnd = hwnd # Stop powerpoint from flashing in the taskbar win32gui.FlashWindowEx(self.presentation_hwnd, win32con.FLASHW_STOP, 0, 0)
def unblank_screen(self): """ Unblanks (restores) the presentation. """ log.debug('unblank_screen') try: self.presentation.SlideShowWindow.Activate() self.presentation.SlideShowWindow.View.State = 1 # Unblanking is broken in PowerPoint 2010 (14.0), need to redisplay if 15.0 > float(self.presentation.Application.Version) >= 14.0: self.presentation.SlideShowWindow.View.GotoSlide( self.index_map[self.blank_slide], False) if self.blank_click: self.presentation.SlideShowWindow.View.GotoClick( self.blank_click) except (AttributeError, pywintypes.com_error): log.exception('Caught exception while in unblank_screen') trace_error_handler(log) self.show_error_msg() # Stop powerpoint from flashing in the taskbar if self.presentation_hwnd: win32gui.FlashWindowEx(self.presentation_hwnd, win32con.FLASHW_STOP, 0, 0) # Make sure powerpoint doesn't steal focus, unless we're on a single screen setup if len(ScreenList()) > 1: Registry().get('main_window').activateWindow()
def next_step(self): """ Triggers the next effect of slide on the running presentation. """ log.debug('next_step') # if we are at the presentations end don't go further, just return True if self.presentation.SlideShowWindow.View.GetClickCount() == \ self.presentation.SlideShowWindow.View.GetClickIndex() \ and self.get_slide_number() == self.get_slide_count(): return True past_end = False try: self.presentation.SlideShowWindow.Activate() self.presentation.SlideShowWindow.View.Next() except (AttributeError, pywintypes.com_error): log.exception('Caught exception while in next_step') trace_error_handler(log) self.show_error_msg() return past_end # If for some reason the presentation end was not detected above, this will catch it. if self.get_slide_number() > self.get_slide_count(): log.debug('past end, stepping back to previous') self.previous_step() past_end = True # Stop powerpoint from flashing in the taskbar if self.presentation_hwnd: win32gui.FlashWindowEx(self.presentation_hwnd, win32con.FLASHW_STOP, 0, 0) # Make sure powerpoint doesn't steal focus, unless we're on a single screen setup if len(ScreenList()) > 1: Registry().get('main_window').activateWindow() return past_end
def foreach_window(hwnd, lParam): global foundcount if win32gui.IsWindowVisible(hwnd): title = win32gui.GetWindowText(hwnd).lower() thisdesk = vdesks.GetWindowDesktopNumber(hwnd) if title.find("amazon") != -1 and thisdesk == 0: pid = win32process.GetWindowThreadProcessId(hwnd) if len(pid) <= 2: exe = '' for p in pid: try: count = counters[p] except KeyError: count = 1 if count < 2: try: hndl = win32api.OpenProcess( 0x0400 | 0x0010, False, p) exe = win32process.GetModuleFileNameEx(hndl, False) except: exe = '' if exe == 'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe': foundcount += 1 vdesks.MoveWindowToDesktopNumber(hwnd, 1) win32gui.FlashWindowEx(hwnd, 0, 0, 0) win32gui.ShowWindow(hwnd, 0) titles[p] = hwnd log.info(f'Moving window {title} to desktop #2.') break return True
def flash_window(self, evt=None): # 打印此次提示的时间 self.on_update_note_tc_a( '以上提示发生时间:' + get_current_datetime_str() + '\n----------------------------------------\n\n') win32gui.FlashWindowEx(self.handle, 2, 3, 400)
def run_command(tokens): """Execute a command line (treat internal and external appropriately""" # Cleanup environment for var in pseudo_vars: if var in os.environ.keys(): del os.environ[var] if tokens[0] == 'exit': internal_exit('Bye!') elif tokens[0].lower() == 'cd' and [t for t in tokens if t in sep_tokens ] == []: # This is a single CD command -- use our custom, more handy CD internal_cd([unescape(t) for t in tokens[1:]]) else: if set(sep_tokens).intersection(tokens) == set([]): # This is a simple (non-compound) command # Crude hack so that we return to the prompt when starting GUI # applications: if we think that the first token on the given command # line is an executable, check its PE header to decide whether it's # GUI application. If it is, spawn the process and then get on with # life. cmd = expand_env_vars(tokens[0].strip('"')) dir, name = os.path.split(cmd) ext = os.path.splitext(name)[1] if not ext or ext in exec_extensions: # Executable given app = cmd else: # Not an executable -- search for the associated application if os.path.isfile(cmd): app = associated_application(ext) else: # No application will be spawned if the file doesn't exist app = None if app: executable = full_executable_path(app) if executable and os.path.splitext( executable)[1].lower() == '.exe': # This is an exe file, try to figure out whether it's a GUI # or console application if is_gui_application(executable): import subprocess s = u' '.join([expand_tilde(t) for t in tokens]) subprocess.Popen(s.encode(sys.getfilesystemencoding()), shell=True) return # Regular (external) command start_time = time.time() run_in_cmd(tokens) console_window = win32console.GetConsoleWindow() if win32gui.GetForegroundWindow( ) != console_window and time.time() - start_time > 15: # If the window is inactive, flash after long tasks win32gui.FlashWindowEx(console_window, win32con.FLASHW_ALL, 3, 750)
def flash_taskbar_icon(num_flashes=10): """Flashes the taskbar icon""" global g_current_window if not g_current_window: g_current_window = win32gui.FindWindow('TkTopLevel','EggTimer') if not g_current_window: return win32gui.FlashWindowEx(g_current_window, win32con.FLASHW_ALL | win32con.FLASHW_TIMERNOFG , num_flashes , 0 )
def Flash(self, caption=True, tray=False, until_active=False, continuous=False, times=10, speed=250): """ Flashes the caption or tray button for a duration. :param caption: Flash the caption :type caption: bool :param tray: Flash the tray :type tray: bool :param until_active: Flash until window is activated :type until_active: bool :param continuous: Keep flashing until stopped. To stop the flashing you need to call this method with caption and tray set to False :type continuous: bool :param times: The number of time to flash (not used if until_active or continuous is set) :type times: int :param speed: The duration of time between flashes in milliseconds :type speed: int :return: None :rtype: None """ self.AssertAlive() flag = 0 if until_active: flag |= win32con.FLASHW_TIMERNOFG elif continuous: flag |= win32con.FLASHW_TIMER if tray and caption: flag |= win32con.FLASHW_ALL elif tray: flag |= win32con.FLASHW_TRAY elif caption: flag |= win32con.FLASHW_CAPTION else: flag = win32con.FLASHW_STOP win32gui.FlashWindowEx(self.hwnd, flag, times, speed)
def _window_enum_callback(self, hwnd, size): """ Method for callback from win32gui.EnumWindows. Used to find the powerpoint presentation window and stop it flashing in the taskbar. """ # Get the size of the current window and if it matches the size of our main display we assume # it is the powerpoint presentation window. (left, top, right, bottom) = win32gui.GetWindowRect(hwnd) window_title = win32gui.GetWindowText(hwnd) log.debug('window size: left=%d, top=%d, right=%d, width=%d' % (left, top, right, bottom)) log.debug('compare size: %d and %d, %d and %d, %d and %d, %d and %d' % (size.y(), top, size.height(), (bottom - top), size.x(), left, size.width(), (right - left))) log.debug('window title: %s' % window_title) filename_root, filename_ext = os.path.splitext(os.path.basename(self.file_path)) if size.y() == top and size.height() == (bottom - top) and size.x() == left and \ size.width() == (right - left) and filename_root in window_title: log.debug('Found a match and will save the handle') self.presentation_hwnd = hwnd # Stop powerpoint from flashing in the taskbar win32gui.FlashWindowEx(self.presentation_hwnd, win32con.FLASHW_STOP, 0, 0)
def flash(dwFlags=3, uCount=5, dwTimeout=500): ''' @see http://timgolden.me.uk/pywin32-docs/win32gui__FlashWindowEx_meth.html flash the window a specified number of times. @param dwFlags integer, Combination of win32con.FLASHW_* flags @param uCount integer, Nbr of times to flash @param dwTimeout integer, Elapsed time between flashes, in milliseconds @more flags: FLASHW_STOP 0000 FLASHW_CAPTION 0001 FLASHW_TRAY 0010 FLASHW_ALL 0011 FLASHW_TIMER 0100 FLASHW_TIMERNOFG 1100 ''' win32gui.FlashWindowEx(hWnd, dwFlags, uCount, dwTimeout)
def next_step(self): """ Triggers the next effect of slide on the running presentation. """ log.debug('next_step') try: self.presentation.SlideShowWindow.Activate() self.presentation.SlideShowWindow.View.Next() except (AttributeError, pywintypes.com_error) as e: log.exception('Caught exception while in next_step') log.exception(e) trace_error_handler(log) self.show_error_msg() return if self.get_slide_number() > self.get_slide_count(): log.debug('past end, stepping back to previous') self.previous_step() # Stop powerpoint from flashing in the taskbar if self.presentation_hwnd: win32gui.FlashWindowEx(self.presentation_hwnd, win32con.FLASHW_STOP, 0, 0) # Make sure powerpoint doesn't steal focus, unless we're on a single screen setup if len(ScreenList().screen_list) > 1: Registry().get('main_window').activateWindow()
def flash(): '''任务栏闪烁''' win32gui.FlashWindowEx(hWnd, 0, 1, 1000) return
def FlashWindow(self, evt): win32gui.FlashWindowEx(self.handle, 2, 3, 400)
# encoding=utf-8
def Flash(): taskbar = win32gui.FindWindow("Shell_TrayWnd", None) win32gui.SetForegroundWindow(taskbar) win32gui.FlashWindowEx(ID, win32con.FLASHW_ALL | win32con.FLASHW_TIMERNOFG, 0, 0)
def StopFlash(): win32gui.FlashWindowEx(ID, win32con.FLASHW_STOP, 0, 0)
# encoding=utf-8
def OnTimer(self, evt): """ 定时器响应函数 :return: """ win32gui.FlashWindowEx(self.GetHandle(), 2, 3, 400)