Exemplo n.º 1
0
    def __init__(self, parent, text=None, icon=None):
        Entry.__init__(self, parent, scrollable=True, single_line=True,
                       size_hint_expand=EXPAND_BOTH,
                       size_hint_fill=FILL_BOTH)
        self.show()
        if text: self.text = text
        if icon: self.icon = icon

        ic = SafeIcon(self, 'go-down')
        ic.size_hint_min = 16, 16 # TODO file a bug for elm on phab
        ic.callback_clicked_add(self.activate)
        self.part_content_set('end', ic)

        self._itc = GenlistItemClass(item_style='default',
                                     text_get_func=self._gl_text_get,
                                     content_get_func=self._gl_content_get)
        self._list = Genlist(self)
        self._list.callback_selected_add(self._list_selected_cb)

        self._hover = Hover(self.parent, target=self)

        self._bg = Background(self, size_hint_expand=EXPAND_BOTH, 
                        size_hint_fill=FILL_BOTH)

        fr = Frame(self, style='pad_medium',
                   size_hint_expand=EXPAND_BOTH, size_hint_fill=FILL_BOTH)
        fr.content = self._list
        fr.show()

        self._table = Table(self, size_hint_expand=EXPAND_BOTH, 
                      size_hint_fill=FILL_BOTH)
        self._table.pack(self._bg, 0, 0, 1, 1)
        self._table.pack(fr, 0, 0, 1, 1)

        self._selected_func = None
Exemplo n.º 2
0
    def _settings_open(self, obj, it):
        h = Hover(self)
        t = it.track_object
        h.pos = t.bottom_center
        del t
        del it.track_object

        l = List(h)
        l.mode = ELM_LIST_EXPAND
        h.part_content_set("bottom", l)
        l.show()

        chk = Check(self, text="Scroll By Page")
        chk.state = self.settings["scroll_by_page"]

        def _scroll_by_page_cb(obj):
            target_state = obj.state
            self.settings["scroll_by_page"] = target_state
            if self.tabs.currentContent:
                if target_state:
                    self.tabs.currentContent.scroll_freeze()
                else:
                    self.tabs.currentContent.scroll_thaw()
            h.dismiss()

        chk.callback_changed_add(_scroll_by_page_cb)

        l.item_append(None, chk)
        l.go()

        h.show()
Exemplo n.º 3
0
    def _settings_open(self, obj, it):
        h = Hover(self)
        t = it.track_object
        h.pos = t.bottom_center
        del t
        del it.track_object

        l = List(h)
        l.mode = ELM_LIST_EXPAND
        h.part_content_set("bottom", l)
        l.show()

        chk = Check(self, text="Scroll By Page")
        chk.state = self.settings["scroll_by_page"]
        def _scroll_by_page_cb(obj):
            self.settings["scroll_by_page"] = obj.state
            h.dismiss()
        chk.callback_changed_add(_scroll_by_page_cb)

        l.item_append(None, chk)
        l.go()

        h.show()
Exemplo n.º 4
0
class ComboBox(Entry):
    def __init__(self, parent, text=None, icon=None):
        Entry.__init__(self, parent, scrollable=True, single_line=True,
                       size_hint_expand=EXPAND_BOTH,
                       size_hint_fill=FILL_BOTH)
        self.show()
        if text: self.text = text
        if icon: self.icon = icon

        ic = SafeIcon(self, 'go-down')
        ic.size_hint_min = 16, 16 # TODO file a bug for elm on phab
        ic.callback_clicked_add(self.activate)
        self.part_content_set('end', ic)

        self._itc = GenlistItemClass(item_style='default',
                                     text_get_func=self._gl_text_get,
                                     content_get_func=self._gl_content_get)
        self._list = Genlist(self)
        self._list.callback_selected_add(self._list_selected_cb)

        self._hover = Hover(self.parent, target=self)

        self._bg = Background(self, size_hint_expand=EXPAND_BOTH, 
                        size_hint_fill=FILL_BOTH)

        fr = Frame(self, style='pad_medium',
                   size_hint_expand=EXPAND_BOTH, size_hint_fill=FILL_BOTH)
        fr.content = self._list
        fr.show()

        self._table = Table(self, size_hint_expand=EXPAND_BOTH, 
                      size_hint_fill=FILL_BOTH)
        self._table.pack(self._bg, 0, 0, 1, 1)
        self._table.pack(fr, 0, 0, 1, 1)

        self._selected_func = None

    def callback_selected_add(self, func):
        self._selected_func = func

    @property
    def icon(self):
        return self.part_content_get('icon')
    @icon.setter
    def icon(self, icon):
        icon.size_hint_min = 16, 16 # TODO file a bug for elm on phab
        self.part_content_set('icon', icon)

    @property
    def guide(self):
        self.part_text_get('guide')
    @guide.setter
    def guide(self, text):
        self.part_text_set('guide', text)
    
    def item_append(self, label=None, icon=None, end=None):
        item_data = (label, icon, end)
        self._list.item_append(self._itc, item_data)

    def clear(self):
        self._list.clear()

    def activate(self, source=None):
        self.focus = False # :/

        # TODO calculate this based on _list and parent size
        # print(self._list.size)
        # print(self._list.geometry)
        self._bg.size_hint_min = 0, 200
        loc = self._hover.best_content_location_get(ELM_HOVER_AXIS_VERTICAL)
        self._hover.part_content_set(loc, self._table)
        self._hover.show()
        self._table.show()
        self._bg.show()
        self._list.show()
    
    def dismiss(self):
        self._hover.dismiss()

    def _list_selected_cb(self, gl, item):
        label, icon, end = item.data
        self.text = label
        if icon:
            self.icon = SafeIcon(self, icon)
        item.selected = False
        self.dismiss()
        if callable(self._selected_func):
            self._selected_func(self)

    def _gl_text_get(self, gl, part, item_data):
        label, icon, end = item_data
        return label

    def _gl_content_get(self, gl, part, item_data):
        label, icon, end = item_data
        if icon and part == 'elm.swallow.icon':
            return SafeIcon(gl, icon)
        elif end and part == 'elm.swallow.end':
            return SafeIcon(gl, end)
def hover2_clicked(obj, item=None):
    win = StandardWindow("hover2", "Hover 2", autodel=True, size=(320, 320))

    bx = Box(win, size_hint_weight=EXPAND_BOTH)
    win.resize_object_add(bx)
    bx.show()

    hv = Hover(win, style="popout")

    bt = Button(win, text="Button")
    bt.callback_clicked_add(hover_bt1_clicked, hv)
    bx.pack_end(bt)
    bt.show()
    hv.target_set(bt)

    bt = Button(win, text="Popup")
    hv.part_content_set("middle", bt)
    bt.show()

    bx = Box(win)

    ic = Icon(win,
              file=os.path.join(img_path, "logo_small.png"),
              resizable=(False, False))
    bx.pack_end(ic)
    ic.show()

    for t in "Top 1", "Top 2", "Top 3":
        bt = Button(win, text=t)
        bx.pack_end(bt)
        bt.show()

    bx.show()
    hv.part_content_set("top", bx)

    bt = Button(win, text="Bot")
    hv.part_content_set("bottom", bt)
    bt.show()

    bt = Button(win, text="Left")
    hv.part_content_set("left", bt)
    bt.show()

    bt = Button(win, text="Right")
    hv.part_content_set("right", bt)
    bt.show()

    win.show()
def hover2_clicked(obj, item=None):
    win = StandardWindow("hover2", "Hover 2", autodel=True, size=(320, 320))

    bx = Box(win, size_hint_weight=EXPAND_BOTH)
    win.resize_object_add(bx)
    bx.show()

    hv = Hover(win, style="popout")

    bt = Button(win, text="Button")
    bt.callback_clicked_add(hover_bt1_clicked, hv)
    bx.pack_end(bt)
    bt.show()
    hv.target_set(bt)

    bt = Button(win, text="Popup")
    hv.part_content_set("middle", bt)
    bt.show()

    bx = Box(win)

    ic = Icon(win, file=os.path.join(img_path, "logo_small.png"),
        resizable=(False, False))
    bx.pack_end(ic)
    ic.show()

    for t in "Top 1", "Top 2", "Top 3":
        bt = Button(win, text=t)
        bx.pack_end(bt)
        bt.show()

    bx.show()
    hv.part_content_set("top", bx)

    bt = Button(win, text="Bot")
    hv.part_content_set("bottom", bt)
    bt.show()

    bt = Button(win, text="Left")
    hv.part_content_set("left", bt)
    bt.show()

    bt = Button(win, text="Right")
    hv.part_content_set("right", bt)
    bt.show()

    win.show()