<s> """<STR_LIT>""" <EOL> from subprocess import Popen , PIPE <EOL> from time import sleep , time <EOL> class Py3status : <EOL> """<STR_LIT:U+0020>""" <EOL> cache_timeout = <NUM_LIT:10> <EOL> format = '<STR_LIT>' <EOL> hide_if_disconnected = False <EOL> horizontal_icon = '<STR_LIT:H>' <EOL> horizontal_rotation = '<STR_LIT>' <EOL> screen = None <EOL> vertical_icon = '<STR_LIT>' <EOL> vertical_rotation = '<STR_LIT:left>' <EOL> def __init__ ( self ) : <EOL> self . displayed = '<STR_LIT>' <EOL> def _call ( self , cmd ) : <EOL> process = Popen ( cmd , stdout = PIPE , shell = True ) <EOL> output = process . communicate ( ) [ <NUM_LIT:0> ] or "<STR_LIT>" <EOL> try : <EOL> output = output . decode ( ) <EOL> except : <EOL> pass <EOL> return output . strip ( ) <EOL> def _get_all_outputs ( self ) : <EOL> cmd = '<STR_LIT>' <EOL> return self . _call ( cmd ) . split ( ) <EOL> def _get_current_rotation_icon ( self , all_outputs ) : <EOL> output = self . screen or all_outputs [ <NUM_LIT:0> ] <EOL> cmd = '<STR_LIT>' + output + '<STR_LIT>' <EOL> output = self . _call ( cmd ) <EOL> is_horizontal = output . startswith ( '<STR_LIT:(>' ) or output in [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> return self . horizontal_icon if is_horizontal else self . vertical_icon <EOL> def _apply ( self ) : <EOL> rotation = self . horizontal_rotation if self . displayed == self . horizontal_icon else self . vertical_rotation <EOL> outputs = [ self . screen ] if self . screen else self . _get_all_outputs ( ) <EOL> for output in outputs : <EOL> cmd = '<STR_LIT>' + output + '<STR_LIT>' + rotation <EOL> Popen ( [ '<STR_LIT>' , cmd ] , stdout = PIPE ) <EOL> def _switch_selection ( self ) : <EOL> self . displayed = self . vertical_icon if self . displayed == self . horizontal_icon else self . horizontal_icon <EOL> def on_click ( self , i3s_output_list , i3s_config , event ) : <EOL> """<STR_LIT>""" <EOL> button = event [ '<STR_LIT>' ] <EOL> if button in [ <NUM_LIT:1> , <NUM_LIT:4> , <NUM_LIT:5> ] : <EOL> self . _switch_selection ( ) <EOL> elif button == <NUM_LIT:3> : <EOL> self . _apply ( ) <EOL> def xrandr_rotate ( self , i3s_output_list , i3s_config ) : <EOL> all_outputs = self . _get_all_outputs ( ) <EOL> selected_screen_disconnected = self . screen is not None and self . screen not in all_outputs <EOL> if selected_screen_disconnected and self . hide_if_disconnected : <EOL> self . displayed = '<STR_LIT>' <EOL> full_text = '<STR_LIT>' <EOL> else : <EOL> if not self . displayed : <EOL> self . displayed = self . _get_current_rotation_icon ( all_outputs ) <EOL> screen = self . screen or all_outputs [ <NUM_LIT:0> ] if len ( all_outputs ) == <NUM_LIT:1> else '<STR_LIT>' <EOL> full_text = self . format . format ( icon = self . displayed or '<STR_LIT:?>' , screen = screen ) <EOL> response = { <EOL> '<STR_LIT>' : time ( ) + self . cache_timeout , <EOL> '<STR_LIT>' : full_text <EOL> } <EOL> if selected_screen_disconnected and not self . hide_if_disconnected : <EOL> response [ '<STR_LIT>' ] = i3s_config [ '<STR_LIT>' ] <EOL> elif self . displayed == self . _get_current_rotation_icon ( all_outputs ) : <EOL> response [ '<STR_LIT>' ] = i3s_config [ '<STR_LIT>' ] <EOL> return response <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> """<STR_LIT>""" <EOL> x = Py3status ( ) <EOL> config = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> while True : <EOL> print ( x . xrandr_rotate ( [ ] , config ) ) <EOL> sleep ( <NUM_LIT:1> ) </s>
