Ubuntu的模糊时钟

很久以前,我有一个时钟设置,用于在面板应用程序中说出早晨,白天,傍晚,夜晚等时间。 广泛的中风,不是非常具体,它可能是一个KDE桌面。 我现在在Ubuntu Mate,有没有办法在配合面板中得到这个模糊的时间描述?

Mate 其他Ubuntu变体的文字/说话时钟

虽然这个问题最初是关于Ubuntu Mate的 ,幸运的是,从15.10开始, 指标也可用于Mate 。 因此,下面的答案至少适用于UnityMate以及Xubuntu上的(测试过)。

用于更改设置的GUI仍然要遵循(处理它),但我测试了下面的指标至少20小时,并且(正如预期的那样)它完成了工作而没有错误。

选项

该指标提供以下选项:

  • 显示文字时间

    在此处输入图像描述

  • 显示文字“日区”( 夜晚早晨白天晚上

    在此处输入图像描述

  • 显示上午/下午

    在此处输入图像描述

  • 一次显示所有这些(或三者的任意组合)

    在此处输入图像描述

  • 说出每一刻钟的时间(需要espeak

  • 可选地,时间显示模糊 ; 四分之一,例如
    10:43 – > quarter to eleven

脚本,模块和图标

解决方案存在脚本,单独的模块和图标,您需要将其存储在同一个目录中

图标:

在此处输入图像描述

右键单击它并将其保存为(完全) indicator_icon.png

模块:

这是生成文本时间和所有其他显示信息的模块。 复制代码,将其(再次, 确切地tcalc.py与上面的图标一起保存在同一个目录中

 #!/usr/bin/env python3 import time # --- set starttime of morning, day, evening, night (whole hrs) limits = [6, 9, 18, 21] # --- periods = ["night", "morning", "day", "evening", "night"] def __fig(n): singles = [ "midnight", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "quarter", "sixteen", "seventeen", "eighteen", "nineteen", ] tens = ["twenty", "half"] if n < 20: return singles[n] else: if n%10 == 0: return tens[int((n/10)-2)] else: fst = tens[int(n/10)-2] lst = singles[int(str(n)[-1])] return fst+"-"+lst def __fuzzy(currtime): minutes = round(currtime[1]/5)*5 if minutes == 60: currtime[1] = 0 currtime[0] = currtime[0] + 1 else: currtime[1] = minutes currtime[0] = 0 if currtime[0] == 24 else currtime[0] return currtime def textualtime(fuzz): currtime = [int(n) for n in time.strftime("%H %M %S").split()] currtime = __fuzzy(currtime) if fuzz == True else currtime speak = True if currtime[1]%15 == 0 else False period = periods[len([n for n in limits if currtime[0] >= n])] # define am / pm if currtime[0] >= 12: daytime = "pm" if currtime[0] == 12: if currtime[1] > 30: currtime[0] = currtime[0] - 12 else: currtime[0] = currtime[0] - 12 else: daytime = "am" # convert time to textual time if currtime[1] == 0: t = __fig(currtime[0])+" o'clock" if currtime[0] != 0 else __fig(currtime[0]) elif currtime[1] > 30: t = __fig((60 - currtime[1]))+" to "+__fig(currtime[0]+1) else: t = __fig(currtime[1])+" past "+__fig(currtime[0]) return [t, period, daytime, currtime[2], speak] 

剧本:

这是实际指标。 复制代码,将其作为moderntimes.py与上面的图标和模块一起保存在同一个目录中

 #!/usr/bin/env python3 import os import signal import subprocess import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk, AppIndicator3, GObject import time from threading import Thread import tcalc # --- define what to show: # showtime = textual time, daytime = am/pm period = "night"/"morning"/day"/"evening" # speak = speak out time every quarter, fuzzy = round time on 5 minutes showtime = True; daytime = False; period = True; speak = True; fuzzy = True class Indicator(): def __init__(self): self.app = 'about_time' path = os.path.dirname(os.path.abspath(__file__)) self.indicator = AppIndicator3.Indicator.new( self.app, os.path.abspath(path+"/indicator_icon.png"), AppIndicator3.IndicatorCategory.OTHER) self.indicator.set_status(AppIndicator3.IndicatorStatus.ACTIVE) self.indicator.set_menu(self.create_menu()) self.update = Thread(target=self.get_time) self.update.setDaemon(True) self.update.start() def get_time(self): # the first loop is 0 seconds, the next loop is 60 seconds, # in phase with computer clock loop = 0; timestring1 = "" while True: time.sleep(loop) tdata = tcalc.textualtime(fuzzy) timestring2 = tdata[0] loop = (60 - tdata[3])+1 mention = (" | ").join([tdata[item[1]] for item in [ [showtime, 0], [period, 1], [daytime, 2] ]if item[0] == True]) if all([ tdata[4] == True, speak == True, timestring2 != timestring1, ]): subprocess.Popen(["espeak", '"'+timestring2+'"', "-s", "130"]) # [4] edited GObject.idle_add( self.indicator.set_label, mention, self.app, priority=GObject.PRIORITY_DEFAULT ) timestring1 = timestring2 def create_menu(self): menu = Gtk.Menu() item_quit = Gtk.MenuItem('Quit') item_quit.connect('activate', self.stop) menu.append(item_quit) menu.show_all() return menu def stop(self, source): Gtk.main_quit() Indicator() GObject.threads_init() signal.signal(signal.SIGINT, signal.SIG_DFL) Gtk.main() 

如何使用

  1. 脚本需要espeak

     sudo apt-get install espeak 
  2. 将上面的所有三个文件复制到同一个目录中,完全按脚本,模块和图标名称命名

  3. 脚本的头部( moderntimes.py )中,定义应显示哪些信息以及如何显示。 只需在行中设置TrueFalse

     # --- define what to show: # time = textual time, daytime = am/pm period = "night"/"morning"/day"/"evening" # speak = speak out time every quarter, fuzzy = round time on 5 minutes showtime = True; daytime = False; period = True; speak = False; fuzzy = True 
  4. 模块的头部,您可以更改从晚上白天傍晚晚上开始的时间:

     # --- set starttime of morning, day, evening, night (whole hrs) limits = [6, 9, 18, 21] # --- 

    暂时不要触摸脚本中的任何其他内容:)

  5. Ubuntu Mate用户需要在其系统上启用指标:选择系统>首选项>外观>配合调整>界面>“启用指标”

    在此处输入图像描述

  6. 使用以下命令运行指示器:

     python3 /path/to/moderntimes.py 

从启动应用程序运行它

请记住,如果从启动应用程序运行该命令,在许多情况下,您需要添加一些中断,尤其是(以及其他)指标:

 /bin/bash -c "sleep 15 && python3 /path/to/moderntimes.py" 

笔记

  • 毫无疑问,脚本将在未来几天内多次更改/更新。 我特别喜欢反馈的一件事是将数字时间转换为文本时间的“风格”。 它现在的方式:

    • 整个小时,例如:

       six o'clock 
    • 一小时后不到30分钟,例如

       twenty past eleven 
    • 一小时后30分钟,例如:

       half past five 
    • 更多30分钟,例如:

       twenty to five 
    • 提到quarter 15分钟,例如:

       quarter past six 
    • exception是午夜,不是zero ,而是midnight ,例如:

       quarter past midnight 
  • 由于在第一次检查循环之后,循环在计算机时钟上自动同步,因此该脚本非常低效。 因此,脚本每分钟只检查一次显示时间/编辑时间,其余时间hibernate。


编辑

根据今天(2016-4-9),可提供一个抛光版本的ppa。 从ppa安装:

 sudo apt-add-repository ppa:vlijm/abouttime sudo apt-get update sudo apt-get install abouttime 

与上面的脚本版本相比,此版本中的日期更改,现在它是:

 morning 6:00-12:00 afternoon 12:00-18:00 evening 18:00-24:00 night 24:00-6:00 

…并且指示器具有在白天更改图标的选项:
上午/下午/晚上/晚上在此处输入图像描述 在此处输入图像描述 在此处输入图像描述 在此处输入图像描述

如上所述,这个版本在Mate (来自原始问题) UnityXubuntu

在此处输入图像描述

如果你有Kubuntu(Plasma桌面Ubuntu发行版),你有一个名为“模糊时钟”的内置小部件 – 至少从14.04开始,或者很久以前等离子4已经出来了,它仍然在等离子5中如在Kubuntu 16.04中找到的。

模糊时钟可以设置为“准确”为五分钟增量,如读取模拟时钟(例如,“十点四”),但它也有三个“模糊”设置,其中一个给出“下午”等读数而且只是给了“周末!” (在星期天下午 – 我猜它明天会说“星期一”)。

我不知道模糊时钟是否可用于其他Ubuntu版本 – 我在我的系统上看到xfce(在Xubuntu中找到),但操作系统安装为Kubuntu,所以我不确定模糊时钟是否是原生于xfce以及KDE / Plasma,也不是它在Unity或Mate中可用。