Example #1
0
def run(thread_shutdown_event=None,
        pl_shutdown_event=None,
        pl_config_loader=None,
        interval=None):
    powerline = Powerline(
        'wm',
        renderer_module='pango_markup',
        shutdown_event=pl_shutdown_event,
        config_loader=pl_config_loader,
    )
    powerline.update_renderer()

    if not thread_shutdown_event:
        thread_shutdown_event = powerline.shutdown_event

    while not thread_shutdown_event.is_set():
        # powerline.update_interval may change over time
        used_interval = interval or powerline.update_interval
        start_time = monotonic()
        s = powerline.render(side='right')
        request = 'powerline_widget:set_markup(\'' + s.translate({
            '\'': '\\\'',
            '\\': '\\\\'
        }) + '\')\n'
        client = Popen(['awesome-client'],
                       shell=False,
                       stdout=PIPE,
                       stderr=PIPE,
                       stdin=PIPE)
        client.stdin.write(request.encode('utf-8'))
        client.stdin.close()
        read_to_log(powerline.pl, client)
        thread_shutdown_event.wait(
            max(used_interval - (monotonic() - start_time), 0.1))
Example #2
0
class Powerline(base._TextBox):
	def __init__(self, timeout=2, text=" ", width=bar.CALCULATED, **config):
		base._TextBox.__init__(self, text, width, **config)
		self.timeout_add(timeout, self.update)
		self.powerline = PowerlineCore(ext='wm', renderer_module='pango_markup')

	def update(self):
		if not self.configured:
			return True
		self.text = self.powerline.render(side='right')
		self.bar.draw()
		return True

	def cmd_update(self, text):
		self.update(text)

	def cmd_get(self):
		return self.text

	def _configure(self, qtile, bar):
		base._TextBox._configure(self, qtile, bar)
		self.layout = self.drawer.textlayout(
			self.text,
			self.foreground,
			self.font,
			self.fontsize,
			self.fontshadow,
			markup=True)
	def test_wm(self):
		from powerline.segments import common
		from imp import reload
		reload(common)
		from powerline import Powerline
		with replace_attr(common, 'urllib_read', urllib_read):
			Powerline(ext='wm', renderer_module='pango_markup', run_once=True).render()
		reload(common)
Example #4
0
def check(path=None):
	search_paths = [path] if path else Powerline.get_config_paths()

	dirs = {
			'themes': defaultdict(lambda: []),
			'colorschemes': defaultdict(lambda: [])
			}
	for path in reversed(search_paths):
		for subdir in ('themes', 'colorschemes'):
			d = os.path.join(path, subdir)
			if os.path.isdir(d):
				for ext in os.listdir(d):
					extd = os.path.join(d, ext)
					if os.path.isdir(extd):
						dirs[subdir][ext].append(extd)
			elif os.path.exists(d):
				hadproblem = True
				sys.stderr.write('Path {0} is supposed to be a directory, but it is not\n'.format(d))

	configs = {
			'themes': defaultdict(lambda: {}),
			'colorschemes': defaultdict(lambda: {})
			}
	for subdir in ('themes', 'colorschemes'):
		for ext in dirs[subdir]:
			for d in dirs[subdir][ext]:
				for config in os.listdir(d):
					if config.endswith('.json'):
						configs[subdir][ext][config[:-5]] = os.path.join(d, config)

	diff = set(configs['themes']) ^ set(configs['colorschemes'])
	if diff:
		hadproblem = True
		for ext in diff:
			sys.stderr.write('{0} extension {1} present only in {2}\n'.format(
				ext,
				'configuration' if (ext in dirs['themes'] and ext in dirs['colorschemes']) else 'directory',
				'themes' if ext in configs['themes'] else 'colorschemes',
				))

	lhadproblem = [False]

	def load_config(stream):
		r, hadproblem = load(stream)
		if hadproblem:
			lhadproblem[0] = True
		return r

	hadproblem = False
	try:
		main_config = load_json_config(search_paths, 'config', load=load_config, open_file=open_file)
	except IOError:
		main_config = {}
		sys.stderr.write('\nConfiguration file not found: config.json\n')
		hadproblem = True
	except MarkedError as e:
		main_config = {}
		sys.stderr.write(str(e) + '\n')
		hadproblem = True
	else:
		if main_spec.match(main_config, data={'configs': configs}, context=(('', main_config),))[1]:
			hadproblem = True

	import_paths = [os.path.expanduser(path) for path in main_config.get('common', {}).get('paths', [])]

	try:
		colors_config = load_json_config(search_paths, 'colors', load=load_config, open_file=open_file)
	except IOError:
		colors_config = {}
		sys.stderr.write('\nConfiguration file not found: colors.json\n')
		hadproblem = True
	except MarkedError as e:
		colors_config = {}
		sys.stderr.write(str(e) + '\n')
		hadproblem = True
	else:
		if colors_spec.match(colors_config, context=(('', colors_config),))[1]:
			hadproblem = True

	if lhadproblem[0]:
		hadproblem = True

	colorscheme_configs = defaultdict(lambda: {})
	for ext in configs['colorschemes']:
		data = {'ext': ext, 'colors_config': colors_config}
		for colorscheme, cfile in configs['colorschemes'][ext].items():
			with open_file(cfile) as config_file_fp:
				try:
					config, lhadproblem = load(config_file_fp)
				except MarkedError as e:
					sys.stderr.write(str(e) + '\n')
					hadproblem = True
					continue
			if lhadproblem:
				hadproblem = True
			colorscheme_configs[ext][colorscheme] = config
			if ext == 'vim':
				spec = vim_colorscheme_spec
			else:
				spec = colorscheme_spec
			if spec.match(config, context=(('', config),), data=data)[1]:
				hadproblem = True

	theme_configs = defaultdict(lambda: {})
	for ext in configs['themes']:
		for theme, sfile in configs['themes'][ext].items():
			with open_file(sfile) as config_file_fp:
				try:
					config, lhadproblem = load(config_file_fp)
				except MarkedError as e:
					sys.stderr.write(str(e) + '\n')
					hadproblem = True
					continue
			if lhadproblem:
				hadproblem = True
			theme_configs[ext][theme] = config
	for ext, configs in theme_configs.items():
		data = {'ext': ext, 'colorscheme_configs': colorscheme_configs, 'import_paths': import_paths,
				'main_config': main_config, 'ext_theme_configs': configs, 'colors_config': colors_config}
		for theme, config in configs.items():
			data['theme'] = theme
			if theme_spec.match(config, context=(('', config),), data=data)[1]:
				hadproblem = True
	return hadproblem
Example #5
0
import sys
import time

from threading import Lock

import i3

from powerline import Powerline
from powerline.lib.monotonic import monotonic

if __name__ == '__main__':
    name = 'wm'
    if len(sys.argv) > 1:
        name = sys.argv[1]

    powerline = Powerline(name, renderer_module='i3bar')
    powerline.update_renderer()

    interval = 0.5

    print('{"version": 1, "custom_workspace": true}')
    print('[')
    print('\t[[],[]]')

    lock = Lock()

    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]'
Example #6
0
#!/usr/bin/env python
# vim:fileencoding=utf-8:noet
from __future__ import print_function

from powerline import Powerline
from powerline.lib.monotonic import monotonic

import sys
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

print( '{"version": 1, "custom_workspace": true}' )
print( '[' )
print( '	[[],[]]' )

lock = Lock()

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]'
Example #7
0
#!/usr/bin/env python
# vim:fileencoding=utf-8:noet
from __future__ import (unicode_literals, division, absolute_import, print_function)

import sys

from time import sleep
from subprocess import Popen, PIPE

from powerline import Powerline
from powerline.lib.monotonic import monotonic

powerline = Powerline('wm', renderer_module='pango_markup')
powerline.update_renderer()

try:
	interval = float(sys.argv[1])
except IndexError:
	interval = 2


def read_to_log(pl, client):
	for line in client.stdout:
		if line:
			pl.info(line, prefix='awesome-client')
	for line in client.stderr:
		if line:
			pl.error(line, prefix='awesome-client')
	if client.wait():
		pl.error('Client exited with {0}', client.returncode, prefix='awesome')
Example #8
0
def check(path=None):
    search_paths = [path] if path else Powerline.get_config_paths()

    dirs = {"themes": defaultdict(lambda: []), "colorschemes": defaultdict(lambda: [])}
    for path in reversed(search_paths):
        for subdir in ("themes", "colorschemes"):
            d = os.path.join(path, subdir)
            if os.path.isdir(d):
                for ext in os.listdir(d):
                    extd = os.path.join(d, ext)
                    if os.path.isdir(extd):
                        dirs[subdir][ext].append(extd)
            elif os.path.exists(d):
                hadproblem = True
                sys.stderr.write("Path {0} is supposed to be a directory, but it is not\n".format(d))

    configs = {"themes": defaultdict(lambda: {}), "colorschemes": defaultdict(lambda: {})}
    for subdir in ("themes", "colorschemes"):
        for ext in dirs[subdir]:
            for d in dirs[subdir][ext]:
                for config in os.listdir(d):
                    if config.endswith(".json"):
                        configs[subdir][ext][config[:-5]] = os.path.join(d, config)

    diff = set(configs["themes"]) ^ set(configs["colorschemes"])
    if diff:
        hadproblem = True
        for ext in diff:
            sys.stderr.write(
                "{0} extension {1} present only in {2}\n".format(
                    ext,
                    "configuration" if (ext in dirs["themes"] and ext in dirs["colorschemes"]) else "directory",
                    "themes" if ext in configs["themes"] else "colorschemes",
                )
            )

    lhadproblem = [False]

    def load_config(stream):
        r, hadproblem = load(stream)
        if hadproblem:
            lhadproblem[0] = True
        return r

    hadproblem = False
    try:
        main_config = load_json_config(find_config_file(search_paths, "config"), load=load_config, open_file=open_file)
    except IOError:
        main_config = {}
        sys.stderr.write("\nConfiguration file not found: config.json\n")
        hadproblem = True
    except MarkedError as e:
        main_config = {}
        sys.stderr.write(str(e) + "\n")
        hadproblem = True
    else:
        if main_spec.match(main_config, data={"configs": configs}, context=(("", main_config),))[1]:
            hadproblem = True

    import_paths = [os.path.expanduser(path) for path in main_config.get("common", {}).get("paths", [])]

    try:
        colors_config = load_json_config(
            find_config_file(search_paths, "colors"), load=load_config, open_file=open_file
        )
    except IOError:
        colors_config = {}
        sys.stderr.write("\nConfiguration file not found: colors.json\n")
        hadproblem = True
    except MarkedError as e:
        colors_config = {}
        sys.stderr.write(str(e) + "\n")
        hadproblem = True
    else:
        if colors_spec.match(colors_config, context=(("", colors_config),))[1]:
            hadproblem = True

    if lhadproblem[0]:
        hadproblem = True

    colorscheme_configs = defaultdict(lambda: {})
    for ext in configs["colorschemes"]:
        data = {"ext": ext, "colors_config": colors_config}
        for colorscheme, cfile in configs["colorschemes"][ext].items():
            with open_file(cfile) as config_file_fp:
                try:
                    config, lhadproblem = load(config_file_fp)
                except MarkedError as e:
                    sys.stderr.write(str(e) + "\n")
                    hadproblem = True
                    continue
            if lhadproblem:
                hadproblem = True
            colorscheme_configs[ext][colorscheme] = config
            if ext == "vim":
                spec = vim_colorscheme_spec
            else:
                spec = colorscheme_spec
            if spec.match(config, context=(("", config),), data=data)[1]:
                hadproblem = True

    theme_configs = defaultdict(lambda: {})
    for ext in configs["themes"]:
        for theme, sfile in configs["themes"][ext].items():
            with open_file(sfile) as config_file_fp:
                try:
                    config, lhadproblem = load(config_file_fp)
                except MarkedError as e:
                    sys.stderr.write(str(e) + "\n")
                    hadproblem = True
                    continue
            if lhadproblem:
                hadproblem = True
            theme_configs[ext][theme] = config
    for ext, configs in theme_configs.items():
        data = {
            "ext": ext,
            "colorscheme_configs": colorscheme_configs,
            "import_paths": import_paths,
            "main_config": main_config,
            "ext_theme_configs": configs,
            "colors_config": colors_config,
        }
        for theme, config in configs.items():
            data["theme"] = theme
            if theme_spec.match(config, context=(("", config),), data=data)[1]:
                hadproblem = True
    return hadproblem
Example #9
0
	def __init__(self, timeout=2, text=" ", width=bar.CALCULATED, **config):
		base._TextBox.__init__(self, text, width, **config)
		self.timeout_add(timeout, self.update)
		self.powerline = PowerlineCore(ext='wm', renderer_module='pango_markup')
Example #10
0
def check(path=None):
	search_paths = [path] if path else Powerline.get_config_paths()

	dirs = {
			'themes': defaultdict(lambda: []),
			'colorschemes': defaultdict(lambda: [])
			}
	for path in reversed(search_paths):
		for subdir in ('themes', 'colorschemes'):
			d = os.path.join(path, subdir)
			if os.path.isdir(d):
				for ext in os.listdir(d):
					extd = os.path.join(d, ext)
					if os.path.isdir(extd):
						dirs[subdir][ext].append(extd)
			elif os.path.exists(d):
				hadproblem = True
				sys.stderr.write('Path {0} is supposed to be a directory, but it is not\n'.format(d))

	configs = {
			'themes': defaultdict(lambda: {}),
			'colorschemes': defaultdict(lambda: {})
			}
	for subdir in ('themes', 'colorschemes'):
		for ext in dirs[subdir]:
			for d in dirs[subdir][ext]:
				for config in os.listdir(d):
					if config.endswith('.json'):
						configs[subdir][ext][config[:-5]] = os.path.join(d, config)

	diff = set(configs['themes']) ^ set(configs['colorschemes'])
	if diff:
		hadproblem = True
		for ext in diff:
			sys.stderr.write('{0} extension {1} present only in {2}\n'.format(
				ext,
				'configuration' if (ext in dirs['themes'] and ext in dirs['colorschemes']) else 'directory',
				'themes' if ext in configs['themes'] else 'colorschemes',
				))

	lhadproblem = [False]

	def load_config(stream):
		r, hadproblem = load(stream)
		if hadproblem:
			lhadproblem[0] = True
		return r

	hadproblem = False
	try:
		main_config = load_json_config(find_config_file(search_paths, 'config'), load=load_config, open_file=open_file)
	except IOError:
		main_config = {}
		sys.stderr.write('\nConfiguration file not found: config.json\n')
		hadproblem = True
	except MarkedError as e:
		main_config = {}
		sys.stderr.write(str(e) + '\n')
		hadproblem = True
	else:
		if main_spec.match(main_config, data={'configs': configs}, context=(('', main_config),))[1]:
			hadproblem = True

	import_paths = [os.path.expanduser(path) for path in main_config.get('common', {}).get('paths', [])]

	try:
		colors_config = load_json_config(find_config_file(search_paths, 'colors'), load=load_config, open_file=open_file)
	except IOError:
		colors_config = {}
		sys.stderr.write('\nConfiguration file not found: colors.json\n')
		hadproblem = True
	except MarkedError as e:
		colors_config = {}
		sys.stderr.write(str(e) + '\n')
		hadproblem = True
	else:
		if colors_spec.match(colors_config, context=(('', colors_config),))[1]:
			hadproblem = True

	if lhadproblem[0]:
		hadproblem = True

	colorscheme_configs = defaultdict(lambda: {})
	for ext in configs['colorschemes']:
		data = {'ext': ext, 'colors_config': colors_config}
		for colorscheme, cfile in configs['colorschemes'][ext].items():
			with open_file(cfile) as config_file_fp:
				try:
					config, lhadproblem = load(config_file_fp)
				except MarkedError as e:
					sys.stderr.write(str(e) + '\n')
					hadproblem = True
					continue
			if lhadproblem:
				hadproblem = True
			colorscheme_configs[ext][colorscheme] = config
			if ext == 'vim':
				spec = vim_colorscheme_spec
			else:
				spec = colorscheme_spec
			if spec.match(config, context=(('', config),), data=data)[1]:
				hadproblem = True

	theme_configs = defaultdict(lambda: {})
	for ext in configs['themes']:
		for theme, sfile in configs['themes'][ext].items():
			with open_file(sfile) as config_file_fp:
				try:
					config, lhadproblem = load(config_file_fp)
				except MarkedError as e:
					sys.stderr.write(str(e) + '\n')
					hadproblem = True
					continue
			if lhadproblem:
				hadproblem = True
			theme_configs[ext][theme] = config
	for ext, configs in theme_configs.items():
		data = {'ext': ext, 'colorscheme_configs': colorscheme_configs, 'import_paths': import_paths,
				'main_config': main_config, 'ext_theme_configs': configs, 'colors_config': colors_config}
		for theme, config in configs.items():
			data['theme'] = theme
			if theme_spec.match(config, context=(('', config),), data=data)[1]:
				hadproblem = True
	return hadproblem
#!/usr/bin/env python
# vim:fileencoding=utf-8:noet
from __future__ import (unicode_literals, division, absolute_import,
                        print_function)

import sys

from time import sleep
from subprocess import Popen, PIPE

from powerline import Powerline
from powerline.lib.monotonic import monotonic

powerline = Powerline('wm', renderer_module='pango_markup')
powerline.update_renderer()

try:
    interval = float(sys.argv[1])
except IndexError:
    interval = 2


def read_to_log(pl, client):
    for line in client.stdout:
        if line:
            pl.info(line, prefix='awesome-client')
    for line in client.stderr:
        if line:
            pl.error(line, prefix='awesome-client')
    if client.wait():
        pl.error('Client exited with {0}', client.returncode, prefix='awesome')