1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| #!/usr/bin/python
# -*- coding: utf-8 -*-
from __future__ import division
# Python 2.7
import sys, os
from PyQt4 import QtCore, QtGui
#############################################################################
class Fenetre(QtGui.QWidget):
def __init__(self, parent=None):
super(Fenetre, self).__init__(parent)
self.setWindowTitle(u"test")
self.resize(400, 300)
# calcul des dimensions disponibles de l'écran courant
self.screen = QtGui.QDesktopWidget().availableGeometry()
self.wscreen, self.hscreen = self.screen.width(), self.screen.height()
def moveEvent(self, xyold):
# nouvelle position de la fenêtre
x, y = self.x(), self.y()
# taille courante de la fenêtre
wfen, hfen = self.width(), self.height()
# repositionnement si la position est hors limite
if x<0:
self.hide(); self.move(0, y); self.show()
if y<0:
self.hide(); self.move(x, 0); self.show()
if x>self.wscreen-wfen:
self.hide(); self.move(self.wscreen-wfen-1, y); self.show()
if y>self.hscreen-hfen:
self.hide(); self.move(x, self.hscreen-hfen-1); self.show()
#############################################################################
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
fen = Fenetre()
fen.show()
sys.exit(app.exec_()) |
Partager