def get_predefined_modes(): modes = [] mode = spelling_mode.spelling_mode() mode.control.name = u"Vor Rechtschreibreform" mode.control.comment = "Rechtschreibregeln wie sie vor der Reform am XXXXX gültig waren." mode.control.isImmutable = True mode.combination.switch_legacy_sz = True modes.append(mode) mode = spelling_mode.spelling_mode() mode.control.name = u"Aktuelle Rechtschreibung" mode.control.isImmutable = True mode.control.isReference = True modes.append(mode) return modes
def read_mode(modeName): global logger filename = get_mode_filename(modeName) file = io.open(filename, "rb") logger.info("read mode file '%s'" % filename) mode = pickle.load(file) file.close() changes = util.add_missing_attributes(mode.combination, spelling_mode.spelling_mode().combination) if changes > 0: logger.info("mode file '%s' is lacking %d attributes; filling up" % (filename, changes)) write_mode(mode) return mode
def __init__(self, conf): super(MainViewController, self).__init__() self.conf = conf self.previousSampleText = None self.currentSampleText = None self.highlightingMode = HIGHLIGHT_DELTA self.autoHide = True self.suppressShowChanges = False self.rule_doc_manager = rules_doc_manager.RulesDocManager(rules_doc_manager.RULE_DOC_FILE) self.selectModeVC = mode_selector.SpellingModeSelector(self) self.selectModeForSaveVC = mode_saver.SpellingModeSaver(self) self.statistics_view_vc = statistics_view.StatisticsViewController(self) self.info_popup = popup.PopupViewController() self.set_reference_mode(filter(lambda m:m.control.isReference, mode_manager.get_available_modes())[0]) self.loadedMode = spelling_mode.spelling_mode() self.currentMode = spelling_mode.spelling_mode() self.delay_show_changes = False self.load_mode_type = LOAD_MODE_RULESET if ui_util.is_iphone(): self.orientations = ( 'portrait', ) else: self.orientations = ( 'landscape', )
def test(): global logger logger.info("Test started") saver = SpellingModeSaver() current_mode = spelling_mode.spelling_mode() saver.select(mode_manager.get_available_modes(False), current_mode) result = saver.get_selected_mode() if result: logger.info("selected_mode='%s' comment='%s'" % (result.control.name, result.control.comment)) else: logger.info("selection cancelled") logger.info("Test finished")
def test(): default_mode = spelling_mode.spelling_mode() rulesets.set_default_mode(default_mode.combination) text = rulesets.to_upper(unicode(sample_text.get_sample_text())) histogram = statistics.map_labels(statistics.get_letter_histogram(text), DEFAULT_REPLACEMENTS) histogram2 = statistics.keep_n_largest(histogram, 20) print histogram2 print histogram2[:][1] plot_letter_histogram(TMP_PLOT_FILE, histogram2, 200, 200) console.show_image(TMP_PLOT_FILE) new_text = text[100:] + 'XXÖÖÜßßßßxxxxp' histogram = statistics.get_letter_histogram(text) histogram2 = statistics.get_letter_histogram(new_text) changes = statistics.compute_changes(histogram, histogram2) summary_small_changes = statistics.summarize_small_changes(changes, 0.05) actual_changes = statistics.keep_actual_changes(changes,0.05) plot_frequency_change_bars(TMP_PLOT_FILE, actual_changes, 600, 200, summary_small_changes) console.show_image(TMP_PLOT_FILE)
def test(): model = spelling_mode.spelling_mode() vc = ViewController() vc.set_model(model)
def main(): global logger console.clear() logger = log.open_logging('rechtschreibung', reload=True) logger.info("Start application") default_mode = spelling_mode.spelling_mode() rulesets.set_default_mode(default_mode.combination) config_handler = config.ConfigHandler(app_config.AppConfig()) conf = config_handler.read_config_file(CONFIG_FILE, SAMPLE_CONFIG_FILE) image_rechtschreibung = ui.Image.named(IMAGE_URL_RECHTSCHREIBUNG).with_rendering_mode(ui.RENDERING_MODE_ORIGINAL) my_main_view_controller = MainViewController(conf) top_navigation_vc = ui_util.ViewController(my_main_view_controller) navigation_vc = ui_util.ViewController(top_navigation_vc) navigation_vc.load('top_navigation') top_navigation_view = ui.NavigationView(navigation_vc.view, title_bar_color = defaults.COLOR_GREY) top_navigation_view.title_bar_color = defaults.COLOR_LIGHT_GREY top_navigation_vc.view = top_navigation_view my_main_view_controller.add_child_controller(NAME_NAVIGATION_VIEW, top_navigation_vc) top_navigation_view.name = NAME_NAVIGATION_VIEW if ui_util.is_iphone(): my_main_view_controller.load('rechtschreibung_iphone') app_control_vc = ui_util.ViewController(my_main_view_controller) app_control_vc.load('rechtschreibung_app_control_iphone') my_main_view_controller.add_left_button_item(NAME_NAVIGATION_VIEW_TOP_LEVEL, 'button_close_top_navigation_view', ui.ButtonItem(image=ui.Image.named('iob:close_round_32'))) button_item_list = [ ui.ButtonItem(image=ui.Image.named('lib/ios7_toggle_32.png'), action=my_main_view_controller.handle_action, title='button_open_top_navigation_view'), ui.ButtonItem(image=ui.Image.named('ionicons-gear-a-32'), action=my_main_view_controller.handle_action, title='button_open_app_control_view'), ui.ButtonItem(image=image_rechtschreibung, action=my_main_view_controller.handle_action, title='button_icon_rechtschreibung'), ] my_main_view_controller.set_right_button_item_list('Rechtschreibung', button_item_list) else: my_main_view_controller.load('rechtschreibung') my_main_view_controller.add_right_button_item('Rechtschreibung', 'button_icon_rechtschreibung', ui.ButtonItem(image=image_rechtschreibung)) my_main_view_controller.add_subview('view_container_navigation', top_navigation_vc.view) view = my_main_view_controller.find_subview_by_name('segmented_control_highlighting_mode') view.action = my_main_view_controller.handle_action view_controller_capitalization = ui_util.ViewController(my_main_view_controller) view_controller_capitalization.load('view_capitalization') view_controller_harmonization = ui_util.ViewController(my_main_view_controller) view_controller_harmonization.load('view_harmonization') view = my_main_view_controller.find_subview_by_name('segmented_control_harmonization_elongation') view.action = my_main_view_controller.handle_action view_controller_combinations_simplification = ui_util.ViewController(my_main_view_controller) view_controller_combinations_simplification.load('view_combinations_simplification') view_controller_combinations_simplification_vowels = ui_util.ViewController(my_main_view_controller) view_controller_combinations_simplification_vowels.load('view_combinations_simplification_vowels') view_controller_punctuation = ui_util.ViewController(my_main_view_controller) view_controller_punctuation.load('view_punctuation') view_controller_legacy = ui_util.ViewController(my_main_view_controller) view_controller_legacy.load('view_legacy') view_controller_layout = ui_util.ViewController(my_main_view_controller) view_controller_layout.load('view_layout') view_controller_misc_rules = ui_util.ViewController(my_main_view_controller) view_controller_misc_rules.load('view_misc_rules') my_main_view_controller.set_model(default_mode.combination) # Set the empty html page for displaying the sample text. The actual content will be set in # method "update_sample_text". We use an absolute path to load the page so that the relative # path reference to the style sheet can be derrived by the browser. text_view = my_main_view_controller.find_subview_by_name('webview_text_view') absolute_page_path = 'file:' + os.path.abspath('etc/text_page.html') logger.info('Loading HTML page at %s' % absolute_page_path) text_view.load_url(absolute_page_path) # Wait for a fraction of a second so that load_url() above (which seems to be aynchronous) # has a chance to load the page before update_sample_text() below sets the initial content. time.sleep(1.0 * conf.rechtschreibung.initial_update_sample_text_delay / 1000.0) my_main_view_controller.update_sample_text() my_main_view_controller.present('fullscreen', title_bar_color=defaults.COLOR_GREY) speech.stop() logger.info("Terminate application")