<s> """<STR_LIT>""" <EOL> import os . path as osp <EOL> import os <EOL> import sys <EOL> import platform <EOL> import locale <EOL> from winpython . qt . QtGui import ( QApplication , QMainWindow , QWidget , QLineEdit , <EOL> QHBoxLayout , QVBoxLayout , QColor , QMessageBox , <EOL> QAbstractItemView , QProgressDialog , QTableView , <EOL> QPushButton , QLabel , QTabWidget , QToolTip , <EOL> QDesktopServices ) <EOL> from winpython . qt . QtCore import ( Qt , QAbstractTableModel , QModelIndex , Signal , <EOL> QThread , QTimer , QUrl ) <EOL> from winpython . qt . compat import ( to_qvariant , getopenfilenames , <EOL> getexistingdirectory ) <EOL> import winpython . qt <EOL> from winpython . qthelpers import ( get_icon , add_actions , create_action , <EOL> keybinding , get_std_icon , action2button , <EOL> mimedata2url ) <EOL> from winpython import __version__ , __project_url__ <EOL> from winpython import wppm , associate , utils <EOL> from winpython . py3compat import getcwd , to_text_string <EOL> COLUMNS = ACTION , CHECK , NAME , VERSION , DESCRIPTION = list ( range ( <NUM_LIT:5> ) ) <EOL> class PackagesModel ( QAbstractTableModel ) : <EOL> dataChanged = Signal ( QModelIndex , QModelIndex ) <EOL> def __init__ ( self ) : <EOL> QAbstractTableModel . __init__ ( self ) <EOL> self . packages = [ ] <EOL> self . checked = set ( ) <EOL> self . actions = { } <EOL> def sortByName ( self ) : <EOL> self . packages = sorted ( self . packages , key = lambda x : x . name ) <EOL> self . reset ( ) <EOL> def flags ( self , index ) : <EOL> if not index . isValid ( ) : <EOL> return Qt . ItemIsEnabled <EOL> column = index . column ( ) <EOL> if column in ( NAME , VERSION , ACTION , DESCRIPTION ) : <EOL> return Qt . ItemFlags ( QAbstractTableModel . flags ( self , index ) ) <EOL> else : <EOL> return Qt . ItemFlags ( QAbstractTableModel . flags ( self , index ) | <EOL> Qt . ItemIsUserCheckable | Qt . ItemIsEditable ) <EOL> def data ( self , index , role = Qt . DisplayRole ) : <EOL> if not index . isValid ( ) or not ( <NUM_LIT:0> <= index . row ( ) < len ( self . packages ) ) : <EOL> return to_qvariant ( ) <EOL> package = self . packages [ index . row ( ) ] <EOL> column = index . column ( ) <EOL> if role == Qt . CheckStateRole and column == CHECK : <EOL> return to_qvariant ( package in self . checked ) <EOL> elif role == Qt . DisplayRole : <EOL> if column == NAME : <EOL> return to_qvariant ( package . name ) <EOL> elif column == VERSION : <EOL> return to_qvariant ( package . version ) <EOL> elif column == ACTION : <EOL> action = self . actions . get ( package ) <EOL> if action is not None : <EOL> return to_qvariant ( action ) <EOL> elif column == DESCRIPTION : <EOL> return to_qvariant ( package . description ) <EOL> elif role == Qt . TextAlignmentRole : <EOL> if column == ACTION : <EOL> return to_qvariant ( int ( Qt . AlignRight | Qt . AlignVCenter ) ) <EOL> else : <EOL> return to_qvariant ( int ( Qt . AlignLeft | Qt . AlignVCenter ) ) <EOL> elif role == Qt . BackgroundColorRole : <EOL> if package in self . checked : <EOL> color = QColor ( Qt . darkGreen ) <EOL> color . setAlphaF ( <NUM_LIT> ) <EOL> return to_qvariant ( color ) <EOL> else : <EOL> color = QColor ( Qt . lightGray ) <EOL> color . setAlphaF ( <NUM_LIT> ) <EOL> return to_qvariant ( color ) <EOL> return to_qvariant ( ) <EOL> def headerData ( self , section , orientation , role = Qt . DisplayRole ) : <EOL> if role == Qt . TextAlignmentRole : <EOL> if orientation == Qt . Horizontal : <EOL> return to_qvariant ( int ( Qt . AlignHCenter | Qt . AlignVCenter ) ) <EOL> return to_qvariant ( int ( Qt . AlignRight | Qt . AlignVCenter ) ) <EOL> if role != Qt . DisplayRole : <EOL> return to_qvariant ( ) <EOL> if orientation == Qt . Horizontal : <EOL> if section == NAME : <EOL> return to_qvariant ( "<STR_LIT:Name>" ) <EOL> elif section == VERSION : <EOL> return to_qvariant ( "<STR_LIT>" ) <EOL> elif section == ACTION : <EOL> return to_qvariant ( "<STR_LIT>" ) <EOL> elif section == DESCRIPTION : <EOL> return to_qvariant ( "<STR_LIT>" ) <EOL> return to_qvariant ( ) <EOL> def rowCount ( self , index = QModelIndex ( ) ) : <EOL> return len ( self . packages ) <EOL> def columnCount ( self , index = QModelIndex ( ) ) : <EOL> return len ( COLUMNS ) <EOL> def setData ( self , index , value , role = Qt . EditRole ) : <EOL> if index . isValid ( ) and <NUM_LIT:0> <= index . row ( ) < len ( self . packages ) and role == Qt . CheckStateRole : <EOL> package = self . packages [ index . row ( ) ] <EOL> if package in self . checked : <EOL> self . checked . remove ( package ) <EOL> else : <EOL> self . checked . add ( package ) <EOL> self . dataChanged . emit ( index , index ) <EOL> return True <EOL> return False <EOL> INSTALL_ACTION = '<STR_LIT>' <EOL> REPAIR_ACTION = '<STR_LIT>' <EOL> NO_REPAIR_ACTION = '<STR_LIT>' <EOL> UPGRADE_ACTION = '<STR_LIT>' <EOL> NONE_ACTION = '<STR_LIT:->' <EOL> class PackagesTable ( QTableView ) : <EOL> package_added = Signal ( ) <EOL> def __init__ ( self , parent , process , winname ) : <EOL> QTableView . __init__ ( self , parent ) <EOL> assert process in ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . process = process <EOL> self . model = PackagesModel ( ) <EOL> self . setModel ( self . model ) <EOL> self . winname = winname <EOL> self . repair = False <EOL> self . resizeColumnToContents ( <NUM_LIT:0> ) <EOL> self . setAcceptDrops ( process == '<STR_LIT>' ) <EOL> if process == '<STR_LIT>' : <EOL> self . hideColumn ( <NUM_LIT:0> ) <EOL> self . distribution = None <EOL> self . setSelectionBehavior ( QAbstractItemView . SelectRows ) <EOL> self . verticalHeader ( ) . hide ( ) <EOL> self . setShowGrid ( False ) <EOL> def reset_model ( self ) : <EOL> self . model . beginResetModel ( ) <EOL> self . model . endResetModel ( ) <EOL> self . horizontalHeader ( ) . setStretchLastSection ( True ) <EOL> for colnb in ( ACTION , CHECK , NAME , VERSION ) : <EOL> self . resizeColumnToContents ( colnb ) <EOL> def get_selected_packages ( self ) : <EOL> """<STR_LIT>""" <EOL> return [ pack for pack in self . model . packages <EOL> if pack in self . model . checked ] <EOL> def add_packages ( self , fnames ) : <EOL> """<STR_LIT>""" <EOL> notsupported = [ ] <EOL> notcompatible = [ ] <EOL> dist = self . distribution <EOL> for fname in fnames : <EOL> bname = osp . basename ( fname ) <EOL> try : <EOL> package = wppm . Package ( fname ) <EOL> if package . is_compatible_with ( dist ) : <EOL> self . add_package ( package ) <EOL> else : <EOL> notcompatible . append ( bname ) <EOL> except NotImplementedError : <EOL> notsupported . append ( bname ) <EOL> self . package_added . emit ( ) <EOL> if notsupported : <EOL> QMessageBox . warning ( self , "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> % ( self . winname , "<STR_LIT>" . join ( notsupported ) ) , <EOL> QMessageBox . Ok ) <EOL> if notcompatible : <EOL> QMessageBox . warning ( self , "<STR_LIT>" , "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> % ( dist . version , dist . architecture , <EOL> "<STR_LIT>" . join ( notcompatible ) ) , <EOL> QMessageBox . Ok ) <EOL> def add_package ( self , package ) : <EOL> for pack in self . model . packages : <EOL> if pack . name == package . name : <EOL> return <EOL> self . model . packages . append ( package ) <EOL> self . model . packages . sort ( key = lambda x : x . name ) <EOL> self . model . checked . add ( package ) <EOL> self . reset_model ( ) <EOL> def remove_package ( self , package ) : <EOL> self . model . packages = [ pack for pack in self . model . packages <EOL> if pack . fname != package . fname ] <EOL> if package in self . model . checked : <EOL> self . model . checked . remove ( package ) <EOL> if package in self . model . actions : <EOL> self . model . actions . pop ( package ) <EOL> self . reset_model ( ) <EOL> def refresh_distribution ( self , dist ) : <EOL> self . distribution = dist <EOL> if self . process == '<STR_LIT>' : <EOL> for package in self . model . packages : <EOL> pack = dist . find_package ( package . name ) <EOL> if pack is None : <EOL> action = INSTALL_ACTION <EOL> elif pack . version == package . version : <EOL> if self . repair : <EOL> action = REPAIR_ACTION <EOL> else : <EOL> action = NO_REPAIR_ACTION <EOL> else : <EOL> action = UPGRADE_ACTION + pack . version <EOL> self . model . actions [ package ] = action <EOL> else : <EOL> self . model . packages = self . distribution . get_installed_packages ( ) <EOL> for package in self . model . packages : <EOL> self . model . actions [ package ] = NONE_ACTION <EOL> self . reset_model ( ) <EOL> def select_all ( self ) : <EOL> allpk = set ( self . model . packages ) <EOL> if self . model . checked == allpk : <EOL> self . model . checked = set ( ) <EOL> else : <EOL> self . model . checked = allpk <EOL> self . model . reset ( ) <EOL> def dragMoveEvent ( self , event ) : <EOL> """<STR_LIT>""" <EOL> event . acceptProposedAction ( ) <EOL> def dragEnterEvent ( self , event ) : <EOL> """<STR_LIT>""" <EOL> source = event . mimeData ( ) <EOL> if source . hasUrls ( ) and mimedata2url ( source ) : <EOL> event . acceptProposedAction ( ) <EOL> def dropEvent ( self , event ) : <EOL> """<STR_LIT>""" <EOL> source = event . mimeData ( ) <EOL> fnames = [ path for path in mimedata2url ( source ) if osp . isfile ( path ) ] <EOL> self . add_packages ( fnames ) <EOL> event . acceptProposedAction ( ) <EOL> class DistributionSelector ( QWidget ) : <EOL> """<STR_LIT>""" <EOL> TITLE = '<STR_LIT>' <EOL> selected_distribution = Signal ( str ) <EOL> def __init__ ( self , parent ) : <EOL> super ( DistributionSelector , self ) . __init__ ( parent ) <EOL> self . browse_btn = None <EOL> self . label = None <EOL> self . line_edit = None <EOL> self . setup_widget ( ) <EOL> def set_distribution ( self , path ) : <EOL> """<STR_LIT>""" <EOL> self . line_edit . setText ( path ) <EOL> def setup_widget ( self ) : <EOL> """<STR_LIT>""" <EOL> self . label = QLabel ( ) <EOL> self . line_edit = QLineEdit ( ) <EOL> self . line_edit . setAlignment ( Qt . AlignRight ) <EOL> self . line_edit . setReadOnly ( True ) <EOL> self . browse_btn = QPushButton ( get_std_icon ( '<STR_LIT>' ) , "<STR_LIT>" , self ) <EOL> self . browse_btn . setToolTip ( self . TITLE ) <EOL> self . browse_btn . clicked . connect ( self . select_directory ) <EOL> layout = QHBoxLayout ( ) <EOL> layout . addWidget ( self . label ) <EOL> layout . addWidget ( self . line_edit ) <EOL> layout . addWidget ( self . browse_btn ) <EOL> layout . setContentsMargins ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> self . setLayout ( layout ) <EOL> def select_directory ( self ) : <EOL> """<STR_LIT>""" <EOL> basedir = to_text_string ( self . line_edit . text ( ) ) <EOL> if not osp . isdir ( basedir ) : <EOL> basedir = getcwd ( ) <EOL> while True : <EOL> directory = getexistingdirectory ( self , self . TITLE , basedir ) <EOL> if not directory : <EOL> break <EOL> if not utils . is_python_distribution ( directory ) : <EOL> QMessageBox . warning ( self , self . TITLE , <EOL> "<STR_LIT>" , <EOL> QMessageBox . Ok ) <EOL> basedir = directory <EOL> continue <EOL> directory = osp . abspath ( osp . normpath ( directory ) ) <EOL> self . set_distribution ( directory ) <EOL> self . selected_distribution . emit ( directory ) <EOL> break <EOL> class Thread ( QThread ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , parent ) : <EOL> QThread . __init__ ( self , parent ) <EOL> self . callback = None <EOL> self . error = None <EOL> def run ( self ) : <EOL> try : <EOL> self . callback ( ) <EOL> except Exception as error : <EOL> error_str = str ( error ) <EOL> fs_encoding = sys . getfilesystemencoding ( ) or locale . getpreferredencoding ( ) <EOL> try : <EOL> error_str = error_str . decode ( fs_encoding ) <EOL> except ( UnicodeError , TypeError , AttributeError ) : <EOL> pass <EOL> self . error = error_str <EOL> def python_distribution_infos ( ) : <EOL> """<STR_LIT>""" <EOL> winpyver = os . environ . get ( '<STR_LIT>' ) <EOL> if winpyver is None : <EOL> return '<STR_LIT>' <EOL> else : <EOL> return '<STR_LIT>' + winpyver <EOL> class PMWindow ( QMainWindow ) : <EOL> NAME = '<STR_LIT>' <EOL> def __init__ ( self ) : <EOL> QMainWindow . __init__ ( self ) <EOL> self . setAttribute ( Qt . WA_DeleteOnClose ) <EOL> self . distribution = None <EOL> self . tabwidget = None <EOL> self . selector = None <EOL> self . table = None <EOL> self . untable = None <EOL> self . basedir = None <EOL> self . select_all_action = None <EOL> self . install_action = None <EOL> self . uninstall_action = None <EOL> self . remove_action = None <EOL> self . packages_icon = get_std_icon ( '<STR_LIT>' ) <EOL> self . setup_window ( ) <EOL> def _add_table ( self , table , title , icon ) : <EOL> """<STR_LIT>""" <EOL> widget = QWidget ( ) <EOL> tabvlayout = QVBoxLayout ( ) <EOL> widget . setLayout ( tabvlayout ) <EOL> tabvlayout . addWidget ( table ) <EOL> btn_layout = QHBoxLayout ( ) <EOL> tabvlayout . addLayout ( btn_layout ) <EOL> self . tabwidget . addTab ( widget , icon , title ) <EOL> return btn_layout <EOL> def setup_window ( self ) : <EOL> """<STR_LIT>""" <EOL> self . setWindowTitle ( self . NAME ) <EOL> self . setWindowIcon ( get_icon ( '<STR_LIT>' ) ) <EOL> self . selector = DistributionSelector ( self ) <EOL> self . selector . selected_distribution . connect ( self . distribution_changed ) <EOL> self . table = PackagesTable ( self , '<STR_LIT>' , self . NAME ) <EOL> self . table . package_added . connect ( self . refresh_install_button ) <EOL> self . table . clicked . connect ( lambda index : self . refresh_install_button ( ) ) <EOL> self . untable = PackagesTable ( self , '<STR_LIT>' , self . NAME ) <EOL> self . untable . clicked . connect ( lambda index : self . refresh_uninstall_button ( ) ) <EOL> self . selector . set_distribution ( sys . prefix ) <EOL> self . distribution_changed ( sys . prefix ) <EOL> self . tabwidget = QTabWidget ( ) <EOL> self . tabwidget . currentChanged . connect ( self . current_tab_changed ) <EOL> btn_layout = self . _add_table ( self . table , "<STR_LIT>" , <EOL> get_std_icon ( "<STR_LIT>" ) ) <EOL> unbtn_layout = self . _add_table ( self . untable , "<STR_LIT>" , <EOL> get_std_icon ( "<STR_LIT>" ) ) <EOL> central_widget = QWidget ( ) <EOL> vlayout = QVBoxLayout ( ) <EOL> vlayout . addWidget ( self . selector ) <EOL> vlayout . addWidget ( self . tabwidget ) <EOL> central_widget . setLayout ( vlayout ) <EOL> self . setCentralWidget ( central_widget ) <EOL> add_action = create_action ( self , "<STR_LIT>" , <EOL> icon = get_std_icon ( '<STR_LIT>' ) , <EOL> triggered = self . add_packages ) <EOL> self . remove_action = create_action ( self , "<STR_LIT>" , <EOL> shortcut = keybinding ( '<STR_LIT>' ) , <EOL> icon = get_std_icon ( '<STR_LIT>' ) , <EOL> triggered = self . remove_packages ) <EOL> self . remove_action . setEnabled ( False ) <EOL> self . select_all_action = create_action ( self , "<STR_LIT>" , <EOL> shortcut = keybinding ( '<STR_LIT>' ) , <EOL> icon = get_std_icon ( '<STR_LIT>' ) , <EOL> triggered = self . table . select_all ) <EOL> self . install_action = create_action ( self , "<STR_LIT>" , <EOL> icon = get_std_icon ( '<STR_LIT>' ) , <EOL> triggered = lambda : self . process_packages ( '<STR_LIT>' ) ) <EOL> self . install_action . setEnabled ( False ) <EOL> quit_action = create_action ( self , "<STR_LIT>" , <EOL> icon = get_std_icon ( '<STR_LIT>' ) , <EOL> triggered = self . close ) <EOL> packages_menu = self . menuBar ( ) . addMenu ( "<STR_LIT>" ) <EOL> add_actions ( packages_menu , [ add_action , self . remove_action , <EOL> self . install_action , <EOL> None , quit_action ] ) <EOL> self . uninstall_action = create_action ( self , "<STR_LIT>" , <EOL> icon = get_std_icon ( '<STR_LIT>' ) , <EOL> triggered = lambda : self . process_packages ( '<STR_LIT>' ) ) <EOL> self . uninstall_action . setEnabled ( False ) <EOL> uninstall_btn = action2button ( self . uninstall_action , autoraise = False , <EOL> text_beside_icon = True ) <EOL> option_menu = self . menuBar ( ) . addMenu ( "<STR_LIT>" ) <EOL> repair_action = create_action ( self , "<STR_LIT>" , <EOL> tip = "<STR_LIT>" , <EOL> toggled = self . toggle_repair ) <EOL> add_actions ( option_menu , ( repair_action , ) ) <EOL> option_menu = self . menuBar ( ) . addMenu ( "<STR_LIT>" ) <EOL> register_action = create_action ( self , "<STR_LIT>" , <EOL> tip = "<STR_LIT>" , <EOL> triggered = self . register_distribution ) <EOL> unregister_action = create_action ( self , "<STR_LIT>" , <EOL> tip = "<STR_LIT>" , <EOL> triggered = self . unregister_distribution ) <EOL> open_console_action = create_action ( self , "<STR_LIT>" , <EOL> triggered = lambda : os . startfile ( self . command_prompt_path ) ) <EOL> open_console_action . setEnabled ( osp . exists ( self . command_prompt_path ) ) <EOL> add_actions ( option_menu , ( register_action , unregister_action , <EOL> None , open_console_action ) ) <EOL> about_action = create_action ( self , "<STR_LIT>" % self . NAME , <EOL> icon = get_std_icon ( '<STR_LIT>' ) , <EOL> triggered = self . about ) <EOL> report_action = create_action ( self , "<STR_LIT>" , <EOL> icon = get_icon ( '<STR_LIT>' ) , <EOL> triggered = self . report_issue ) <EOL> help_menu = self . menuBar ( ) . addMenu ( "<STR_LIT:?>" ) <EOL> add_actions ( help_menu , [ about_action , None , report_action ] ) <EOL> status = self . statusBar ( ) <EOL> status . setObjectName ( "<STR_LIT>" ) <EOL> status . showMessage ( "<STR_LIT>" % self . NAME , <NUM_LIT> ) <EOL> for act in ( add_action , self . remove_action , None , <EOL> self . select_all_action , self . install_action ) : <EOL> if act is None : <EOL> btn_layout . addStretch ( ) <EOL> else : <EOL> btn_layout . addWidget ( action2button ( act , autoraise = False , <EOL> text_beside_icon = True ) ) <EOL> unbtn_layout . addWidget ( uninstall_btn ) <EOL> unbtn_layout . addStretch ( ) <EOL> self . resize ( <NUM_LIT> , <NUM_LIT> ) <EOL> def current_tab_changed ( self , index ) : <EOL> """<STR_LIT>""" <EOL> if index == <NUM_LIT:0> : <EOL> self . show_drop_tip ( ) <EOL> def refresh_install_button ( self ) : <EOL> """<STR_LIT>""" <EOL> self . table . refresh_distribution ( self . distribution ) <EOL> self . install_action . setEnabled ( <EOL> len ( self . get_packages_to_be_installed ( ) ) > <NUM_LIT:0> ) <EOL> nbp = len ( self . table . get_selected_packages ( ) ) <EOL> for act in ( self . remove_action , self . select_all_action ) : <EOL> act . setEnabled ( nbp > <NUM_LIT:0> ) <EOL> self . show_drop_tip ( ) <EOL> def show_drop_tip ( self ) : <EOL> """<STR_LIT>""" <EOL> callback = lambda : QToolTip . showText ( <EOL> self . table . mapToGlobal ( self . table . pos ( ) ) , <EOL> '<STR_LIT>' '<STR_LIT>' , <EOL> self ) <EOL> QTimer . singleShot ( <NUM_LIT> , callback ) <EOL> def refresh_uninstall_button ( self ) : <EOL> """<STR_LIT>""" <EOL> nbp = len ( self . untable . get_selected_packages ( ) ) <EOL> self . uninstall_action . setEnabled ( nbp > <NUM_LIT:0> ) <EOL> def toggle_repair ( self , state ) : <EOL> """<STR_LIT>""" <EOL> self . table . repair = state <EOL> self . refresh_install_button ( ) <EOL> def register_distribution ( self ) : <EOL> """<STR_LIT>""" <EOL> answer = QMessageBox . warning ( self , "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> QMessageBox . Yes | QMessageBox . No ) <EOL> if answer == QMessageBox . Yes : <EOL> associate . register ( self . distribution . target ) <EOL> def unregister_distribution ( self ) : <EOL> """<STR_LIT>""" <EOL> answer = QMessageBox . warning ( self , "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> QMessageBox . Yes | QMessageBox . No ) <EOL> if answer == QMessageBox . Yes : <EOL> associate . unregister ( self . distribution . target ) <EOL> @ property <EOL> def command_prompt_path ( self ) : <EOL> return osp . join ( self . distribution . target , osp . pardir , <EOL> "<STR_LIT>" ) <EOL> def distribution_changed ( self , path ) : <EOL> """<STR_LIT>""" <EOL> for package in self . table . model . packages : <EOL> self . table . remove_package ( package ) <EOL> dist = wppm . Distribution ( to_text_string ( path ) ) <EOL> self . table . refresh_distribution ( dist ) <EOL> self . untable . refresh_distribution ( dist ) <EOL> self . distribution = dist <EOL> self . selector . label . setText ( '<STR_LIT>' <EOL> % ( dist . version , dist . architecture ) ) <EOL> def add_packages ( self ) : <EOL> """<STR_LIT>""" <EOL> basedir = self . basedir if self . basedir is not None else '<STR_LIT>' <EOL> fnames , _selfilter = getopenfilenames ( parent = self , basedir = basedir , <EOL> caption = '<STR_LIT>' , <EOL> filters = '<STR_LIT>' ) <EOL> if fnames : <EOL> self . basedir = osp . dirname ( fnames [ <NUM_LIT:0> ] ) <EOL> self . table . add_packages ( fnames ) <EOL> def get_packages_to_be_installed ( self ) : <EOL> """<STR_LIT>""" <EOL> return [ pack for pack in self . table . get_selected_packages ( ) <EOL> if self . table . model . actions [ pack ] <EOL> not in ( NO_REPAIR_ACTION , NONE_ACTION ) ] <EOL> def remove_packages ( self ) : <EOL> """<STR_LIT>""" <EOL> for package in self . table . get_selected_packages ( ) : <EOL> self . table . remove_package ( package ) <EOL> def process_packages ( self , action ) : <EOL> """<STR_LIT>""" <EOL> if action == '<STR_LIT>' : <EOL> text , table = '<STR_LIT>' , self . table <EOL> if not self . get_packages_to_be_installed ( ) : <EOL> return <EOL> elif action == '<STR_LIT>' : <EOL> text , table = '<STR_LIT>' , self . untable <EOL> else : <EOL> raise AssertionError <EOL> packages = table . get_selected_packages ( ) <EOL> if not packages : <EOL> return <EOL> func = getattr ( self . distribution , action ) <EOL> thread = Thread ( self ) <EOL> for widget in self . children ( ) : <EOL> if isinstance ( widget , QWidget ) : <EOL> widget . setEnabled ( False ) <EOL> try : <EOL> status = self . statusBar ( ) <EOL> except AttributeError : <EOL> status = self . parent ( ) . statusBar ( ) <EOL> progress = QProgressDialog ( self , Qt . FramelessWindowHint ) <EOL> progress . setMaximum ( len ( packages ) ) <EOL> for index , package in enumerate ( packages ) : <EOL> progress . setValue ( index ) <EOL> progress . setLabelText ( "<STR_LIT>" <EOL> % ( text , package . name , package . version ) ) <EOL> QApplication . processEvents ( ) <EOL> if progress . wasCanceled ( ) : <EOL> break <EOL> if package in table . model . actions : <EOL> try : <EOL> thread . callback = lambda : func ( package ) <EOL> thread . start ( ) <EOL> while thread . isRunning ( ) : <EOL> QApplication . processEvents ( ) <EOL> if progress . wasCanceled ( ) : <EOL> status . setEnabled ( True ) <EOL> status . showMessage ( "<STR_LIT>" ) <EOL> table . remove_package ( package ) <EOL> error = thread . error <EOL> except Exception as error : <EOL> error = to_text_string ( error ) <EOL> if error is not None : <EOL> pstr = package . name + '<STR_LIT:U+0020>' + package . version <EOL> QMessageBox . critical ( self , "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> % ( action , pstr , error ) ) <EOL> progress . setValue ( progress . maximum ( ) ) <EOL> status . clearMessage ( ) <EOL> for widget in self . children ( ) : <EOL> if isinstance ( widget , QWidget ) : <EOL> widget . setEnabled ( True ) <EOL> thread = None <EOL> for table in ( self . table , self . untable ) : <EOL> table . refresh_distribution ( self . distribution ) <EOL> def report_issue ( self ) : <EOL> issue_template = """<STR_LIT>""" % ( python_distribution_infos ( ) , <EOL> __version__ , platform . python_version ( ) , <EOL> winpython . qt . QtCore . __version__ , winpython . qt . API_NAME , <EOL> winpython . qt . __version__ ) <EOL> url = QUrl ( "<STR_LIT>" % __project_url__ ) <EOL> url . addQueryItem ( "<STR_LIT>" , issue_template ) <EOL> QDesktopServices . openUrl ( url ) <EOL> def about ( self ) : <EOL> """<STR_LIT>""" <EOL> QMessageBox . about ( self , <EOL> "<STR_LIT>" % self . NAME , <EOL> """<STR_LIT>""" <EOL> % ( self . NAME , __version__ , __project_url__ , <EOL> python_distribution_infos ( ) , <EOL> platform . python_version ( ) , winpython . qt . QtCore . __version__ , <EOL> winpython . qt . API_NAME , winpython . qt . __version__ , ) ) <EOL> def main ( test = False ) : <EOL> app = QApplication ( [ ] ) <EOL> win = PMWindow ( ) <EOL> win . show ( ) <EOL> if test : <EOL> return app , win <EOL> else : <EOL> app . exec_ ( ) <EOL> def test ( ) : <EOL> app , win = main ( test = True ) <EOL> print ( sys . modules ) <EOL> app . exec_ ( ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> main ( ) </s>
