<s> """<STR_LIT>""" <EOL> import os <EOL> from PyQt4 . QtCore import Qt <EOL> from PyQt4 import QtGui , uic <EOL> from PyQt4 . QtGui import QApplication , QDialog , QFileDialog <EOL> from collections import OrderedDict <EOL> from util import Util <EOL> from ckanconnector import CkanConnector <EOL> import json <EOL> FORM_CLASS , _ = uic . loadUiType ( os . path . join ( <EOL> os . path . dirname ( __file__ ) , '<STR_LIT>' ) ) <EOL> class CKANBrowserDialogSettings ( QtGui . QDialog , FORM_CLASS ) : <EOL> def __init__ ( self , settings , iface , parent = None ) : <EOL> """<STR_LIT>""" <EOL> super ( CKANBrowserDialogSettings , self ) . __init__ ( parent ) <EOL> self . setupUi ( self ) <EOL> self . iface = iface <EOL> self . main_win = parent <EOL> self . settings = settings <EOL> self . util = Util ( self . settings , self . main_win ) <EOL> self . IDC_leCacheDir . setText ( self . settings . cache_dir ) <EOL> self . IDC_leCkanApi . setText ( self . settings . ckan_url ) <EOL> self . cc = CkanConnector ( self . settings , self . util ) <EOL> self . pre_ckan_apis = None <EOL> self . fill_combobox ( ) ; <EOL> def fill_combobox ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> json_path = self . util . resolve ( u'<STR_LIT>' ) <EOL> with open ( json_path ) as json_file : <EOL> self . pre_ckan_apis = json . load ( json_file , object_pairs_hook = OrderedDict ) <EOL> for key in self . pre_ckan_apis . keys ( ) : <EOL> self . IDC_cbPreCkanApi . addItem ( key ) <EOL> value = self . pre_ckan_apis . itervalues ( ) . next ( ) <EOL> self . IDC_lblPreCkan . setText ( value ) <EOL> except IOError as err : <EOL> self . util . dlg_warning ( self . util . tr ( u"<STR_LIT>" ) . format ( err ) ) <EOL> def select_cache_dir ( self ) : <EOL> cache_dir = QFileDialog . getExistingDirectory ( <EOL> self . main_win , <EOL> self . settings . DLG_CAPTION , <EOL> self . settings . cache_dir , <EOL> QFileDialog . ShowDirsOnly | QFileDialog . DontResolveSymlinks <EOL> ) <EOL> if '<STR_LIT>' == cache_dir : <EOL> self . util . msg_log ( '<STR_LIT>' ) <EOL> else : <EOL> self . IDC_leCacheDir . setText ( cache_dir ) <EOL> def test_ckan_url ( self ) : <EOL> """<STR_LIT>""" <EOL> api_url = self . IDC_leCkanApi . text ( ) <EOL> self . util . msg_log ( '<STR_LIT>' . format ( api_url ) ) <EOL> QApplication . setOverrideCursor ( Qt . WaitCursor ) <EOL> ok , result = self . cc . test_groups ( api_url ) <EOL> QApplication . restoreOverrideCursor ( ) <EOL> if ok is False : <EOL> self . util . dlg_warning ( result ) <EOL> return <EOL> else : <EOL> self . util . dlg_information ( self . util . tr ( u"<STR_LIT>" ) ) <EOL> def pre_ckan_api ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> key = self . IDC_cbPreCkanApi . currentText ( ) <EOL> value = self . pre_ckan_apis [ key ] <EOL> self . IDC_lblPreCkan . setText ( value ) <EOL> except TypeError as err : <EOL> self . util . msg_log ( '<STR_LIT>' . format ( err ) ) <EOL> pass <EOL> def choose_pre_api ( self ) : <EOL> value = self . IDC_lblPreCkan . text ( ) <EOL> self . IDC_leCkanApi . setText ( value ) <EOL> def cancel ( self ) : <EOL> QDialog . reject ( self ) <EOL> def save ( self ) : <EOL> cache_dir = self . IDC_leCacheDir . text ( ) <EOL> if self . util . check_dir ( cache_dir ) is False : <EOL> self . util . dlg_warning ( <EOL> self . util . tr ( u'<STR_LIT>' ) . format ( self . settings . cache_dir ) <EOL> ) <EOL> return <EOL> api_url = self . IDC_leCkanApi . text ( ) <EOL> if self . util . check_api_url ( api_url ) is False : <EOL> self . util . dlg_warning ( self . util . tr ( u'<STR_LIT>' ) ) <EOL> return <EOL> self . settings . cache_dir = cache_dir <EOL> self . settings . ckan_url = api_url <EOL> self . settings . save ( ) <EOL> QDialog . accept ( self ) <EOL> def help_cache_dir ( self ) : <EOL> self . util . dlg_information ( self . util . tr ( u'<STR_LIT>' ) ) <EOL> def help_pre_urls ( self ) : <EOL> self . util . dlg_information ( self . util . tr ( u'<STR_LIT>' ) ) <EOL> def help_api_url ( self ) : <EOL> self . util . dlg_information ( self . util . tr ( u'<STR_LIT>' ) ) </s>
