From 0777af89c47e8fe0f9fb5b49b565143f2aeb3ef7 Mon Sep 17 00:00:00 2001 From: Tuukka Ojala Date: Mon, 17 Apr 2017 15:00:32 +0300 Subject: [PATCH] Add a script for announcing the system's uptime. --- .../globalPlugins/resourceMonitor/__init__.py | 29 ++++++++++++++++++- buildVars.py | 2 +- readme.md | 3 +- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/addon/globalPlugins/resourceMonitor/__init__.py b/addon/globalPlugins/resourceMonitor/__init__.py index e2698d49..28c73cab 100644 --- a/addon/globalPlugins/resourceMonitor/__init__.py +++ b/addon/globalPlugins/resourceMonitor/__init__.py @@ -1,9 +1,10 @@ #Resource Monitor for NvDA #Presents basic info on CPU load, memory and disk usage, as well as battery information. -#Authors: Alex Hall (core mechanics and messages), Joseph Lee (internationalization), Beqa Gozalishvili (updated psutil to 0.6.1, and made needed changes to make code run). +#Authors: Alex Hall (core mechanics and messages), Joseph Lee (internationalization), Beqa Gozalishvili (updated psutil to 0.6.1, and made needed changes to make code run), Tuukka Ojala (uptime). # Copyright 2013-2017, released under GPL. import _winreg +from datetime import datetime import sys import os import globalPluginHandler @@ -173,6 +174,31 @@ def script_announceWinVer(self, gesture): # Translators: Input help mode message about Windows version command in Resource Monitor. script_announceWinVer.__doc__=_("Announces the version of Windows you are using.") + def getUptime(self): + bootTimestamp = psutil.boot_time() + if bootTimestamp == 0.0: + raise TypeError + uptime = datetime.now() - datetime.fromtimestamp(bootTimestamp) + hours, remainingMinutes = divmod(uptime.seconds, 3600) + minutes, seconds = divmod(remainingMinutes, 60) + hoursMinutesSeconds = "{hours:02}:{minutes:02}:{seconds:02}".format(hours=hours, minutes=minutes, seconds=seconds) + # Translators: The system's uptime + return _("{days} days, {hoursMinutesSeconds}").format(days=uptime.days, hoursMinutesSeconds=hoursMinutesSeconds) + + def script_announceUptime(self, gesture): + try: + uptime = self.getUptime() + if scriptHandler.getLastScriptRepeatCount() == 0: + ui.message(uptime) + else: + if api.copyToClip(uptime): + ui.message(self.RMCopyMessage) + except: + # Translators: Obtaining uptime failed + ui.message(_("Failed to get the system's uptime.")) + # Translators: Input help mode message about obtaining the system's uptime + script_announceUptime.__doc__=_("Announces the system's uptime.") + def script_announceResourceSummary(self, gesture): # Faster to build info on the fly rather than keep appending to a string. # Translators: presents the overall summary of resource usage, such as CPU load and RAM usage. @@ -200,4 +226,5 @@ def script_announceResourceSummary(self, gesture): "KB:NVDA+shift+4":"announceBatteryInfo", "KB:NVDA+shift+5":"announceRamInfo", "KB:NVDA+shift+6":"announceWinVer", + "kb:nvda+shift+7": "announceUptime", } diff --git a/buildVars.py b/buildVars.py index d264b52f..0358ef01 100644 --- a/buildVars.py +++ b/buildVars.py @@ -21,7 +21,7 @@ # version "addon_version" : "17.02", # Author(s) - "addon_author" : "Alex Hall , Joseph Lee , beqa gozalishvili and other NVDA contributors", + "addon_author" : "Alex Hall , Joseph Lee , beqa gozalishvili , Tuukka Ojala and other NVDA contributors", # URL for the add-on documentation support "addon_url" : "http://addons.nvda-project.org/", # Documentation file name diff --git a/readme.md b/readme.md index 4785686c..4035c595 100644 --- a/readme.md +++ b/readme.md @@ -1,6 +1,6 @@ [[!meta title="Resource Monitor"]] -* Authors: Alex Hall, Joseph Lee, beqa gozalishvili and other NVDA contributors +* Authors: Alex Hall, Joseph Lee, beqa gozalishvili, Tuukka Ojala and other NVDA contributors * Download [stable version][1] This plugin gives information about CPU load, memory usage and other resource usage information. @@ -13,6 +13,7 @@ This plugin gives information about CPU load, memory usage and other resource us * NVDA+Shift+3 Presents the used and total space of the static and removable drives. * NVDA+Shift+4 Presents battery percentage, charging status, remaining time (if not charging), and a warning if the battery is low or critical. * NVDA+Shift+6 Presents CPU Architecture 32/64-bit and Windows version and service pack numbers. +* NVDA+Shift+7 presents the system's uptime. If you have NvDA 2013.3 or later installed, you can change these shortcut keys.