2012-09-23 11 views
5

Come dovrei andare a spostare una finestra creata con PySide usando il window manager?Sposta finestra usando PySide e PyKDE4

Vedo che kdeui ha la classe NETRootInfo con un metodo moveResizeRequest, che fa esattamente quello che voglio. Il seguente:

from PySide.QtCore import Qt 
from PyKDE4 import kdeui 
from PySide.QtGui import QX11Info 
import sys 
from ctypes import CDLL 
Xlib = CDLL('libX11.so.6') 

def move_window(window, event): 
    if event.buttons() & Qt.LeftButton: 
     pos = event.buttonDownScreenPos(Qt.LeftButton) 
     Xlib.XUngrabPointer(QX11Info.display(), QX11Info.appTime()) 
     rootinfo = kdeui.NETRootInfo(QX11Info.display(), kdeui.NET.WMMoveResize) 
     rootinfo.moveResizeRequest(window.winId(), pos.x(), pos.y(), kdeui.NET.Move) 

mi da:

TypeError: NETRootInfo(): arguments did not match any overloaded call: 
    overload 1: argument 1 has unexpected type 'int' 
    overload 2: argument 1 has unexpected type 'int' 
    overload 3: argument 1 has unexpected type 'int' 
    overload 4: argument 1 has unexpected type 'int' 

Questo errore è causato perché QX11Info.display() restituisce una lunga (puntatore), e non una struttura di visualizzazione.

posso usare di QX11Info.display() come primo parametro al costruttore al posto del PySide uno NETRootInfo s', come PyQt4:

... 
from PySide.QtGui import QX11Info 
from PyQt4.QtGui import QX11Info as QX11InfoQt 
... 

def move_window(window, event): 
    if event.buttons() & Qt.LeftButton: 
     pos = event.buttonDownScreenPos(Qt.LeftButton) 
     Xlib.XUngrabPointer(QX11Info.display(), QX11Info.appTime()) 
     rootinfo = kdeui.NETRootInfo(QX11InfoQt.display(), kdeui.NET.WMMoveResize) 
     rootinfo.moveResizeRequest(window.winId(), pos.x(), pos.y(), kdeui.NET.Move) 

Ma questo aggiunge una dipendenza da PyQt4 oltre a PySide.

Inoltre, ho provato a utilizzare la funzione XMoveWindow di Xlib, ma questo impedisce alla finestra di trascinare parzialmente fuori dallo schermo e non fornisce il feedback di spostamento (ad esempio effetti di trasparenza) fornito dai gestori di finestre come Compiz o KWin.

La mia domanda è:

  1. Come posso convertire PySide di QX11Info.display() in un "display" che può essere passato a kdeui.NETRootInfo, o
  2. Come faccio a utilizzare Python e Xlib (sia con python-xlib o tramite libX11.so) per utilizzare un messaggio come _NET_WM_MOVERESIZE per spostare la finestra?
+0

Sicuramente PyKDE4 richiede già PyQt4, quindi non esiste alcuna dipendenza * aggiuntiva * per l'opzione (1). – ekhumoro

+0

Non proprio. PyKDE4 è un wrapper per KDE4. KDE4 richiede il funzionamento di Qt4, ma non ** Py ** Qt4. Il wrapper Python è puramente un wrapper C++ e quindi non ha alcuna dipendenza da PyQt4. –

+0

No. PyKDE è ora mantenuto come parte di KDE, ma ha sempre richiesto sia PyQt che SIP e questo non è cambiato: vedi [qui] (http://www.riverbankcomputing.com/software/pykde/intro) e [qui] (http://techbase.kde.org/Development/Languages/Python) per i dettagli. – ekhumoro

risposta

0

Ho il sospetto che la tua ultima chiamata ha effettivamente firma diversa, forse in questo modo:

moveResizeRequest(<window object>, <int>, <int>, <const>)

mentre si sta cercando di spremere pagina ID (int), invece.

avendo avuto un po 'di esperienza con pygtk (e non con pykde), probabilmente è necessario enumerare tutte le finestre di alto livello in uno schermo dato per ottenere un oggetto di gestione delle finestre.

Allo stesso modo, da C++ KDE docs:

display  An X11 Display struct. 
supportWindow The Window id of the supportWindow. The supportWindow must be created by the window manager as a child of the rootWindow. The supportWindow must not be destroyed until the Window Manager exits. 

mentre si sta cercando di spremere qualche costante in SupportWindow.