2

Using Qt and python, I would like to create a window attached to Chrome that moves when I resize my Chrome window. For now, I can attach to the chrome window on start, but I don't know how I could get a move/resize event of the chrome window to adapt the size of main, which is my QMainWindow.

Here's my code:

import win32gui
import sys,os,re,getopt
from PyQt4.QtGui import *
from PyQt4.QtCore import *
import win32com.client

def callback(hwnd, main):
    rect = win32gui.GetWindowRect(hwnd)
    x = rect[0]
    y = rect[1]
    w = rect[2] - x
    h = rect[3] - y
    if w>20 and h>20:
        windowName= win32gui.GetWindowText(hwnd)
        if "- Google" in windowName:
            print "Window %s:" % win32gui.GetWindowText(hwnd)
            print "classname %s:" % win32gui.GetClassName(hwnd)
            print "\tLocation: (%d, %d)" % (x, y)
            print "\t    Size: (%d, %d)" % (w, h)
            main.move(x,y+40)
def main():
    app = QApplication(sys.argv)
    main = QMainWindow(None,Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint)
    main.resize(200,200)
    main.move(400,400)
    qtextedit= QTextEdit(main)
    qtextedit.resize(200,200)
    qtextedit.setPlainText('Hello world')
    qtextedit.setReadOnly(True)
    main.show()
    win32gui.EnumWindows(callback, main)
    sys.exit(app.exec_())


if __name__ == '__main__':
    main()

How does the code work ?

main creates a new QMainWindow, with a qtextedit inside it. Than win32gui.EnumWindows is called, which goes through all open windows. I find the Application I want to attach to with the windowName, that contains "- Google". I than move the main window 40px lower than the main window.

The problem is when I move the chrome window, my window doesn't move with it.

Is it possible to catch a move event of other windows ?

edi9999
  • 19,701
  • 13
  • 88
  • 127
  • This looks promising http://stackoverflow.com/questions/5836176/docking-window-inside-another-window. – Jordan May 16 '15 at 22:36

1 Answers1

0

For now, I will call the EnumWindows function every second, to track the changes, but it isn't really a good solution imo.

edi9999
  • 19,701
  • 13
  • 88
  • 127