示例#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_fontsize_setter(fn, const_text="", 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()
    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")
            mdm = MetaDataManager()
            mdm.read_data(fn)
            mdm.data["font_size"] = font_size
##            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
示例#3
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
示例#4
0
def make_fontsize_setter(fn, const_text="", 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()
    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")
            mdm = MetaDataManager()
            mdm.read_data(fn)
            mdm.data["font_size"] = font_size
##            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
示例#5
0
def make_display_options_setter(fn,
                                const_text="",
                                sliders_length=100,
                                limvalsw=(400, None),
                                limvalsh=(400, None),
                                restart_app=True):
    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()
    w, h = functions.get_screen_size()
    maxsize = functions.get_current_application().max_screen_size
    if limvalsw[1] is None: limvalsw = (limvalsw[0], maxsize[0])
    if limvalsh[1] is None: limvalsh = (limvalsh[0], maxsize[1])
    fullscreen = bool(functions.get_screen().get_flags() & pygame.FULLSCREEN)
    varset.add("screen_w",
               value=int(w),
               text="Screen width: ",
               limits=limvalsw)
    varset.add("screen_h",
               value=int(h),
               text="Screen height: ",
               limits=limvalsh)
    varset.add("fullscreen", value=fullscreen, text="Fullscreen")
    button = ParamSetterLauncher.make([varset],
                                      const_text,
                                      const_text,
                                      text_ok="Apply")

    def reac_func_norestart(event):
        if event.what == constants.LAUNCH_DONE:
            w, h = varset.get_value("screen_w"), varset.get_value("screen_h")
            mdm = MetaDataManager()
            mdm.read_data(fn)
            mdm.data["screen_w"] = w
            mdm.data["screen_h"] = h
            mdm.data["fullscreen"] = varset.get_value("fullscreen")
            ##            print("writing", mdm.data, fn)
            mdm.write_data(fn)
            #restart script
            flags = functions.get_screen().get_flags()
            if varset.get_value("fullscreen"):
                flags |= pygame.FULLSCREEN
            else:
                flags = 0
            pygame.display.set_mode((w, h), flags)
            functions.get_current_menu()._elements[0].get_oldest_ancester(
            ).unblit_and_reblit()
            button.launched.blit()
            button.launched.update()

    def reac_func_restart(event):
        if event.what == constants.LAUNCH_DONE:
            w, h = varset.get_value("screen_w"), varset.get_value("screen_h")
            mdm = MetaDataManager()
            mdm.read_data(fn)
            mdm.data["screen_w"] = w
            mdm.data["screen_h"] = h
            mdm.data["fullscreen"] = varset.get_value("fullscreen")
            ##            print("writing", mdm.data, fn)
            mdm.write_data(fn)
            #restart script
            python = sys.executable
            os.execl(python, python, *sys.argv)

    reac_func = reac_func_restart if restart_app else reac_func_norestart
    reac = Reaction(constants.THORPY_EVENT, reac_func, {
        "id": constants.EVENT_UNLAUNCH,
        "launcher": button.launcher
    })
    button.add_reaction(reac)
    return button
示例#6
0
def make_display_options_setter(fn, const_text="",
                                sliders_length=100,
                                limvalsw=(400,None),
                                limvalsh=(400,None),
                                restart_app=True):
    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()
    w,h = functions.get_screen_size()
    maxsize = functions.get_current_application().max_screen_size
    if limvalsw[1] is None: limvalsw = (limvalsw[0], maxsize[0])
    if limvalsh[1] is None: limvalsh = (limvalsh[0], maxsize[1])
    fullscreen = bool(functions.get_screen().get_flags()&pygame.FULLSCREEN)
    varset.add("screen_w", value=int(w), text="Screen width: ", limits=limvalsw)
    varset.add("screen_h", value=int(h), text="Screen height: ", limits=limvalsh)
    varset.add("fullscreen", value=fullscreen, text="Fullscreen")
    button = ParamSetterLauncher.make([varset], const_text, const_text,
                                      text_ok="Apply")
    def reac_func_norestart(event):
        if event.what == constants.LAUNCH_DONE:
            w,h = varset.get_value("screen_w"), varset.get_value("screen_h")
            mdm = MetaDataManager()
            mdm.read_data(fn)
            mdm.data["screen_w"] = w
            mdm.data["screen_h"] = h
            mdm.data["fullscreen"] = varset.get_value("fullscreen")
##            print("writing", mdm.data, fn)
            mdm.write_data(fn)
            #restart script
            flags = functions.get_screen().get_flags()
            if varset.get_value("fullscreen"):
                flags |= pygame.FULLSCREEN
            else:
                flags = 0
            pygame.display.set_mode((w,h), flags)
            functions.get_current_menu()._elements[0].get_oldest_ancester().unblit_and_reblit()
            button.launched.blit()
            button.launched.update()

    def reac_func_restart(event):
        if event.what == constants.LAUNCH_DONE:
            w,h = varset.get_value("screen_w"), varset.get_value("screen_h")
            mdm = MetaDataManager()
            mdm.read_data(fn)
            mdm.data["screen_w"] = w
            mdm.data["screen_h"] = h
            mdm.data["fullscreen"] = varset.get_value("fullscreen")
##            print("writing", mdm.data, fn)
            mdm.write_data(fn)
            #restart script
            python = sys.executable
            os.execl(python, python, * sys.argv)

    reac_func=reac_func_restart if restart_app else reac_func_norestart
    reac = Reaction(constants.THORPY_EVENT, reac_func, {"id":constants.EVENT_UNLAUNCH,
                                                        "launcher":button.launcher})
    button.add_reaction(reac)
    return button