def update_combo_encoding(self, text): check_and_save_path(self.config, 'df_exe_translation_file', text) # Update codepage combobox # TODO: Cache supported codepages' list codepages = get_codepages().keys() if self.fileentry_translation_file.path_is_valid(): translation_file = self.fileentry_translation_file.text with open(translation_file, 'r', encoding='utf-8') as fn: pofile = po.PoReader(fn) self.translation_file_language = pofile.meta['Language'] strings = [ cleanup_special_symbols(entry['msgstr']) for entry in pofile ] codepages = filter_codepages(codepages, strings) self.combo_encoding.values = sorted( codepages, key=lambda x: int(x.strip(string.ascii_letters))) if self.translation_file_language not in self.config[ 'language_codepages']: if self.combo_encoding.values: self.combo_encoding.current(0) else: self.combo_encoding.text = 'cp437' else: self.combo_encoding.text = self.config['language_codepages'][ self.translation_file_language]
def on_change_translation_files_path(self, config, key, directory): check_and_save_path(config, key, directory) if path.exists(directory): languages = self.get_languages(directory) self.combo_language.values = languages if languages: self.combo_language.current(0) else: self.combo_language.text = '' self.update_listbox_translation_files(language=self.combo_language.text) else: self.combo_language.values = tuple() self.combo_language.text = ''
def __init__(self, master, config, *args, **kwargs): super().__init__(master, *args, **kwargs) self.config = init_section(config, section_name='translate_external_files') config = self.config tk.Label(self, text='Dwarf Fortress root path:').grid() self.fileentry_df_root_path = FileEntry( self, dialogtype='askdirectory', default_path=config.get('df_root_path', ''), on_change=lambda text: check_and_save_path(self.config, 'df_root_path', text), ) self.fileentry_df_root_path.grid(row=0, column=1, sticky='WE') tk.Label(self, text="Translation files' directory:").grid() self.fileentry_translation_files = FileEntry( self, dialogtype='askdirectory', default_path=config.get('translation_files_path', ''), on_change=lambda text: self.on_change_translation_files_path(self.config, 'translation_files_path', text), ) self.fileentry_translation_files.grid(row=1, column=1, sticky='WE') tk.Label(self, text="Language:").grid() self.combo_language = ComboboxCustom(self) self.combo_language.grid(row=2, column=1, sticky='WE') directory = self.fileentry_translation_files.text if path.exists(directory): languages = self.get_languages(directory) self.combo_language.values = languages if languages: self.combo_language.current(0) self.combo_language.bind('<<ComboboxSelected>>', self.update_listbox_translation_files) tk.Label(self, text="Encoding:").grid() self.combo_encoding = ComboboxCustom(self) self.combo_encoding.grid(row=3, column=1, sticky='WE') self.update_combo_encoding() self.listbox_translation_files = ListboxCustom(self) self.listbox_translation_files.grid(columnspan=2, sticky='NSWE') self.update_listbox_translation_files(language=self.combo_language.text) ttk.Button(self, text='Search', command=self.bt_search).grid() ttk.Button(self, text='Translate', command=lambda: self.bt_search(translate=True)).grid(row=5, column=1) self.listbox_found_directories = ListboxCustom(self) self.listbox_found_directories.grid(columnspan=2, sticky='NSWE') self.grid_columnconfigure(1, weight=1)
def __init__(self, master, config: Config, debug=False): super().__init__(master) self.config = init_section( config, section_name='patch_executable', defaults=dict( fix_space_exclusions=dict(ru=['Histories of ']), language_codepages=dict(), )) config = self.config self.exclusions = config['fix_space_exclusions'] self.dfrus_process = None self._dictionary = None tk.Label(self, text='DF executable file:').grid() self.fileentry_executable_file = FileEntry( self, dialogtype='askopenfilename', filetypes=[('Executable files', '*.exe')], default_path=config.get('df_executable', ''), on_change=lambda text: check_and_save_path(self.config, 'df_executable', text), ) self.fileentry_executable_file.grid(column=1, row=0, columnspan=2, sticky='EW') tk.Label(self, text='DF executable translation file:').grid() self.fileentry_translation_file = FileEntry( self, dialogtype='askopenfilename', filetypes=[ ("Hardcoded strings' translation", '*hardcoded*.po'), ('Translation files', '*.po'), # ('csv file', '*.csv'), # @TODO: Currently not supported ], default_path=config.get('df_exe_translation_file', ''), on_change=self.update_combo_encoding, change_color=True) self.fileentry_translation_file.grid(column=1, row=1, columnspan=2, sticky='EW') tk.Label(self, text='Encoding:').grid() self.combo_encoding = ComboboxCustom(self) self.combo_encoding.grid(column=1, row=2, sticky=tk.E + tk.W) codepages = get_codepages().keys() if not self.fileentry_translation_file.path_is_valid(): self.translation_file_language = None else: translation_file = self.fileentry_translation_file.text with open(translation_file, 'r', encoding='utf-8') as fn: pofile = po.PoReader(fn) self.translation_file_language = pofile.meta['Language'] strings = [ cleanup_special_symbols(entry['msgstr']) for entry in pofile ] codepages = filter_codepages(codepages, strings) self.combo_encoding.values = natsorted(codepages) if 'last_encoding' in config: self.combo_encoding.text = config['last_encoding'] elif self.combo_encoding.values: self.combo_encoding.current(0) def save_encoding_into_config(event): config['last_encoding'] = event.widget.text if self.translation_file_language: config['language_codepages'][ self.translation_file_language] = event.widget.text self.combo_encoding.bind('<<ComboboxSelected>>', func=save_encoding_into_config) # FIXME: chk_dont_patch_charmap does nothing self.chk_dont_patch_charmap = self.setup_checkbutton( text="Don't patch charmap table", config_key='dont_patch_charmap', default_state=False) self.chk_dont_patch_charmap.grid(column=1, sticky=tk.W) self.chk_add_leading_trailing_spaces = self.setup_checkbutton( text='Add necessary leading/trailing spaces', config_key='add_leading_trailing_spaces', default_state=True) self.chk_add_leading_trailing_spaces.grid(columnspan=2, sticky=tk.W) button_exclusions = ttk.Button(self, text='Exclusions...', command=self.bt_exclusions) button_exclusions.grid(row=4, column=2) self.debug_frame = None if not debug else DebugFrame( self, dictionary=self.dictionary) if self.debug_frame: self.debug_frame.grid(columnspan=3, sticky='NSWE') self.grid_rowconfigure(5, weight=1) self.chk_debug_output = self.setup_checkbutton( text='Enable debugging output', config_key='debug_output', default_state=False) self.chk_debug_output.grid(columnspan=2, sticky=tk.W) self.button_patch = TwoStateButton(self, text='Patch!', command=self.bt_patch, text2='Stop!', command2=self.bt_stop) self.button_patch.grid(row=6, column=2) self.log_field = CustomText(self, width=48, height=8, enabled=False) self.log_field.grid(columnspan=3, sticky='NSWE') self.grid_rowconfigure(self.log_field.grid_info()['row'], weight=1) self.grid_columnconfigure(1, weight=1) self.bind('<Destroy>', self.kill_processes)
def __init__(self, master, config: Config): super().__init__(master) self.config = init_section( config, section_name='download_translations', defaults=dict(recent_projects=['dwarf-fortress'])) tk.Label(self, text='Transifex project:').grid() self.combo_projects = ComboboxCustom( self, values=self.config['recent_projects']) self.combo_projects.current(0) self.combo_projects.grid(column=1, row=0, sticky=tk.W + tk.E) tk.Label(self, text='Username:'******'username', '') self.entry_username.grid(column=1, row=1, sticky=tk.W + tk.E) tk.Label(self, text='Password:'******'\u2022') # 'bullet' symbol self.entry_password.grid(column=1, row=2, sticky=tk.W + tk.E) button_connect = ttk.Button(self, text='Connect...', command=self.bt_connect) button_connect.grid(row=0, column=2, rowspan=3, sticky=tk.N + tk.S + tk.W + tk.E) ttk.Separator(self, orient=tk.HORIZONTAL).grid(columnspan=3, sticky=tk.W + tk.E, pady=5) tk.Label(self, text='Choose language:').grid(column=0) self.combo_languages = ComboboxCustom(self) self.combo_languages.grid(column=1, row=4, sticky=tk.W + tk.E) # self.chk_all_languages = CheckbuttonVar(self, text='All languages (backup)') # self.chk_all_languages.grid(column=1) ttk.Separator(self, orient=tk.HORIZONTAL).grid(columnspan=3, sticky=tk.W + tk.E, pady=5) tk.Label(self, text='Download to:').grid() self.fileentry_download_to = FileEntry( self, dialogtype='askdirectory', default_path=self.config.get('download_to', ''), on_change=lambda text: check_and_save_path(self.config, 'download_to', text), ) self.fileentry_download_to.grid(column=1, row=6, columnspan=2, sticky='WE') self.button_download = TwoStateButton( self, text='Download translations', command=self.bt_download, text2='Stop', command2=self.bt_stop_downloading) self.button_download.grid(sticky=tk.W + tk.E) self.progressbar = ttk.Progressbar(self) self.progressbar.grid(column=1, row=7, columnspan=2, sticky=tk.W + tk.E) tk.Label(self, text='Resources:').grid(columnspan=3) self.listbox_resources = ListboxCustom(self) self.listbox_resources.grid(column=0, columnspan=3, sticky=tk.E + tk.W + tk.N + tk.S) self.grid_columnconfigure(1, weight=1) self.grid_rowconfigure(9, weight=1) self.resources = None self.tx = None self.download_started = False self.download_process = None self.bind('<Destroy>', self.kill_processes)