web-dev-qa-db-ja.com

メニューバーに現在のタイムゾーンニアタイムインジケーターを表示する方法は?

Ubuntu 16.10のメニューバーに時刻と日付に近い現在のタイムゾーンを表示するにはどうすればよいですか?これは他のバージョンにも関連するはずです。これは非常に不足している機能であり、これがないと簡単に混乱する可能性があります。 「金12月23日20:35:05(ヨーロッパ/キエフ)」のようなものを取得したいと思います。

また、「2016年12月23日金曜日-20:35:05(ヨーロッパ/キエフ)」のように、その文字列を任意にカスタマイズできると便利です。ありがとうございました!

更新

日付形式の変更方法 を参照することができます

gsettings set com.canonical.indicator.datetime time-format "'custom'"

gsettings set com.canonical.indicator.datetime custom-time-format "'%a, %d.%m.%y - %H:%M:%S (%Z)'"

これにより、システムの時刻と日付のインジケータが

2016年12月23日金曜日-20:35:05(EET)

ご覧のとおり、タイムゾーン名以外はすべて問題ありません。タイムゾーンをTime&Date settings> Clock> Choose Locationsに設定します。次に、端末にtimedatectlと書くと、

タイムゾーン:ヨーロッパ/キエフ(EET、+ 0200)

したがって、タイムゾーン名にはいくつかのオプションがあり、どちらを使用するかを決定するのはstrftime関数であり、フォーマット文字列を渡すだけでタイムゾーン名「Europe/Kiev」(「EET」または「+0200」のみ)を取得する方法。

タイムゾーンの名前形式を選択する方法はありますか?

Sergのスクリプトを使用して、システムインジケータの横に優先名を配置できますか?

ありがとう!

3
vstepaniuk

前書き

以下に示すインジケータは、トップパネルに現在のタイムゾーンを表示します。仕組みはかなり簡単です。タイムゾーン設定は/etc/timezoneファイルで設定されます。すべてのインジケーターは、そのファイルを読み取り、必要に応じて表示される情報を更新します。

以下のソースコードを~/bin/timezone_indicatorとして保存し、chmod +x ~/bin/timezone_indicatorを実行して実行可能にし、~/bin/timezone_indicatorとして実行します。自動的にログインするたびに起動するようにしたい場合は、[スタートアップアプリケーション]メニューを開き、コマンドの1つとしてインジケーターへのフルパスを追加します。

enter image description here

https://askubuntu.com/a/524362/295286 に示すように、タイムゾーンの変更を自由にテストしてください。

スクリプトソース

GitHub でも利用可能:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

#
# Author: Serg Kolo , <[email protected]>
# Date: December 23, 2016
# Purpose: Indicator that displays timezone
# Written for:  https://askubuntu.com/q/863952/295286
# Tested on: Ubuntu 16.04 LTS
#
# Licensed under The MIT License (MIT).
# See included LICENSE file or the notice below.
#
# Copyright © 2016 Sergiy Kolodyazhnyy
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import gi
gi.require_version('AppIndicator3', '0.1')
from gi.repository import GLib as glib
from gi.repository import AppIndicator3 as appindicator
from gi.repository import Gtk as gtk
from time import gmtime
import os

class TimezoneIndicator(object):

    def __init__(self):
        self.app = appindicator.Indicator.new(
            'timezone-ndicator', "",
            appindicator.IndicatorCategory.APPLICATION_STATUS)

        self.app.set_status(appindicator.IndicatorStatus.ACTIVE)
        self.app.set_icon('locale')

        self.app_menu = gtk.Menu()
        self.quit_app = gtk.MenuItem('Quit')
        self.quit_app.connect('activate', self.quit)
        self.quit_app.show()

        self.cache = None

        self.app_menu.append(self.quit_app)
        self.app.set_menu(self.app_menu)

        self.update_label()

    def run(self):
        gtk.main()

    def quit(self, data=None):
        gtk.main_quit()

    def update_label(self):
        timezone = None
        with open('/etc/timezone') as f: 
             timezone = f.read().strip()
        if timezone != self.cache:
             self.app.set_label(timezone,"")
        self.cache = timezone
        glib.timeout_add_seconds(1, self.callback)

    def callback(self):
        self.update_label()

def main():

    indicator = TimezoneIndicator()
    indicator.run()

if __== '__main__':
    main()
5

ターミナルコマンドから満足のいく形式でタイムゾーンを取得できる場合は、 Sysmonitor Indicator をインストールし、そのコマンドを(スクリプトとして)追加できます。

さらに進んでデフォルトのクロックを無効にすることもできます(非表示にするオプションがあります)。スクリプト/コマンドは、好みに応じて日付/時間/タイムゾーンを表示します。

1
Bernmeister