Ejemplo n.º 1
0
class TabbedBox(Box):
    def __init__(self, parent_widget, *args, **kwargs):
        Box.__init__(self, parent_widget, *args, **kwargs)

        self.tabs = []
        self.currentTab = None
        self.tabChangedCallback = None
        self.closeCallback = None
        self.emptyCallback = None

        self.scr = Scroller(self, size_hint_weight=EXPAND_HORIZ,
                           size_hint_align=FILL_BOTH)
        self.scr.content_min_limit(False, True)

        self.buttonBox = Box(self.scr, size_hint_weight=EXPAND_HORIZ,
                           align=ALIGN_LEFT)
        self.buttonBox.horizontal = True
        self.buttonBox.show()

        self.scr.content = self.buttonBox
        self.scr.show()
        
        self.nf = Naviframe(self, size_hint_weight=EXPAND_BOTH,
                               size_hint_align=FILL_BOTH)
        self.nf.show()

        self.pack_end(self.scr)
        self.pack_end(self.nf)
        
    def addTab(self, widget, tabName, canClose=True, disabled=False):
        self.tabs.append(widget)

        btn = Button(self.buttonBox, style="anchor", size_hint_align=ALIGN_LEFT)
        btn.text = tabName
        btn.data["widget"] = widget
        btn.disabled = disabled
        btn.callback_clicked_add(self.showTab, widget)
        btn.show()

        icn = Icon(self.buttonBox)
        icn.standard_set("gtk-close")
        icn.show()

        cls = Button(self.buttonBox, content=icn, style="anchor", size_hint_align=ALIGN_LEFT)
        cls.data["widget"] = widget
        cls.callback_clicked_add(self.closeTab)
        cls.disabled = disabled
        if canClose:
            cls.show()

        sep = Separator(self.buttonBox, size_hint_align=ALIGN_LEFT)
        sep.show()

        self.buttonBox.pack_end(btn)
        self.buttonBox.pack_end(cls)
        self.buttonBox.pack_end(sep)

        #Arguments go: btn, cls, sep
        widget.data["close"] = cls
        widget.data["button"] = btn
        widget.data["sep"] = sep
        
        self.showTab(widget=widget)
    
    def disableTab(self, tabIndex):
        btn, cls = self.tabs[tabIndex].data["button"], self.tabs[tabIndex].data["close"]
        btn.disabled = True
        cls.disabled = True
        
    def enableTab(self, tabIndex):
        btn, cls = self.tabs[tabIndex].data["button"], self.tabs[tabIndex].data["close"]
        btn.disabled = False
        cls.disabled = False
    
    def showTab(self, btn=None, widget=None):
        if type(btn) is int:
            widget = self.tabs[btn]
        if widget != self.currentTab:
            if self.currentTab:
                self.currentTab.data["button"].style="anchor"
            self.nf.item_simple_push(widget)
            self.currentTab = widget
            self.currentTab.data["button"].style="widget"
            
            if self.tabChangedCallback:
                self.tabChangedCallback(self, widget)
    
    def closeTab(self, btn):
        if not self.closeCallback:
            self.deleteTab(btn.data["widget"])
        else:
            self.closeCallback(self, btn.data["widget"])
    
    def deleteTab(self, widget):
        if type(widget) is int:
            widget = self.tabs[tabIndex]
        
        del self.tabs[self.tabs.index(widget)]
        
        self.buttonBox.unpack(widget.data["close"])
        self.buttonBox.unpack(widget.data["button"])
        self.buttonBox.unpack(widget.data["sep"])
        
        widget.data["close"].delete()
        widget.data["button"].delete()
        widget.data["sep"].delete()
        widget.delete()
        
        if self.currentTab == widget and len(self.tabs):
            self.showTab(widget=self.tabs[0])
            
        if not len(self.tabs) and self.emptyCallback:
            self.emptyCallback(self)
Ejemplo n.º 2
0
class TabbedBox(Box):
    '''A TabbedBox class.'''
    def __init__(self, parent_widget, *args, **kwargs):
        Box.__init__(self, parent_widget, *args, **kwargs)

        self.tabs = []
        self.current = None
        self.tab_changed_cb = None
        self.close_cb = None
        self.empty_cb = None

        self.scr = Scroller(self,
                            size_hint_weight=EXPAND_HORIZ,
                            size_hint_align=FILL_BOTH)
        self.scr.content_min_limit(False, True)

        self.button_bx = Box(self.scr,
                             size_hint_weight=EXPAND_HORIZ,
                             align=ALIGN_LEFT)
        self.button_bx.horizontal = True
        self.button_bx.show()

        self.scr.content = self.button_bx
        self.scr.show()

        self.nav_fr = Naviframe(self,
                                size_hint_weight=EXPAND_BOTH,
                                size_hint_align=FILL_BOTH)
        self.nav_fr.show()

        self.pack_end(self.scr)
        self.pack_end(self.nav_fr)

    def add(self, widget, name, can_close=True, disabled=False):
        '''Add a tab to the tabbed box'''
        self.tabs.append(widget)

        btn = Button(self.button_bx,
                     style="anchor",
                     size_hint_align=ALIGN_LEFT)
        btn.text = name
        btn.data["widget"] = widget
        btn.disabled = disabled
        btn.callback_clicked_add(self.show_tab, widget)
        btn.show()

        icn = Icon(self.button_bx)
        icn.standard_set("gtk-close")
        icn.show()

        cls = Button(self.button_bx,
                     content=icn,
                     style="anchor",
                     size_hint_align=ALIGN_LEFT)
        cls.data["widget"] = widget
        cls.callback_clicked_add(self.cb_close_btn)
        cls.disabled = disabled
        if can_close:
            cls.show()

        sep = Separator(self.button_bx, size_hint_align=ALIGN_LEFT)
        sep.show()

        self.button_bx.pack_end(btn)
        self.button_bx.pack_end(cls)
        self.button_bx.pack_end(sep)

        # Arguments go: btn, cls, sep
        widget.data["close"] = cls
        widget.data["button"] = btn
        widget.data["sep"] = sep

        self.show_tab(widget=widget)

    def disable(self, index):
        '''Disable a tab'''
        btn, cls = self.tabs[index].data["button"], self.tabs[index].data[
            "close"]
        btn.disabled = True
        cls.disabled = True

    def enable(self, index):
        '''Enable a tab'''
        btn, cls = self.tabs[index].data["button"], self.tabs[index].data[
            "close"]
        btn.disabled = False
        cls.disabled = False

    def show_tab(self, btn=None, widget=None):
        '''Show tab'''
        # pylint: disable=unidiomatic-typecheck
        #   This is as clear as any alternative to me
        if type(btn) is int:
            widget = self.tabs[btn]
        if widget != self.current:
            if self.current:
                self.current.data["button"].style = "anchor"
            self.nav_fr.item_simple_push(widget)
            self.current = widget
            self.current.data["button"].style = "widget"

            if self.tab_changed_cb:
                # pylint: disable=not-callable
                self.tab_changed_cb(self, widget)

    def cb_close_btn(self, btn):
        '''Close tab'''
        # pylint: disable=not-callable
        if not self.close_cb:
            self.delete_tab(btn.data["widget"])
        else:
            self.close_cb(self, btn.data["widget"])

    def delete_tab(self, widget):
        '''Delete tab'''
        # pylint: disable=unidiomatic-typecheck
        #   This is as clear as any alternative to me
        if type(widget) is int:
            widget = self.tabs[widget]

        del self.tabs[self.tabs.index(widget)]

        self.button_bx.unpack(widget.data["close"])
        self.button_bx.unpack(widget.data["button"])
        self.button_bx.unpack(widget.data["sep"])

        widget.data["close"].delete()
        widget.data["button"].delete()
        widget.data["sep"].delete()
        widget.delete()

        if self.current == widget and self.tabs:
            self.show_tab(widget=self.tabs[0])

        if not self.tabs and self.empty_cb:
            # pylint: disable=not-callable
            self.empty_cb(self)
Ejemplo n.º 3
0
def focus_clicked(obj, item=None):
    win = StandardWindow("focus", "Focus", autodel=True, size=(800,600))
    
    win.focus_highlight_enabled = True

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

    ### Toolbar
    tbar = Toolbar(win, shrink_mode=ELM_TOOLBAR_SHRINK_MENU,
                   size_hint_align=(EVAS_HINT_FILL,0.0))

    tb_it = tbar.item_append("document-print", "Hello", _tb_sel)
    tb_it.disabled = True
    tb_it = tbar.item_append("folder-new", "World", _tb_sel)
    tb_it = tbar.item_append("object-rotate-right", "H", _tb_sel)
    tb_it = tbar.item_append("mail-send", "Comes", _tb_sel)
    tb_it = tbar.item_append("clock", "Elementary", _tb_sel)

    tb_it = tbar.item_append("refresh", "Menu", _tb_sel)
    tb_it.menu = True
    tbar.menu_parent = win
    menu = tb_it.menu

    menu.item_add(None, "Shrink", "edit-cut", _tb_sel)
    menu_it = menu.item_add(None, "Mode", "edit-copy", _tb_sel)
    menu.item_add(menu_it, "is set to", "edit-paste", _tb_sel)
    menu.item_add(menu_it, "or to", "edit-paste", _tb_sel)
    menu.item_add(None, "Menu", "edit-delete", _tb_sel)

    tbx.pack_end(tbar)
    tbar.show()


    mainbx = Box(win, horizontal=True, size_hint_weight=EXPAND_BOTH)
    tbx.pack_end(mainbx)
    mainbx.show()

    ## First Col
    bx = Box(win, size_hint_weight=EXPAND_BOTH)
    mainbx.pack_end(bx)
    bx.show()

    lb = Label(win, text="<b>Use Tab or Shift+Tab<br/>or Arrow keys</b>",
                    size_hint_align=FILL_BOTH)
    bx.pack_end(lb)
    lb.show()

    tg = Check(win, style="toggle")
    tg.part_text_set("on", "Yes")
    tg.part_text_set("off", "No")
    bx.pack_end(tg)
    tg.show()
    
    en = Entry(win, scrollable=True, single_line=True, text="This is a single line",
                    size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ)
    bx.pack_end(en)
    en.show()

    #
    bx2 = Box(win, horizontal=True, size_hint_align=FILL_BOTH)
    bx.pack_end(bx2)
    bx2.show()

    for i in range(2):
        bt = Button(win, text="Box", size_hint_align=FILL_BOTH, disabled=(i % 2))
        bx2.pack_end(bt)
        bt.show()

    sc = Scroller(win, bounce=(True,True), content_min_limit=(1,1),
                  size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH)
    bx2.pack_end(sc)
    sc.show()

    bt = Button(win, text="Scroller", size_hint_align=FILL_BOTH)
    sc.content = bt
    bt.show()

    #
    bt = Button(win, text="Box", size_hint_align=FILL_BOTH)
    bx.pack_end(bt)
    bt.show()

    #
    bx2 = Box(win, horizontal=True, size_hint_align=FILL_BOTH)
    bx.pack_end(bx2)
    bx2.show()
    
    for i in range(2):
        bx3 = Box(win, size_hint_align=FILL_BOTH)
        bx2.pack_end(bx3)
        bx3.show()

        for j in range(3):
            bt = Button(win, text="Box", size_hint_align=FILL_BOTH)
            bx3.pack_end(bt)
            bt.show()
    

    sc = Scroller(win, bounce=(False, True), content_min_limit=(1,0),
                  size_hint_align=FILL_BOTH, size_hint_weight=EXPAND_BOTH)
    sc.content_min_limit=(1,1)
    bx2.pack_end(sc)
    sc.show()

    bx3 = Box(win, size_hint_align=FILL_BOTH)
    sc.content = bx3
    bx3.show()

    for i in range(5):
        bt = Button(win, text="BX Scroller", size_hint_align=FILL_BOTH)
        bx3.pack_end(bt)
        bt.show()


    ## Second Col
    ly = Layout(win, size_hint_weight=EXPAND_BOTH)
    ly.file = edj_file, "twolines"
    mainbx.pack_end(ly)
    ly.show()

    bx2 = Box(win, horizontal=True, size_hint_align=FILL_BOTH)
    ly.part_content_set("element1", bx2)
    bx2.show()

    for i in range(3):
        bt = Button(win, text="Layout", size_hint_align=FILL_BOTH)
        bx2.pack_end(bt)
        bt.show()
        bx2.focus_custom_chain_prepend(bt)

    bx2 = Box(win, size_hint_align=FILL_BOTH)
    ly.part_content_set("element2", bx2)
    bx2.show()

    bt = Button(win, text="Disable", size_hint_align=FILL_BOTH)
    bt.callback_clicked_add(lambda b: b.disabled_set(True))
    bx2.pack_end(bt)
    bt.show()
    bx2.focus_custom_chain_prepend(bt)

    bt2 = Button(win, text="Enable", size_hint_align=FILL_BOTH)
    bt2.callback_clicked_add(lambda b, b1: b1.disabled_set(False), bt)
    bx2.pack_end(bt2)
    bt2.show()
    bx2.focus_custom_chain_append(bt2)

    ## Third Col
    bx = Box(win, size_hint_weight=EXPAND_BOTH)
    mainbx.pack_end(bx)
    bx.show()

    fr = Frame(win, text="Frame", )
    bx.pack_end(fr)
    fr.show()

    tb = Table(win, size_hint_weight=EXPAND_BOTH)
    fr.content = tb
    tb.show()

    for j in range(1):
        for i in range(2):
            bt = Button(win, text="Table", size_hint_align=FILL_BOTH, size_hint_weight=EXPAND_BOTH)
            tb.pack(bt, i, j, 1, 1)
            bt.show()

    #
    fr = Bubble(win, text="Bubble", size_hint_align=FILL_BOTH, size_hint_weight=EXPAND_BOTH)
    bx.pack_end(fr)
    fr.show()

    tb = Table(win,  size_hint_weight=EXPAND_BOTH)
    fr.content = tb
    tb.show()

    for j in range(2):
        for i in range(1):
            bt = Button(win, text="Table", size_hint_align=FILL_BOTH, size_hint_weight=EXPAND_BOTH)
            tb.pack(bt, i, j, 1, 1)
            bt.show()


    win.show()
Ejemplo n.º 4
0
class TabbedBox(Box):
    def __init__(self, parent_widget, *args, **kwargs):
        Box.__init__(self, parent_widget, *args, **kwargs)

        self.tabs = []
        self.currentTab = None
        self.tabChangedCallback = None
        self.closeCallback = None
        self.emptyCallback = None

        self.scr = Scroller(self,
                            size_hint_weight=EXPAND_HORIZ,
                            size_hint_align=FILL_BOTH)
        self.scr.content_min_limit(False, True)

        self.buttonBox = Box(self.scr,
                             size_hint_weight=EXPAND_HORIZ,
                             align=ALIGN_LEFT)
        self.buttonBox.horizontal = True
        self.buttonBox.show()

        self.scr.content = self.buttonBox
        self.scr.show()

        self.nf = Naviframe(self,
                            size_hint_weight=EXPAND_BOTH,
                            size_hint_align=FILL_BOTH)
        self.nf.show()

        self.pack_end(self.scr)
        self.pack_end(self.nf)

    def addTab(self, widget, tabName, canClose=True, disabled=False):
        self.tabs.append(widget)

        btn = Button(self.buttonBox,
                     style="anchor",
                     size_hint_align=ALIGN_LEFT)
        btn.text = tabName
        btn.data["widget"] = widget
        btn.disabled = disabled
        btn.callback_clicked_add(self.showTab, widget)
        btn.show()

        icn = Icon(self.buttonBox)
        icn.standard_set("gtk-close")
        icn.show()

        cls = Button(self.buttonBox,
                     content=icn,
                     style="anchor",
                     size_hint_align=ALIGN_LEFT)
        cls.data["widget"] = widget
        cls.callback_clicked_add(self.closeTab)
        cls.disabled = disabled
        if canClose:
            cls.show()

        sep = Separator(self.buttonBox, size_hint_align=ALIGN_LEFT)
        sep.show()

        self.buttonBox.pack_end(btn)
        self.buttonBox.pack_end(cls)
        self.buttonBox.pack_end(sep)

        #Arguments go: btn, cls, sep
        widget.data["close"] = cls
        widget.data["button"] = btn
        widget.data["sep"] = sep

        self.showTab(widget=widget)

    def disableTab(self, tabIndex):
        btn, cls = self.tabs[tabIndex].data["button"], self.tabs[
            tabIndex].data["close"]
        btn.disabled = True
        cls.disabled = True

    def enableTab(self, tabIndex):
        btn, cls = self.tabs[tabIndex].data["button"], self.tabs[
            tabIndex].data["close"]
        btn.disabled = False
        cls.disabled = False

    def showTab(self, btn=None, widget=None):
        if type(btn) is int:
            widget = self.tabs[btn]
        if widget != self.currentTab:
            if self.currentTab:
                self.currentTab.data["button"].style = "anchor"
            self.nf.item_simple_push(widget)
            self.currentTab = widget
            self.currentTab.data["button"].style = "widget"

            if self.tabChangedCallback:
                self.tabChangedCallback(self, widget)

    def closeTab(self, btn):
        if not self.closeCallback:
            self.deleteTab(btn.data["widget"])
        else:
            self.closeCallback(self, btn.data["widget"])

    def deleteTab(self, widget):
        if type(widget) is int:
            widget = self.tabs[widget]

        del self.tabs[self.tabs.index(widget)]

        self.buttonBox.unpack(widget.data["close"])
        self.buttonBox.unpack(widget.data["button"])
        self.buttonBox.unpack(widget.data["sep"])

        widget.data["close"].delete()
        widget.data["button"].delete()
        widget.data["sep"].delete()
        widget.delete()

        if self.currentTab == widget and len(self.tabs):
            self.showTab(widget=self.tabs[0])

        if not len(self.tabs) and self.emptyCallback:
            self.emptyCallback(self)
Ejemplo n.º 5
0
def focus_clicked(obj, item=None):
    win = StandardWindow("focus", "Focus", autodel=True, size=(800, 600))

    win.focus_highlight_enabled = True

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

    ### Toolbar
    tbar = Toolbar(win,
                   shrink_mode=ELM_TOOLBAR_SHRINK_MENU,
                   size_hint_align=(EVAS_HINT_FILL, 0.0))

    tb_it = tbar.item_append("document-print", "Hello", _tb_sel)
    tb_it.disabled = True
    tb_it = tbar.item_append("folder-new", "World", _tb_sel)
    tb_it = tbar.item_append("object-rotate-right", "H", _tb_sel)
    tb_it = tbar.item_append("mail-send", "Comes", _tb_sel)
    tb_it = tbar.item_append("clock", "Elementary", _tb_sel)

    tb_it = tbar.item_append("refresh", "Menu", _tb_sel)
    tb_it.menu = True
    tbar.menu_parent = win
    menu = tb_it.menu

    menu.item_add(None, "Shrink", "edit-cut", _tb_sel)
    menu_it = menu.item_add(None, "Mode", "edit-copy", _tb_sel)
    menu.item_add(menu_it, "is set to", "edit-paste", _tb_sel)
    menu.item_add(menu_it, "or to", "edit-paste", _tb_sel)
    menu.item_add(None, "Menu", "edit-delete", _tb_sel)

    tbx.pack_end(tbar)
    tbar.show()

    mainbx = Box(win, horizontal=True, size_hint_weight=EXPAND_BOTH)
    tbx.pack_end(mainbx)
    mainbx.show()

    ## First Col
    bx = Box(win, size_hint_weight=EXPAND_BOTH)
    mainbx.pack_end(bx)
    bx.show()

    lb = Label(win,
               text="<b>Use Tab or Shift+Tab<br/>or Arrow keys</b>",
               size_hint_align=FILL_BOTH)
    bx.pack_end(lb)
    lb.show()

    tg = Check(win, style="toggle")
    tg.part_text_set("on", "Yes")
    tg.part_text_set("off", "No")
    bx.pack_end(tg)
    tg.show()

    en = Entry(win,
               scrollable=True,
               single_line=True,
               text="This is a single line",
               size_hint_weight=EXPAND_HORIZ,
               size_hint_align=FILL_HORIZ)
    bx.pack_end(en)
    en.show()

    #
    bx2 = Box(win, horizontal=True, size_hint_align=FILL_BOTH)
    bx.pack_end(bx2)
    bx2.show()

    for i in range(2):
        bt = Button(win,
                    text="Box",
                    size_hint_align=FILL_BOTH,
                    disabled=(i % 2))
        bx2.pack_end(bt)
        bt.show()

    sc = Scroller(win,
                  bounce=(True, True),
                  content_min_limit=(1, 1),
                  size_hint_weight=EXPAND_BOTH,
                  size_hint_align=FILL_BOTH)
    bx2.pack_end(sc)
    sc.show()

    bt = Button(win, text="Scroller", size_hint_align=FILL_BOTH)
    sc.content = bt
    bt.show()

    #
    bt = Button(win, text="Box", size_hint_align=FILL_BOTH)
    bx.pack_end(bt)
    bt.show()

    #
    bx2 = Box(win, horizontal=True, size_hint_align=FILL_BOTH)
    bx.pack_end(bx2)
    bx2.show()

    for i in range(2):
        bx3 = Box(win, size_hint_align=FILL_BOTH)
        bx2.pack_end(bx3)
        bx3.show()

        for j in range(3):
            bt = Button(win, text="Box", size_hint_align=FILL_BOTH)
            bx3.pack_end(bt)
            bt.show()

    sc = Scroller(win,
                  bounce=(False, True),
                  content_min_limit=(1, 0),
                  size_hint_align=FILL_BOTH,
                  size_hint_weight=EXPAND_BOTH)
    sc.content_min_limit = (1, 1)
    bx2.pack_end(sc)
    sc.show()

    bx3 = Box(win, size_hint_align=FILL_BOTH)
    sc.content = bx3
    bx3.show()

    for i in range(5):
        bt = Button(win, text="BX Scroller", size_hint_align=FILL_BOTH)
        bx3.pack_end(bt)
        bt.show()

    ## Second Col
    ly = Layout(win, size_hint_weight=EXPAND_BOTH)
    ly.file = edj_file, "twolines"
    mainbx.pack_end(ly)
    ly.show()

    bx2 = Box(win, horizontal=True, size_hint_align=FILL_BOTH)
    ly.part_content_set("element1", bx2)
    bx2.show()

    for i in range(3):
        bt = Button(win, text="Layout", size_hint_align=FILL_BOTH)
        bx2.pack_end(bt)
        bt.show()
        bx2.focus_custom_chain_prepend(bt)

    bx2 = Box(win, size_hint_align=FILL_BOTH)
    ly.part_content_set("element2", bx2)
    bx2.show()

    bt = Button(win, text="Disable", size_hint_align=FILL_BOTH)
    bt.callback_clicked_add(lambda b: b.disabled_set(True))
    bx2.pack_end(bt)
    bt.show()
    bx2.focus_custom_chain_prepend(bt)

    bt2 = Button(win, text="Enable", size_hint_align=FILL_BOTH)
    bt2.callback_clicked_add(lambda b, b1: b1.disabled_set(False), bt)
    bx2.pack_end(bt2)
    bt2.show()
    bx2.focus_custom_chain_append(bt2)

    ## Third Col
    bx = Box(win, size_hint_weight=EXPAND_BOTH)
    mainbx.pack_end(bx)
    bx.show()

    fr = Frame(
        win,
        text="Frame",
    )
    bx.pack_end(fr)
    fr.show()

    tb = Table(win, size_hint_weight=EXPAND_BOTH)
    fr.content = tb
    tb.show()

    for j in range(1):
        for i in range(2):
            bt = Button(win,
                        text="Table",
                        size_hint_align=FILL_BOTH,
                        size_hint_weight=EXPAND_BOTH)
            tb.pack(bt, i, j, 1, 1)
            bt.show()

    #
    fr = Bubble(win,
                text="Bubble",
                size_hint_align=FILL_BOTH,
                size_hint_weight=EXPAND_BOTH)
    bx.pack_end(fr)
    fr.show()

    tb = Table(win, size_hint_weight=EXPAND_BOTH)
    fr.content = tb
    tb.show()

    for j in range(2):
        for i in range(1):
            bt = Button(win,
                        text="Table",
                        size_hint_align=FILL_BOTH,
                        size_hint_weight=EXPAND_BOTH)
            tb.pack(bt, i, j, 1, 1)
            bt.show()

    win.show()