Skip to content

Commit 1290b01

Browse files
Filled in doc strings (much more to go!)
1 parent 94ac5b3 commit 1290b01

File tree

1 file changed

+47
-36
lines changed

1 file changed

+47
-36
lines changed

PySimpleGUI.py

Lines changed: 47 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -379,14 +379,13 @@ def hidetip(self):
379379
# Element CLASS #
380380
# ------------------------------------------------------------------------- #
381381
class Element():
382-
"""The base class for all Elements.
382+
"""
383+
The base class for all Elements.
383384
Holds the basic description of an Element like size and colors
384-
385-
386385
"""
387386
def __init__(self, type, size=(None, None), auto_size_text=None, font=None, background_color=None, text_color=None, key=None, pad=None, tooltip=None, visible=True):
388387
"""
389-
388+
Element base class. Only used internally. User will not create an Element object by itself
390389
:param type: ??????????????????????????
391390
:param size: ▲ (w,h) w=characters-wide, h=rows-high
392391
:param auto_size_text: True if size should fit the text length
@@ -426,17 +425,17 @@ def __init__(self, type, size=(None, None), auto_size_text=None, font=None, back
426425

427426
def _RightClickMenuCallback(self, event):
428427
"""
429-
430-
:param event:
428+
Callback function that's called when a right click happens. Shows right click menu as result
429+
:param event: information provided by tkinter about the event including x,y location of click
431430
432431
"""
433432
self.TKRightClickMenu.tk_popup(event.x_root, event.y_root, 0)
434433
self.TKRightClickMenu.grab_release()
435434

436435
def _MenuItemChosenCallback(self, item_chosen): # TEXT Menu item callback
437436
"""
438-
439-
:param item_chosen:
437+
Callback function called when user chooses a menu item from menubar, Button Menu or right click menu
438+
:param item_chosen: str. String holding the value chosen.
440439
441440
"""
442441
# print('IN MENU ITEM CALLBACK', item_chosen)
@@ -448,9 +447,10 @@ def _MenuItemChosenCallback(self, item_chosen): # TEXT Menu item callback
448447

449448
def _FindReturnKeyBoundButton(self, form):
450449
"""
451-
452-
:param form:
453-
450+
Searches for which Button has the flag Button.BindReturnKey set. It is called recursively when a
451+
"Container Element" is encountered. Func has to walk entire window including these "sub-forms"
452+
:param form: the Window object to search
453+
:return Button Object if a button is found, else None if no button found
454454
"""
455455
for row in form.Rows:
456456
for element in row:
@@ -481,7 +481,8 @@ def _FindReturnKeyBoundButton(self, form):
481481

482482
def _TextClickedHandler(self, event):
483483
"""
484-
484+
Callback that's called when a text element is clicked on with events enabled on the Text Element.
485+
Result is that control is returned back to user (quits mainloop).
485486
:param event:
486487
487488
"""
@@ -506,8 +507,8 @@ def _ReturnKeyHandler(self, event):
506507

507508
def _ListboxSelectHandler(self, event):
508509
"""
509-
510-
:param event:
510+
Callback function for when a listbox item is selected
511+
:param event: Information from tkinter about the callback
511512
512513
"""
513514
# first, get the results table built
@@ -630,30 +631,32 @@ def __del__(self):
630631
# Input Class #
631632
# ---------------------------------------------------------------------- #
632633
class InputText(Element):
633-
"""Shows a single line of input."""
634+
"""
635+
Display a single text input field. Based on the tkinter Widget Entry
636+
"""
634637
def __init__(self, default_text='', size=(None, None), disabled=False, password_char='',
635638
justification=None, background_color=None, text_color=None, font=None, tooltip=None,
636639
change_submits=False, enable_events=False, do_not_clear=True, key=None, focus=False, pad=None,
637640
right_click_menu=None, visible=True):
638641
"""
639642
640-
:param default_text: Text initially shown in the input box (Default value = '')
643+
:param default_text: Text initially shown in the input box as a default value(Default value = '')
641644
:param size: ▲ (w,h) w=characters-wide, h=rows-high
642645
:param disabled: set disable state for element (Default = False)
643-
:param password_char: Passwork character if this is a password field (Default value = '')
644-
:param justification: justification for data display
646+
:param password_char: Password character if this is a password field (Default value = '')
647+
:param justification: justification for data display. Valid choices - left, right, center
645648
:param background_color: color of background
646649
:param text_color: color of the text
647650
:param font: ▲ specifies the font family, size, etc
648-
:param tooltip: text, that will appear the you hover on
651+
:param tooltip: str. Text shown when cursor hovers over the element
649652
:param change_submits: If True, pressing Enter key submits window- DEPRICATED DO NOT USE! (Default = False)
650653
:param enable_events: Turns on the element specific events. Use this instead of change_submits (Default = False)
651-
:param do_not_clear: see docx (Default = True)
652-
:param key: ▲ Used with window.FindElement and with return values
653-
:param focus: if focus should be set to this
654-
:param pad: ▲ Amount of padding to put around element
655-
:param right_click_menu: see "Right Click Menus"
656-
:param visible: set visibility state of the element (Default = True)
654+
:param do_not_clear: Bool. If False then the field will be set to blank after ANY submission (button, any event) (Default = True)
655+
:param key: ▲ Any. Value that uniquely identifies this element from all other elements. Used when Finding an element or in return values
656+
:param focus: Bool. Determines if initial focus should go to this element.
657+
:param pad: ▲ Tuple. Amount of padding to put around element. Normally (horizontal pixels, vertical pixels) but can be split apart further into ((horizontal left, horizontal right), (vertical above, vertical below))
658+
:param right_click_menu: [[]]. A list of lists of Menu items to show when this element is right clicked. See docs for format.
659+
:param visible: Bool. set visibility state of the element (Default = True)
657660
"""
658661
self.DefaultText = default_text
659662
self.PasswordCharacter = password_char
@@ -929,18 +932,17 @@ def __del__(self):
929932
# Listbox #
930933
# ---------------------------------------------------------------------- #
931934
class Listbox(Element):
932-
"""A List Box. Provide a list of values for the user to choose one or more of. Returns a list of selected rows
935+
"""
936+
A List Box. Provide a list of values for the user to choose one or more of. Returns a list of selected rows
933937
when a window.Read() is executed.
934-
935-
936938
"""
937939
def __init__(self, values, default_values=None, select_mode=None, change_submits=False, enable_events=False,
938940
bind_return_key=False, size=(None, None), disabled=False, auto_size_text=None, font=None,
939941
background_color=None, text_color=None, key=None, pad=None, tooltip=None, right_click_menu=None,
940942
visible=True):
941943
"""Listbox Element
942944
943-
:param values: list of values to display
945+
:param values: list of values to display. Can be any type including mixed types as long as they have __str__ method
944946
:param default_values: list of objects for listbox
945947
:param select_mode: can be a string or a constant value defined as a variable. Generally speaking strings are used for these kinds of options
946948
:param change_submits: If True, pressing Enter key submits window (Default = False)
@@ -986,8 +988,8 @@ def __init__(self, values, default_values=None, select_mode=None, change_submits
986988

987989
def Update(self, values=None, disabled=None, set_to_index=None, scroll_to_index=None, visible=None):
988990
"""
989-
990-
:param values: new list of choices
991+
Update some of the element's settings
992+
:param values: new list of choices to be shown to user
991993
:param disabled: disable or enable state of the element
992994
:param set_to_index: highlights the item at this index as if user clicked
993995
:param scroll_to_index: scroll the listbox so that this index is the first shown
@@ -1039,12 +1041,20 @@ def SetValue(self, values):
10391041

10401042

10411043
def GetListValues(self):
1042-
""" """
1044+
# type: (Listbox) -> []
1045+
"""
1046+
Returns list of Values provided by the user in the user's format
1047+
:return: List. List of values. Can be any / mixed types -> []
1048+
"""
10431049
return self.Values
10441050

10451051

10461052
def SetFocus(self, force=False):
1047-
""" """
1053+
"""
1054+
Moves the focus to this element
1055+
:param force: Bool. If True, will call focus_force instead of focus_set
1056+
:return:
1057+
"""
10481058
try:
10491059
if force:
10501060
self.TKListbox.focus_force()
@@ -6526,9 +6536,10 @@ def _FindElementFromKeyInSubForm(form, key):
65266536

65276537

65286538
def _FindElementWithFocusInSubForm(form):
6539+
# type: (...) -> Element or None
65296540
"""
6530-
6531-
:param form:
6541+
Searches through a "sub-form" (can be a window or container) for the current element with focus
6542+
:param form: a Window, Column, Frame, or TabGroup (container elements)
65326543
65336544
"""
65346545
for row_num, row in enumerate(form.Rows):
@@ -6561,7 +6572,7 @@ def _FindElementWithFocusInSubForm(form):
65616572
if element.TKButton is not None:
65626573
if element.TKButton is element.TKButton.focus_get():
65636574
return element
6564-
6575+
return None
65656576

65666577
if sys.version_info[0] >= 3:
65676578
def AddMenuItem(top_menu, sub_menu_info, element, is_sub_menu=False, skip=False):

0 commit comments

Comments
 (0)