def get_screen_position_and_size(window_handles): """Return screen position; X, Y and size; width, height. Parameters ---------- window_handles: list of handles to open window figures (Note: only needed the first time) Returns -------- X : coordinate of the left side of the screen. Y : coordinate of the top of the screen. width : screen horizontal size height : screen vertical size """ # pylint: disable=global-statement global _SCREENSIZE if _SCREENSIZE is None: window_handle = window_handles[0] pos = get_window_position_and_size(window_handle) _show_windows((window_handle,), win32con.SW_SHOWMAXIMIZED) _SCREENSIZE = get_window_position_and_size(window_handle) MoveWindow(window_handle, pos[0], pos[1], pos[2], pos[3], 1) return _SCREENSIZE
def move(gui, win, ctrl, x, y, cx, cy): spare_height = cy - ctrl.fixed_height for section in ctrl.fields: if not isinstance(section, (Section, Field)): field_height = section.height if not field_height: field_height = spare_height // ctrl.var_heights spare_height += 1 # Distribute division rounding move = gui.controls[type(section)].move move(gui, win, section, 0, y, cx, field_height) y += field_height continue group_top = y y += win.label_height for field in section.fields: if isinstance(field, Field): target = field.field else: target = field if target.height: field_height = max(win.label_height, target.height) label_y = y + (field_height - win.label_height) // 2 else: field_height = spare_height // ctrl.var_heights spare_height += 1 # Distribute rounding from division label_y = y if isinstance(field, Field): label_width = round(80 * win.x_unit) MoveWindow(field.label, 0, label_y, label_width, win.label_height, 1) else: label_width = 0 target_width = cx - label_width move = gui.controls[type(target)].move move(gui, win, target, label_width, y, target_width, field_height) y += field_height y += round(4 * win.y_unit) group_height = y - group_top MoveWindow(section.hwnd, 0, group_top, cx, group_height, 1)
def restore_window_positions(c_db, store_db): _db = dict() for k, v in c_db.items(): if k in store_db: _l, _t, _r, _b, _ = store_db[k] try: MoveWindow(k, _l, _t, _r, _b, True) except pywintypes.error: # intercept and ignore 'access denied' errors pass
def stack(*figure_numbers, **kwds): """Stack figure windows. Parameters ---------- figure_numbers : list of integers or string specifying which figures to stack (default 'all'). kwds : dict with the following keys figs_per_stack : number of figures per stack (default depends on screenheight) Description ----------- STACK stacks all open figure windows on top of eachother with maximum overlap. STACK(FIGS) can be used to specify which figures that should be stacked. Figures are not sorted when specified. Example: -------- >>> import pylab as p >>> import wafo.fig as fig >>> for ix in range(7): ... f = p.figure(ix) >>> fig.stack() # stack all open figures >>> fig.stack(range(1,4), 5, 7) # stack figure 1,2,3,5 and 7 >>> fig.close() See also -------- fig.cycle, fig.keep, fig.maximize, fig.restore, fig.pile, fig.tile """ wnds = find_figure_handles(*figure_numbers) numfigs = len(wnds) if numfigs > 0: screenpos = get_screen_position_and_size(wnds) y_step = 25 x_step = border = 5 figs_per_stack = kwds.get( 'figs_per_stack', int(numpy.fix(0.7 * (screenpos[3] - border) / y_step))) for iy in range(numfigs): pos = get_window_position_and_size(wnds[iy]) # print('[x, y, w, h] = ', pos) ix = iy % figs_per_stack ypos = int(screenpos[1] + ix * y_step + border) xpos = int(screenpos[0] + ix * x_step + border) MoveWindow(wnds[iy], xpos, ypos, pos[2], pos[3], 1) BringWindowToTop(wnds[iy])
def main(): print("Inside main") for hwnd, text, cls in enum_windows(): if IsWindowEnabled(hwnd) and IsWindowVisible(hwnd) and text: if not inside_desktop(hwnd): left, top, right, bottom = GetWindowPlacement(hwnd)[4] width = right - left height = bottom - top (x, y) = GetWindowRect(GetDesktopWindow())[:2] try: MoveWindow(hwnd, x, y, width, height, 1) print ("moved '%s'" % text) except: # Ignore windows we can't move. print("Can't move") pass
def set_size(*figure_numbers, **kwds): """Set size for figure windows. Parameters ---------- figure_numbers : list of integers or string specifying which figures to pile (default 'all'). kwds : dict with the following keys width : height : Description ------------- Set size sets the size of all open figure windows. SET_SIZE(FIGS) can be used to specify which figures that should be resized. Figures are not sorted when specified. Example: -------- >>> import pylab as p >>> import fig >>> for ix in range(7): ... f = p.figure(ix) >>> fig.set_size(7, width=150, height=100) >>> fig.set_size(range(1,4), 5,width=250, height=170) >>> fig.close() See also -------- fig.cycle, fig.keep, fig.maximize, fig.restore, fig.stack, fig.tile """ handles = find_figure_handles(*figure_numbers) numfigs = len(handles) if numfigs > 0: screen_width, screen_height = _get_screen_size(handles) width = kwds.get('width', int(screen_width / 2.5)) height = kwds.get('height', int(screen_height / 2)) new_pos = kwds.get('position', None) pos = new_pos for handle in handles: if not new_pos: pos = get_window_position_and_size(handle) MoveWindow(handle, pos[0], pos[1], width, height, 1) BringWindowToTop(handle)
def pile(*figure_numbers, **kwds): """Pile figure windows. Parameters ---------- figure_numbers : list of integers or string specifying which figures to pile (default 'all'). kwds : dict with the following keys position : width : height : Description ------------- PILE piles all open figure windows on top of eachother with complete overlap. PILE(FIGS) can be used to specify which figures that should be piled. Figures are not sorted when specified. Example: -------- >>> import pylab as p >>> import wafo.fig as fig >>> for ix in range(7): ... f = p.figure(ix) >>> fig.pile() # pile all open figures >>> fig.pile(range(1,4), 5, 7) # pile figure 1,2,3,5 and 7 >>> fig.close() See also -------- fig.cycle, fig.keep, fig.maximize, fig.restore, fig.stack, fig.tile """ wnds = find_figure_handles(*figure_numbers) numfigs = len(wnds) if numfigs > 0: screen_width, screen_height = _get_screen_size(wnds) pos = kwds.get( 'position', (int(screen_width / 5), int(screen_height / 4))) width = kwds.get('width', int(screen_width / 2.5)) height = kwds.get('height', int(screen_height / 2)) for wnd in wnds: MoveWindow(wnd, pos[0], pos[1], width, height, 1) BringWindowToTop(wnd)
def resize_and_keybinds(self): ''' return values: 2 = exit 5 = skip 0 = nothing ''' if (GetWindowText(GetForegroundWindow()) == 'VLC (Direct3D11 output)'): if not self.winsize: MoveWindow(GetForegroundWindow(), 150, 30, 1600, 1000, True) self.winsize = True if keyboard.is_pressed('space'): if self.toggle: self.player.pause() self.toggle = False time.sleep(0.5) else: self.player.play() self.toggle = True time.sleep(0.5) if keyboard.is_pressed('ctrl+d'): self.player.set_time(self.player.get_time() + 60000) time.sleep(0.5) elif keyboard.is_pressed('d'): self.player.set_time(self.player.get_time() + 15000) time.sleep(0.5) if keyboard.is_pressed('ctrl+a'): self.player.set_time(self.player.get_time() - 60000) time.sleep(0.5) elif keyboard.is_pressed('a'): self.player.set_time(self.player.get_time() - 15000) time.sleep(0.5) if keyboard.is_pressed('shift+f'): self.player.toggle_fullscreen() self.fullscreen = not self.fullscreen time.sleep(0.5) if keyboard.is_pressed('y'): return 5 if keyboard.is_pressed('esc'): return 2 return 0 else: time.sleep(1) return 0
def move_window(targ_proc, x, y, relative=False): from win32gui import MoveWindow, GetWindowRect if isinstance(targ_proc, int) or (isinstance(targ_proc, str) and targ_proc.isdigit()): hwnd = get_hwnds_for_pid(int(targ_proc))[0] else: hwnd = get_main_handle(targ_proc) rect = GetWindowRect(hwnd) width = rect[2] - rect[0] height = rect[3] - rect[1] if relative: x += rect[0] y += rect[1] MoveWindow(hwnd, x, y, width, height, True)
def new_window(self, win, parent=None, *, title=None, contents): template = (title, (0, 0, 0, 0), WS_OVERLAPPEDWINDOW) handlers = { WM_INITDIALOG: partial(self.on_init_dialog, win), WM_DESTROY: partial(self.on_destroy, win), WM_CLOSE: partial(self.on_close, win), WM_SIZE: partial(self.on_size, win), WM_COMMAND: partial(self.on_command, win), WM_NOTIFY: partial(self.on_notify, win), } win.contents = contents win.commands = dict() win.id = 1024 if parent: parent = parent.hwnd win.init_exc = None # Tunnel exceptions raised during WM_INITDIALOG try: CreateDialogIndirect(None, (template, ), parent, handlers) if win.init_exc: raise win.init_exc finally: del win.init_exc (left, top, _, _) = GetWindowRect(win.hwnd) width = round(80 * win.x_unit) + round(160 * win.x_unit) height = round(250 * win.y_unit) width += GetSystemMetrics(SM_CXSIZEFRAME) * 2 height += GetSystemMetrics(SM_CYSIZEFRAME) * 2 height += GetSystemMetrics(SM_CYCAPTION) MoveWindow(win.hwnd, left, top, width, height, 0) ShowWindow(win.hwnd, SW_SHOWNORMAL) self.visible.add(win)
def tile(*figure_numbers, **kwds): """Tile figure windows. Parameters ---------- figure_numbers : list of integers or string specifying which figures to tile (default 'all'). kwds : dict with key pairs specifying how many pairs of figures that are tiled at a time Description ----------- TILE places all open figure windows around on the screen with no overlap. TILE(FIGS) can be used to specify which figures that should be tiled. Figures are not sorted when specified. Example: -------- >>> import pylab as p >>> import wafo.fig as fig >>> for ix in range(7): ... f = p.figure(ix) >>> fig.tile() # tile all open figures >>> fig.tile( range(1,4), 5, 7) # tile figure 1,2,3,5 and 7 >>> fig.tile(range(1,11), pairs=2) # tile figure 1 to 10 two at a time >>> fig.tile(range(1,11), pairs=3) # tile figure 1 to 10 three at a time >>> fig.close() See also -------- fig.cycle, fig.keep, fig.maximize, fig.minimize fig.restore, fig.pile, fig.stack """ wnds = find_figure_handles(*figure_numbers) nfigs = len(wnds) # Number of windows. if nfigs > 0: nfigspertile = kwds.get('pairs', nfigs) ceil = numpy.ceil sqrt = numpy.sqrt maximum = numpy.maximum nlayers = int(ceil(nfigs / nfigspertile)) # Number of figures horisontally. nh = maximum(int(ceil(sqrt(nfigspertile))), 2) # Number of figures vertically. nv = maximum(int(ceil(nfigspertile / nh)), 2) screenpos = get_screen_position_and_size(wnds) screen_width, screen_heigth = screenpos[2:4] hspc = 10 # Horisontal space. topspc = 20 # Space above top figure. medspc = 10 # Space between figures. botspc = 20 # Space below bottom figure. figwid = (screen_width - (nh + 1) * hspc) / nh fighgt = (screen_heigth - (topspc + botspc) - (nv - 1) * medspc) / nv figwid = int(numpy.round(figwid)) fighgt = int(numpy.round(fighgt)) idx = 0 for unused_ix in range(nlayers): for row in range(nv): figtop = int(screenpos[1] + topspc + row * (fighgt + medspc)) for col in range(nh): if (row) * nh + col < nfigspertile: if idx < nfigs: figlft = int( screenpos[0] + (col + 1) * hspc + col * figwid) fighnd = wnds[idx] MoveWindow(fighnd, figlft, figtop, figwid, fighgt, 1) # Set position. BringWindowToTop(fighnd) idx += 1
def move(gui, win, ctrl, left, top, width, height): MoveWindow(ctrl.hwnd, left, top, width, height, 1)
def move(gui, win, ctrl, left, top, width, height): left += (width - ctrl.width) // 2 top += (height - ctrl.height) // 2 MoveWindow(ctrl.hwnd, left, top, ctrl.width, ctrl.height, 1)
from win32gui import FindWindow, GetWindowRect, MoveWindow windowNameOne = "1.txt - Notepad" windowNameTwo = "2.txt - Notepad" while True: #Window1 windowHandleOne = FindWindow(None, windowNameOne) windowRectOne = GetWindowRect(windowHandleOne) rectOne = windowRectOne x1 = rectOne[2] #- rect[0] y1 = rectOne[3] #- rect[1] #Window2 #windowHandleTwo = FindWindow(None, windowNameTwo) #windowTwo = GetWindowRect(windowHandleTwo) #rectTwo = windowTwo #x2 = rectTwo[2] #- rect[0] #y2 = rectTwo[3] #- rect[1] hwnd = FindWindow(None, windowNameTwo) MoveWindow(hwnd, x1, y1, 720, 720, True) print(x1,y1)
def resize_client(self, w, h): cx1, cy1, cx2, cy2 = GetClientRect(self.hwnd) wx1, wy1, wx2, wy2 = GetWindowRect(self.hwnd) dx = (wx2 - wx1) - cx2 dy = (wy2 - wy1) - cy2 MoveWindow(self.hwnd, wx1, wy1, w+dx, h+dy, True)
def move_to(self, x, y): MoveWindow(self.hwnd, x, y, self.width, self.height, True)