Skip to content

Commit

Permalink
Merge branch 'fixup-general'
Browse files Browse the repository at this point in the history
  • Loading branch information
moses-palmer committed Oct 11, 2021
2 parents fb8b229 + 588988e commit 02eb7d9
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 31 deletions.
24 changes: 13 additions & 11 deletions lib/pystray/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,9 @@ def run(self, setup=None):
thread once the loop has started. It is passed the icon as its sole
argument.
If not specified, a simple setup function setting :attr:`visible` to
``True`` is used. If you specify a custom setup function, you must
explicitly set this attribute.
If not specified, a simple setup function setting :attr:`visible`
to ``True`` is used. If you specify a custom setup function, you
must explicitly set this attribute.
"""
def setup_handler():
self.__queue.get()
Expand Down Expand Up @@ -247,8 +247,10 @@ def _mark_ready(self):
is called.
"""
self._running = True
self.update_menu()
self.__queue.put(True)
try:
self.update_menu()
finally:
self.__queue.put(True)

def _handler(self, callback):
"""Generates a callback handler.
Expand Down Expand Up @@ -384,8 +386,8 @@ def checked(self):
"""Whether this item is checked.
This can be either ``True``, which implies that the item is checkable
and checked, ``False``, which implies that the item is checkable but not
checked, and ``None`` for uncheckable items.
and checked, ``False``, which implies that the item is checkable but
not checked, and ``None`` for uncheckable items.
Depending on platform, uncheckable items may be rendered differently
from unchecked items.
Expand All @@ -396,8 +398,8 @@ def checked(self):
def radio(self):
"""Whether this item is a radio button.
This is only used for checkable items. It is always set to ``False`` for
uncheckable items.
This is only used for checkable items. It is always set to ``False``
for uncheckable items.
"""
if self.checked is not None:
return self._radio(self)
Expand Down Expand Up @@ -442,8 +444,8 @@ def _assert_action(self, action):
less than the expected number of arguments, a wrapper will be
returned.
:raises ValueError: if ``action`` requires more than the expected number
of arguments
:raises ValueError: if ``action`` requires more than the expected
number of arguments
:return: a callable
"""
Expand Down
4 changes: 2 additions & 2 deletions lib/pystray/_darwin.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ def _create_menu(self, descriptors, callbacks):
return nsmenu

def _create_menu_item(self, descriptor, callbacks):
"""Creates a :class:`AppKit.NSMenuItem` from a :class:`pystray.MenuItem`
instance.
"""Creates a :class:`AppKit.NSMenuItem` from a
:class:`pystray.MenuItem` instance.
:param descriptor: The menu item descriptor.
Expand Down
6 changes: 4 additions & 2 deletions lib/pystray/_gtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ def __init__(self, *args, **kwargs):
super(Icon, self).__init__(*args, **kwargs)

self._status_icon = Gtk.StatusIcon.new()
self._status_icon.connect('activate', self._on_status_icon_activate)
self._status_icon.connect('popup-menu', self._on_status_icon_popup_menu)
self._status_icon.connect(
'activate', self._on_status_icon_activate)
self._status_icon.connect(
'popup-menu', self._on_status_icon_popup_menu)

if self.icon:
self._update_icon()
Expand Down
9 changes: 7 additions & 2 deletions lib/pystray/_util/gtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,13 @@ def _run(self):
self._notifier = notify_dbus.Notifier()
self._mark_ready()

# Make sure that we do not inhibit ctrl+c
signal.signal(signal.SIGINT, signal.SIG_DFL)
# Make sure that we do not inhibit ctrl+c; this is only possible from
# the main thread
try:
signal.signal(signal.SIGINT, signal.SIG_DFL)
except ValueError:
pass

try:
self._loop.run()
except:
Expand Down
3 changes: 2 additions & 1 deletion lib/pystray/_util/win32.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,8 @@ def _err(result, func, arguments):
ChangeWindowMessageFilterEx.errcheck = _err

except KeyError:
def ChangeWindowMessageFilterEx(hWnd, message, action, pCHangeFilterStruct):
def ChangeWindowMessageFilterEx(
hWnd, message, action, pCHangeFilterStruct):
"""A dummy implementation of ``ChangeWindowMessageFilterEx`` always
returning ``TRUE``.
Expand Down
18 changes: 9 additions & 9 deletions lib/pystray/_win32.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,22 +238,22 @@ def _create_window(self, atom):
win32.GetModuleHandle(None),
None)

# On Vista+, we must explicitly opt-in to receive WM_TASKBARCREATED when
# running with escalated privileges
# On Vista+, we must explicitly opt-in to receive WM_TASKBARCREATED
# when running with escalated privileges
win32.ChangeWindowMessageFilterEx(
hwnd, win32.WM_TASKBARCREATED, win32.MSGFLT_ALLOW, None)
return hwnd

def _create_menu(self, descriptors, callbacks):
"""Creates a :class:`ctypes.wintypes.HMENU` from a :class:`pystray.Menu`
instance.
"""Creates a :class:`ctypes.wintypes.HMENU` from a
:class:`pystray.Menu` instance.
:param descriptors: The menu descriptors. If this is falsy, ``None`` is
returned.
:param callbacks: A list to which a callback is appended for every menu
item created. The menu item IDs correspond to the items in this list
plus one.
item created. The menu item IDs correspond to the items in this
list plus one.
:return: a menu
"""
Expand All @@ -265,7 +265,7 @@ def _create_menu(self, descriptors, callbacks):
hmenu = win32.CreatePopupMenu()
for i, descriptor in enumerate(descriptors):
# Append the callbacks before creating the menu items to ensure
# that the first item get the ID 1
# that the first item gets the ID 1
callbacks.append(self._handler(descriptor))
menu_item = self._create_menu_item(descriptor, callbacks)
win32.InsertMenuItem(hmenu, i, True, ctypes.byref(menu_item))
Expand All @@ -279,8 +279,8 @@ def _create_menu_item(self, descriptor, callbacks):
:param descriptor: The menu item descriptor.
:param callbacks: A list to which a callback is appended for every menu
item created. The menu item IDs correspond to the items in this list
plus one.
item created. The menu item IDs correspond to the items in this
list plus one.
:return: a :class:`pystray._util.win32.MENUITEMINFO`
"""
Expand Down
11 changes: 7 additions & 4 deletions lib/pystray/_xorg.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ def _show(self):
try:
self._assert_docked()
except AssertionError:
# There is no systray selection owner, so we cannot dock; ignore and
# dock later
# There is no systray selection owner, so we cannot dock; ignore
# and dock later
self._log.error(
'Failed to dock icon', exc_info=True)

Expand Down Expand Up @@ -305,7 +305,8 @@ def on_client_message(event):

# Create the atoms and a mapping from atom to actual implementation
atoms = [
self._display.intern_atom('_PYSTRAY_%s' % original.__name__.upper())
self._display.intern_atom(
'_PYSTRAY_%s' % original.__name__.upper())
for original in args]
handlers = {
atom: wrapper(original)
Expand Down Expand Up @@ -333,10 +334,12 @@ def _create_window(self):
-1, -1, 1, 1, 0, screen.root_depth,
event_mask=Xlib.X.ExposureMask | Xlib.X.StructureNotifyMask,
window_class=Xlib.X.InputOutput)
flags = (
Xlib.Xutil.PPosition | Xlib.Xutil.PSize | Xlib.Xutil.PMinSize)
window.set_wm_class('%sSystemTrayIcon' % self.name, self.name)
window.set_wm_name(self.title)
window.set_wm_normal_hints(
flags=(Xlib.Xutil.PPosition | Xlib.Xutil.PSize | Xlib.Xutil.PMinSize),
flags=flags,
min_width=24,
min_height=24)

Expand Down

0 comments on commit 02eb7d9

Please sign in to comment.