Skip to content

Commit 02eb7d9

Browse files
committed
Merge branch 'fixup-general'
2 parents fb8b229 + 588988e commit 02eb7d9

File tree

7 files changed

+44
-31
lines changed

7 files changed

+44
-31
lines changed

lib/pystray/_base.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,9 @@ def run(self, setup=None):
176176
thread once the loop has started. It is passed the icon as its sole
177177
argument.
178178
179-
If not specified, a simple setup function setting :attr:`visible` to
180-
``True`` is used. If you specify a custom setup function, you must
181-
explicitly set this attribute.
179+
If not specified, a simple setup function setting :attr:`visible`
180+
to ``True`` is used. If you specify a custom setup function, you
181+
must explicitly set this attribute.
182182
"""
183183
def setup_handler():
184184
self.__queue.get()
@@ -247,8 +247,10 @@ def _mark_ready(self):
247247
is called.
248248
"""
249249
self._running = True
250-
self.update_menu()
251-
self.__queue.put(True)
250+
try:
251+
self.update_menu()
252+
finally:
253+
self.__queue.put(True)
252254

253255
def _handler(self, callback):
254256
"""Generates a callback handler.
@@ -384,8 +386,8 @@ def checked(self):
384386
"""Whether this item is checked.
385387
386388
This can be either ``True``, which implies that the item is checkable
387-
and checked, ``False``, which implies that the item is checkable but not
388-
checked, and ``None`` for uncheckable items.
389+
and checked, ``False``, which implies that the item is checkable but
390+
not checked, and ``None`` for uncheckable items.
389391
390392
Depending on platform, uncheckable items may be rendered differently
391393
from unchecked items.
@@ -396,8 +398,8 @@ def checked(self):
396398
def radio(self):
397399
"""Whether this item is a radio button.
398400
399-
This is only used for checkable items. It is always set to ``False`` for
400-
uncheckable items.
401+
This is only used for checkable items. It is always set to ``False``
402+
for uncheckable items.
401403
"""
402404
if self.checked is not None:
403405
return self._radio(self)
@@ -442,8 +444,8 @@ def _assert_action(self, action):
442444
less than the expected number of arguments, a wrapper will be
443445
returned.
444446
445-
:raises ValueError: if ``action`` requires more than the expected number
446-
of arguments
447+
:raises ValueError: if ``action`` requires more than the expected
448+
number of arguments
447449
448450
:return: a callable
449451
"""

lib/pystray/_darwin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,8 @@ def _create_menu(self, descriptors, callbacks):
202202
return nsmenu
203203

204204
def _create_menu_item(self, descriptor, callbacks):
205-
"""Creates a :class:`AppKit.NSMenuItem` from a :class:`pystray.MenuItem`
206-
instance.
205+
"""Creates a :class:`AppKit.NSMenuItem` from a
206+
:class:`pystray.MenuItem` instance.
207207
208208
:param descriptor: The menu item descriptor.
209209

lib/pystray/_gtk.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ def __init__(self, *args, **kwargs):
2727
super(Icon, self).__init__(*args, **kwargs)
2828

2929
self._status_icon = Gtk.StatusIcon.new()
30-
self._status_icon.connect('activate', self._on_status_icon_activate)
31-
self._status_icon.connect('popup-menu', self._on_status_icon_popup_menu)
30+
self._status_icon.connect(
31+
'activate', self._on_status_icon_activate)
32+
self._status_icon.connect(
33+
'popup-menu', self._on_status_icon_popup_menu)
3234

3335
if self.icon:
3436
self._update_icon()

lib/pystray/_util/gtk.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,13 @@ def _run(self):
6464
self._notifier = notify_dbus.Notifier()
6565
self._mark_ready()
6666

67-
# Make sure that we do not inhibit ctrl+c
68-
signal.signal(signal.SIGINT, signal.SIG_DFL)
67+
# Make sure that we do not inhibit ctrl+c; this is only possible from
68+
# the main thread
69+
try:
70+
signal.signal(signal.SIGINT, signal.SIG_DFL)
71+
except ValueError:
72+
pass
73+
6974
try:
7075
self._loop.run()
7176
except:

lib/pystray/_util/win32.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,8 @@ def _err(result, func, arguments):
347347
ChangeWindowMessageFilterEx.errcheck = _err
348348

349349
except KeyError:
350-
def ChangeWindowMessageFilterEx(hWnd, message, action, pCHangeFilterStruct):
350+
def ChangeWindowMessageFilterEx(
351+
hWnd, message, action, pCHangeFilterStruct):
351352
"""A dummy implementation of ``ChangeWindowMessageFilterEx`` always
352353
returning ``TRUE``.
353354

lib/pystray/_win32.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -238,22 +238,22 @@ def _create_window(self, atom):
238238
win32.GetModuleHandle(None),
239239
None)
240240

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

247247
def _create_menu(self, descriptors, callbacks):
248-
"""Creates a :class:`ctypes.wintypes.HMENU` from a :class:`pystray.Menu`
249-
instance.
248+
"""Creates a :class:`ctypes.wintypes.HMENU` from a
249+
:class:`pystray.Menu` instance.
250250
251251
:param descriptors: The menu descriptors. If this is falsy, ``None`` is
252252
returned.
253253
254254
:param callbacks: A list to which a callback is appended for every menu
255-
item created. The menu item IDs correspond to the items in this list
256-
plus one.
255+
item created. The menu item IDs correspond to the items in this
256+
list plus one.
257257
258258
:return: a menu
259259
"""
@@ -265,7 +265,7 @@ def _create_menu(self, descriptors, callbacks):
265265
hmenu = win32.CreatePopupMenu()
266266
for i, descriptor in enumerate(descriptors):
267267
# Append the callbacks before creating the menu items to ensure
268-
# that the first item get the ID 1
268+
# that the first item gets the ID 1
269269
callbacks.append(self._handler(descriptor))
270270
menu_item = self._create_menu_item(descriptor, callbacks)
271271
win32.InsertMenuItem(hmenu, i, True, ctypes.byref(menu_item))
@@ -279,8 +279,8 @@ def _create_menu_item(self, descriptor, callbacks):
279279
:param descriptor: The menu item descriptor.
280280
281281
:param callbacks: A list to which a callback is appended for every menu
282-
item created. The menu item IDs correspond to the items in this list
283-
plus one.
282+
item created. The menu item IDs correspond to the items in this
283+
list plus one.
284284
285285
:return: a :class:`pystray._util.win32.MENUITEMINFO`
286286
"""

lib/pystray/_xorg.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ def _show(self):
142142
try:
143143
self._assert_docked()
144144
except AssertionError:
145-
# There is no systray selection owner, so we cannot dock; ignore and
146-
# dock later
145+
# There is no systray selection owner, so we cannot dock; ignore
146+
# and dock later
147147
self._log.error(
148148
'Failed to dock icon', exc_info=True)
149149

@@ -305,7 +305,8 @@ def on_client_message(event):
305305

306306
# Create the atoms and a mapping from atom to actual implementation
307307
atoms = [
308-
self._display.intern_atom('_PYSTRAY_%s' % original.__name__.upper())
308+
self._display.intern_atom(
309+
'_PYSTRAY_%s' % original.__name__.upper())
309310
for original in args]
310311
handlers = {
311312
atom: wrapper(original)
@@ -333,10 +334,12 @@ def _create_window(self):
333334
-1, -1, 1, 1, 0, screen.root_depth,
334335
event_mask=Xlib.X.ExposureMask | Xlib.X.StructureNotifyMask,
335336
window_class=Xlib.X.InputOutput)
337+
flags = (
338+
Xlib.Xutil.PPosition | Xlib.Xutil.PSize | Xlib.Xutil.PMinSize)
336339
window.set_wm_class('%sSystemTrayIcon' % self.name, self.name)
337340
window.set_wm_name(self.title)
338341
window.set_wm_normal_hints(
339-
flags=(Xlib.Xutil.PPosition | Xlib.Xutil.PSize | Xlib.Xutil.PMinSize),
342+
flags=flags,
340343
min_width=24,
341344
min_height=24)
342345

0 commit comments

Comments
 (0)