<s> import re <EOL> import subprocess <EOL> from subprocess import CalledProcessError <EOL> from . import base <EOL> from libqtile . log_utils import logger <EOL> kb_regex = re . compile ( '<STR_LIT>' ) <EOL> class KeyboardLayout ( base . InLoopPollText ) : <EOL> """<STR_LIT>""" <EOL> orientations = base . ORIENTATION_HORIZONTAL <EOL> defaults = [ <EOL> ( "<STR_LIT>" , <NUM_LIT:1> , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , [ "<STR_LIT>" ] , "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) , <EOL> ] <EOL> def __init__ ( self , ** config ) : <EOL> base . InLoopPollText . __init__ ( self , ** config ) <EOL> self . add_defaults ( KeyboardLayout . defaults ) <EOL> def button_press ( self , x , y , button ) : <EOL> if button == <NUM_LIT:1> : <EOL> self . next_keyboard ( ) <EOL> def next_keyboard ( self ) : <EOL> """<STR_LIT>""" <EOL> current_keyboard = self . keyboard <EOL> if current_keyboard in self . configured_keyboards : <EOL> next_keyboard = self . configured_keyboards [ <EOL> ( self . configured_keyboards . index ( current_keyboard ) + <NUM_LIT:1> ) % <EOL> len ( self . configured_keyboards ) ] <EOL> else : <EOL> next_keyboard = self . configured_keyboards [ <NUM_LIT:0> ] <EOL> self . keyboard = next_keyboard <EOL> def poll ( self ) : <EOL> return self . keyboard . upper ( ) <EOL> def get_keyboard_layout ( self , setxkbmap_output ) : <EOL> matches = kb_regex . search ( setxkbmap_output ) <EOL> if matches is None : <EOL> return '<STR_LIT>' <EOL> return matches . group ( '<STR_LIT>' ) <EOL> @ property <EOL> def keyboard ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> command = '<STR_LIT>' <EOL> setxkbmap_output = self . call_process ( command . split ( '<STR_LIT:U+0020>' ) ) <EOL> keyboard = self . get_keyboard_layout ( setxkbmap_output ) <EOL> return str ( keyboard ) <EOL> except CalledProcessError as e : <EOL> logger . error ( '<STR_LIT>' . format ( e ) ) <EOL> except OSError as e : <EOL> logger . error ( '<STR_LIT>' . format ( e ) ) <EOL> return "<STR_LIT>" <EOL> @ keyboard . setter <EOL> def keyboard ( self , keyboard ) : <EOL> command = [ '<STR_LIT>' ] <EOL> command . extend ( keyboard . split ( "<STR_LIT:U+0020>" ) ) <EOL> try : <EOL> subprocess . check_call ( command ) <EOL> except CalledProcessError as e : <EOL> logger . error ( '<STR_LIT>' . format ( e ) ) <EOL> except OSError as e : <EOL> logger . error ( '<STR_LIT>' . format ( e ) ) <EOL> def cmd_next_keyboard ( self ) : <EOL> """<STR_LIT>""" <EOL> self . next_keyboard ( ) </s>
