示例#1
0
def launch_blocking(element,
                    after=None,
                    func=None,
                    set_auto_ok=True,
                    add_ok_enter=None):
    if set_auto_ok:
        auto_ok(element)
    from thorpy.elements.inserter import Inserter
    inserters = []
    if add_ok_enter is None:  #auto detect
        add_ok_enter = True
        for e in [element] + list(element.get_descendants()):
            if isinstance(e, Inserter):
                inserters.append(e)
    if add_ok_enter:
        reac = ConstantReaction(pygame.KEYDOWN, emulate_ok_press,
                                {"key": pygame.K_RETURN}, {
                                    "element": element,
                                    "inserters": inserters
                                })
        element.add_reaction(reac)
    m = TickedMenu(element)
    m.play()
    if add_ok_enter:
        element.remove_reaction(reac)
    if after:
        after.unblit_and_reblit()
    if func:
        func()
def launch_blocking_choices(text,
                            choices,
                            parent=None,
                            title_fontsize=None,
                            title_fontcolor=None,
                            func=None):
    """choices are tuple (text,func)"""
    if title_fontsize is None: title_fontsize = thorpy.style.FONT_SIZE
    if title_fontcolor is None: title_fontcolor = thorpy.style.FONT_COLOR
    elements = [thorpy.make_button(t, f) for t, f in choices]
    ghost = thorpy.make_group(elements)
    e_text = thorpy.make_text(text, title_fontsize, title_fontcolor)
    box = thorpy.Box.make([e_text, ghost])
    box.center()
    from thorpy.miscgui.reaction import ConstantReaction
    for e in elements:
        reac = ConstantReaction(thorpy.constants.THORPY_EVENT,
                                thorpy.functions.quit_menu_func, {
                                    "id": thorpy.constants.EVENT_UNPRESS,
                                    "el": e
                                })
        box.add_reaction(reac)
    from thorpy.menus.tickedmenu import TickedMenu
    m = TickedMenu(box)
    m.play()
    box.unblit()
    if parent:
        parent.partial_blit(None, box.get_fus_rect())
        box.update()
    if func:
        func()
示例#3
0
def launch_blocking_choices(text, choices, parent=None, title_fontsize=None,
                    title_fontcolor=None, main_color=None):
    """choices is a list of either tuple(text,func) or elements"""
    if title_fontsize is None: title_fontsize = style.FONT_SIZE
    if title_fontcolor is None: title_fontcolor = style.FONT_COLOR
##    elements = [make_button(t,f) for t,f in choices] #old form
    elements = []
    for choice in choices:
        if isinstance(choice, tuple):
            elements.append(make_button(choice[0],choice[1]))
        else:
            elements.append(choice)
    ghost = make_stored_ghost(elements)
    e_text = make_text(text, title_fontsize, title_fontcolor)
    box = Box.make([e_text, ghost])
    if main_color:
        box.set_main_color(main_color)
    box.center()
    from thorpy.miscgui.reaction import ConstantReaction
    for e in elements:
        reac = ConstantReaction(constants.THORPY_EVENT,
                                functions.quit_menu_func,
                                {"id":constants.EVENT_UNPRESS,
                                 "el":e})
        box.add_reaction(reac)
    from thorpy.menus.tickedmenu import TickedMenu
    m = TickedMenu(box)
    m.play()
    box.unblit()
    if parent:
        parent.partial_blit(None, box.get_fus_rect())
        box.update()
def launch_blocking_alert(title,
                          text,
                          parent=None,
                          font_size=None,
                          font_color=None,
                          ok_text="Ok",
                          transp=False,
                          alpha_dialog=200,
                          func=None):
    if font_size is None: font_size = thorpy.style.FONT_SIZE
    if font_color is None: font_color = thorpy.style.FONT_COLOR
    box_alert = make_textbox(title, text, font_size, font_color, ok_text)
    box_alert.center()
    if transp:
        color_transp = tuple(list(thorpy.style.DEF_COLOR)[:3] + [alpha_dialog])
        box_alert.set_main_color(color_transp)
    from thorpy.menus.tickedmenu import TickedMenu
    m = TickedMenu(box_alert)
    box_alert.get_elements_by_text(
        ok_text)[0].user_func = thorpy.functions.quit_menu_func
    box_alert.get_elements_by_text(ok_text)[0].user_params = {}
    m.play()
    box_alert.unblit()
    if parent:
        parent.partial_blit(None, box_alert.get_fus_rect())
        box_alert.update()
    if func:
        func()
示例#5
0
    def _launch(self, done_no_save):
        self._set_branch_last()
        self.add_elements([self.launched_element])
        my = style.MARGINS[1]
        tm = TickedMenu(self.launched_element)
        if self.click_quit:
            self._quit_when_click(self.launched_element)
        tm.refresh()
        r = self.get_storer_rect()
        lr = self.launched_element.get_storer_rect()
        fr = self.launched_element.get_family_rect(only_children=True)
        bottom = fr.top + fr.height
##        h_store(self.launched_element,
##                [self._done_element, self._cancel_element],
##                ycoord=bottom-my-self._cancel_element.get_storer_rect().h)
        if self._spawn == "auto":
            if self.launched_element._bar:
                r2 = Rect((r.left, r.bottom + my + \
                              self.launched_element._bar.get_fus_size()[1]),
                          lr.size)
            else:
                r2 = Rect((r.left, r.bottom + my), lr.size)
            self.launched_element.set_topleft(r2.topleft)
        elif self._spawn == "center":
            self.launched_element.center()
        else:
            self.launched_element.set_topleft(spawn)
        if done_no_save:
            self._done_element.set_as_menu_exiter()
        self._cancel_element.set_as_menu_exiter()
        tm.play()
        if self.click_quit:
            self.launched_element.deactivate_reaction(constants.REAC_CLICKQUIT)
        self._deny_child(self.launched_element)
示例#6
0
def launch_blocking(element, after=None, func=None, set_auto_ok=True,
                    add_ok_enter=None, set_auto_cancel=True, click_quit=False):
    if set_auto_ok:
        auto_ok(element)
    if set_auto_cancel:
        auto_cancel(element)
    if click_quit:
##        auto_click_quit(element)
        def click(e):
            if element.get_fus_rect().collidepoint(e.pos):
                if hasattr(element,"e_ok"):
                    emulate_ok_press(element.e_ok)
                elif hasattr(element, "e_cancel"):
                    post_cancel(element)
                    functions.quit_menu_func()
        element.add_reaction(Reaction(pygame.MOUSEBUTTONDOWN, click))
    from thorpy.elements.inserter import Inserter
    inserters = []
    if add_ok_enter is None: #auto detect
        add_ok_enter = True
        for e in [element]+list(element.get_descendants()):
            if isinstance(e, Inserter):
                inserters.append(e)
    if add_ok_enter:
        reac = ConstantReaction(pygame.KEYDOWN, emulate_ok_press,
                        {"key":pygame.K_RETURN}, {"element":element,
                                                    "inserters":inserters})
        element.add_reaction(reac)
    m = TickedMenu(element)
    m.play()
    if add_ok_enter:
        element.remove_reaction(reac)
    if after:
        after.unblit_and_reblit()
    if func:
        func()
    done = None
    cancel = None
    if hasattr(element, "e_ok"):
        done = element.e_ok.message
    if hasattr(element, "e_cancel"):
        cancel = element.e_cancel.message
    if done and not(cancel):
        return _FakeLauncher("done")
    elif cancel and not(done):
        return _FakeLauncher("cancel")
    elif done and cancel:
        raise Exception()
    else:
        return _FakeLauncher(None)
示例#7
0
def launch_blocking_choices_str(text,
                                choices,
                                parent=None,
                                title_fontsize=None,
                                title_fontcolor=None,
                                func=None,
                                store="v"):
    """choices are tuple (text,func)"""
    if title_fontsize is None: title_fontsize = thorpy.style.FONT_SIZE
    if title_fontcolor is None: title_fontcolor = thorpy.style.FONT_COLOR

    class Choice:
        value = None

    def choice_func(value):
        Choice.value = value

    elements = []
    for name in choices:
        e = thorpy.make_button(name, choice_func, {"value": name})
        elements.append(e)
    ghost = thorpy.make_group(elements, mode=store)
    e_text = thorpy.make_text(text, title_fontsize, title_fontcolor)
    box = thorpy.Box.make([e_text, thorpy.Line(100, "h"), ghost])
    box.center()
    from thorpy.miscgui.reaction import ConstantReaction
    for e in elements:
        reac = ConstantReaction(thorpy.constants.THORPY_EVENT,
                                thorpy.functions.quit_menu_func, {
                                    "id": thorpy.constants.EVENT_UNPRESS,
                                    "el": e
                                })
        box.add_reaction(reac)

    def click_outside(e):
        if not box.get_fus_rect().collidepoint(e.pos):
            thorpy.functions.quit_menu_func()

    reac = thorpy.Reaction(pygame.MOUSEBUTTONDOWN, click_outside)
    box.add_reaction(reac)
    from thorpy.menus.tickedmenu import TickedMenu
    m = TickedMenu(box)
    m.play()
    box.unblit()
    if parent:
        parent.partial_blit(None, box.get_fus_rect())
        box.update()
    if func:
        func()
    return Choice.value
示例#8
0
def launch_blocking_alert(text, parent=None, font_size=None, font_color=None,
                            ok_text="Ok"):
    if font_size is None: font_size = style.FONT_SIZE
    if font_color is None: font_color = style.FONT_COLOR
    box_alert = make_alert(text, font_size, font_color, ok_text)
    box_alert.center()
    from thorpy.menus.tickedmenu import TickedMenu
    m = TickedMenu(box_alert)
    box_alert.get_elements_by_text(ok_text)[0].user_func = functions.quit_menu_func
    box_alert.get_elements_by_text(ok_text)[0].user_params = {}
    m.play()
    box_alert.unblit()
    if parent:
        parent.partial_blit(None, box_alert.get_fus_rect())
        box_alert.update()
示例#9
0
def launch_blocking_alert(text,
                          parent=None,
                          font_size=None,
                          font_color=None,
                          ok_text="Ok"):
    if font_size is None: font_size = style.FONT_SIZE
    if font_color is None: font_color = style.FONT_COLOR
    box_alert = make_alert(text, font_size, font_color, ok_text)
    box_alert.center()
    from thorpy.menus.tickedmenu import TickedMenu
    m = TickedMenu(box_alert)
    box_alert.get_elements_by_text(
        ok_text)[0].user_func = functions.quit_menu_func
    box_alert.get_elements_by_text(ok_text)[0].user_params = {}
    m.play()
    box_alert.unblit()
    if parent:
        parent.partial_blit(None, box_alert.get_fus_rect())
        box_alert.update()
示例#10
0
 def _launch(self, done_no_save):
     self._set_branch_last()
     self.add_elements([self.launched_element])
     my = style.MARGINS[1]
     tm = TickedMenu(self.launched_element)
     if self.click_quit:
         self._quit_when_click(self.launched_element)
     tm.refresh()
     r = self.get_storer_rect()
     lr = self.launched_element.get_storer_rect()
     fr = self.launched_element.get_family_rect(only_children=True)
     bottom = fr.top + fr.height
     ##        h_store(self.launched_element,
     ##                [self._done_element, self._cancel_element],
     ##                ycoord=bottom-my-self._cancel_element.get_storer_rect().h)
     if self._spawn == "auto":
         if self.launched_element._bar:
             r2 = Rect((r.left, r.bottom + my + \
                           self.launched_element._bar.get_fus_size()[1]),
                       lr.size)
         else:
             r2 = Rect((r.left, r.bottom + my), lr.size)
         self.launched_element.set_topleft(r2.topleft)
     elif self._spawn == "center":
         self.launched_element.center()
     else:
         self.launched_element.set_topleft(spawn)
     if done_no_save:
         self._done_element.set_as_menu_exiter()
     self._cancel_element.set_as_menu_exiter()
     tm.play()
     if self.click_quit:
         self.launched_element.deactivate_reaction(constants.REAC_CLICKQUIT)
     self._deny_child(self.launched_element)
 def launch_ddlf(self):
     self._set_branch_last()
     r = self.get_storer_rect()
     self.launched_element.set_topleft(r.bottomleft)
     self.add_elements([self.launched_element])
     tm = TickedMenu(self.launched_element)
     if self.click_quit:
         self._quit_when_click(self.launched_element)
     self.launched_element._set_selecter(tm)
     tm.refresh()
     tm.play()
     if self.click_quit:
         self.launched_element.deactivate_reaction(constants.REAC_CLICKQUIT)
     if self.launched_element._clicked:
         text = normpath(self.launched_element._clicked)
         text = basename(text)
         self.selected = text
         functions.debug_msg(self.selected)
         if self.show_select:
             size = (self.file_width, self.get_fus_size()[1])
             self.set_text(text, size=size)
     self._deny_child(self.launched_element)
     self._unlaunch()
示例#12
0
def launch_blocking_choices(text, choices, parent=None, title_fontsize=None,
                    title_fontcolor=None):
    """choices are tuple (text,func)"""
    if title_fontsize is None: title_fontsize = style.FONT_SIZE
    if title_fontcolor is None: title_fontcolor = style.FONT_COLOR
    elements = [make_button(t,f) for t,f in choices]
    ghost = make_stored_ghost(elements)
    e_text = make_text(text, title_fontsize, title_fontcolor)
    box = Box.make([e_text, ghost])
    box.center()
    from thorpy.miscgui.reaction import ConstantReaction
    for e in elements:
        reac = ConstantReaction(constants.THORPY_EVENT,
                                functions.quit_menu_func,
                                {"id":constants.EVENT_UNPRESS,
                                 "el":e})
        box.add_reaction(reac)
    from thorpy.menus.tickedmenu import TickedMenu
    m = TickedMenu(box)
    m.play()
    box.unblit()
    if parent:
        parent.partial_blit(None, box.get_fus_rect())
        box.update()
 def launch_ddlf(self):
     self._set_branch_last()
     r = self.get_storer_rect()
     self.launched_element.set_topleft(r.bottomleft)
     self.add_elements([self.launched_element])
     tm = TickedMenu(self.launched_element)
     if self.click_quit:
         self._quit_when_click(self.launched_element)
     self.launched_element._set_selecter(tm)
     tm.refresh()
     tm.play()
     if self.click_quit:
         self.launched_element.deactivate_reaction(constants.REAC_CLICKQUIT)
     if self.launched_element._clicked:
         text = normpath(self.launched_element._clicked)
         text = basename(text)
         self.selected = text
         functions.debug_msg(self.selected)
         if self.show_select:
             size = (self.file_width, self.get_fus_size()[1])
             self.set_text(text, size=size)
     self._deny_child(self.launched_element)
     self._unlaunch()