Compare commits

...

4 Commits

Author SHA1 Message Date
deltragon fe2212f96c
Merge 1ebcfa2bb8 into 00c33908a3 2024-02-27 12:24:04 -05:00
aerowolf 00c33908a3
Translated using Weblate (Chinese (Simplified))
Currently translated at 100.0% (116 of 116 strings)

Translation: Safe Eyes/Translations
Translate-URL: https://hosted.weblate.org/projects/safe-eyes/translations/zh_Hans/
2024-02-21 11:01:57 +01:00
deltragon 1ebcfa2bb8
port to Gtk.Application
Gtk.main() and Gtk.main_quit() are dropped in gtk4 in favor of
subclassing Gtk.Application.

This commit also moves argument handling from a separate thread to
GtkApplication.do_startup().
2024-01-02 13:19:53 +01:00
deltragon f45b83cfe6
fix deprecations 2024-01-02 13:19:40 +01:00
4 changed files with 66 additions and 64 deletions

View File

@ -25,9 +25,7 @@ import locale
import logging
import signal
import sys
from threading import Timer
import gi
import psutil
from safeeyes import utility
from safeeyes.model import Config
@ -35,9 +33,6 @@ from safeeyes.safeeyes import SafeEyes
from safeeyes.safeeyes import SAFE_EYES_VERSION
from safeeyes.rpc import RPCClient
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
gettext.install('safeeyes', utility.LOCALE_PATH)
@ -68,22 +63,6 @@ def __running():
return False
def __evaluate_arguments(args, safe_eyes):
"""
Evaluate the arguments and execute the operations.
"""
if args.about:
utility.execute_main_thread(safe_eyes.show_about)
elif args.disable:
utility.execute_main_thread(safe_eyes.disable_safeeyes)
elif args.enable:
utility.execute_main_thread(safe_eyes.enable_safeeyes)
elif args.settings:
utility.execute_main_thread(safe_eyes.show_settings)
elif args.take_break:
utility.execute_main_thread(safe_eyes.take_break)
def main():
"""
Start the Safe Eyes.
@ -147,10 +126,8 @@ def main():
sys.exit(0)
elif not args.quit:
logging.info("Starting Safe Eyes")
safe_eyes = SafeEyes(system_locale, config)
safe_eyes = SafeEyes(system_locale, config, args)
safe_eyes.start()
Timer(1.0, lambda: __evaluate_arguments(args, safe_eyes)).start()
Gtk.main()
if __name__ == '__main__':

View File

@ -6,8 +6,8 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"POT-Creation-Date: \n"
"PO-Revision-Date: 2021-10-10 05:05+0000\n"
"Last-Translator: Frank.wu <me@wuzhiping.top>\n"
"PO-Revision-Date: 2024-02-21 10:01+0000\n"
"Last-Translator: aerowolf <aerowolf@tom.com>\n"
"Language-Team: Chinese (Simplified) <https://hosted.weblate.org/projects/"
"safe-eyes/translations/zh_Hans/>\n"
"Language: zh_CN\n"
@ -15,23 +15,23 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=1; plural=0;\n"
"X-Generator: Weblate 4.9-dev\n"
"X-Generator: Weblate 5.5-dev\n"
# Short break
msgid "Tightly close your eyes"
msgstr "闭上您的眼睛休息一会"
msgstr "闭上眼睛休息一下"
# Short break
msgid "Roll your eyes a few times to each side"
msgstr "向两边各翻几下眼睛"
msgstr "左右转动眼球"
# Short break
msgid "Rotate your eyes in clockwise direction"
msgstr "按顺时针方向旋转你的眼球"
msgstr "顺时针方向转动眼球"
# Short break
msgid "Rotate your eyes in counterclockwise direction"
msgstr "按逆时针方向旋转你的眼球"
msgstr "逆时针方向转动眼球"
# Short break
msgid "Blink your eyes"
@ -39,11 +39,11 @@ msgstr "眨眨眼"
# Short break
msgid "Focus on a point in the far distance"
msgstr "望远:将视线聚焦到远处物体上"
msgstr "远眺:看看尽可能远的远处"
# Short break
msgid "Have some water"
msgstr "喝点水"
msgstr "喝点水"
# Long break
msgid "Walk for a while"
@ -51,7 +51,7 @@ msgstr "站起来走走"
# Long break
msgid "Lean back at your seat and relax"
msgstr "靠在椅背上休息一"
msgstr "靠在椅背上休息一"
# Commandline arg description
msgid "show the about dialog"
@ -59,15 +59,15 @@ msgstr "显示“关于”对话框"
# Commandline arg description
msgid "disable the currently running safeeyes instance"
msgstr "禁用当前正在运行的Safe Eyes"
msgstr "暂停当前正在运行的Safe Eyes"
# Commandline arg description
msgid "enable the currently running safeeyes instance"
msgstr "启用当前正在运行的Safe Eyes"
msgstr "恢复当前正在运行的Safe Eyes"
# Commandline arg description
msgid "quit the running safeeyes instance and exit"
msgstr "退出正在运行的Safe Eeyes"
msgstr "退出Safe Eeyes"
# Commandline arg description
msgid "show the settings dialog"
@ -79,17 +79,17 @@ msgstr "以调试模式运行Safe Eyes"
# Commandline arg description
msgid "print the status of running safeeyes instance and exit"
msgstr "打印Safe Eyes运行状态后退出"
msgstr "显示Safe Eyes运行状态后退出"
# Status message
msgid "Safe Eyes is not running"
msgstr "Safe Eyes 尚未运行"
msgstr "Safe Eyes 没有运行"
# RPC not enabled message
msgid ""
"Safe Eyes is running without an RPC server. Turn it on to use command-line "
"arguments."
msgstr "Safe Eyes 正在没有RPC服务器的情况下运行。打开以使用命令行参数。"
msgstr "Safe Eyes 正在没有RPC服务器的情况下运行。打开RPC服务器可以使用命令行参数。"
# About dialog
msgid "Close"
@ -106,7 +106,7 @@ msgstr ""
# About dialog
msgid "License"
msgstr "许可"
msgstr "许可"
# Break screen
msgid "Skip"
@ -142,7 +142,7 @@ msgstr "以随机顺序显示休息"
# Settings dialog
msgid "Strict break (No way to skip breaks)"
msgstr "坚持休息(无法跳过)"
msgstr "坚持休息(不允许跳过)"
# Settings dialog
msgid "Allow postponing breaks"
@ -150,7 +150,7 @@ msgstr "允许推迟休息"
# Settings dialog
msgid "Persist the internal state"
msgstr "持内部状态"
msgstr "持内部状态"
# Settings dialog
msgid "Use RPC server to receive runtime commands"
@ -414,11 +414,11 @@ msgstr "在通知区域显示托盘图标"
#: plugins/trayicon
msgid "Show next break time in tray icon"
msgstr "在托盘图标显示下次休息时间"
msgstr "在托盘图标显示下次休息时间"
#: plugins/trayicon
msgid "Allow disabling Safe Eyes"
msgstr "允许禁用Safe Eyes"
msgstr "允许暂停Safe Eyes"
#: plugins/trayicon
msgid "About"
@ -426,19 +426,19 @@ msgstr "关于"
#: plugins/trayicon
msgid "Disable Safe Eyes"
msgstr "禁用 Safe Eyes"
msgstr "暂停 Safe Eyes"
#: plugins/trayicon
msgid "Disabled until %s"
msgstr "禁用软件直到 %s"
msgstr "暂停,直到 %s"
#: plugins/trayicon
msgid "Disabled until restart"
msgstr "禁用软件直到重启"
msgstr "暂停,直到重启"
#: plugins/trayicon
msgid "Enable Safe Eyes"
msgstr "启用 Safe Eyes"
msgstr "恢复 Safe Eyes"
#: plugins/trayicon
msgid "For %d Hour"
@ -457,7 +457,7 @@ msgstr[0] "%d 秒"
#: plugins/trayicon
msgid "Next break at %s"
msgstr "下次休息在 %s"
msgstr "下次休息在 %s"
#: plugins/trayicon
msgid "No Breaks Available"

View File

@ -38,17 +38,21 @@ from safeeyes.core import SafeEyesCore
from safeeyes.ui.settings_dialog import SettingsDialog
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
from gi.repository import Gtk, Gio
SAFE_EYES_VERSION = "2.1.6"
class SafeEyes:
class SafeEyes(Gtk.Application):
"""
This class represents a runnable Safe Eyes instance.
"""
def __init__(self, system_locale, config):
def __init__(self, system_locale, config, cli_args):
super().__init__(
application_id="io.github.slgobinath.SafeEyes",
flags=Gio.ApplicationFlags.IS_SERVICE
)
self.active = False
self.break_screen = None
self.safe_eyes_core = None
@ -58,6 +62,7 @@ class SafeEyes:
self.settings_dialog_active = False
self.rpc_server = None
self._status = ''
self.cli_args = cli_args
# Initialize the Safe Eyes Context
self.context['version'] = SAFE_EYES_VERSION
@ -98,6 +103,9 @@ class SafeEyes:
self.context['api']['postpone'] = self.safe_eyes_core.postpone
self.context['api']['get_break_time'] = self.safe_eyes_core.get_break_time
self.plugins_manager.init(self.context, self.config)
self.hold()
atexit.register(self.persist_session)
def start(self):
@ -114,6 +122,22 @@ class SafeEyes:
self.safe_eyes_core.start()
self.handle_system_suspend()
self.run()
def do_startup(self):
Gtk.Application.do_startup(self)
if self.cli_args.about:
self.show_about()
elif self.cli_args.disable:
self.disable_safeeyes()
elif self.cli_args.enable:
self.enable_safeeyes()
elif self.cli_args.settings:
self.show_settings()
elif self.cli_args.take_break:
self.take_break()
def show_settings(self):
"""
Listen to tray icon Settings action and send the signal to Settings dialog.
@ -144,9 +168,8 @@ class SafeEyes:
self.plugins_manager.exit()
self.__stop_rpc_server()
self.persist_session()
Gtk.main_quit()
# Exit all threads
os._exit(0)
super().quit()
def handle_suspend_callback(self, sleeping):
"""

View File

@ -151,12 +151,14 @@ class BreakScreen:
# Lock the keyboard
utility.start_thread(self.__lock_keyboard)
screen = Gtk.Window().get_screen()
no_of_monitors = screen.get_n_monitors()
display = Gdk.Display.get_default()
screen = display.get_default_screen()
no_of_monitors = display.get_n_monitors()
logging.info("Show break screens in %d display(s)", no_of_monitors)
for monitor in range(no_of_monitors):
monitor_gemoetry = screen.get_monitor_geometry(monitor)
for monitor_num in range(no_of_monitors):
monitor = display.get_monitor(monitor_num)
monitor_gemoetry = monitor.get_geometry()
x = monitor_gemoetry.x
y = monitor_gemoetry.y
@ -165,7 +167,7 @@ class BreakScreen:
builder.connect_signals(self)
window = builder.get_object("window_main")
window.set_title("SafeEyes-" + str(monitor))
window.set_title("SafeEyes-" + str(monitor_num))
lbl_message = builder.get_object("lbl_message")
lbl_count = builder.get_object("lbl_count")
lbl_widget = builder.get_object("lbl_widget")
@ -188,7 +190,7 @@ class BreakScreen:
# Add the buttons
if self.enable_postpone:
# Add postpone button
btn_postpone = Gtk.Button(_('Postpone'))
btn_postpone = Gtk.Button.new_with_label(_('Postpone'))
btn_postpone.get_style_context().add_class('btn_postpone')
btn_postpone.connect('clicked', self.on_postpone_clicked)
btn_postpone.set_visible(True)
@ -196,7 +198,7 @@ class BreakScreen:
if not self.strict_break:
# Add the skip button
btn_skip = Gtk.Button(_('Skip'))
btn_skip = Gtk.Button.new_with_label(_('Skip'))
btn_skip.get_style_context().add_class('btn_skip')
btn_skip.connect('clicked', self.on_skip_clicked)
btn_skip.set_visible(True)
@ -222,7 +224,7 @@ class BreakScreen:
window.resize(monitor_gemoetry.width, monitor_gemoetry.height)
window.stick()
window.set_keep_above(True)
window.fullscreen()
window.fullscreen_on_monitor(screen, monitor_num)
window.present()
# In other desktop environments, move the window after present
window.move(x, y)