def __init__(self, title_prefix=''): ProgramPage.__init__(self) self.setupUi(self) self.language = Constants.LANGUAGE_DELPHI self.edit_mode = False self.build_system_fpcmake_help_template = self.label_build_system_fpcmake_help.text( ) self.build_system_lazbuild_help_template = self.label_build_system_lazbuild_help.text( ) self.lazbuild_available = False self.setTitle('{0}{1} Configuration'.format( title_prefix, Constants.language_display_names[self.language])) self.registerField('delphi.start_mode', self.combo_start_mode) self.registerField('delphi.executable', self.edit_executable) self.registerField('delphi.compile_from_source', self.check_compile_from_source) self.registerField('delphi.build_system', self.combo_build_system) self.registerField('delphi.working_directory', self.combo_working_directory, 'currentText') self.combo_start_mode.currentIndexChanged.connect(self.update_ui_state) self.combo_start_mode.currentIndexChanged.connect( self.completeChanged.emit) self.check_compile_from_source.stateChanged.connect( self.update_ui_state) self.combo_build_system.currentIndexChanged.connect( self.update_ui_state) self.combo_build_system.currentIndexChanged.connect( self.check_build_system) self.check_show_advanced_options.stateChanged.connect( self.update_ui_state) self.label_spacer.setText('') self.edit_executable_checker = MandatoryLineEditChecker( self, self.label_executable, self.edit_executable) self.combo_working_directory_selector = MandatoryDirectorySelector( self, self.label_working_directory, self.combo_working_directory) self.make_option_list_editor = ListWidgetEditor( self.label_make_options, self.list_make_options, self.label_make_options_help, self.button_add_make_option, self.button_remove_make_option, self.button_edit_make_option, self.button_up_make_option, self.button_down_make_option, '<new Make option {0}>') self.lazbuild_option_list_editor = ListWidgetEditor( self.label_lazbuild_options, self.list_lazbuild_options, self.label_lazbuild_options_help, self.button_add_lazbuild_option, self.button_remove_lazbuild_option, self.button_edit_lazbuild_option, self.button_up_lazbuild_option, self.button_down_lazbuild_option, '<new Lazbuild option {0}>')
def __init__(self, title_prefix=''): ProgramPage.__init__(self) self.setupUi(self) self.language = Constants.LANGUAGE_JAVA self.bin_directory = '/tmp' self.class_path_candidates = [] self.setTitle('{0}{1} Configuration'.format( title_prefix, Constants.language_display_names[self.language])) self.registerField('java.version', self.combo_version) self.registerField('java.start_mode', self.combo_start_mode) self.registerField('java.main_class', self.combo_main_class, 'currentText') self.registerField('java.jar_file', self.combo_jar_file, 'currentText') self.registerField('java.working_directory', self.combo_working_directory, 'currentText') self.combo_start_mode.currentIndexChanged.connect(self.update_ui_state) self.combo_start_mode.currentIndexChanged.connect( self.completeChanged.emit) self.check_show_class_path.stateChanged.connect(self.update_ui_state) self.button_add_class_path_entry.clicked.connect( self.add_class_path_entry) self.check_show_advanced_options.stateChanged.connect( self.update_ui_state) self.label_main_class_error.setVisible(False) self.label_spacer.setText('') self.combo_main_class_checker = MandatoryEditableComboBoxChecker( self, self.label_main_class, self.combo_main_class) self.combo_jar_file_selector = MandatoryTypedFileSelector( self, self.label_jar_file, self.combo_jar_file, self.label_jar_file_type, self.combo_jar_file_type, self.label_jar_file_help) self.combo_working_directory_selector = MandatoryDirectorySelector( self, self.label_working_directory, self.combo_working_directory) self.class_path_list_editor = ListWidgetEditor( self.label_class_path, self.list_class_path, self.label_class_path_help, None, self.button_remove_class_path_entry, self.button_edit_class_path_entry, self.button_up_class_path_entry, self.button_down_class_path_entry, '<new class path entry {0}>') self.option_list_editor = ListWidgetEditor( self.label_options, self.list_options, self.label_options_help, self.button_add_option, self.button_remove_option, self.button_edit_option, self.button_up_option, self.button_down_option, '<new JVM option {0}>')
def __init__(self, title_prefix=''): ProgramPage.__init__(self) self.setupUi(self) self.language = Constants.LANGUAGE_PYTHON self.url_template = self.label_url.text() self.setTitle('{0}{1} Configuration'.format( title_prefix, Constants.language_display_names[self.language])) self.registerField('python.version', self.combo_version) self.registerField('python.start_mode', self.combo_start_mode) self.registerField('python.script_file', self.combo_script_file, 'currentText') self.registerField('python.module_name', self.edit_module_name) self.registerField('python.command', self.edit_command) self.registerField('python.working_directory', self.combo_working_directory, 'currentText') self.combo_start_mode.currentIndexChanged.connect(self.update_ui_state) self.combo_start_mode.currentIndexChanged.connect( self.completeChanged.emit) self.check_show_advanced_options.stateChanged.connect( self.update_ui_state) self.label_spacer.setText('') self.combo_script_file_selector = MandatoryTypedFileSelector( self, self.label_script_file, self.combo_script_file, self.label_script_file_type, self.combo_script_file_type, self.label_script_file_help) self.edit_module_name_checker = MandatoryLineEditChecker( self, self.label_module_name, self.edit_module_name) self.edit_command_checker = MandatoryLineEditChecker( self, self.label_command, self.edit_command) self.combo_working_directory_selector = MandatoryDirectorySelector( self, self.label_working_directory, self.combo_working_directory) self.option_list_editor = ListWidgetEditor( self.label_options, self.list_options, self.label_options_help, self.button_add_option, self.button_remove_option, self.button_edit_option, self.button_up_option, self.button_down_option, '<new Python option {0}>')
def __init__(self, title_prefix=''): ProgramPage.__init__(self) self.setupUi(self) self.language = Constants.LANGUAGE_OCTAVE self.is_full_image = None self.setTitle('{0}{1} Configuration'.format(title_prefix, Constants.language_display_names[self.language])) self.registerField('octave.version', self.combo_version) self.registerField('octave.start_mode', self.combo_start_mode) self.registerField('octave.script_file', self.combo_script_file, 'currentText') self.registerField('octave.working_directory', self.combo_working_directory, 'currentText') self.combo_start_mode.currentIndexChanged.connect(self.update_ui_state) self.combo_start_mode.currentIndexChanged.connect(self.completeChanged.emit) self.check_show_advanced_options.stateChanged.connect(self.update_ui_state) self.label_spacer.setText('') self.combo_script_file_selector = MandatoryTypedFileSelector(self, self.label_script_file, self.combo_script_file, self.label_script_file_type, self.combo_script_file_type, self.label_script_file_help) self.combo_working_directory_selector = MandatoryDirectorySelector(self, self.label_working_directory, self.combo_working_directory) self.option_list_editor = ListWidgetEditor(self.label_options, self.list_options, self.label_options_help, self.button_add_option, self.button_remove_option, self.button_edit_option, self.button_up_option, self.button_down_option, '<new Octave option {0}>')
class ProgramPageC(ProgramPage, Ui_ProgramPageC): def __init__(self, title_prefix=''): ProgramPage.__init__(self) self.setupUi(self) self.language = Constants.LANGUAGE_C self.edit_mode = False self.compile_from_source_help_new_template = self.label_compile_from_source_help_new.text( ) self.compile_from_source_help_edit_template = self.label_compile_from_source_help_edit.text( ) self.setTitle('{0}{1} Configuration'.format( title_prefix, Constants.language_display_names[self.language])) self.registerField('c.start_mode', self.combo_start_mode) self.registerField('c.executable', self.edit_executable) self.registerField('c.compile_from_source', self.check_compile_from_source) self.registerField('c.working_directory', self.combo_working_directory, 'currentText') self.combo_start_mode.currentIndexChanged.connect(self.update_ui_state) self.combo_start_mode.currentIndexChanged.connect( self.completeChanged.emit) self.check_compile_from_source.stateChanged.connect( self.update_ui_state) self.check_show_advanced_options.stateChanged.connect( self.update_ui_state) self.label_spacer.setText('') self.edit_executable_checker = MandatoryLineEditChecker( self, self.label_executable, self.edit_executable) self.combo_working_directory_selector = MandatoryDirectorySelector( self, self.label_working_directory, self.combo_working_directory) self.make_option_list_editor = ListWidgetEditor( self.label_make_options, self.list_make_options, self.label_make_options_help, self.button_add_make_option, self.button_remove_make_option, self.button_edit_make_option, self.button_up_make_option, self.button_down_make_option, '<new Make option {0}>') # overrides QWizardPage.initializePage def initializePage(self): self.set_formatted_sub_title( 'Specify how the {language} program [{name}] should be executed.') def cb_gcc_versions(versions): if versions[0].version != None: gcc = '<b>{0}</b> ({1})'.format(versions[0].executable, versions[0].version) else: gcc = '<b>{0}</b>'.format(versions[0].executable) if versions[1].version != None: gpp = '<b>{0}</b> ({1})'.format(versions[1].executable, versions[1].version) else: gpp = '<b>{0}</b>'.format(versions[1].executable) self.label_compile_from_source_help_new.setText( self.compile_from_source_help_new_template.replace( '<GCC>', gcc).replace('<G++>', gpp)) self.label_compile_from_source_help_edit.setText( self.compile_from_source_help_edit_template.replace( '<GCC>', gcc).replace('<G++>', gpp)) self.get_executable_versions('gcc', cb_gcc_versions) self.combo_start_mode.setCurrentIndex(Constants.DEFAULT_C_START_MODE) self.check_compile_from_source.setChecked(False) self.check_show_advanced_options.setChecked(False) self.combo_working_directory_selector.reset() self.make_option_list_editor.reset() # if a program exists then this page is used in an edit wizard if self.wizard().program != None: program = self.wizard().program self.edit_mode = True # start mode start_mode_api_name = program.cast_custom_option_value( 'c.start_mode', str, '<unknown>') start_mode = Constants.get_c_start_mode(start_mode_api_name) self.combo_start_mode.setCurrentIndex(start_mode) # executable self.edit_executable.setText( program.cast_custom_option_value('c.executable', str, '')) # compile from source self.check_compile_from_source.setChecked( program.cast_custom_option_value('c.compile_from_source', bool, False)) # working directory self.combo_working_directory_selector.set_current_text( program.working_directory) # make options self.make_option_list_editor.clear() for make_option in program.cast_custom_option_value_list( 'c.make_options', str, []): self.make_option_list_editor.add_item(make_option) self.update_ui_state() # overrides QWizardPage.isComplete def isComplete(self): if not self.edit_executable_checker.complete: return False return self.combo_working_directory_selector.complete and ProgramPage.isComplete( self) # overrides ProgramPage.update_ui_state def update_ui_state(self): start_mode = self.get_field('c.start_mode') start_mode_executable = start_mode == Constants.C_START_MODE_EXECUTABLE compile_from_source = self.check_compile_from_source.isChecked() show_advanced_options = self.check_show_advanced_options.isChecked() self.edit_executable.setVisible(start_mode_executable) self.label_executable_help.setVisible(start_mode_executable) self.line1.setVisible(start_mode_executable) self.check_compile_from_source.setVisible(start_mode_executable) self.label_compile_from_source_help_new.setVisible( start_mode_executable and not self.edit_mode) self.label_compile_from_source_help_edit.setVisible( start_mode_executable and self.edit_mode) self.combo_working_directory_selector.set_visible( show_advanced_options) self.make_option_list_editor.set_visible(compile_from_source and show_advanced_options) self.label_spacer.setVisible(not compile_from_source or not show_advanced_options) self.make_option_list_editor.update_ui_state() def get_make_options(self): return self.make_option_list_editor.get_items() def get_html_summary(self): start_mode = self.get_field('c.start_mode') executable = self.get_field('c.executable') compile_from_source = self.get_field('c.compile_from_source') working_directory = self.get_field('c.working_directory') make_options = ' '.join(self.make_option_list_editor.get_items()) html_text = 'Start Mode: {0}<br/>'.format( html.escape(Constants.c_start_mode_display_names[start_mode])) if start_mode == Constants.C_START_MODE_EXECUTABLE: html_text += 'Executable: {0}<br/>'.format(html.escape(executable)) if compile_from_source: html_text += 'Compile From Source: Enabled<br/>' else: html_text += 'Compile From Source: Disabled<br/>' html_text += 'Working Directory: {0}<br/>'.format( html.escape(working_directory)) if compile_from_source: html_text += 'Make Options: {0}<br/>'.format( html.escape(make_options)) return html_text def get_custom_options(self): return { 'c.start_mode': Constants.c_start_mode_api_names[self.get_field('c.start_mode')], 'c.executable': self.get_field('c.executable'), 'c.compile_from_source': self.get_field('c.compile_from_source'), 'c.make_options': self.make_option_list_editor.get_items() } def get_command(self): executable = self.get_field('c.executable') arguments = [] environment = [] working_directory = self.get_field('c.working_directory') if not executable.startswith('/'): executable = posixpath.join('./', executable) return executable, arguments, environment, working_directory def apply_program_changes(self): self.apply_program_custom_options_and_command_changes()
class ProgramPageJava(ProgramPage, Ui_ProgramPageJava): def __init__(self, title_prefix=''): ProgramPage.__init__(self) self.setupUi(self) self.language = Constants.LANGUAGE_JAVA self.bin_directory = '/tmp' self.class_path_candidates = [] self.setTitle('{0}{1} Configuration'.format( title_prefix, Constants.language_display_names[self.language])) self.registerField('java.version', self.combo_version) self.registerField('java.start_mode', self.combo_start_mode) self.registerField('java.main_class', self.combo_main_class, 'currentText') self.registerField('java.jar_file', self.combo_jar_file, 'currentText') self.registerField('java.working_directory', self.combo_working_directory, 'currentText') self.combo_start_mode.currentIndexChanged.connect(self.update_ui_state) self.combo_start_mode.currentIndexChanged.connect( self.completeChanged.emit) self.check_show_class_path.stateChanged.connect(self.update_ui_state) self.button_add_class_path_entry.clicked.connect( self.add_class_path_entry) self.check_show_advanced_options.stateChanged.connect( self.update_ui_state) self.label_main_class_error.setVisible(False) self.label_spacer.setText('') self.combo_main_class_checker = MandatoryEditableComboBoxChecker( self, self.label_main_class, self.combo_main_class) self.combo_jar_file_selector = MandatoryTypedFileSelector( self, self.label_jar_file, self.combo_jar_file, self.label_jar_file_type, self.combo_jar_file_type, self.label_jar_file_help) self.combo_working_directory_selector = MandatoryDirectorySelector( self, self.label_working_directory, self.combo_working_directory) self.class_path_list_editor = ListWidgetEditor( self.label_class_path, self.list_class_path, self.label_class_path_help, None, self.button_remove_class_path_entry, self.button_edit_class_path_entry, self.button_up_class_path_entry, self.button_down_class_path_entry, '<new class path entry {0}>') self.option_list_editor = ListWidgetEditor( self.label_options, self.list_options, self.label_options_help, self.button_add_option, self.button_remove_option, self.button_edit_option, self.button_up_option, self.button_down_option, '<new JVM option {0}>') # overrides QWizardPage.initializePage def initializePage(self): self.set_formatted_sub_title( 'Specify how the {language} program [{name}] should be executed.') self.update_combo_version('java', self.combo_version) self.combo_start_mode.setCurrentIndex( Constants.DEFAULT_JAVA_START_MODE) self.combo_jar_file_selector.reset() self.class_path_list_editor.reset() self.check_show_class_path.setChecked(False) self.check_show_advanced_options.setChecked(False) self.combo_working_directory_selector.reset() self.option_list_editor.reset() # if a program exists then this page is used in an edit wizard program = self.wizard().program if program != None: self.bin_directory = posixpath.join(program.root_directory, 'bin') else: identifier = self.get_field('identifier') self.bin_directory = posixpath.join('/', 'home', 'tf', 'programs', identifier, 'bin') # collect class path entries self.class_path_candidates = ['.'] for filename in sorted(self.wizard().available_files): directroy = posixpath.split(filename)[0] if len(directroy ) > 0 and directroy not in self.class_path_candidates: self.class_path_candidates.append(directroy) if filename.endswith('.class') or filename.endswith('.properties'): if program == None: self.class_path_list_editor.add_item(directroy) elif filename.endswith('.jar'): self.class_path_candidates.append(filename) if program == None: self.class_path_list_editor.add_item(filename) self.class_path_list_editor.add_item( '/usr/tinkerforge/bindings/java/Tinkerforge.jar') self.class_path_candidates.append( '/usr/tinkerforge/bindings/java/Tinkerforge.jar') self.combo_main_class.clear() self.combo_main_class.clearEditText() # collect main classes if program != None: self.combo_main_class.setEnabled(False) def get_main_classes(): script_instance_ref = [None] def progress_canceled(): script_instance = script_instance_ref[0] if script_instance == None: return self.wizard().script_manager.abort_script(script_instance) progress = ExpandingProgressDialog(self.wizard()) progress.set_progress_text_visible(False) progress.setWindowTitle('Edit Program') progress.setLabelText('Collecting Java main classes') progress.setModal(True) progress.setRange(0, 0) progress.canceled.connect(progress_canceled) progress.show() def cb_java_main_classes(result): script_instance = script_instance_ref[0] if script_instance != None: aborted = script_instance.abort else: aborted = False script_instance_ref[0] = None def done(): progress.cancel() self.combo_main_class.setEnabled(True) self.completeChanged.emit() if aborted: done() return okay, message = check_script_result(result, decode_stderr=True) if not okay: self.label_main_class_error.setText( '<b>Error:</b> ' + html.escape(message)) self.label_main_class_error.setVisible(True) done() return def expand_async(data): try: main_classes = json.loads( zlib.decompress( memoryview(data)).decode('utf-8')) if not isinstance(main_classes, dict): main_classes = {} except: main_classes = {} return main_classes def cb_expand_success(main_classes): self.combo_main_class.clear() for cls in sorted(main_classes.keys()): self.combo_main_class.addItem( cls, main_classes[cls]) self.combo_main_class_checker.set_current_text( program.cast_custom_option_value( 'java.main_class', str, '')) done() def cb_expand_error(): self.label_main_class_error.setText( '<b>Error:</b> Internal async error') self.label_main_class_error.setVisible(True) done() async_call(expand_async, result.stdout, cb_expand_success, cb_expand_error) script_instance_ref[0] = self.wizard( ).script_manager.execute_script('java_main_classes', cb_java_main_classes, [self.bin_directory], max_length=1024 * 1024, decode_output_as_utf8=False) # need to decouple this with a timer, otherwise it's executed at # a time where the progress bar cannot properly enter model state # to block the parent widget QTimer.singleShot(0, get_main_classes) elif self.wizard().hasVisitedPage(Constants.PAGE_FILES): uploads = self.wizard().page(Constants.PAGE_FILES).get_uploads() if len(uploads) > 0: abort_ref = [False] def progress_canceled(): abort_ref[0] = True progress = ExpandingProgressDialog(self) progress.set_progress_text_visible(False) progress.setWindowTitle('New Program') progress.setLabelText('Collecting Java main classes') progress.setModal(True) progress.setRange(0, 0) progress.canceled.connect(progress_canceled) progress.show() def cb_main_classes(main_classes): for main_class in main_classes: self.combo_main_class.addItem(main_class) if self.combo_main_class.count() > 1: self.combo_main_class.clearEditText() progress.cancel() self.combo_main_class.setEnabled(True) self.completeChanged.emit() def cb_main_classes_error(): self.label_main_class_error.setText( '<b>Error:</b> Internal async error') self.label_main_class_error.setVisible(True) progress.cancel() self.combo_main_class.clearEditText() self.combo_main_class.setEnabled(True) self.completeChanged.emit() def get_main_classes_async(uploads): return sorted( get_main_classes_from_class_or_jar(uploads, abort_ref)) self.combo_main_class.setEnabled(False) async_call(get_main_classes_async, uploads, cb_main_classes, cb_main_classes_error) # if a program exists then this page is used in an edit wizard if program != None: # start mode start_mode_api_name = program.cast_custom_option_value( 'java.start_mode', str, '<unknown>') start_mode = Constants.get_java_start_mode(start_mode_api_name) self.combo_start_mode.setCurrentIndex(start_mode) # main class self.combo_main_class_checker.set_current_text( program.cast_custom_option_value('java.main_class', str, '')) # jar file self.combo_jar_file_selector.set_current_text( program.cast_custom_option_value('java.jar_file', str, '')) # class path self.class_path_list_editor.clear() for class_path_entry in program.cast_custom_option_value_list( 'java.class_path', str, []): self.class_path_list_editor.add_item(class_path_entry) # working directory self.combo_working_directory_selector.set_current_text( program.working_directory) # options self.option_list_editor.clear() for option in program.cast_custom_option_value_list( 'java.options', str, []): self.option_list_editor.add_item(option) self.update_ui_state() # overrides QWizardPage.isComplete def isComplete(self): executable = self.get_executable() start_mode = self.get_field('java.start_mode') if len(executable) == 0: return False if start_mode == Constants.JAVA_START_MODE_MAIN_CLASS and \ not self.combo_main_class_checker.complete: return False if start_mode == Constants.JAVA_START_MODE_JAR_FILE and \ not self.combo_jar_file_selector.complete: return False return self.combo_working_directory_selector.complete and ProgramPage.isComplete( self) # overrides ProgramPage.update_ui_state def update_ui_state(self): start_mode = self.get_field('java.start_mode') start_mode_main_class = start_mode == Constants.JAVA_START_MODE_MAIN_CLASS start_mode_jar_file = start_mode == Constants.JAVA_START_MODE_JAR_FILE show_class_path = self.check_show_class_path.isChecked() show_advanced_options = self.check_show_advanced_options.isChecked() self.label_main_class.setVisible(start_mode_main_class) self.combo_main_class.setVisible(start_mode_main_class) self.label_main_class_help.setVisible(start_mode_main_class) self.combo_jar_file_selector.set_visible(start_mode_jar_file) self.class_path_list_editor.set_visible(show_class_path) self.button_add_class_path_entry.setVisible(show_class_path) self.combo_working_directory_selector.set_visible( show_advanced_options) self.option_list_editor.set_visible(show_advanced_options) self.label_spacer.setVisible(not show_class_path and not show_advanced_options) self.class_path_list_editor.update_ui_state() self.option_list_editor.update_ui_state() def add_class_path_entry(self): dialog = ExpandingInputDialog(self) dialog.setModal(True) dialog.setWindowTitle('Add Class Path Entry') dialog.setLabelText('Enter/Choose new class path entry:') dialog.setOkButtonText('Add') dialog.setComboBoxItems(self.class_path_candidates) dialog.setComboBoxEditable(True) dialog.setTextValue('') if dialog.exec_() != QDialog.Accepted: return entry = dialog.textValue() if len(entry) == 0: QMessageBox.critical(get_main_window(), 'Add Class Path Entry Error', 'A valid class path entry cannot be empty.') return self.class_path_list_editor.add_item(entry, select_item=True) def get_executable(self): return self.combo_version.itemData(self.get_field('java.version')) def get_html_summary(self): version = self.get_field('java.version') start_mode = self.get_field('java.start_mode') main_class = self.get_field('java.main_class') jar_file = self.get_field('java.jar_file') working_directory = self.get_field('java.working_directory') class_path = ':'.join(self.class_path_list_editor.get_items()) options = ' '.join(self.option_list_editor.get_items()) html_text = 'Java Version: {0}<br/>'.format( html.escape(self.combo_version.itemText(version))) html_text += 'Start Mode: {0}<br/>'.format( html.escape(Constants.java_start_mode_display_names[start_mode])) if start_mode == Constants.JAVA_START_MODE_MAIN_CLASS: html_text += 'Main Class: {0}<br/>'.format(html.escape(main_class)) elif start_mode == Constants.JAVA_START_MODE_JAR_FILE: html_text += 'JAR File: {0}<br/>'.format(html.escape(jar_file)) html_text += 'Class Path: {0}<br/>'.format(html.escape(class_path)) html_text += 'Working Directory: {0}<br/>'.format( html.escape(working_directory)) html_text += 'JVM Options: {0}<br/>'.format(html.escape(options)) return html_text def get_custom_options(self): return { 'java.start_mode': Constants.java_start_mode_api_names[self.get_field( 'java.start_mode')], 'java.main_class': self.get_field('java.main_class'), 'java.jar_file': self.get_field('java.jar_file'), 'java.class_path': self.class_path_list_editor.get_items(), 'java.options': self.option_list_editor.get_items() } def get_command(self): executable = self.get_executable() arguments = self.option_list_editor.get_items() environment = [] start_mode = self.get_field('java.start_mode') class_path_entries = self.class_path_list_editor.get_items() if len(class_path_entries) > 0: absolute_entries = [] for filename in class_path_entries: if not filename.startswith('/'): absolute_entries.append( posixpath.join(self.bin_directory, filename)) else: absolute_entries.append(filename) arguments += ['-cp', ':'.join(absolute_entries)] if start_mode == Constants.JAVA_START_MODE_MAIN_CLASS: arguments.append(self.get_field('java.main_class')) elif start_mode == Constants.JAVA_START_MODE_JAR_FILE: arguments.append('-jar') arguments.append(self.get_field('java.jar_file')) working_directory = self.get_field('java.working_directory') return executable, arguments, environment, working_directory def apply_program_changes(self): self.apply_program_custom_options_and_command_changes()
class ProgramPagePHP(ProgramPage, Ui_ProgramPagePHP): def __init__(self, title_prefix=''): ProgramPage.__init__(self) self.setupUi(self) self.language = Constants.LANGUAGE_PHP self.url_template = self.label_url.text() self.setTitle('{0}{1} Configuration'.format( title_prefix, Constants.language_display_names[self.language])) self.registerField('php.version', self.combo_version) self.registerField('php.start_mode', self.combo_start_mode) self.registerField('php.script_file', self.combo_script_file, 'currentText') self.registerField('php.command', self.edit_command) self.registerField('php.working_directory', self.combo_working_directory, 'currentText') self.combo_start_mode.currentIndexChanged.connect(self.update_ui_state) self.combo_start_mode.currentIndexChanged.connect( self.completeChanged.emit) self.check_show_advanced_options.stateChanged.connect( self.update_ui_state) self.label_spacer.setText('') self.combo_script_file_selector = MandatoryTypedFileSelector( self, self.label_script_file, self.combo_script_file, self.label_script_file_type, self.combo_script_file_type, self.label_script_file_help) self.edit_command_checker = MandatoryLineEditChecker( self, self.label_command, self.edit_command) self.combo_working_directory_selector = MandatoryDirectorySelector( self, self.label_working_directory, self.combo_working_directory) self.option_list_editor = ListWidgetEditor( self.label_options, self.list_options, self.label_options_help, self.button_add_option, self.button_remove_option, self.button_edit_option, self.button_up_option, self.button_down_option, '<new PHP option {0}>') # overrides QWizardPage.initializePage def initializePage(self): self.set_formatted_sub_title( 'Specify how the {language} program [{name}] should be executed.') self.update_combo_version('php', self.combo_version) self.combo_start_mode.setCurrentIndex(Constants.DEFAULT_PHP_START_MODE) self.combo_script_file_selector.reset() self.label_url.setText( self.url_template.replace('<SERVER>', 'red-brick').replace( '<IDENTIFIER>', self.get_field('identifier'))) self.check_show_advanced_options.setChecked(False) self.combo_working_directory_selector.reset() self.option_list_editor.reset() # if a program exists then this page is used in an edit wizard program = self.wizard().program if program != None: # start mode start_mode_api_name = program.cast_custom_option_value( 'php.start_mode', str, '<unknown>') start_mode = Constants.get_php_start_mode(start_mode_api_name) self.combo_start_mode.setCurrentIndex(start_mode) # script file self.combo_script_file_selector.set_current_text( program.cast_custom_option_value('php.script_file', str, '')) # command self.edit_command.setText( program.cast_custom_option_value('php.command', str, '')) # working directory self.combo_working_directory_selector.set_current_text( program.working_directory) # options self.option_list_editor.clear() for option in program.cast_custom_option_value_list( 'php.options', str, []): self.option_list_editor.add_item(option) self.update_ui_state() # overrides QWizardPage.isComplete def isComplete(self): executable = self.get_executable() start_mode = self.get_field('php.start_mode') # In web interface mode there is nothing to configure at all if start_mode == Constants.PYTHON_START_MODE_WEB_INTERFACE: return ProgramPage.isComplete(self) if len(executable) == 0: return False if start_mode == Constants.PHP_START_MODE_SCRIPT_FILE and \ not self.combo_script_file_selector.complete: return False if start_mode == Constants.PHP_START_MODE_COMMAND and \ not self.edit_command_checker.complete: return False return self.combo_working_directory_selector.complete and ProgramPage.isComplete( self) # overrides ProgramPage.update_ui_state def update_ui_state(self): start_mode = self.get_field('php.start_mode') start_mode_script_file = start_mode == Constants.PHP_START_MODE_SCRIPT_FILE start_mode_command = start_mode == Constants.PHP_START_MODE_COMMAND start_mode_web_interface = start_mode == Constants.PHP_START_MODE_WEB_INTERFACE show_advanced_options = self.check_show_advanced_options.isChecked() self.combo_version.setVisible(not start_mode_web_interface) self.label_version.setVisible(not start_mode_web_interface) self.combo_script_file_selector.set_visible(start_mode_script_file) self.label_command.setVisible(start_mode_command) self.edit_command.setVisible(start_mode_command) self.label_command_help.setVisible(start_mode_command) self.label_web_interface_help.setVisible(start_mode_web_interface) self.label_url_title.setVisible(start_mode_web_interface) self.label_url.setVisible(start_mode_web_interface) self.line.setVisible(not start_mode_web_interface) self.check_show_advanced_options.setVisible( not start_mode_web_interface) self.combo_working_directory_selector.set_visible( not start_mode_web_interface and show_advanced_options) self.option_list_editor.set_visible(not start_mode_web_interface and show_advanced_options) self.label_spacer.setVisible(start_mode_web_interface or not show_advanced_options) self.option_list_editor.update_ui_state() def get_executable(self): return self.combo_version.itemData(self.get_field('php.version')) def get_html_summary(self): version = self.get_field('php.version') start_mode = self.get_field('php.start_mode') script_file = self.get_field('php.script_file') command = self.get_field('php.command') working_directory = self.get_field('php.working_directory') options = ' '.join(self.option_list_editor.get_items()) if start_mode == Constants.PHP_START_MODE_WEB_INTERFACE: html_text = 'Start Mode: {0}<br/>'.format( html.escape( Constants.php_start_mode_display_names[start_mode])) else: html_text = 'PHP Version: {0}<br/>'.format( html.escape(self.combo_version.itemText(version))) html_text += 'Start Mode: {0}<br/>'.format( html.escape( Constants.php_start_mode_display_names[start_mode])) if start_mode == Constants.PHP_START_MODE_SCRIPT_FILE: html_text += 'Script File: {0}<br/>'.format( html.escape(script_file)) elif start_mode == Constants.PHP_START_MODE_COMMAND: html_text += 'Command: {0}<br/>'.format(html.escape(command)) html_text += 'Working Directory: {0}<br/>'.format( html.escape(working_directory)) html_text += 'PHP Options: {0}<br/>'.format(html.escape(options)) return html_text def get_custom_options(self): return { 'php.start_mode': Constants.php_start_mode_api_names[self.get_field( 'php.start_mode')], 'php.script_file': self.get_field('php.script_file'), 'php.command': self.get_field('php.command'), 'php.options': self.option_list_editor.get_items() } def get_command(self): start_mode = self.get_field('php.start_mode') if start_mode == Constants.PHP_START_MODE_WEB_INTERFACE: return None executable = self.get_executable() arguments = self.option_list_editor.get_items() environment = [] if start_mode == Constants.PHP_START_MODE_SCRIPT_FILE: arguments.append(self.get_field('php.script_file')) elif start_mode == Constants.PHP_START_MODE_COMMAND: arguments.append('-r') arguments.append(self.get_field('php.command')) working_directory = self.get_field('php.working_directory') return executable, arguments, environment, working_directory def apply_program_changes(self): self.apply_program_custom_options_and_command_changes()
class ProgramPageJavaScript(ProgramPage, Ui_ProgramPageJavaScript): def __init__(self, title_prefix=''): ProgramPage.__init__(self) self.setupUi(self) self.language = Constants.LANGUAGE_JAVASCRIPT self.setTitle('{0}{1} Configuration'.format( title_prefix, Constants.language_display_names[self.language])) self.registerField('javascript.flavor', self.combo_flavor) self.registerField('javascript.start_mode', self.combo_start_mode) self.registerField('javascript.script_file', self.combo_script_file, 'currentText') self.registerField('javascript.command', self.edit_command) self.registerField('javascript.working_directory', self.combo_working_directory, 'currentText') self.combo_flavor.currentIndexChanged.connect(self.update_ui_state) self.combo_flavor.currentIndexChanged.connect( self.completeChanged.emit) self.combo_start_mode.currentIndexChanged.connect(self.update_ui_state) self.combo_start_mode.currentIndexChanged.connect( self.completeChanged.emit) self.check_show_advanced_options.stateChanged.connect( self.update_ui_state) self.label_spacer.setText('') self.combo_script_file_selector = MandatoryTypedFileSelector( self, self.label_script_file, self.combo_script_file, self.label_script_file_type, self.combo_script_file_type, self.label_script_file_help) self.edit_command_checker = MandatoryLineEditChecker( self, self.label_command, self.edit_command) self.combo_working_directory_selector = MandatoryDirectorySelector( self, self.label_working_directory, self.combo_working_directory) self.option_list_editor = ListWidgetEditor( self.label_options, self.list_options, self.label_options_help, self.button_add_option, self.button_remove_option, self.button_edit_option, self.button_up_option, self.button_down_option, '<new Node.js option {0}>') # overrides QWizardPage.initializePage def initializePage(self): self.set_formatted_sub_title( 'Specify how the {language} program [{name}] should be executed.') def cb_nodejs_versions(versions): if versions[0].version != None: node_version_str = ' ' + versions[0].version else: node_version_str = '' self.combo_flavor.clear() self.combo_flavor.addItem('Client-Side (Browser)', '/bin/false') self.combo_flavor.addItem( 'Server-Side (Node.js{0})'.format(node_version_str), versions[0].executable) # if a program exists then this page is used in an edit wizard if self.wizard().program != None: program = self.wizard().program flavor_api_name = program.cast_custom_option_value( 'javascript.flavor', str, '<unknown>') flavor = Constants.get_javascript_flavor(flavor_api_name) if flavor == Constants.JAVASCRIPT_FLAVOR_BROWSER: executable = '/bin/false' else: executable = program.executable set_current_combo_index_from_data(self.combo_flavor, executable) self.combo_flavor.setEnabled(True) self.completeChanged.emit() self.get_executable_versions('nodejs', cb_nodejs_versions) self.combo_start_mode.setCurrentIndex( Constants.DEFAULT_JAVASCRIPT_START_MODE) self.combo_script_file_selector.reset() self.check_show_advanced_options.setChecked(False) self.combo_working_directory_selector.reset() self.option_list_editor.reset() # if a program exists then this page is used in an edit wizard program = self.wizard().program if program != None: # start mode start_mode_api_name = program.cast_custom_option_value( 'javascript.start_mode', str, '<unknown>') start_mode = Constants.get_javascript_start_mode( start_mode_api_name) self.combo_start_mode.setCurrentIndex(start_mode) # script file self.combo_script_file_selector.set_current_text( program.cast_custom_option_value('javascript.script_file', str, '')) # command self.edit_command.setText( program.cast_custom_option_value('javascript.command', str, '')) # working directory self.combo_working_directory_selector.set_current_text( program.working_directory) # options self.option_list_editor.clear() for option in program.cast_custom_option_value_list( 'javascript.options', str, []): self.option_list_editor.add_item(option) self.update_ui_state() # overrides QWizardPage.isComplete def isComplete(self): flavor = self.get_field('javascript.flavor') executable = self.get_executable() start_mode = self.get_field('javascript.start_mode') if flavor == Constants.JAVASCRIPT_FLAVOR_NODEJS: if len(executable) == 0: return False if start_mode == Constants.JAVASCRIPT_START_MODE_SCRIPT_FILE and \ not self.combo_script_file_selector.complete: return False if start_mode == Constants.JAVASCRIPT_START_MODE_COMMAND and \ not self.edit_command_checker.complete: return False return self.combo_working_directory_selector.complete and ProgramPage.isComplete( self) # overrides ProgramPage.update_ui_state def update_ui_state(self): flavor = self.get_field('javascript.flavor') flavor_browser = flavor == Constants.JAVASCRIPT_FLAVOR_BROWSER flavor_nodejs = flavor == Constants.JAVASCRIPT_FLAVOR_NODEJS start_mode = self.get_field('javascript.start_mode') start_mode_script_file = start_mode == Constants.JAVASCRIPT_START_MODE_SCRIPT_FILE start_mode_command = start_mode == Constants.JAVASCRIPT_START_MODE_COMMAND show_advanced_options = self.check_show_advanced_options.isChecked() self.label_start_mode.setVisible(flavor_nodejs) self.combo_start_mode.setVisible(flavor_nodejs) self.combo_script_file_selector.set_visible(flavor_nodejs and start_mode_script_file) self.label_command.setVisible(flavor_nodejs and start_mode_command) self.edit_command.setVisible(flavor_nodejs and start_mode_command) self.label_command_help.setVisible(flavor_nodejs and start_mode_command) self.line.setVisible(flavor_nodejs) self.check_show_advanced_options.setVisible(flavor_nodejs) self.combo_working_directory_selector.set_visible( flavor_nodejs and show_advanced_options) self.option_list_editor.set_visible(flavor_nodejs and show_advanced_options) self.label_spacer.setVisible(flavor_browser or not show_advanced_options) self.option_list_editor.update_ui_state() def get_executable(self): return self.combo_flavor.itemData(self.get_field('javascript.flavor')) def get_html_summary(self): flavor = self.get_field('javascript.flavor') start_mode = self.get_field('javascript.start_mode') script_file = self.get_field('javascript.script_file') command = self.get_field('javascript.command') working_directory = self.get_field('javascript.working_directory') options = ' '.join(self.option_list_editor.get_items()) html_text = 'JavaScript Flavor: {0}<br/>'.format( html.escape(self.combo_flavor.itemText(flavor))) if flavor == Constants.JAVASCRIPT_FLAVOR_NODEJS: html_text += 'Start Mode: {0}<br/>'.format( html.escape( Constants.javascript_start_mode_display_names[start_mode])) if start_mode == Constants.JAVASCRIPT_START_MODE_SCRIPT_FILE: html_text += 'Script File: {0}<br/>'.format( html.escape(script_file)) elif start_mode == Constants.JAVASCRIPT_START_MODE_COMMAND: html_text += 'Command: {0}<br/>'.format(html.escape(command)) html_text += 'Working Directory: {0}<br/>'.format( html.escape(working_directory)) html_text += 'Node.js Options: {0}<br/>'.format( html.escape(options)) return html_text def get_custom_options(self): return { 'javascript.flavor': Constants.javascript_flavor_api_names[self.get_field( 'javascript.flavor')], 'javascript.start_mode': Constants.javascript_start_mode_api_names[self.get_field( 'javascript.start_mode')], 'javascript.script_file': self.get_field('javascript.script_file'), 'javascript.command': self.get_field('javascript.command'), 'javascript.options': self.option_list_editor.get_items() } def get_command(self): flavor = self.get_field('javascript.flavor') if flavor == Constants.JAVASCRIPT_FLAVOR_BROWSER: return None executable = self.get_executable() arguments = self.option_list_editor.get_items() environment = ['NODE_PATH=/usr/local/lib/node_modules'] start_mode = self.get_field('javascript.start_mode') if start_mode == Constants.JAVASCRIPT_START_MODE_SCRIPT_FILE: arguments.append(self.get_field('javascript.script_file')) elif start_mode == Constants.JAVASCRIPT_START_MODE_COMMAND: arguments.append('-e') arguments.append(self.get_field('javascript.command')) working_directory = self.get_field('javascript.working_directory') return executable, arguments, environment, working_directory def apply_program_changes(self): if not self.apply_program_custom_options_and_command_changes(): return # stop scheduler if switching to browser flavor program = self.wizard().program if program == None: return if self.get_field( 'javascript.flavor') == Constants.JAVASCRIPT_FLAVOR_BROWSER: try: program.set_schedule(REDProgram.START_MODE_NEVER, False, 0, '') # FIXME: async_call except (Error, REDError) as e: QMessageBox.critical( get_main_window(), 'Edit Program Error', 'Could not update schedule of program [{0}]:\n\n{1}'. format( program.cast_custom_option_value( 'name', str, '<unknown>'), e))
class ProgramPageDelphi(ProgramPage, Ui_ProgramPageDelphi): def __init__(self, title_prefix=''): ProgramPage.__init__(self) self.setupUi(self) self.language = Constants.LANGUAGE_DELPHI self.edit_mode = False self.build_system_fpcmake_help_template = self.label_build_system_fpcmake_help.text( ) self.build_system_lazbuild_help_template = self.label_build_system_lazbuild_help.text( ) self.lazbuild_available = False self.setTitle('{0}{1} Configuration'.format( title_prefix, Constants.language_display_names[self.language])) self.registerField('delphi.start_mode', self.combo_start_mode) self.registerField('delphi.executable', self.edit_executable) self.registerField('delphi.compile_from_source', self.check_compile_from_source) self.registerField('delphi.build_system', self.combo_build_system) self.registerField('delphi.working_directory', self.combo_working_directory, 'currentText') self.combo_start_mode.currentIndexChanged.connect(self.update_ui_state) self.combo_start_mode.currentIndexChanged.connect( self.completeChanged.emit) self.check_compile_from_source.stateChanged.connect( self.update_ui_state) self.combo_build_system.currentIndexChanged.connect( self.update_ui_state) self.combo_build_system.currentIndexChanged.connect( self.check_build_system) self.check_show_advanced_options.stateChanged.connect( self.update_ui_state) self.label_spacer.setText('') self.edit_executable_checker = MandatoryLineEditChecker( self, self.label_executable, self.edit_executable) self.combo_working_directory_selector = MandatoryDirectorySelector( self, self.label_working_directory, self.combo_working_directory) self.make_option_list_editor = ListWidgetEditor( self.label_make_options, self.list_make_options, self.label_make_options_help, self.button_add_make_option, self.button_remove_make_option, self.button_edit_make_option, self.button_up_make_option, self.button_down_make_option, '<new Make option {0}>') self.lazbuild_option_list_editor = ListWidgetEditor( self.label_lazbuild_options, self.list_lazbuild_options, self.label_lazbuild_options_help, self.button_add_lazbuild_option, self.button_remove_lazbuild_option, self.button_edit_lazbuild_option, self.button_up_lazbuild_option, self.button_down_lazbuild_option, '<new Lazbuild option {0}>') # overrides QWizardPage.initializePage def initializePage(self): self.set_formatted_sub_title( 'Specify how the {language} program [{name}] should be executed.') def cb_fpc_versions(versions): if versions[0].version != None: fpc = '<b>{0}</b> ({1})'.format(versions[0].executable, versions[0].version) else: fpc = '<b>{0}</b>'.format(versions[0].executable) self.label_build_system_fpcmake_help.setText( self.build_system_fpcmake_help_template.replace('<FPC>', fpc)) self.get_executable_versions('fpc', cb_fpc_versions) def cb_lazbuild_versions(versions): if versions[0].version != None: lazbuild = '<b>{0}</b> ({1})'.format(versions[0].executable, versions[0].version) self.lazbuild_available = True self.combo_build_system.setItemText(1, 'lazbuild') else: lazbuild = '<b>{0}</b>'.format(versions[0].executable) self.label_build_system_lazbuild_help.setText( self.build_system_lazbuild_help_template.replace( '<LAZBUILD>', lazbuild)) self.get_executable_versions('lazbuild', cb_lazbuild_versions) self.combo_start_mode.setCurrentIndex( Constants.DEFAULT_DELPHI_START_MODE) self.check_compile_from_source.setChecked(False) self.check_show_advanced_options.setChecked(False) self.combo_working_directory_selector.reset() self.make_option_list_editor.reset() self.lazbuild_option_list_editor.reset() # if a program exists then this page is used in an edit wizard if self.wizard().program != None: program = self.wizard().program self.edit_mode = True # start mode start_mode_api_name = program.cast_custom_option_value( 'delphi.start_mode', str, '<unknown>') start_mode = Constants.get_delphi_start_mode(start_mode_api_name) self.combo_start_mode.setCurrentIndex(start_mode) # executable self.edit_executable.setText( program.cast_custom_option_value('delphi.executable', str, '')) # compile from source self.check_compile_from_source.setChecked( program.cast_custom_option_value('delphi.compile_from_source', bool, False)) # build system build_system_api_name = program.cast_custom_option_value( 'delphi.build_system', str, '<unknown>') build_system = Constants.get_delphi_build_system( build_system_api_name) self.combo_build_system.setCurrentIndex(build_system) # working directory self.combo_working_directory_selector.set_current_text( program.working_directory) # make options self.make_option_list_editor.clear() for make_option in program.cast_custom_option_value_list( 'delphi.make_options', str, []): self.make_option_list_editor.add_item(make_option) # lazbuild options self.lazbuild_option_list_editor.clear() for lazbuild_option in program.cast_custom_option_value_list( 'delphi.lazbuild_options', str, []): self.lazbuild_option_list_editor.add_item(lazbuild_option) self.update_ui_state() # overrides QWizardPage.isComplete def isComplete(self): if not self.edit_executable_checker.complete: return False if not self.lazbuild_available and \ self.get_field('delphi.build_system') == Constants.DELPHI_BUILD_SYSTEM_LAZBUILD: return False if not self.combo_working_directory_selector.complete: return False return ProgramPage.isComplete(self) # overrides ProgramPage.update_ui_state def update_ui_state(self): start_mode = self.get_field('delphi.start_mode') start_mode_executable = start_mode == Constants.DELPHI_START_MODE_EXECUTABLE compile_from_source = self.check_compile_from_source.isChecked() build_system = self.get_field('delphi.build_system') build_system_fpcmake = build_system == Constants.DELPHI_BUILD_SYSTEM_FPCMAKE build_system_lazbuild = build_system == Constants.DELPHI_BUILD_SYSTEM_LAZBUILD show_advanced_options = self.check_show_advanced_options.isChecked() self.edit_executable.setVisible(start_mode_executable) self.label_executable_help.setVisible(start_mode_executable) self.line1.setVisible(start_mode_executable) self.check_compile_from_source.setVisible(start_mode_executable) self.label_compile_from_source_help_new.setVisible( start_mode_executable and not self.edit_mode) self.label_compile_from_source_help_edit.setVisible( start_mode_executable and self.edit_mode) self.label_build_system.setVisible(compile_from_source) self.combo_build_system.setVisible(compile_from_source) self.label_build_system_fpcmake_help.setVisible( compile_from_source and build_system_fpcmake) self.label_build_system_lazbuild_help.setVisible( compile_from_source and build_system_lazbuild) self.combo_working_directory_selector.set_visible( show_advanced_options) self.make_option_list_editor.set_visible(compile_from_source and show_advanced_options and build_system_fpcmake) self.lazbuild_option_list_editor.set_visible(compile_from_source and show_advanced_options and build_system_lazbuild) self.label_spacer.setVisible(not compile_from_source or not show_advanced_options) self.make_option_list_editor.update_ui_state() self.lazbuild_option_list_editor.update_ui_state() def check_build_system(self, build_system): if not self.lazbuild_available and \ build_system == Constants.DELPHI_BUILD_SYSTEM_LAZBUILD: self.label_build_system.setStyleSheet('QLabel { color : red }') else: self.label_build_system.setStyleSheet('') self.completeChanged.emit() def get_make_options(self): return self.make_option_list_editor.get_items() def get_lazbuild_options(self): return self.lazbuild_option_list_editor.get_items() def get_html_summary(self): start_mode = self.get_field('delphi.start_mode') executable = self.get_field('delphi.executable') compile_from_source = self.get_field('delphi.compile_from_source') build_system = self.get_field('delphi.build_system') working_directory = self.get_field('delphi.working_directory') make_options = ' '.join(self.make_option_list_editor.get_items()) lazbuild_options = ' '.join( self.lazbuild_option_list_editor.get_items()) html_text = 'Start Mode: {0}<br/>'.format( html.escape(Constants.delphi_start_mode_display_names[start_mode])) if start_mode == Constants.DELPHI_START_MODE_EXECUTABLE: html_text += 'Executable: {0}<br/>'.format(html.escape(executable)) if compile_from_source: html_text += 'Compile From Source: Enabled<br/>' html_text += 'Build System: {0}<br/>'.format( html.escape( Constants.delphi_build_system_display_names[build_system])) else: html_text += 'Compile From Source: Disabled<br/>' html_text += 'Working Directory: {0}<br/>'.format( html.escape(working_directory)) if compile_from_source: if build_system == Constants.DELPHI_BUILD_SYSTEM_FPCMAKE: html_text += 'Make Options: {0}<br/>'.format( html.escape(make_options)) elif build_system == Constants.DELPHI_BUILD_SYSTEM_LAZBUILD: html_text += 'Lazbuild Options: {0}<br/>'.format( html.escape(lazbuild_options)) return html_text def get_custom_options(self): return { 'delphi.start_mode': Constants.delphi_start_mode_api_names[self.get_field( 'delphi.start_mode')], 'delphi.executable': self.get_field('delphi.executable'), 'delphi.compile_from_source': self.get_field('delphi.compile_from_source'), 'delphi.build_system': Constants.delphi_build_system_api_names[self.get_field( 'delphi.build_system')], 'delphi.make_options': self.make_option_list_editor.get_items(), 'delphi.lazbuild_options': self.lazbuild_option_list_editor.get_items() } def get_command(self): executable = self.get_field('delphi.executable') arguments = [] environment = [] working_directory = self.get_field('delphi.working_directory') if not executable.startswith('/'): executable = posixpath.join('./', executable) return executable, arguments, environment, working_directory def apply_program_changes(self): self.apply_program_custom_options_and_command_changes()
class ProgramPageOctave(ProgramPage, Ui_ProgramPageOctave): def __init__(self, title_prefix=''): ProgramPage.__init__(self) self.setupUi(self) self.language = Constants.LANGUAGE_OCTAVE self.is_full_image = None self.setTitle('{0}{1} Configuration'.format(title_prefix, Constants.language_display_names[self.language])) self.registerField('octave.version', self.combo_version) self.registerField('octave.start_mode', self.combo_start_mode) self.registerField('octave.script_file', self.combo_script_file, 'currentText') self.registerField('octave.working_directory', self.combo_working_directory, 'currentText') self.combo_start_mode.currentIndexChanged.connect(self.update_ui_state) self.combo_start_mode.currentIndexChanged.connect(self.completeChanged.emit) self.check_show_advanced_options.stateChanged.connect(self.update_ui_state) self.label_spacer.setText('') self.combo_script_file_selector = MandatoryTypedFileSelector(self, self.label_script_file, self.combo_script_file, self.label_script_file_type, self.combo_script_file_type, self.label_script_file_help) self.combo_working_directory_selector = MandatoryDirectorySelector(self, self.label_working_directory, self.combo_working_directory) self.option_list_editor = ListWidgetEditor(self.label_options, self.list_options, self.label_options_help, self.button_add_option, self.button_remove_option, self.button_edit_option, self.button_up_option, self.button_down_option, '<new Octave option {0}>') # overrides QWizardPage.initializePage def initializePage(self): self.set_formatted_sub_title('Specify how the {language} program [{name}] should be executed.') self.update_combo_version('octave', self.combo_version) self.combo_start_mode.setCurrentIndex(Constants.DEFAULT_OCTAVE_START_MODE) self.combo_script_file_selector.reset() self.check_show_advanced_options.setChecked(False) self.combo_working_directory_selector.reset() self.option_list_editor.reset() self.option_list_editor.add_item('--silent') # FIXME: check if X11 service is enabled instead self.is_full_image = self.wizard().image_version.flavor == 'full' if not self.is_full_image: self.option_list_editor.add_item('--no-window-system') # if a program exists then this page is used in an edit wizard program = self.wizard().program if program != None: # start mode start_mode_api_name = program.cast_custom_option_value('octave.start_mode', str, '<unknown>') start_mode = Constants.get_octave_start_mode(start_mode_api_name) self.combo_start_mode.setCurrentIndex(start_mode) # script file self.combo_script_file_selector.set_current_text(program.cast_custom_option_value('octave.script_file', str, '')) # working directory self.combo_working_directory_selector.set_current_text(program.working_directory) # options self.option_list_editor.clear() for option in program.cast_custom_option_value_list('octave.options', str, []): self.option_list_editor.add_item(option) self.update_ui_state() # overrides QWizardPage.isComplete def isComplete(self): executable = self.get_executable() start_mode = self.get_field('octave.start_mode') if len(executable) == 0: return False if start_mode == Constants.OCTAVE_START_MODE_SCRIPT_FILE and \ not self.combo_script_file_selector.complete: return False return self.combo_working_directory_selector.complete and ProgramPage.isComplete(self) # overrides ProgramPage.update_ui_state def update_ui_state(self): start_mode = self.get_field('octave.start_mode') start_mode_script_file = start_mode == Constants.OCTAVE_START_MODE_SCRIPT_FILE show_advanced_options = self.check_show_advanced_options.isChecked() self.combo_script_file_selector.set_visible(start_mode_script_file) self.combo_working_directory_selector.set_visible(show_advanced_options) self.option_list_editor.set_visible(show_advanced_options) self.label_spacer.setVisible(not show_advanced_options) self.option_list_editor.update_ui_state() def get_executable(self): return self.combo_version.itemData(self.get_field('octave.version')) def get_html_summary(self): version = self.get_field('octave.version') start_mode = self.get_field('octave.start_mode') script_file = self.get_field('octave.script_file') working_directory = self.get_field('octave.working_directory') options = ' '.join(self.option_list_editor.get_items()) html_text = 'Octave Version: {0}<br/>'.format(html.escape(self.combo_version.itemText(version))) html_text += 'Start Mode: {0}<br/>'.format(html.escape(Constants.octave_start_mode_display_names[start_mode])) if start_mode == Constants.OCTAVE_START_MODE_SCRIPT_FILE: html_text += 'Script File: {0}<br/>'.format(html.escape(script_file)) html_text += 'Working Directory: {0}<br/>'.format(html.escape(working_directory)) html_text += 'Octave Options: {0}<br/>'.format(html.escape(options)) return html_text def get_custom_options(self): return { 'octave.start_mode': Constants.octave_start_mode_api_names[self.get_field('octave.start_mode')], 'octave.script_file': self.get_field('octave.script_file'), 'octave.options': self.option_list_editor.get_items() } def get_command(self): executable = self.get_executable() arguments = self.option_list_editor.get_items() environment = [] start_mode = self.get_field('octave.start_mode') if self.is_full_image: environment.append('DISPLAY=:0') if start_mode == Constants.OCTAVE_START_MODE_SCRIPT_FILE: arguments.append(self.get_field('octave.script_file')) working_directory = self.get_field('octave.working_directory') return executable, arguments, environment, working_directory def apply_program_changes(self): self.apply_program_custom_options_and_command_changes()