示例#1
0
def make_font_options_setter(fn, const_text="", var_text="", ddl_size="auto",
                             slider_length=100, limvals=(6,36)):
    from thorpy.miscgui.reaction import Reaction
    from thorpy.miscgui.metadata import MetaDataManager
    from thorpy.elements.launchers.paramsetterlauncher import ParamSetterLauncher
    from thorpy.miscgui.varset import VarSet
    import os, sys
    varset = VarSet()
    titles = list(constants.AVAILABLE_FONTS)
    titles.sort()
    current_font = functions.get_default_font_infos()["name"]
    varset.add("fontname", titles, text="Font: ", more={"ddlf_size":ddl_size,
                                                        "var_text":current_font})
    varset.add("fontsize", value=style.FONT_SIZE, text="Font size:",
                limits=limvals, more={"length":slider_length})
    button = ParamSetterLauncher.make([varset], const_text, const_text,
                                        text_ok="Apply")
    def reac_func(event):
        if event.what == constants.LAUNCH_DONE:
            font_size = varset.get_value("fontsize")
            font_name = varset.get_value("fontname")
##            print("font_name=", font_name)
            mdm = MetaDataManager()
            mdm.read_data(fn)
            mdm.data["font_size"] = font_size
            mdm.data["font"] = font_name
##            print("writing", mdm.data, fn)
            mdm.write_data(fn)
            #restart script
            python = sys.executable
            os.execl(python, python, * sys.argv)
    reac = Reaction(constants.THORPY_EVENT, reac_func, {"id":constants.EVENT_UNLAUNCH,
                                                        "launcher":button.launcher})
    button.add_reaction(reac)
    return button
示例#2
0
def make_font_options_setter(fn, const_text="", var_text="", ddl_size="auto",
                             slider_length=100, limvals=(6,36)):
    from thorpy.miscgui.reaction import Reaction
    from thorpy.miscgui.metadata import MetaDataManager
    from thorpy.elements.launchers.paramsetterlauncher import ParamSetterLauncher
    from thorpy.miscgui.varset import VarSet
    import os, sys
    varset = VarSet()
    titles = list(constants.AVAILABLE_FONTS)
    titles.sort()
    current_font = functions.get_default_font_infos()["name"]
    varset.add("fontname", titles, text="Font: ", more={"ddlf_size":ddl_size,
                                                        "var_text":current_font})
    varset.add("fontsize", value=style.FONT_SIZE, text="Font size:",
                limits=limvals, more={"length":slider_length})
    button = ParamSetterLauncher.make([varset], const_text, const_text,
                                        text_ok="Apply")
    def reac_func(event):
        if event.what == constants.LAUNCH_DONE:
            font_size = varset.get_value("fontsize")
            font_name = varset.get_value("fontname")
##            print("font_name=", font_name)
            mdm = MetaDataManager()
            mdm.read_data(fn)
            mdm.data["font_size"] = font_size
            mdm.data["font"] = font_name
##            print("writing", mdm.data, fn)
            mdm.write_data(fn)
            #restart script
            python = sys.executable
            os.execl(python, python, * sys.argv)
    reac = Reaction(constants.THORPY_EVENT, reac_func, {"id":constants.EVENT_UNLAUNCH,
                                                        "launcher":button.launcher})
    button.add_reaction(reac)
    return button