| 1 |
# Nagstamon - Nagios status monitor for your desktop |
| 2 |
# Copyright (C) 2008-2026 Henri Wahl <[email protected]> et al. |
| 3 |
# |
| 4 |
# This program is free software; you can redistribute it and/or modify |
| 5 |
# it under the terms of the GNU General Public License as published by |
| 6 |
# the Free Software Foundation; either version 2 of the License, or |
| 7 |
# (at your option) any later version. |
| 8 |
# |
| 9 |
# This program is distributed in the hope that it will be useful, |
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
# GNU General Public License for more details. |
| 13 |
# |
| 14 |
# You should have received a copy of the GNU General Public License |
| 15 |
# along with this program; if not, write to the Free Software |
| 16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
| 17 |
|
| 18 |
from Nagstamon.config import (conf, |
| 19 |
OS, |
| 20 |
OS_MACOS) |
| 21 |
from Nagstamon.qui.qt import (QObject, |
| 22 |
QPoint, |
| 23 |
Signal, |
| 24 |
Slot) |
| 25 |
from Nagstamon.qui.widgets.app import app |
| 26 |
from Nagstamon.servers import servers |
| 27 |
|
| 28 |
# make icon status in macOS dock accessible via NSApp, used by set_macos_dock_icon_visible() |
| 29 |
if OS == OS_MACOS: |
| 30 |
from AppKit import (NSApp, |
| 31 |
NSApplicationPresentationDefault, |
| 32 |
NSApplicationPresentationHideDock) |
| 33 |
|
| 34 |
|
| 35 |
class CheckServers(QObject): |
| 36 |
""" |
| 37 |
check if there are any servers configured and enabled |
| 38 |
""" |
| 39 |
# signal to emit if no server is configured or enabled |
| 40 |
checked = Signal(str) |
| 41 |
|
| 42 |
@Slot() |
| 43 |
def check(self): |
| 44 |
""" |
| 45 |
check if there are any servers configured and enabled |
| 46 |
""" |
| 47 |
# no server is configured |
| 48 |
if len(servers) == 0: |
| 49 |
# emit signal that no server is configured |
| 50 |
self.checked.emit('no_server') |
| 51 |
# no server is enabled |
| 52 |
elif len([x for x in conf.servers.values() if x.enabled is True]) == 0: |
| 53 |
# emit signal that no server is enabled |
| 54 |
self.checked.emit('no_server_enabled') |
| 55 |
|
| 56 |
|
| 57 |
def hide_macos_dock_icon(hide=False): |
| 58 |
""" |
| 59 |
small helper to make dock icon visible or not in macOS |
| 60 |
inspired by https://stackoverflow.com/questions/6796028/start-a-gui-process-in-mac-os-x-without-dock-icon |
| 61 |
""" |
| 62 |
if hide: |
| 63 |
NSApp.setActivationPolicy_(NSApplicationPresentationHideDock) |
| 64 |
else: |
| 65 |
NSApp.setActivationPolicy_(NSApplicationPresentationDefault) |
| 66 |
|
| 67 |
|
| 68 |
def get_screen_name(x, y): |
| 69 |
""" |
| 70 |
find out which screen the given coordinates belong to |
| 71 |
gives back 'None' if coordinates are out of any known screen |
| 72 |
""" |
| 73 |
# integerify these values as they *might* be strings |
| 74 |
x = int(x) |
| 75 |
y = int(y) |
| 76 |
|
| 77 |
# QApplication (using Qt5 and/or its Python binding on RHEL/CentOS 7) has no attribute 'screenAt' |
| 78 |
try: |
| 79 |
screen = app.screenAt(QPoint(x, y)) |
| 80 |
del x, y |
| 81 |
if screen: |
| 82 |
return screen.name |
| 83 |
else: |
| 84 |
return None |
| 85 |
except: |
| 86 |
return None |
| 87 |
|
| 88 |
|
| 89 |
def get_screen_geometry(screen_name): |
| 90 |
""" |
| 91 |
set screen for fullscreen |
| 92 |
""" |
| 93 |
for screen in app.screens(): |
| 94 |
if screen.name() == screen_name: |
| 95 |
return screen.geometry() |
| 96 |
|
| 97 |
# if screen_name didn't match available use primary screen |
| 98 |
return app.primaryScreen().geometry() |
| 99 |
|
| 100 |
|
| 101 |
# to be used in nagstamon.py and qui/widgets/dialogs/settings.py |
| 102 |
check_servers = CheckServers() |