def _setup(self, width=None, dragsize=None): if width is None: width = style.LIFT_BUTTON_SIZE[0] if dragsize is None: dragsize = style.LIFT_DRAG_SIZE self._drag_element = DraggerLiftY(self) self._height = width painter = functions.obtain_valid_painter( painterstyle.DEF_PAINTER, pressed=True, color=style.DEF_COLOR2, size=( width, self._length + dragsize[1] + style.LIFT_MARGINS[1] + 1)) self.set_painter(painter) self._drag_element.set_painter( painterstyle.DEF_PAINTER( size=dragsize), autopress=False) try: self._drag_element.set_center((self.get_fus_center()[0], None)) except AttributeError: # state is ghost state, and has no fusionner self._drag_element.set_center((self.get_ghost_center()[0], None)) self._drag_element.set_free(y=False) Ghost.fit_children(self)
def _add_buttons(self, size=None): _GraphicalSlider._add_buttons(self, size) rect = self.get_fus_rect() self._minus.set_center((-2 + rect.left - size[0] // 2, rect.centery)) self._plus.set_center((2 + rect.right + size[0] // 2, rect.centery)) Ghost.fit_children(self) self._add_buttons_reactions()
def _setup(self, height=None, dragsize=None): height = style.SLIDER_THICK if height is None else height dragsize = style.SLIDERX_DRAG_SIZE if dragsize is None else dragsize self._height = height size = (self._length + dragsize[0] + style.SLIDER_MARGINS[0], height) painter = functions.obtain_valid_painter( painterstyle.DEF_PAINTER, pressed=True, color=style.DEF_COLOR2, size=size) self.set_painter(painter) dp = functions.obtain_valid_painter( painterstyle.DEF_PAINTER, pressed=False, size=dragsize) try: drag_x = self.val_to_pix(self.initial_value, self.get_fus_topleft()[0]) + 1 self._drag_element.change_painter(dp, autopress=False) self._drag_element.set_center((drag_x, self.get_fus_center()[1])) except AttributeError: drag_x = self.val_to_pix(self.initial_value, self.get_ghost_topleft()[0]) + 1 self._drag_element.set_painter(dp, autopress=False) self._drag_element.set_center((drag_x, self.get_ghost_center()[1])) self._drag_element.set_free(y=False) Ghost.fit_children(self)
def __init__(self, length, limvals=None, text="", elements=None, normal_params=None, namestyle=None, valuestyle=None, type_=float, initial_value=None): """Slider for choosing a value. <length>: single int value specifying the length of slider in pixels. <limvals>: 2-tuple specifying the min and max values. <text>: text preceeding the element. <type_>: the type of the number to be chosen (e.g int or float) <initial_value>: the initial value. If None, set to minimum value. """ namestyle = style.STYLE_SLIDER_NAME if namestyle is None else namestyle valuestyle=style.STYLE_SLIDER_VALUE if valuestyle is None else valuestyle Ghost.__init__(self, elements, normal_params) self._slider_el=_SliderXSetter(length, limvals, "", initial_value=initial_value) self._slider_el.finish() self.add_elements([self._slider_el]) self._value_type = type_ self._round_decimals = 2 self._name_element = self._get_name_element(text, namestyle) #herite de setter self._value_element = self._get_value_element(valuestyle) self.add_elements([self._name_element, self._value_element]) self._name_element.rank = 1 self._slider_el.rank = 2 self._value_element.rank = 3 self.sort_children_by_rank() self._storer_rect = None self._refresh_pos()
def __init__(self, length, limvals=None, text="", elements=None, normal_params=None, namestyle=None, valuestyle=None, type_=float, initial_value=None): namestyle = style.STYLE_SLIDER_NAME if namestyle is None else namestyle valuestyle=style.STYLE_SLIDER_VALUE if valuestyle is None else valuestyle Ghost.__init__(self, elements, normal_params) self._slider_el=_SliderXSetter(length, limvals, "", initial_value=initial_value) self._slider_el.finish() self.add_elements([self._slider_el]) self._value_type = type_ self._round_decimals = 2 self._name_element = self._get_name_element(text, namestyle) #herite de setter self._value_element = self._get_value_element(valuestyle) self.add_elements([self._name_element, self._value_element]) self._name_element.rank = 1 self._slider_el.rank = 2 self._value_element.rank = 3 self.sort_children_by_rank() self._storer_rect = None self._refresh_pos()
def __init__(self, text="", elements=None, normal_params=None): """Simplest graphical element of an application. <text>: the text to be displayed. <elements>: list of children elements.""" _Screened.__init__(self) Ghost.__init__(self, elements, normal_params) self._finished = False self.normal_params.polite_set("txt", text) self.visible = self.normal_params.params.get("visible", True)
def _add_buttons(self, size=None): _GraphicalSlider._add_buttons(self, size) rect = self.get_fus_rect() pos = (rect.centerx, rect.bottom + style.SLIDER_MARGINS[1] + size[1]/2) self._minus.set_center(pos) pos = (rect.centerx, rect.top - style.SLIDER_MARGINS[1] - size[1]/2) self._plus.set_center(pos) Ghost.fit_children(self) self._add_buttons_reactions()
def _finish_add(self, size=None): size = style.LIFT_BUTTON_SIZE if size is None else size rect = self.get_fus_rect() pos = (rect.centerx, rect.bottom + style.BUTTON_MARGINS[1] + size[1]/2) self._minus.set_center(pos) pos = (rect.centerx, rect.top - style.BUTTON_MARGINS[1] - size[1]/2) self._plus.set_center(pos) Ghost.fit_children(self) self._add_buttons_reactions()
def __init__(self, length, limvals=None, text="", elements=None, normal_params=None): self._height = None self._drag_element = DraggerY(self) super(SliderY, self).__init__(length, limvals, text, elements, normal_params) self._drag_element.finish() self.add_elements(list([self._drag_element])) Ghost.fit_children(self)
def __init__(self, hover_zone=None, elements=None, normal_params=None): Ghost.__init__(self, elements, normal_params) self._hovered = False self.set_hover(MOUSEMOTION) self._help_element = None self._waited = 0 self._help_wait_time = parameters.HELP_WAIT_TIME self._help_pos = None self._help_reaction = None self._help_blitted = False self.visible = False if hover_zone: self.set_hover_zone(hover_zone)
def __init__(self, hover_zone=None, elements=None, normal_params=None): Ghost.__init__(self, elements, normal_params) self._hovered = False self.set_hover(MOUSEMOTION) self._help_element = None self._waited = 0 self._help_wait_time = parameters.HELP_WAIT_TIME self._help_pos = None self._help_reaction = None self._help_blitted = False self.visible = False if hover_zone: self.set_hover_zone(hover_zone) self.surface = functions.get_screen()
def interactive_pause(max_time_in_seconds, element=None, fps=45): if element is None: element = Ghost() menu = TickedMenu(element, fps=fps) menu.kill_after(menu.fps * max_time_in_seconds) menu.play() return menu.kill_after
def __init__(self, hover_zone=None, elements=None, normal_params=None): """Ghost element designed to react to mouse hovering - can post hover events . <hover_zone>: a pygame rect defining the hovering zone.""" Ghost.__init__(self, elements, normal_params) self._hovered = False self.set_hover(MOUSEMOTION) self._help_element = None self._waited = 0 self._help_wait_time = parameters.HELP_WAIT_TIME self._help_pos = None self._help_reaction = None self._help_blitted = False self.visible = False if hover_zone: self.set_hover_zone(hover_zone) self.surface = functions.get_screen()
def is_family_bigger(self, state=None): if not state: state = self.current_state_key fr = Ghost.get_family_rect(self, state) r = self.get_fus_rect(state) sl = r.left st = r.top sw = r.width sh = r.height return (((fr.x < sl) or (fr.w > sw)), ((fr.y < st) or (fr.h > sh)))
def get_family_rect(self, state=None, only_children=False): if not state: state = self.current_state_key gfr = Ghost.get_family_rect(self, state, only_children) if only_children: return gfr elif self.visible: if self._finished: r = self.get_fus_rect(state) else: r = self.get_ghost_rect(state) return r.union(gfr)
def get_family_rect(self, state=None, only_children=False): if not state: state = self.current_state_key gfr = Ghost.get_family_rect(self, state) if only_children: return gfr elif self.visible: if self._finished: r = self.get_fus_rect(state) else: r = self.get_ghost_rect(state) return r.union(gfr)
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
def __init__(self, length, limvals=None, text="", elements=None, normal_params=None, namestyle=None, valuestyle=None, type_=float, initial_value=None): """Slider for choosing a value. <length>: single int value specifying the length of slider in pixels. <limvals>: 2-tuple specifying the min and max values. <text>: text preceeding the element. <type_>: the type of the number to be chosen (e.g int or float) <initial_value>: the initial value. If None, set to minimum value. """ namestyle = style.STYLE_SLIDER_NAME if namestyle is None else namestyle valuestyle = style.STYLE_SLIDER_VALUE if valuestyle is None else valuestyle Ghost.__init__(self, elements, normal_params) self._slider_el = _SliderXSetter(length, limvals, "", initial_value=initial_value) self._slider_el.finish() self.add_elements([self._slider_el]) self._value_type = type_ self._round_decimals = 2 self._name_element = self._get_name_element( text, namestyle) #herite de setter self._value_element = self._get_value_element(valuestyle) self.add_elements([self._name_element, self._value_element]) self._name_element.rank = 1 self._slider_el.rank = 2 self._value_element.rank = 3 self.sort_children_by_rank() self._storer_rect = None self._refresh_pos() self.limvals = self._slider_el.limvals
def fit_children(self, w=1., h=1., state=constants.STATE_NORMAL, only_children=False): """Scale to englobe children""" Ghost.englobe_childrens(self) #set the ghost rect fr = self.get_family_rect(state, only_children=only_children) width = fr.width height = fr.height if not w: width = self.get_fus_size()[0] elif w == "auto": width += 2 else: width *= w if not h: height = self.get_fus_size()[1] elif h == "auto": height += 2 else: height *= h self.set_size((width, height)) if self._lift: self.refresh_lift()
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])
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])
def __init__(self, text="", elements=None, normal_params=None): _Screened.__init__(self) Ghost.__init__(self, elements, normal_params) self._finished = False self.normal_params.polite_set("txt", text) self.visible = self.normal_params.params.get("visible", True)
def make_stored_ghost(elements, mode="h"): ghost = Ghost(elements) ghost.finish() store(ghost, mode=mode) ghost.fit_children() return ghost
def finish(self): Ghost.finish(self) self._refresh_pos() self._slider_el._drag_element.set_setter() value = str(self._slider_el.get_value()) self._value_element.set_text(value)