From ec010f29e80277471144d41f5f5b7f75c189486d Mon Sep 17 00:00:00 2001 From: beville Date: Tue, 5 Feb 2013 05:14:26 +0000 Subject: [PATCH] Center progress dialogs on update to keep from drifting due to growth git-svn-id: http://comictagger.googlecode.com/svn/trunk@423 6c5673fe-1810-88d6-992b-cd32ca31540c --- fileselectionlist.py | 1 + taggerwindow.py | 4 ++++ utils.py | 18 +++++++++++++++++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/fileselectionlist.py b/fileselectionlist.py index 1304d38..a00d190 100644 --- a/fileselectionlist.py +++ b/fileselectionlist.py @@ -189,6 +189,7 @@ class FileSelectionList(QWidget): break progdialog.setValue(idx) progdialog.setLabelText(f) + utils.centerWindowOnScreen( progdialog ) QCoreApplication.processEvents() row = self.addPathItem( f ) if firstAdded is None and row is not None: diff --git a/taggerwindow.py b/taggerwindow.py index f6ddff4..92a7f4c 100644 --- a/taggerwindow.py +++ b/taggerwindow.py @@ -392,6 +392,7 @@ class TaggerWindow( QtGui.QMainWindow): progdialog.setValue(prog_idx) prog_idx += 1 progdialog.setLabelText( ca.path ) + utils.centerWindowOnScreen( progdialog ) QtCore.QCoreApplication.processEvents() original_path = os.path.abspath( ca.path ) @@ -1392,6 +1393,7 @@ class TaggerWindow( QtGui.QMainWindow): progdialog.setValue(prog_idx) prog_idx += 1 progdialog.setLabelText( ca.path ) + utils.centerWindowOnScreen( progdialog ) QtCore.QCoreApplication.processEvents() if ca.hasMetadata( style ) and ca.isWritable(): @@ -1468,6 +1470,7 @@ class TaggerWindow( QtGui.QMainWindow): progdialog.setValue(prog_idx) prog_idx += 1 progdialog.setLabelText( ca.path ) + utils.centerWindowOnScreen( progdialog ) QtCore.QCoreApplication.processEvents() if ca.hasMetadata( src_style ) and ca.isWritable(): @@ -1667,6 +1670,7 @@ class TaggerWindow( QtGui.QMainWindow): self.atprogdialog.progressBar.setValue( prog_idx ) prog_idx += 1 self.atprogdialog.label.setText( ca.path ) + utils.centerWindowOnScreen( self.atprogdialog ) QtCore.QCoreApplication.processEvents() if ca.isWritable(): diff --git a/utils.py b/utils.py index e1c558a..c3db48e 100644 --- a/utils.py +++ b/utils.py @@ -532,5 +532,21 @@ if qt_available: f = widget.font() if f.pointSize() > 10: f.setPointSize( f.pointSize() - delta ) - widget.setFont( f ) + widget.setFont( f ) + + def centerWindowOnScreen( window ): + """ + Center the window on screen. This implemention will handle the window + being resized or the screen resolution changing. + """ + # Get the current screens' dimensions... + screen = QtGui.QDesktopWidget().screenGeometry() + # ... and get this windows' dimensions + mysize = window.geometry() + # The horizontal position is calulated as screenwidth - windowwidth /2 + hpos = ( screen.width() - window.width() ) / 2 + # And vertical position the same, but with the height dimensions + vpos = ( screen.height() - window.height() ) / 2 + # And the move call repositions the window + window.move(hpos, vpos)