<s> from utils import log , open_folder_in_explorer <EOL> import os <EOL> import re <EOL> import glob <EOL> import sys <EOL> import codecs <EOL> import platform <EOL> import requests <EOL> import validators <EOL> from PySide import QtGui , QtCore <EOL> from PySide . QtGui import QApplication , QHBoxLayout , QVBoxLayout <EOL> from PySide . QtNetwork import QHttp <EOL> from PySide . QtCore import QUrl , QFile , QIODevice , QCoreApplication <EOL> from pycns import pngs_from_icns <EOL> from command_line import CommandBase , logger , get_file <EOL> from command_line import __version__ as __gui_version__ <EOL> from utils import get_data_path , get_data_file_path <EOL> import utils <EOL> COMMAND_LINE = False <EOL> MAX_RECENT = <NUM_LIT:10> <EOL> def url_exists ( path ) : <EOL> if validators . url ( path ) : <EOL> return True <EOL> return False <EOL> class ExistingProjectDialog ( QtGui . QDialog ) : <EOL> def __init__ ( self , recent_projects , directory_callback , parent = None ) : <EOL> super ( ExistingProjectDialog , self ) . __init__ ( parent ) <EOL> self . setWindowTitle ( '<STR_LIT>' ) <EOL> self . setWindowIcon ( QtGui . QIcon ( get_file ( '<STR_LIT>' ) ) ) <EOL> self . setMinimumWidth ( <NUM_LIT> ) <EOL> group_box = QtGui . QGroupBox ( '<STR_LIT>' ) <EOL> gbox_layout = QtGui . QVBoxLayout ( ) <EOL> self . project_list = QtGui . QListWidget ( ) <EOL> gbox_layout . addWidget ( self . project_list ) <EOL> group_box . setLayout ( gbox_layout ) <EOL> self . callback = directory_callback <EOL> self . projects = recent_projects <EOL> for i in range ( len ( recent_projects ) ) : <EOL> project = recent_projects [ i ] <EOL> text = u'<STR_LIT>' . format ( os . path . basename ( project ) , project ) <EOL> self . project_list . addItem ( text ) <EOL> self . project_list . itemClicked . connect ( self . project_clicked ) <EOL> self . cancel = QtGui . QPushButton ( '<STR_LIT>' ) <EOL> self . open = QtGui . QPushButton ( '<STR_LIT>' ) <EOL> self . browse = QtGui . QPushButton ( '<STR_LIT>' ) <EOL> self . open . setEnabled ( False ) <EOL> self . open . clicked . connect ( self . open_clicked ) <EOL> self . browse . clicked . connect ( self . browse_clicked ) <EOL> buttons = QtGui . QWidget ( ) <EOL> button_layout = QtGui . QHBoxLayout ( ) <EOL> button_layout . addWidget ( self . cancel ) <EOL> button_layout . addWidget ( QtGui . QWidget ( ) ) <EOL> button_layout . addWidget ( self . browse ) <EOL> button_layout . addWidget ( self . open ) <EOL> buttons . setLayout ( button_layout ) <EOL> layout = QtGui . QVBoxLayout ( ) <EOL> layout . addWidget ( group_box ) <EOL> layout . addWidget ( buttons ) <EOL> self . setLayout ( layout ) <EOL> self . cancel . clicked . connect ( self . cancelled ) <EOL> def browse_clicked ( self ) : <EOL> directory = QtGui . QFileDialog . getExistingDirectory ( self , '<STR_LIT>' , <EOL> self . parent ( ) . project_dir ( ) or self . parent ( ) . last_project_dir ) <EOL> if directory : <EOL> self . callback ( directory ) <EOL> self . close ( ) <EOL> def open_clicked ( self ) : <EOL> pos = self . project_list . currentRow ( ) <EOL> self . callback ( self . projects [ pos ] ) <EOL> self . close ( ) <EOL> def project_clicked ( self , item ) : <EOL> self . open . setEnabled ( True ) <EOL> def cancelled ( self ) : <EOL> self . close ( ) <EOL> class Validator ( QtGui . QRegExpValidator ) : <EOL> def __init__ ( self , regex , action , parent = None ) : <EOL> self . exp = regex <EOL> self . action = str <EOL> if hasattr ( str , action ) : <EOL> self . action = getattr ( str , action ) <EOL> reg = QtCore . QRegExp ( regex ) <EOL> super ( Validator , self ) . __init__ ( reg , parent ) <EOL> def validate ( self , text , pos ) : <EOL> result = super ( Validator , self ) . validate ( text , pos ) <EOL> return result <EOL> def fixup ( self , text ) : <EOL> return '<STR_LIT>' . join ( re . findall ( self . exp , self . action ( text ) ) ) <EOL> class BackgroundThread ( QtCore . QThread ) : <EOL> def __init__ ( self , widget , method_name , parent = None ) : <EOL> QtCore . QThread . __init__ ( self , parent ) <EOL> self . widget = widget <EOL> self . method_name = method_name <EOL> def run ( self ) : <EOL> if hasattr ( self . widget , self . method_name ) : <EOL> func = getattr ( self . widget , self . method_name ) <EOL> func ( ) <EOL> class MainWindow ( QtGui . QMainWindow , CommandBase ) : <EOL> def update_nw_versions ( self , button ) : <EOL> self . get_versions_in_background ( ) <EOL> def load_recent_projects ( self ) : <EOL> files = [ ] <EOL> history_file = get_data_file_path ( '<STR_LIT>' ) <EOL> if not os . path . exists ( history_file ) : <EOL> return files <EOL> with codecs . open ( history_file , encoding = '<STR_LIT:utf-8>' ) as f : <EOL> for line in f : <EOL> line = line . strip ( ) <EOL> if line and os . path . exists ( line ) : <EOL> files . append ( line ) <EOL> files . reverse ( ) <EOL> return files <EOL> def load_last_project_path ( self ) : <EOL> proj_path = '<STR_LIT>' <EOL> proj_file = get_data_file_path ( '<STR_LIT>' ) <EOL> if os . path . exists ( proj_file ) : <EOL> with codecs . open ( proj_file , encoding = '<STR_LIT:utf-8>' ) as f : <EOL> proj_path = f . read ( ) . strip ( ) <EOL> if not proj_path : <EOL> proj_path = QtCore . QDir . currentPath ( ) <EOL> return proj_path <EOL> def save_project_path ( self , path ) : <EOL> proj_file = get_data_file_path ( '<STR_LIT>' ) <EOL> with codecs . open ( proj_file , '<STR_LIT>' , encoding = '<STR_LIT:utf-8>' ) as f : <EOL> f . write ( path ) <EOL> def save_recent_project ( self , proj ) : <EOL> recent_file_path = get_data_file_path ( '<STR_LIT>' ) <EOL> max_length = MAX_RECENT <EOL> recent_files = [ ] <EOL> if os . path . exists ( recent_file_path ) : <EOL> recent_files = codecs . open ( recent_file_path , encoding = '<STR_LIT:utf-8>' ) . read ( ) . split ( u'<STR_LIT:\n>' ) <EOL> try : <EOL> recent_files . remove ( proj ) <EOL> except ValueError : <EOL> pass <EOL> recent_files . append ( proj ) <EOL> with codecs . open ( recent_file_path , '<STR_LIT>' , encoding = '<STR_LIT:utf-8>' ) as f : <EOL> for recent_file in recent_files [ - max_length : ] : <EOL> if recent_file and os . path . exists ( recent_file ) : <EOL> f . write ( u'<STR_LIT>' . format ( recent_file ) ) <EOL> def update_recent_files ( self ) : <EOL> previous_files = self . load_recent_projects ( ) <EOL> self . recent_separator . setVisible ( len ( previous_files ) > <NUM_LIT:0> ) <EOL> for i in range ( len ( previous_files ) ) : <EOL> text = u'<STR_LIT>' . format ( i + <NUM_LIT:1> , os . path . basename ( previous_files [ i ] ) ) <EOL> action = self . recent_file_actions [ i ] <EOL> action . setText ( text ) <EOL> action . setData ( previous_files [ i ] ) <EOL> action . setVisible ( True ) <EOL> def __init__ ( self , width , height , app , parent = None ) : <EOL> super ( MainWindow , self ) . __init__ ( parent ) <EOL> CommandBase . __init__ ( self ) <EOL> recent_projects = self . load_recent_projects ( ) <EOL> self . existing_dialog = ExistingProjectDialog ( recent_projects , self . load_project , parent = self ) <EOL> drect = QtGui . QApplication . desktop ( ) . availableGeometry ( self ) <EOL> center = drect . center ( ) <EOL> self . move ( center . x ( ) - self . width ( ) * <NUM_LIT:0.5> , center . y ( ) - self . height ( ) * <NUM_LIT:0.5> ) <EOL> self . icon_style = '<STR_LIT>' <EOL> self . last_project_dir = self . load_last_project_path ( ) <EOL> status_bar = QtGui . QStatusBar ( ) <EOL> self . setStatusBar ( status_bar ) <EOL> self . project_path = '<STR_LIT>' <EOL> self . project_menu = self . menuBar ( ) . addMenu ( '<STR_LIT>' ) <EOL> browse_action = QtGui . QAction ( '<STR_LIT>' , self . project_menu , <EOL> shortcut = QtGui . QKeySequence . Open , <EOL> statusTip = '<STR_LIT>' , <EOL> triggered = self . browse_dir ) <EOL> self . project_menu . addAction ( browse_action ) <EOL> self . project_menu . addSeparator ( ) <EOL> self . recent_file_actions = [ ] <EOL> for i in range ( MAX_RECENT ) : <EOL> if i == <NUM_LIT:9> : <EOL> key = <NUM_LIT:0> <EOL> else : <EOL> key = i + <NUM_LIT:1> <EOL> action = QtGui . QAction ( self , visible = False , triggered = self . open_recent_file , <EOL> shortcut = QtGui . QKeySequence ( '<STR_LIT>' . format ( key ) ) ) <EOL> self . recent_file_actions . append ( action ) <EOL> self . project_menu . addAction ( action ) <EOL> self . recent_separator = self . project_menu . addSeparator ( ) <EOL> self . update_recent_files ( ) <EOL> exit_action = QtGui . QAction ( '<STR_LIT>' , self . project_menu ) <EOL> exit_action . triggered . connect ( QtGui . qApp . closeAllWindows ) <EOL> self . project_menu . addAction ( exit_action ) <EOL> self . logger = logger <EOL> self . gui_app = app <EOL> self . desktop_width = app . desktop ( ) . screenGeometry ( ) . width ( ) <EOL> self . desktop_height = app . desktop ( ) . screenGeometry ( ) . height ( ) <EOL> self . options_enabled = False <EOL> self . output_package_json = True <EOL> self . setWindowIcon ( QtGui . QIcon ( get_file ( '<STR_LIT>' ) ) ) <EOL> self . update_json = False <EOL> self . setup_nw_versions ( ) <EOL> self . thread = None <EOL> self . original_packagejson = { } <EOL> self . resize ( width , height ) <EOL> self . extract_error = None <EOL> self . create_application_layout ( ) <EOL> self . option_settings_enabled ( False ) <EOL> self . setWindowTitle ( u"<STR_LIT>" . format ( __gui_version__ ) ) <EOL> self . update_nw_versions ( None ) <EOL> def open_recent_file ( self ) : <EOL> action = self . sender ( ) <EOL> if action : <EOL> self . load_project ( action . data ( ) ) <EOL> def setup_nw_versions ( self ) : <EOL> nw_version = self . get_setting ( '<STR_LIT>' ) <EOL> try : <EOL> f = codecs . open ( get_data_file_path ( '<STR_LIT>' ) , encoding = '<STR_LIT:utf-8>' ) <EOL> for line in f : <EOL> nw_version . values . append ( line . strip ( ) ) <EOL> f . close ( ) <EOL> except IOError : <EOL> nw_version . values . append ( nw_version . default_value ) <EOL> def create_application_layout ( self ) : <EOL> self . main_layout = QtGui . QVBoxLayout ( ) <EOL> self . tab_widget = QtGui . QTabWidget ( ) <EOL> self . main_layout . setContentsMargins ( <NUM_LIT:10> , <NUM_LIT:5> , <NUM_LIT:10> , <NUM_LIT:5> ) <EOL> self . create_layout_widgets ( ) <EOL> self . addWidgets_to_main_layout ( ) <EOL> w = QtGui . QWidget ( ) <EOL> w . setLayout ( self . main_layout ) <EOL> self . setCentralWidget ( w ) <EOL> def create_layout_widgets ( self ) : <EOL> self . download_bar_widget = self . create_download_bar ( ) <EOL> self . app_settings_widget = self . create_application_settings ( ) <EOL> self . comp_settings_widget = self . create_compression_settings ( ) <EOL> self . win_settings_widget = self . create_window_settings ( ) <EOL> self . ex_settings_widget = self . create_export_settings ( ) <EOL> self . dl_settings_widget = self . create_download_settings ( ) <EOL> self . directory_chooser_widget = self . create_directory_choose ( ) <EOL> def addWidgets_to_main_layout ( self ) : <EOL> self . warning_settings_icon = QtGui . QIcon ( get_file ( '<STR_LIT>' ) ) <EOL> self . app_settings_icon = QtGui . QIcon ( get_file ( '<STR_LIT>' ) ) <EOL> self . win_settings_icon = QtGui . QIcon ( get_file ( '<STR_LIT>' ) ) <EOL> self . ex_settings_icon = QtGui . QIcon ( get_file ( '<STR_LIT>' ) ) <EOL> self . comp_settings_icon = QtGui . QIcon ( get_file ( '<STR_LIT>' ) ) <EOL> self . download_settings_icon = QtGui . QIcon ( get_file ( '<STR_LIT>' ) ) <EOL> self . tab_icons = [ self . app_settings_icon , <EOL> self . win_settings_icon , <EOL> self . ex_settings_icon , <EOL> self . comp_settings_icon , <EOL> self . download_settings_icon ] <EOL> self . main_layout . addWidget ( self . directory_chooser_widget ) <EOL> self . tab_widget . addTab ( self . app_settings_widget , <EOL> self . app_settings_icon , <EOL> '<STR_LIT>' ) <EOL> self . tab_widget . addTab ( self . win_settings_widget , <EOL> self . win_settings_icon , <EOL> '<STR_LIT>' ) <EOL> self . tab_widget . addTab ( self . ex_settings_widget , <EOL> self . ex_settings_icon , '<STR_LIT>' ) <EOL> self . tab_widget . addTab ( self . comp_settings_widget , <EOL> self . comp_settings_icon , <EOL> '<STR_LIT>' ) <EOL> self . tab_widget . addTab ( self . dl_settings_widget , <EOL> self . download_settings_icon , <EOL> '<STR_LIT>' ) <EOL> self . main_layout . addWidget ( self . tab_widget ) <EOL> self . main_layout . addLayout ( self . download_bar_widget ) <EOL> def option_settings_enabled ( self , is_enabled ) : <EOL> self . ex_button . setEnabled ( is_enabled ) <EOL> self . app_settings_widget . setEnabled ( is_enabled ) <EOL> self . win_settings_widget . setEnabled ( is_enabled ) <EOL> self . ex_settings_widget . setEnabled ( is_enabled ) <EOL> self . comp_settings_widget . setEnabled ( is_enabled ) <EOL> self . dl_settings_widget . setEnabled ( is_enabled ) <EOL> self . options_enabled = is_enabled <EOL> def export ( self , export_button , cancel_button ) : <EOL> self . get_files_to_download ( ) <EOL> self . try_to_download_files ( ) <EOL> def open_export ( self , open_export_button ) : <EOL> open_folder_in_explorer ( self . output_dir ( ) ) <EOL> def try_to_download_files ( self ) : <EOL> if self . files_to_download : <EOL> self . progress_bar . setVisible ( True ) <EOL> self . cancel_button . setEnabled ( True ) <EOL> self . disable_ui_while_working ( ) <EOL> self . download_file_with_error_handling ( ) <EOL> else : <EOL> QtGui . QMessageBox . information ( self , <EOL> '<STR_LIT>' , <EOL> ( '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> def selected_version ( self ) : <EOL> return self . get_setting ( '<STR_LIT>' ) . value <EOL> def enable_ui_after_error ( self ) : <EOL> self . enable_ui ( ) <EOL> self . progress_text = '<STR_LIT>' <EOL> self . progress_bar . setVisible ( False ) <EOL> self . cancel_button . setEnabled ( False ) <EOL> def show_error ( self , exception ) : <EOL> QtGui . QMessageBox . information ( self , '<STR_LIT>' , exception ) <EOL> def disable_ui_while_working ( self ) : <EOL> self . option_settings_enabled ( False ) <EOL> self . directory_chooser_widget . setEnabled ( False ) <EOL> def enable_ui ( self ) : <EOL> self . option_settings_enabled ( True ) <EOL> self . directory_chooser_widget . setEnabled ( True ) <EOL> def get_tab_index_for_setting_name ( self , name ) : <EOL> options_dict = { '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : <NUM_LIT:2> , <EOL> '<STR_LIT>' : <NUM_LIT:2> , <EOL> '<STR_LIT>' : <NUM_LIT:3> , <EOL> '<STR_LIT>' : <NUM_LIT:4> } <EOL> for setting_group_name , setting_group in self . _setting_items : <EOL> if name in setting_group : <EOL> return options_dict . get ( setting_group_name , None ) <EOL> def required_settings_filled ( self , ignore_options = False ) : <EOL> if not self . options_enabled and not ignore_options : <EOL> return False <EOL> red_border = '<STR_LIT>' <EOL> settings_valid = True <EOL> for sgroup in self . settings [ '<STR_LIT>' ] + [ self . settings [ '<STR_LIT>' ] ] : <EOL> for sname , setting in sgroup . items ( ) : <EOL> if setting . type in set ( [ '<STR_LIT:file>' , '<STR_LIT>' ] ) and os . path . isabs ( setting . value ) : <EOL> setting_path = setting . value <EOL> else : <EOL> setting_path = utils . path_join ( self . project_dir ( ) , <EOL> setting . value ) <EOL> if setting . required and not setting . value : <EOL> settings_valid = False <EOL> widget = self . find_child_by_name ( setting . name ) <EOL> if widget is not None : <EOL> widget . setStyleSheet ( red_border ) <EOL> widget . setToolTip ( '<STR_LIT>' ) <EOL> tab = self . get_tab_index_for_setting_name ( setting . name ) <EOL> self . tab_widget . setTabIcon ( tab , self . warning_settings_icon ) <EOL> if ( setting . type == '<STR_LIT:file>' and <EOL> setting . value ) : <EOL> setting_path_invalid = not os . path . exists ( setting_path ) <EOL> setting_url_invalid = not url_exists ( setting . value ) <EOL> if setting_path_invalid and setting_url_invalid : <EOL> log ( setting . value , "<STR_LIT>" ) <EOL> settings_valid = False <EOL> widget = self . find_child_by_name ( setting . name ) <EOL> if widget is not None : <EOL> widget . setStyleSheet ( red_border ) <EOL> widget . setToolTip ( u'<STR_LIT>' . format ( setting . value ) ) <EOL> tab = self . get_tab_index_for_setting_name ( setting . name ) <EOL> self . tab_widget . setTabIcon ( tab , self . warning_settings_icon ) <EOL> if ( setting . type == '<STR_LIT>' and <EOL> setting . value and <EOL> not os . path . exists ( setting_path ) ) : <EOL> settings_valid = False <EOL> widget = self . find_child_by_name ( setting . name ) <EOL> if widget is not None : <EOL> widget . setStyleSheet ( red_border ) <EOL> widget . setToolTip ( u'<STR_LIT>' . format ( setting_path ) ) <EOL> tab = self . get_tab_index_for_setting_name ( setting . name ) <EOL> self . tab_widget . setTabIcon ( tab , self . warning_settings_icon ) <EOL> if settings_valid : <EOL> widget = self . find_child_by_name ( setting . name ) <EOL> if widget is not None : <EOL> widget . setStyleSheet ( '<STR_LIT>' ) <EOL> widget . setToolTip ( '<STR_LIT>' ) <EOL> tab = self . get_tab_index_for_setting_name ( setting . name ) <EOL> self . tab_widget . setTabIcon ( tab , self . tab_icons [ tab ] ) <EOL> export_chosen = False <EOL> for setting_name , setting in self . settings [ '<STR_LIT>' ] . items ( ) : <EOL> if setting . value : <EOL> export_chosen = True <EOL> if not settings_valid : <EOL> return export_chosen and settings_valid <EOL> for setting_name , setting in self . settings [ '<STR_LIT>' ] . items ( ) : <EOL> if not export_chosen : <EOL> widget = self . find_child_by_name ( setting . name ) <EOL> if widget is not None : <EOL> widget . setStyleSheet ( '<STR_LIT>' ) <EOL> widget . setToolTip ( '<STR_LIT>' ) <EOL> tab = self . get_tab_index_for_setting_name ( setting . name ) <EOL> self . tab_widget . setTabIcon ( tab , self . warning_settings_icon ) <EOL> else : <EOL> widget = self . find_child_by_name ( setting . name ) <EOL> if widget is not None : <EOL> widget . setStyleSheet ( '<STR_LIT>' ) <EOL> widget . setToolTip ( '<STR_LIT>' ) <EOL> tab = self . get_tab_index_for_setting_name ( setting . name ) <EOL> self . tab_widget . setTabIcon ( tab , self . tab_icons [ tab ] ) <EOL> return export_chosen and settings_valid <EOL> def project_dir ( self ) : <EOL> return self . project_path <EOL> if hasattr ( self , '<STR_LIT>' ) : <EOL> return self . input_line . text ( ) <EOL> return '<STR_LIT>' <EOL> def output_dir ( self ) : <EOL> if hasattr ( self , '<STR_LIT>' ) : <EOL> if os . path . isabs ( self . output_line . text ( ) ) : <EOL> return self . output_line . text ( ) <EOL> else : <EOL> return utils . path_join ( self . project_dir ( ) , self . output_line . text ( ) ) <EOL> return '<STR_LIT>' <EOL> def create_download_bar ( self ) : <EOL> hlayout = QtGui . QHBoxLayout ( ) <EOL> vlayout = QtGui . QVBoxLayout ( ) <EOL> vlayout . setContentsMargins ( <NUM_LIT:5> , <NUM_LIT:5> , <NUM_LIT:5> , <NUM_LIT:5> ) <EOL> vlayout . setSpacing ( <NUM_LIT:5> ) <EOL> hlayout . setSpacing ( <NUM_LIT:5> ) <EOL> hlayout . setContentsMargins ( <NUM_LIT:5> , <NUM_LIT:5> , <NUM_LIT:5> , <NUM_LIT:5> ) <EOL> progress_label = QtGui . QLabel ( '<STR_LIT>' ) <EOL> progress_bar = QtGui . QProgressBar ( ) <EOL> progress_bar . setVisible ( False ) <EOL> progress_bar . setContentsMargins ( <NUM_LIT:5> , <NUM_LIT:5> , <NUM_LIT:5> , <NUM_LIT:5> ) <EOL> vlayout . addWidget ( progress_label ) <EOL> vlayout . addWidget ( progress_bar ) <EOL> vlayout . addWidget ( QtGui . QLabel ( '<STR_LIT>' ) ) <EOL> ex_button = QtGui . QPushButton ( '<STR_LIT>' ) <EOL> ex_button . setEnabled ( False ) <EOL> cancel_button = QtGui . QPushButton ( '<STR_LIT>' ) <EOL> cancel_button . setEnabled ( False ) <EOL> open_export_button = QtGui . QPushButton ( ) <EOL> open_export_button . setEnabled ( False ) <EOL> open_export_button . setIcon ( QtGui . QIcon ( get_file ( '<STR_LIT>' ) ) ) <EOL> open_export_button . setToolTip ( '<STR_LIT>' ) <EOL> open_export_button . setStatusTip ( '<STR_LIT>' ) <EOL> open_export_button . setMaximumWidth ( <NUM_LIT:30> ) <EOL> open_export_button . setMaximumHeight ( <NUM_LIT:30> ) <EOL> ex_button . clicked . connect ( self . call_with_object ( '<STR_LIT>' , ex_button , cancel_button ) ) <EOL> cancel_button . clicked . connect ( self . cancel_download ) <EOL> open_export_button . clicked . connect ( self . call_with_object ( '<STR_LIT>' , open_export_button ) ) <EOL> button_box = QtGui . QDialogButtonBox ( ) <EOL> button_box . addButton ( open_export_button , QtGui . QDialogButtonBox . NoRole ) <EOL> button_box . addButton ( cancel_button , QtGui . QDialogButtonBox . RejectRole ) <EOL> button_box . addButton ( ex_button , QtGui . QDialogButtonBox . AcceptRole ) <EOL> hlayout . addLayout ( vlayout ) <EOL> hlayout . addWidget ( button_box ) <EOL> self . progress_label = progress_label <EOL> self . progress_bar = progress_bar <EOL> self . cancel_button = cancel_button <EOL> self . open_export_button = open_export_button <EOL> http = QHttp ( self ) <EOL> http . requestFinished . connect ( self . http_request_finished ) <EOL> http . dataReadProgress . connect ( self . update_progress_bar ) <EOL> http . responseHeaderReceived . connect ( self . read_response_header ) <EOL> self . http = http <EOL> self . ex_button = ex_button <EOL> return hlayout <EOL> def read_response_header ( self , response_header ) : <EOL> if response_header . statusCode ( ) not in ( <NUM_LIT:200> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) : <EOL> self . show_error ( u'<STR_LIT>' . format ( response_header . reasonPhrase ( ) ) ) <EOL> self . http_request_aborted = True <EOL> self . http . abort ( ) <EOL> self . enable_ui_after_error ( ) <EOL> def http_request_finished ( self , request_id , error ) : <EOL> if request_id != self . http_get_id : <EOL> return <EOL> if self . http_request_aborted : <EOL> if self . out_file is not None : <EOL> self . out_file . close ( ) <EOL> self . out_file . remove ( ) <EOL> self . out_file = None <EOL> return <EOL> self . out_file . close ( ) <EOL> self . http . abort ( ) <EOL> if error : <EOL> self . out_file . remove ( ) <EOL> self . show_error ( u'<STR_LIT>' . format ( self . http . errorString ( ) ) ) <EOL> self . enable_ui_after_error ( ) <EOL> else : <EOL> self . continue_downloading_or_extract ( ) <EOL> def continue_downloading_or_extract ( self ) : <EOL> if self . files_to_download : <EOL> self . progress_bar . setVisible ( True ) <EOL> self . cancel_button . setEnabled ( True ) <EOL> self . disable_ui_while_working ( ) <EOL> self . download_file_with_error_handling ( ) <EOL> else : <EOL> self . progress_text = '<STR_LIT>' <EOL> self . cancel_button . setEnabled ( False ) <EOL> self . progress_bar . setVisible ( False ) <EOL> self . extract_files_in_background ( ) <EOL> @ property <EOL> def progress_text ( self ) : <EOL> return self . progress_label . text ( ) <EOL> @ progress_text . setter <EOL> def progress_text ( self , value ) : <EOL> self . progress_label . setText ( value ) <EOL> def run_in_background ( self , method_name , callback ) : <EOL> self . thread = BackgroundThread ( self , method_name ) <EOL> self . thread . finished . connect ( callback ) <EOL> self . thread . start ( ) <EOL> def get_versions_in_background ( self ) : <EOL> self . ex_button . setEnabled ( False ) <EOL> self . run_in_background ( '<STR_LIT>' , self . done_getting_versions ) <EOL> def done_getting_versions ( self ) : <EOL> self . ex_button . setEnabled ( self . required_settings_filled ( ) ) <EOL> self . progress_text = '<STR_LIT>' <EOL> nw_version = self . get_setting ( '<STR_LIT>' ) <EOL> combo = self . find_child_by_name ( nw_version . name ) <EOL> combo . clear ( ) <EOL> combo . addItems ( nw_version . values ) <EOL> def make_output_files_in_background ( self ) : <EOL> self . ex_button . setEnabled ( False ) <EOL> self . run_in_background ( '<STR_LIT>' , self . done_making_files ) <EOL> def run_custom_script ( self ) : <EOL> script = self . get_setting ( '<STR_LIT>' ) . value <EOL> self . run_script ( script ) <EOL> def script_done ( self ) : <EOL> self . ex_button . setEnabled ( self . required_settings_filled ( ) ) <EOL> self . enable_ui ( ) <EOL> self . progress_text = '<STR_LIT>' <EOL> def done_making_files ( self ) : <EOL> self . ex_button . setEnabled ( self . required_settings_filled ( ) ) <EOL> self . progress_text = '<STR_LIT>' <EOL> self . delete_files ( ) <EOL> if self . output_err : <EOL> self . show_error ( self . output_err ) <EOL> self . enable_ui_after_error ( ) <EOL> else : <EOL> self . progress_text = '<STR_LIT>' <EOL> self . ex_button . setEnabled ( False ) <EOL> self . run_in_background ( '<STR_LIT>' , self . script_done ) <EOL> def extract_files_in_background ( self ) : <EOL> self . progress_text = '<STR_LIT>' <EOL> self . ex_button . setEnabled ( False ) <EOL> self . run_in_background ( '<STR_LIT>' , self . done_extracting ) <EOL> def done_extracting ( self ) : <EOL> self . ex_button . setEnabled ( self . required_settings_filled ( ) ) <EOL> if self . extract_error : <EOL> self . progress_text = '<STR_LIT>' <EOL> self . show_error ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> self . enable_ui_after_error ( ) <EOL> else : <EOL> self . progress_text = '<STR_LIT>' <EOL> self . make_output_files_in_background ( ) <EOL> def cancel_download ( self ) : <EOL> self . progress_text = '<STR_LIT>' <EOL> self . cancel_button . setEnabled ( False ) <EOL> self . http_request_aborted = True <EOL> self . http . abort ( ) <EOL> self . enable_ui ( ) <EOL> self . progress_bar . setValue ( <NUM_LIT:0> ) <EOL> self . progress_bar . setVisible ( False ) <EOL> def update_progress_bar ( self , bytes_read , total_bytes ) : <EOL> if self . http_request_aborted : <EOL> self . progress_bar . setValue ( <NUM_LIT:0> ) <EOL> self . progress_bar . setVisible ( False ) <EOL> return <EOL> self . progress_bar . setMaximum ( total_bytes ) <EOL> self . progress_bar . setValue ( bytes_read ) <EOL> def download_file ( self , path , setting ) : <EOL> version_file = self . settings [ '<STR_LIT>' ] . format ( self . selected_version ( ) ) <EOL> sdk_build_setting = self . get_setting ( '<STR_LIT>' ) <EOL> sdk_build = sdk_build_setting . value <EOL> location = self . get_setting ( '<STR_LIT>' ) . value <EOL> versions = re . findall ( '<STR_LIT>' , path ) [ <NUM_LIT:0> ] <EOL> minor = int ( versions [ <NUM_LIT:1> ] ) <EOL> if minor >= <NUM_LIT:12> : <EOL> path = path . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if minor >= <NUM_LIT> and sdk_build : <EOL> path = utils . replace_right ( path , '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:1> ) <EOL> self . progress_text = u'<STR_LIT>' . format ( path . replace ( version_file , '<STR_LIT>' ) ) <EOL> url = QUrl ( path ) <EOL> file_name = setting . save_file_path ( self . selected_version ( ) , location , sdk_build ) <EOL> archive_exists = QFile . exists ( file_name ) <EOL> forced = self . get_setting ( '<STR_LIT>' ) . value <EOL> if archive_exists and not forced : <EOL> self . continue_downloading_or_extract ( ) <EOL> return <EOL> self . out_file = QFile ( file_name ) <EOL> if not self . out_file . open ( QIODevice . WriteOnly ) : <EOL> error = self . out_file . error ( ) . name <EOL> self . show_error ( u'<STR_LIT>' . format ( file_name , <EOL> error ) ) <EOL> self . out_file = None <EOL> self . enable_ui ( ) <EOL> return <EOL> mode = QHttp . ConnectionModeHttp <EOL> port = url . port ( ) <EOL> if port == - <NUM_LIT:1> : <EOL> port = <NUM_LIT:0> <EOL> self . http . setHost ( url . host ( ) , mode , port ) <EOL> self . http_request_aborted = False <EOL> path = QUrl . toPercentEncoding ( url . path ( ) , "<STR_LIT>" ) <EOL> if path : <EOL> path = str ( path ) <EOL> else : <EOL> path = u'<STR_LIT:/>' <EOL> self . http_get_id = self . http . get ( path , self . out_file ) <EOL> def create_icon_box ( self , name , text ) : <EOL> style = '<STR_LIT>' <EOL> icon_label = QtGui . QLabel ( ) <EOL> icon_label . setStyleSheet ( style ) <EOL> icon_label . setMaximumWidth ( <NUM_LIT> ) <EOL> icon_label . setMinimumWidth ( <NUM_LIT> ) <EOL> icon_label . setMaximumHeight ( <NUM_LIT> ) <EOL> icon_label . setMinimumHeight ( <NUM_LIT> ) <EOL> setattr ( self , name , icon_label ) <EOL> icon_text = QtGui . QLabel ( text ) <EOL> icon_text . setStyleSheet ( '<STR_LIT>' ) <EOL> icon_text . setAlignment ( QtCore . Qt . AlignCenter ) <EOL> vbox = QVBoxLayout ( ) <EOL> vbox . setAlignment ( QtCore . Qt . AlignCenter ) <EOL> vbox . addWidget ( icon_label ) <EOL> vbox . addWidget ( icon_text ) <EOL> vbox . setContentsMargins ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> w = QtGui . QWidget ( ) <EOL> w . setLayout ( vbox ) <EOL> w . setMaximumWidth ( <NUM_LIT> ) <EOL> return w <EOL> def create_directory_choose ( self ) : <EOL> group_box = QtGui . QGroupBox ( '<STR_LIT>' ) <EOL> title_hbox = QHBoxLayout ( ) <EOL> title_hbox . setContentsMargins ( <NUM_LIT:10> , <NUM_LIT:10> , <NUM_LIT:10> , <NUM_LIT:10> ) <EOL> win_icon = self . create_icon_box ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> exe_icon = self . create_icon_box ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> mac_icon = self . create_icon_box ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . title_label = QtGui . QLabel ( '<STR_LIT>' ) <EOL> self . title_label . setStyleSheet ( '<STR_LIT>' ) <EOL> title_hbox . addWidget ( self . title_label ) <EOL> title_hbox . addWidget ( QtGui . QLabel ( ) ) <EOL> title_hbox . addWidget ( win_icon ) <EOL> title_hbox . addWidget ( exe_icon ) <EOL> title_hbox . addWidget ( mac_icon ) <EOL> vlayout = QtGui . QVBoxLayout ( ) <EOL> vlayout . setSpacing ( <NUM_LIT:5> ) <EOL> vlayout . setContentsMargins ( <NUM_LIT:10> , <NUM_LIT:5> , <NUM_LIT:10> , <NUM_LIT:5> ) <EOL> vlayout . addLayout ( title_hbox ) <EOL> group_box . setLayout ( vlayout ) <EOL> return group_box <EOL> def set_window_icon ( self ) : <EOL> icon_setting = self . get_setting ( '<STR_LIT>' ) <EOL> mac_icon_setting = self . get_setting ( '<STR_LIT>' ) <EOL> exe_icon_setting = self . get_setting ( '<STR_LIT>' ) <EOL> self . set_icon ( icon_setting . value , self . window_icon ) <EOL> if not mac_icon_setting . value : <EOL> self . set_icon ( icon_setting . value , self . mac_icon ) <EOL> if not exe_icon_setting . value : <EOL> self . set_icon ( icon_setting . value , self . exe_icon ) <EOL> def set_exe_icon ( self ) : <EOL> icon_setting = self . get_setting ( '<STR_LIT>' ) <EOL> self . set_icon ( icon_setting . value , self . exe_icon ) <EOL> def set_mac_icon ( self ) : <EOL> icon_setting = self . get_setting ( '<STR_LIT>' ) <EOL> self . set_icon ( icon_setting . value , self . mac_icon ) <EOL> def set_icon ( self , icon_path , icon ) : <EOL> if icon_path : <EOL> icon_path = utils . path_join ( self . project_dir ( ) , icon_path ) <EOL> if os . path . exists ( icon_path ) : <EOL> if icon_path . endswith ( '<STR_LIT>' ) : <EOL> pngs = pngs_from_icns ( icon_path ) <EOL> if pngs : <EOL> image = QtGui . QImage . fromData ( QtCore . QByteArray ( pngs [ - <NUM_LIT:1> ] . data ) , '<STR_LIT>' ) <EOL> else : <EOL> return <EOL> else : <EOL> image = QtGui . QImage ( icon_path ) <EOL> if image . width ( ) >= image . height ( ) : <EOL> image = image . scaledToWidth ( <NUM_LIT> , <EOL> QtCore . Qt . SmoothTransformation ) <EOL> else : <EOL> image = image . scaledToHeight ( <NUM_LIT> , <EOL> QtCore . Qt . SmoothTransformation ) <EOL> icon . setPixmap ( QtGui . QPixmap . fromImage ( image ) ) <EOL> icon . setStyleSheet ( '<STR_LIT>' ) <EOL> else : <EOL> icon . setPixmap ( None ) <EOL> icon . setStyleSheet ( self . icon_style ) <EOL> else : <EOL> icon . setPixmap ( None ) <EOL> icon . setStyleSheet ( self . icon_style ) <EOL> def call_with_object ( self , name , obj , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> def call ( * cargs , ** ckwargs ) : <EOL> if hasattr ( self , name ) : <EOL> func = getattr ( self , name ) <EOL> kwargs . update ( ckwargs ) <EOL> func ( obj , * ( args + cargs ) , ** kwargs ) <EOL> return call <EOL> def find_child_by_name ( self , name ) : <EOL> return self . findChild ( QtCore . QObject , name ) <EOL> def find_all_children ( self , names ) : <EOL> children = [ ] <EOL> for child in self . find_children ( QtCore . QObject ) : <EOL> if child . object_name ( ) in names : <EOL> children . append ( child ) <EOL> return children <EOL> def project_name ( self ) : <EOL> return self . find_child_by_name ( '<STR_LIT>' ) . text ( ) <EOL> def browse_dir ( self ) : <EOL> directory = QtGui . QFileDialog . getExistingDirectory ( self , '<STR_LIT>' , <EOL> self . project_dir ( ) or self . last_project_dir ) <EOL> if directory : <EOL> self . load_project ( directory ) <EOL> def load_project ( self , directory ) : <EOL> self . update_json = False <EOL> self . project_path = directory <EOL> self . save_recent_project ( directory ) <EOL> self . save_project_path ( directory ) <EOL> self . update_recent_files ( ) <EOL> self . reset_settings ( ) <EOL> proj_name = os . path . basename ( directory ) <EOL> self . title_label . setText ( proj_name ) <EOL> setting_input = self . find_child_by_name ( '<STR_LIT>' ) <EOL> files = ( glob . glob ( utils . path_join ( directory , '<STR_LIT>' ) ) + <EOL> glob . glob ( utils . path_join ( directory , '<STR_LIT>' ) ) + <EOL> glob . glob ( utils . path_join ( directory , '<STR_LIT>' ) ) ) <EOL> if not setting_input . text ( ) : <EOL> if files : <EOL> setting_input . setText ( files [ <NUM_LIT:0> ] . replace ( self . project_dir ( ) + os . path . sep , '<STR_LIT>' ) ) <EOL> app_name_input = self . find_child_by_name ( '<STR_LIT>' ) <EOL> name_input = self . find_child_by_name ( '<STR_LIT:name>' ) <EOL> name_setting = self . get_setting ( '<STR_LIT:name>' ) <EOL> title_input = self . find_child_by_name ( '<STR_LIT:title>' ) <EOL> if not name_input . text ( ) : <EOL> name_input . setText ( name_setting . filter_name ( proj_name ) ) <EOL> if not app_name_input . text ( ) : <EOL> app_name_input . setText ( proj_name ) <EOL> if not title_input . text ( ) : <EOL> title_input . setText ( proj_name ) <EOL> self . load_package_json ( utils . get_data_file_path ( '<STR_LIT>' ) ) <EOL> self . load_package_json ( ) <EOL> default_dir = '<STR_LIT>' <EOL> export_dir_setting = self . get_setting ( '<STR_LIT>' ) <EOL> default_dir = export_dir_setting . value or default_dir <EOL> self . output_line . setText ( default_dir ) <EOL> script_setting = self . get_setting ( '<STR_LIT>' ) <EOL> self . script_line . setText ( script_setting . value ) <EOL> self . set_window_icon ( ) <EOL> self . open_export_button . setEnabled ( True ) <EOL> self . update_json = True <EOL> def browse_out_dir ( self ) : <EOL> self . update_json = False <EOL> directory = QtGui . QFileDialog . getExistingDirectory ( self , "<STR_LIT>" , <EOL> ( self . output_line . text ( ) or <EOL> self . project_dir ( ) or <EOL> self . last_project_dir ) ) <EOL> if directory : <EOL> self . update_json = True <EOL> self . output_line . setText ( directory ) <EOL> def get_file ( self , obj , text_obj , setting , * args , ** kwargs ) : <EOL> file_path , _ = QtGui . QFileDialog . getOpenFileName ( self , '<STR_LIT>' , <EOL> ( setting . last_value or <EOL> self . project_dir ( ) or <EOL> QtCore . QDir . currentPath ( ) ) , <EOL> setting . file_types ) <EOL> if file_path : <EOL> file_path = os . path . abspath ( file_path ) <EOL> file_path = file_path . replace ( self . project_dir ( ) + os . path . sep , '<STR_LIT>' ) <EOL> text_obj . setText ( file_path ) <EOL> setting . last_value = file_path <EOL> def get_file_reg ( self , obj , text_obj , setting , file_types , * args , ** kwargs ) : <EOL> file_path , _ = QtGui . QFileDialog . getOpenFileName ( self , '<STR_LIT>' , <EOL> ( setting . last_value or <EOL> self . project_dir ( ) or <EOL> QtCore . QDir . currentPath ( ) ) , <EOL> file_types ) <EOL> if file_path : <EOL> file_path = os . path . abspath ( file_path ) <EOL> file_path = file_path . replace ( self . project_dir ( ) + os . path . sep , '<STR_LIT>' ) <EOL> text_obj . setText ( file_path ) <EOL> setting . last_value = file_path <EOL> def get_folder ( self , obj , text_obj , setting , * args , ** kwargs ) : <EOL> folder = QtGui . QFileDialog . getExistingDirectory ( self , '<STR_LIT>' , <EOL> ( setting . last_value or <EOL> QtCore . QDir . currentPath ( ) ) ) <EOL> if folder : <EOL> folder = folder . replace ( self . project_dir ( ) + os . path . sep , '<STR_LIT>' ) <EOL> text_obj . setText ( folder ) <EOL> setting . last_value = folder <EOL> def create_application_settings ( self ) : <EOL> group_box = QtGui . QWidget ( ) <EOL> vlayout = self . create_layout ( self . settings [ '<STR_LIT>' ] [ '<STR_LIT>' ] , cols = <NUM_LIT:3> ) <EOL> group_box . setLayout ( vlayout ) <EOL> return group_box <EOL> def create_compression_settings ( self ) : <EOL> group_box = QtGui . QWidget ( ) <EOL> vlayout = self . create_layout ( self . settings [ '<STR_LIT>' ] [ '<STR_LIT>' ] , cols = <NUM_LIT:1> ) <EOL> warning_label = QtGui . QLabel ( '<STR_LIT>' ) <EOL> vbox = QtGui . QVBoxLayout ( ) <EOL> vbox . addLayout ( vlayout ) <EOL> vbox . addWidget ( warning_label ) <EOL> group_box . setLayout ( vbox ) <EOL> return group_box <EOL> def create_setting ( self , name ) : <EOL> setting = self . get_setting ( name ) <EOL> if setting . type == '<STR_LIT:string>' : <EOL> return self . create_text_input_setting ( name ) <EOL> elif setting . type == '<STR_LIT>' : <EOL> return self . create_text_input_setting ( name ) <EOL> elif setting . type == '<STR_LIT:file>' : <EOL> return self . create_text_input_with_file_setting ( name ) <EOL> elif setting . type == '<STR_LIT>' : <EOL> return self . create_text_input_with_folder_setting ( name ) <EOL> elif setting . type == '<STR_LIT>' : <EOL> return self . create_check_setting ( name ) <EOL> elif setting . type == '<STR_LIT:list>' : <EOL> return self . create_list_setting ( name ) <EOL> elif setting . type == '<STR_LIT>' : <EOL> return self . create_range_setting ( name ) <EOL> def create_window_settings ( self ) : <EOL> group_box = QtGui . QWidget ( ) <EOL> vlayout = self . create_layout ( self . settings [ '<STR_LIT>' ] [ '<STR_LIT>' ] , cols = <NUM_LIT:3> ) <EOL> group_box . setLayout ( vlayout ) <EOL> return group_box <EOL> def create_export_settings ( self ) : <EOL> group_box = QtGui . QWidget ( ) <EOL> vlayout = self . create_layout ( self . settings [ '<STR_LIT>' ] [ '<STR_LIT>' ] , cols = <NUM_LIT:4> ) <EOL> output_layout = QtGui . QHBoxLayout ( ) <EOL> output_label = QtGui . QLabel ( '<STR_LIT>' ) <EOL> output_label . setMinimumWidth ( <NUM_LIT> ) <EOL> self . output_line = QtGui . QLineEdit ( ) <EOL> self . output_line . textChanged . connect ( self . call_with_object ( '<STR_LIT>' , <EOL> self . output_line , <EOL> self . get_setting ( '<STR_LIT>' ) ) ) <EOL> self . output_line . textChanged . connect ( self . project_path_changed ) <EOL> self . output_line . setStatusTip ( '<STR_LIT>' ) <EOL> output_button = QtGui . QPushButton ( '<STR_LIT>' ) <EOL> output_button . clicked . connect ( self . browse_out_dir ) <EOL> output_layout . addWidget ( output_label ) <EOL> output_layout . addWidget ( self . output_line ) <EOL> output_layout . addWidget ( output_button ) <EOL> script_layout = QtGui . QHBoxLayout ( ) <EOL> script_label = QtGui . QLabel ( '<STR_LIT>' ) <EOL> script_label . setMinimumWidth ( <NUM_LIT> ) <EOL> self . script_line = QtGui . QLineEdit ( ) <EOL> script_setting = self . get_setting ( '<STR_LIT>' ) <EOL> self . script_line . setObjectName ( script_setting . name ) <EOL> self . script_line . textChanged . connect ( self . call_with_object ( '<STR_LIT>' , <EOL> self . script_line , <EOL> script_setting ) ) <EOL> self . script_line . setStatusTip ( '<STR_LIT>' ) <EOL> script_button = QtGui . QPushButton ( '<STR_LIT>' ) <EOL> file_types = [ '<STR_LIT>' ] <EOL> if platform . system ( ) == '<STR_LIT>' : <EOL> file_types . append ( '<STR_LIT>' ) <EOL> else : <EOL> file_types . append ( '<STR_LIT>' ) <EOL> script_button . clicked . connect ( self . call_with_object ( '<STR_LIT>' , script_button , <EOL> self . script_line , script_setting , <EOL> '<STR_LIT:U+0020>' . join ( file_types ) ) ) <EOL> script_layout . addWidget ( script_label ) <EOL> script_layout . addWidget ( self . script_line ) <EOL> script_layout . addWidget ( script_button ) <EOL> vbox = QtGui . QVBoxLayout ( ) <EOL> vbox . addLayout ( vlayout ) <EOL> vbox . addLayout ( output_layout ) <EOL> vbox . addLayout ( script_layout ) <EOL> group_box . setLayout ( vbox ) <EOL> return group_box <EOL> def create_download_settings ( self ) : <EOL> group_box = QtGui . QWidget ( ) <EOL> vlayout = self . create_layout ( self . settings [ '<STR_LIT>' ] [ '<STR_LIT>' ] , cols = <NUM_LIT:1> ) <EOL> group_box . setLayout ( vlayout ) <EOL> return group_box <EOL> def create_layout ( self , settings , cols = <NUM_LIT:3> ) : <EOL> glayout = QtGui . QGridLayout ( ) <EOL> glayout . setContentsMargins ( <NUM_LIT:10> , <NUM_LIT:15> , <NUM_LIT:10> , <NUM_LIT:5> ) <EOL> glayout . setAlignment ( QtCore . Qt . AlignTop ) <EOL> glayout . setSpacing ( <NUM_LIT:10> ) <EOL> glayout . setHorizontalSpacing ( <NUM_LIT:20> ) <EOL> col = <NUM_LIT:0> <EOL> row = <NUM_LIT:0> <EOL> for setting_name in settings : <EOL> setting = self . get_setting ( setting_name ) <EOL> if col >= cols * <NUM_LIT:2> : <EOL> row += <NUM_LIT:1> <EOL> col = <NUM_LIT:0> <EOL> display_name = setting . display_name + '<STR_LIT::>' <EOL> if setting . required : <EOL> display_name += '<STR_LIT:*>' <EOL> setting_label = QtGui . QLabel ( display_name ) <EOL> setting_label . setToolTip ( setting . description ) <EOL> setting_label . setStatusTip ( setting . description ) <EOL> glayout . addWidget ( setting_label , row , col ) <EOL> glayout . addLayout ( self . create_setting ( setting_name ) , <EOL> row , col + <NUM_LIT:1> ) <EOL> col += <NUM_LIT:2> <EOL> return glayout <EOL> def create_text_input_setting ( self , name ) : <EOL> hlayout = QtGui . QHBoxLayout ( ) <EOL> setting = self . get_setting ( name ) <EOL> text = QtGui . QLineEdit ( ) <EOL> text . setValidator ( Validator ( setting . filter , setting . filter_action ) ) <EOL> text . setObjectName ( setting . name ) <EOL> text . textChanged . connect ( self . call_with_object ( '<STR_LIT>' , <EOL> text , setting ) ) <EOL> if setting . value : <EOL> text . setText ( setting . value ) <EOL> text . setStatusTip ( setting . description ) <EOL> text . setToolTip ( setting . description ) <EOL> hlayout . addWidget ( text ) <EOL> return hlayout <EOL> def create_text_input_with_file_setting ( self , name ) : <EOL> hlayout = QtGui . QHBoxLayout ( ) <EOL> setting = self . get_setting ( name ) <EOL> text = QtGui . QLineEdit ( ) <EOL> text . setObjectName ( setting . name ) <EOL> button = QtGui . QPushButton ( '<STR_LIT>' ) <EOL> button . setMaximumWidth ( <NUM_LIT:30> ) <EOL> button . setMaximumHeight ( <NUM_LIT> ) <EOL> button . clicked . connect ( self . call_with_object ( '<STR_LIT>' , button , <EOL> text , setting ) ) <EOL> if setting . value : <EOL> text . setText ( setting . value ) <EOL> text . setStatusTip ( setting . description ) <EOL> text . setToolTip ( setting . description ) <EOL> text . textChanged . connect ( self . call_with_object ( '<STR_LIT>' , <EOL> text , setting ) ) <EOL> hlayout . addWidget ( text ) <EOL> hlayout . addWidget ( button ) <EOL> return hlayout <EOL> def create_text_input_with_folder_setting ( self , name ) : <EOL> hlayout = QtGui . QHBoxLayout ( ) <EOL> setting = self . get_setting ( name ) <EOL> text = QtGui . QLineEdit ( ) <EOL> text . setObjectName ( setting . name ) <EOL> button = QtGui . QPushButton ( '<STR_LIT>' ) <EOL> button . setMaximumWidth ( <NUM_LIT:30> ) <EOL> button . setMaximumHeight ( <NUM_LIT> ) <EOL> button . clicked . connect ( self . call_with_object ( '<STR_LIT>' , button , <EOL> text , setting ) ) <EOL> if setting . value : <EOL> text . setText ( setting . value ) <EOL> text . setStatusTip ( setting . description ) <EOL> text . setToolTip ( setting . description ) <EOL> text . textChanged . connect ( self . call_with_object ( '<STR_LIT>' , <EOL> text , setting ) ) <EOL> hlayout . addWidget ( text ) <EOL> hlayout . addWidget ( button ) <EOL> return hlayout <EOL> def reset_settings ( self ) : <EOL> for sgroup in self . settings [ '<STR_LIT>' ] : <EOL> for setting in sgroup . values ( ) : <EOL> widget = self . find_child_by_name ( setting . name ) <EOL> if widget is None : <EOL> continue <EOL> if ( setting . type == '<STR_LIT:string>' or <EOL> setting . type == '<STR_LIT:file>' or <EOL> setting . type == '<STR_LIT>' ) : <EOL> old_val = '<STR_LIT>' <EOL> if setting . default_value is not None : <EOL> old_val = setting . default_value <EOL> setting . value = old_val . replace ( '<STR_LIT:\\>' , '<STR_LIT>' ) <EOL> widget . setText ( old_val ) <EOL> elif setting . type == '<STR_LIT>' : <EOL> old_val = [ ] <EOL> if setting . default_value is not None : <EOL> old_val = setting . default_value <EOL> setting . value = [ v . replace ( '<STR_LIT:\\>' , '<STR_LIT>' ) for v in old_val ] <EOL> widget . setText ( '<STR_LIT:U+002C>' . join ( setting . value ) ) <EOL> elif setting . type == '<STR_LIT>' : <EOL> old_val = False <EOL> if setting . default_value is not None : <EOL> old_val = setting . default_value <EOL> setting . value = old_val <EOL> widget . setChecked ( old_val ) <EOL> elif setting . type == '<STR_LIT>' : <EOL> old_val = <NUM_LIT:0> <EOL> if setting . default_value is not None : <EOL> old_val = setting . default_value <EOL> setting . value = old_val <EOL> widget . setValue ( old_val ) <EOL> def set_kiosk_emulation_options ( self , is_checked ) : <EOL> if is_checked : <EOL> width_field = self . find_child_by_name ( '<STR_LIT:width>' ) <EOL> width_field . setText ( self . desktop_width ) <EOL> height_field = self . find_child_by_name ( '<STR_LIT>' ) <EOL> height_field . setText ( self . desktop_height ) <EOL> toolbar_field = self . find_child_by_name ( '<STR_LIT>' ) <EOL> toolbar_field . setChecked ( not is_checked ) <EOL> frame_field = self . find_child_by_name ( '<STR_LIT>' ) <EOL> frame_field . setChecked ( not is_checked ) <EOL> show_field = self . find_child_by_name ( '<STR_LIT>' ) <EOL> show_field . setChecked ( is_checked ) <EOL> kiosk_field = self . find_child_by_name ( '<STR_LIT>' ) <EOL> kiosk_field . setChecked ( not is_checked ) <EOL> fullscreen_field = self . find_child_by_name ( '<STR_LIT>' ) <EOL> fullscreen_field . setChecked ( not is_checked ) <EOL> always_on_top_field = self . find_child_by_name ( '<STR_LIT>' ) <EOL> always_on_top_field . setChecked ( is_checked ) <EOL> resizable_field = self . find_child_by_name ( '<STR_LIT>' ) <EOL> resizable_field . setChecked ( not is_checked ) <EOL> def refresh_export ( self ) : <EOL> versions = self . get_version_tuple ( ) <EOL> major_ver = versions [ <NUM_LIT:0> ] <EOL> minor_ver = versions [ <NUM_LIT:1> ] <EOL> mac = self . find_child_by_name ( '<STR_LIT>' ) <EOL> if ( major_ver > <NUM_LIT:0> or minor_ver >= <NUM_LIT> ) : <EOL> if mac : <EOL> mac . setEnabled ( False ) <EOL> else : <EOL> if mac : <EOL> mac . setEnabled ( True ) <EOL> def setting_changed ( self , obj , setting , * args , ** kwargs ) : <EOL> if ( setting . type == '<STR_LIT:string>' or <EOL> setting . type == '<STR_LIT:file>' or <EOL> setting . type == '<STR_LIT>' ) : <EOL> setting . value = args [ <NUM_LIT:0> ] <EOL> elif setting . type == '<STR_LIT>' : <EOL> setting . value = args [ <NUM_LIT:0> ] . split ( '<STR_LIT:U+002C>' ) <EOL> elif setting . type == '<STR_LIT>' : <EOL> setting . value = obj . isChecked ( ) <EOL> check_action = setting . check_action <EOL> if hasattr ( self , check_action ) : <EOL> getattr ( self , check_action ) ( obj . isChecked ( ) ) <EOL> elif setting . type == '<STR_LIT:list>' : <EOL> setting . value = obj . currentText ( ) <EOL> elif setting . type == '<STR_LIT>' : <EOL> setting . value = obj . value ( ) <EOL> if setting . action is not None : <EOL> action = getattr ( self , setting . action , None ) <EOL> if callable ( action ) : <EOL> action ( ) <EOL> if self . update_json : <EOL> json_file = utils . path_join ( self . project_dir ( ) , '<STR_LIT>' ) <EOL> global_json = utils . get_data_file_path ( '<STR_LIT>' ) <EOL> with codecs . open ( json_file , '<STR_LIT>' , encoding = '<STR_LIT:utf-8>' ) as f : <EOL> f . write ( self . generate_json ( ) ) <EOL> with codecs . open ( global_json , '<STR_LIT>' , encoding = '<STR_LIT:utf-8>' ) as f : <EOL> f . write ( self . generate_json ( global_json = True ) ) <EOL> self . ex_button . setEnabled ( self . required_settings_filled ( ) ) <EOL> def project_path_changed ( self , text ) : <EOL> self . ex_button . setEnabled ( self . required_settings_filled ( True ) ) <EOL> dirs_filled_out = False <EOL> if self . project_dir ( ) and self . output_dir ( ) : <EOL> if os . path . exists ( self . project_dir ( ) ) : <EOL> dirs_filled_out = True <EOL> self . option_settings_enabled ( dirs_filled_out ) <EOL> def create_check_setting ( self , name ) : <EOL> hlayout = QtGui . QHBoxLayout ( ) <EOL> setting = self . get_setting ( name ) <EOL> check = QtGui . QCheckBox ( ) <EOL> check . setObjectName ( setting . name ) <EOL> check . clicked . connect ( self . call_with_object ( '<STR_LIT>' , <EOL> check , setting ) ) <EOL> check . setChecked ( setting . value ) <EOL> check . setStatusTip ( setting . description ) <EOL> check . setToolTip ( setting . description ) <EOL> hlayout . addWidget ( check ) <EOL> return hlayout <EOL> def create_list_setting ( self , name ) : <EOL> hlayout = QtGui . QHBoxLayout ( ) <EOL> setting = self . get_setting ( name ) <EOL> button = None <EOL> if setting . button : <EOL> button = QtGui . QPushButton ( setting . button ) <EOL> button . clicked . connect ( lambda : setting . button_callback ( button ) ) <EOL> combo = QtGui . QComboBox ( ) <EOL> combo . setObjectName ( setting . name ) <EOL> combo . currentIndexChanged . connect ( self . call_with_object ( '<STR_LIT>' , <EOL> combo , setting ) ) <EOL> combo . editTextChanged . connect ( self . call_with_object ( '<STR_LIT>' , <EOL> combo , setting ) ) <EOL> combo . setStatusTip ( setting . description ) <EOL> combo . setToolTip ( setting . description ) <EOL> for val in setting . values : <EOL> combo . addItem ( val ) <EOL> default_index = combo . findText ( setting . default_value ) <EOL> if default_index != - <NUM_LIT:1> : <EOL> combo . setCurrentIndex ( default_index ) <EOL> hlayout . addWidget ( QtGui . QLabel ( ) ) <EOL> hlayout . addWidget ( combo ) <EOL> if button : <EOL> hlayout . addWidget ( button ) <EOL> return hlayout <EOL> def create_range_setting ( self , name ) : <EOL> hlayout = QtGui . QHBoxLayout ( ) <EOL> setting = self . get_setting ( name ) <EOL> button = None <EOL> if setting . button : <EOL> button = QtGui . QPushButton ( setting . button ) <EOL> button . clicked . connect ( lambda : setting . button_callback ( button ) ) <EOL> slider = QtGui . QSlider ( QtCore . Qt . Orientation . Horizontal ) <EOL> slider . setRange ( setting . min , setting . max ) <EOL> slider . valueChanged . connect ( self . call_with_object ( '<STR_LIT>' , <EOL> slider , setting ) ) <EOL> slider . setObjectName ( setting . name ) <EOL> slider . setValue ( setting . default_value ) <EOL> slider . setStatusTip ( setting . description ) <EOL> slider . setToolTip ( setting . description ) <EOL> range_label = QtGui . QLabel ( str ( setting . default_value ) ) <EOL> range_label . setMaximumWidth ( <NUM_LIT:30> ) <EOL> slider . valueChanged . connect ( self . call_with_object ( '<STR_LIT>' , <EOL> range_label ) ) <EOL> w = QtGui . QWidget ( ) <EOL> whlayout = QtGui . QHBoxLayout ( ) <EOL> whlayout . addWidget ( slider ) <EOL> whlayout . addWidget ( range_label ) <EOL> w . setLayout ( whlayout ) <EOL> hlayout . addWidget ( w ) <EOL> return hlayout <EOL> def _update_range_label ( self , label , value ) : <EOL> label . setText ( str ( value ) ) <EOL> def load_package_json ( self , json_path = None ) : <EOL> setting_list = super ( MainWindow , self ) . load_package_json ( json_path ) <EOL> for setting in setting_list : <EOL> setting_field = self . find_child_by_name ( setting . name ) <EOL> if setting_field : <EOL> if ( setting . type == '<STR_LIT:file>' or <EOL> setting . type == '<STR_LIT:string>' or <EOL> setting . type == '<STR_LIT>' ) : <EOL> val_str = self . convert_val_to_str ( setting . value ) <EOL> setting_field . setText ( setting . filter_name ( val_str ) ) <EOL> if setting . type == '<STR_LIT>' : <EOL> vals = [ self . convert_val_to_str ( v ) for v in setting . value ] <EOL> setting_field . setText ( '<STR_LIT:U+002C>' . join ( vals ) ) <EOL> if setting . type == '<STR_LIT>' : <EOL> setting_field . setChecked ( setting . value ) <EOL> if setting . type == '<STR_LIT:list>' : <EOL> val_str = self . convert_val_to_str ( setting . value ) <EOL> index = setting_field . findText ( val_str ) <EOL> if index != - <NUM_LIT:1> : <EOL> setting_field . setCurrentIndex ( index ) <EOL> if setting . type == '<STR_LIT>' : <EOL> setting_field . setValue ( int ( setting . value ) ) <EOL> self . ex_button . setEnabled ( self . required_settings_filled ( ) ) <EOL> def show_and_raise ( self ) : <EOL> self . show ( ) <EOL> self . raise_ ( ) <EOL> self . existing_dialog . show ( ) <EOL> self . existing_dialog . raise_ ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> app = QApplication ( sys . argv ) <EOL> QCoreApplication . setApplicationName ( "<STR_LIT>" ) <EOL> QCoreApplication . setApplicationVersion ( __gui_version__ ) <EOL> QCoreApplication . setOrganizationName ( "<STR_LIT>" ) <EOL> QCoreApplication . setOrganizationDomain ( "<STR_LIT>" ) <EOL> frame = MainWindow ( <NUM_LIT> , <NUM_LIT> , app ) <EOL> frame . show_and_raise ( ) <EOL> sys . exit ( app . exec_ ( ) ) </s>
