Example #1
0
    def _tabs_viewport_resize_children(self):
        # allow x_align to take effect only if tabs fit.
        x = max(self.tabs_container.x, self._tabs_viewport.width - self.tabs_container.width - 1)

        Bin.resize_children(self._tabs_viewport)

        if self.tabs_container.width > self._tabs_viewport.width:
            self.tabs_container.x = x

        self._position_tabs()
Example #2
0
    def _tabs_viewport_resize_children(self):
        # allow x_align to take effect only if tabs fit.
        x = max(self.tabs_container.x,
                self._tabs_viewport.width - self.tabs_container.width - 1)

        Bin.resize_children(self._tabs_viewport)

        if self.tabs_container.width > self._tabs_viewport.width:
            self.tabs_container.x = x

        self._position_tabs()
Example #3
0
    def __init__(self,
                 text="",
                 markup="",
                 spacing=5,
                 image=None,
                 image_position=None,
                 size=None,
                 font_desc=None,
                 overflow=False,
                 color="#000",
                 background_color=None,
                 **kwargs):

        # TODO - am initiating table with fill = false but that yields suboptimal label placement and the 0,0 points to whatever parent gave us
        Bin.__init__(self, **kwargs)

        #: image to put next to the label
        self.image = image

        # the actual container that contains the label and/or image
        self.container = Box(spacing=spacing,
                             fill=False,
                             x_align=self.x_align,
                             y_align=self.y_align)

        if image_position is not None:
            self.image_position = image_position

        self.display_label = _DisplayLabel(text=text,
                                           markup=markup,
                                           color=color,
                                           size=size)
        self.display_label.x_align = 0  # the default is 0.5 which makes label align incorrectly on wrapping

        if font_desc or self.font_desc:
            self.display_label.font_desc = font_desc or self.font_desc

        self.display_label.size = size or self.size

        self.background_color = background_color

        #: either the pango `wrap <http://www.pygtk.org/pygtk2reference/pango-constants.html#pango-wrap-mode-constants>`_
        #: or `ellipsize <http://www.pygtk.org/pygtk2reference/pango-constants.html#pango-ellipsize-mode-constants>`_ constant.
        #: if set to False will refuse to become smaller
        self.overflow = overflow

        self.add_child(self.container)

        self._position_contents()
        self.connect_after("on-render", self.__on_render)
Example #4
0
    def __setattr__(self, name, val):
        if name in ("text", "markup", "color", "size"):
            if self.display_label.__dict__.get(
                    name, "hamster_graphics_no_value_really") == val:
                return
            setattr(self.display_label, name, val)
        elif name in ("spacing"):
            setattr(self.container, name, val)
        else:
            if self.__dict__.get(name,
                                 "hamster_graphics_no_value_really") == val:
                return
            Bin.__setattr__(self, name, val)

        if name in ('x_align', 'y_align') and hasattr(self, "container"):
            setattr(self.container, name, val)

        elif name == "alloc_w" and hasattr(self, "display_label") and getattr(
                self, "overflow") is not False:
            self._update_max_width()

        elif name == "min_width" and hasattr(self, "display_label"):
            self.display_label.width = val - self.horizontal_padding

        elif name == "overflow" and hasattr(self, "display_label"):
            if val is False:
                self.display_label.wrap = None
                self.display_label.ellipsize = None
            elif isinstance(
                    val, pango.WrapMode) and val in (pango.WrapMode.WORD,
                                                     pango.WrapMode.WORD_CHAR,
                                                     pango.WrapMode.CHAR):
                self.display_label.wrap = val
                self.display_label.ellipsize = None
            elif isinstance(val, pango.EllipsizeMode) and val in (
                    pango.EllipsizeMode.START, pango.EllipsizeMode.MIDDLE,
                    pango.EllipsizeMode.END):
                self.display_label.wrap = None
                self.display_label.ellipsize = val

            self._update_max_width()
        elif name in ("font_desc", "size"):
            setattr(self.display_label, name, val)

        if name in ("text", "markup", "image", "image_position", "overflow",
                    "size"):
            if hasattr(self, "overflow"):
                self._position_contents()
                self.container.queue_resize()
Example #5
0
    def __setattr__(self, name, val):
        if name == "cursor_position" and not self.editable:
            val = None

        if self.__dict__.get(name, "hamster_graphics_no_value_really") == val:
            return

        if name == "text":
            val = val or ""
            if getattr(self, "text_formatter", None):
                markup = self.text_formatter(
                    val.replace("&",
                                "&amp;").replace("<",
                                                 "&lt;").replace(">", "&gt;"))

            if markup:
                self.display_label.markup = markup
            else:
                self.display_label.text = val

        Bin.__setattr__(self, name, val)

        if name == "text":
            self.emit("on-change", val)

        if name in ("font_desc", "alignment", "single_paragraph", "color"):
            setattr(self.display_label, name, val)

        elif name == "alloc_w" and getattr(self, "overflow",
                                           False) != False and hasattr(
                                               self, "display_label"):
            self.display_label.width = val - self.horizontal_padding

        elif name == "overflow" and val != False and hasattr(
                self, "display_label"):
            if val in (pango.WrapMode.WORD, pango.WrapMode.WORD_CHAR,
                       pango.WrapMode.CHAR):
                self.display_label.wrap = val
                self.display_label.ellipsize = None
            elif val in (pango.EllipsizeMode.START, pango.EllipsizeMode.END):
                self.display_label.wrap = None
                self.display_label.ellipsize = val

        if name == "cursor_position":
            self.emit("on-position-change", val)
Example #6
0
    def __setattr__(self, name, val):
        if name in ("text", "markup", "color", "size"):
            if self.display_label.__dict__.get(name, "hamster_graphics_no_value_really") == val:
                return
            setattr(self.display_label, name, val)
        elif name in ("spacing"):
            setattr(self.container, name, val)
        else:
            if self.__dict__.get(name, "hamster_graphics_no_value_really") == val:
                return
            Bin.__setattr__(self, name, val)


        if name in ('x_align', 'y_align') and hasattr(self, "container"):
            setattr(self.container, name, val)

        elif name == "alloc_w" and hasattr(self, "display_label") and getattr(self, "overflow") is not False:
            self._update_max_width()

        elif name == "min_width" and hasattr(self, "display_label"):
            self.display_label.width = val - self.horizontal_padding

        elif name == "overflow" and hasattr(self, "display_label"):
            if val is False:
                self.display_label.wrap = None
                self.display_label.ellipsize = None
            elif isinstance(val, pango.WrapMode) and val in (pango.WrapMode.WORD, pango.WrapMode.WORD_CHAR, pango.WrapMode.CHAR):
                self.display_label.wrap = val
                self.display_label.ellipsize = None
            elif isinstance(val, pango.EllipsizeMode) and val in (pango.EllipsizeMode.START, pango.EllipsizeMode.MIDDLE, pango.EllipsizeMode.END):
                self.display_label.wrap = None
                self.display_label.ellipsize = val

            self._update_max_width()
        elif name in ("font_desc", "size"):
            setattr(self.display_label, name, val)

        if name in ("text", "markup", "image", "image_position", "overflow", "size"):
            if hasattr(self, "overflow"):
                self._position_contents()
                self.container.queue_resize()
Example #7
0
    def __setattr__(self, name, val):
        if name == "cursor_position" and not self.editable:
            val = None

        if self.__dict__.get(name, "hamster_graphics_no_value_really") == val:
            return

        if name == "text":
            val = val or ""
            if getattr(self, "text_formatter", None):
                markup = self.text_formatter(val.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;"))

            if markup:
                self.display_label.markup = markup
            else:
                self.display_label.text = val

        Bin.__setattr__(self, name, val)

        if name == "text":
            self.emit("on-change", val)

        if name in("font_desc", "alignment", "single_paragraph", "color"):
            setattr(self.display_label, name, val)

        elif name == "alloc_w" and getattr(self, "overflow", False) != False and hasattr(self, "display_label"):
            self.display_label.width = val - self.horizontal_padding

        elif name == "overflow" and val != False and hasattr(self, "display_label"):
            if val in (pango.WrapMode.WORD, pango.WrapMode.WORD_CHAR, pango.WrapMode.CHAR):
                self.display_label.wrap = val
                self.display_label.ellipsize = None
            elif val in (pango.EllipsizeMode.START, pango.EllipsizeMode.END):
                self.display_label.wrap = None
                self.display_label.ellipsize = val

        if name == "cursor_position":
            self.emit("on-position-change", val)
Example #8
0
    def __init__(self, text = "", markup = "", spacing = 5, image = None,
                 image_position = None, size = None, font_desc = None,
                 overflow = False,
                 color = "#000", background_color = None, **kwargs):

        # TODO - am initiating table with fill = false but that yields suboptimal label placement and the 0,0 points to whatever parent gave us
        Bin.__init__(self, **kwargs)

        #: image to put next to the label
        self.image = image

        # the actual container that contains the label and/or image
        self.container = Box(spacing = spacing, fill = False,
                             x_align = self.x_align, y_align = self.y_align)

        if image_position is not None:
            self.image_position = image_position

        self.display_label = _DisplayLabel(text = text, markup = markup, color=color, size = size)
        self.display_label.x_align = 0 # the default is 0.5 which makes label align incorrectly on wrapping

        if font_desc or self.font_desc:
            self.display_label.font_desc = font_desc or self.font_desc

        self.display_label.size = size or self.size

        self.background_color = background_color

        #: either the pango `wrap <http://www.pygtk.org/pygtk2reference/pango-constants.html#pango-wrap-mode-constants>`_
        #: or `ellipsize <http://www.pygtk.org/pygtk2reference/pango-constants.html#pango-ellipsize-mode-constants>`_ constant.
        #: if set to False will refuse to become smaller
        self.overflow = overflow

        self.add_child(self.container)

        self._position_contents()
        self.connect_after("on-render", self.__on_render)
Example #9
0
    def __init__(self,
                 text="",
                 draw_border=True,
                 valid_chars=None,
                 validate_on_type=True,
                 single_paragraph=True,
                 text_formatter=None,
                 alignment=None,
                 font_desc=None,
                 **kwargs):
        Bin.__init__(self, **kwargs)

        self.display_label = graphics.Label(color=self.color)

        self.viewport = Viewport(self.display_label)
        self.viewport.connect("on-render", self.__on_viewport_render)

        self.add_child(self.viewport)

        self.can_focus = True

        self.interactive = True

        self.editable = True

        #: current cursor position
        self.cursor_position = None

        #: start position of the selection
        self.selection_start = 0

        #: end position of the selection
        self.selection_end = 0

        if font_desc is not None:
            self.font_desc = font_desc
        self.display_label.font_desc = self.font_desc

        #: text alignment in the entry
        self.alignment = alignment

        #: if True, a border will be drawn around the input element
        self.draw_border = draw_border

        #self.connect("on-key-press", self.__on_key_press)
        self.connect("on-mouse-down", self.__on_mouse_down)
        self.connect("on-double-click", self.__on_double_click)
        self.connect("on-triple-click", self.__on_triple_click)
        self.connect("on-blur", self.__on_blur)
        self.connect("on-focus", self.__on_focus)

        self.connect_after("on-render", self.__on_render)

        self._scene_mouse_move = None
        self._scene_mouse_up = None
        self._selection_start_position = None
        self._letter_positions = []

        #: a string, function or regexp or valid chars for the input
        #: in case of function, it will receive the string to be tested
        #: as input and expects to receive back a boolean of whether the string
        #: is valid or not
        self.valid_chars = valid_chars

        #: should the content be validate right when typing and invalid version prohibited
        self.validate_on_type = validate_on_type

        #: function to style the entry text - change color and such
        #: the function receives one param - the text, and must return
        #: processed text back. will be using original text if the function
        #: does not return anything.
        #: Note: this function can change only the style, not the actual content
        #: as the latter will mess up text selection because of off-sync between
        #: the label value and what is displayed
        self.text_formatter = text_formatter if text_formatter else self.text_formatter

        #: should the text input support multiple lines
        self.single_paragraph = single_paragraph

        self.update_text(text)
        self._last_good_value = text  # last known good value of the input
Example #10
0
    def __init__(self, text="", draw_border = True,  valid_chars = None,
                 validate_on_type = True, single_paragraph = True,
                 text_formatter = None, alignment = None,
                 font_desc = None, **kwargs):
        Bin.__init__(self, **kwargs)

        self.display_label = graphics.Label(color=self.color)

        self.viewport = Viewport(self.display_label)
        self.viewport.connect("on-render", self.__on_viewport_render)

        self.add_child(self.viewport)

        self.can_focus = True

        self.interactive = True

        self.editable = True

        #: current cursor position
        self.cursor_position = None

        #: start position of the selection
        self.selection_start = 0

        #: end position of the selection
        self.selection_end = 0

        if font_desc is not None:
            self.font_desc = font_desc
        self.display_label.font_desc = self.font_desc

        #: text alignment in the entry
        self.alignment = alignment

        #: if True, a border will be drawn around the input element
        self.draw_border = draw_border

        #self.connect("on-key-press", self.__on_key_press)
        self.connect("on-mouse-down", self.__on_mouse_down)
        self.connect("on-double-click", self.__on_double_click)
        self.connect("on-triple-click", self.__on_triple_click)
        self.connect("on-blur", self.__on_blur)
        self.connect("on-focus", self.__on_focus)

        self.connect_after("on-render", self.__on_render)

        self._scene_mouse_move = None
        self._scene_mouse_up = None
        self._selection_start_position = None
        self._letter_positions = []

        #: a string, function or regexp or valid chars for the input
        #: in case of function, it will receive the string to be tested
        #: as input and expects to receive back a boolean of whether the string
        #: is valid or not
        self.valid_chars = valid_chars

        #: should the content be validate right when typing and invalid version prohibited
        self.validate_on_type = validate_on_type

        #: function to style the entry text - change color and such
        #: the function receives one param - the text, and must return
        #: processed text back. will be using original text if the function
        #: does not return anything.
        #: Note: this function can change only the style, not the actual content
        #: as the latter will mess up text selection because of off-sync between
        #: the label value and what is displayed
        self.text_formatter = text_formatter if text_formatter else self.text_formatter


        #: should the text input support multiple lines
        self.single_paragraph = single_paragraph

        self.update_text(text)
        self._last_good_value = text # last known good value of the input