Пример #1
0
 def __init__(self,
              varsets,
              elements=None,
              normal_params=None,
              size=None,
              bar=None,
              file_width=None,
              finish=True):
     if file_width is None: file_width = style.FILE_WIDTH
     ##        box_size = style.BOX_SIZE if box_size is None else box_size
     self.scale_list = [DropDownListLauncher]  #!paramsetter
     self.varsets = varsets
     if not isinstance(self.varsets, list):
         self.varsets = [self.varsets]
     self.handlers = self.get_handlers(
     )  #below, will deny them so they know self
     elements = [] if elements is None else elements
     elements += self.handlers.values()
     Box.__init__(self,
                  elements=elements,
                  normal_params=normal_params,
                  size=size,
                  finish=False)
     if finish:
         self.finish()
Пример #2
0
 def store(self, size=None):
     Box.store(self, size)
     left = min([e.get_fus_rect().left for e in [self._r_element,
                                                 self._g_element,
                                                 self._b_element]])
     self._r_element.set_topleft((left,None))
     self._g_element.set_topleft((left,None))
     self._b_element.set_topleft((left,None))
Пример #3
0
 def store(self, size=None):
     Box.store(self, size)
     left = min([e.get_fus_rect().left for e in [self._r_element,
                                                 self._g_element,
                                                 self._b_element]])
     self._r_element.set_topleft((left,None))
     self._g_element.set_topleft((left,None))
     self._b_element.set_topleft((left,None))
Пример #4
0
def make_ok_box(elements,ok_text="Ok"):
    ok = make_button(ok_text)
    ok.user_func = post_done
    linesize = max(e.get_fus_rect().w for e in elements+[ok])
    line = Line.make(linesize, "h")
    box = Box(elements=elements+[line,ok])
    box.finish()
    ok.user_params = {"el":box}
    return box
Пример #5
0
def make_ok_box(elements,ok_text="Ok"):
    ok = make_button(ok_text)
    ok.user_func = post_done
    linesize = max(e.get_fus_rect().w for e in elements+[ok])
    line = Line.make(linesize, "h")
    box = Box(elements=elements+[line,ok])
    box.finish()
    ok.user_params = {"el":box}
    box.e_ok = ok
    return box
Пример #6
0
 def __init__(self,
              text="",
              elements=None,
              normal_params=None,
              storer_params=None,
              size=None,
              put_lift=True,
              color_size=(50, 50),
              value=(255, 0, 0),
              color_limvals=(0, 255)):
     Box.__init__(self, text, elements, normal_params, storer_params, size,
                  put_lift)
     self._color_size = color_size
     self._r_element = SliderXSetter(100,
                                     text="R: ",
                                     typ=int,
                                     limvals=color_limvals,
                                     initial_value=value[0])
     self._r_element.finish()
     self._g_element = SliderXSetter(100,
                                     text="G: ",
                                     typ=int,
                                     limvals=color_limvals,
                                     initial_value=value[1])
     self._g_element.finish()
     self._b_element = SliderXSetter(100,
                                     text="B: ",
                                     typ=int,
                                     limvals=color_limvals,
                                     initial_value=value[2])
     self._b_element.finish()
     reac_red = ConstantReaction(constants.THORPY_EVENT,
                                 self.refresh, {
                                     "name": constants.EVENT_SLIDE,
                                     "el": self._r_element
                                 },
                                 name="setcolorred")
     reac_green = ConstantReaction(constants.THORPY_EVENT,
                                   self.refresh, {
                                       "name": constants.EVENT_SLIDE,
                                       "el": self._g_element
                                   },
                                   name="setcolorgreen")
     reac_blue = ConstantReaction(constants.THORPY_EVENT,
                                  self.refresh, {
                                      "name": constants.EVENT_SLIDE,
                                      "el": self._b_element
                                  },
                                  name="setcolorblue")
     self.add_reactions([reac_red, reac_green, reac_blue])
     self._example_element = self._get_example_element()
     self.add_elements([
         self._r_element, self._g_element, self._b_element,
         self._example_element
     ])
Пример #7
0
 def _get_launched_el(self, els, size, storer_params):
     _done_element = Clickable(style.OK_TXT)
     _cancel_element = Clickable(style.CANCEL_TXT)
     _done_element.finish()
     _cancel_element.finish()
     g = Ghost([_done_element, _cancel_element])
     g.finish()
     g.englobe_childrens()
     g.rank = float("inf")
     store(g, g.get_elements(), "h")
     els += [g]
     box = Box(elements=els, size=size, storer_params=storer_params)
     box.finish()  #box stores its elements
     return box, _done_element, _cancel_element
Пример #8
0
 def _get_launched_el(self, els, size, storer_params):
     _done_element = Clickable(style.OK_TXT)
     _cancel_element = Clickable(style.CANCEL_TXT)
     _done_element.finish()
     _cancel_element.finish()
     g = Ghost([_done_element, _cancel_element])
     g.finish()
     g.englobe_childrens()
     g.rank = float("inf")
     store(g, g.get_elements(), "h")
     els += [g]
     box = Box(elements=els, size=size, storer_params=storer_params)
     box.finish() #box stores its elements
     return box, _done_element, _cancel_element
Пример #9
0
 def __init__(self,
              text="",
              elements=None,
              normal_params=None,
              storer_params=None,
              size=None,
              put_lift=True,
              color_size=(50, 50),
              value=(255, 0, 0),
              color_limvals=(0, 255)):
     """Box in which three sliders and a visualization square provide a way to
     define a color.
     <text>: title text for the color box.
     <size>: if not None, force the size of the box.
     <color_size>: the size of the color visualization rect.
     <value>: 3-tuple defining the initial color value.
     """
     Box.__init__(self, elements, normal_params, storer_params, size,
                  put_lift)
     self._color_size = color_size
     self._r_element = SliderXSetter(100, text="R: ", type_=int,
                            limvals=color_limvals, initial_value=value[0])
     self._r_element.finish()
     self._g_element = SliderXSetter(100, text="G: ", type_=int,
                            limvals=color_limvals, initial_value=value[1])
     self._g_element.finish()
     self._b_element = SliderXSetter(100, text="B: ", type_=int,
                            limvals=color_limvals, initial_value=value[2])
     self._b_element.finish()
     reac_red= ConstantReaction(constants.THORPY_EVENT,
                                self.refresh,
                                {"id":constants.EVENT_SLIDE,
                                 "el":self._r_element},
                                reac_name="setcolorred")
     reac_green= ConstantReaction(constants.THORPY_EVENT,
                                  self.refresh,
                                  {"id":constants.EVENT_SLIDE,
                                   "el":self._g_element},
                                  reac_name="setcolorgreen")
     reac_blue= ConstantReaction(constants.THORPY_EVENT,
                                 self.refresh,
                                 {"id":constants.EVENT_SLIDE,
                                  "el":self._b_element},
                                 reac_name="setcolorblue")
     self.add_reactions([reac_red, reac_green, reac_blue])
     self._example_element = get_example_element(value, color_size)
     self.add_elements([self._r_element, self._g_element, self._b_element,
                        self._example_element])
Пример #10
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()
Пример #11
0
def launch_choices(text, choices, title_fontsize=None, title_fontcolor=None,
                    click_quit=False):
    """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]
    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])
    box.center()
    from thorpy.miscgui.launchers.launcher import launch
    from thorpy.miscgui.reaction import ConstantReaction, Reaction
    from thorpy import functions
    launcher = launch(box)
    for e in elements:
        reac = ConstantReaction(constants.THORPY_EVENT,
                                launcher.unlaunch,
                                {"id":constants.EVENT_UNPRESS, "el":e},
                                {"what":None})
        box.add_reaction(reac)
    def click_outside(e):
        if not box.get_fus_rect().collidepoint(e.pos):
            functions.quit_menu_func()
    box.add_reaction(Reaction(pygame.MOUSEBUTTONDOWN, click_outside))
    return launcher
Пример #12
0
def launch_choices(text, choices, 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]
    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])
    box.center()
    from thorpy.miscgui.launchers.launcher import launch
    from thorpy.miscgui.reaction import ConstantReaction
    launcher = launch(box)
    for e in elements:
        reac = ConstantReaction(constants.THORPY_EVENT, launcher.unlaunch, {
            "id": constants.EVENT_UNPRESS,
            "el": e
        }, {"what": None})
        box.add_reaction(reac)
    return launcher
Пример #13
0
 def __init__(self,
              browser,
              name_txt="",
              file_txt="",
              launcher_txt="",
              normal_params=None,
              file_width=None,
              show_select=True,
              click_quit=False):
     """<browser> : the browser to be launched. Can either be a Browser
                    instance or a BrowserLight instance.
     <name_txt> : the text that stands before the (optionnal) file name and
                  the button to launch browser.
     <file_txt> : the default value shown to the user.
     <launcher_txt> : the text on the launcher button.
     """
     file_width = style.FILE_WIDTH if file_width is None else file_width
     self.show_select = show_select
     if not self.show_select:
         file_txt = ""
     _Launcher.__init__(self, "", normal_params, click_quit)
     self._spawn = "center"
     self.file_width = file_width
     self._done_element = Clickable(style.OK_TXT)
     self._done_element.finish()
     self._cancel_element = Clickable(style.CANCEL_TXT)
     self._cancel_element.finish()
     g = Ghost([self._done_element, self._cancel_element])
     g.finish()
     g.fit_children()
     g.rank = float("inf")
     store(g, g.get_elements(), "h")
     # to launch : must not be in self._elements!
     self.browser = browser
     box = Box(elements=[self.browser, g],
               storer_params=None)
     box.finish()
     self.launched_element = box
     self._deny_child(self.launched_element)
     # launcher
     self.launcher_el = self.get_launcher_element(launcher_txt)
     self.launcher_el.user_func = self.launch_box
     # name
     self._name_element = self._get_name_element(name_txt)
     self._name_element.user_func = self.launch_box
     self._file_element = self._get_file_element(file_txt)
     self.add_elements([self._name_element, self.launcher_el, self._file_element])
Пример #14
0
 def __init__(self,
              browser,
              name_txt,
              file_txt,
              launcher_txt,
              normal_params=None,
              file_width=None,
              show_select=True,
              click_quit=False):
     """<browser> : the browser to be launched. Can either be a Browser
                    instance or a BrowserLight instance.
     <name_txt> : the text that stands before the (optionnal) file name and
                  the button to launch browser.
     <file_txt> : the default value shown to the user.
     <launcher_txt> : the text on the launcher button.
     """
     file_width = style.FILE_WIDTH if file_width is None else file_width
     self.show_select = show_select
     if not self.show_select:
         file_txt = ""
     _Launcher.__init__(self, "", normal_params, click_quit)
     self._spawn = "center"
     self.file_width = file_width
     self._done_element = Clickable(style.OK_TXT)
     self._done_element.finish()
     self._cancel_element = Clickable(style.CANCEL_TXT)
     self._cancel_element.finish()
     g = Ghost([self._done_element, self._cancel_element])
     g.finish()
     g.englobe_childrens()
     g.rank = float("inf")
     store(g, g.get_elements(), "h")
     # to launch : must not be in self._elements!
     self.browser = browser
     box = Box(elements=[self.browser, g], storer_params=None)
     box.finish()
     self.launched_element = box
     self._deny_child(self.launched_element)
     # launcher
     self.launcher_el = self.get_launcher_element(launcher_txt)
     self.launcher_el.user_func = self.launch_box
     # name
     self._name_element = self._get_name_element(name_txt)
     self._name_element.user_func = self.launch_box
     self._file_element = self._get_file_element(file_txt)
     self.add_elements(
         [self._name_element, self.launcher_el, self._file_element])
Пример #15
0
    def __init__(self,
                 varsets,
                 elements=None,
                 normal_params=None,
                 size=None,
                 bar=None,
                 file_width=None):
        if file_width is None: file_width = style.FILE_WIDTH
##        box_size = style.BOX_SIZE if box_size is None else box_size
        self.scale_list = [DropDownListLauncher] #!paramsetter
        self.varsets = varsets
        if not isinstance(self.varsets, list):
            self.varsets = [self.varsets]
        self.handlers = self.get_handlers() #below, will deny them so they know self
        elements = [] if elements is None else elements
        elements += self.handlers.values()
        Box.__init__(self, elements=elements, normal_params=normal_params, size=size)
Пример #16
0
 def __init__(self,
              text="",
              elements=None,
              normal_params=None,
              storer_params=None,
              size=None,
              put_lift=True,
              color_size=(50, 50),
              value=(255, 0, 0),
              color_limvals=(0, 255)):
     Box.__init__(self, text, elements, normal_params, storer_params, size,
                  put_lift)
     self._color_size = color_size
     self._r_element = SliderXSetter(100, text="R: ", typ=int,
                            limvals=color_limvals, initial_value=value[0])
     self._r_element.finish()
     self._g_element = SliderXSetter(100, text="G: ", typ=int,
                            limvals=color_limvals, initial_value=value[1])
     self._g_element.finish()
     self._b_element = SliderXSetter(100, text="B: ", typ=int,
                            limvals=color_limvals, initial_value=value[2])
     self._b_element.finish()
     reac_red= ConstantReaction(constants.THORPY_EVENT,
                                self.refresh,
                                {"name" : constants.EVENT_SLIDE,
                                 "el": self._r_element},
                                name="setcolorred")
     reac_green= ConstantReaction(constants.THORPY_EVENT,
                                  self.refresh,
                                  {"name" : constants.EVENT_SLIDE,
                                   "el": self._g_element},
                                  name="setcolorgreen")
     reac_blue= ConstantReaction(constants.THORPY_EVENT,
                                 self.refresh,
                                 {"name" : constants.EVENT_SLIDE,
                                  "el": self._b_element},
                                 name="setcolorblue")
     self.add_reactions([reac_red, reac_green, reac_blue])
     self._example_element = self._get_example_element()
     self.add_elements([self._r_element, self._g_element, self._b_element,
                        self._example_element])
Пример #17
0
def make_ok_cancel_box(elements,ok_text="Ok",cancel_text="Cancel"):
    ok = make_button(ok_text)
    ok.user_func = post_done
    #
    cancel = make_button(cancel_text)
    cancel.user_func = post_cancel
    #
##    ghost = Ghost(elements=[ok, cancel])
##    ghost.finish()
##    store(ghost, mode="h")
##    ghost.fit_children()
    ok_cancel = make_stored_ghost([ok,cancel])
    #
    linesize = max(e.get_family_rect().w for e in elements+[ok_cancel])
    line = Line.make(linesize, "h")
    #
    box = Box(elements=elements+[line,ok_cancel])
    box.finish()
    ok.user_params = {"el":box}
    cancel.user_params = {"el":box}
    return box
Пример #18
0
def make_ok_cancel_box(elements, ok_text="Ok", cancel_text="Cancel"):
    ok = make_button(ok_text)
    ok.user_func = post_done
    #
    cancel = make_button(cancel_text)
    cancel.user_func = post_cancel
    #
##    ghost = Ghost(elements=[ok, cancel])
##    ghost.finish()
##    thorpy.store(ghost, mode="h")
##    ghost.fit_children()
    ok_cancel = make_stored_ghost([ok,cancel])
    #
    linesize = max(e.get_family_rect().w for e in elements+[ok_cancel])
    line = Line.make(linesize, "h")
    #
    box = Box(elements=elements+[line,ok_cancel])
    ok.user_params = {"el":box}
    cancel.user_params = {"el":box}
    box.e_ok = ok
    box.e_cancel = cancel
    return box
Пример #19
0
def launch_choices(text, choices, 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.launchers.launcher import launch
    from thorpy.miscgui.reaction import ConstantReaction
    launcher = launch(box)
    for e in elements:
        reac = ConstantReaction(constants.THORPY_EVENT,
                                launcher.unlaunch,
                                {"id":constants.EVENT_UNPRESS, "el":e},
                                {"what":None})
        box.add_reaction(reac)
    return launcher
Пример #20
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()