From 048131d19937e71287536da0fb07d9e648415ac4 Mon Sep 17 00:00:00 2001 From: PySimpleGUI Date: Fri, 15 May 2020 21:15:57 -0400 Subject: [PATCH] The new readme creator and proposed new call reference file --- readme_creator/1_HEADER_top_part.md | 12 +- readme_creator/2_readme.md | 2082 +-------------------------- readme_creator/5_call_reference.md | 1999 +++++++++++++++++++++++++ readme_creator/LoG.json | 42 + readme_creator/PySimpleGUIlib.py | 28 +- readme_creator/make_real_readme.py | 51 +- readme_creator/run_me.py | 221 ++- readme_creator/show_all_tags.py | 87 +- 8 files changed, 2410 insertions(+), 2112 deletions(-) create mode 100644 readme_creator/5_call_reference.md create mode 100644 readme_creator/LoG.json diff --git a/readme_creator/1_HEADER_top_part.md b/readme_creator/1_HEADER_top_part.md index 0779ccd0..bdf578ed 100644 --- a/readme_creator/1_HEADER_top_part.md +++ b/readme_creator/1_HEADER_top_part.md @@ -27,20 +27,14 @@ HOW DO I INSERT IMAGES ??? ![pysimplegui_logo](https://user-images.githubusercontent.com/13696193/43165867-fe02e3b2-8f62-11e8-9fd0-cc7c86b11772.png) -[![Downloads](http://pepy.tech/badge/pysimplegui)](http://pepy.tech/project/pysimplegui) tkinter - -[![Downloads ](https://pepy.tech/badge/pysimplegui27)](https://pepy.tech/project/pysimplegui27) tkinter 2.7 - +[![tkinter](http://pepy.tech/badge/pysimplegui)](http://pepy.tech/project/pysimplegui) tkinter +[![tkinter27](https://pepy.tech/badge/pysimplegui27)](https://pepy.tech/project/pysimplegui27) tk 2.7 [![Downloads](https://pepy.tech/badge/pysimpleguiqt)](https://pepy.tech/project/pysimpleguiqt) Qt - [![Downloads](https://pepy.tech/badge/pysimpleguiwx)](https://pepy.tech/project/pysimpleguiWx) WxPython - [![Downloads](https://pepy.tech/badge/pysimpleguiweb)](https://pepy.tech/project/pysimpleguiWeb) Web (Remi) - ![Documentation Status](https://readthedocs.org/projects/pysimplegui/badge/?version=latest) -![Awesome Meter](https://img.shields.io/badge/Awesome_meter-100-yellow.svg) -![Python Version](https://img.shields.io/badge/Python-2.7_3.x-yellow.svg) +![Python Version](https://img.shields.io/badge/Python-2.7_3.4+-yellow.svg) [![PyPI Version](https://img.shields.io/pypi/v/pysimplegui.svg?style=for-the-badge)](https://pypi.org/project/pysimplegui/) tkinter [![PyPI Version](https://img.shields.io/pypi/v/pysimpleguiqt.svg?style=for-the-badge)](https://pypi.org/project/pysimpleguiqt/) Qt diff --git a/readme_creator/2_readme.md b/readme_creator/2_readme.md index c77629de..a6c700cc 100644 --- a/readme_creator/2_readme.md +++ b/readme_creator/2_readme.md @@ -113,9 +113,9 @@ The list of Popup output functions are: The trailing portion of the function name after Popup indicates what buttons are shown. `PopupYesNo` shows a pair of button with Yes and No on them. `PopupCancel` has a Cancel button, etc.. -While these are "output" windows, they do collect input in the form of buttons. The Popup functions return the button that was clicked. If the Ok button was clicked, then Popup returns the string 'Ok'. If the user clicked the X button to close the window, then the button value returned is `None`. +While these are "output" windows, they do collect input in the form of buttons. The Popup functions return the button that was clicked. If the Ok button was clicked, then Popup returns the string 'Ok'. If the user clicked the X button to close the window, then the button value returned is `None` or `WIN_CLOSED` is more explicit way of writing it. -The function `PopupTimed` or `PopupAutoClose` are popup windows that will automatically close after come period of time. +The function `popup_timed` or `popup_auto_close` are popup windows that will automatically close after come period of time. Here is a quick-reference showing how the Popup calls look. @@ -193,7 +193,7 @@ If `non_blocking` parameter is set, then the call will not blocking waiting for -The Popup call PopupNoWait or PopupNonBlocking will create a popup window and then immediately return control back to you. You can turn other popup calls into non-blocking popups if they have a `non_blocking` parameter. Setting `non_blocking` to True will cause the function to return immediately rather than waiting for the window to be closed. +The `popup` call `popup_no_wait` or `popup_non_blocking` will create a popup window and then immediately return control back to you. You can turn other popup calls into non-blocking popups if they have a `non_blocking` parameter. Setting `non_blocking` to True will cause the function to return immediately rather than waiting for the window to be closed. This function is very handy for when you're **debugging** and want to display something as output but don't want to change the programs's overall timing by blocking. Think of it like a `print` statement. There are no return values on one of these Popups. @@ -252,14 +252,14 @@ A typical call produces this window. ```python text = sg.popup_get_file('Please enter a file name') -sg.popup('Results', 'The value returned from PopupGetFile', text) +sg.popup('Results', 'The value returned from popup_get_file', text) ``` ![popupgetfile](https://user-images.githubusercontent.com/13696193/44957857-2fd31680-aea5-11e8-8eb7-f6b91c202cc8.jpg) ### popup_get_folder -The window created to get a folder name looks the same as the get a file name. The difference is in what the browse button does. `PopupGetFile` shows an Open File dialog box while `PopupGetFolder` shows an Open Folder dialog box. +The window created to get a folder name looks the same as the get a file name. The difference is in what the browse button does. `popup_get_file` shows an Open File dialog box while `popup_get_folder` shows an Open Folder dialog box. @@ -267,7 +267,7 @@ This is a typical call ```python text = sg.popup_get_folder('Please enter a folder name') - sg.popup('Results', 'The value returned from PopupGetFolder', text) + sg.popup('Results', 'The value returned from popup_get_folder', text) ``` ![popupgetfolder](https://user-images.githubusercontent.com/13696193/44957861-45484080-aea5-11e8-926c-cf607a45251c.jpg) @@ -301,7 +301,7 @@ That line of code resulted in this window popping up and updating. ![preogress meter](https://user-images.githubusercontent.com/13696193/43667625-d47da702-9746-11e8-91e6-e5177883abae.jpg) A meter AND fun statistics to watch while your machine grinds away, all for the price of 1 line of code. -With a little trickery you can provide a way to break out of your loop using the Progress Meter window. The cancel button results in a `False` return value from `OneLineProgressMeter`. It normally returns `True`. +With a little trickery you can provide a way to break out of your loop using the Progress Meter window. The cancel button results in a `False` return value from `one_line_progress_meter`. It normally returns `True`. ***Be sure and add one to your loop counter*** so that your counter goes from 1 to the max value. If you do not add one, your counter will never hit the max value. Instead it will go from 0 to max-1. @@ -428,12 +428,17 @@ layout = [[sg.Text('Enter a Number')], [sg.Input()], [sg.OK()] ] -event, values = sg.Window('Enter a number example', layout).read() +window = sg.Window('Enter a number example', layout) + +event, values = window.read() + +window.close() sg.Popup(event, values[0]) ``` -Your call to `Read` will return a dictionary, but will "look like a list" in how you access it. The first input field will be entry 0, the next one is 1, etc.. Later you'll learn about the `key` parameter which allows you to use your own values to identify elements instead of them being numbered for you. +Your call to `read` will normally return a dictionary, but will "look like a list" in how you access it. The first input field will be entry 0, the next one is 1, etc.. Later you'll learn about the `key` parameter which allows you to use your own values to identify elements instead of them being numbered for you. + ### Example 2 - Get a filename @@ -466,6 +471,8 @@ Read on for detailed instructions on the calls that show the window and return y All of your PySimpleGUI programs will utilize one of these 2 design patterns depending on the type of window you're implementing. +Beginning in release 4.19.0 the constant WIN_CLOSED replaced using `None` as the event signaling that a window was closed. + ## Pattern 1 A - "One-shot Window" - Read a window one time then close it This will be the most common pattern you'll follow if you are not using an "event loop" (not reading the window multiple times). The window is read and closed. @@ -526,7 +533,7 @@ window = sg.Window('Window that stays open', layout) while True: event, values = window.read() - if event is None or event == 'Exit': + if event == sg.WIN_CLOSED or event == 'Exit': break print(event, values) @@ -539,9 +546,7 @@ This is a slightly more complex, but maybe more realistic version that reads inp Do not worry yet what all of these statements mean. Just copy it so you can begin to play with it, make some changes. Experiment to see how thing work. -A final note... the parameter `do_not_clear` in the input call determines the action of the input field after a button event. If this value is True, the input value remains visible following button clicks. If False, then the input field is CLEARED of whatever was input. If you are building a "Form" type of window with data entry, you likely want False. The default is to NOT clear the input element (`do_not_clear=True`). - -This example introduces the concept of "keys". Keys are super important in PySimpleGUI as they enable you to identify and work with Elements using names you want to use. Keys can be ANYTHING, except `None`. To access an input element's data that is read in the example below, you will use `values['-IN-']` instead of `values[0]` like before. +This example introduces the concept of "keys". Keys are super important in PySimpleGUI as they enable you to identify and work with Elements using names you want to use. Keys can be (almost) ANYTHING, except `None` or a List (a tuple is fine). To access an input element's data that is read in the example below, you will use `values['-IN-']` instead of `values[0]` like before. ```python import PySimpleGUI as sg @@ -555,15 +560,13 @@ layout = [[sg.Text('Your typed chars appear here:'), sg.Text(size=(12,1), key='- window = sg.Window('Window Title', layout) while True: # Event Loop - event, values = window.read() # can also be written as event, values = window() + event, values = window.read() print(event, values) - if event is None or event == 'Exit': + if event == sg.WIN_CLOSED or event == 'Exit': break if event == 'Show': # change the "output" element to be the value of "input" element window['-OUTPUT-'].update(values['-IN-']) - # above line can also be written without the update specified - window['-OUTPUT-'](values['-IN-']) window.close() ``` @@ -588,9 +591,9 @@ import PySimpleGUI as sg sg.theme('Dark Blue 3') # please make your windows colorful layout = [[sg.Text('Rename files or folders')], - [sg.Text('Source for Folders', size=(15, 1)), sg.InputText(), sg.FolderBrowse()], - [sg.Text('Source for Files ', size=(15, 1)), sg.InputText(), sg.FolderBrowse()], - [sg.Submit(), sg.Cancel()]] + [sg.Text('Source for Folders', size=(15, 1)), sg.InputText(), sg.FolderBrowse()], + [sg.Text('Source for Files ', size=(15, 1)), sg.InputText(), sg.FolderBrowse()], + [sg.Submit(), sg.Cancel()]] window = sg.Window('Rename Files or Folders', layout) @@ -687,22 +690,24 @@ For Windows that have specifically enabled these. Please see the appropriate se ### Window closed event -Another convention to follow is the check for windows being closed with an X. *This is an critically important event to catch*. If you don't check for this and you attempt to use the window, your program will crash. Please check for closed window and exit your program gracefully. Your users will like you for it. +Another convention to follow is the check for windows being closed with an X. *This is an critically important event to catch*. If you don't check for this and you attempt to use the window, your program will crash, or silently consume 100% of your CPU. Please check for closed window and exit your program gracefully. Your users will like you for it. Close your windows when you're done with them even though exiting the program will also close them. tkinter can generate an error/warning sometimes if you don't close the window. For other ports, such as PySimpleGUIWeb, not closing the Window will potentially cause your program to continue to run in the background. To check for a closed window use this line of code: ```python -if event is None: +if event == sg.WIN_CLOSED: ``` +Prior to release 4.19.0 you'll find code that checks for `None` instead of `WIN_CLOSED`. These are in fact the same as `WIN_CLOSED` is `None`. + Putting it all together we end up with an "event loop" that looks something like this: ```python while True: event, values = window.read() - if event is None: + if event == sg.WIN_CLOSED: break window.close() ``` @@ -711,13 +716,15 @@ You will very often see the examples and demo programs write this check as: ```python event, values = window.read() - if event in (None, 'Exit'): + if event in (sg.WIN_CLOSED, 'Exit'): break ``` +The keyword `in` means to check the list of things to see if the `event` is in that list (or tuple) + This if statement is the same as: ```python - if event is None or event == 'Exit': + if event == sg.WIN_CLOSED or event == 'Exit': break ``` @@ -743,7 +750,7 @@ If your window has an event loop where it is read over and over, remember to giv ```python while True: event, values = window.read() - if event is None or event == 'Quit': + if event == sg.WIN_CLOSED or event == 'Quit': break ``` @@ -752,7 +759,7 @@ Actually, the more "Pythonic version" is used in most Demo Programs and examples ```python while True: event, values = window.read() - if event in (None, 'Quit'): + if event in (sg.WIN_CLOSED, 'Quit'): break ``` @@ -2579,7 +2586,7 @@ progress_bar = window['progressbar'] for i in range(1000): # check to see if the cancel button was clicked and exit loop if clicked event, values = window.read(timeout=10) - if event == 'Cancel' or event is None: + if event == 'Cancel' or event == sg.WIN_CLOSED: break # update bar with loop value +1 so that bar eventually reaches the maximum progress_bar.UpdateBar(i + 1) @@ -3353,7 +3360,7 @@ window = sg.Window('Window that stays open', layout) while True: event, values = window.read() print(event, values) - if event in (None, 'Exit'): + if event in (sg.WIN_CLOSED, 'Exit'): break window.close() @@ -3404,7 +3411,7 @@ If you wanted to test for "no event" in your loop, it would be written like this ```python while True: event, value = window.read(timeout=10) - if event is None: + if event == sg.WIN_CLOSED: break # the use has closed the window if event == sg.TIMEOUT_KEY: print("Nothing happened") @@ -3553,7 +3560,7 @@ window = sg.Window('My new window', layout) while True: # Event Loop event, values = window.read() - if event is None: + if event == sg.WIN_CLOSED: break window['-TEXT-'].update('My new text value') ``` @@ -3573,7 +3580,7 @@ window['-TEXT-'].update('My new text value') while True: # Event Loop event, values = window.read() - if event is None: + if event == sg.WIN_CLOSED: break ``` @@ -3613,7 +3620,7 @@ window = sg.Window("Font size selector", layout, grab_anywhere=False) # Event Loop while True: event, values= window.read() - if event is None: + if event == sg.WIN_CLOSED: break sz_spin = int(values['spin']) sz_slider = int(values['slider']) @@ -3703,7 +3710,7 @@ window = sg.Window("Keyboard Test", layout, return_keyboard_events=True, use_de while True: event, value = window.read() - if event == "OK" or event is None: + if event == "OK" or event == sg.WIN_CLOSED: print(event, "exiting") break text_elem.update(event) @@ -4002,7 +4009,7 @@ while True: event, values = window.read(timeout=500) if event == sg.TIMEOUT_KEY: continue - if event is None: + if event == sg.WIN_CLOSED: break print(event, values) window.close() @@ -4340,7 +4347,7 @@ window['Go'].bind("", '+RIGHT CLICK+') while True: # Event Loop event, values = window.read() print(event, values) - if event in (None, 'Exit'): + if event in (sg.WIN_CLOSED, 'Exit'): break window.close(); del window @@ -4351,2006 +4358,3 @@ There is no way to "unbind" and event at this time. (sorry, didn't think of it ------------------ - -# ELEMENT AND FUNCTION CALL REFERENCE - -This reference section was previously intermixed with the text explanation, diagrams, code samples, etc.. That was OK early on, but now that there are more Elements and more methods are being added on a fequent basis, it means that keeping this list updated is a difficult chore if it has a lot of text all around it. - -Hoping this is a change for the better and that users will be able to find the information they seek quicker. - -NOTE that this documentatiuopn section is created using the ***GitHUB released PySimpleGUI.py file***. Some of the calls may not be available to you or your port (Qt, Wx, Web). And some of the parameters may be different. We're working on adding docstrings to all the ports which will enable this kind of document to be available for each port. - -## Caution - Some functions / methods may be internal only yet exposed in this documenation - -This section of the documentation is generated directly from the source code. As a result, sometimes internal only functions or methods that you are not supposed to be calling are accidently shown in this documentation. Hopefully these accidents don't happen often. - -Without further delay... here are all of the Elements and the Window class - -## Button Element - - - -### Click - - -### GetText - - -### SetFocus - - -### SetTooltip - - -### Update - - -### bind - - -### click - - -### expand - - -### get_size - - -### get_text - - -### hide_row - - -### set_cursor - - -### set_focus - - -### set_size - - -### set_tooltip - - -### unbind - - -### unhide_row - - -### update - - -## ButtonMenu Element - - - -### Click - - -### SetFocus - - -### SetTooltip - - -### Update - - -### bind - - -### expand - - -### get_size - - -### hide_row - - -### set_cursor - - -### set_focus - - -### set_size - - -### set_tooltip - - -### unbind - - -### unhide_row - - -### update - - -## Canvas Element - - - -### SetFocus - - -### SetTooltip - - -### TKCanvas - - -### bind - - -### expand - - -### get_size - - -### hide_row - - -### set_cursor - - -### set_focus - - -### set_size - - -### set_tooltip - - -### tk_canvas - - -### unbind - - -### unhide_row - - -## Checkbox Element - - - -### Get - - -### SetFocus - - -### SetTooltip - - -### Update - - -### bind - - -### expand - - -### get - - -### get_size - - -### hide_row - - -### set_cursor - - -### set_focus - - -### set_size - - -### set_tooltip - - -### unbind - - -### unhide_row - - -### update - - -## Column Element - - - -### AddRow - - -### Layout - - -### SetFocus - - -### SetTooltip - - -### Update - - -### add_row - - -### bind - - -### expand - - -### get_size - - -### hide_row - - -### layout - - -### set_cursor - - -### set_focus - - -### set_size - - -### set_tooltip - - -### unbind - - -### unhide_row - - -### update - - -## Combo Element - - - -### Get - - -### SetFocus - - -### SetTooltip - - -### Update - - -### bind - - -### expand - - -### get - - -### get_size - - -### hide_row - - -### set_cursor - - -### set_focus - - -### set_size - - -### set_tooltip - - -### unbind - - -### unhide_row - - -### update - - - -## Frame Element - - - -### AddRow - - -### Layout - - -### SetFocus - - -### SetTooltip - - -### Update - - -### add_row - - -### bind - - -### expand - - -### get_size - - -### hide_row - - -### layout - - -### set_cursor - - -### set_focus - - -### set_size - - -### set_tooltip - - -### unbind - - -### unhide_row - - -### update - - -## Graph Element - - - -### BringFigureToFront - - -### DeleteFigure - - -### DrawArc - - -### DrawCircle - - -### DrawImage - - -### DrawLine - - -### DrawOval - - -### DrawPoint - - -### DrawPolygon - - -### DrawRectangle - - -### DrawText - - -### Erase - - -### GetBoundingBox - - -### GetFiguresAtLocation - - -### Move - - -### MoveFigure - - -### RelocateFigure - - -### SendFigureToBack - - -### SetFocus - - -### SetTooltip - - -### TKCanvas - - -### Update - - -### bind - - -### bring_figure_to_front - - -### change_coordinates - - -### delete_figure - - -### draw_arc - - -### draw_circle - - -### draw_image - - -### draw_line - - -### draw_oval - - -### draw_point - - -### draw_polygon - - -### draw_rectangle - - -### draw_text - - -### erase - - -### expand - - -### get_bounding_box - - -### get_figures_at_location - - -### get_size - - -### hide_row - - -### move - - -### move_figure - - -### relocate_figure - - -### send_figure_to_back - - -### set_cursor - - -### set_focus - - -### set_size - - -### set_tooltip - - -### tk_canvas - - -### unbind - - -### unhide_row - - -### update - - -## Image Element - - - -### SetFocus - - -### SetTooltip - - -### Update - - -### UpdateAnimation - - -### bind - - -### expand - - -### get_size - - -### hide_row - - -### set_cursor - - -### set_focus - - -### set_size - - -### set_tooltip - - -### unbind - - -### unhide_row - - -### update - - -### update_animation - - -### update_animation_no_buffering - - -## InputText Element - - - -### Get - - -### SetFocus - - -### SetTooltip - - -### Update - - -### bind - - -### expand - - -### get - - -### get_size - - -### hide_row - - -### set_cursor - - -### set_focus - - -### set_size - - -### set_tooltip - - -### unbind - - -### unhide_row - - -### update - - -## Listbox Element - - - -### GetIndexes - - -### GetListValues - - -### SetFocus - - -### SetTooltip - - -### SetValue - - -### Update - - -### bind - - -### expand - - -### get - - -### get_indexes - - -### get_list_values - - -### get_size - - -### hide_row - - -### set_cursor - - -### set_focus - - -### set_size - - -### set_tooltip - - -### set_value - - -### unbind - - -### unhide_row - - -### update - - -## Menu Element - - - -### SetFocus - - -### SetTooltip - - -### Update - - -### bind - - -### expand - - -### get_size - - -### hide_row - - -### set_cursor - - -### set_focus - - -### set_size - - -### set_tooltip - - -### unbind - - -### unhide_row - - -### update - - -## Multiline Element - - - -### Get - - -### SetFocus - - -### SetTooltip - - -### Update - - -### bind - - -### expand - - -### get - - -### get_size - - -### hide_row - - -### print - - -### set_cursor - - -### set_focus - - -### set_size - - -### set_tooltip - - -### unbind - - -### unhide_row - - -### update - - -## OptionMenu Element - - - -### SetFocus - - -### SetTooltip - - -### Update - - -### bind - - - -### expand - - -### get_size - - -### hide_row - - -### set_cursor - - -### set_focus - - -### set_size - - -### set_tooltip - - -### unbind - - -### unhide_row - - -### update - - -## Output Element - - - -### Get - - -### SetFocus - - -### SetTooltip - - -### TKOut - - -### Update - - -### bind - - -### expand - - -### get_size - - -### hide_row - - -### set_cursor - - -### set_focus - - -### set_size - - -### set_tooltip - - -### tk_out - - -### unbind - - -### unhide_row - - -### update - - -## Pane Element - - - -### SetFocus - - -### SetTooltip - - -### Update - - -### bind - - -### expand - - -### get_size - - -### hide_row - - -### set_cursor - - -### set_focus - - -### set_size - - -### set_tooltip - - -### unbind - - -### unhide_row - - -### update - - -## ProgressBar Element - - - -### SetFocus - - -### SetTooltip - - -### Update - - -### UpdateBar - - -### bind - - -### expand - - -### get_size - - -### hide_row - - -### set_cursor - - -### set_focus - - -### set_size - - -### set_tooltip - - -### unbind - - -### unhide_row - - -### update - - -### update_bar - - -## Radio Element - - - -### Get - - -### ResetGroup - - -### SetFocus - - -### SetTooltip - - -### Update - - -### bind - - -### expand - - -### get - - -### get_size - - -### hide_row - - -### reset_group - - -### set_cursor - - -### set_focus - - -### set_size - - -### set_tooltip - - -### unbind - - -### unhide_row - - -### update - - -## Slider Element - - - -### SetFocus - - -### SetTooltip - - -### Update - - -### bind - - -### expand - - -### get_size - - -### hide_row - - -### set_cursor - - -### set_focus - - -### set_size - - -### set_tooltip - - -### unbind - - -### unhide_row - - -### update - - -## Spin Element - - - -### Get - - -### SetFocus - - -### SetTooltip - - -### Update - - -### bind - - -### expand - - -### get - - -### get_size - - -### hide_row - - -### set_cursor - - -### set_focus - - -### set_size - - -### set_tooltip - - -### unbind - - -### unhide_row - - -### update - - -## StatusBar Element - - - -### SetFocus - - -### SetTooltip - - -### Update - - -### bind - - -### expand - - -### get_size - - -### hide_row - - -### set_cursor - - -### set_focus - - -### set_size - - -### set_tooltip - - -### unbind - - -### unhide_row - - -### update - - -## SystemTray - - - -### Close - - -### Hide - - -### Read - - -### ShowMessage - - -### UnHide - - -### Update - - -### close - - -### hide - - -### notify - - -### read - - -### show_message - - -### un_hide - - -### update - - -## Tab Element - - - -### AddRow - - -### Layout - - -### Select - - -### SetFocus - - -### SetTooltip - - -### Update - - -### add_row - - -### bind - - -### expand - - -### get_size - - -### hide_row - - -### layout - - -### select - - -### set_cursor - - -### set_focus - - -### set_size - - -### set_tooltip - - -### unbind - - -### unhide_row - - -### update - - -## TabGroup Element - - - - -### FindKeyFromTabName - - -### Get - - -### SetFocus - - -### SetTooltip - - -### bind - - -### expand - - -### find_key_from_tab_name - - -### get - - -### get_size - - -### hide_row - - - -### set_cursor - - -### set_focus - - -### set_size - - -### set_tooltip - - -### unbind - - -### unhide_row - - -## Table Element - - - -### Get - - -### SetFocus - - -### SetTooltip - - -### Update - - -### bind - - - -### expand - - -### get - - -### get_size - - -### hide_row - - -### set_cursor - - -### set_focus - - -### set_size - - -### set_tooltip - - -### unbind - - -### unhide_row - - -### update - - -## Text Element - - - -#### Get - - -### SetFocus - - -### SetTooltip - - -### Update - - -### bind - - -### expand - - -#### get - - -### get_size - - -### hide_row - - -### set_cursor - - -### set_focus - - -### set_size - - -### set_tooltip - - -### unbind - - -### unhide_row - - -### update - - - -## Tree Element - - - -### SetFocus - - -### SetTooltip - - -### Update - - -### add_treeview_data - - -### bind - - -### expand - - -### get_size - - -### hide_row - - -### set_cursor - - -### set_focus - - -### set_size - - -### set_tooltip - - -### unbind - - -### unhide_row - - -### update - - -## TreeData (for Tree Element) - - - -### Insert - - -### Node - - -### insert - - -## VerticalSeparator Element - - - -### SetFocus - - -### SetTooltip - - -### bind - - -### expand - - -### get_size - - -### hide_row - - -### set_cursor - - -### set_focus - - -### set_size - - -### set_tooltip - - -### unbind - - -### unhide_row - - -## Window - - - -### AddRow - - -### AddRows - - -### AlphaChannel - - -### BringToFront - - -### Close - - -### CurrentLocation - - -### Disable - - -### DisableDebugger - - -### Disappear - - -### Elem - - -### Element - - -### Enable - - -### EnableDebugger - - -### Fill - - -### Finalize - - -### Find - - -### FindElement - - -### FindElementWithFocus - - -### GetScreenDimensions - - -### GrabAnyWhereOff - - -### GrabAnyWhereOn - - -### Hide - - -### Layout - - -### LoadFromDisk - - -### Maximize - - -### Minimize - - -### Move - - -### Normal - - -### Read - - -### Reappear - - -### Refresh - - -### SaveToDisk - - -### SendToBack - - -### SetAlpha - - -### SetIcon - - -### SetTransparentColor - - -### Size - - -### UnHide - - -### VisibilityChanged - - -### add_row - - -### add_rows - - -### alpha_channel - - -### bind - - -### bring_to_front - - -### close - - -### current_location - - -### disable - - -### disable_debugger - - -### disappear - - -### elem - - -### element - - -### element_list - - -### enable - - -### enable_debugger - - -### extend_layout - - -### fill - - -### finalize - - -### find - - -### find_element - - -### find_element_with_focus - - -### get_screen_dimensions - - -### get_screen_size - - -### grab_any_where_off - - -### grab_any_where_on - - - -### hide - - -### layout - - -### load_from_disk - - -### maximize - - -### minimize - - -### move - - -### normal - - -### read - - -### reappear - - -### refresh - - -### save_to_disk - - -### send_to_back - - -### set_alpha - - -### set_icon - - -### set_transparent_color - - -### size - - -### un_hide - - -### visibility_changed - - - -## Function Reference - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -## Debug Window Output - - - - - - - - - - - - -## OneLineProgressMeter - - - - - - - -## Popup Functions - - - - - - - - - - - - - - - - - - - - - - - - - -## Popups PEP8 Versions - - - - - - - - - - - - - - - - - - - - - - - - - - - -## PEP8 Function Bindings - - - - - - - - - - - - - - -## Themes - - - - - - - - - - - - - - - - - - - -## Old Themes (Look and Feel) - Replaced by theme() - - - - - - - diff --git a/readme_creator/5_call_reference.md b/readme_creator/5_call_reference.md new file mode 100644 index 00000000..bbb775eb --- /dev/null +++ b/readme_creator/5_call_reference.md @@ -0,0 +1,1999 @@ + +# ELEMENT AND FUNCTION CALL REFERENCE + +NOTE that this documentation section is created using the ***GitHUB released PySimpleGUI.py file***. This means you're seeing the tkinter port only and some of the changes might not yet be released on PyPI. Some of the calls may not be available to you or your port (Qt, Wx, Web). And some of the parameters may be different. We're working on adding docstrings to all the ports which will enable this kind of document to be available for each port. + +## Caution - Some functions / methods may be internal only yet exposed in this documentation + +This section of the documentation is generated directly from the source code. As a result, sometimes internal only functions or methods that you are not supposed to be calling are accidently shown in this documentation. Hopefully these accidents don't happen often. + +Here are all of the Elements, the Window & SystemTray classes, and all functions + +## Button Element + + + +### Click + + +### GetText + + +### SetFocus + + +### SetTooltip + + +### Update + + +### bind + + +### click + + +### expand + + +### get_size + + +### get_text + + +### hide_row + + +### set_cursor + + +### set_focus + + +### set_size + + +### set_tooltip + + +### unbind + + +### unhide_row + + +### update + + +## ButtonMenu Element + + + +### Click + + +### SetFocus + + +### SetTooltip + + +### Update + + +### bind + + +### expand + + +### get_size + + +### hide_row + + +### set_cursor + + +### set_focus + + +### set_size + + +### set_tooltip + + +### unbind + + +### unhide_row + + +### update + + +## Canvas Element + + + +### SetFocus + + +### SetTooltip + + +### TKCanvas + + +### bind + + +### expand + + +### get_size + + +### hide_row + + +### set_cursor + + +### set_focus + + +### set_size + + +### set_tooltip + + +### tk_canvas + + +### unbind + + +### unhide_row + + +## Checkbox Element + + + +### Get + + +### SetFocus + + +### SetTooltip + + +### Update + + +### bind + + +### expand + + +### get + + +### get_size + + +### hide_row + + +### set_cursor + + +### set_focus + + +### set_size + + +### set_tooltip + + +### unbind + + +### unhide_row + + +### update + + +## Column Element + + + +### AddRow + + +### Layout + + +### SetFocus + + +### SetTooltip + + +### Update + + +### add_row + + +### bind + + +### expand + + +### get_size + + +### hide_row + + +### layout + + +### set_cursor + + +### set_focus + + +### set_size + + +### set_tooltip + + +### unbind + + +### unhide_row + + +### update + + +## Combo Element + + + +### Get + + +### SetFocus + + +### SetTooltip + + +### Update + + +### bind + + +### expand + + +### get + + +### get_size + + +### hide_row + + +### set_cursor + + +### set_focus + + +### set_size + + +### set_tooltip + + +### unbind + + +### unhide_row + + +### update + + + +## Frame Element + + + +### AddRow + + +### Layout + + +### SetFocus + + +### SetTooltip + + +### Update + + +### add_row + + +### bind + + +### expand + + +### get_size + + +### hide_row + + +### layout + + +### set_cursor + + +### set_focus + + +### set_size + + +### set_tooltip + + +### unbind + + +### unhide_row + + +### update + + +## Graph Element + + + +### BringFigureToFront + + +### DeleteFigure + + +### DrawArc + + +### DrawCircle + + +### DrawImage + + +### DrawLine + + +### DrawOval + + +### DrawPoint + + +### DrawPolygon + + +### DrawRectangle + + +### DrawText + + +### Erase + + +### GetBoundingBox + + +### GetFiguresAtLocation + + +### Move + + +### MoveFigure + + +### RelocateFigure + + +### SendFigureToBack + + +### SetFocus + + +### SetTooltip + + +### TKCanvas + + +### Update + + +### bind + + +### bring_figure_to_front + + +### change_coordinates + + +### delete_figure + + +### draw_arc + + +### draw_circle + + +### draw_image + + +### draw_line + + +### draw_oval + + +### draw_point + + +### draw_polygon + + +### draw_rectangle + + +### draw_text + + +### erase + + +### expand + + +### get_bounding_box + + +### get_figures_at_location + + +### get_size + + +### hide_row + + +### move + + +### move_figure + + +### relocate_figure + + +### send_figure_to_back + + +### set_cursor + + +### set_focus + + +### set_size + + +### set_tooltip + + +### tk_canvas + + +### unbind + + +### unhide_row + + +### update + + +## Image Element + + + +### SetFocus + + +### SetTooltip + + +### Update + + +### UpdateAnimation + + +### bind + + +### expand + + +### get_size + + +### hide_row + + +### set_cursor + + +### set_focus + + +### set_size + + +### set_tooltip + + +### unbind + + +### unhide_row + + +### update + + +### update_animation + + +### update_animation_no_buffering + + +## InputText Element + + + +### Get + + +### SetFocus + + +### SetTooltip + + +### Update + + +### bind + + +### expand + + +### get + + +### get_size + + +### hide_row + + +### set_cursor + + +### set_focus + + +### set_size + + +### set_tooltip + + +### unbind + + +### unhide_row + + +### update + + +## Listbox Element + + + +### GetIndexes + + +### GetListValues + + +### SetFocus + + +### SetTooltip + + +### SetValue + + +### Update + + +### bind + + +### expand + + +### get + + +### get_indexes + + +### get_list_values + + +### get_size + + +### hide_row + + +### set_cursor + + +### set_focus + + +### set_size + + +### set_tooltip + + +### set_value + + +### unbind + + +### unhide_row + + +### update + + +## Menu Element + + + +### SetFocus + + +### SetTooltip + + +### Update + + +### bind + + +### expand + + +### get_size + + +### hide_row + + +### set_cursor + + +### set_focus + + +### set_size + + +### set_tooltip + + +### unbind + + +### unhide_row + + +### update + + +## Multiline Element + + + +### Get + + +### SetFocus + + +### SetTooltip + + +### Update + + +### bind + + +### expand + + +### get + + +### get_size + + +### hide_row + + +### print + + +### set_cursor + + +### set_focus + + +### set_size + + +### set_tooltip + + +### unbind + + +### unhide_row + + +### update + + +## OptionMenu Element + + + +### SetFocus + + +### SetTooltip + + +### Update + + +### bind + + + +### expand + + +### get_size + + +### hide_row + + +### set_cursor + + +### set_focus + + +### set_size + + +### set_tooltip + + +### unbind + + +### unhide_row + + +### update + + +## Output Element + + + +### Get + + +### SetFocus + + +### SetTooltip + + +### TKOut + + +### Update + + +### bind + + +### expand + + +### get_size + + +### hide_row + + +### set_cursor + + +### set_focus + + +### set_size + + +### set_tooltip + + +### tk_out + + +### unbind + + +### unhide_row + + +### update + + +## Pane Element + + + +### SetFocus + + +### SetTooltip + + +### Update + + +### bind + + +### expand + + +### get_size + + +### hide_row + + +### set_cursor + + +### set_focus + + +### set_size + + +### set_tooltip + + +### unbind + + +### unhide_row + + +### update + + +## ProgressBar Element + + + +### SetFocus + + +### SetTooltip + + +### Update + + +### UpdateBar + + +### bind + + +### expand + + +### get_size + + +### hide_row + + +### set_cursor + + +### set_focus + + +### set_size + + +### set_tooltip + + +### unbind + + +### unhide_row + + +### update + + +### update_bar + + +## Radio Element + + + +### Get + + +### ResetGroup + + +### SetFocus + + +### SetTooltip + + +### Update + + +### bind + + +### expand + + +### get + + +### get_size + + +### hide_row + + +### reset_group + + +### set_cursor + + +### set_focus + + +### set_size + + +### set_tooltip + + +### unbind + + +### unhide_row + + +### update + + +## Slider Element + + + +### SetFocus + + +### SetTooltip + + +### Update + + +### bind + + +### expand + + +### get_size + + +### hide_row + + +### set_cursor + + +### set_focus + + +### set_size + + +### set_tooltip + + +### unbind + + +### unhide_row + + +### update + + +## Spin Element + + + +### Get + + +### SetFocus + + +### SetTooltip + + +### Update + + +### bind + + +### expand + + +### get + + +### get_size + + +### hide_row + + +### set_cursor + + +### set_focus + + +### set_size + + +### set_tooltip + + +### unbind + + +### unhide_row + + +### update + + +## StatusBar Element + + + +### SetFocus + + +### SetTooltip + + +### Update + + +### bind + + +### expand + + +### get_size + + +### hide_row + + +### set_cursor + + +### set_focus + + +### set_size + + +### set_tooltip + + +### unbind + + +### unhide_row + + +### update + + +## SystemTray + + + +### Close + + +### Hide + + +### Read + + +### ShowMessage + + +### UnHide + + +### Update + + +### close + + +### hide + + +### notify + + +### read + + +### show_message + + +### un_hide + + +### update + + +## Tab Element + + + +### AddRow + + +### Layout + + +### Select + + +### SetFocus + + +### SetTooltip + + +### Update + + +### add_row + + +### bind + + +### expand + + +### get_size + + +### hide_row + + +### layout + + +### select + + +### set_cursor + + +### set_focus + + +### set_size + + +### set_tooltip + + +### unbind + + +### unhide_row + + +### update + + +## TabGroup Element + + + + +### FindKeyFromTabName + + +### Get + + +### SetFocus + + +### SetTooltip + + +### bind + + +### expand + + +### find_key_from_tab_name + + +### get + + +### get_size + + +### hide_row + + + +### set_cursor + + +### set_focus + + +### set_size + + +### set_tooltip + + +### unbind + + +### unhide_row + + +## Table Element + + + +### Get + + +### SetFocus + + +### SetTooltip + + +### Update + + +### bind + + + +### expand + + +### get + + +### get_size + + +### hide_row + + +### set_cursor + + +### set_focus + + +### set_size + + +### set_tooltip + + +### unbind + + +### unhide_row + + +### update + + +## Text Element + + + +#### Get + + +### SetFocus + + +### SetTooltip + + +### Update + + +### bind + + +### expand + + +#### get + + +### get_size + + +### hide_row + + +### set_cursor + + +### set_focus + + +### set_size + + +### set_tooltip + + +### unbind + + +### unhide_row + + +### update + + + +## Tree Element + + + +### SetFocus + + +### SetTooltip + + +### Update + + +### add_treeview_data + + +### bind + + +### expand + + +### get_size + + +### hide_row + + +### set_cursor + + +### set_focus + + +### set_size + + +### set_tooltip + + +### unbind + + +### unhide_row + + +### update + + +## TreeData (for Tree Element) + + + +### Insert + + +### Node + + +### insert + + +## VerticalSeparator Element + + + +### SetFocus + + +### SetTooltip + + +### bind + + +### expand + + +### get_size + + +### hide_row + + +### set_cursor + + +### set_focus + + +### set_size + + +### set_tooltip + + +### unbind + + +### unhide_row + + +## Window + + + +### AddRow + + +### AddRows + + +### AlphaChannel + + +### BringToFront + + +### Close + + +### CurrentLocation + + +### Disable + + +### DisableDebugger + + +### Disappear + + +### Elem + + +### Element + + +### Enable + + +### EnableDebugger + + +### Fill + + +### Finalize + + +### Find + + +### FindElement + + +### FindElementWithFocus + + +### GetScreenDimensions + + +### GrabAnyWhereOff + + +### GrabAnyWhereOn + + +### Hide + + +### Layout + + +### LoadFromDisk + + +### Maximize + + +### Minimize + + +### Move + + +### Normal + + +### Read + + +### Reappear + + +### Refresh + + +### SaveToDisk + + +### SendToBack + + +### SetAlpha + + +### SetIcon + + +### SetTransparentColor + + +### Size + + +### UnHide + + +### VisibilityChanged + + +### add_row + + +### add_rows + + +### alpha_channel + + +### bind + + +### bring_to_front + + +### close + + +### current_location + + +### disable + + +### disable_debugger + + +### disappear + + +### elem + + +### element + + +### element_list + + +### enable + + +### enable_debugger + + +### extend_layout + + +### fill + + +### finalize + + +### find + + +### find_element + + +### find_element_with_focus + + +### get_screen_dimensions + + +### get_screen_size + + +### grab_any_where_off + + +### grab_any_where_on + + + +### hide + + +### layout + + +### load_from_disk + + +### maximize + + +### minimize + + +### move + + +### normal + + +### read + + +### reappear + + +### refresh + + +### save_to_disk + + +### send_to_back + + +### set_alpha + + +### set_icon + + +### set_transparent_color + + +### size + + +### un_hide + + +### visibility_changed + + + +## Function Reference + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +## Debug Window Output + + + + + + + + + + + + +## OneLineProgressMeter + + + + + + + +## Popup Functions + + + + + + + + + + + + + + + + + + + + + + + + + +## Popups PEP8 Versions + + + + + + + + + + + + + + + + + + + + + + + + + + + +## PEP8 Function Bindings + + + + + + + + + + + + + + +## Themes + + + + + + + + + + + + + + + + + + + +## Old Themes (Look and Feel) - Replaced by theme() + + + + + + + diff --git a/readme_creator/LoG.json b/readme_creator/LoG.json new file mode 100644 index 00000000..39011ed0 --- /dev/null +++ b/readme_creator/LoG.json @@ -0,0 +1,42 @@ +[ + { + "message_type": "info", + "message_text": "STARTING", + "message_time": 2 + }, + { + "message_type": "warning", + "message_text": "ALERT ------ Hi, Mike! Please, fix ':return:' in 'PopupNonBlocking' \tIF you want to see 'return' row in 'signature table'", + "message_time": 3 + }, + { + "message_type": "warning", + "message_text": "ALERT ------ Hi, Mike! Please, fix ':return:' in 'PopupAnimated' \tIF you want to see 'return' row in 'signature table'", + "message_time": 4 + }, + { + "message_type": "info", + "message_text": "\n=================================================\nSTARTING TO INSERT markdown text into 2_readme.md\n=================================================\n", + "message_time": 5 + }, + { + "message_type": "info", + "message_text": "DONE 8 TAGS:\n - COMPLETE\n - COMPLETE\n - COMPLETE\n - COMPLETE\n - COMPLETE\n - COMPLETE\n - COMPLETE\n - COMPLETE", + "message_time": 6 + }, + { + "message_type": "info", + "message_text": "No bad tags, YES!", + "message_time": 7 + }, + { + "message_type": "info", + "message_text": "Deleting html comments", + "message_time": 8 + }, + { + "message_type": "info", + "message_text": "ending. writing to a file///////////////", + "message_time": 9 + } +] \ No newline at end of file diff --git a/readme_creator/PySimpleGUIlib.py b/readme_creator/PySimpleGUIlib.py index 9520f445..d7364190 100644 --- a/readme_creator/PySimpleGUIlib.py +++ b/readme_creator/PySimpleGUIlib.py @@ -1,6 +1,6 @@ #!/usr/bin/python3 -version = __version__ = "4.19.0 Released 5-May-2020" +version = __version__ = "4.19.0.3 Unreleased - Window.set_title added, removed resetting stdout when flush happens, fixed MenuBar tearoff not working" port = 'PySimpleGUI' @@ -307,7 +307,6 @@ DEFAULT_SCROLLBAR_COLOR = None # A transparent button is simply one that matches the background # TRANSPARENT_BUTTON = 'This constant has been depricated. You must set your button background = background it is on for it to be transparent appearing' -TRANSPARENT_BUTTON = ('#F0F0F0', '#F0F0F0') # Use (sg.theme_background_color(), sg.theme_background_color()) instead!!! # -------------------------------------------------------------------------------- # Progress Bar Relief Choices @@ -358,7 +357,7 @@ LISTBOX_SELECT_MODE_SINGLE = 'single' TABLE_SELECT_MODE_NONE = tk.NONE TABLE_SELECT_MODE_BROWSE = tk.BROWSE TABLE_SELECT_MODE_EXTENDED = tk.EXTENDED -DEFAULT_TABLE_SECECT_MODE = TABLE_SELECT_MODE_EXTENDED +DEFAULT_TABLE_SELECT_MODE = TABLE_SELECT_MODE_EXTENDED TITLE_LOCATION_TOP = tk.N TITLE_LOCATION_BOTTOM = tk.S @@ -642,7 +641,7 @@ class Element(): self.Visible = visible self.TKRightClickMenu = None self.Widget = None # Set when creating window. Has the main tkinter widget for element - self.Tearoff = False + # self.Tearoff = False # why was this here?? should already be in the Menubar element...confusing... self.ParentRowFrame = None # type tk.Frame self.metadata = metadata # type: Any self.user_bind_dict = {} # Used when user defines a tkinter binding using bind method - convert bind string to key modifier @@ -2592,10 +2591,11 @@ class TKOutput(tk.Frame): def flush(self): """ - This doesn't look right. This restores stdout and stderr to their old values + Flush parameter was passed into a print statement. + For now doing nothing. Not sure what action should be taken to ensure a flush happens regardless. """ - sys.stdout = self.previous_stdout - sys.stderr = self.previous_stderr + return + def __del__(self): """ @@ -7810,6 +7810,17 @@ class Window: """ return + + def set_title(self, title): + """ + Change the title of the window + + :param title: The string to set the title to + :type title: str + """ + + self.TKroot.wm_title(str(title)) + # def __enter__(self): # """ # WAS used with context managers which are no longer needed nor advised. It is here for legacy support and @@ -13055,6 +13066,9 @@ def theme_background_color(color=None): set_options(background_color=color) return DEFAULT_BACKGROUND_COLOR +# This "constant" is misleading but rather than remove and break programs, will try this method instead +TRANSPARENT_BUTTON = (theme_background_color(), theme_background_color()) # replaces an older version that had hardcoded numbers + def theme_element_background_color(color=None): """ diff --git a/readme_creator/make_real_readme.py b/readme_creator/make_real_readme.py index 54fa5a94..d06e7d3a 100644 --- a/readme_creator/make_real_readme.py +++ b/readme_creator/make_real_readme.py @@ -1,6 +1,8 @@ from inspect import getmembers, isfunction, isclass, getsource, signature, _empty, isdatadescriptor from datetime import datetime import PySimpleGUIlib, click, textwrap, logging, json, re, os +import os +cd = CD = os.path.dirname(os.path.abspath(__file__)) from collections import namedtuple triplet = namedtuple('triplet', 'name value atype'.split(' ')) @@ -88,6 +90,8 @@ def get_return_part(code: str, line_break=None) -> str: return '' + + only_return = code[code.index(':return:')+len(':return:'):].strip().replace('\n', line_break) if ':rtype' in only_return: only_return = only_return.split(':rtype')[0] @@ -198,6 +202,8 @@ def special_cases(function_name, function_obj, sig, doc_string, line_break=None) def get_doc_desc(doc, original_obj): + + return_in = ':return' in doc param_in = ':param' in doc @@ -254,8 +260,11 @@ def get_sig_table_parts(function_obj, function_name, doc_string, sig_content = f',\n{TAB_char}'.join(rows) if len(rows) > 2 else f', '.join(rows) if rows else '' + sign = "\n\n{0}\n\n```\n{1}({2})\n```".format(get_doc_desc(doc_string, function_obj), function_name, sig_content) + + if is_method: if insert_md_section_for__class_methods: sign = "\n\n{0}\n\n```\n{1}({2})\n```".format(get_doc_desc(doc_string, function_obj), function_name, sig_content) @@ -283,9 +292,7 @@ def get_sig_table_parts(function_obj, function_name, doc_string, # 2 - def make_md_table_from_docstring(docstring): - # print(f'docstring = {docstring}') - # print(f'docstring = {type(docstring)}') + def make_md_table_from_docstring(docstring, a_original_obj): row_n_type_regex = re.compile(r':param ([\s\S]*?):([\s\S]*?):type [\s\S]*?:([\d\D]*?)\n', flags=re.M|re.DOTALL) # row_n_type_regex = re.compile(r':param ([\d\w]+):([\d\D]*?):type [\w\d]+:([\d\D].*?)$', flags=re.M|re.DOTALL) @@ -325,7 +332,7 @@ def get_sig_table_parts(function_obj, function_name, doc_string, try: max_type_width, max_name_width = max([len(i.atype) for i in trips]), max([len(i.name) for i in trips]) except Exception as e: - pass + logger.warning(f"ALERT ------ bug with max_type_width, max_name_width variables") row_template = f'| {{: ^{max_type_width}}} | {{: ^{max_name_width}}} | {{}} |' # rows, and finally table. @@ -342,11 +349,12 @@ def get_sig_table_parts(function_obj, function_name, doc_string, text, atype = aa.group(1).strip(), aa.group(2).strip() rows.append(f'| {atype} | **RETURN** | {text}') - except Exception as e: - print(e) - # print(f'docstring = {docstring}') - pass + padded_name = "{: <25}".format(f"'{a_original_obj.__name__}'") + + logger.warning(f"ALERT ------ Hi, Mike! Please, fix ':return:' in {padded_name}" + " \tIF you want to see 'return' row in 'signature table'") + # import pdb; pdb.set_trace(); header = '\nParameter Descriptions:\n\n|Type|Name|Meaning|\n|--|--|--|\n' @@ -359,8 +367,9 @@ def get_sig_table_parts(function_obj, function_name, doc_string, # 3 try: - params_TABLE = md_table = make_md_table_from_docstring(doc_string) + params_TABLE = md_table = make_md_table_from_docstring(doc_string, function_obj) except Exception as e: + logger.warning(f'Boy======= We got empty md_table for "{function_obj.__name__}"') params_TABLE = md_table = '' if not md_table.strip(): @@ -539,6 +548,8 @@ def main(do_full_readme=False, func_tags = [j for j in mark_points if 'func.' in j] + + # 0===0 functions 0===0 for tag in func_tags: @@ -576,6 +587,7 @@ def main(do_full_readme=False, logger.error(f' General error in parsing function tag: tag = "{tag}"; error="{str(e)}"') continue + injection_points.append('now, classes.') # 0===0 classes 0===0 for tag in classes_method_tags: try: @@ -637,25 +649,27 @@ def main(do_full_readme=False, # 8888888888888888888888888888888888888888888888888888888 + bar_it = lambda x: '\n' + '='*len(x) + f'\nSTARTING TO INSERT markdown text into 2_readme.md\n' + '='*len(x) + '\n' # 1> log some data success_tags = [] bad_tags = [] for injection in injection_points: + if injection == 'now, classes.': + logger.info(bar_it('STARTING TO INSERT markdown text into 2_readme.md')) + continue # SPECIAL CASE: X.doc tag if injection['part2'] == 'doc': a_tag = injection['tag'] - print(f'a_tag = {a_tag}') - print(f'a_tag = {type(a_tag)}') + logger.info(f'a_tag = {a_tag, type(a_tag).__name__}') doc_ = '' if not injection['parent_class'].__doc__ else injection['parent_class'].__doc__ # if doc_ == None or a_tag == None: - # import pdb; pdb.set_trace(); + readme = readme.replace(a_tag, doc_) else: - content = render(injection, logger=logger, line_break=line_break, insert_md_section_for__class_methods=insert_md_section_for__class_methods) @@ -667,6 +681,7 @@ def main(do_full_readme=False, readme = readme.replace(tag, content) + bad_part = '''\n\nParameter Descriptions:\n\n|Type|Name|Meaning|\n|--|--|--|\n\n''' readme = readme.replace(bad_part, '\n') @@ -683,8 +698,6 @@ def main(do_full_readme=False, logger.info(good_message) logger.info(bad_message) - print(123) - # 8888888888888888888888888888888888 # =========== 6 join =========== # @@ -733,8 +746,8 @@ def main(do_full_readme=False, if remove_repeated_sections_classmethods: rega = re.compile(r'((\#+\s\w+)\n\s){2}', flags=re.MULTILINE) for index, i in enumerate(re.finditer(rega, content)): - print(f'{index} - > {i.group(0)}') - print(f'{index} - > {i.group(1)}') + logger.info(f'{index} - > {i.group(0)}') + logger.info(f'{index} - > {i.group(1)}') content = content.replace(i.group(0), i.group(1)) # re # content = re.sub(rega, r'\1', content, flags=re.MULTILINE) @@ -750,6 +763,9 @@ def main(do_full_readme=False, if logger: logger.error(f'Error in main') + logger.save_messages() + + @click.command() @click.option('-nol', '--no_log', is_flag=True, help='Disable log') @@ -772,7 +788,6 @@ def cli(no_log, delete_log, delete_html_comments, output_name, log_file): my_file = logging.FileHandler(log_file, mode='w') my_file.setLevel(logging.DEBUG) formatter = logging.Formatter('%(asctime)s>%(levelname)s: %(message)s') - my_file.setFormatter(formatter) logger.addHandler(my_file) diff --git a/readme_creator/run_me.py b/readme_creator/run_me.py index 16ea9e22..dd7eadba 100644 --- a/readme_creator/run_me.py +++ b/readme_creator/run_me.py @@ -1,4 +1,17 @@ +import datetime,time,os +cd = CD = os.path.dirname(os.path.abspath(__file__)) + from make_real_readme import main +def readfile(filename): + with open(filename, 'r', encoding='utf-8') as ff: return ff.read() +def writefile(fpath, content): + with open(fpath, 'w', encoding='utf-8') as ff: ff.write(content) +import json +def writejson(a_path:str, a_dict:dict) -> None: + with open(a_path, 'w', encoding='utf-8') as output_file: + json.dump(a_dict, output_file, ensure_ascii=False, indent=2) +def readjson(a_path:str) -> dict: + with open(a_path, 'r', encoding='utf-8') as f: return json.load(f) ######################################################################## # __ _ _ # @@ -60,25 +73,138 @@ if method == 'simple, no log': # / /_ # # |____| # ################ -if method == 'with logs': +class BESTLOG(object): + def __init__(self, filename): + # my_file = logging.FileHandler(filename, mode='w') + # my_file.setLevel(logging.DEBUG) + # my_file.setFormatter(logging.Formatter('%(asctime)s>%(levelname)s: %(message)s')) + # logger = logging.getLogger(__name__) + # logger.setLevel(logging.DEBUG) + # logger.addHandler(my_file) + self.filename = filename + self.json_name = filename + '.json' + self.error_list = [] + self.warning_list = [] + self.info_list = [] + self.debug_list = [] + self.tick_amount=1 + self.names = self.messages_names = 'error warning info debug'.split(' ') - import logging - logger = logging.getLogger(__name__) - logger.setLevel(logging.DEBUG) + def tick(self): + self.tick_amount+=1 + return self.tick_amount - my_file = logging.FileHandler('usage.log.txt', mode='w') - my_file.setLevel(logging.DEBUG) - formatter = logging.Formatter('%(asctime)s>%(levelname)s: %(message)s') - my_file.setFormatter(formatter) - logger.addHandler(my_file) - logger.info('STARTING') + ####################################################################### + # __ _ _ _ # + # / _| | | (_) | # + # | |_ ___ _ __ | |_ _ __ __ _ _ __ ___ _ __ _| | ___ _ __ # + # | _/ _ \| '__| | __| '__/ _` | '_ \/ __| '_ \| | |/ _ \ '__| # + # | || (_) | | | |_| | | (_| | | | \__ \ |_) | | | __/ | # + # |_| \___/|_| \__|_| \__,_|_| |_|___/ .__/|_|_|\___|_| # + # | | # + # |_| # + ####################################################################### + def error(self, m): self.error_list.append([self.tick(), m]) + def warning(self, m): self.warning_list.append([self.tick(), m]) + def info(self, m): self.info_list.append([self.tick(), m]) + def debug(self, m): self.debug_list.append([self.tick(), m]) + + ########################################## + # __ # + # / _| # + # | |_ ___ _ __ _ __ ___ ___ # + # | _/ _ \| '__| | '_ ` _ \ / _ \ # + # | || (_) | | | | | | | | __/ # + # |_| \___/|_| |_| |_| |_|\___| # + # # + # # + ########################################## + def tolist(self): return zip([self.error_list, self.warning_list, self.info_list, self.debug_list], self.names) + def todict(self): return {'error' : self.error_list, 'warning' : self.warning_list, 'info' : self.info_list, 'debug' : self.debug_list} - main(logger=logger, + def save(self): + all_messages_list = [] + for messages, message_type in self.tolist(): + all_messages_list.extend([{'message_type' : message_type, 'message_text' : m_text, 'message_time' : m_time} for m_time, m_text in messages]) + + # sort messages on time + all_messages_list = sorted(all_messages_list, key=lambda x: x['message_time']) + + # convert time + # for i in all_messages_list: i['message_time'] = i['message_time'].strftime('%Y-%m-%d %H:%M:%S.%f') + + writejson(self.json_name, all_messages_list) + def load(self, **kw): + ''' + return dict with messages + + kw = { + use_psg_color : bool + show_time : bool + } + ''' + + # plan: + # read json, convert time + + # read + all_messages_list = readjson(self.json_name) + # convert time + # for i in all_messages_list: i['message_time'] = datetime.datetime.strptime(i['message_time'], '%Y-%m-%d %H:%M:%S.%f') + + def format_message(message): + if kw['show_time']: + return str(message['message_time']) + ':' + message['message_text'] + else: + return message['message_text'] + + + #=========# + # 4 lists # + #=========# + error_list = [i for i in all_messages_list if i['message_type'] == 'error'] + warning_list = [i for i in all_messages_list if i['message_type'] == 'warning'] + info_list = [i for i in all_messages_list if i['message_type'] == 'info'] + debug_list = [i for i in all_messages_list if i['message_type'] == 'debug'] + + + #=================# + # and 1 more list # + #=================# + colors = {'warning' : 'magenta', 'info' : 'black'} + warning_info_ = [] + for message in sorted(warning_list + info_list, key=lambda x: x['message_time']): + if kw['use_psg_color']: + warning_info_.append([ format_message(message), + colors.get(message['message_type']) ]) + else: + warning_info_.append(format_message(message)) + + error_list = map(format_message, error_list) + warning_list = map(format_message, warning_list) + info_list = map(format_message, info_list) + debug_list = map(format_message, debug_list) + + return error_list, warning_list, info_list, debug_list, warning_info_ + +def compile_all_stuff(**kw): + # import logging + + log_file = os.path.join(cd, 'LoG') + log_obj = BESTLOG(log_file) + main(logger=log_obj, insert_md_section_for__class_methods=insert_md_section_for__class_methods, remove_repeated_sections_classmethods=remove_repeated_sections_classmethods, files_to_include=[0, 1, 2, 3], output_name=OUTPUT_FILENAME, delete_html_comments=True) + log_obj.save() + + # cd = CD = os.path.dirname(os.path.abspath(__file__)) + # log_file = os.path.join(cd, 'usage.log.txt') + return log_obj.load(**kw) + +# if method == 'with logs': compile_all_stuff() ######################################## # _____ # @@ -90,9 +216,76 @@ if method == 'with logs': # | | | | # # |_| |_| # ######################################## +def mini_GUI(): + my_font = ("Helvetica", 12) + my_font2 = ("Helvetica", 12, "bold") + my_font3 = ("Helvetica", 15, "bold") + + + layout = [ + [ + sg.Column(layout=[ + [sg.T('debug', font=my_font, text_color='blue')], + [sg.ML(size=(70-15,20), key='debug')], + [sg.T('error', font=my_font, text_color='red')], + [sg.ML(size=(70-15,20), key='error')], + ]) + ,sg.T(' ') + ,sg.Column(layout=[ + [sg.T('warning', font=my_font2)], + [sg.ML(size=(70-12,20), key='warning')], + [sg.T('info', font=my_font2)], + [sg.ML(size=(70-12,20), key='info')], + ]), + sg.Column(layout=[ + [sg.T('warning_info', font=my_font3)], + [sg.ML(size=(110,42), key='warning_info')], + ]), + + ] + ] + window = sg.Window('We are live! Again! --- ' + 'Completed making {}'.format(OUTPUT_FILENAME), [ + [sg.T(size=(25,1), font=my_font, key='-compile-time-')] + ,[ + sg.B('Run again (F1)', key='-run-') + ,sg.CB('show time in logs (F2)', False, key='show_time') + ,sg.CB('Logs with Color (F3)', True, key='use_psg_color') + ] + ,*layout + ], resizable=True, finalize=True, location=(0,0), return_keyboard_events = True) + + def update_compilation_in_psg(values): + # get results + results = compile_all_stuff(use_psg_color=values['use_psg_color'], show_time=values['show_time']) + + # UPDATE GUI + curr_time = lambda : datetime.datetime.today().strftime('%Y-%m-%d %H:%M:%S.%f') + window['-compile-time-'](curr_time()) + for key, txt in zip('error warning info debug'.split(' '), results[:4]): + window[key]('\n'.join(txt)) + # colors warning_info + window['warning_info'].update('') + if values['use_psg_color']: + for text, color in results[-1]: + window['warning_info'].print(text, text_color=color) + else: + window['warning_info']('\n'.join(results[-1])) + + update_compilation_in_psg({'use_psg_color':not False, 'show_time':False}) + while True: + event, values = window() + if event in ('Exit', None): break + + # print(event) + if event == '-run-' or 'F1' in event: update_compilation_in_psg(values) + if 'F2' in event: window['show_time'](not values['show_time']) + if 'F3' in event: window['use_psg_color'](not values['use_psg_color']) + + window.close() + + if enable_popup: import PySimpleGUI as sg - lines = open('usage.log.txt', mode='r').readlines() - sg.PopupScrolled('Completed making {}'.format(OUTPUT_FILENAME), ''.join(lines), size=(80,50)) - + mini_GUI() + # sg.PopupScrolled('Completed making {}'.format(OUTPUT_FILENAME), ''.join(lines), size=(80,50)) \ No newline at end of file diff --git a/readme_creator/show_all_tags.py b/readme_creator/show_all_tags.py index afbe297e..48a31cc3 100644 --- a/readme_creator/show_all_tags.py +++ b/readme_creator/show_all_tags.py @@ -1,5 +1,5 @@ -import inspect -import PySimpleGUIlib +import PySimpleGUIlib;sg = PySimpleGUIlib +import datetime, inspect """ Create All Possible Tags @@ -8,12 +8,8 @@ import PySimpleGUIlib Displays the results in a PySimpleGUI window which can be used to copy and paste into other places. """ -layout = [[PySimpleGUIlib.Output(size=(80,40))]] -window = PySimpleGUIlib.Window('Dump of tags', layout, resizable=True).Finalize() - - - -SHOW_UNDERSCORE_METHODS = not False +messages = []; log = lambda x: messages.append(x) # logging utility +SHOW_functionsNmethods_that_starts_with_UNDERSCORE = True def valid_field(pair): bad_fields = 'LOOK_AND_FEEL_TABLE copyright __builtins__'.split(' ') @@ -29,10 +25,13 @@ def valid_field(pair): return True -psg_members = [i for i in inspect.getmembers(PySimpleGUIlib) if valid_field(i)] -psg_funcs = [o[0] for o in psg_members if inspect.isfunction(o[1])] -psg_classes = [o for o in psg_members if inspect.isclass(o[1])] -# psg_props = [o for o in psg_members if type(o[1]).__name__ == 'property'] + +# # ] +psg_members = [i for i in inspect.getmembers(PySimpleGUIlib) if valid_field(i)] # ] +psg_funcs = [o[0] for o in psg_members if inspect.isfunction(o[1])] # ] Grabing PSG objects +psg_classes = [o for o in psg_members if inspect.isclass(o[1])] # ] +# psg_props = [o for o in psg_members if type(o[1]).__name__ == 'property'] # ] + # I don't know how this magic filtering works, I just know it works. "Private" stuff (begins with _) are somehow # excluded from the list with the following 2 lines of code. Very nicely done Kol-ee-ya! @@ -40,24 +39,62 @@ psg_classes = sorted(list(set([i[1] for i in psg_classes])), key=lambda x : x.__ for aclass in psg_classes: class_name = aclass.__name__ - if 'Tk' in class_name or 'TK' in class_name or 'Element' == class_name: # or 'Window' == class_name: + + # filter bad objects + if 'Tk' in class_name or 'TK' in class_name or\ + 'Element' == class_name: # or 'Window' == class_name: continue - print(f'### {class_name} Element ') - print(f'') - print(f'\n') - print('\n'.join([f"#### {name}\n\n" for name, obj in inspect.getmembers(aclass) if not name.startswith('_') ])) + + # print standart things: + log(f'### {class_name} Element ') + log(f'') + log(f'\n') -print('\n------------------------- Functions start here -------------------------\n') + # print all public methods: + log('\n'.join([f"#### {name}\n\n" + for name, obj in inspect.getmembers(aclass) + if not name.startswith('_') ])) -if SHOW_UNDERSCORE_METHODS: +def get_filtered_funcs(psg_funcs, show_underscore=False): + space = '-'*30 + curr_dt = today = datetime.datetime.today() + filtered = [f'{curr_dt}\n\n{space}Functions start here{space}\n'] for i in psg_funcs: - if '_' in i: - print( f"" ) -else: - for i in psg_funcs: - print( f"" ) + txt = f"" + + if i.startswith('_') and show_underscore: + filtered.append(txt); continue + filtered.append(txt) + return f'TOTAL funcs amount listed below: {len(filtered)}\n' + '\n'.join(filtered) +############################### +# _____ _ _ _____ # +# / ____| | | |_ _| # +# | | __| | | | | | # +# | | |_ | | | | | | # +# | |__| | |__| |_| |_ # +# \_____|\____/|_____| # +# # +############################### +window = sg.Window('Dump of tags', [ + [sg.ML(size=(80,40), key='w'), + sg.Col([ + [sg.ML(size=(80,40), key='w2')], + [sg.CB('show _ funcs&methods?', key='-_sc-', enable_events=True)] + ])] +], resizable=True, finalize=True) +window['w']('\n'.join(messages)) +window['w2'](get_filtered_funcs(psg_funcs, True)) -window.Read() \ No newline at end of file +while True: + event, values = window() + if event in ('Exit', None): break + + print(event) + if event == '-_sc-': + filtered = get_filtered_funcs(psg_funcs, values['-_sc-']) + window['w2'](filtered) + +window.close()