Skip to content

Commit

Permalink
Merge branch 'fixup-documentation'
Browse files Browse the repository at this point in the history
  • Loading branch information
moses-palmer committed Jun 17, 2019
2 parents 1c30ec3 + fd584d1 commit b4167f4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
6 changes: 6 additions & 0 deletions README.rst
Expand Up @@ -2,3 +2,9 @@ pystray Package Documentation
=============================

This library allows you to create a *system tray icon*.

Supported platforms are *Linux* under *Xorg*, *GNOME* and *Ubuntu*, *macOS*
and *Windows*.

See `here <https://pystray.readthedocs.io/en/latest/>`_ for the full
documentation.
35 changes: 27 additions & 8 deletions docs/usage.rst
Expand Up @@ -95,7 +95,8 @@ A menu item has several attributes:
*text* and *action*
The menu item text and its associated action.

These are the only required attribute.
These are the only required attributes. Please see *submenu* below for
alternate interpretations of *action*.

*checked*
Whether the menu item is checked.
Expand All @@ -114,6 +115,8 @@ A menu item has several attributes:
If you want this to actually be togglable, you must pass a callable that
returns the current state::

from pystray import Icon as icon, Menu as menu, MenuItem as item

state = False

def on_clicked(icon, item):
Expand All @@ -122,8 +125,8 @@ A menu item has several attributes:

# Update the state in `on_clicked` and return the new state in
# a `checked` callable
Icon('test', create_image(), menu=Menu(
MenuItem(
icon('test', create_image(), menu=menu(
item(
'Checkable',
on_clicked,
checked=lambda item: state))).run()
Expand All @@ -134,6 +137,8 @@ A menu item has several attributes:
This is used only if ``checked`` is ``True`` or ``False``, and only has a
visual meaning. The menu has no concept of radio button groups::

from pystray import Icon as icon, Menu as menu, MenuItem as item

state = 0

def set_state(v):
Expand All @@ -149,8 +154,8 @@ A menu item has several attributes:

# Let the menu items be a callable returning a sequence of menu
# items to allow the menu to grow
Icon('test', create_image(), menu=Menu(lambda: (
MenuItem(
icon('test', create_image(), menu=menu(lambda: (
item(
'State %d' % i,
set_state(i),
checked=get_state(i),
Expand All @@ -172,9 +177,23 @@ A menu item has several attributes:
greyed out and cannot be activated.

*submenu*
The submenu, if any, that is attached to this menu item.

If this is set, the action will not be called.
The submenu, if any, that is attached to this menu item. Either a submenu
or an action can be passed as the second argument to the constructor.

The submenu must be an instance of :class:`Menu`::

from pystray import Icon as icon, Menu as menu, MenuItem as item

icon('test', create_image(), menu=menu(
item(
'With submenu',
menu(
item(
'Submenu item 1',
lambda icon, item: 1),
item(
'Submenu item 2',
lambda icon, item: 2))))).run()

Once created, menus and menu items cannot be modified. All attributes except for
the menu item callbacks can however be set to callables returning the current
Expand Down

0 comments on commit b4167f4

Please sign in to comment.