From 8041ea095614ca21d718c09d84a7dea77d85347f Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 15 Feb 2014 21:01:14 +0400 Subject: [PATCH 1/2] Some style fixes --- docs/source/overview.rst | 13 +++++--- powerline/bindings/i3/powerline-i3.py | 47 ++++++++++++++------------- powerline/renderers/i3bgbar.py | 11 +++++-- powerline/segments/i3wm.py | 23 ++++++++----- 4 files changed, 56 insertions(+), 38 deletions(-) diff --git a/docs/source/overview.rst b/docs/source/overview.rst index d846efba..6ec996e4 100644 --- a/docs/source/overview.rst +++ b/docs/source/overview.rst @@ -235,13 +235,15 @@ Add the following to your :file:`~/.config/qtile/config.py`: ), ] -with i3bar replacement ------------------ +I3 bar +------ -.. note:: Until the patch is done in i3, you will need a custom ``i3bar`` build called ``i3bgbar``. - The source is available `here `_. +.. note:: Until the patch is done in i3, you will need a custom ``i3bar`` build + called ``i3bgbar``. The source is available `here + `_. Add the following to your :file:`~/.i3/config`:: + bar { i3bar_command i3bgbar @@ -249,4 +251,5 @@ Add the following to your :file:`~/.i3/config`:: font pango:PowerlineFont 12 } -where ``i3bgbar`` may be replaced with the path to the custom i3bar binary and ``PowerlineFont`` is any system font with powerline support. +where ``i3bgbar`` may be replaced with the path to the custom i3bar binary and +``PowerlineFont`` is any system font with powerline support. diff --git a/powerline/bindings/i3/powerline-i3.py b/powerline/bindings/i3/powerline-i3.py index 463b3f4d..69ad1ffd 100755 --- a/powerline/bindings/i3/powerline-i3.py +++ b/powerline/bindings/i3/powerline-i3.py @@ -10,31 +10,34 @@ import time import i3 from threading import Lock -name = 'wm' -if len( sys.argv ) > 1: - name = sys.argv[1] -powerline = Powerline(name, renderer_module='i3bgbar') -powerline.update_renderer() -interval = 0.5 +if __name__ == '__main__': + name = 'wm' + if len(sys.argv) > 1: + name = sys.argv[1] -print( '{"version": 1, "custom_workspace": true}' ) -print( '[' ) -print( ' [[],[]]' ) + powerline = Powerline(name, renderer_module='i3bgbar') + powerline.update_renderer() -lock = Lock() + interval = 0.5 -def render( event=None, data=None, sub=None ): - global lock - with lock: - s = '[\n' + powerline.render(side='right')[:-2] + '\n]\n' - s += ',[\n' + powerline.render(side='left' )[:-2] + '\n]' - print( ',[\n' + s + '\n]' ) - sys.stdout.flush() + print ('{"version": 1, "custom_workspace": true}') + print ('[') + print ('\t[[],[]]') -sub = i3.Subscription( render, 'workspace' ) + lock = Lock() -while True: - start_time = monotonic() - render() - time.sleep(max(interval - (monotonic() - start_time), 0.1)) + def render(event=None, data=None, sub=None): + global lock + with lock: + s = '[\n' + powerline.render(side='right')[:-2] + '\n]\n' + s += ',[\n' + powerline.render(side='left')[:-2] + '\n]' + print (',[\n' + s + '\n]') + sys.stdout.flush() + + sub = i3.Subscription(render, 'workspace') + + while True: + start_time = monotonic() + render() + time.sleep(max(interval - (monotonic() - start_time), 0.1)) diff --git a/powerline/renderers/i3bgbar.py b/powerline/renderers/i3bgbar.py index bc549b10..55e1c3d4 100644 --- a/powerline/renderers/i3bgbar.py +++ b/powerline/renderers/i3bgbar.py @@ -1,9 +1,9 @@ # vim:fileencoding=utf-8:noet from powerline.renderer import Renderer -from powerline.colorscheme import ATTR_BOLD, ATTR_ITALIC, ATTR_UNDERLINE import json + class i3bgbarRenderer(Renderer): '''i3bgbar Segment Renderer''' @@ -15,7 +15,11 @@ class i3bgbarRenderer(Renderer): def hl(self, contents, fg=None, bg=None, attr=None): '''Highlight a segment.''' - segment = { "full_text": contents, "separator": False, "separator_block_width": 0 } # no seperators + segment = { + "full_text": contents, + "separator": False, + "separator_block_width": 0, # no seperators + } if fg is not None: if fg is not False and fg[1] is not False: @@ -23,7 +27,8 @@ class i3bgbarRenderer(Renderer): if bg is not None: if bg is not False and bg[1] is not False: segment['background_color'] = "#{0:06x}".format(bg[1]) - return json.dumps( segment ) + ",\n" # i3bar "pseudo json" requires one line at a time + # i3bar "pseudo json" requires one line at a time + return json.dumps(segment) + ",\n" renderer = i3bgbarRenderer diff --git a/powerline/segments/i3wm.py b/powerline/segments/i3wm.py index 04115444..69752dff 100644 --- a/powerline/segments/i3wm.py +++ b/powerline/segments/i3wm.py @@ -1,19 +1,26 @@ # vim:fileencoding=utf-8:noet -from powerline.theme import requires_segment_info import i3 -def calcgrp( w ): + +def calcgrp(w): group = [] - if w['focused']: group.append( 'w_focused' ) - if w['urgent']: group.append( 'w_urgent' ) - if w['visible']: group.append( 'w_visible' ) - group.append( 'workspace' ) + if w['focused']: + group.append('w_focused') + if w['urgent']: + group.append('w_urgent') + if w['visible']: + group.append('w_visible') + group.append('workspace') return group -def workspaces( pl ): + +def workspaces(pl): '''Return workspace list Highlight groups used: ``workspace``, ``w_visible``, ``w_focused``, ``w_urgent`` ''' - return [ {'contents': w['name'], 'highlight_group': calcgrp( w )} for w in i3.get_workspaces() ] + return [{ + 'contents': w['name'], + 'highlight_group': calcgrp(w) + } for w in i3.get_workspaces()] From dfdc12b45a4cf85d4e87cda032bb62e2318c9739 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 15 Feb 2014 21:04:40 +0400 Subject: [PATCH 2/2] Move i3bgbar.py to i3bar.py --- powerline/bindings/i3/powerline-i3.py | 2 +- powerline/renderers/{i3bgbar.py => i3bar.py} | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) rename powerline/renderers/{i3bgbar.py => i3bar.py} (82%) diff --git a/powerline/bindings/i3/powerline-i3.py b/powerline/bindings/i3/powerline-i3.py index 69ad1ffd..d6d84f59 100755 --- a/powerline/bindings/i3/powerline-i3.py +++ b/powerline/bindings/i3/powerline-i3.py @@ -16,7 +16,7 @@ if __name__ == '__main__': if len(sys.argv) > 1: name = sys.argv[1] - powerline = Powerline(name, renderer_module='i3bgbar') + powerline = Powerline(name, renderer_module='i3bar') powerline.update_renderer() interval = 0.5 diff --git a/powerline/renderers/i3bgbar.py b/powerline/renderers/i3bar.py similarity index 82% rename from powerline/renderers/i3bgbar.py rename to powerline/renderers/i3bar.py index 55e1c3d4..2e0ef9b3 100644 --- a/powerline/renderers/i3bgbar.py +++ b/powerline/renderers/i3bar.py @@ -4,8 +4,11 @@ from powerline.renderer import Renderer import json -class i3bgbarRenderer(Renderer): - '''i3bgbar Segment Renderer''' +class I3barRenderer(Renderer): + '''I3bar Segment Renderer. + + Currently works only for i3bgbar (i3 bar with custom patches). + ''' @staticmethod def hlstyle(*args, **kwargs): @@ -13,8 +16,6 @@ class i3bgbarRenderer(Renderer): return '' def hl(self, contents, fg=None, bg=None, attr=None): - '''Highlight a segment.''' - segment = { "full_text": contents, "separator": False, @@ -31,4 +32,4 @@ class i3bgbarRenderer(Renderer): return json.dumps(segment) + ",\n" -renderer = i3bgbarRenderer +renderer = I3barRenderer