Ejemplo n.º 1
0
    def __init__(self, rows = [], dropdown_height=None, open_below = True,
                 overflow = pango.EllipsizeMode.END, **kwargs):
        ToggleButton.__init__(self, overflow = overflow, **kwargs)

        if dropdown_height:
            self.dropdown_height = dropdown_height

        self.padding_right = self.drop_mark_width
        self._scene_mouse_down = None # scene mouse down listener to hide our window if clicked anywhere else
        self._echo = False

        self.listitem = self.DropdownClass(select_on_drag = True)
        self.connect_child(self.listitem, "on-mouse-move", self._on_listitem_mouse_move)
        self.connect_child(self.listitem, "on-mouse-up", self._on_listitem_mouse_up)
        self.connect_child(self.listitem, "on-select", self._on_listitem_select)

        #: the list of text strings available for selection
        self.rows = rows

        #: Whether the dropdown should appear below or over the input element
        self.open_below = open_below

        if rows:
            self._set_label(self.label or rows[0])

        self.scrollbox = ScrollArea(fill=False)
        self.scrollbox.add_child(self.listitem)

        self.connect("on-mouse-move", self.__on_mouse_move)
        self.connect("on-mouse-down", self.__on_mouse_down)
        self.connect("on-click", self.__on_click)
        self.connect("on-toggle", self._on_toggle)
        self.connect("on-key-press", self._on_key_press)

        self._echo_up = False
Ejemplo n.º 2
0
    def __init__(self, label="", attachment = "top", pressed_offset = 0, **kwargs):
        ToggleButton.__init__(self, label=label, pressed_offset = pressed_offset, **kwargs)
        self.attachment = attachment

        self.interactive = True

        self.force_vertical_image = True
Ejemplo n.º 3
0
    def __init__(self, label="", attachment="top", pressed_offset=0, **kwargs):
        ToggleButton.__init__(self,
                              label=label,
                              pressed_offset=pressed_offset,
                              **kwargs)
        self.attachment = attachment

        self.interactive = True

        self.force_vertical_image = True
Ejemplo n.º 4
0
    def _set_label(self, item):
        if isinstance(item, (dict)):
            label = item.get("text", pango.parse_markup(item.get("markup", ""), -1, "0")[2])
        else:
            label = item

        if label == self.label:
            return #have it already!

        idx = self.listitem.find(label)

        if idx != -1:
            ToggleButton.__setattr__(self, 'label', label)

            # mark current row
            if not self.listitem.current_row or self.listitem.current_row[0] != self.label:
                self.listitem.select(self.listitem.rows[idx])

            self.emit("on-change", item)
Ejemplo n.º 5
0
    def __init__(self,
                 rows=[],
                 dropdown_height=None,
                 open_below=True,
                 overflow=pango.EllipsizeMode.END,
                 **kwargs):
        ToggleButton.__init__(self, overflow=overflow, **kwargs)

        if dropdown_height:
            self.dropdown_height = dropdown_height

        self.padding_right = self.drop_mark_width
        self._scene_mouse_down = None  # scene mouse down listener to hide our window if clicked anywhere else
        self._echo = False

        self.listitem = self.DropdownClass(select_on_drag=True)
        self.connect_child(self.listitem, "on-mouse-move",
                           self._on_listitem_mouse_move)
        self.connect_child(self.listitem, "on-mouse-up",
                           self._on_listitem_mouse_up)
        self.connect_child(self.listitem, "on-select",
                           self._on_listitem_select)

        #: the list of text strings available for selection
        self.rows = rows

        #: Whether the dropdown should appear below or over the input element
        self.open_below = open_below

        if rows:
            self._set_label(self.label or rows[0])

        self.scrollbox = ScrollArea(fill=False)
        self.scrollbox.add_child(self.listitem)

        self.connect("on-mouse-move", self.__on_mouse_move)
        self.connect("on-mouse-down", self.__on_mouse_down)
        self.connect("on-click", self.__on_click)
        self.connect("on-toggle", self._on_toggle)
        self.connect("on-key-press", self._on_key_press)

        self._echo_up = False
Ejemplo n.º 6
0
    def __setattr__(self, name, val):
        if name == "label":
            self._set_label(val)
            return

        if name == "rows":
            self.listitem.rows = val
            if val and hasattr(self, "label"):
                if self.label in val:
                    self.listitem.select(self.listitem.rows[self.listitem.find(self.label)])
                else:
                    self._set_label(val[0])

            # make sure we get pointer to the listitems treemodel
            ToggleButton.__setattr__(self, name, self.listitem.rows)
            return

        ToggleButton.__setattr__(self, name, val)
        if name == "drop_mark_width":
            self.padding_right = val
Ejemplo n.º 7
0
    def __setattr__(self, name, val):
        if name == "label":
            self._set_label(val)
            return

        if name == "rows":
            self.listitem.rows = val
            if val and hasattr(self, "label"):
                if self.label in val:
                    self.listitem.select(self.listitem.rows[self.listitem.find(
                        self.label)])
                else:
                    self._set_label(val[0])

            # make sure we get pointer to the listitems treemodel
            ToggleButton.__setattr__(self, name, self.listitem.rows)
            return

        ToggleButton.__setattr__(self, name, val)
        if name == "drop_mark_width":
            self.padding_right = val
Ejemplo n.º 8
0
    def _set_label(self, item):
        if isinstance(item, (dict)):
            label = item.get(
                "text",
                pango.parse_markup(item.get("markup", ""), -1, "0")[2])
        else:
            label = item

        if label == self.label:
            return  #have it already!

        idx = self.listitem.find(label)

        if idx != -1:
            ToggleButton.__setattr__(self, 'label', label)

            # mark current row
            if not self.listitem.current_row or self.listitem.current_row[
                    0] != self.label:
                self.listitem.select(self.listitem.rows[idx])

            self.emit("on-change", item)
Ejemplo n.º 9
0
    def do_render(self):
        ToggleButton.do_render(self)
        w, h = self.drop_mark_width, self.height

        self.graphics.save_context()
        self.graphics.translate(self.width - self.drop_mark_width + 0.5, 0)

        self.graphics.move_to(0, 5)
        self.graphics.line_to(0, h - 5)
        self.graphics.stroke("#888")

        self.graphics.translate((w - 8) / 2.0, (h - 10) / 2.0 - 5)

        self.graphics.move_to(0, 8)
        self.graphics.line_to(3, 5)
        self.graphics.line_to(6, 8)

        self.graphics.move_to(0, 12)
        self.graphics.line_to(3, 15)
        self.graphics.line_to(6, 12)
        self.graphics.stroke("#666")

        self.graphics.restore_context()
Ejemplo n.º 10
0
    def do_render(self):
        ToggleButton.do_render(self)
        w, h = self.drop_mark_width, self.height

        self.graphics.save_context()
        self.graphics.translate(self.width - self.drop_mark_width + 0.5, 0)

        self.graphics.move_to(0, 5)
        self.graphics.line_to(0, h - 5)
        self.graphics.stroke("#888")

        self.graphics.translate((w - 8) / 2.0, (h - 10) / 2.0 - 5)

        self.graphics.move_to(0, 8)
        self.graphics.line_to(3, 5)
        self.graphics.line_to(6, 8)

        self.graphics.move_to(0, 12)
        self.graphics.line_to(3, 15)
        self.graphics.line_to(6, 12)
        self.graphics.stroke("#666")

        self.graphics.restore_context()
Ejemplo n.º 11
0
 def resize_children(self):
     ToggleButton.resize_children(self)
     self.display_label.max_width = self.width - self.horizontal_padding
Ejemplo n.º 12
0
 def resize_children(self):
     ToggleButton.resize_children(self)
     self.display_label.max_width = self.width - self.horizontal_padding