Giter Site home page Giter Site logo

objbrowser's Introduction

objbrowser

Extensible Python object inspection tool implemented in Qt.

Displays objects as trees and allows you to inspect their attributes recursively (e.g. browse through a list of dictionaries). You can add your own inspection methods as new columns to the tree view, or as radio buttons to the details pane. Altering existing inspection methods is possible as well.

Installation:

First install PyQt or PySide2

The object browser automatically detects which Qt bindings are installed. If both bindings are installed it prefers PyQt over PySide. You can force the object browser to use a certain binding by setting the QT_API environment variable to pyqt5, pyqt4, or pyside2.

Then install the object browser with:

%> pip install objbrowser

or use the installer:

%> python setup.py install

User interface:

objbrowser screen shot

From the View menu you can select some extra columns, for instance the object's id column. This can also be done by right-clicking on the table header. An overview of the available columns, and their meanings, can be found in here.

Callable objects (typically functions, methods and classes) are displayed in blue. Objects that are an attribute of their parent (as opposed to a list element or dictionary item) are displayed in italics.

If Show callable attributes from the View menu is checked, objects that are callable and are an attribute are shown. Otherwise they are hidden.

If Show dunder attributes from the View menu is checked, objects that are attributes, and have a name that starts and ends with two underscores, are shown. Otherwise they are hidden.

The details pane at the bottom shows object properties that do not fit on one line, such as the docstrings and the output of various functions of the inspect module from the Python standard library.

Usage examples:

The first parameter is the object to be inspected. For example you can examine the dictionary with the local variables:

from objbrowser import browse
a = 67; pi = 3.1415 
browse(locals())

The second parameter can be the name of the object. In that case the object itself will be displayed in the root node.

browse(locals(), 'locals()')

By setting the show_callable_attributes and/or the show_dunder_attributes parameters you can override the settings from the View menu. The reset parameter resets the persistent window settings (e.g. size and position)

s1 = 'Hello'
s2 = 'World'

browse({'s1': s1, 's2': s2}, 
        show_callable_attributes = True,
        show_dunder_attributes = False, 
        reset = True)

Some complete examples can be found in the examples directory. E.g.:

objbrowser's People

Contributors

titusjan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

objbrowser's Issues

Error with Python 3.11 and PySide 6.4 and possible fix

Hello,

I've tried objbrowser with Python 3.11 and PySide 6.4, but throws following exception:

  File "C:\path\objbrowser\objectbrowser.py", line 275, in _setup_views
    self.button_group.buttonClicked[int].connect(self._change_details_field)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^
IndexError: Signature "buttonClicked(int)" not found for signal: "buttonClicked". Available candidates: "buttonClicked(QAbstractButton*)"

If i replace that with self.button_group.buttonClicked.connect(self._change_details_field) and it's running now without issues.

I've also replaced line 539 with self.button_group.buttonClicked.disconnect(self._change_details_field), or it throws the same error.

I have no idea about compatibility with other Pyside or Python versions for that fix ...

Python 3.10 Won't Run browse

Python 3.9 seems to work totally fine, but with Python 3.10 when calling the browse function:

Python 3.10.9 (main, Dec  7 2022, 01:11:56) [GCC 7.5.0]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.4.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: from objbrowser import browse

In [2]: browse({"Hello": 1})
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Input In [2], in <cell line: 1>()
----> 1 browse({"Hello": 1})

File ~/Git/hardware-tooling/venv-10/lib/python3.10/site-packages/objbrowser/__init__.py:45, in browse(*args, **kwargs)
     42 def browse(*args, **kwargs):
     43     """ Opens and executes an ObjectBrowser window
     44     """
---> 45     ObjectBrowser.browse(*args, **kwargs)

File ~/Git/hardware-tooling/venv-10/lib/python3.10/site-packages/objbrowser/objectbrowser.py:627, in ObjectBrowser.browse(cls, *args, **kwargs)
    624 logger.info("Using Python {}".format(PYTHON_VERSION))
    625 logger.info("Using {} (api {}, qtpy: {})".format(QT_API_NAME, QT_API, QTPY_VERSION))
--> 627 cls.create_browser(*args, **kwargs)
    628 exit_code = cls.execute()
    629 return exit_code

File ~/Git/hardware-tooling/venv-10/lib/python3.10/site-packages/objbrowser/objectbrowser.py:598, in ObjectBrowser.create_browser(cls, *args, **kwargs)
    594     logger.debug("Reusing existing QApplication instance")
    596 cls._q_app = q_app # keeping reference to prevent garbage collection. 
--> 598 object_browser = cls(*args, **kwargs)
    599 object_browser.show()
    600 object_browser.raise_()

File ~/Git/hardware-tooling/venv-10/lib/python3.10/site-packages/objbrowser/objectbrowser.py:107, in ObjectBrowser.__init__(self, obj, name, attribute_columns, attribute_details, show_callable_attributes, show_special_attributes, auto_refresh, refresh_rate, reset)
    105 assert self._refresh_rate > 0, "refresh_rate must be > 0. Got: {}".format(self._refresh_rate)
    106 self._refresh_timer = QtCore.QTimer(self)
--> 107 self._refresh_timer.setInterval(self._refresh_rate * 1000)
    108 self._refresh_timer.timeout.connect(self.refresh)
    110 # Update views with model

TypeError: setInterval(self, int): argument 1 has unexpected type 'float'

Version:
objbrowser==1.3.0
Tested on 3.9 and 3.10

addAction(self, action: typing.Optional[QAction]): argument 1 has unexpected type 'str'

I install PyQt6 and use this code:

from objbrowser import browse
a = 16; b = 'hello'
browse(locals())

It gives this error:

Traceback (most recent call last):
  File "D:\QC supplements\Code\Apps\Trấn Kỳ\test.py", line 3, in <module>
    browse(locals())
  File "C:\Users\ganuo\AppData\Local\Programs\Python\Python311\Lib\site-packages\objbrowser\__init__.py", line 45, in browse
    ObjectBrowser.browse(*args, **kwargs)     
  File "C:\Users\ganuo\AppData\Local\Programs\Python\Python311\Lib\site-packages\objbrowser\objectbrowser.py", line 627, in browse        
    cls.create_browser(*args, **kwargs)       
  File "C:\Users\ganuo\AppData\Local\Programs\Python\Python311\Lib\site-packages\objbrowser\objectbrowser.py", line 598, in create_browser
    object_browser = cls(*args, **kwargs)     
                     ^^^^^^^^^^^^^^^^^^^^     
  File "C:\Users\ganuo\AppData\Local\Programs\Python\Python311\Lib\site-packages\objbrowser\objectbrowser.py", line 99, in __init__       
    self._setup_menu()
  File "C:\Users\ganuo\AppData\Local\Programs\Python\Python311\Lib\site-packages\objbrowser\objectbrowser.py", line 202, in _setup_menu   
    file_menu.addAction("C&lose", self.close, "Ctrl+W")
TypeError: arguments did not match any overloaded call:
  addAction(self, icon: QIcon, text: Optional[str]): argument 1 has unexpected type 'str'   
  addAction(self, icon: QIcon, text: Optional[str], slot: PYQT_SLOT, type: Qt.ConnectionType = Qt.AutoConnection): argument 1 has unexpected type 'str'
  addAction(self, icon: QIcon, text: Optional[str], shortcut: Union[QKeySequence, QKeySequence.StandardKey, Optional[str], int]): argument 1 has unexpected type 'str'
  addAction(self, icon: QIcon, text: Optional[str], shortcut: Union[QKeySequence, QKeySequence.StandardKey, Optional[str], int], slot: PYQT_SLOT, type: Qt.ConnectionType = Qt.AutoConnection): argument 1 has unexpected type 'str'  
  addAction(self, text: Optional[str]): too many arguments
  addAction(self, text: Optional[str], shortcut: Union[QKeySequence, QKeySequence.StandardKey, Optional[str], int]): argument 2 has unexpected type 'builtin_function_or_method'        
  addAction(self, text: Optional[str], slot: PYQT_SLOT, type: Qt.ConnectionType = Qt.AutoConnection): argument 3 has unexpected type 'str'  addAction(self, text: Optional[str], shortcut: Union[QKeySequence, QKeySequence.StandardKey, Optional[str], int], slot: PYQT_SLOT, type: Qt.ConnectionType = Qt.AutoConnection): argument 2 has unexpected type 'builtin_function_or_method'
  addAction(self, action: typing.Optional[QAction]): argument 1 has unexpected type 'str' 

Why is that?

How to run browser without blocking the REPL

Hey there!
Thank you for this, it's extremely useful!

Still I'm trying to figure out how I can run the browser without blocking the REPL, so that I can check the dumped data for what I need and go on in the REPL with the window open as a reference if I need it again.

I'm a bit naive and don't know much about QT, is it possible to launch the browser in a separate thread or something similar so to have the REPL free to continue?

Thank you for time!

Feature request: search by key

Thank you for providing the object browser.
It'd nice to have a search field where one can look for specific methods and fields.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.