Inspection

PyTermGUI provides a pretty nifty inspection utility, inspect! It's useful to figure out the signature of functions, inspect their general shape & docstrings.

docs/src/inspect1.py ────────────────────────────────────────────────────────────────────────────────────────────────── │                                pytermgui.widgets.containers.Container                                │ │            Located in  /Users/lapis/Code/Projects/pytermgui/pytermgui/widgets/containers.py            │ ────────────────────────────────────────────────────────────────────────────────────────────────── class   Container (*widgets:  Any , **attrs:  Any ) ->  None :                                                      A widget that displays other widgets, stacked vertically.                                                                                                                                                  def   bind (self, key:  str , action:  BoundCallback , description:  Optional [ str ] =  None ) ->  None :                 Binds an action to a keypress.                                                                                                                                                                          def   center (self, where:  CenteringPolicy  |  None  =  None , store:  bool  =  True ) ->  Container :                    Centers this object to the given axis.                                                                                                                                                                  def   contains (self, pos:  tuple [ int int ]) ->  bool :                                                           Determines whether widget contains `pos`.                                                                                                                                                               def   copy (self) ->  Widget :                                                                                   Creates a deep copy of this widget                                                                                                                                                                      def   debug (self) ->  str :                                                                                     Returns a string with identifiable information on this widget.                                                                                                                                          def   execute_binding (self, key:  Any , ignore_any:  bool  =  False ) ->  bool :                                

The easiest way to use it is by running ptg -i or ptg --inspect with a fully qualified name. This will create an Inspector object for the given name, and print it.

You can also give the same function an expression to evaluate. This might be useful if you want to know the type & methods of an object that is the result of some function or method.

The more general way to access the API is by using the inspect function from within Python. You can give it any object, and it will give you as much information as it can found out from the signature & source code. You can also play around with an interactive version of the tool by running ptg --app inspect, which will give you a nice UI to play around with.

docs/src/inspect2.py ══════════════════════════════════════════════════════════════════════════════════════════════════ ║                                                Inspector                                               ║ ║  ────────────────────────────────────────────────────────────────────────────────────────────────  ║ ║                                                                                                     ║ ║  ──────────────────────────────────────────────────────────────────────────────────────────────  ║ ║  │                                    pytermgui.widgets.boxes.Box                                   │  ║ ║  │            Located in  /Users/lapis/Code/Projects/pytermgui/pytermgui/widgets/boxes.py            │  ║ ║  ──────────────────────────────────────────────────────────────────────────────────────────────  ║ ║  class   Box (lines:  list [ str ], content_char:  str  = x):                                                ║ ║       Class for defining border & corner styles                                                      ║ ║                                                                                                     ║ ║       `lines` should be `list[str]` of length 3, such as:                                            ║ ║                                                                                                     ║ ║       ```python3                                                                                     ║ ║       lines = [                                                                                      ║ ║           ".---.",                                                                                   ║ ║           "| x |",                                                                                   ║ ║           "`---`",                                                                                   ║ ║       ]                                                                                              ║ ║       ```                                                                                            ║ ║                                                                                                     ║ ║       The length of individual lines is arbitrary, only limitation is                                ║ ║       that the top & bottom border characters should occur most often in                             ║ ║       their respective lines.                                                                        ║ ║                                                                                                     ║ ║       You can set corners to be of any length, their end is calculated by                            ║ ║       finding the index of the most often occuring character, which is assumed                       ║ ║       to be the border character.                                                                    ║ ║                                                                                                     ║ ║       Top & bottom borders are currently limited in length to 1, but sides                           ║ ║       operate similarly to corners. They are separated by finding the index                          ║ ║       of the fill char from the start or end. The content char is "x" by                             ║ ║       default, however it can be set to anything else by giving the "content_char"                   ║ ║       construction parameter.                                                                        ║ ║                                                                                                     ║ ║       As such, this:                                                                                 ║ ║                                                                                                     ║ ║       ```python3                                                                                     ║ ║       boxes.Box(                                                                                     ║ ║          [                                                                                           ║ ║              "corner1 ________________ corner2",                                                     ║ ║              "xleft   ################ rightxx",                                                     ║ ║              "corner3 ---------------- corner4",                                                     ║ ║          ],                                                                                          ║ ║          content_char="#",                                                                           ║ ║       )                                                                                              ║ ║       ```                                                                                            ║ ║                                                                                                     ║ ║       Will result in:                                                                                ║ ║                                                                                                     ║ ║       ```python3                                                                                     ║ ║       Box(                                                                                           ║ ║           borders=['xleft   ', '_', ' rightxx', '-'],                                                ║ ║           corners=['corner1 ', ' corner2', ' corner4', 'corner3 ']                                   ║ ║       )                                                                                              ║ ║       ```                                                                                            ║ ║                                                                                                    ║ ║      def   debug (self) ->  str :                                                                         ║ ║           Return identifiable information about object                                                ║ ║                                                                                                    ║ ║      def   set_chars_of (self, cls_or_obj:  WidgetType ) ->  WidgetType :                                   ║ ║           Set border & corner chars of cls_or_obj to self values                                      ║ ║                                                                                                     ║ ║  ──────────────────────────────────────────────────────────────────────────────────────────────  ║ ║  │  boxes.Box                                                                                      │  ║ ║  ──────────────────────────────────────────────────────────────────────────────────────────────  ║ ══════════════════════════════════════════════════════════════════════════════════════════════════   ══════════════════════════════════════════════════════════════════════════════════════════════════ ║                                                Inspector                                               ║ ║  ────────────────────────────────────────────────────────────────────────────────────────────────  ║ ║                                                                                                     ║ ║  ──────────────────────────────────────────────────────────────────────────────────────────────  ║ ║  │                                    pytermgui.widgets.boxes.Box                                   │  ║ ║  │            Located in  /Users/lapis/Code/Projects/pytermgui/pytermgui/widgets/boxes.py            │  ║ ║  ──────────────────────────────────────────────────────────────────────────────────────────────  ║ ║  class   Box (lines:  list [ str ], content_char:  str  = x):                                                ║ ║       Class for defining border & corner styles                                                      ║ ║                                                                                                     ║ ║       `lines` should be `list[str]` of length 3, such as:                                            ║ ║                                                                                                     ║ ║       ```python3                                                                                     ║ ║       lines = [                                                                                      ║ ║           ".---.",                                                                                   ║ ║           "| x |",                                                                                   ║ ║           "`---`",                                                                                   ║ ║       ]                                                                                              ║ ║       ```                                                                                            ║ ║                                                                                                     ║ ║       The length of individual lines is arbitrary, only limitation is                                ║ ║       that the top & bottom border characters should occur most often in                             ║ ║       their respective lines.                                                                        ║ ║                                                                                                     ║ ║       You can set corners to be of any length, their end is calculated by                            ║ ║       finding the index of the most often occuring character, which is assumed                       ║ ║       to be the border character.                                                                    ║ ║                                                                                                     ║ ║       Top & bottom borders are currently limited in length to 1, but sides                           ║ ║       operate similarly to corners. They are separated by finding the index                          ║ ║       of the fill char from the start or end. The content char is "x" by                             ║ ║       default, however it can be set to anything else by giving the "content_char"                   ║ ║       construction parameter.                                                                        ║ ║                                                                                                     ║ ║       As such, this:                                                                                 ║ ║                                                                                                     ║ ║       ```python3                                                                                     ║ ║       boxes.Box(                                                                                     ║ ║          [                                                                                           ║ ║              "corner1 ________________ corner2",                                                     ║ ║              "xleft   ################ rightxx",                                                     ║ ║              "corner3 ---------------- corner4",                                                     ║ ║          ],                                                                                          ║ ║          content_char="#",                                                                           ║ ║       )                                                                                              ║ ║       ```                                                                                            ║ ║                                                                                                     ║ ║       Will result in:                                                                                ║ ║                                                                                                     ║ ║       ```python3                                                                                     ║ ║       Box(                                                                                           ║ ║           borders=['xleft   ', '_', ' rightxx', '-'],                                                ║ ║           corners=['corner1 ', ' corner2', ' corner4', 'corner3 ']                                   ║ ║       )                                                                                              ║ ║       ```                                                                                            ║ ║                                                                                                    ║ ║      def   debug (self) ->  str :                                                                         ║ ║           Return identifiable information about object                                                ║ ║                                                                                                    ║ ║      def   set_chars_of (self, cls_or_obj:  WidgetType ) ->  WidgetType :                                   ║ ║           Set border & corner chars of cls_or_obj to self values                                      ║ ║                                                                                                     ║ ║  ──────────────────────────────────────────────────────────────────────────────────────────────  ║ ║  │  boxes.Box                                                                                      │  ║ ║  ──────────────────────────────────────────────────────────────────────────────────────────────  ║ ══════════════════════════════════════════════════════════════════════════════════════════════════