PySimpleGUI / PySimpleGUI

Python GUIs for Humans! PySimpleGUI is the top-rated Python application development environment. Launched in 2018 and actively developed, maintained, and supported in 2024. Transforms tkinter, Qt, WxPython, and Remi into a simple, intuitive, and fun experience for both hobbyists and expert users.

Home Page:https://www.PySimpleGUI.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Enhancement ] popup enhancement so that titles are fully shown when windows are small

henriquelino opened this issue · comments

Type of Issue (Enhancement, Error, Bug, Question)

Question, maybe an enchancement?


Operating System

All

PySimpleGUI Port (tkinter, Qt, Wx, Web)

tkinter


Versions

Python version (sg.sys.version)

3.9.7

PySimpleGUI Version (sg.__version__)

4.59.0


Your Experience In Months or Years

Years Python programming experience
2

Years Programming experience overall
4

Have used another Python GUI Framework? (tkinter, Qt, etc) (yes/no is fine)
no

Anything else you think would be helpful?
no


Troubleshooting

These items may solve your problem. Please check those you've done by changing - [ ] to - [X]

  • Searched main docs for your problem www.PySimpleGUI.org
  • Looked for Demo Programs that are similar to your goal Demos.PySimpleGUI.org
  • If not tkinter - looked for Demo Programs for specific port
  • For non tkinter - Looked at readme for your specific port if not PySimpleGUI (Qt, WX, Remi)
  • Run your program outside of your debugger (from a command line)
  • Searched through Issues (open and closed) to see if already reported Issues.PySimpleGUI.org
  • Tried using the PySimpleGUI.py file on GitHub. Your problem may have already been fixed but not released

Detailed Description

Firstly, I love psg!

So the thing is: Popups are building a Window with every arg each popup have, it builds it in line ~18634 of PySimpleGUI.py, and Window does have an size(x, y) argument, so not using it in popups are a design choice?

I'm messing around with some popups and if I print something really small, the title bar hides, if I could set the size to be a bit bigger, the popup would look nicer.

I know it's easy to create a popup using the same method as the popup function does, but I was wondering why it does not have the size arg.

Ty!

Code To Duplicate

from PySimpleGUI import popup_ok
popup_ok('Done', title="My app title") # does not show title :(
popup_ok(f'Done\n{"."*50}', title="My app title") # the title shows :)

Screenshot, Sketch, or Drawing

2022_05_02-17h 06m 26s 839ms

2022_05_02-17h 06m 33s 389ms

forcing a size arg in popup function:
image


Watcha Makin?

I'm migrating some popups from pymsgbox to PySimpleGUI popups, and some texts are so small that the popup not shows the title.

IMO, it should be an enhancement.
Most of time, it looks strange for a small popup window with only partial window title shown.

There are a couple of reasons... one is in the docs....

When you've reached the point with Popups that you are thinking of filing a GitHub "Enhancement Issue" to get the Popup call extended to include a new feature that you think would be helpful.... not just to you but others is what you had in mind, right? For the good of others.

Well, don't file that enhancement request. Instead, it's at THIS time that you should immediately turn to the section entitled "Custom Window API Calls - Your First Window". Congratulations, you just graduated and are now an official "GUI Designer".

image

It's meant entirely as a joke and in fun. Not trying to be a jerk about it. Maybe it's time that I re-word it a little... it's been a few years.

The other is...

The other is that I really really don't recommend using the size parm on Windows. I've written about it a number of times. There's a high likelihood of cutting things off.

The docstring for the Window object even warns against this:

        :param size:                                 (width, height) size in pixels for this window. Normally the window is autosized to fit contents, not set to an absolute size by the user. Try not to set this value. You risk, the contents being cut off, etc. Let the layout determine the window size instead

There are some valid uses for size on Windows, but generally speaking, it should be avoided and instead the layout should be padded to get to the size you're after.

Lemme think through how I would like to design a solution to short titles... that's really the problem we're talking about here.

I read somewhere that line_width would force the popup width and the height would be auto-sized with the text, which is not the case today.

How do you feel about line_width forcing the size? I can't find where in code, but seens that filling with empty spaces ' '*50 or tabs '\t'*50 takes no effect on size, that's why I fill with dots '.'*50

edit:
maybe I've found where the '\t' and ' ' are not being used, in line 18588 of PySimpleGUI.py, inside textwrap lib:


# Hardcode the recognized whitespace characters to the US-ASCII
# whitespace characters.  The main reason for doing this is that
# some Unicode spaces (like \u00a0) are non-breaking whitespaces.
_whitespace = '\t\n\x0b\x0c\r '

Line width is a different thing. Adding spaces won't work. I need a little bit of time to think it through. Today's my first day back working a much as possible.

popups are compact on purpose if that's of any help, and the "long title problem" has been known for a while (likely issues open now), I just haven't fully addressed it in popups, particularly since 1 line of code is capable of doing the same thing as a popup frequently.

size is a parameter I definitely don't want to add. It has caused some quite significant problems, especially moving from one OS to another. I know size is popular in tkinter, but it has burned enough people and even examples in published books that use PySimpleGUI, that I don't want to open that door.

If the title of the window is indeed the main problem that we're trying to solve..... would a parameter such as ensure_title_visible=True be a satisfactory / ideal solution?

I also thought about minimum_width_pixels, but this puts some amount of pressure back on the user to calculate. I'm not sure how I'm going to pull it off to be honest, but I typically look first at the API and work out how I want that to look. It's the feature after all... so starting there is the best place when defining a new feature.

I believe ensure_title_visible would be the best, but idk how to accomplish that, maybe counting how many chars in the title and adding a pad for the buttons + icon, but this way aren't you setting the size arg?

image

Would be like: 25+(len(title)*9)+230

idk if the sizes of the letters/icon change with any Windows configuration, but we have to consider that these sizes change with the setup of each other user too.

Sadly, looking deep into the issue, maybe this is too much hassle just to have a title showing in a popup...

Awesome!
image

Glad you like the idea.... I think it's the problem we're trying to solve, so I like to start there.

Don't worry about the how. Me and Jason and Tanay and the internet will figure that part out. If you want to help figure it out, great, but feel no guilt about this, please. You've pointed out a valid thing that has been discussed before. I've simply not provided a fantastic solution (like this one is ;-) )

Your job for the moment is done. Your next task will be to help verify the enhancement if and when I get it done. Keep moving forward with your project. Instead of using the built-in popup call, make your own Window, etc.

OK, all that said.... I would like to call upon the wizard of pixels, the miracle-maker of DPI, @jason990420 to see if he has ideas on how this can be solved. Do you have any ideas Jason on how we can map titlebar title size to pixels or text so that I can pad out the window?

I have no idea to set the window size to fit the title because it's the job of window manager and tkinter do nothing for it.

Maybe be we can set option to use custom title bar in sg.popup, then there will be no issue to fit the title.
Maybe there will be more options for the appearance of custom title bar.

import PySimpleGUI as sg

def popup():
    layout = [[sg.Input(expand_x=True, key="INPUT")],[sg.Button('OK'), sg.Button('Cancel')]]
    window = sg.Window("What's your name ? Please enter your name here",  layout, use_custom_titlebar=True, modal=True)
    event, values = window.read(close=True)
    return values['INPUT'].strip() if event == 'OK' else ''

layout = [[sg.Text("Hello, dear my friend", size=30, key='Friend'), sg.Button("Name")]]
window = sg.Window('Say Hello', layout)

while True:

    event, values = window.read()

    if event == sg.WIN_CLOSED:
        break
    elif event == 'Name':
        name = popup()
        if name:
            window['Friend'].update(f"Hello, dear {name}")

window.close()

image

Thank you for the help!

That does remind me that I have to fix some things with the title on the custom bars. It can get to be HUGE, or it was,. I may have sorta fixed it.

I'll do the best I can given the length of the title. I think "the best we can do" is the best we can do this time around.... but it's better than nothing

image

Line width is a different thing. Adding spaces won't work. I need a little bit of time to think it through. Today's my first day back working a much as possible.

popups are compact on purpose if that's of any help, and the "long title problem" has been known for a while (likely issues open now), I just haven't fully addressed it in popups, particularly since 1 line of code is capable of doing the same thing as a popup frequently.

size is a parameter I definitely don't want to add. It has caused some quite significant problems, especially moving from one OS to another. I know size is popular in tkinter, but it has burned enough people and even examples in published books that use PySimpleGUI, that I don't want to open that door.

I was about to open a new issue, but this comment may be the answer, so I want to confirm: is this the reason the height part of the size parameter in popup_get_text does nothing? The width part works. Just as a reminder, according to the docs, size should be the (width, height) of the InputText Element.

Oh, right! Correct... size is for input element.... I had forgotten the definition of that parm. Thanks for the reminder.

image