New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SubWindow centered in MainWindow #177

Closed
AbrhmSanchez opened this Issue Jun 8, 2017 · 4 comments

Comments

Projects
None yet
2 participants
@AbrhmSanchez

AbrhmSanchez commented Jun 8, 2017

Could a method be added to locate SubWindows centered to the Main Window? The location defaults to (100,100). Something like this could do the trick:

def setSubWindowCentered(self, title):
    main_win = self.topLevel
    win = self.__verifyItem(self.n_subWindows, title)
    # Find subWindow width and height
    win.update_idletasks()
    width = win.winfo_width()
    frm_width = win.winfo_rootx() - win.winfo_x()
    win_width = width + 2 * frm_width
    height = win.winfo_height()
    titlebar_height = win.winfo_rooty() - win.winfo_y()
    win_height = height + titlebar_height + frm_width
    # Find Main Window width and height (same thing as before)
    m_width = main_win.winfo_width()
    m_frm_width = main_win.winfo_rootx() - main_win.winfo_x()
    m_win_width = m_width + 2 * m_frm_width
    m_height = main_win.winfo_height()
    m_titlebar_height = main_win.winfo_rooty() - main_win.winfo_y()
    m_win_height = m_height + m_titlebar_height + m_frm_width
    # Find x and y centered on the Main Window
    x = main_win.winfo_x() + m_win_width // 2 - win_width // 2
    y = main_win.winfo_y() + m_win_height // 2 - win_height // 2
    win.geometry('+{}+{}'.format(x, y))

Please bear with me as I am a programming noob. I made this based on the static function gui.CENTER(win)

@AbrhmSanchez

This comment has been minimized.

Show comment
Hide comment
@AbrhmSanchez

AbrhmSanchez Jun 8, 2017

Tested it in windows 7. Appears to work well after the subWindow has been shown at least once. It appears a bit off center if the method is called before the first show.

AbrhmSanchez commented Jun 8, 2017

Tested it in windows 7. Appears to work well after the subWindow has been shown at least once. It appears a bit off center if the method is called before the first show.

@jarvisteach jarvisteach self-assigned this Jun 11, 2017

@jarvisteach jarvisteach added this to the 0.08 milestone Jun 11, 2017

@jarvisteach

This comment has been minimized.

Show comment
Hide comment
@jarvisteach

jarvisteach Jun 11, 2017

Owner

FYI, SubWindows have all the same functions as the main window, so there is the option to simply call .setLocation(x, y). Although that won't achieve exactly what you've asked for.

As you mention, the difficulty is finding positions before things have been drawn. Until the main window and SubWindow has been draw, their widths & heights won't have been calculated correctly.

First drawing them & then re-positioning them doesn't give a great user experience.

However, there are functions: winfo_reqwidth() & winfo_reqheight() which allow you to query the expected width & height - these might have better results, and save having to first draw the windows.

I'll add it as something to investigate for the next release.

Owner

jarvisteach commented Jun 11, 2017

FYI, SubWindows have all the same functions as the main window, so there is the option to simply call .setLocation(x, y). Although that won't achieve exactly what you've asked for.

As you mention, the difficulty is finding positions before things have been drawn. Until the main window and SubWindow has been draw, their widths & heights won't have been calculated correctly.

First drawing them & then re-positioning them doesn't give a great user experience.

However, there are functions: winfo_reqwidth() & winfo_reqheight() which allow you to query the expected width & height - these might have better results, and save having to first draw the windows.

I'll add it as something to investigate for the next release.

@AbrhmSanchez

This comment has been minimized.

Show comment
Hide comment
@AbrhmSanchez

AbrhmSanchez Jun 12, 2017

Alright, thought it could be useful. Thanks for the input!

AbrhmSanchez commented Jun 12, 2017

Alright, thought it could be useful. Thanks for the input!

jarvisteach added a commit that referenced this issue Aug 11, 2017

Some work on .setLocation() (#177)
CENTER function is more generic
And used by topLevel & popups

.setLocation()  now can receive the parameter "CENTER" and will center the window using the above function

jarvisteach added a commit that referenced this issue Aug 11, 2017

Changes to TopLevel positioning (#177)
A SubWindow now defaults to being CENTERED.

Modified the num/text dialogs - they now show more smoothly.
@jarvisteach

This comment has been minimized.

Show comment
Hide comment
@jarvisteach

jarvisteach Aug 11, 2017

Owner

Would be useful to have a dialog follow its parent - so, if the main appJar GUI is moved, a SubWindow would be centred over it.

This could also be done for num/text boxes - although the built in dialogs don't support it - so would give different behaviour.

Will raise as a new feature request.

Owner

jarvisteach commented Aug 11, 2017

Would be useful to have a dialog follow its parent - so, if the main appJar GUI is moved, a SubWindow would be centred over it.

This could also be done for num/text boxes - although the built in dialogs don't support it - so would give different behaviour.

Will raise as a new feature request.

jarvisteach added a commit that referenced this issue Jan 27, 2018

tweaking centering #177
take into account user defined position

jarvisteach pushed a commit that referenced this issue Jan 27, 2018

Richard Jarvis
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment