Beispiel #1
0
def open_file():
    #get file with open file dialog
    filename = fd.askopenfilename(
        initialdir='shell:Desktop',
        title="Select font file",
        filetypes=[("All suppported font format",
                    "*.ttf *.otf *.woff *.woff2 *.otc *.ttc"),
                   ("Single font file format", "*.ttf *.otf *.woff *.woff2"),
                   ("TrueType font", "*.ttf"), ("OpenType font", "*.otf"),
                   ("Web Open Font Format (WOFF)", "*.woff *.woff2"),
                   ("OpenType collection font", "*.otc *.ttc"),
                   ("All files", "*.*")])
    #test if the file is a valid font file
    is_a_font = False
    if (filename.lower().endswith(".otf") or filename.lower().endswith(".ttf")
            or filename.lower().endswith(".woff")
            or filename.lower().endswith(".woff2")
            or filename.lower().endswith(".otc")
            or filename.lower().endswith(".ttc")):
        # external module: get_char
        is_a_font = get_char.is_font(filename)

    #default value for non-TTCollection
    font_id = -1
    #for TTCollections, get which font to check
    if is_a_font and (filename.lower().endswith(".otc")
                      or filename.lower().endswith(".ttc")):
        #get which font to use, if no choose will return 0 as default font - external module: ttc_get
        font_id = ttc_get.TTC_popup(main, filename, lang=current_lang).show()
        #if user not select
        if font_id is None:
            filename = ""  #trigger as no font selected
            is_a_font = False  #prevent font to process

    if is_a_font:
        #show filename
        font_name.set("File name: " + path_leaf(filename))
        #reset 0
        for cjk_enc in global_var.cjk_list:
            cjk_var[cjk_enc].set(0)
        for unicode_enc in global_var.unicode_list:
            unicode_var[unicode_enc].set(0)
        #get character list in font - external module: get_char
        char_list = get_char.font_import(filename, font_id, lang=current_lang)
        #get list count - external module: count_char
        output = count_char.count_char(char_list)
        cjk_char_count = output[0]
        unicode_char_count = output[1]
        #update list count
        for cjk_enc in global_var.cjk_list:
            cjk_var[cjk_enc].set(cjk_char_count[cjk_enc])
        for unicode_enc in global_var.unicode_list:
            unicode_var[unicode_enc].set(unicode_char_count[unicode_enc])
    elif filename == '' or filename is None:
        #no file selected, fd.askopenfilename() will return empty string
        font_name.set("File name: null")
        messagebox.showwarning(title="No file", message="No font selected.")
    elif not is_a_font:
        #not a font, change filename back to null n give error message
        font_name.set("File name: null")
        messagebox.showwarning(title="Not a font",
                               message="This is not a valid font file.")
    else:
        #unknown error
        font_name.set("File name: null")
        messagebox.showwarning(title="Error",
                               message="Something happened. Please try again.")
def open_file(filename_arg):
    #check if file is dragged onto here
    if filename_arg:
        #set filename to font
        filename = filename_arg
    else:
        #get file with open file dialog
        filename = fd.askopenfilename(
            initialdir='shell:Desktop',
            title="選擇字型文件",
            filetypes=[("所有支援的字型格式", "*.ttf *.otf *.woff *.woff2 *.otc *.ttc"),
                       ("單獨字型文件", "*.ttf *.otf *.woff *.woff2"),
                       ("TrueType 字型", "*.ttf"), ("OpenType 字型", "*.otf"),
                       ("網頁開放字型 (WOFF)", "*.woff *.woff2"),
                       ("OpenType 合集字型", "*.otc *.ttc"), ("全部文件", "*.*")])
    #test if the file is a valid font file
    is_a_font = False
    if (filename.lower().endswith(
        (".otf", ".ttf", ".woff", ".woff2", ".otc", ".ttc"))):
        # external module: get_char
        is_a_font = get_char.is_font(filename)

    #default value for non-TTCollection
    font_id = -1
    #for TTCollections, get which font to check
    if is_a_font and (filename.lower().endswith((".otc", ".ttc"))):
        #get which font to use, if no choose will return None - external module: ttc_get
        font_id = ttc_get.TTC_popup(main, filename, lang=current_lang).show()
        #if user not select
        if font_id is None:
            filename = ""  #trigger as no font selected
            is_a_font = False  #prevent font to process

    if is_a_font:
        #show filename
        font_name.set(path_leaf(filename))
        #reset 0
        for cjk_enc in global_var.cjk_list:
            cjk_var[cjk_enc].set(0)
        for unicode_enc in global_var.unicode_list:
            unicode_var[unicode_enc].set(0)
        #get character list in font - external module: get_char
        char_list = get_char.font_import(filename, font_id, lang=current_lang)
        #get list count - external module: count_char
        output = count_char.count_char(char_list, main, lang=current_lang)
        cjk_char_count = output[0]
        unicode_char_count = output[1]
        #update list count
        for cjk_enc in global_var.cjk_list:
            cjk_var[cjk_enc].set(cjk_char_count[cjk_enc])
        for unicode_enc in global_var.unicode_list:
            unicode_var[unicode_enc].set(unicode_char_count[unicode_enc])
    elif filename == '' or filename is None:
        #no file selected, fd.askopenfilename() will return empty string
        font_name.set("無")
        messagebox.showwarning(title="無選擇", message="沒有選擇字體。")
    elif not is_a_font:
        #not a font, change filename back to null n give error message
        font_name.set("無")
        messagebox.showwarning(title="非字型", message="這不是一個標準字型檔。")
    else:
        #unknown error
        font_name.set("無")
        messagebox.showwarning(title="錯誤", message="出現問題,請重試。")
    #reset to finish counting first time
    first_time = False
Beispiel #3
0
def open_file():
    #get file with open file dialog
    filename = fd.askopenfilename(
        initialdir='shell:Desktop',
        title="选择字体文件",
        filetypes=[("所有支援的字体格式", "*.ttf *.otf *.woff *.woff2 *.otc *.ttc"),
                   ("单独字体文件", "*.ttf *.otf *.woff *.woff2"),
                   ("TrueType 字体", "*.ttf"), ("OpenType 字体", "*.otf"),
                   ("网页开放字体 (WOFF)", "*.woff *.woff2"),
                   ("OpenType 合集字体", "*.otc *.ttc"), ("全部文件", "*.*")])
    #test if the file is a valid font file
    is_a_font = False
    if (filename.lower().endswith(".otf") or filename.lower().endswith(".ttf")
            or filename.lower().endswith(".woff")
            or filename.lower().endswith(".woff2")
            or filename.lower().endswith(".otc")
            or filename.lower().endswith(".ttc")):
        # external module: get_char
        is_a_font = get_char.is_font(filename)

    #default value for non-TTCollection
    font_id = -1
    #for TTCollections, get which font to check
    if is_a_font and (filename.lower().endswith(".otc")
                      or filename.lower().endswith(".ttc")):
        #get which font to use, if no choose will return 0 as default font - external module: ttc_get
        font_id = ttc_get.TTC_popup(main, filename, lang=current_lang).show()
        #if user not select
        if font_id is None:
            filename = ""  #trigger as no font selected
            is_a_font = False  #prevent font to process

    if is_a_font:
        #show filename
        font_name.set(path_leaf(filename))
        #reset 0
        for cjk_enc in global_var.cjk_list:
            cjk_var[cjk_enc].set(0)
        for unicode_enc in global_var.unicode_list:
            unicode_var[unicode_enc].set(0)
        #get character list in font - external module: get_char
        char_list = get_char.font_import(filename, font_id, lang=current_lang)
        #get list count - external module: count_char
        output = count_char.count_char(char_list)
        cjk_char_count = output[0]
        unicode_char_count = output[1]
        #update list count
        for cjk_enc in global_var.cjk_list:
            cjk_var[cjk_enc].set(cjk_char_count[cjk_enc])
        for unicode_enc in global_var.unicode_list:
            unicode_var[unicode_enc].set(unicode_char_count[unicode_enc])
    elif filename == '' or filename is None:
        #no file selected, fd.askopenfilename() will return empty string
        font_name.set("无")
        messagebox.showwarning(title="无选择", message="没有选择字体。")
    elif not is_a_font:
        #not a font, change filename back to null n give error message
        font_name.set("无")
        messagebox.showwarning(title="非字体", message="这不是一个标准字体档。")
    else:
        #unknown error
        font_name.set("无")
        messagebox.showwarning(title="错误", message="出现问题,请重试。")