11#!/usr/bin/env python3
2- #& DocuPort - PySimpleGUI v2.3.3b
2+
33#! Simple GUI Script to open user-specified chapter of the Online-Documentation for PySimpleGUI.
44#@ =============================== Libraries =============================== @#
55from random import choice as rChoice
@@ -10,24 +10,23 @@ import PySimpleGUI as sg
1010#@ ========================================================================= @#
1111#$ =============================== Functions =============================== $#
1212
13+ __version__ = '2.3.3b'
14+
1315#> Changes the base color layout each time the app is opened.
14- theme : str = rChoice (sg .theme_list ())
15- sg .theme (theme )
16+ rtheme : str = rChoice (sg .theme_list ())
17+ sg .theme (rtheme )
1618
1719
18- def open_PSGUI (title : str , url : str ) -> bool :
20+ def open_PSGUI (url : str ) -> bool :
1921 """Open a specific PySimpleGUI documentation section in the user's default browser.
2022
23+ ---
2124 Parameters
22- :param title: title of the documentation-section selected.
23- :type title: str
2425 :param url: URL of the doc-section to open in user's default browser.
2526 :type url: str
2627 :return: opens new page/tab in browser.
2728 :rtype: None
2829 """
29- window_MAIN ['-TEXT_TOP-' ].update (f'Opening Doc Section: { title } ' )
30- window_MAIN .refresh ()
3130 return open (url , new = 2 , autoraise = True )
3231
3332
@@ -71,13 +70,13 @@ menu_choices: dict = {
7170 'Multiple Windows' :
7271 r'https://pysimplegui.readthedocs.io/en/latest/#running-multiple-windows' ,
7372 'Debug' :
74- 'https://pysimplegui.readthedocs.io/en/latest/#the-pysimplegui-debugger' ,
73+ r 'https://pysimplegui.readthedocs.io/en/latest/#the-pysimplegui-debugger' ,
7574 'User Settings API' :
7675 r'https://pysimplegui.readthedocs.io/en/latest/#user-settings-api' ,
7776 'Extensions' :
7877 r'https://pysimplegui.readthedocs.io/en/latest/#extending-pysimplegui' ,
7978 'Demo Apps' :
80- 'https://pysimplegui.readthedocs.io/en/latest/#demo-programs-applications' ,
79+ r 'https://pysimplegui.readthedocs.io/en/latest/#demo-programs-applications' ,
8180 'Create .EXE' :
8281 r'https://pysimplegui.readthedocs.io/en/latest/#creating-a-windows-exe-file' ,
8382 'Create .MAC' :
@@ -87,12 +86,12 @@ menu_choices: dict = {
8786#& ========================================================================= &#
8887#> ================================ Layouts ================================ <#
8988winlayout = [
90- [ #* Top Row Text
89+ [
9190 sg .Text ('Choose Topic from PySimpleGUI Docs to Browse' ,
9291 key = '-TEXT_TOP-' ,
9392 justification = 'Center' )
9493 ],
95- [ #* Option Menu & Open URL Buttons
94+ [
9695 sg .OptionMenu (key = '-OPTION_MENU-' ,
9796 values = list (menu_choices .keys ()),
9897 default_value = list (menu_choices .keys ())[0 ],
@@ -103,60 +102,58 @@ winlayout = [
103102 tooltip =
104103 'Open selected section from online PySimpleGUI documentation using your default browser.'
105104 )
106- ],
107- #* Exit Button
108- [sg .Exit (tooltip = 'Exit the program.' )],
109- #* Small Text to Display Current Theme
110- [sg .Text (f'Current Color Theme: { theme } ' , font = '_ 8' )],
111- #[
112- # sg.Button('Random Theme',
113- # k='-CHANGE_THEME-',
114- # tooltip='Click for a random color scheme.',
115- # font='_ 8')
116- #]
105+ ], [sg .Exit (tooltip = 'Exit the program.' )],
106+ [sg .Text (f'Current Color Theme: { rtheme } ' , font = '_ 8' )]
117107]
118108
119109#@ Displays Window:
120110window_MAIN = sg .Window (title = 'DocuPort - PySimpleGUI' ,
121111 layout = winlayout ,
122112 element_justification = 'Center' ,
123113 auto_size_buttons = True ,
114+ auto_size_text = True ,
124115 keep_on_top = True ,
125116 element_padding = (1 , 1 ),
126117 margins = ((3 , 3 )))
118+
119+
127120#> ========================================================================= <#
128121#$ ============================= Window Events ============================= $#
129- while True : #* Main event loop.
130- event , values = window_MAIN .read ()
131- #print(event,values) #NOTE: #? Enable to print stdout to console. #DEFAULT: -> OFF
132-
133- #@ Closes Window upon clicking 'x' or sg.Exit() Button.
134- if event in [sg .WIN_CLOSED , 'Exit' ]:
135- break
136- if event == '-OPEN_URL-' :
137- docs_section : str = values ['-OPTION_MENU-' ]
138- if docs_section in menu_choices :
139- choice = menu_choices [docs_section ]
140-
141- #> If chosen option is a valid function:
142- if callable (choice ):
143- choice () #< Call chosen function.
144-
145- #* If chosen option is a string variable:
146- else :
147- open_PSGUI (title = docs_section , url = choice )
148- s (1.5 )
149- window_MAIN ['-TEXT_TOP-' ].update ('Done!' )
150- window_MAIN .Refresh ()
151- s (1 )
152- #if event == '-CHANGE_THEME-':
153- # sg.theme(new_theme=rChoice(sg.theme_list()))
154- # window_MAIN['-TEXT_TOP-'].update(f'Theme changed to: {theme}!')
155- # window_MAIN.Finalize()
156- # s(0.5)
157- window_MAIN ['-TEXT_TOP-' ].update (
158- 'Choose Topic from PySimpleGUI Docs to Browse' )
159-
160- #! Close program and release computer resources:
161- window_MAIN .close ()
122+ def main ():
123+ while True :
124+ event , values = window_MAIN .read ()
125+ print (event , values
126+ ) #NOTE: #? Enable to print stdout to console. #DEFAULT: -> OFF
127+
128+ #@ Closes Window upon clicking 'x' or sg.Exit() Button.
129+ if event in [sg .WIN_CLOSED , 'Exit' ]:
130+ break
131+ if event == '-OPEN_URL-' :
132+ docs_section : str = values ['-OPTION_MENU-' ]
133+ if docs_section in menu_choices :
134+ choice = menu_choices [docs_section ]
135+
136+ #> If chosen option is a valid function:
137+ if callable (choice ):
138+ choice () #< Call chosen function.
139+
140+ #* If chosen option is a string variable:
141+ else :
142+ open_PSGUI (url = choice )
143+ window_MAIN ['-TEXT_TOP-' ].update (
144+ f'Opening Doc Section: { docs_section } ' )
145+ window_MAIN .refresh ()
146+ s (1.5 )
147+ window_MAIN ['-TEXT_TOP-' ].update ('Done!' )
148+ window_MAIN .Refresh ()
149+ s (1 )
150+ window_MAIN ['-TEXT_TOP-' ].update (
151+ 'Choose Topic from PySimpleGUI Docs to Browse' )
152+
153+ window_MAIN .close ()
154+
155+
156+ if __name__ == '__main__' :
157+ main ()
158+
162159#$ ========================================================================= $#
0 commit comments