• Stars
    star
    202
  • Rank 193,691 (Top 4 %)
  • Language
    Python
  • License
    BSD 3-Clause "New...
  • Created about 12 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Windows system tray icon

infi.systray

This module implements a Windows system tray icon with a right-click context menu.

Installation

To install infi.systray, run:

pip install infi.systray

Alternatively, you can use easy_install.

Usage

Creating an icon with one option in the context menu:

from infi.systray import SysTrayIcon
def say_hello(systray):
    print "Hello, World!"
menu_options = (("Say Hello", None, say_hello),)
systray = SysTrayIcon("icon.ico", "Example tray icon", menu_options)
systray.start()

The first parameter to SysTrayIcon is a path to the icon to show in the systray. If the icon is not found, or if None is specified, a default system icon will be displayed. The second parameter is the hover text to show when the mouse is hovered over the systray icon. The traybar will run in its own thread, so the using script can continue to run.

The icon and/or hover text can be updated using the update() method with the appropriate hover_text or icon keyword argument:

for item in ['item1', 'item2', 'item3']:
    systray.update(hover_text=item)
    do_something(item)

To destroy the icon when the program ends, call

systray.shutdown()

SysTrayIcon can be used as a context manager to start and shutdown the tray, which also prevents hung tray threads should the parent thread fail or otherwise not close the tray process:

with SysTrayIcon(icon, hover_text) as systray:
    for item in ['item1', 'item2', 'item3']:
        systray.update(hover_text=item)
        do_something(item)

A "Quit" command is always appended to the end of the icon context menu, after the menu options specified by the user. To perform operations when Quit is selected, pass "on_quit=callback" as a parameter, e.g.:

def on_quit_callback(systray):
    program.shutdown()
systray = SysTrayIcon("icon.ico", "Example tray icon", menu_options, on_quit=on_quit_callback)

When the user double-clicks the systray icon, the first option specified in menu_options will be executed. The default command may be changed to a different option by setting the parameter "default_menu_index", e.g.:

systray = SysTrayIcon("icon.ico", "Example tray icon", menu_options, default_menu_index=2)

menu_options must be a list of 3-tuples. Each 3-tuple specifies a context menu options. The first value in each tuple is the context menu string. Some versions of Windows can show icons next to each option in the context menu. This icon can be specified in the second value of the tuples. If None is passed, no icon is displayed for the option. The third value is the command to execute when the context menu is selected by the user.

It is possible to create sub-menus in the context menu by recursively passing a list of 3-tuple options as the third value of an option, instead of passing a callback function. e.g.

from infi.systray import SysTrayIcon
hover_text = "SysTrayIcon Demo"
def hello(sysTrayIcon):
    print "Hello World."
def simon(sysTrayIcon):
    print "Hello Simon."
def bye(sysTrayIcon):
    print 'Bye, then.'
def do_nothing(sysTrayIcon):
    pass
menu_options = (('Say Hello', "hello.ico", hello),
                ('Do nothing', None, do_nothing),
                ('A sub-menu', "submenu.ico", (('Say Hello to Simon', "simon.ico", simon),
                                               ('Do nothing', None, do_nothing),
                                              ))
               )
sysTrayIcon = SysTrayIcon("main.ico", hover_text, menu_options, on_quit=bye, default_menu_index=1)
sysTrayIcon.start()

Note that in the previous examples, if no code is executed after calling systray.start(), the main thread will exit and the icon thread will continue to exist until the Quit option is selected. In order to catch keyboard interrupts, some code must be written that will call systray.shutdown when the program should quit. Using SysTrayIcon as a context manager automates the start and shutdown of the tray.

This module can only be used in Windows systems, otherwise the import statement will fail.

Credit

This module is adapted from an implementation by Simon Brunning, which in turn was adapted from Mark Hammond's win32gui_taskbar.py and win32gui_menu.py demos from PyWin32.

Checking out the code

To run this code from the repository for development purposes, run the following:

easy_install -U infi.projector
projector devenv build

More Repositories

1

infi.clickhouse_orm

A Python library for working with the ClickHouse database (https://clickhouse.yandex/)
Python
411
star
2

infi.docopt_completion

Python
108
star
3

infi.clickhouse_fdw

A PostgreSQL foreign data wrapper for ClickHouse
Python
53
star
4

relocatable-python3

Python
38
star
5

relocatable-python

build system for building a portable python interpreter
Python
24
star
6

infi.projector

Python
20
star
7

gitpy

Python bindings for the Git source control system
Python
19
star
8

infi.devicemanager

Python bindings to Windows Device Manager's APIs
Python
15
star
9

dowser

Python
14
star
10

infi.pyvmomi_wrapper

Python
13
star
11

infinitrace

A trace solution for C/C++ code on Linux, optimized for high trace volumes and low latency
C
12
star
12

slimfastq

Fast, efficient, lossless compression of fastq files
C++
11
star
13

infi.asi

asynchronous SCSI interface
Python
11
star
14

infi.diskmanagement

Windows Disk Management wrapping in Python
Python
10
star
15

infinisdk

Python SDK for INFINIDAT storage products
Python
9
star
16

infi.iscsiapi

Crossplaform python module to perform basic iSCSI operations
Python
9
star
17

infi.storagemodel

A high-level library for traversing the OS storage model.
Python
7
star
18

infi.traceback

better tracebacks
Python
6
star
19

infi.wioctl

Python library for doing IOCTLs on Windows
Python
6
star
20

infi.recipe.application_packager

Python
5
star
21

infi.instruct

declarative structure marshalling
Python
5
star
22

infi.execute

Python
5
star
23

infi.pyutils

Misc python utilities
Python
5
star
24

infi.win32service

wrapping library for windows services in Python
Python
5
star
25

infinibox-csi-driver

Go
5
star
26

infinidat-k8s-provisioner

Go
4
star
27

loggest

High performance logging library and utilities for Rust
Rust
4
star
28

fscmp

Directory/file comparison utility
Rust
4
star
29

infi.django_rest_utils

Python
3
star
30

infi.parted

Python library for adding/removing disk partitions in linux
Python
3
star
31

infi.exceptools

a mechanism for chaining exceptions, compatible with Python 2.x
Python
3
star
32

infi.jira_cli

Python
3
star
33

infi.hbaapi

wrapping library for hbaapi in Python
Python
3
star
34

infi.rpc

Python
2
star
35

infinidat_openstack

Python
2
star
36

infi.dtypes.hctl

HCTL-related datatypes in Python
Python
2
star
37

infi.conf

Yet another python configuration library
Python
2
star
38

infinidat-k8s-installer

Go
2
star
39

cronorc

Cron job monitoring
Python
2
star
40

infi.multipathtools

python bindings to multipath-tools daemon
Python
2
star
41

infi.reboot

a mechanism for Python applications to request host reboots
Python
2
star
42

infi.registry

a Python dictionary-like interface to the Windows Registry
Python
2
star
43

infi.pypi_manager

scripts for copying packages to djangopypi servers
Python
2
star
44

infi.credentials_store

Python
2
star
45

infi.os_info

Python
2
star
46

infi.dtypes.wwn

WWN datatype in Python
Python
2
star
47

intercom.js

A client-side cross-window message broadcast library built on top of the HTML5 localStorage API.
JavaScript
2
star
48

infi.amqp

Simple AMQP publisher and consumer, with auto-reconnection.
Python
2
star
49

infi.cwrap

wrapping library for calling c functions from shared libraries on Windows in Python
Python
2
star
50

infi.clickhouse_django_rest_utils

This project contains classes and utils making the django rest framwork compatible to work against a Clickhouse ORM.
Python
2
star
51

sentinels

https://pypi.org/project/sentinels/
Python
1
star
52

storage_interfaces

Abstract classes for representing storage-related objects
Python
1
star
53

infi.logging

Python
1
star
54

infi.git_mirror

Scripts for replicating git repositories
Python
1
star
55

infi.tracing

C
1
star
56

infi.srm_client

Python
1
star
57

infi.pkgmgr

Linux package management in Python
Python
1
star
58

pystick

Python
1
star
59

infi.hello

hello world
Python
1
star
60

sublime-infinidat

Infinidat plug-in for Sublime Text 3
Python
1
star
61

infi.recipe.python

a recipe for downloading and packing portable builds of Python
Python
1
star
62

infi.sysv_service

Python
1
star
63

infi.wmpio

Windows MPIO Management in Python
Python
1
star
64

ttyrec

C
1
star
65

smb.cli

smbmgr is a cli interface to manage MS smb cluster with InfiniBox integration
Python
1
star
66

infi.mountoolinux

Python library for posix mounts
Python
1
star
67

infi.recipe.console_scripts

Python
1
star
68

infi.app_repo

Python
1
star
69

tripleo-deployment-configs

Files required for RHEL OpenStack Platform Cinder integration for Infinidat
Dockerfile
1
star
70

infi.unittest

Various extensions to the unittest module
Python
1
star
71

infi.pysync

rsync-like utility to help sync dev files to a remote machine
Python
1
star
72

infi.recipe.template.version

an extension to collective.recipe.template
Python
1
star
73

api_object_schema

Utilities for defining schemas of Pythonic objects interacting with external APIs
Python
1
star
74

infi.wmi

monkeypatched fork of comptypes to support faster WMI access
Python
1
star
75

infi.run_as_root

Python decorator for ensuring that you're running as root
Python
1
star
76

infi.winver

Windows version information in Python
Python
1
star
77

infi.dtypes.iqn

IQN datatype in Python
Python
1
star
78

infi.monotonic_time

monotonic time
Python
1
star
79

ansible-infinidat-collection

A set of Ansible modules that allow simple, but powerful, idempotent interactions with Infinidat InfiniBoxes.
Python
1
star
80

infi.winapi.file_version_information

Python module for file versioning API in Windows
Python
1
star