-
Notifications
You must be signed in to change notification settings - Fork 1
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
One more? The built-in SDK Ref is a nice way to pull up docs when no connection is available. #2
Comments
If you want to be a bit more table driven, then a dictionary works nicely since you've got the mapping between choice and destination all figured out already. Sorry for the long line length. I work on massive monitors, prefer horizontal code, and thus end up with long looking lines. # #& DocuPort PSG v2.1.0-Beta
# ? Simple GUI Script to open user-specified chapter of the Online-Documentation for PySimpleGUI.
# ? =============================== Libraries =============================== ?#
import random
import webbrowser
import PySimpleGUI as sg
# ? ========================================================================= ?#
# & =============================== Functions =============================== &#
# ? Changes the base color layout each time the app is opened.
theme = random.choice(sg.theme_list())
sg.theme(theme)
# & ========================================================================= &#
# List of choices in the option menu along with the "action". If a function, call it. If a string, launch in browser
opt_menu_choices_dict = { 'Built-in Docs': sg.main_sdk_help,
'Homepage': r'https://pysimplegui.readthedocs.io/en/latest/',
'Learning Resources' : r'https://pysimplegui.readthedocs.io/en/latest/#learning-resources',
'Getting Started' : r'https://pysimplegui.readthedocs.io/en/latest/#getting-started-with-pysimplegui',
'Demo Screenshots' : r'https://pysimplegui.readthedocs.io/en/latest/screenshots_demos' ,
'Call Reference' : r'https://pysimplegui.readthedocs.io/en/latest/call%20reference',
'Cookbook' :r'https://pysimplegui.readthedocs.io/en/latest/cookbook/',
'Readme' : r'https://pysimplegui.readthedocs.io/en/latest/readme/',
'Popups' : r'https://pysimplegui.readthedocs.io/en/latest/#high-level-api-calls-popups',
'Progress Meters' :r'https://pysimplegui.readthedocs.io/en/latest/#progress-meters',
'Custom Windows' :r'https://pysimplegui.readthedocs.io/en/latest/#custom-window-api-calls-your-first-window',
'Layouts' :r'https://pysimplegui.readthedocs.io/en/latest/#layouts',
'Elements' :r'https://pysimplegui.readthedocs.io/en/latest/#elements',
'Themes' : r'https://pysimplegui.readthedocs.io/en/latest/#themes-automatic-coloring-of-your-windows',
'Return Values' : r'https://pysimplegui.readthedocs.io/en/latest/#return-values',
'System Tray' : r'https://pysimplegui.readthedocs.io/en/latest/#systemtray',
'Keyboard & Mouse Capture' : r'https://pysimplegui.readthedocs.io/en/latest/#keyboard-mouse-capture',
'Menus' :r'https://pysimplegui.readthedocs.io/en/latest/#menus',
'Multiple Windows' : r'https://pysimplegui.readthedocs.io/en/latest/#running-multiple-windows',
'Debug' : 'https://pysimplegui.readthedocs.io/en/latest/#the-pysimplegui-debugger',
'User Settings API' :r'https://pysimplegui.readthedocs.io/en/latest/#user-settings-api',
'Extensions' :r'https://pysimplegui.readthedocs.io/en/latest/#extending-pysimplegui',
'Demo Apps' : 'https://pysimplegui.readthedocs.io/en/latest/#demo-programs-applications',
'Create .EXE' :r'https://pysimplegui.readthedocs.io/en/latest/#creating-a-windows-exe-file',
'Create .MAC': r'https://pysimplegui.readthedocs.io/en/latest/#creating-a-mac-app-file'}
# ^ ================================ Layouts ================================ ^#
winlayout = [[sg.Text('Choose Section from PySimpleGUI Docs to Browse')],
[sg.OptionMenu(key='-OPTION_MENU-', values=list(opt_menu_choices_dict.keys()), default_value=list(opt_menu_choices_dict.keys())[0], tooltip='Choose a topic to browse.'),
sg.Button('Open Section', key='-OPEN_URL-', tooltip='Opens selection using default browser.')],
[sg.Exit()],
[sg.Text(f'Like the theme? It is {theme}', font='_ 8')]]
window = sg.Window(title='DocuPort PSG', layout=winlayout, element_justification='Center', auto_size_buttons=True, keep_on_top=True, element_padding=(2, 2), margins=((5, 5)))
# * ============================= Window Events ============================= *#
while True: # * The Infinite Loop that keeps the Window open, and returns feedback from the user.
event, values = window.read()
# print(event, values) #NOTE: #? Enable to print stdout to console.
# ! Closes Window upon clicking 'x' or sg.Exit() Button.
if (event == sg.WIN_CLOSED or event == 'Exit'):
break
if event == '-OPEN_URL-':
choice = values['-OPTION_MENU-']
if choice in opt_menu_choices_dict.keys():
action = opt_menu_choices_dict[choice]
if callable(action):
action()
else:
webbrowser.open_new_tab(action)
window.close()
# * ========================================================================= *# |
Oh crap, I never realized there was an "internal sdk"! I feel like that sort of eliminates any practical need for my application lmao 🤣! It appears I've created a solution to a problem that I invented out of my own ignorance! But hey, that's what learning is all about right?! The suggestion to list the current theme's name is genius and so simple, I can't believe I didn't think of that before haha! Also the use of a dictionary is very succinct and looks natural; it feels like I rarely ever work with dictionaries when developing my own projects (I am not hired programmer or developer, so I imagine the use of dictionaries is much more common and useful than my projects would suggest), so it's interesting to see them used in a practical situation such as this. I love your program and what you've done @PySimpleGUI, I find it extremely motivating and inspirational just using Thank you so much my friend! |
Thank you for the kind words. It's people like you that make all this happen. Without the inspiration and motivation from people just like you, none of it would happen. It's a feedback look of sorts.
This is one reason that I enjoy learning from beginners. I learn something new and unexpected looking at what beginners do. I was ignorant writing PySimpleGUI. I hadn't written a GUI program before, so I didn't know the "right" way to do it. Being ignorant can be an advantage at times. It's like being a kid that doesn't know boundaries so well. Produces interesting results. Dictionaries were a new concept for me too when I wrote PySimpleGUI. Never used them so it's been interesting to learn spots they can be applied. One way of looking for spots to use them is when you want to show one thing, but also have something else associated with that thing. They come in real handy with a Listbox of files for example. The files shown in the Listbox on the left side use the displayed text as the key to the dictionary. The dictionary looks like this: Key : Value files = {'abc' : 'c:\somewhere\abc'} The Listbox values would be files.keys(). This way you're showing the user the things that are the keys... and when they choose one, you can get the full filename: files['abc'] "Mapping" is a term that I use when I think about uses for them. I'm mapping from one value to another. There are other uses for dictionaries of course, but this is a good one for use with GUIs. I think "mapping from something simple to something more complex". In this case, it's mapping a simple filename, just the name, into the larger, absolute filename. |
Should have added the explicit dictionary use in your code... In your program, the dictionary instead of being used in a Listbox, was used in an OptionMenu. Same exact thing. Any place a list is used, it's a possible fit. Listbox, Combo, OptionMenu, Table, Tree, etc. In your example, we mapped from the text shown in the OptionMenu to a URL or a function. Simple was the string shown in the OptionMenu, and added and more complex data was the URL or function to call. |
Oh! I also like that you took the unusual step of naming your file with a .pyw extension. Very nice. |
Thank you so much @PySimpleGUI ! Indeed developing with PySimpleGUI has been integral in helping me learn to be _much more comfortable around lists, dicts, and especially leaning to actually use the documentation the devs are so kind to provide haha! That was something I never understood in my early days of programming, and learning about external libraries/modules was much more tedious before I sort-of "knew" the usefulness of good, solid documentation. But yeah I ended up learning that simply using a .pyw extension circumnavigates the "false trojan" flag that at the time, antiviruses would detect .exe programs as when made using pyinstaller... I remember looking into this issue for a long time, through their github issues, thread after thread, with many others having the exact same issue. It was nearly 8 months ago now, so maybe there has been some sort of fix within pyinstaller itself, but I basically just had to whitelist any directories that contained the generated files, so that Windows Defender didn't freak out on me for no reason haha! Oh, but I forgot to mention, both suggestions have been implemented in the most recent release, I put it up last night! |
Thank you again for the many kind words. I'm really pleased to see you being excited about programming. It's what gets me up every day to work on PySimpleGUI. Knowing I have the opportunity to help someone fall in love with programming is highly motivating. Getting to witness the spark, the moment when someone realizes that they can code is priceless. It's why I'm really thankful for the kind words. I can tell that you're thoroughly enjoying what you're doing. Documentation is sometimes available, sometimes not... with not being the more typical situation. There may be docs, but their effectiveness is what matters. It's possible to have documentation but it still not be all that helpful in the end. It depends on what's being documented as well. The docstrings have helped people considerably I think because when I look at the readthedocs traffic, more people are going to the cookbook than to the call reference. The docstrings / IDE are providing a lot of the information that's needed when writing code. I should be asking you that.... how have you learned how to use the elements and the different parameters? Keep on making stuff!!! It doesn't matter what you make. What matters is that you want to make it and then as a result, do end up making it. "Tutorials" are ok, but have a big downside that they don't really drive you into creating. It's by creating that I've learned everything I've learned over the years. I read about programming in Python of course, but it was the act of creating something that drove me to do the reading. What IDE do you use? How did you learn PySimpleGUI? Tell me a little about the process. It would be helpful to hear. |
One more suggestion.... the internal SDK reference has each element explained and a link to the online doc at the bottom of each element's explanation that will open the browser.
It looks like this:
Moving the option menu list out to a variable enables you make the first entry be the default:
Then add this to your event loop:
DocuPort_PSG/src/DocuPort_PSG.pyw
Line 200 in 74cd3cb
The text was updated successfully, but these errors were encountered: