示例#1
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)
示例#2
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)
示例#3
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
示例#4
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