<s> from __future__ import absolute_import , division , print_function <EOL> import os <EOL> from contextlib import contextmanager <EOL> from glue . external . qt import QtGui , QtCore <EOL> from glue . external . qt . QtCore import Qt <EOL> from glue . utils . qt import get_text <EOL> __all__ = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> def update_combobox ( combo , labeldata ) : <EOL> """<STR_LIT>""" <EOL> combo . blockSignals ( True ) <EOL> idx = combo . currentIndex ( ) <EOL> if idx >= <NUM_LIT:0> : <EOL> current = combo . itemData ( idx ) <EOL> else : <EOL> current = None <EOL> combo . clear ( ) <EOL> index = <NUM_LIT:0> <EOL> for i , ( label , data ) in enumerate ( labeldata ) : <EOL> combo . addItem ( label , userData = data ) <EOL> if data is current : <EOL> index = i <EOL> combo . blockSignals ( False ) <EOL> combo . setCurrentIndex ( index ) <EOL> if idx == index or idx == - <NUM_LIT:1> : <EOL> combo . currentIndexChanged . emit ( index ) <EOL> class GlueTabBar ( QtGui . QTabBar ) : <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( GlueTabBar , self ) . __init__ ( * args , ** kwargs ) <EOL> def rename_tab ( self , index = None ) : <EOL> """<STR_LIT>""" <EOL> index = index or self . currentIndex ( ) <EOL> label = get_text ( "<STR_LIT>" ) <EOL> if not label : <EOL> return <EOL> self . setTabText ( index , label ) <EOL> def mouseDoubleClickEvent ( self , event ) : <EOL> if event . button ( ) != Qt . LeftButton : <EOL> return <EOL> index = self . tabAt ( event . pos ( ) ) <EOL> if index >= <NUM_LIT:0> : <EOL> self . rename_tab ( index ) <EOL> CUSTOM_QWIDGETS = [ ] <EOL> def load_ui ( path , parent = None , directory = None ) : <EOL> """<STR_LIT>""" <EOL> if directory is not None : <EOL> full_path = os . path . join ( directory , path ) <EOL> else : <EOL> full_path = os . path . abspath ( path ) <EOL> if not os . path . exists ( full_path ) and '<STR_LIT>' in full_path : <EOL> full_path = os . path . join ( full_path . replace ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> from glue . external . qt import load_ui <EOL> return load_ui ( full_path , parent , custom_widgets = CUSTOM_QWIDGETS ) <EOL> @ contextmanager <EOL> def process_dialog ( delay = <NUM_LIT:0> , accept = False , reject = False , function = None ) : <EOL> """<STR_LIT>""" <EOL> def _accept ( dialog ) : <EOL> dialog . accept ( ) <EOL> def _reject ( dialog ) : <EOL> dialog . reject ( ) <EOL> n_args = sum ( ( accept , reject , function is not None ) ) <EOL> if n_args > <NUM_LIT:1> : <EOL> raise ValueError ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> elif n_args == <NUM_LIT:0> : <EOL> raise ValueError ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> if accept : <EOL> function = _accept <EOL> elif reject : <EOL> function = _reject <EOL> def wrapper ( ) : <EOL> from glue . external . qt import get_qapp <EOL> app = get_qapp ( ) <EOL> dialog = app . focusWidget ( ) . window ( ) <EOL> function ( dialog ) <EOL> timer = QtCore . QTimer ( ) <EOL> timer . setInterval ( delay ) <EOL> timer . setSingleShot ( True ) <EOL> timer . timeout . connect ( wrapper ) <EOL> timer . start ( ) <EOL> yield </s>
