Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
PH111P committed Feb 12, 2017
1 parent ccf1446 commit d79972d
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 8 deletions.
6 changes: 5 additions & 1 deletion powerline/segments/common/mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,14 @@ def render_one(unread_count, max_msgs=None, **kwargs):
return [{
'contents': str(unread_count),
'highlight_groups': ['email_alert'],
'condition_values': {'unread_count': str(unread_count)}
}]
else:
return [{
'contents': str(unread_count),
'highlight_groups': ['email_alert_gradient', 'email_alert'],
'gradient_level': min(unread_count * 100.0 / max_msgs, 100),
'condition_values': {'unread_count': str(unread_count)}
}]


Expand All @@ -71,8 +73,10 @@ def render_one(unread_count, max_msgs=None, **kwargs):
will use gradient level equal to 100, otherwise gradient level is equal to
``100 * msgs_num / max_msgs``. If not present gradient is not computed.
:param bool use_ssl:
If ``True`` then use SSL connection. If ``False`` then do not use it.
If ``True`` then use SSL connection. If ``False`` then do not use it.
Default is ``True`` if port is equal to {ssl_port} and ``False`` otherwise.
Highlight groups used: ``email_alert_gradient`` (gradient), ``email_alert``.
Conditions available: ``unread_count`` (string)
''').format(ssl_port=IMAP4_SSL_PORT))
14 changes: 10 additions & 4 deletions powerline/segments/common/net.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ def wireless(pl, device, format='{quality:3.0%} at {essid}'):
:param string format:
the output format
Highlight groups used: ``quality_gradient`` (gradient)
Conditions available: ``quality`` (int), ``essid`` (string)
'''

try:
Expand All @@ -50,9 +52,10 @@ def wireless(pl, device, format='{quality:3.0%} at {essid}'):
if essid == '' or quality == 0:
return None
return [{
'contents': format.format(quality=quality/70, essid=essid.decode(), frequency=frequency),
'contents': format.format(quality=quality/85, essid=essid.decode(), frequency=frequency),
'highlight_groups': ['quality_gradient'],
'gradient_level': 100 * (70 - quality) / 70
'gradient_level': 100 * (85 - quality) / 85,
'condition_values': {'essid': essid, 'quality': quality * 100 / 85}
}]

def _external_ip(query_url='http://ipv6.icanhazip.com/'):
Expand All @@ -72,7 +75,8 @@ def update(self, old_ip):
def render(self, ip, **kwargs):
if not ip:
return None
return [{'contents': ip, 'divider_highlight_group': 'background:divider'}]
return [{'contents': ip, 'divider_highlight_group': 'background:divider',
'condition_values': {'external_ip': ip}}]


external_ip = with_docstring(ExternalIpSegment(),
Expand All @@ -88,6 +92,8 @@ def render(self, ip, **kwargs):
* http://icanhazip.com/ (returns IPv6 address if available, else IPv4)
Divider highlight group used: ``background:divider``.
Conditions available: ``external_ip`` (string)
''')


Expand Down Expand Up @@ -291,7 +297,7 @@ def render_one(self, idata, recv_format='DL {value:>8}', sent_format='UL {value:
r.append({
'contents': format.format(value=humanize_bytes(value, suffix, si_prefix)),
'divider_highlight_group': 'network_load:divider',
'highlight_groups': hl_groups,
'highlight_groups': hl_groups
})
if is_gradient:
max = kwargs[max_key]
Expand Down
11 changes: 10 additions & 1 deletion powerline/segments/common/sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ def system_load(pl, format='{avg:.1f}', threshold_good=1, threshold_bad=2,
Divider highlight group used: ``background:divider``.
Highlight groups used: ``system_load_gradient`` (gradient) or ``system_load``.
Conditions available: ``avg`` (string), ``avg_raw`` (int)
'''
global cpu_count
try:
Expand All @@ -63,6 +65,7 @@ def system_load(pl, format='{avg:.1f}', threshold_good=1, threshold_bad=2,
'highlight_groups': ['system_load_gradient', 'system_load'],
'divider_highlight_group': 'background:divider',
'gradient_level': gradient_level,
'condition_values': {'avg':format.format(avg=avg), 'avg_raw':avg}
})

if short:
Expand Down Expand Up @@ -96,6 +99,7 @@ def render(self, cpu_percent, format='{0:.0f}%', threshold=None, **kwargs):
'contents': format.format(cpu_percent),
'gradient_level': cpu_percent,
'highlight_groups': ['cpu_load_percent_gradient', 'cpu_load_percent'],
'condition_values': {'cpu_load': format.format(cpu_percent), 'cpu_load_raw': cpu_percent}
}]
except ImportError:
class CPULoadPercentSegment(ThreadedSegment):
Expand Down Expand Up @@ -130,6 +134,8 @@ def render(cpu_percent, pl, format='{0:.0f}%', threshold=None **kwargs):
Minimum load to display the segment (in percent)
Highlight groups used: ``cpu_load_percent_gradient`` (gradient) or ``cpu_load_percent``.
Conditions available: ``cpu_load`` (string), ``cpu_load_raw`` (int)
''')


Expand Down Expand Up @@ -193,11 +199,14 @@ def temp(pl, format='{:.1f}°C', path="/sys/class/thermal/thermal_zone0/temp", a
Path of the file containing the temperature
:param int accuracy:
Accuracy to read
Conditions available: ``temp`` (string), ``temp_raw`` (int)
'''
with open(path, "r") as f:
temp = int(f.read()) * accuracy
return [{
'contents': format.format(temp),
'highlight_groups': ['temp'],
'gradient_level': 100 * min(1, max(0, (temp-lowtemp) / (hightemp-lowtemp)))
'gradient_level': 100 * min(1, max(0, (temp-lowtemp) / (hightemp-lowtemp))),
'condition_values': {'temp': format.format(temp), 'temp_raw': temp}
}]
3 changes: 3 additions & 0 deletions powerline/segments/common/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ def date(pl, format='%Y-%m-%d', istime=False, timezone=None):
Divider highlight group used: ``time:divider``.
Highlight groups used: ``time`` or ``date``.
Conditions available: ``contents`` (string)
'''
try:
tz = datetime.strptime(timezone, '%z').tzinfo if timezone else None
Expand All @@ -33,6 +35,7 @@ def date(pl, format='%Y-%m-%d', istime=False, timezone=None):
'contents': contents,
'highlight_groups': (['time'] if istime else []) + ['date'],
'divider_highlight_group': 'time:divider' if istime else None,
'condition_values': {'contents': contents}
}]


Expand Down
8 changes: 6 additions & 2 deletions powerline/segments/common/volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ def vol( pl, format='♪ {volume:3.0%}', format_muted='♪ {volume}', control='M
:param string control: The control.
:param int id: The control id.
Highlight groups used: ``volume_gradient`` (gradient).
Conditions available: ``volume`` (int), ``muted`` (boolean)
'''

avg = 0;
Expand All @@ -24,12 +26,14 @@ def vol( pl, format='♪ {volume:3.0%}', format_muted='♪ {volume}', control='M
elif not format:
return None

muted = alsaaudio.Mixer(control,id).getmute()[0] == 1

return [{
'contents':(format_muted.format(volume='--')
if alsaaudio.Mixer(control,id).getmute()[0] == 1
else format.format(volume=avg/(100*len(res)))),
if muted else format.format(volume=avg/(100*len(res)))),
'highlight_groups': ['volume_gradient'],
'divider_highlight_group': None,
'gradient_level': int(a / len( res )),
'condition_values': {'volume': avg/(100*len(res)), 'muted': muted}
}]

0 comments on commit d79972d

Please sign in to comment.