OpenSecurity/bin/ui/password_dialog.py
changeset 232 56120b285fc8
parent 134 f1c1c06c947d
child 236 8bfcfd4dd6ad
     1.1 --- a/OpenSecurity/bin/ui/password_dialog.py	Tue Apr 29 13:00:46 2014 +0200
     1.2 +++ b/OpenSecurity/bin/ui/password_dialog.py	Thu Oct 02 13:18:22 2014 +0200
     1.3 @@ -34,6 +34,11 @@
     1.4  
     1.5  import sys
     1.6  
     1.7 +if sys.platform == 'win32' or sys.platform == 'cygwin':
     1.8 +    import win32api
     1.9 +    import win32con
    1.10 +    import win32gui
    1.11 +
    1.12  from PyQt4 import QtCore
    1.13  from PyQt4 import QtGui
    1.14  
    1.15 @@ -70,6 +75,12 @@
    1.16          screen = QtGui.QDesktopWidget().screenGeometry()
    1.17          size = self.geometry()
    1.18          self.move((screen.width() - size.width()) / 2, (screen.height() - size.height()) / 2)
    1.19 +
    1.20 +        t = QtCore.QTimer(self)
    1.21 +        t.timeout.connect(self.force_foreground)
    1.22 +        t.setInterval(0)
    1.23 +        t.setSingleShot(True)
    1.24 +        t.start()
    1.25   
    1.26  
    1.27      def clicked_about(self):
    1.28 @@ -89,6 +100,17 @@
    1.29          self.accept()
    1.30  
    1.31  
    1.32 +    def force_foreground(self):
    1.33 +
    1.34 +        """Force ourselves into foreground"""
    1.35 +        if sys.platform == 'win32' or sys.platform == 'cygwin':
    1.36 +            w = self
    1.37 +            while not w.nativeParentWidget() is None:
    1.38 +                w = w.nativeParentWidget()
    1.39 +            win32gui.BringWindowToTop(int(w.effectiveWinId()))
    1.40 +            win32gui.SetForegroundWindow(int(w.effectiveWinId()))
    1.41 +
    1.42 +
    1.43      def set_user_text(user_text):
    1.44  
    1.45          """Set a text to explain which password we need."""
    1.46 @@ -96,8 +118,11 @@
    1.47  
    1.48  
    1.49  if __name__ == "__main__":
    1.50 +    if sys.platform == 'win32' or sys.platform == 'cygwin':
    1.51 +        win32gui.SystemParametersInfo(win32con.SPI_SETFOREGROUNDLOCKTIMEOUT, 0, win32con.SPIF_SENDWININICHANGE | win32con.SPIF_UPDATEINIFILE)
    1.52      a = QtGui.QApplication(sys.argv)
    1.53      d = PasswordDialog()
    1.54 +    d.setWindowModality(QtCore.Qt.ApplicationModal)
    1.55      d.show()
    1.56      sys.exit(a.exec_())     
    1.57