From 1eddd57061e85b3e6e30105d01d37878e82190aa Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Tue, 9 Oct 2012 10:46:49 +0200 Subject: turn on and off icanon + get terminal width + get maximum and current brightness --- adjbacklight.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/adjbacklight.py b/adjbacklight.py index 5e28396..0d07f46 100755 --- a/adjbacklight.py +++ b/adjbacklight.py @@ -2,6 +2,7 @@ # -*- coding: utf-8 -*- import os +import sys from subprocess import Popen, PIPE @@ -14,14 +15,23 @@ def print(text = '', end = '\n'): - ''' This is the mane class of the program ''' class Adjbacklight(): - -#Popen(compressCommand(ext).split(' '), stdout=fileout, stdin=filein).communicate() -#(out, err) = Popen(['env', 'python', '--version'], stdout=PIPE, stderr=PIPE).communicate() + def __init__(self): + Popen('stty -icanon'.split(' ')).wait() + try: + dir = '/sys/class/backlight/intel_backlight/' + (size, dummy) = Popen('stty size'.split(' '), stdout=PIPE, stderr=PIPE).communicate() + width = int(size.decode('UTF-8').replace('\n', '').split(' ')[1]) + with open(dir + 'brightness', 'r') as file: + current = int(file.readline().replace('\n', '')) + with open(dir + 'max_brightness', 'r') as file: + max = int(file.readline().replace('\n', '')) + + finally: + Popen('stty icanon'.split(' ')).wait() ''' -- cgit v1.2.3-70-g09d2