]> SALOME platform Git repositories - tools/eficas.git/blob - Editeur/centerwindow.py
Salome HOME
95d9d33b71b21ee409c604230bb90cad95dc27ec
[tools/eficas.git] / Editeur / centerwindow.py
1 """
2    Ce module contient la fonction utilitaire centerwindow
3    qui sert à centrer une fenetre
4 """
5 import types
6
7 def centerwindow(window,parent = 'avec'):
8     if parent =='avec':
9         parent = window.winfo_parent()
10         if type(parent) == types.StringType:
11             parent = window._nametowidget(parent)
12     # Find size of window.
13     window.update_idletasks()
14     width = window.winfo_width()
15     height = window.winfo_height()
16     if width == 1 and height == 1:
17         # If the window has not yet been displayed, its size is
18         # reported as 1x1, so use requested size.
19         width = window.winfo_reqwidth()
20         height = window.winfo_reqheight()
21     # Place in centre of screen:
22     if parent =='avec' :
23         x = (window.winfo_screenwidth() - width) / 2 - parent.winfo_vrootx()
24         y = (window.winfo_screenheight() - height) / 3 - parent.winfo_vrooty()
25     else:
26         x = (window.winfo_screenwidth() - width) / 2 
27         y = (window.winfo_screenheight() - height) / 3
28     if x < 0:
29         x = 0
30     if y < 0:
31         y = 0
32     window.geometry('+%d+%d' % (x, y))
33