Pyside QMenuView

PyPI version Build Status Downloads per month Coverage License Documentation

PySide view for menues

Features

  • MenuView class which creates submenus/actions based on a model.
  • Supports modelReset, rowsInserted, rowsRemoved and dataChanged signals of the model.
  • Supports icon, text, iconText, toolTip, checked, whatsThis, statusTip, enabled
  • Easy to extend and customize.

Welcome to Pyside QMenuView‘s documentation!

Contents:

Installation

At the command line either via easy_install or pip:

$ easy_install qmenuview
$ pip install qmenuview

Or, if you have virtualenvwrapper installed:

$ mkvirtualenv qmenuview
$ pip install qmenuview

Usage

To use QMenuView:

from PySide import QtGui
import qmenuview

app = QtGui.QApplication([])

view = qmenuview.MenuView('RootMenuTitle')

# create a model
m = QtGui.QStandardItemModel()
for i in range(10):
    m.appendRow(QtGui.QStandardItem("Delicious dish no. %s" % i))

view.model = m  # now the submenus are created

# insert new menus
m.appendRow(QtGui.QStandardItem("New fancy dish"))
# the view will also handle trees
rootitem = QtGui.QStandardItem("root")
lvl1item = QtGui.QStandardItem("Level 1")
lvl2item = QtGui.QStandardItem("Level 2")
rootitem.appendRow(lvl1item)
lvl1item.appendRow(lvl2item)
m.appendRow(rootitem)

# remove menus
m.removeRow(0)

# Menus are automatically updated
rootitem.setText("Newroot")

view.show()

app.exec_()

Signals

To handle signals connect to the views signals:

from PySide import QtGui
import qmenuview

app = QtGui.QApplication([])

view = qmenuview.MenuView('RootMenuTitle')

# create a model
m = QtGui.QStandardItemModel()
for i in range(10):
    m.appendRow(QtGui.QStandardItem("Delicious dish no. %s" % i))

view.model = m  # now the submenus are created

def triggered_cb(index, checked=False):
     item = index.model().itemForIndex(index)
     print('Item triggered', item)
menuview.action_triggered.connect(triggered_cb)

See qmenuview.MenuView.action_triggered, qmenuview.MenuView.action_toggled, qmenuview.MenuView.action_hovered.

Customization

There are multiple things you can customize.

Columns

You can specify which columns of the model you want to use for the data:

import qmenuview
view = qmenuview.MenuView()

view.text_column = 2  # use third column for action text
view.icon_column = 1  # use second column for icon
view.icontext_column = -1  # don't set the icontext
Advanced Data Control

If you want to have more control over how the data is applied to actions, have a look at the qmenuview.MenuView.setdataargs. It is a list of qmenuview.view.SetDataArgs. Each entry defines a column and a role for the data to query, a method to convert the data and a name of a action method to apply the data.

So you can remove or add entries to the list. The following example will make the view query data from column 0 with PySide.QtCore.Qt.FontRole. There is no need to convert the data, so the convertion function is None. setFont will specify that PySide.QtGui.QAction.setFont() will be used to apply the data:

from PySide import QtCore
import qmenuview
view = qmenuview.MenuView()
fontargs = qmenuview.SetDataArgs('setFont', 0, QtCore.Qt.FontRole, None)
view.setdataargs.append(fontargs)
Custom classes

If you want to use custom menu or action classes subclass the view and override qmenuview.MenuView.create_menu() or qmenuview.MenuView.create_action():

from PySide import QtGui
import qmenuview

class SuperAction(QtGui.QAction): pass

class SuperMenuView(qmenuview.MenuView):
    def create_action(self, parent):
        return SuperAction(parent)

Reference

Automatic generated Documenation by apidoc and autodoc.

qmenuview

Submodules
qmenuview.view
Classes
MenuView([title, parent]) A view that creates submenus based on a model.
SetDataArgs(setfunc, column, role, convertfunc) A container of arguments for setting attributes on an action.
Data
qmenuview.view.QtCore = <Mock id='139768670968656'>
qmenuview.view.QtGui = <Mock id='139768670968784'>
Module contents
Data
qmenuview.absolute_import = _Feature((2, 5, 0, 'alpha', 1), (3, 0, 0, 'alpha', 0), 16384)

Contributing

Contributions are welcome, and they are greatly appreciated! Every little bit helps, and credit will always be given.

You can contribute in many ways:

Types of Contributions

Report Bugs

Report bugs at https://github.com/storax/qmenuview/issues.

If you are reporting a bug, please include:

  • Your operating system name and version.
  • Any details about your local setup that might be helpful in troubleshooting.
  • Detailed steps to reproduce the bug.
Fix Bugs

Look through the GitHub issues for bugs. Anything tagged with “bug” is open to whoever wants to implement it.

Implement Features

Look through the GitHub issues for features. Anything tagged with “feature” is open to whoever wants to implement it.

Write Documentation

Pyside QMenuView could always use more documentation, whether as part of the official Pyside QMenuView docs, in docstrings, or even on the web in blog posts, articles, and such.

Submit Feedback

The best way to send feedback is to file an issue at https://github.com/storax/qmenuview/issues.

If you are proposing a feature:

  • Explain in detail how it would work.
  • Keep the scope as narrow as possible, to make it easier to implement.
  • Remember that this is a volunteer-driven project, and that contributions are welcome :)

Get Started!

Ready to contribute? Here’s how to set up qmenuview for local development.

  1. Fork the qmenuview repo on GitHub.

  2. Clone your fork locally:

    $ git clone git@github.com:your_name_here/qmenuview.git
    
  3. Create a branch for local development:

    $ git checkout -b name-of-your-bugfix-or-feature
    

Now you can make your changes locally.

  1. When you’re done making changes, check that your changes pass style and unit tests, including testing other Python versions with tox:

    $ tox
    

To get tox, just pip install it.

  1. Commit your changes and push your branch to GitHub:

    $ git add .
    $ git commit -m "Your detailed description of your changes."
    $ git push origin name-of-your-bugfix-or-feature
    
  2. Submit a pull request through the GitHub website.

Pull Request Guidelines

Before you submit a pull request, check that it meets these guidelines:

  1. The pull request should include tests.
  2. If the pull request adds functionality, the docs should be updated. Put your new functionality into a function with a docstring, and add the feature to the list in README.rst.
  3. The pull request should work for Python 2.6, 2.7, and 3.3, and for PyPy. Check https://travis-ci.org/storax/qmenuview under pull requests for active pull requests or run the tox command and make sure that the tests pass for all supported Python versions.

Tips

To run a subset of tests:

$ py.test test/test_qmenuview.py

Credits

Development Lead

Contributors

None yet. Why not be the first?

History

0.1.0 (2015-08-08)

  • First release on PyPI.

0.1.1 (2015-08-11)

  • Fix getting parents of action
  • Fix changing columns

0.1.4 (2015-08-11)

  • Fix removing all rows below root.

Feedback

If you have any suggestions or questions about Pyside QMenuView feel free to email me at zuber.david@gmx.de.

If you encounter any errors or problems with Pyside QMenuView, please let me know! Open an Issue at the GitHub https://github.com/storax/qmenuview main repository.

Indices and tables