lemonbar: Create DateTimeModule using python time function
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import threading
|
||||
import subprocess
|
||||
import contextlib
|
||||
import os, signal, getpass
|
||||
import time, os, signal, getpass
|
||||
import queue
|
||||
|
||||
import i3_lemonbar_config as config
|
||||
import i3_lemonbar_common as common
|
||||
@@ -71,13 +72,67 @@ def format_load(data, module, alert):
|
||||
module.alt_scheme = None
|
||||
return (d_v, u_v)
|
||||
|
||||
class DateTimeModule(LemonModule):
|
||||
def __init__(self):
|
||||
self.show_secs = False
|
||||
super().__init__()
|
||||
|
||||
def _start_module(self):
|
||||
class DateTimeThread(threading.Thread):
|
||||
def __init__(self):
|
||||
self.last_out = ''
|
||||
self.out_queue = queue.Queue()
|
||||
self.out_queue.readline = self.out_queue.get
|
||||
super().__init__()
|
||||
|
||||
def run(self):
|
||||
while True:
|
||||
timestr = time.strftime("%a %d %b %H:%M:%S", time.gmtime())
|
||||
if timestr != self.last_out:
|
||||
self.last_out = timestr
|
||||
self.out_queue.put('{}\n'.format(timestr))
|
||||
time.sleep(0.1)
|
||||
|
||||
self.dt_thread = DateTimeThread()
|
||||
self.dt_thread.start()
|
||||
self.status_handle = self.dt_thread.out_queue
|
||||
|
||||
self.date = parser.IconTextUnit('date', action='date', order=40)
|
||||
self.time = parser.IconTextUnit('time', action='toggle_secs', order=41
|
||||
, alt_scheme=parser.COLOR_SCHEME.SPECIAL)
|
||||
self.time.modes = [mode for mode in common.bar_mode]
|
||||
|
||||
parser.g_parser.register_unit(self.date)
|
||||
parser.g_parser.register_unit(self.time)
|
||||
|
||||
self.register_action('date' , self.date_comm)
|
||||
self.register_action('toggle_secs' , self.toggle_secs)
|
||||
|
||||
def _stop_module(self):
|
||||
if self.p_handle is not None:
|
||||
self.p_handle.terminate()
|
||||
|
||||
parser.g_parser.remove_unit(self.date)
|
||||
parser.g_parser.remove_unit(self.time)
|
||||
|
||||
def _parse_data(self, data):
|
||||
# Date and time
|
||||
self.date.items = [(config.icon_clock, ' '.join(data[0:3]))]
|
||||
self.time.items = [('', data[3] if self.show_secs else data[3][:-3])]
|
||||
|
||||
def date_comm(self):
|
||||
subprocess.Popen(['yad', '--no-buttons', '--calendar', '--sticky'
|
||||
, '--on-top' , '--class' , '"YADWIN"', '--posx=1650', '--posy=24'
|
||||
, '--close-on-unfocus'])
|
||||
|
||||
def toggle_secs(self):
|
||||
self.show_secs = not self.show_secs
|
||||
|
||||
class ConkyFastModule(LemonModule):
|
||||
# TODO use internal python stuff for stuff like clock, then raise update interval
|
||||
if os.uname()[1] == 'kubaDesktop':
|
||||
conky_config = """
|
||||
conky_config_str = """
|
||||
conky.config = {
|
||||
background=false,
|
||||
update_interval=0.2,
|
||||
update_interval=1,
|
||||
total_run_times=0,
|
||||
override_utf8_locale=true,
|
||||
short_units=true,
|
||||
@@ -87,9 +142,10 @@ conky.config = {
|
||||
if_up_strictness='address',
|
||||
format_human_readable=true,
|
||||
}
|
||||
|
||||
"""
|
||||
if os.uname()[1] == 'kubaDesktop':
|
||||
conky_config = conky_config_str + """
|
||||
conky.text = [[
|
||||
${time %a %d %b %H:%M:%S} \
|
||||
${exec ~/.i3/lemonbar/get_vol.sh} \
|
||||
down down\
|
||||
\
|
||||
@@ -99,22 +155,8 @@ ${else}down down${endif}\
|
||||
]]
|
||||
"""
|
||||
else:
|
||||
conky_config = """
|
||||
conky.config = {
|
||||
background=false,
|
||||
update_interval=0.2,
|
||||
total_run_times=0,
|
||||
override_utf8_locale=true,
|
||||
short_units=true,
|
||||
uppercase=false,
|
||||
out_to_console=true,
|
||||
out_to_x=false,
|
||||
if_up_strictness='address',
|
||||
format_human_readable=true,
|
||||
}
|
||||
|
||||
conky_config = conky_config_str + """
|
||||
conky.text = [[
|
||||
${time %a %d %b %H:%M:%S} \
|
||||
${exec ~/.i3/lemonbar/get_vol.sh} \
|
||||
${if_up wlp3s0}${downspeedf wlp3s0} ${upspeedf wlp3s0}\
|
||||
${else}down down${endif}\
|
||||
@@ -125,7 +167,6 @@ ${else}down down${endif}\
|
||||
]]
|
||||
"""
|
||||
def __init__(self):
|
||||
self.show_secs = False
|
||||
super().__init__()
|
||||
|
||||
def _start_module(self):
|
||||
@@ -138,21 +179,13 @@ ${else}down down${endif}\
|
||||
self.wlan_load = parser.IconTextUnit('wlan_load', action='wlan', order=13)
|
||||
self.eth_load = parser.IconTextUnit('eth_load', action='eth', order=14)
|
||||
self.volume = parser.IconTextUnit('volume', action='pavu', order=20)
|
||||
self.date = parser.IconTextUnit('date', action='date', order=40)
|
||||
self.time = parser.IconTextUnit('time', action='toggle_secs', order=41
|
||||
, alt_scheme=parser.COLOR_SCHEME.SPECIAL)
|
||||
self.time.modes = [mode for mode in common.bar_mode]
|
||||
|
||||
parser.g_parser.register_unit(self.wlan_load)
|
||||
parser.g_parser.register_unit(self.eth_load)
|
||||
parser.g_parser.register_unit(self.volume)
|
||||
parser.g_parser.register_unit(self.date)
|
||||
parser.g_parser.register_unit(self.time)
|
||||
|
||||
self.register_action('wlan' , self.nmtui)
|
||||
self.register_action('pavu' , self.pavu)
|
||||
self.register_action('date' , self.date_comm)
|
||||
self.register_action('toggle_secs' , self.toggle_secs)
|
||||
|
||||
def _stop_module(self):
|
||||
if self.p_handle is not None:
|
||||
@@ -161,30 +194,24 @@ ${else}down down${endif}\
|
||||
parser.g_parser.remove_unit(self.wlan_load)
|
||||
parser.g_parser.remove_unit(self.eth_load)
|
||||
parser.g_parser.remove_unit(self.volume)
|
||||
parser.g_parser.remove_unit(self.date)
|
||||
parser.g_parser.remove_unit(self.time)
|
||||
|
||||
def _parse_data(self, data):
|
||||
# wlan and eth
|
||||
(wland_v, wlanu_v) = format_load(data[5:7], self.wlan_load, config.net_alert)
|
||||
(wland_v, wlanu_v) = format_load(data[1:3], self.wlan_load, config.net_alert)
|
||||
self.wlan_load.items = [(config.icon_wlan + config.icon_dl, wland_v)
|
||||
,(config.icon_ul, wlanu_v)]
|
||||
|
||||
(ethd_v, ethu_v) = format_load(data[7:9], self.eth_load, config.net_alert)
|
||||
(ethd_v, ethu_v) = format_load(data[3:5], self.eth_load, config.net_alert)
|
||||
self.eth_load.items = [(config.icon_eth + config.icon_dl, ethd_v)
|
||||
,(config.icon_ul, ethu_v)]
|
||||
|
||||
# Volume
|
||||
mute = data[4] == 'MUTE' or data[4] == 'NONE'
|
||||
(vol,vols) = (-1,'×') if mute else (int(data[4]), data[4]+'%')
|
||||
mute = data[0] == 'MUTE' or data[0] == 'NONE'
|
||||
(vol,vols) = (-1,'×') if mute else (int(data[0]), data[0]+'%')
|
||||
icon_v = config.icon_vol_mute if vol == 0 else \
|
||||
config.icon_vol_low if vol < 50 else config.icon_vol
|
||||
self.volume.items = [(icon_v, vols)]
|
||||
|
||||
# Date and time
|
||||
self.date.items = [(config.icon_clock, ' '.join(data[0:3]))]
|
||||
self.time.items = [('', data[3] if self.show_secs else data[3][:-3])]
|
||||
|
||||
def nmtui(self):
|
||||
p = subprocess.Popen(['xterm', '-class', 'FLOAT_TERM', '-e', 'nmtui'])
|
||||
common.kill_on_unfocus.append(p.pid)
|
||||
@@ -193,17 +220,8 @@ ${else}down down${endif}\
|
||||
p = subprocess.Popen(['pavucontrol', '--class=FLOAT_PAVU'])
|
||||
common.kill_on_unfocus.append(p.pid)
|
||||
|
||||
def date_comm(self):
|
||||
subprocess.Popen(['yad', '--no-buttons', '--calendar', '--sticky'
|
||||
, '--on-top' , '--class' , '"YADWIN"', '--posx=1650', '--posy=24'
|
||||
, '--close-on-unfocus'])
|
||||
|
||||
def toggle_secs(self):
|
||||
self.show_secs = not self.show_secs
|
||||
|
||||
class ConkySlowModule(LemonModule):
|
||||
if os.uname()[1] == 'kubaDesktop':
|
||||
conky_config = """
|
||||
conky_config_str = """
|
||||
conky.config = {
|
||||
background=false,
|
||||
update_interval=5,
|
||||
@@ -216,7 +234,9 @@ conky.config = {
|
||||
if_up_strictness='address',
|
||||
format_human_readable=true,
|
||||
}
|
||||
|
||||
"""
|
||||
if os.uname()[1] == 'kubaDesktop':
|
||||
conky_config = conky_config_str + """
|
||||
conky.text = [[
|
||||
${cpu} \
|
||||
${mem} \
|
||||
@@ -228,21 +248,7 @@ ${exec /home/kuba/.i3/scripts/lang.sh show}
|
||||
]]
|
||||
"""
|
||||
else:
|
||||
conky_config = """
|
||||
|
||||
conky.config = {
|
||||
background=false,
|
||||
update_interval=5,
|
||||
total_run_times=0,
|
||||
override_utf8_locale=true,
|
||||
short_units=true,
|
||||
uppercase=false,
|
||||
out_to_console=true,
|
||||
out_to_x=false,
|
||||
if_up_strictness='address',
|
||||
format_human_readable=true,
|
||||
}
|
||||
|
||||
conky_config = conky_config_str + """
|
||||
conky.text = [[
|
||||
${cpu} \
|
||||
${mem} \
|
||||
@@ -641,33 +647,37 @@ class PowerOptionsModule(LemonModule):
|
||||
, ', (r) reboot, (Shift+s) shutdown'])
|
||||
|
||||
def do_action(keyword):
|
||||
global m_conky_fast, m_conky_slow, m_i3ws
|
||||
global m_datetime, m_conky_fast, m_conky_slow, m_i3ws
|
||||
|
||||
m_i3ws.do_action(keyword)
|
||||
m_datetime.do_action(keyword)
|
||||
m_conky_slow.do_action(keyword)
|
||||
m_conky_fast.do_action(keyword)
|
||||
m_screen.do_action(keyword)
|
||||
m_power.do_action(keyword)
|
||||
|
||||
def start_all():
|
||||
global m_conky_fast, m_conky_slow, m_i3ws, m_screen, m_power
|
||||
global m_datetime, m_conky_fast, m_conky_slow, m_i3ws, m_screen, m_power
|
||||
|
||||
m_i3ws = i3Module()
|
||||
m_datetime = DateTimeModule()
|
||||
m_conky_slow = ConkySlowModule()
|
||||
m_conky_fast = ConkyFastModule()
|
||||
m_screen = ScreenModule()
|
||||
m_power = PowerOptionsModule()
|
||||
|
||||
m_i3ws.start()
|
||||
m_datetime.start()
|
||||
m_conky_slow.start()
|
||||
m_conky_fast.start()
|
||||
m_screen.start()
|
||||
m_power.start()
|
||||
|
||||
def stop_all():
|
||||
global m_conky_fast, m_conky_slow, m_i3ws, m_screen, m_power
|
||||
global m_datetime, m_conky_fast, m_conky_slow, m_i3ws, m_screen, m_power
|
||||
|
||||
m_i3ws.stop()
|
||||
m_datetime.stop()
|
||||
m_conky_slow.stop()
|
||||
m_conky_fast.stop()
|
||||
m_screen.stop()
|
||||
|
||||
Reference in New Issue
Block a user