<s> from __future__ import absolute_import , division , print_function <EOL> import os <EOL> from glue . external . qt . QtCore import Qt <EOL> from glue . external . qt import QtGui <EOL> from glue . _plugin_helpers import PluginConfig <EOL> from glue . utils . qt import load_ui <EOL> __all__ = [ "<STR_LIT>" ] <EOL> class QtPluginManager ( object ) : <EOL> def __init__ ( self , installed = None ) : <EOL> self . ui = load_ui ( '<STR_LIT>' , None , <EOL> directory = os . path . dirname ( __file__ ) ) <EOL> self . ui . cancel . clicked . connect ( self . reject ) <EOL> self . ui . confirm . clicked . connect ( self . finalize ) <EOL> self . _checkboxes = { } <EOL> self . update_list ( installed = installed ) <EOL> def clear ( self ) : <EOL> self . _checkboxes . clear ( ) <EOL> self . ui . tree . clear ( ) <EOL> def update_list ( self , installed = None ) : <EOL> self . clear ( ) <EOL> config = PluginConfig . load ( ) <EOL> if installed is not None : <EOL> config . filter ( installed ) <EOL> for plugin in sorted ( config . plugins ) : <EOL> check = QtGui . QTreeWidgetItem ( self . ui . tree . invisibleRootItem ( ) , <EOL> [ "<STR_LIT>" , plugin ] ) <EOL> check . setFlags ( check . flags ( ) | Qt . ItemIsUserCheckable ) <EOL> if config . plugins [ plugin ] : <EOL> check . setCheckState ( <NUM_LIT:0> , Qt . Checked ) <EOL> else : <EOL> check . setCheckState ( <NUM_LIT:0> , Qt . Unchecked ) <EOL> self . _checkboxes [ plugin ] = check <EOL> self . ui . tree . resizeColumnToContents ( <NUM_LIT:0> ) <EOL> self . ui . tree . resizeColumnToContents ( <NUM_LIT:1> ) <EOL> def reject ( self ) : <EOL> self . ui . reject ( ) <EOL> def finalize ( self ) : <EOL> config = PluginConfig . load ( ) <EOL> for name in self . _checkboxes : <EOL> config . plugins [ name ] = self . _checkboxes [ name ] . checkState ( <NUM_LIT:0> ) > <NUM_LIT:0> <EOL> try : <EOL> config . save ( ) <EOL> except Exception : <EOL> import traceback <EOL> detail = str ( traceback . format_exc ( ) ) <EOL> from glue . utils . qt import QMessageBoxPatched as QMessageBox <EOL> message = QMessageBox ( QMessageBox . Critical , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" ) <EOL> message . setDetailedText ( detail ) <EOL> message . exec_ ( ) <EOL> return <EOL> self . ui . accept ( ) </s>
