From 005c18f775728b27bb120220b8093aa3c260cf4b Mon Sep 17 00:00:00 2001 From: PySimpleGUI Date: Wed, 12 Aug 2020 10:58:09 -0400 Subject: [PATCH 1/2] Support for titles in the taskbar icon --- .../Demo_Titlebar_Custom_Dark_Theme.py | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/DemoPrograms/Demo_Titlebar_Custom_Dark_Theme.py b/DemoPrograms/Demo_Titlebar_Custom_Dark_Theme.py index 0767ca83..68a7af63 100644 --- a/DemoPrograms/Demo_Titlebar_Custom_Dark_Theme.py +++ b/DemoPrograms/Demo_Titlebar_Custom_Dark_Theme.py @@ -23,7 +23,7 @@ import PySimpleGUI as sg # sg.theme_add_new('DarkGrey8', DarkGrey8) -def dummy_window(): +def dummy_minimized_window(title): """ Creates an invisible window that is minimized to the taskbar As soon as something happens to the window, it is closed and the function @@ -31,14 +31,20 @@ def dummy_window(): The FocusIn event is set so that if the user restores the window from the taskbar, then the read wille return, the window will be closed, and the function will return """ - layout = [[sg.T('You will not see this')]] - window = sg.Window('Window Title', layout, finalize=True, alpha_channel=0) + layout = [[sg.T('This is your window with a customized titlebar... you just cannot see it')]] + window = sg.Window(title, layout, finalize=True, alpha_channel=0) window.minimize() window.bind('', '-FOCUS-') window.read(close=True) def title_bar(title): + """ + Creates a "row" that can be added to a layout. This row looks like a titlebar + :param title: The "title" to show in the titlebar + :type title: str + :return: List[sg.Element] + """ bg = sg.theme_input_background_color() return [sg.Col([[sg.T(title, background_color=bg )]], pad=(0, 0), background_color=bg), @@ -47,13 +53,16 @@ def title_bar(title): def main(): sg.theme('DarkGrey8') - layout = [ title_bar('Window Title'), + + title = 'Customized Titlebar Window' + + layout = [ title_bar(title), [sg.T('This is normal window text. The above is the fake "titlebar"')], [sg.T('Input something:')], [sg.Input(key='-IN-'), sg.Text(size=(12,1), key='-OUT-')], [sg.Button('Go')] ] - window = sg.Window('Window Title', layout, resizable=True, no_titlebar=True, grab_anywhere=True, keep_on_top=True, margins=(0,0), finalize=True) + window = sg.Window(title, layout, resizable=True, no_titlebar=True, grab_anywhere=True, keep_on_top=True, margins=(0,0), finalize=True) window['-C-'].expand(True, False, False) @@ -64,7 +73,7 @@ def main(): break if event == '-MINIMIZE-': window.hide() - dummy_window() + dummy_minimized_window(window.Title) window.un_hide() if event == 'Go': window['-OUT-'].update(values['-IN-']) From 7a5cfcd2513a60fd1d1153a19d88f33923593316 Mon Sep 17 00:00:00 2001 From: PySimpleGUI Date: Wed, 12 Aug 2020 11:02:17 -0400 Subject: [PATCH 2/2] Docstrings, comments --- DemoPrograms/Demo_Titlebar_Custom_Dark_Theme.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/DemoPrograms/Demo_Titlebar_Custom_Dark_Theme.py b/DemoPrograms/Demo_Titlebar_Custom_Dark_Theme.py index 68a7af63..f4265707 100644 --- a/DemoPrograms/Demo_Titlebar_Custom_Dark_Theme.py +++ b/DemoPrograms/Demo_Titlebar_Custom_Dark_Theme.py @@ -2,8 +2,9 @@ import PySimpleGUI as sg """ Demo showing how to remove the titlebar and replace with your own - Note that you cannot minimize these kinds of windows because they do not - have an icon representing them on the taskbar + Unlike previous demos that lacked a titlebar, this one provides a way for you + to "minimize" your window that does not have a titlebar. This is done by faking + the window using a hidden window that is minimized. Copyright 2020 PySimpleGUI.org """ @@ -31,6 +32,7 @@ def dummy_minimized_window(title): The FocusIn event is set so that if the user restores the window from the taskbar, then the read wille return, the window will be closed, and the function will return """ + layout = [[sg.T('This is your window with a customized titlebar... you just cannot see it')]] window = sg.Window(title, layout, finalize=True, alpha_channel=0) window.minimize() @@ -43,7 +45,8 @@ def title_bar(title): Creates a "row" that can be added to a layout. This row looks like a titlebar :param title: The "title" to show in the titlebar :type title: str - :return: List[sg.Element] + :return: A list of elements (i.e. a "row" for a layout) + :type: List[sg.Element] """ bg = sg.theme_input_background_color() @@ -64,7 +67,7 @@ def main(): window = sg.Window(title, layout, resizable=True, no_titlebar=True, grab_anywhere=True, keep_on_top=True, margins=(0,0), finalize=True) - window['-C-'].expand(True, False, False) + window['-C-'].expand(True, False, False) # expand the titlebar's rightmost column so that it resizes correctly while True: # Event Loop event, values = window.read() @@ -79,5 +82,6 @@ def main(): window['-OUT-'].update(values['-IN-']) window.close() + if __name__ == '__main__': main()