python-efl

Python-efl Tutorial 8

'''
Abdur-Ramaan Janhangeer
Updated from Jeff Hoogland's tutos
for Python3.9 and Python-elf 1.25.0

https://www.toolbox.com/tech/programming/blogs/pyefl-tutorial-8-genlist-120215/
'''

import efl.elementary as elm
from efl.elementary.window import StandardWindow
from efl.elementary.genlist import Genlist, GenlistItem, GenlistItemClass

from elmextensions import StandardPopup

ListItems = ["Apples",
            "Bananas",
            "Cookies",
            "Fruit Loops",
            "Milk",
            "Apple Juice",
            "BBQ Sauce",
            "Nesquik",
            "Trail Mix",
            "Chips",
            "Crackers",
            "Cheese",
            "Peanutbutter",
            "Jelly",
            "Ham",
            "Turkey",
            "Potatos",
            "Stuffing",
            "Tomato Sauce",
            "Pineapple",
            "Hot Dog Chili Sauce",
            "Stewed Tomatoes",
            "Creamed Corn",
            "Cream of Mushroom Soup",
            "Peaches",
            "Chilies and Tomatoes",
            "Cream of Chicken Soup",    
            "Cherry Pie Filling",   
            "Canned Beans (various)",
            "Cream of Tomato Soup", 
            "Apple Pie Filling",
            "Canned Peas",
            "Green Beans"
            ]

from efl.evas import EVAS_HINT_EXPAND, EVAS_HINT_FILL
EXPAND_BOTH = EVAS_HINT_EXPAND, EVAS_HINT_EXPAND
EXPAND_HORIZ = EVAS_HINT_EXPAND, 0.0
FILL_BOTH = EVAS_HINT_FILL, EVAS_HINT_FILL

class GLIC(GenlistItemClass):
    def __init__(self):
        GenlistItemClass.__init__(self, item_style="default")

    def text_get(self, gl, part, data):
        return data["itemName"]

class MainWindow(StandardWindow):
    def __init__(self):
        StandardWindow.__init__(self, "ex11", "Genlist List", size=(300, 200))
        self.callback_delete_request_add(lambda o: elm.exit())

        our_list = Genlist(self)
        our_list.size_hint_weight = EXPAND_BOTH
        our_list.callback_activated_add(self.list_item_selected)

        ListItems.sort()

        for it in ListItems:
            li = GenlistItem(item_data={"itemName":it}, item_class=GLIC())
            li.append_to(our_list)

        our_list.show()

        self.resize_object_add(our_list)

    def list_item_selected(self, our_list, our_item):
        our_popup = StandardPopup(self, "You selected %s"%our_item.data["itemName"], "ok")
        our_popup.show()

if __name__ == "__main__":
    elm.init()
    gui = MainWindow()
    gui.show()
    elm.run()