示例#1
0
def change_tool_environment(env: str, tool: xw.Book = None):
    '''
	Changes the db environment that the defined wtso tool is pointing to. Strings are defined in constants.
	TODO: Move the connection string cells to constants.
	:param env: The target environment as a three character caps string
	'''
    if (tool is None):
        tool = xw.books.active
    tool.app.api.EnableEvents = False
    info_sheet = tool.sheets('Tool Info')
    info_sheet.api.Visible = True
    unprotect_wtso_sheet(info_sheet)
    conn_list = c.XL_CONNECTIONS[env]
    info_sheet.range("d3").value = conn_list[0]
    info_sheet.range("e3").value = conn_list[1]
    info_sheet.api.Visible = False
    tool.app.api.EnableEvents = True
            for lang in self.lang_select_list:
                sht_raw = self.excel_raw.loc[:, ['类型', self.base_lang.get()]]
                sht_trans = self.excel_trans.loc[:,
                                                 [self.base_lang.get(), lang]]
                pool.apply_async(translate, (
                    sht_raw,
                    sht_trans,
                    self.roles,
                    self.return_dict,
                ))
            pool.close()
            pool.join()
            # self.destroy()
            self.quit()

        except BaseLangError:
            messagebox.showerror('Error', '翻译文档的第一列不是基本语言。')


if __name__ == "__main__":
    freeze_support()
    root = Root()
    root.mainloop()

    wb_raw = Book(root.raw_file.get())
    sht_raw = wb_raw.sheets('Sheet1')
    for lang, result in root.return_dict.items():
        index = root.column_index_raw[lang]
        sht_raw.range(3, index).options(transpose=True).value = result
    # 翻译结束后弹窗告知
    messagebox.showinfo('Info', "已经成功完成翻译,并写入原始文档中,请查看。未匹配单元格已标注为\'$ERROR$\'")