def update_ui_state(self): show_class_path = self.check_show_class_path.isChecked() show_advanced_options = self.check_show_advanced_options.isChecked() # version def cb_java_versions(versions): for version in versions: if version.executable == self.program.executable: self.label_version.setText(version.version) return self.label_version.setText('<unknown>') self.get_executable_versions('java', cb_java_versions) # start mode start_mode_api_name = self.program.cast_custom_option_value( 'java.start_mode', str, '<unknown>') start_mode = Constants.get_java_start_mode(start_mode_api_name) start_mode_main_class = start_mode == Constants.JAVA_START_MODE_MAIN_CLASS start_mode_jar_file = start_mode == Constants.JAVA_START_MODE_JAR_FILE self.label_start_mode.setText( Constants.java_start_mode_display_names[start_mode]) # main class self.label_main_class_title.setVisible(start_mode_main_class) self.label_main_class.setVisible(start_mode_main_class) self.label_main_class.setText( self.program.cast_custom_option_value('java.main_class', str, '<unknown>')) # jar file self.label_jar_file_title.setVisible(start_mode_jar_file) self.label_jar_file.setVisible(start_mode_jar_file) self.label_jar_file.setText( self.program.cast_custom_option_value('java.jar_file', str, '<unknown>')) # class path self.label_class_path_title.setVisible(show_class_path) self.label_class_path.setVisible(show_class_path) self.label_class_path.setText('\n'.join( self.program.cast_custom_option_value_list('java.class_path', str, []))) # working directory self.label_working_directory_title.setVisible(show_advanced_options) self.label_working_directory.setVisible(show_advanced_options) self.label_working_directory.setText(self.program.working_directory) # options self.label_options_title.setVisible(show_advanced_options) self.label_options.setVisible(show_advanced_options) self.label_options.setText('\n'.join( self.program.cast_custom_option_value_list('java.options', str, [])))
def update_ui_state(self): show_class_path = self.check_show_class_path.isChecked() show_advanced_options = self.check_show_advanced_options.isChecked() # version def cb_java_versions(versions): for version in versions: if version.executable == self.program.executable: self.label_version.setText(version.version) return self.label_version.setText('<unknown>') self.get_executable_versions('java', cb_java_versions) # start mode start_mode_api_name = self.program.cast_custom_option_value('java.start_mode', str, '<unknown>') start_mode = Constants.get_java_start_mode(start_mode_api_name) start_mode_main_class = start_mode == Constants.JAVA_START_MODE_MAIN_CLASS start_mode_jar_file = start_mode == Constants.JAVA_START_MODE_JAR_FILE self.label_start_mode.setText(Constants.java_start_mode_display_names[start_mode]) # main class self.label_main_class_title.setVisible(start_mode_main_class) self.label_main_class.setVisible(start_mode_main_class) self.label_main_class.setText(self.program.cast_custom_option_value('java.main_class', str, '<unknown>')) # jar file self.label_jar_file_title.setVisible(start_mode_jar_file) self.label_jar_file.setVisible(start_mode_jar_file) self.label_jar_file.setText(self.program.cast_custom_option_value('java.jar_file', str, '<unknown>')) # class path self.label_class_path_title.setVisible(show_class_path) self.label_class_path.setVisible(show_class_path) self.label_class_path.setText('\n'.join(self.program.cast_custom_option_value_list('java.class_path', str, []))) # working directory self.label_working_directory_title.setVisible(show_advanced_options) self.label_working_directory.setVisible(show_advanced_options) self.label_working_directory.setText(self.program.working_directory) # options self.label_options_title.setVisible(show_advanced_options) self.label_options.setVisible(show_advanced_options) self.label_options.setText('\n'.join(self.program.cast_custom_option_value_list('java.options', str, [])))
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()