Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,19 @@ flatpak install flathub io.github.slgobinath.SafeEyes
Ensure to meet the following dependencies:

- gir1.2-notify-0.7
- gir1.2-gtk-4.0
- python3-babel
- python3-croniter
- python3-gi
- python3-psutil
- python3-packaging
- python3-xlib
- xprintidle (optional)
- wlrctl (wayland optional)
- python3-pywayland (optional for KDE/other wayland)
- xprintidle (optional for X11)
- wlrctl (optional for wayland/wlroots)
- Python 3.10+

**To install Safe Eyes:**
**To install Safe Eyes from PyPI:**

```bash
sudo pip3 install safeeyes
Expand Down
3 changes: 0 additions & 3 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
target-version = "py310"

# gettext
builtins = ["_"]

[lint]
select = ["E", "W", "F", "D2", "D3", "D4"]
ignore = [
Expand Down
23 changes: 3 additions & 20 deletions safeeyes/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,18 @@
"""

import argparse
import gettext
import locale
import logging
import signal
import sys

import psutil
from safeeyes import utility
from safeeyes import utility, translations
from safeeyes.translations import translate as _
from safeeyes.model import Config
from safeeyes.safeeyes import SafeEyes
from safeeyes.safeeyes import SAFE_EYES_VERSION
from safeeyes.rpc import RPCClient

gettext.install("safeeyes", utility.LOCALE_PATH)


def __running():
"""Check if SafeEyes is already running."""
Expand Down Expand Up @@ -68,21 +65,7 @@ def __running():

def main():
"""Start the Safe Eyes."""
system_locale = gettext.translation(
"safeeyes",
localedir=utility.LOCALE_PATH,
languages=[utility.system_locale(), "en_US"],
fallback=True,
)
system_locale.install()
try:
# locale.bindtextdomain is required for Glade files
locale.bindtextdomain("safeeyes", utility.LOCALE_PATH)
except AttributeError:
logging.warning(
"installed python's gettext module does not support locale.bindtextdomain."
" locale.bindtextdomain is required for Glade files"
)
system_locale = translations.setup()

parser = argparse.ArgumentParser(prog="safeeyes")
group = parser.add_mutually_exclusive_group()
Expand Down
1 change: 1 addition & 0 deletions safeeyes/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from gi.repository import Gtk

from safeeyes import utility
from safeeyes.translations import translate as _


class Break:
Expand Down
1 change: 1 addition & 0 deletions safeeyes/plugins/donotdisturb/dependency_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from safeeyes import utility
from safeeyes.translations import translate as _


def validate(plugin_config, plugin_settings):
Expand Down
1 change: 1 addition & 0 deletions safeeyes/plugins/healthstats/dependency_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from safeeyes import utility
from safeeyes.translations import translate as _


def validate(plugin_config, plugin_settings):
Expand Down
1 change: 1 addition & 0 deletions safeeyes/plugins/healthstats/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import croniter
import datetime
import logging
from safeeyes.translations import translate as _

context = None
session = None
Expand Down
1 change: 1 addition & 0 deletions safeeyes/plugins/limitconsecutiveskipping/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"""Limit how many breaks can be skipped or postponed in a row."""

import logging
from safeeyes.translations import translate as _

context = None
no_of_skipped_breaks = 0
Expand Down
1 change: 1 addition & 0 deletions safeeyes/plugins/notification/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import gi
from safeeyes.model import BreakType
from safeeyes.translations import translate as _

gi.require_version("Notify", "0.7")
from gi.repository import Notify
Expand Down
1 change: 1 addition & 0 deletions safeeyes/plugins/smartpause/dependency_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from safeeyes import utility
from safeeyes.translations import translate as _


def validate(plugin_config, plugin_settings):
Expand Down
1 change: 1 addition & 0 deletions safeeyes/plugins/trayicon/dependency_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

from safeeyes import utility
from safeeyes.model import PluginDependency
from safeeyes.translations import translate as _

import gi

Expand Down
1 change: 1 addition & 0 deletions safeeyes/plugins/trayicon/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from gi.repository import Gio, GLib
import logging
from safeeyes import utility
from safeeyes.translations import translate as _
import threading
import time
import typing
Expand Down
1 change: 1 addition & 0 deletions safeeyes/safeeyes.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from safeeyes.ui.required_plugin_dialog import RequiredPluginDialog
from safeeyes.model import State, RequiredPluginException
from safeeyes.rpc import RPCServer
from safeeyes.translations import translate as _
from safeeyes.plugin_manager import PluginManager
from safeeyes.core import SafeEyesCore
from safeeyes.ui.settings_dialog import SettingsDialog
Expand Down
51 changes: 51 additions & 0 deletions safeeyes/translations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env python
# Safe Eyes is a utility to remind you to take break frequently
# to protect your eyes from eye strain.

# Copyright (C) 2024 Mel Dafert <[email protected]>

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Translation setup and helpers."""

import locale
import logging
import gettext
from safeeyes import utility

_translations = gettext.NullTranslations()


def setup():
global _translations
_translations = gettext.translation(
"safeeyes",
localedir=utility.LOCALE_PATH,
languages=[utility.system_locale(), "en_US"],
fallback=True,
)
try:
# locale.bindtextdomain is required for Glade files
locale.bindtextdomain("safeeyes", utility.LOCALE_PATH)
except AttributeError:
logging.warning(
"installed python's gettext module does not support locale.bindtextdomain."
" locale.bindtextdomain is required for Glade files"
)

return _translations


def translate(message: str) -> str:
"""Translate the message using the current translator."""
return _translations.gettext(message)
1 change: 1 addition & 0 deletions safeeyes/ui/about_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import os

from safeeyes import utility
from safeeyes.translations import translate as _

ABOUT_DIALOG_GLADE = os.path.join(utility.BIN_DIRECTORY, "glade/about_dialog.glade")

Expand Down
1 change: 1 addition & 0 deletions safeeyes/ui/break_screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import gi
from safeeyes import utility
from safeeyes.translations import translate as _
import Xlib
from Xlib.display import Display
from Xlib import X
Expand Down
1 change: 1 addition & 0 deletions safeeyes/ui/required_plugin_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

from safeeyes import utility
from safeeyes.model import PluginDependency
from safeeyes.translations import translate as _

REQUIRED_PLUGIN_DIALOG_GLADE = os.path.join(
utility.BIN_DIRECTORY, "glade/required_plugin_dialog.glade"
Expand Down
1 change: 1 addition & 0 deletions safeeyes/ui/settings_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import gi
from safeeyes import utility
from safeeyes.model import Config, PluginDependency
from safeeyes.translations import translate as _

gi.require_version("Gtk", "4.0")
from gi.repository import Gtk, Gio
Expand Down
3 changes: 2 additions & 1 deletion safeeyes/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
from gi.repository import GLib
from gi.repository import GdkPixbuf
from packaging.version import parse
from safeeyes.translations import translate as _

BIN_DIRECTORY = os.path.dirname(os.path.realpath(__file__))
HOME_DIRECTORY = os.environ.get("HOME") or os.path.expanduser("~")
Expand Down Expand Up @@ -533,7 +534,7 @@ def initialize_platform():
logging.error("Failed to create desktop entry at %s" % desktop_entry)

# Add links for all icons
for path, _, filenames in os.walk(SYSTEM_ICONS):
for path, _dirnames, filenames in os.walk(SYSTEM_ICONS):
for filename in filenames:
system_icon = os.path.join(path, filename)
local_icon = os.path.join(
Expand Down