示例#1
0
def access_clicked(obj, item=None):
    win = StandardWindow("access", "Access")
    win.autodel = True
    win.on_free_add(cleanup_cb)

    config.access = True

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

    gl = Genlist(win, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH)
    bx.pack_end(gl)
    gl.show()

    gl.callback_realized_add(_realized)

    itc1 = GLItC1(item_style="default")
    itc2 = GLItC2(item_style="full")

    for i in range(1, 9):
        if i % 4:
            gl.item_append(itc1, i, None, ELM_GENLIST_ITEM_NONE)
        else:
            gl.item_append(itc2, i, None, ELM_GENLIST_ITEM_NONE)

    itc1.free()
    itc2.free()
    win.resize(500, 400)
    win.show()
示例#2
0
    def __init__(self, parent):

        self.win = parent
        self.sig1 = None

        # create the genlist
        Genlist.__init__(self, parent)
        self.itc = NamesListItemClass()
        self.itc_g = NamesListGroupItemClass()
        self.callback_selected_add(self.item_selected_cb)

        # add private & public group items
        self.public_group = self.item_append(self.itc_g,
                                             "Public Services",
                                             flags=elm.ELM_GENLIST_ITEM_GROUP)
        self.public_group.select_mode_set(
            elm.ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY)

        self.private_group = self.item_append(self.itc_g,
                                              "Private Services",
                                              flags=elm.ELM_GENLIST_ITEM_GROUP)
        self.private_group.select_mode_set(
            elm.ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY)

        # populate the genlist
        self.populate()
示例#3
0
def genlist15_clicked(obj, item=None):
    win = StandardWindow("genlist-decorate-all-mode",
                         "Genlist Decorate All Mode",
                         autodel=True,
                         size=(520, 520))

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

    gl = Genlist(win, size_hint_align=FILL_BOTH, size_hint_weight=EXPAND_BOTH)
    gl.show()

    itc15 = ItemClass15(item_style="default", decorate_all_item_style="edit")
    itc15.state_get = gl_state_get

    for i in range(100):
        ck = Check(gl)
        data = [i, False]
        it = GenlistItem(
            item_class=itc15,
            item_data=data,
            parent_item=None,
            flags=ELM_GENLIST_ITEM_NONE,
            func=gl15_sel,
            func_data=data,
        ).append_to(gl)

        data.append(it)

    bx.pack_end(gl)
    bx.show()

    bx2 = Box(win,
              horizontal=True,
              homogeneous=True,
              size_hint_weight=EXPAND_HORIZ,
              size_hint_align=FILL_BOTH)

    bt = Button(win,
                text="Decorate All mode",
                size_hint_align=FILL_BOTH,
                size_hint_weight=EXPAND_HORIZ)
    bt.callback_clicked_add(gl15_deco_all_mode, gl)
    bx2.pack_end(bt)
    bt.show()

    bt = Button(win,
                text="Normal mode",
                size_hint_align=FILL_BOTH,
                size_hint_weight=EXPAND_HORIZ)
    bt.callback_clicked_add(gl15_normal_mode, gl)
    bx2.pack_end(bt)
    bt.show()

    bx.pack_end(bx2)
    bx2.show()

    win.show()
def index_clicked(obj):
    win = StandardWindow("index", "Index test", autodel=True, size=(320, 480))
    if obj is None:
        win.callback_delete_request_add(lambda o: elementary.exit())

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

    # index
    idx = Index(win, size_hint_align=FILL_BOTH, size_hint_weight=EXPAND_BOTH)
    idx.callback_delay_changed_add(cb_idx_delay_changed)
    idx.callback_changed_add(cb_idx_changed)
    idx.callback_selected_add(cb_idx_selected)
    win.resize_object_add(idx)
    idx.show()

    # genlist
    itc = GenlistItemClass(item_style="default", text_get_func=gl_text_get)
    # content_get_func=gl_content_get,
    # state_get_func=gl_state_get)
    gl = Genlist(win, size_hint_align=FILL_BOTH, size_hint_weight=EXPAND_BOTH)
    vbox.pack_end(gl)
    gl.show()

    for i in 'ABCDEFGHILMNOPQRSTUVZ':
        for j in 'acegikmo':
            gl_item = gl.item_append(itc, i + j)
            if j == 'a':
                idx_item = idx.item_append(i, cb_idx_item, gl_item)
                idx_item.data["gl_item"] = gl_item

    idx.level_go(0)

    sep = Separator(win, horizontal=True)
    vbox.pack_end(sep)
    sep.show()

    hbox = Box(win, horizontal=True, size_hint_weight=EXPAND_HORIZ)
    vbox.pack_end(hbox)
    hbox.show()

    ck = Check(win, text="autohide_disabled")
    ck.callback_changed_add(lambda ck: idx.autohide_disabled_set(ck.state))
    hbox.pack_end(ck)
    ck.show()

    ck = Check(win, text="indicator_disabled")
    ck.callback_changed_add(lambda ck: idx.indicator_disabled_set(ck.state))
    hbox.pack_end(ck)
    ck.show()

    ck = Check(win, text="horizontal")
    ck.callback_changed_add(lambda ck: idx.horizontal_set(ck.state))
    hbox.pack_end(ck)
    ck.show()

    win.show()
def dnd_genlist_gengrid_clicked(obj, item=None):
    win = StandardWindow("dnd-genlist-gengrid",
                         "DnD-Genlist-Gengrid",
                         autodel=True,
                         size=(680, 800))

    bxx = Box(win, horizontal=True, size_hint_weight=EXPAND_BOTH)
    win.resize_object_add(bxx)
    bxx.show()

    gl = Genlist(win,
                 multi_select=True,
                 size_hint_weight=EXPAND_BOTH,
                 size_hint_align=FILL_BOTH)
    win.callback_delete_request_add(win_del, gl)

    # START Drag and Drop handling
    gl.drop_item_container_add(ELM_SEL_FORMAT_TARGETS,
                               gl_item_getcb,
                               dropcb=gl_dropcb)

    gl.drag_item_container_add(ANIM_TIME, DRAG_TIMEOUT, gl_item_getcb,
                               gl_dnd_default_anim_data_getcb)
    # END Drag and Drop handling

    # FIXME: This causes genlist to resize the horiz axis very slowly :(
    # Reenable this and resize the window horizontally, then try to resize it back
    #elm_genlist_mode_set(gl, ELM_LIST_LIMIT)
    bxx.pack_end(gl)
    gl.show()

    for i in range(20):
        gl.item_append(itc1, img[i % 9], flags=ELM_GENLIST_ITEM_NONE)

    grid = Gengrid(win,
                   item_size=(conf.scale * 150, conf.scale * 150),
                   horizontal=False,
                   reorder_mode=False,
                   multi_select=True,
                   size_hint_weight=EXPAND_BOTH,
                   size_hint_align=FILL_BOTH)
    win.callback_delete_request_add(win_del, grid)

    grid.drop_item_container_add(ELM_SEL_FORMAT_TARGETS,
                                 grid_item_getcb,
                                 dropcb=grid_dropcb)

    grid.drag_item_container_add(ANIM_TIME, DRAG_TIMEOUT, grid_item_getcb,
                                 grid_data_getcb)

    for i in range(20):
        grid.item_append(gic, img[i % 9])

    bxx.pack_end(grid)
    grid.show()

    win.show()
示例#6
0
 def __init__(self, parent):
     Genlist.__init__(self, parent)
     self._parent = parent
     self.itc = NodeItemClass()
     self.itc_g = ObjectItemClass()
     self.callback_expand_request_add(self.expand_request_cb)
     self.callback_expanded_add(self.expanded_cb)
     self.callback_contract_request_add(self.contract_request_cb)
     self.callback_contracted_add(self.contracted_cb)
     self.callback_clicked_double_add(self.double_click_cb)
示例#7
0
def genlist5_clicked(obj, item=None):
    win = StandardWindow("Genlist",
                         "Genlist iteration test",
                         autodel=True,
                         size=(320, 320))

    gl = Genlist(win,
                 homogeneous=True,
                 size_hint_align=FILL_BOTH,
                 size_hint_weight=EXPAND_BOTH)
    win.resize_object_add(gl)
    gl.show()

    itc_i = GenlistItemClass(item_style="default",
                             text_get_func=gl_text_get,
                             content_get_func=gl_content_get,
                             state_get_func=gl_state_get)

    item_count = 10000

    t1 = time.time()
    for i in range(item_count):
        GenlistItem(itc_i, i).append_to(gl)
    t2 = time.time()

    assert (len(gl) == gl.items_count)

    t3 = time.time()
    it = gl.first_item
    while it:
        d = it.data
        it = it.next
    t4 = time.time()

    assert (d == item_count - 1)

    t5 = time.time()
    for it in gl:
        e = it.data
    t6 = time.time()

    assert (e == item_count - 1)
    assert (it in gl)

    print("Time to add {0} items:".format(item_count))
    print(t2 - t1)
    print("Time to iterate item data over {0} items using "
          "it.next:".format(item_count))
    print(t4 - t3)
    print("Time to iterate item data over {0} items using "
          "a python iterator:".format(item_count))
    print(t6 - t5)

    win.show()
示例#8
0
def genlist3_clicked(obj, item=None):
    win = StandardWindow("Genlist",
                         "Genlist Group test",
                         autodel=True,
                         size=(320, 320))

    gl = Genlist(win, size_hint_align=FILL_BOTH, size_hint_weight=EXPAND_BOTH)
    win.resize_object_add(gl)
    gl.show()

    itc_i = GenlistItemClass(item_style="default",
                             text_get_func=gl_text_get,
                             content_get_func=gl_content_get,
                             state_get_func=gl_state_get)

    itc_g = GenlistItemClass(item_style="group_index",
                             text_get_func=glg_text_get,
                             content_get_func=glg_content_get)

    for i in range(300):
        if i % 10 == 0:
            git = gl.item_append(itc_g, i / 10, flags=ELM_GENLIST_ITEM_GROUP)
            git.select_mode_set(ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY)
        gl.item_append(itc_i, i, git)

    win.show()
示例#9
0
def genlist4_clicked(obj, item=None):
    win = StandardWindow("Genlist",
                         "Genlist sorted insert test",
                         autodel=True,
                         size=(320, 320))

    gl = Genlist(win, size_hint_align=FILL_BOTH, size_hint_weight=EXPAND_BOTH)
    win.resize_object_add(gl)
    gl.show()

    itc_i = GenlistItemClass(item_style="default",
                             text_get_func=gl_text_get,
                             content_get_func=gl_content_get,
                             state_get_func=gl_state_get)

    for i in range(100, -1, -1):
        GenlistItem(itc_i, i).sorted_insert(gl, gl_comp_func)

    win.show()
    def __init__(self, parent):
        Frame.__init__(self, parent, text="Signals")
        self._parent = parent

        vbox = Box(self)
        vbox.show()
        self.content = vbox

        self.siglist = Genlist(self, homogeneous=True, mode=ELM_LIST_SCROLL)
        self.siglist.size_hint_weight = EVAS_HINT_EXPAND, EVAS_HINT_EXPAND
        self.siglist.size_hint_align = EVAS_HINT_FILL, EVAS_HINT_FILL
        self.siglist.callback_clicked_double_add(self.signal_clicked_cb)
        self.siglist.show()
        vbox.pack_end(self.siglist)
        self.itc = SignalItemClass()

        hbox = Box(self, horizontal=True)
        hbox.size_hint_align = 0.0, 0.5
        hbox.show()
        vbox.pack_end(hbox)

        bt = Button(self, text='Clear')
        bt.callback_clicked_add(lambda b: self.siglist.clear())
        hbox.pack_end(bt)
        bt.show()

        def scroll_on_signal_clicked_cb(chk):
            options.scroll_on_signal = chk.state

        ck = Check(self, text='Scroll on signal')
        ck.state = options.scroll_on_signal
        ck.callback_changed_add(scroll_on_signal_clicked_cb)
        hbox.pack_end(ck)
        ck.show()

        for b in session_bus, system_bus:
            b.add_signal_receiver(self.signal_cb,
                                  sender_keyword='sender',
                                  destination_keyword='dest',
                                  interface_keyword='iface',
                                  member_keyword='signal',
                                  path_keyword='path')
def floating_clicked(obj):
    win = StandardWindow("floating", "Floating", autodel=True, size=(480, 800))

    gl = Genlist(win,
                 size_hint_weight=EXPAND_BOTH,
                 size_hint_align=FILL_BOTH,
                 pos=(800, 0),
                 size=(480, 800))
    gl.show()

    for i in range(20):
        GenlistItem(ItemClass(), i, None, ELM_GENLIST_ITEM_NONE, gl_sel_cb,
                    i).append_to(gl)

    win.show()

    ani = Animator(anim, gl)
    win.callback_delete_request_add(del_cb, ani)
    if obj is None:
        win.callback_delete_request_add(lambda o: elementary.exit())
    def __init__(self, parent):

        self.win = parent
        self.sig1 = None
        self.waiting_activation = None
        self.waiting_popup = None

        # create the genlist
        Genlist.__init__(self, parent)
        self.itc = NamesListItemClass()
        self.itc_g = NamesListGroupItemClass()
        self.callback_selected_add(self.item_selected_cb)

        # add public group item
        self.public_group = self.item_append(self.itc_g,
                                             "Public Services",
                                             flags=ELM_GENLIST_ITEM_GROUP)
        self.public_group.select_mode_set(ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY)

        # add activatables group item
        self.activatable_group = self.item_append(self.itc_g,
                                                  "Activatable Services",
                                                  flags=ELM_GENLIST_ITEM_GROUP)
        self.activatable_group.select_mode_set(
            ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY)

        # add private group item
        if options.show_private_stuff:
            self.private_group = self.item_append(self.itc_g,
                                                  "Private Services",
                                                  flags=ELM_GENLIST_ITEM_GROUP)
            self.private_group.select_mode_set(
                ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY)

        # populate the genlist
        self.populate()
示例#13
0
    def __init__(self):
        StandardWindow.__init__(self, "ex11", "Genlist List", size=(300, 200))
        self.callback_delete_request_add(lambda o: elm.exit())

        ourList = Genlist(self)
        ourList.size_hint_weight = EXPAND_BOTH
        ourList.callback_activated_add(self.listItemSelected)

        ListItems.sort()

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

        ourList.show()

        self.resize_object_add(ourList)
    def __init__(self, parent, h):
        Box.__init__(self, parent)

        filelist = Genlist(self)
        filelist.size_hint_align = -1.0, -1.0
        filelist.size_hint_weight = 1.0, 1.0

        self.populate(filelist, h)

        filelist.callback_activated_add(self.item_activated_cb)
        filelist.show()

        sel_all = Button(self)
        sel_all.text = "Select all"
        sel_all.callback_clicked_add(self.select_all_cb, filelist, h, True)
        sel_all.show()

        sel_none = Button(self)
        sel_none.text = "Select none"
        sel_none.callback_clicked_add(self.select_all_cb, filelist, h, False)
        sel_none.show()

        xbtn = Button(self)
        xbtn.text = "Close"
        xbtn.callback_clicked_add(lambda x: parent.item_pop())
        xbtn.show()

        btn_box = Box(self)
        btn_box.horizontal = True
        btn_box.pack_end(sel_all)
        btn_box.pack_end(sel_none)
        btn_box.pack_end(xbtn)
        btn_box.show()

        self.pack_end(filelist)
        self.pack_end(btn_box)
        self.show()
class FileSelector(Box):
    '''FileSelector Class'''

    # pylint: disable=too-many-instance-attributes, too-many-statements
    def __init__(self,
                 parent_widget,
                 *args,
                 default_path='',
                 default_populate=True,
                 **kwargs):
        Box.__init__(self, parent_widget, *args, **kwargs)

        self.cancel_cb = None
        self.action_cb = None
        self.cb_dir_change = None

        self.threaded_fn = ThreadedFunction()
        # pylint: disable=c-extension-no-member
        self._timer = ecore.Timer(0.02, self.populate_file)

        # Watch key presses for ctrl+l to select entry
        parent_widget.elm_event_callback_add(self.cb_events)

        self.selected_dir = None
        self.show_hidden = False
        self.cur_dir = None
        self.focused_entry = None
        self.dir_only = False
        self.sort_reverse = False
        self.adding_hidden = False
        self.pending_files = deque()
        self.cur_subdirs = []
        self.cur_files = []

        # Mode should be 'save' or 'load'
        self.mode = 'save'

        self.home = os.path.expanduser('~')

        desktop = os.environ.get('XDG_DESKTOP_DIR')
        if desktop:
            self.desktop = desktop
        else:
            self.desktop = self.home + '/Desktop'

        self.root = '/'

        # Label+Entry for File Name
        self.filename_bx = Box(self,
                               size_hint_weight=EXPAND_HORIZ,
                               size_hint_align=FILL_HORIZ)
        self.filename_bx.horizontal = True
        self.filename_bx.show()

        file_label = Label(self,
                           size_hint_weight=(0.15, EVAS_HINT_EXPAND),
                           size_hint_align=FILL_HORIZ)
        file_label.text = 'Filename:'
        file_label.show()

        self.file_entry = Entry(self,
                                size_hint_weight=EXPAND_BOTH,
                                size_hint_align=FILL_HORIZ)
        self.file_entry.single_line_set(True)
        self.file_entry.scrollable_set(True)
        self.file_entry.callback_changed_user_add(self.cb_file_entry)
        self.file_entry.show()

        self.filename_bx.pack_end(file_label)
        self.filename_bx.pack_end(self.file_entry)

        sep = Separator(self,
                        size_hint_weight=EXPAND_HORIZ,
                        size_hint_align=FILL_HORIZ)
        sep.horizontal_set(True)
        sep.show()

        # Label+Entry for File Path
        self.filepath_bx = Box(self,
                               size_hint_weight=EXPAND_HORIZ,
                               size_hint_align=FILL_HORIZ)
        self.filepath_bx.horizontal = True
        self.filepath_bx.show()

        file_label = Label(self,
                           size_hint_weight=(0.15, EVAS_HINT_EXPAND),
                           size_hint_align=FILL_HORIZ)
        file_label.text = 'Current Folder:'
        file_label.show()

        self.filepath_en = Entry(self,
                                 size_hint_weight=EXPAND_BOTH,
                                 size_hint_align=FILL_HORIZ)
        self.filepath_en.single_line_set(True)
        self.filepath_en.scrollable_set(True)
        self.filepath_en.callback_changed_user_add(self.cb_file_entry)
        self.filepath_en.callback_unfocused_add(self.cb_filepath_en)
        self.filepath_en.callback_activated_add(self.cb_filepath_en)
        # Wish this worked. Doesn't seem to do anything
        # Working now EFL 1.22 ?
        self.filepath_en.input_hint_set(ELM_INPUT_HINT_AUTO_COMPLETE)

        if default_path and os.path.isdir(default_path):
            start = default_path
        else:
            start = self.home
        self.filepath_en.show()

        self.filepath_bx.pack_end(file_label)
        self.filepath_bx.pack_end(self.filepath_en)

        self.autocomplete_hover = Hoversel(self, hover_parent=self)
        self.autocomplete_hover.callback_selected_add(self.cb_hover)
        self.autocomplete_hover.show()

        self.file_selector_bx = Panes(self,
                                      content_left_size=0.3,
                                      size_hint_weight=EXPAND_BOTH,
                                      size_hint_align=FILL_BOTH)
        self.file_selector_bx.show()
        # Bookmarks Box contains:
        #
        # - Button - Up Arrow
        # - List - Home/Desktop/Root/GTK bookmarks
        # - Box
        # -- Button - Add Bookmark
        # -- Button - Remove Bookmark
        self.bookmark_bx = Box(self,
                               size_hint_weight=(0.3, EVAS_HINT_EXPAND),
                               size_hint_align=FILL_BOTH)
        self.bookmark_bx.show()

        up_ic = Icon(self,
                     size_hint_weight=EXPAND_BOTH,
                     size_hint_align=FILL_BOTH,
                     order_lookup=ELM_ICON_LOOKUP_THEME)
        up_ic.standard_set('arrow-up')
        up_ic.show()

        self.up_btn = Button(self,
                             size_hint_weight=EXPAND_HORIZ,
                             size_hint_align=FILL_HORIZ,
                             content=up_ic)
        self.up_btn.text = 'Up'
        self.up_btn.callback_pressed_add(self.cb_up_btn)
        self.up_btn.show()

        self.bookmarks_lst = List(self,
                                  size_hint_weight=EXPAND_BOTH,
                                  size_hint_align=FILL_BOTH)
        self.bookmarks_lst.callback_activated_add(self.cb_bookmarks_lst)
        self.bookmarks_lst.show()

        self.bookmark_modbox = Box(self,
                                   size_hint_weight=EXPAND_HORIZ,
                                   size_hint_align=FILL_HORIZ)
        self.bookmark_modbox.horizontal = True
        self.bookmark_modbox.show()

        con = Icon(self,
                   size_hint_weight=EXPAND_BOTH,
                   size_hint_align=FILL_BOTH)
        con.standard_set('list-add')
        con.show()

        self.add_btn = Button(self,
                              size_hint_weight=EXPAND_HORIZ,
                              size_hint_align=FILL_HORIZ,
                              content=con)
        self.add_btn.callback_pressed_add(self.cb_add_btn)
        self.add_btn.disabled = True
        self.add_btn.show()

        con = Icon(self,
                   size_hint_weight=EXPAND_BOTH,
                   size_hint_align=FILL_BOTH)
        con.standard_set('list-remove')
        con.show()

        self.rm_btn = Button(self,
                             size_hint_weight=EXPAND_HORIZ,
                             size_hint_align=FILL_HORIZ,
                             content=con)
        self.rm_btn.callback_pressed_add(self.cb_remove)
        self.rm_btn.disabled = True
        self.rm_btn.show()

        self.bookmark_modbox.pack_end(self.add_btn)
        self.bookmark_modbox.pack_end(self.rm_btn)

        self.bookmark_bx.pack_end(self.up_btn)
        self.bookmark_bx.pack_end(self.bookmarks_lst)
        self.bookmark_bx.pack_end(self.bookmark_modbox)

        # Directory List
        self.file_list_bx = Box(self,
                                size_hint_weight=EXPAND_BOTH,
                                size_hint_align=FILL_BOTH)
        self.file_list_bx.show()

        self.file_sort_btn = Button(self,
                                    size_hint_weight=EXPAND_HORIZ,
                                    size_hint_align=FILL_HORIZ)
        self.file_sort_btn.text = u'⬆ Name'
        self.file_sort_btn.callback_pressed_add(self.cb_sort)
        self.file_sort_btn.show()

        self.file_lst = Genlist(self,
                                size_hint_weight=EXPAND_BOTH,
                                size_hint_align=FILL_BOTH,
                                homogeneous=True,
                                mode=ELM_LIST_COMPRESS)
        self.file_lst.callback_activated_add(self.cb_file_lst)
        self.file_lst.show()

        self.preview = preview = Image(self)
        preview.size_hint_align = FILL_BOTH
        preview.show()

        self.file_list_bx.pack_end(self.file_sort_btn)
        self.file_list_bx.pack_end(self.file_lst)
        self.file_list_bx.pack_end(self.preview)

        self.file_selector_bx.part_content_set('left', self.bookmark_bx)
        self.file_selector_bx.part_content_set('right', self.file_list_bx)

        # Cancel and Save/Open button
        self.button_bx = Box(self,
                             size_hint_weight=EXPAND_HORIZ,
                             size_hint_align=(1.0, 0.5))
        self.button_bx.horizontal = True
        self.button_bx.show()

        self.action_ic = Icon(self,
                              size_hint_weight=EXPAND_BOTH,
                              size_hint_align=FILL_BOTH)
        self.action_ic.standard_set('document-save')
        self.action_ic.show()

        self.action_btn = Button(self,
                                 size_hint_weight=(0.0, 0.0),
                                 size_hint_align=(1.0, 0.5),
                                 content=self.action_ic)
        self.action_btn.text = 'Save  '
        self.action_btn.callback_pressed_add(self.cb_action_btn)
        self.action_btn.show()

        cancel_ic = Icon(self,
                         size_hint_weight=EXPAND_BOTH,
                         size_hint_align=FILL_BOTH)
        cancel_ic.standard_set('application-exit')
        cancel_ic.show()

        self.cancel_btn = Button(self,
                                 size_hint_weight=(0.0, 0.0),
                                 size_hint_align=(1.0, 0.5),
                                 content=cancel_ic)
        self.cancel_btn.text = 'Cancel  '
        self.cancel_btn.callback_pressed_add(self.cb_cancel_btn)
        self.cancel_btn.show()

        con = Icon(self,
                   size_hint_weight=EXPAND_BOTH,
                   size_hint_align=FILL_BOTH)
        con.standard_set('edit-find')
        con.show()

        self.hidden_btn = Button(self,
                                 size_hint_weight=(0.0, 0.0),
                                 size_hint_align=(1.0, 0.5),
                                 content=con)
        self.hidden_btn.text = 'Toggle Hidden  '
        self.hidden_btn.callback_pressed_add(self.cb_toggle_hidden)
        self.hidden_btn.show()

        con = Icon(self,
                   size_hint_weight=EXPAND_BOTH,
                   size_hint_align=FILL_BOTH)
        con.standard_set('folder-new')
        con.show()

        self.create_dir_btn = Button(self,
                                     size_hint_weight=(0.0, 0.0),
                                     size_hint_align=(1.0, 0.5),
                                     content=con)
        self.create_dir_btn.text = 'Create Folder  '
        self.create_dir_btn.callback_pressed_add(self.cb_create_dir)
        self.create_dir_btn.show()

        self.button_bx.pack_end(self.create_dir_btn)
        self.button_bx.pack_end(self.hidden_btn)
        self.button_bx.pack_end(self.cancel_btn)
        self.button_bx.pack_end(self.action_btn)

        self.pack_end(self.filename_bx)
        self.pack_end(sep)
        self.pack_end(self.filepath_bx)
        self.pack_end(self.autocomplete_hover)
        self.pack_end(self.file_selector_bx)
        self.pack_end(self.button_bx)

        self.populate_bookmarks()

        self.create_popup = Popup(self)
        self.create_popup.part_text_set('title,text', 'Create Folder:')

        self.create_en = Entry(self,
                               size_hint_weight=EXPAND_HORIZ,
                               size_hint_align=FILL_HORIZ)
        self.create_en.single_line_set(True)
        self.create_en.scrollable_set(True)
        self.create_en.show()

        self.create_popup.content = self.create_en

        bt0 = Button(self, text='Create')
        bt0.callback_clicked_add(self.cb_create_folder)
        self.create_popup.part_content_set('button1', bt0)
        bt1 = Button(self, text='Cancel')
        bt1.callback_clicked_add(self.cb_close_popup)
        self.create_popup.part_content_set('button2', bt1)

        self.recent = None  # keeps pylint happy:
        if default_populate:
            self.populate_files(start)

    def dir_only_set(self, value):
        '''Set folder only attribute and adjust display'''
        self.dir_only = value

        if not self.dir_only:
            self.filename_bx.show()
        else:
            self.filename_bx.hide()

    def cb_create_folder(self, obj):
        '''Create a new folder'''
        new = f'{self.cur_dir}{self.create_en.text}'
        os.makedirs(new)
        self.cb_close_popup()
        self.populate_files(self.cur_dir)

    def cb_create_dir(self, obj):
        '''Open popup to create a new folder'''
        self.create_en.text = ''
        self.create_popup.show()
        self.create_en.select_all()

    def cb_close_popup(self, btn=None):
        '''Close popup'''
        self.create_popup.hide()

    # pylint: disable=unused-argument
    def shutdown(self, obj=None):
        '''Cleanup function for FileSelector widget shutdown'''
        self._timer.delete()
        self.threaded_fn.shutdown()

    def cb_sort(self, btn):
        '''callback for sort button'''
        self.sort_reverse = not self.sort_reverse
        if self.sort_reverse:
            self.file_sort_btn.text = u'⬇ Name'
        else:
            self.file_sort_btn.text = u'⬆ Name'

        self.populate_files(self.cur_dir)

    def populate_bookmarks(self):
        '''Fill Bookamrks List'''
        con = Icon(self,
                   size_hint_weight=EXPAND_BOTH,
                   size_hint_align=FILL_BOTH)
        con.standard_set('document-open-recent')
        con.show()
        cur_item = self.bookmarks_lst.item_append('Recent', icon=con)
        cur_item.data['path'] = 'recent:///'

        cur_item = self.bookmarks_lst.item_append('')
        cur_item.separator_set(True)

        con = Icon(self,
                   size_hint_weight=EXPAND_BOTH,
                   size_hint_align=FILL_BOTH)
        con.standard_set('user-home')
        con.show()

        cur_item = self.bookmarks_lst.item_append('Home', icon=con)
        cur_item.data['path'] = self.home

        if os.path.isdir(self.desktop):
            con = Icon(self,
                       size_hint_weight=EXPAND_BOTH,
                       size_hint_align=FILL_BOTH)
            con.standard_set('user-desktop')
            con.show()

            cur_item = self.bookmarks_lst.item_append('Desktop', icon=con)
            cur_item.data['path'] = self.desktop

        con = Icon(self,
                   size_hint_weight=EXPAND_BOTH,
                   size_hint_align=FILL_BOTH)
        con.standard_set('drive-harddisk')
        con.show()

        cur_item = self.bookmarks_lst.item_append('Root', icon=con)
        cur_item.data['path'] = self.root

        cur_item = self.bookmarks_lst.item_append('')
        cur_item.separator_set(True)

        for url in self.get_gtk_bookmarks():
            con = Icon(self,
                       size_hint_weight=EXPAND_BOTH,
                       size_hint_align=FILL_BOTH)
            con.standard_set('folder')
            con.show()
            cur_item = self.bookmarks_lst.item_append(url.split('/')[-1],
                                                      icon=con)
            cur_item.data['path'] = url[7:]

    def populate_file(self):
        '''Add Pending File to Files list'''
        pen_file = len(self.pending_files)
        if pen_file:
            for _ in range(int(math.sqrt(pen_file))):
                path, name, is_dir = self.pending_files.popleft()
                self.pack_all(path, name, is_dir)

        # else:
        #    self._timer.freeze()

        return True

    def populate_files(self, path):
        '''Start threaded FN to get dir contents'''
        self.autocomplete_hover.hover_end()

        self.pending_files.clear()

        if path[:-1] != '/':
            path = path + '/'
        if path != self.filepath_en.text or not self.show_hidden:
            self.adding_hidden = False

            if self.cb_dir_change:
                self.cb_dir_change(path)

            del self.cur_subdirs[:]
            del self.cur_files[:]
            self.file_lst.clear()
        else:
            self.adding_hidden = True

        self.filepath_en.text = path.replace('//', '/')
        self.cur_dir = path.replace('//', '/')

        self.threaded_fn.run(self.get_dir_contents)

    def get_dir_contents(self):
        '''Add Folder contents to pending files'''
        path = self.cur_dir
        if path == 'recent://':
            self.recent = Bookmarks()
            data = list(self.recent.dict.keys())
            for cur in data:
                self.pending_files.append([path, cur, False])
            return
        data = os.listdir(str(path))

        sorted_data = []
        for name in data:
            is_dir = os.path.isdir(f'{path}{name}')
            if is_dir:
                self.cur_subdirs.append(name)
                if self.sort_reverse:
                    sorted_data.append([1, name])
                else:
                    sorted_data.append([0, name])
            else:
                self.cur_files.append(name)
                if self.sort_reverse:
                    sorted_data.append([0, name])
                else:
                    sorted_data.append([1, name])

        sorted_data.sort(reverse=self.sort_reverse)
        for cur in sorted_data:
            name = cur[1]
            is_dir = cur[0] if self.sort_reverse else not cur[0]
            if self.adding_hidden and name[0] == '.':
                self.pending_files.append([path, name, is_dir])
            elif (name[0] != '.' or
                  self.show_hidden) and not self.adding_hidden:
                self.pending_files.append([path, name, is_dir])

    def pack_all(self, path, name, is_dir):
        '''Append to genlist'''
        if is_dir:
            gen_lst_it = GenlistItem(item_data={
                'type': 'dir',
                'path': path,
                'd': name
            },
                                     item_class=DIRGLIC,
                                     func=self.list_it_selected)
        else:
            gen_lst_it = GenlistItem(item_data={
                'type': 'file',
                'path': path,
                'd': name
            },
                                     item_class=FILEGLIC,
                                     func=self.list_it_selected)
        gen_lst_it.append_to(self.file_lst)

    def cb_file_lst(self, obj, item=None, event=None):
        '''File list double clicked callback'''
        if item.data['type'] == 'dir':
            self.add_btn.disabled = True
            self.rm_btn.disabled = True
            self.populate_files(item.data['path'] + item.text)
        else:
            self.cb_action_btn(self.action_btn)

    # pylint: disable=no-self-use
    def get_gtk_bookmarks(self):
        '''Read GTK bookmarks'''
        try:
            with open(os.path.expanduser('~/.config/gtk-3.0/bookmarks'),
                      'r') as gtk_bk:
                bks = []
                for url in gtk_bk:
                    url = url.split(' ')[0]
                    url = url.replace('%20', ' ')
                    url = url.strip()
                    bks.append(url)
                return bks
        except IOError:
            return []

    def cb_bookmarks_lst(self, obj, item=None, event=None):
        '''Bookamrk list item double clicked callback'''
        item.selected_set(False)
        self.add_btn.disabled = True
        self.rm_btn.disabled = True
        self.populate_files(item.data['path'])

    def list_it_selected(self, item, gen_lst, data):
        '''Genlist item selected'''
        if item.data['type'] == 'dir':
            self.dir_selected(item)
        else:
            self.file_selected(item.text)
            item.selected_set(False)

    def file_selected(self, cur):
        '''File was selected, update everything'''
        self.file_entry.text = cur
        self.add_btn.disabled = True
        self.rm_btn.disabled = True
        self.selected_dir = None

        # Update image preview if an image is selected
        if cur[-3:] in ['jpg', 'png', 'gif']:
            if self.filepath_en.text == 'recent://':
                self.preview.file_set(self.recent[cur])
            else:
                self.preview.file_set(f'{self.filepath_en.text}/{cur}')
            self.preview.size_hint_weight = (1.0, 0.4)
        else:
            self.preview.size_hint_weight = (0, 0)

    def dir_selected(self, btn):
        '''Folder was selected, update everything'''
        cur = btn.data['path']
        if btn == self.selected_dir:
            self.populate_files(cur)
            self.add_btn.disabled = True
        else:
            self.selected_dir = btn
            gtk_bks = self.get_gtk_bookmarks()
            to_append = f'file://{self.filepath_en.text}{self.selected_dir.text}'
            if to_append not in gtk_bks:
                self.add_btn.disabled = False
                self.rm_btn.disabled = True
            else:
                self.add_btn.disabled = True
                self.rm_btn.disabled = False

    def cb_up_btn(self, btn):
        '''Callback for dir up button'''
        cur = self.filepath_en.text.split('/')
        del cur[-1]
        del cur[-1]
        self.populate_files('/'.join(cur))

    def cb_add_btn(self, btn):
        '''Add dir button pressed'''
        safe = self.selected_dir.text.replace(' ', '%20')
        cur = f"file://{self.filepath_en.text}{safe}"

        con = Icon(self,
                   size_hint_weight=EXPAND_BOTH,
                   size_hint_align=FILL_BOTH)
        con.standard_set('gtk-directory')
        con.show()
        current = self.bookmarks_lst.item_append(self.selected_dir.text,
                                                 icon=con)
        current.data[
            'path'] = f'{self.filepath_en.text}{self.selected_dir.text}'
        self.bookmarks_lst.go()

        self.add_btn.disabled = True
        self.rm_btn.disabled = False

        with open(os.path.expanduser('~/.config/gtk-3.0/bookmarks'),
                  'a') as gtk_bk:
            gtk_bk.write(cur + ' ' + self.selected_dir.text + '\n')

    def cb_remove(self, btn):
        '''Remove button pressed callback'''
        cur = f'file://{self.filepath_en.text}{self.selected_dir.text}'
        bks = self.get_gtk_bookmarks()
        bks.remove(cur)

        with open(os.path.expanduser('~/.config/gtk-3.0/bookmarks'),
                  'w') as gtk_bk:
            for url in bks:
                name = url.split('/')[-1]
                url = url.replace(' ', '%20')
                gtk_bk.write(url + ' ' + name + '\n')

        self.bookmarks_lst.clear()
        self.populate_bookmarks()

        self.add_btn.disabled = False
        self.rm_btn.disabled = True

    def set_mode(self, mode):
        '''Set FileSelector mode: save or open'''
        self.mode = mode.lower()
        self.action_btn.text = f'{mode}  '
        self.action_ic.standard_set(f'document-{mode.lower()}')

        if self.mode != 'save':
            self.create_dir_btn.hide()
        else:
            self.create_dir_btn.show()

    def cb_events(self, obj, src, event_type, event):
        '''Keyboard event callback: Watch key presses for ctrl+l to select entry'''
        if event.modifier_is_set(
                'Control') and event_type == EVAS_CALLBACK_KEY_DOWN:
            if event.key.lower() == 'l':
                self.filepath_en.focus_set(True)
                self.filepath_en.cursor_end_set()

    def cb_toggle_hidden(self, btn):
        '''Toggle hidden files and folders'''
        self.show_hidden = not self.show_hidden
        self.populate_files(self.filepath_en.text)

    def callback_cancel_add(self, callback):
        '''Add a cancel callback'''
        self.cancel_cb = callback

    def callback_activated_add(self, callback):
        '''Add an action callback'''
        self.action_cb = callback

    def callback_directory_open_add(self, callback):
        '''Add an open folder callback'''
        self.cb_dir_change = callback

    def cb_cancel_btn(self, btn):
        '''Cancel button callback'''
        if self.cancel_cb:
            self.cancel_cb(self)

    def cb_action_btn(self, btn):
        '''Action button callback'''
        if self.action_cb:
            if not self.dir_only and self.file_entry.text:
                if self.filepath_en.text == 'recent://':
                    self.action_cb(self, self.recent[self.file_entry.text])
                else:
                    self.action_cb(
                        self, f'{self.filepath_en.text}{self.file_entry.text}')
            elif self.dir_only:
                self.action_cb(self, f'{self.filepath_en.text}')

    def cb_file_entry(self, entry):
        '''File entry callback'''
        typed = entry.text.split('/')[-1]
        new_lst = []
        self.focused_entry = entry
        if entry == self.filepath_en:
            for name in self.cur_subdirs:
                if typed in name:
                    if len(new_lst) < 10:
                        new_lst.append(name)
                    else:
                        break
        else:
            for name in self.cur_files:
                if typed in name:
                    if len(new_lst) < 10:
                        new_lst.append(name)
                    else:
                        break

        if self.autocomplete_hover.expanded_get():
            self.autocomplete_hover.hover_end()
        self.autocomplete_hover.clear()

        for name in new_lst:
            self.autocomplete_hover.item_add(name)

        self.autocomplete_hover.hover_begin()
        self.focused_entry.focus = True

    def cb_hover(self, hov, item):
        '''Autocomplete Hover item selected callback'''
        hov.hover_end()
        if self.focused_entry == self.filepath_en:
            self.populate_files(f'{self.cur_dir}{item.text}')
            self.filepath_en.cursor_end_set()
        else:
            self.file_entry.text = item.text
            self.file_entry.cursor_end_set()

    def cb_filepath_en(self, entry):
        '''File Path Entry callback'''
        if os.path.isdir(entry.text) and entry.text != self.cur_dir:
            self.populate_files(entry.text)
            self.filepath_en.cursor_end_set()
        else:
            # entry.text = self.cur_dir
            pass

    def selected_get(self):
        '''Return selected'''
        return f'{self.filepath_en.text}{self.file_entry.text}'
示例#16
0
class MainWin(StandardWindow):
    def __init__(self, app):
        self.app = app
        self.prog_popup = None

        # the window
        StandardWindow.__init__(self, 'epack', 'Epack')
        self.autodel_set(True)
        self.callback_delete_request_add(lambda o: self.app.exit())

        ### main table (inside a padding frame)
        frame = Frame(self,
                      style='pad_small',
                      size_hint_weight=EXPAND_BOTH,
                      size_hint_align=FILL_BOTH)
        self.resize_object_add(frame)
        frame.content = table = Table(frame)
        frame.show()

        ### header horiz box
        self.header_box = Box(self,
                              horizontal=True,
                              size_hint_weight=EXPAND_HORIZ,
                              size_hint_align=FILL_HORIZ)
        table.pack(self.header_box, 0, 0, 3, 1)
        self.header_box.show()

        # genlist with archive content (inside a small padding frame)
        frame = Frame(self,
                      style='pad_small',
                      size_hint_weight=EXPAND_BOTH,
                      size_hint_align=FILL_BOTH)
        table.pack(frame, 0, 1, 3, 1)

        self.file_itc = GenlistItemClass(item_style="no_icon",
                                         text_get_func=self._gl_file_text_get)
        self.fold_itc = GenlistItemClass(
            item_style="one_icon",
            text_get_func=self._gl_fold_text_get,
            content_get_func=self._gl_fold_icon_get)
        self.file_list = Genlist(frame, homogeneous=True)
        self.file_list.callback_expand_request_add(self._gl_expand_req_cb)
        self.file_list.callback_contract_request_add(self._gl_contract_req_cb)
        self.file_list.callback_expanded_add(self._gl_expanded_cb)
        self.file_list.callback_contracted_add(self._gl_contracted_cb)
        frame.content = self.file_list
        frame.show()

        # rect hack to force a min size on the genlist
        r = evas.Rectangle(table.evas,
                           size_hint_min=(250, 250),
                           size_hint_weight=EXPAND_BOTH,
                           size_hint_align=FILL_BOTH)
        table.pack(r, 0, 1, 3, 1)

        # FileSelectorButton
        self.fsb = DestinationButton(app, self)
        table.pack(self.fsb, 0, 2, 3, 1)
        self.fsb.show()

        sep = Separator(table, horizontal=True, size_hint_weight=EXPAND_HORIZ)
        table.pack(sep, 0, 3, 3, 1)
        sep.show()

        # extract button
        self.extract_btn = Button(table, text=_('Extract'))
        self.extract_btn.callback_clicked_add(self.extract_btn_cb)
        table.pack(self.extract_btn, 0, 4, 1, 2)
        self.extract_btn.show()

        sep = Separator(table, horizontal=False)
        table.pack(sep, 1, 4, 1, 2)
        sep.show()

        # delete-archive checkbox
        self.del_chk = Check(table,
                             text=_('Delete archive after extraction'),
                             size_hint_weight=EXPAND_HORIZ,
                             size_hint_align=(0.0, 1.0))
        self.del_chk.callback_changed_add(self.del_check_cb)
        table.pack(self.del_chk, 2, 4, 1, 1)
        self.del_chk.show()

        # create-archive-folder checkbox
        self.create_folder_chk = Check(table,
                                       text=_('Create archive folder'),
                                       size_hint_weight=EXPAND_HORIZ,
                                       size_hint_align=(0.0, 1.0))
        table.pack(self.create_folder_chk, 2, 5, 1, 1)
        self.create_folder_chk.callback_changed_add(
            lambda c: self.update_fsb_label())
        self.create_folder_chk.show()

        # set the correct ui state
        self.update_ui()

        # show the window
        self.show()

    def del_check_cb(self, check):
        self.app.delete_after_extract = check.state

    def update_ui(self, listing_in_progress=False):
        box = self.header_box
        box.clear()
        ui_disabled = True

        # file listing in progress
        if listing_in_progress:
            spin = Progressbar(box, style='wheel', pulse_mode=True)
            spin.pulse(True)
            spin.show()
            box.pack_end(spin)

            lb = Label(box,
                       text=_('Reading archive, please wait...'),
                       size_hint_weight=EXPAND_HORIZ,
                       size_hint_align=(0.0, 0.5))
            lb.show()
            box.pack_end(lb)

        # or header button
        else:
            if self.app.file_name is None:
                txt = _('No archive loaded, click to choose a file')
            else:
                ui_disabled = False
                txt = _('<b>Archive:</b> %s') % \
                      (os.path.basename(self.app.file_name))

            txt = '<align=left>%s</align>' % txt
            lb = Label(box, ellipsis=True, text=txt)
            bt = Button(box,
                        content=lb,
                        size_hint_weight=EXPAND_HORIZ,
                        size_hint_fill=FILL_HORIZ)
            bt.callback_clicked_add(lambda b: \
                        FileSelectorInwin(self, _('Choose an archive'),
                                          self._archive_selected_cb,
                                          path=os.getcwd()))
            box.pack_end(bt)
            bt.show()

        # always show the about button
        sep = Separator(box)
        box.pack_end(sep)
        sep.show()

        ic = SafeIcon(box, 'help-about', size_hint_min=(24, 24))
        ic.callback_clicked_add(lambda i: InfoWin(self))
        box.pack_end(ic)
        ic.show()

        for widget in (self.extract_btn, self.fsb, self.create_folder_chk,
                       self.del_chk):
            widget.disabled = ui_disabled

        self.update_fsb_label()

    def _archive_selected_cb(self, path):
        if os.path.isfile(path):
            self.app.load_file(path)

    def update_fsb_label(self):
        if self.create_folder_chk.state is True:
            name = os.path.splitext(os.path.basename(self.app.file_name))[0]
            self.fsb.text = os.path.join(self.app.dest_folder, name)
        else:
            self.fsb.text = self.app.dest_folder or ''

    def show_error_msg(self, msg):
        pop = Popup(self, text=msg)
        pop.part_text_set('title,text', _('Error'))

        btn = Button(self, text=_('Continue'))
        btn.callback_clicked_add(lambda b: pop.delete())
        pop.part_content_set('button1', btn)

        btn = Button(self, text=_('Exit'))
        btn.callback_clicked_add(lambda b: self.app.exit())
        pop.part_content_set('button2', btn)

        pop.show()

    def tree_populate(self, file_list=None, parent=None):
        if file_list is not None:
            self.file_list.clear()
            self._file_list = file_list

        if parent is None:
            prefix = None  # items must match this prefix to be listed
            fscount = 0  # folder must have this number of slashes
            dscount = 1  # files must have this number of slashes
        else:
            prefix = parent.data[:-1]
            fscount = prefix.count('/') + 1
            dscount = fscount + 1

        files = []
        for path in self._file_list:
            if prefix and not path.startswith(prefix):
                continue

            if path.endswith('/'):
                if path.count('/') == dscount:
                    self.file_list.item_append(self.fold_itc,
                                               path,
                                               parent,
                                               flags=ELM_GENLIST_ITEM_TREE)
            else:
                if path.count('/') == fscount:
                    files.append(path)

        for path in files:
            self.file_list.item_append(self.file_itc, path, parent)

    def _gl_fold_text_get(self, obj, part, item_data):
        return item_data[:-1].split('/')[-1]

    def _gl_fold_icon_get(self, obj, part, item_data):
        return SafeIcon(obj, 'folder')

    def _gl_file_text_get(self, obj, part, item_data):
        return item_data.split('/')[-1]

    def _gl_expand_req_cb(self, gl, item):
        item.expanded = True

    def _gl_expanded_cb(self, gl, item):
        self.tree_populate(None, item)

    def _gl_contract_req_cb(self, gl, item):
        item.expanded = False

    def _gl_contracted_cb(self, gl, item):
        item.subitems_clear()

    def extract_btn_cb(self, btn):
        self.prog_popup = None
        self.app.dest_folder = self.fsb.text
        self.app.extract_archive()

    def build_prog_popup(self):
        pp = Popup(self)
        pp.part_text_set('title,text', _('Extracting files, please wait...'))
        pp.show()

        vbox = Box(self)
        pp.part_content_set('default', vbox)
        vbox.show()

        lb = Label(self,
                   ellipsis=True,
                   size_hint_weight=EXPAND_HORIZ,
                   size_hint_align=FILL_HORIZ)
        vbox.pack_end(lb)
        lb.show()

        pb = Progressbar(pp,
                         size_hint_weight=EXPAND_HORIZ,
                         size_hint_align=FILL_HORIZ)
        vbox.pack_end(pb)
        pb.show()

        bt = Button(pp, text=_('Cancel'))
        bt.callback_clicked_add(lambda b: self.app.abort_operation())
        pp.part_content_set('button1', bt)

        self.prog_pbar = pb
        self.prog_label = lb
        self.prog_popup = pp

    def extract_progress(self, progress, cur_name):
        if self.prog_popup is None:
            self.build_prog_popup()

        self.prog_pbar.value = progress
        self.prog_label.text = cur_name

    def extract_finished(self):
        if self.prog_popup:
            self.prog_popup.delete()
            self.prog_popup = None

    def _open_fm_and_exit_cb(self, bt):
        utils.xdg_open(self.app.dest_folder)
        self.app.exit()

    def _open_term_and_exit_cb(self, bt):
        utils.open_in_terminal(self.app.dest_folder)
        self.app.exit()

    def ask_what_to_do_next(self):
        pop = Popup(self)
        pop.part_text_set('title,text', _('Extract completed'))

        box = Box(pop)
        pop.content = box
        box.show()

        lb = Label(pop, text=_('What to do next?'), size_hint_align=FILL_HORIZ)
        box.pack_end(lb)
        lb.show()

        btn = Button(pop,
                     text=_('Open Filemanager'),
                     size_hint_align=FILL_HORIZ)
        btn.callback_clicked_add(self._open_fm_and_exit_cb)
        box.pack_end(btn)
        btn.show()

        btn = Button(pop, text=_('Open Terminal'), size_hint_align=FILL_HORIZ)
        btn.callback_clicked_add(self._open_term_and_exit_cb)
        box.pack_end(btn)
        btn.show()

        btn = Button(pop,
                     text=_('Close this popup'),
                     size_hint_align=FILL_HORIZ)
        btn.callback_clicked_add(lambda b: pop.delete())
        box.pack_end(btn)
        btn.show()

        btn = Button(pop, text=_('Exit'), size_hint_align=FILL_HORIZ)
        btn.callback_clicked_add(lambda b: self.app.exit())
        box.pack_end(btn)
        btn.show()

        pop.show()
def dnd_genlist_user_anim_clicked(obj, item=None):
    win = StandardWindow("dnd-genlist-user-anim",
                         "DnD-Genlist-User-Anim",
                         autodel=True,
                         size=(680, 800))

    bxx = Box(win, horizontal=True, size_hint_weight=EXPAND_BOTH)
    win.resize_object_add(bxx)
    bxx.show()

    for j in range(2):
        gl = Genlist(win,
                     multi_select=True,
                     size_hint_weight=EXPAND_BOTH,
                     size_hint_align=FILL_BOTH)

        # START Drag and Drop handling
        win.callback_delete_request_add(win_del, gl)
        gl.drop_item_container_add(ELM_SEL_FORMAT_TARGETS,
                                   gl_item_getcb,
                                   dropcb=gl_dropcb)

        gl.drag_item_container_add(ANIM_TIME, DRAG_TIMEOUT, gl_item_getcb,
                                   gl_data_getcb)

        # We add mouse-down, up callbacks to start/stop drag animation
        gl.event_callback_add(EVAS_CALLBACK_MOUSE_DOWN, gl_obj_mouse_down, gl)
        # END Drag and Drop handling

        # FIXME: This causes genlist to resize the horiz axis very slowly :(
        # Reenable this and resize the window horizontally, then try to resize it back
        #elm_genlist_mode_set(gl, ELM_LIST_LIMIT)
        bxx.pack_end(gl)
        gl.show()

        for i in range(20):
            gl.item_append(itc1, img[i % 9], flags=ELM_GENLIST_ITEM_NONE)

    win.show()
    def __init__(self,
                 parent_widget,
                 *args,
                 default_path='',
                 default_populate=True,
                 **kwargs):
        Box.__init__(self, parent_widget, *args, **kwargs)

        self.cancel_cb = None
        self.action_cb = None
        self.cb_dir_change = None

        self.threaded_fn = ThreadedFunction()
        # pylint: disable=c-extension-no-member
        self._timer = ecore.Timer(0.02, self.populate_file)

        # Watch key presses for ctrl+l to select entry
        parent_widget.elm_event_callback_add(self.cb_events)

        self.selected_dir = None
        self.show_hidden = False
        self.cur_dir = None
        self.focused_entry = None
        self.dir_only = False
        self.sort_reverse = False
        self.adding_hidden = False
        self.pending_files = deque()
        self.cur_subdirs = []
        self.cur_files = []

        # Mode should be 'save' or 'load'
        self.mode = 'save'

        self.home = os.path.expanduser('~')

        desktop = os.environ.get('XDG_DESKTOP_DIR')
        if desktop:
            self.desktop = desktop
        else:
            self.desktop = self.home + '/Desktop'

        self.root = '/'

        # Label+Entry for File Name
        self.filename_bx = Box(self,
                               size_hint_weight=EXPAND_HORIZ,
                               size_hint_align=FILL_HORIZ)
        self.filename_bx.horizontal = True
        self.filename_bx.show()

        file_label = Label(self,
                           size_hint_weight=(0.15, EVAS_HINT_EXPAND),
                           size_hint_align=FILL_HORIZ)
        file_label.text = 'Filename:'
        file_label.show()

        self.file_entry = Entry(self,
                                size_hint_weight=EXPAND_BOTH,
                                size_hint_align=FILL_HORIZ)
        self.file_entry.single_line_set(True)
        self.file_entry.scrollable_set(True)
        self.file_entry.callback_changed_user_add(self.cb_file_entry)
        self.file_entry.show()

        self.filename_bx.pack_end(file_label)
        self.filename_bx.pack_end(self.file_entry)

        sep = Separator(self,
                        size_hint_weight=EXPAND_HORIZ,
                        size_hint_align=FILL_HORIZ)
        sep.horizontal_set(True)
        sep.show()

        # Label+Entry for File Path
        self.filepath_bx = Box(self,
                               size_hint_weight=EXPAND_HORIZ,
                               size_hint_align=FILL_HORIZ)
        self.filepath_bx.horizontal = True
        self.filepath_bx.show()

        file_label = Label(self,
                           size_hint_weight=(0.15, EVAS_HINT_EXPAND),
                           size_hint_align=FILL_HORIZ)
        file_label.text = 'Current Folder:'
        file_label.show()

        self.filepath_en = Entry(self,
                                 size_hint_weight=EXPAND_BOTH,
                                 size_hint_align=FILL_HORIZ)
        self.filepath_en.single_line_set(True)
        self.filepath_en.scrollable_set(True)
        self.filepath_en.callback_changed_user_add(self.cb_file_entry)
        self.filepath_en.callback_unfocused_add(self.cb_filepath_en)
        self.filepath_en.callback_activated_add(self.cb_filepath_en)
        # Wish this worked. Doesn't seem to do anything
        # Working now EFL 1.22 ?
        self.filepath_en.input_hint_set(ELM_INPUT_HINT_AUTO_COMPLETE)

        if default_path and os.path.isdir(default_path):
            start = default_path
        else:
            start = self.home
        self.filepath_en.show()

        self.filepath_bx.pack_end(file_label)
        self.filepath_bx.pack_end(self.filepath_en)

        self.autocomplete_hover = Hoversel(self, hover_parent=self)
        self.autocomplete_hover.callback_selected_add(self.cb_hover)
        self.autocomplete_hover.show()

        self.file_selector_bx = Panes(self,
                                      content_left_size=0.3,
                                      size_hint_weight=EXPAND_BOTH,
                                      size_hint_align=FILL_BOTH)
        self.file_selector_bx.show()
        # Bookmarks Box contains:
        #
        # - Button - Up Arrow
        # - List - Home/Desktop/Root/GTK bookmarks
        # - Box
        # -- Button - Add Bookmark
        # -- Button - Remove Bookmark
        self.bookmark_bx = Box(self,
                               size_hint_weight=(0.3, EVAS_HINT_EXPAND),
                               size_hint_align=FILL_BOTH)
        self.bookmark_bx.show()

        up_ic = Icon(self,
                     size_hint_weight=EXPAND_BOTH,
                     size_hint_align=FILL_BOTH,
                     order_lookup=ELM_ICON_LOOKUP_THEME)
        up_ic.standard_set('arrow-up')
        up_ic.show()

        self.up_btn = Button(self,
                             size_hint_weight=EXPAND_HORIZ,
                             size_hint_align=FILL_HORIZ,
                             content=up_ic)
        self.up_btn.text = 'Up'
        self.up_btn.callback_pressed_add(self.cb_up_btn)
        self.up_btn.show()

        self.bookmarks_lst = List(self,
                                  size_hint_weight=EXPAND_BOTH,
                                  size_hint_align=FILL_BOTH)
        self.bookmarks_lst.callback_activated_add(self.cb_bookmarks_lst)
        self.bookmarks_lst.show()

        self.bookmark_modbox = Box(self,
                                   size_hint_weight=EXPAND_HORIZ,
                                   size_hint_align=FILL_HORIZ)
        self.bookmark_modbox.horizontal = True
        self.bookmark_modbox.show()

        con = Icon(self,
                   size_hint_weight=EXPAND_BOTH,
                   size_hint_align=FILL_BOTH)
        con.standard_set('list-add')
        con.show()

        self.add_btn = Button(self,
                              size_hint_weight=EXPAND_HORIZ,
                              size_hint_align=FILL_HORIZ,
                              content=con)
        self.add_btn.callback_pressed_add(self.cb_add_btn)
        self.add_btn.disabled = True
        self.add_btn.show()

        con = Icon(self,
                   size_hint_weight=EXPAND_BOTH,
                   size_hint_align=FILL_BOTH)
        con.standard_set('list-remove')
        con.show()

        self.rm_btn = Button(self,
                             size_hint_weight=EXPAND_HORIZ,
                             size_hint_align=FILL_HORIZ,
                             content=con)
        self.rm_btn.callback_pressed_add(self.cb_remove)
        self.rm_btn.disabled = True
        self.rm_btn.show()

        self.bookmark_modbox.pack_end(self.add_btn)
        self.bookmark_modbox.pack_end(self.rm_btn)

        self.bookmark_bx.pack_end(self.up_btn)
        self.bookmark_bx.pack_end(self.bookmarks_lst)
        self.bookmark_bx.pack_end(self.bookmark_modbox)

        # Directory List
        self.file_list_bx = Box(self,
                                size_hint_weight=EXPAND_BOTH,
                                size_hint_align=FILL_BOTH)
        self.file_list_bx.show()

        self.file_sort_btn = Button(self,
                                    size_hint_weight=EXPAND_HORIZ,
                                    size_hint_align=FILL_HORIZ)
        self.file_sort_btn.text = u'⬆ Name'
        self.file_sort_btn.callback_pressed_add(self.cb_sort)
        self.file_sort_btn.show()

        self.file_lst = Genlist(self,
                                size_hint_weight=EXPAND_BOTH,
                                size_hint_align=FILL_BOTH,
                                homogeneous=True,
                                mode=ELM_LIST_COMPRESS)
        self.file_lst.callback_activated_add(self.cb_file_lst)
        self.file_lst.show()

        self.preview = preview = Image(self)
        preview.size_hint_align = FILL_BOTH
        preview.show()

        self.file_list_bx.pack_end(self.file_sort_btn)
        self.file_list_bx.pack_end(self.file_lst)
        self.file_list_bx.pack_end(self.preview)

        self.file_selector_bx.part_content_set('left', self.bookmark_bx)
        self.file_selector_bx.part_content_set('right', self.file_list_bx)

        # Cancel and Save/Open button
        self.button_bx = Box(self,
                             size_hint_weight=EXPAND_HORIZ,
                             size_hint_align=(1.0, 0.5))
        self.button_bx.horizontal = True
        self.button_bx.show()

        self.action_ic = Icon(self,
                              size_hint_weight=EXPAND_BOTH,
                              size_hint_align=FILL_BOTH)
        self.action_ic.standard_set('document-save')
        self.action_ic.show()

        self.action_btn = Button(self,
                                 size_hint_weight=(0.0, 0.0),
                                 size_hint_align=(1.0, 0.5),
                                 content=self.action_ic)
        self.action_btn.text = 'Save  '
        self.action_btn.callback_pressed_add(self.cb_action_btn)
        self.action_btn.show()

        cancel_ic = Icon(self,
                         size_hint_weight=EXPAND_BOTH,
                         size_hint_align=FILL_BOTH)
        cancel_ic.standard_set('application-exit')
        cancel_ic.show()

        self.cancel_btn = Button(self,
                                 size_hint_weight=(0.0, 0.0),
                                 size_hint_align=(1.0, 0.5),
                                 content=cancel_ic)
        self.cancel_btn.text = 'Cancel  '
        self.cancel_btn.callback_pressed_add(self.cb_cancel_btn)
        self.cancel_btn.show()

        con = Icon(self,
                   size_hint_weight=EXPAND_BOTH,
                   size_hint_align=FILL_BOTH)
        con.standard_set('edit-find')
        con.show()

        self.hidden_btn = Button(self,
                                 size_hint_weight=(0.0, 0.0),
                                 size_hint_align=(1.0, 0.5),
                                 content=con)
        self.hidden_btn.text = 'Toggle Hidden  '
        self.hidden_btn.callback_pressed_add(self.cb_toggle_hidden)
        self.hidden_btn.show()

        con = Icon(self,
                   size_hint_weight=EXPAND_BOTH,
                   size_hint_align=FILL_BOTH)
        con.standard_set('folder-new')
        con.show()

        self.create_dir_btn = Button(self,
                                     size_hint_weight=(0.0, 0.0),
                                     size_hint_align=(1.0, 0.5),
                                     content=con)
        self.create_dir_btn.text = 'Create Folder  '
        self.create_dir_btn.callback_pressed_add(self.cb_create_dir)
        self.create_dir_btn.show()

        self.button_bx.pack_end(self.create_dir_btn)
        self.button_bx.pack_end(self.hidden_btn)
        self.button_bx.pack_end(self.cancel_btn)
        self.button_bx.pack_end(self.action_btn)

        self.pack_end(self.filename_bx)
        self.pack_end(sep)
        self.pack_end(self.filepath_bx)
        self.pack_end(self.autocomplete_hover)
        self.pack_end(self.file_selector_bx)
        self.pack_end(self.button_bx)

        self.populate_bookmarks()

        self.create_popup = Popup(self)
        self.create_popup.part_text_set('title,text', 'Create Folder:')

        self.create_en = Entry(self,
                               size_hint_weight=EXPAND_HORIZ,
                               size_hint_align=FILL_HORIZ)
        self.create_en.single_line_set(True)
        self.create_en.scrollable_set(True)
        self.create_en.show()

        self.create_popup.content = self.create_en

        bt0 = Button(self, text='Create')
        bt0.callback_clicked_add(self.cb_create_folder)
        self.create_popup.part_content_set('button1', bt0)
        bt1 = Button(self, text='Cancel')
        bt1.callback_clicked_add(self.cb_close_popup)
        self.create_popup.part_content_set('button2', bt1)

        self.recent = None  # keeps pylint happy:
        if default_populate:
            self.populate_files(start)
class FileSelector(Box):
    def __init__(self,
                 parent_widget,
                 defaultPath="",
                 defaultPopulate=True,
                 *args,
                 **kwargs):
        Box.__init__(self, parent_widget, *args, **kwargs)

        self.cancelCallback = None
        self.actionCallback = None
        self.directoryChangeCallback = None

        self.threadedFunction = ThreadedFunction()
        self._timer = ecore.Timer(0.02, self.populateFile)

        #Watch key presses for ctrl+l to select entry
        parent_widget.elm_event_callback_add(self.eventsCb)

        self.selectedFolder = None
        self.showHidden = False
        self.currentDirectory = None
        self.focusedEntry = None
        self.folderOnly = False
        self.sortReverse = False
        self.addingHidden = False
        self.pendingFiles = deque()
        self.currentSubFolders = []
        self.currentFiles = []

        #Mode should be "save" or "load"
        self.mode = "save"

        self.home = os.path.expanduser("~")
        self.root = "/"

        #Label+Entry for File Name
        self.filenameBox = Box(self,
                               size_hint_weight=EXPAND_HORIZ,
                               size_hint_align=FILL_HORIZ)
        self.filenameBox.horizontal = True
        self.filenameBox.show()

        fileLabel = Label(self,
                          size_hint_weight=(0.15, EVAS_HINT_EXPAND),
                          size_hint_align=FILL_HORIZ)
        fileLabel.text = "Filename:"
        fileLabel.show()

        self.fileEntry = Entry(self,
                               size_hint_weight=EXPAND_BOTH,
                               size_hint_align=FILL_HORIZ)
        self.fileEntry.single_line_set(True)
        self.fileEntry.scrollable_set(True)
        self.fileEntry.callback_changed_user_add(self.fileEntryChanged)
        self.fileEntry.show()

        self.filenameBox.pack_end(fileLabel)
        self.filenameBox.pack_end(self.fileEntry)

        sep = Separator(self,
                        size_hint_weight=EXPAND_HORIZ,
                        size_hint_align=FILL_HORIZ)
        sep.horizontal_set(True)
        sep.show()

        #Label+Entry for File Path
        self.filepathBox = Box(self,
                               size_hint_weight=EXPAND_HORIZ,
                               size_hint_align=FILL_HORIZ)
        self.filepathBox.horizontal = True
        self.filepathBox.show()

        fileLabel = Label(self,
                          size_hint_weight=(0.15, EVAS_HINT_EXPAND),
                          size_hint_align=FILL_HORIZ)
        fileLabel.text = "Current Folder:"
        fileLabel.show()

        self.filepathEntry = Entry(self,
                                   size_hint_weight=EXPAND_BOTH,
                                   size_hint_align=FILL_HORIZ)
        self.filepathEntry.single_line_set(True)
        self.filepathEntry.scrollable_set(True)
        self.filepathEntry.callback_changed_user_add(self.fileEntryChanged)
        self.filepathEntry.callback_unfocused_add(self.filepathEditDone)
        self.filepathEntry.callback_activated_add(self.filepathEditDone)
        #Wish this worked. Doesn't seem to do anything
        #self.filepathEntry.input_hint_set(ELM_INPUT_HINT_AUTO_COMPLETE)

        if defaultPath and os.path.isdir(defaultPath):
            startPath = defaultPath
        else:
            startPath = self.home
        self.filepathEntry.show()

        self.filepathBox.pack_end(fileLabel)
        self.filepathBox.pack_end(self.filepathEntry)

        self.autocompleteHover = Hoversel(self, hover_parent=self)
        self.autocompleteHover.callback_selected_add(self.autocompleteSelected)
        #self.autocompleteHover.show()

        self.fileSelectorBox = Panes(self,
                                     content_left_size=0.3,
                                     size_hint_weight=EXPAND_BOTH,
                                     size_hint_align=FILL_BOTH)
        self.fileSelectorBox.show()
        """Bookmarks Box contains:

            - Button - Up Arrow
            - List - Home/Root/GTK bookmarks
            - Box
            -- Button - Add Bookmark
            -- Button - Remove Bookmark"""
        self.bookmarkBox = Box(self,
                               size_hint_weight=(0.3, EVAS_HINT_EXPAND),
                               size_hint_align=FILL_BOTH)
        self.bookmarkBox.show()

        upIcon = Icon(self,
                      size_hint_weight=EXPAND_BOTH,
                      size_hint_align=FILL_BOTH)
        upIcon.standard_set("go-up")
        upIcon.show()

        self.upButton = Button(self,
                               size_hint_weight=EXPAND_HORIZ,
                               size_hint_align=FILL_HORIZ,
                               content=upIcon)
        self.upButton.text = "Up"
        self.upButton.callback_pressed_add(self.upButtonPressed)
        self.upButton.show()

        self.bookmarksList = List(self,
                                  size_hint_weight=EXPAND_BOTH,
                                  size_hint_align=FILL_BOTH)
        self.bookmarksList.callback_activated_add(self.bookmarkDoubleClicked)
        self.bookmarksList.show()

        self.bookmarkModBox = Box(self,
                                  size_hint_weight=EXPAND_HORIZ,
                                  size_hint_align=FILL_HORIZ)
        self.bookmarkModBox.horizontal = True
        self.bookmarkModBox.show()

        con = Icon(self,
                   size_hint_weight=EXPAND_BOTH,
                   size_hint_align=FILL_BOTH)
        con.standard_set("add")
        con.show()

        self.addButton = Button(self,
                                size_hint_weight=EXPAND_HORIZ,
                                size_hint_align=FILL_HORIZ,
                                content=con)
        self.addButton.callback_pressed_add(self.addButtonPressed)
        self.addButton.disabled = True
        self.addButton.show()

        con = Icon(self,
                   size_hint_weight=EXPAND_BOTH,
                   size_hint_align=FILL_BOTH)
        con.standard_set("remove")
        con.show()

        self.removeButton = Button(self,
                                   size_hint_weight=EXPAND_HORIZ,
                                   size_hint_align=FILL_HORIZ,
                                   content=con)
        self.removeButton.callback_pressed_add(self.removeButtonPressed)
        self.removeButton.disabled = True
        self.removeButton.show()

        self.bookmarkModBox.pack_end(self.addButton)
        self.bookmarkModBox.pack_end(self.removeButton)

        self.bookmarkBox.pack_end(self.upButton)
        self.bookmarkBox.pack_end(self.bookmarksList)
        self.bookmarkBox.pack_end(self.bookmarkModBox)

        #Directory List
        self.fileListBox = Box(self,
                               size_hint_weight=EXPAND_BOTH,
                               size_hint_align=FILL_BOTH)
        self.fileListBox.show()

        self.fileSortButton = Button(self,
                                     size_hint_weight=EXPAND_HORIZ,
                                     size_hint_align=FILL_HORIZ)
        self.fileSortButton.text = u"⬆ Name"
        self.fileSortButton.callback_pressed_add(self.sortData)
        self.fileSortButton.show()

        self.fileList = Genlist(self,
                                size_hint_weight=EXPAND_BOTH,
                                size_hint_align=FILL_BOTH,
                                homogeneous=True,
                                mode=ELM_LIST_COMPRESS)
        self.fileList.callback_activated_add(self.fileDoubleClicked)
        self.fileList.show()

        self.previewImage = previewImage = Image(self)
        #previewImage.size_hint_weight = EXPAND_BOTH
        previewImage.size_hint_align = FILL_BOTH
        previewImage.show()

        self.fileListBox.pack_end(self.fileSortButton)
        self.fileListBox.pack_end(self.fileList)
        self.fileListBox.pack_end(self.previewImage)

        self.fileSelectorBox.part_content_set("left", self.bookmarkBox)
        self.fileSelectorBox.part_content_set("right", self.fileListBox)

        #Cancel and Save/Open button
        self.buttonBox = Box(self,
                             size_hint_weight=EXPAND_HORIZ,
                             size_hint_align=(1.0, 0.5))
        self.buttonBox.horizontal = True
        self.buttonBox.show()

        self.actionIcon = Icon(self,
                               size_hint_weight=EXPAND_BOTH,
                               size_hint_align=FILL_BOTH)
        self.actionIcon.standard_set("document-save")
        self.actionIcon.show()

        self.actionButton = Button(self,
                                   size_hint_weight=(0.0, 0.0),
                                   size_hint_align=(1.0, 0.5),
                                   content=self.actionIcon)
        self.actionButton.text = "Save  "
        self.actionButton.callback_pressed_add(self.actionButtonPressed)
        self.actionButton.show()

        cancelIcon = Icon(self,
                          size_hint_weight=EXPAND_BOTH,
                          size_hint_align=FILL_BOTH)
        cancelIcon.standard_set("dialog-cancel")
        cancelIcon.show()

        self.cancelButton = Button(self,
                                   size_hint_weight=(0.0, 0.0),
                                   size_hint_align=(1.0, 0.5),
                                   content=cancelIcon)
        self.cancelButton.text = "Cancel  "
        self.cancelButton.callback_pressed_add(self.cancelButtonPressed)
        self.cancelButton.show()

        con = Icon(self,
                   size_hint_weight=EXPAND_BOTH,
                   size_hint_align=FILL_BOTH)
        con.standard_set("gtk-find")
        con.show()

        self.toggleHiddenButton = Button(self,
                                         size_hint_weight=(0.0, 0.0),
                                         size_hint_align=(1.0, 0.5),
                                         content=con)
        self.toggleHiddenButton.text = "Toggle Hidden  "
        self.toggleHiddenButton.callback_pressed_add(
            self.toggleHiddenButtonPressed)
        self.toggleHiddenButton.show()

        con = Icon(self,
                   size_hint_weight=EXPAND_BOTH,
                   size_hint_align=FILL_BOTH)
        con.standard_set("folder-new")
        con.show()

        self.createFolderButton = Button(self,
                                         size_hint_weight=(0.0, 0.0),
                                         size_hint_align=(1.0, 0.5),
                                         content=con)
        self.createFolderButton.text = "Create Folder  "
        self.createFolderButton.callback_pressed_add(
            self.createFolderButtonPressed)
        self.createFolderButton.show()

        self.buttonBox.pack_end(self.createFolderButton)
        self.buttonBox.pack_end(self.toggleHiddenButton)
        self.buttonBox.pack_end(self.cancelButton)
        self.buttonBox.pack_end(self.actionButton)

        self.pack_end(self.filenameBox)
        self.pack_end(sep)
        self.pack_end(self.filepathBox)
        self.pack_end(self.autocompleteHover)
        self.pack_end(self.fileSelectorBox)
        self.pack_end(self.buttonBox)

        self.populateBookmarks()

        self.createPopup = Popup(self)
        self.createPopup.part_text_set("title,text", "Create Folder:")

        self.createEn = en = Entry(self,
                                   size_hint_weight=EXPAND_HORIZ,
                                   size_hint_align=FILL_HORIZ)
        en.single_line_set(True)
        en.scrollable_set(True)
        en.show()

        self.createPopup.content = en

        bt = Button(self, text="Create")
        bt.callback_clicked_add(self.createFolder)
        self.createPopup.part_content_set("button1", bt)

        bt2 = Button(self, text="Cancel")
        bt2.callback_clicked_add(self.closePopup)
        self.createPopup.part_content_set("button2", bt2)

        if defaultPopulate:
            self.populateFiles(startPath)

    def folderOnlySet(self, ourValue):
        self.folderOnly = ourValue

        if not self.folderOnly:
            self.filenameBox.show()
        else:
            self.filenameBox.hide()

    def createFolder(self, obj):
        newDir = "%s%s" % (self.currentDirectory, self.createEn.text)
        os.makedirs(newDir)
        self.closePopup()
        self.populateFiles(self.currentDirectory)

    def createFolderButtonPressed(self, obj):
        self.createEn.text = ""
        self.createPopup.show()
        self.createEn.select_all()

    def closePopup(self, btn=None):
        self.createPopup.hide()

    def shutdown(self, obj=None):
        self._timer.delete()
        self.threadedFunction.shutdown()

    def sortData(self, btn):
        self.sortReverse = not self.sortReverse

        if self.sortReverse:
            self.fileSortButton.text = u"⬇ Name"
        else:
            self.fileSortButton.text = u"⬆ Name"

        self.populateFiles(self.currentDirectory)

    def populateBookmarks(self):
        con = Icon(self,
                   size_hint_weight=EXPAND_BOTH,
                   size_hint_align=FILL_BOTH)
        con.standard_set("folder_home")
        con.show()

        it = self.bookmarksList.item_append("Home", icon=con)
        it.data["path"] = self.home

        con = Icon(self,
                   size_hint_weight=EXPAND_BOTH,
                   size_hint_align=FILL_BOTH)
        con.standard_set("drive-harddisk")
        con.show()

        it = self.bookmarksList.item_append("Root", icon=con)
        it.data["path"] = self.root

        it = self.bookmarksList.item_append("")
        it.separator_set(True)

        for bk in self.getGTKBookmarks():
            con = Icon(self,
                       size_hint_weight=EXPAND_BOTH,
                       size_hint_align=FILL_BOTH)
            con.standard_set("gtk-directory")
            con.show()
            it = self.bookmarksList.item_append(bk.split("/")[-1], icon=con)
            it.data["path"] = bk[7:]

    def populateFile(self):
        pen_file = len(self.pendingFiles)
        if pen_file:
            for _ in range(int(math.sqrt(pen_file))):
                ourPath, d, isDir = self.pendingFiles.popleft()
                self.packFileFolder(ourPath, d, isDir)

        #else:
        #    self._timer.freeze()

        return True

    def populateFiles(self, ourPath):
        self.autocompleteHover.hover_end()

        self.pendingFiles.clear()

        if ourPath[:-1] != "/":
            ourPath = ourPath + "/"

        if ourPath != self.filepathEntry.text or not self.showHidden:
            self.addingHidden = False

            if self.directoryChangeCallback:
                self.directoryChangeCallback(ourPath)

            del self.currentSubFolders[:]
            del self.currentFiles[:]
            self.fileList.clear()
        else:
            self.addingHidden = True

        self.filepathEntry.text = ourPath.replace("//", "/")
        self.currentDirectory = ourPath.replace("//", "/")

        self.threadedFunction.run(self.getFolderContents)
        #self._timer.thaw()

    def getFolderContents(self):
        ourPath = self.currentDirectory

        try:
            data = os.listdir(unicode(ourPath))
        except:
            data = os.listdir(str(ourPath))

        sortedData = []

        for d in data:
            isDir = os.path.isdir("%s%s" % (ourPath, d))

            if isDir:
                self.currentSubFolders.append(d)
                if self.sortReverse:
                    sortedData.append([1, d])
                else:
                    sortedData.append([0, d])
            else:
                self.currentFiles.append(d)
                if self.sortReverse:
                    sortedData.append([0, d])
                else:
                    sortedData.append([1, d])

        sortedData.sort(reverse=self.sortReverse)

        for ourFile in sortedData:
            d = ourFile[1]
            isDir = ourFile[0] if self.sortReverse else not ourFile[0]
            if self.addingHidden and d[0] == ".":
                self.pendingFiles.append([ourPath, d, isDir])
            elif (d[0] != "." or self.showHidden) and not self.addingHidden:
                self.pendingFiles.append([ourPath, d, isDir])

    def packFileFolder(self, ourPath, d, isDir):
        if isDir:
            li = GenlistItem(item_data={
                "type": "dir",
                "path": ourPath,
                "d": d
            },
                             item_class=dirglic,
                             func=self.listItemSelected)
        else:
            li = GenlistItem(item_data={
                "type": "file",
                "path": ourPath,
                "d": d
            },
                             item_class=fileglic,
                             func=self.listItemSelected)

        li.append_to(self.fileList)
        #self.fileList.go()
        #print("Adding: %s %s %s"%(ourPath, d, isDir))

    def fileDoubleClicked(self, obj, item=None, eventData=None):
        if item.data["type"] == "dir":
            self.addButton.disabled = True
            self.removeButton.disabled = True
            self.populateFiles(item.data["path"] + item.text)
        else:
            self.actionButtonPressed(self.actionButton)

    def getGTKBookmarks(self):
        try:
            with open(os.path.expanduser('~/.config/gtk-3.0/bookmarks'),
                      'r') as f:
                ourBks = []
                for x in f:
                    x = x.split(" ")[0]
                    x = x.replace("%20", " ")
                    x = x.strip()
                    ourBks.append(x)
                return ourBks
        except IOError:
            return []

    def bookmarkDoubleClicked(self, obj, item=None, eventData=None):
        item.selected_set(False)
        self.addButton.disabled = True
        self.removeButton.disabled = True
        self.populateFiles(item.data["path"])

    def listItemSelected(self, item, gl, data):
        if item.data["type"] == "dir":
            self.directorySelected(item)
        else:
            self.fileSelected(item.text)
            item.selected_set(False)

    def fileSelected(self, ourFile):
        self.fileEntry.text = ourFile
        self.addButton.disabled = True
        self.removeButton.disabled = True
        self.selectedFolder = None

        #Update image preview if an image is selected
        if ourFile[-3:] in ["jpg", "png", "gif"]:
            self.previewImage.file_set("%s/%s" %
                                       (self.filepathEntry.text, ourFile))
            self.previewImage.size_hint_weight = (1.0, 0.4)
        else:
            self.previewImage.size_hint_weight = (0, 0)

    def directorySelected(self, btn):
        ourPath = btn.data["path"]
        if btn == self.selectedFolder:
            self.populateFiles(ourPath)
            self.addButton.disabled = True
        else:
            self.selectedFolder = btn

            currentMarks = self.getGTKBookmarks()

            toAppend = "file://%s%s" % (self.filepathEntry.text,
                                        self.selectedFolder.text)

            if toAppend not in currentMarks:
                self.addButton.disabled = False
                self.removeButton.disabled = True
            else:
                self.addButton.disabled = True
                self.removeButton.disabled = False

    def upButtonPressed(self, btn):
        ourSplit = self.filepathEntry.text.split("/")
        del ourSplit[-1]
        del ourSplit[-1]
        self.populateFiles("/".join(ourSplit))

    def addButtonPressed(self, btn):
        toAppend = "file://%s%s" % (self.filepathEntry.text,
                                    self.selectedFolder.text.replace(
                                        " ", "%20"))

        con = Icon(self,
                   size_hint_weight=EXPAND_BOTH,
                   size_hint_align=FILL_BOTH)
        con.standard_set("gtk-directory")
        con.show()
        it = self.bookmarksList.item_append(self.selectedFolder.text, icon=con)
        it.data["path"] = "%s%s" % (self.filepathEntry.text,
                                    self.selectedFolder.text)

        self.bookmarksList.go()

        self.addButton.disabled = True
        self.removeButton.disabled = False

        with open(os.path.expanduser('~/.config/gtk-3.0/bookmarks'), 'a') as f:
            f.write(toAppend + " " + self.selectedFolder.text + "\n")

    def removeButtonPressed(self, btn):
        toRemove = "file://%s%s" % (self.filepathEntry.text,
                                    self.selectedFolder.text)

        bks = self.getGTKBookmarks()
        bks.remove(toRemove)

        with open(os.path.expanduser('~/.config/gtk-3.0/bookmarks'), 'w') as f:
            for b in bks:
                bName = b.split("/")[-1]
                b = b.replace(" ", "%20")
                f.write(b + " " + bName + "\n")

        self.bookmarksList.clear()
        self.populateBookmarks()

        self.addButton.disabled = False
        self.removeButton.disabled = True

    def setMode(self, ourMode):
        self.mode = ourMode.lower()

        self.actionButton.text = "%s  " % ourMode
        self.actionIcon.standard_set("document-%s" % ourMode.lower())

        if self.mode != "save":
            self.createFolderButton.hide()
        else:
            self.createFolderButton.show()

    def eventsCb(self, obj, src, event_type, event):
        if event.modifier_is_set(
                "Control") and event_type == EVAS_CALLBACK_KEY_DOWN:
            if event.key.lower() == "l":
                self.filepathEntry.focus_set(True)
                self.filepathEntry.cursor_end_set()

    def toggleHiddenButtonPressed(self, btn):
        self.showHidden = not self.showHidden
        self.populateFiles(self.filepathEntry.text)

    def toggleHidden(self):
        self.showHidden = not self.showHidden
        self.populateFiles(self.filepathEntry.text)

    def callback_cancel_add(self, cb):
        self.cancelCallback = cb

    def callback_activated_add(self, cb):
        self.actionCallback = cb

    def callback_directory_open_add(self, cb):
        self.directoryChangeCallback = cb

    def cancelButtonPressed(self, btn):
        if self.cancelCallback:
            self.cancelCallback(self)

    def actionButtonPressed(self, btn):
        if self.actionCallback:
            if not self.folderOnly and self.fileEntry.text:
                self.actionCallback(
                    self,
                    "%s%s" % (self.filepathEntry.text, self.fileEntry.text))
            elif self.folderOnly:
                self.actionCallback(self, "%s" % (self.filepathEntry.text))

    def fileEntryChanged(self, en):
        typed = en.text.split("/")[-1]

        newList = []

        self.focusedEntry = en

        if en == self.filepathEntry:
            for x in self.currentSubFolders:
                if typed in x:
                    if len(newList) < 10:
                        newList.append(x)
                    else:
                        break
        else:
            for x in self.currentFiles:
                if typed in x:
                    if len(newList) < 10:
                        newList.append(x)
                    else:
                        break

        if self.autocompleteHover.expanded_get():
            self.autocompleteHover.hover_end()

        self.autocompleteHover.clear()

        for x in newList:
            self.autocompleteHover.item_add(x)

        self.autocompleteHover.hover_begin()

    def autocompleteSelected(self, hov, item):
        hov.hover_end()
        if self.focusedEntry == self.filepathEntry:
            self.populateFiles("%s%s" % (self.currentDirectory, item.text))
            self.filepathEntry.cursor_end_set()
        else:
            self.fileEntry.text = item.text
            self.fileEntry.cursor_end_set()

    def filepathEditDone(self, en):
        if os.path.isdir(en.text) and en.text != self.currentDirectory:
            self.populateFiles(en.text)
            self.filepathEntry.cursor_end_set()
        else:
            #en.text = self.currentDirectory
            pass

    def selected_get(self):
        return "%s%s" % (self.filepathEntry.text, self.fileEntry.text)
def store_clicked(obj):
    win = StandardWindow("store", "Store")
    win.autodel = True
    if obj is None:
        win.callback_delete_request_add(lambda o: elementary.exit())

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

    gl = Genlist(win)
    gl.mode = ELM_LIST_COMPRESS
    gl.callback_selected_add(st_selected)
    gl.callback_clicked_double_add(st_double_clicked)
    gl.callback_longpressed_add(st_longpress)
    gl.size_hint_weight = EVAS_HINT_EXPAND, EVAS_HINT_EXPAND
    gl.size_hint_align = EVAS_HINT_FILL, EVAS_HINT_FILL
    bx.pack_end(gl)
    gl.show()

    itc1 = GenlistItemClass()
    itc1.item_style = "message"

    st = Store()
    st.fs_list_func_set(st_store_list)
    st.fetch_func_set(st_store_fetch)
    #st.fetch_thread = False
    #st.unfetch_func_set(st_store_unfetch)
    st.items_sorted = False
    st.target_genlist = gl
    st.filesystem_directory = "."

    win.size = 480, 800
    win.show()
示例#21
0
def genlist10_clicked(obj, item=None):
    win = StandardWindow("genlist-decorate-item-mode",
                         "Genlist Decorate Item Mode",
                         autodel=True,
                         size=(520, 520))

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

    bx2 = Box(win)
    bx2.show()

    fr = Frame(win, text="Decorate Item Mode Type", content=bx2)
    bx.pack_end(fr)
    fr.show()

    rd = Radio(win,
               size_hint_weight=EXPAND_BOTH,
               state_value=0,
               text="Slide : Sweep genlist items to the right.")
    rd.show()
    bx2.pack_end(rd)
    rdg = rd

    rd = Radio(win,
               size_hint_weight=EXPAND_BOTH,
               state_value=1,
               text="Rotate : Click each item.")
    rd.group_add(rdg)
    rd.show()
    bx2.pack_end(rd)

    gl = Genlist(win, size_hint_align=FILL_BOTH, size_hint_weight=EXPAND_BOTH)
    gl.callback_drag_start_right_add(my_gl_mode_right, rdg)
    gl.callback_drag_start_left_add(my_gl_mode_left, rdg)
    gl.callback_drag_start_up_add(my_gl_mode_cancel, rdg)
    gl.callback_drag_start_down_add(my_gl_mode_cancel, rdg)
    gl.show()

    itc10 = ItemClass10(item_style="default", decorate_item_style="mode")
    itc10.state_get = gl_state_get

    for i in range(1000, 1050):
        GenlistItem(item_class=itc10,
                    item_data=i,
                    parent_item=None,
                    flags=ELM_GENLIST_ITEM_NONE,
                    func=gl_sel10,
                    func_data=(i, rdg)).append_to(gl)

    bx.pack_end(gl)

    win.size = 520, 520
    win.show()
    def __init__(self,
                 parent_widget,
                 defaultPath="",
                 defaultPopulate=True,
                 *args,
                 **kwargs):
        Box.__init__(self, parent_widget, *args, **kwargs)

        self.cancelCallback = None
        self.actionCallback = None
        self.directoryChangeCallback = None

        self.threadedFunction = ThreadedFunction()
        self._timer = ecore.Timer(0.02, self.populateFile)

        #Watch key presses for ctrl+l to select entry
        parent_widget.elm_event_callback_add(self.eventsCb)

        self.selectedFolder = None
        self.showHidden = False
        self.currentDirectory = None
        self.focusedEntry = None
        self.folderOnly = False
        self.sortReverse = False
        self.addingHidden = False
        self.pendingFiles = deque()
        self.currentSubFolders = []
        self.currentFiles = []

        #Mode should be "save" or "load"
        self.mode = "save"

        self.home = os.path.expanduser("~")
        self.root = "/"

        #Label+Entry for File Name
        self.filenameBox = Box(self,
                               size_hint_weight=EXPAND_HORIZ,
                               size_hint_align=FILL_HORIZ)
        self.filenameBox.horizontal = True
        self.filenameBox.show()

        fileLabel = Label(self,
                          size_hint_weight=(0.15, EVAS_HINT_EXPAND),
                          size_hint_align=FILL_HORIZ)
        fileLabel.text = "Filename:"
        fileLabel.show()

        self.fileEntry = Entry(self,
                               size_hint_weight=EXPAND_BOTH,
                               size_hint_align=FILL_HORIZ)
        self.fileEntry.single_line_set(True)
        self.fileEntry.scrollable_set(True)
        self.fileEntry.callback_changed_user_add(self.fileEntryChanged)
        self.fileEntry.show()

        self.filenameBox.pack_end(fileLabel)
        self.filenameBox.pack_end(self.fileEntry)

        sep = Separator(self,
                        size_hint_weight=EXPAND_HORIZ,
                        size_hint_align=FILL_HORIZ)
        sep.horizontal_set(True)
        sep.show()

        #Label+Entry for File Path
        self.filepathBox = Box(self,
                               size_hint_weight=EXPAND_HORIZ,
                               size_hint_align=FILL_HORIZ)
        self.filepathBox.horizontal = True
        self.filepathBox.show()

        fileLabel = Label(self,
                          size_hint_weight=(0.15, EVAS_HINT_EXPAND),
                          size_hint_align=FILL_HORIZ)
        fileLabel.text = "Current Folder:"
        fileLabel.show()

        self.filepathEntry = Entry(self,
                                   size_hint_weight=EXPAND_BOTH,
                                   size_hint_align=FILL_HORIZ)
        self.filepathEntry.single_line_set(True)
        self.filepathEntry.scrollable_set(True)
        self.filepathEntry.callback_changed_user_add(self.fileEntryChanged)
        self.filepathEntry.callback_unfocused_add(self.filepathEditDone)
        self.filepathEntry.callback_activated_add(self.filepathEditDone)
        #Wish this worked. Doesn't seem to do anything
        #self.filepathEntry.input_hint_set(ELM_INPUT_HINT_AUTO_COMPLETE)

        if defaultPath and os.path.isdir(defaultPath):
            startPath = defaultPath
        else:
            startPath = self.home
        self.filepathEntry.show()

        self.filepathBox.pack_end(fileLabel)
        self.filepathBox.pack_end(self.filepathEntry)

        self.autocompleteHover = Hoversel(self, hover_parent=self)
        self.autocompleteHover.callback_selected_add(self.autocompleteSelected)
        #self.autocompleteHover.show()

        self.fileSelectorBox = Panes(self,
                                     content_left_size=0.3,
                                     size_hint_weight=EXPAND_BOTH,
                                     size_hint_align=FILL_BOTH)
        self.fileSelectorBox.show()
        """Bookmarks Box contains:

            - Button - Up Arrow
            - List - Home/Root/GTK bookmarks
            - Box
            -- Button - Add Bookmark
            -- Button - Remove Bookmark"""
        self.bookmarkBox = Box(self,
                               size_hint_weight=(0.3, EVAS_HINT_EXPAND),
                               size_hint_align=FILL_BOTH)
        self.bookmarkBox.show()

        upIcon = Icon(self,
                      size_hint_weight=EXPAND_BOTH,
                      size_hint_align=FILL_BOTH)
        upIcon.standard_set("go-up")
        upIcon.show()

        self.upButton = Button(self,
                               size_hint_weight=EXPAND_HORIZ,
                               size_hint_align=FILL_HORIZ,
                               content=upIcon)
        self.upButton.text = "Up"
        self.upButton.callback_pressed_add(self.upButtonPressed)
        self.upButton.show()

        self.bookmarksList = List(self,
                                  size_hint_weight=EXPAND_BOTH,
                                  size_hint_align=FILL_BOTH)
        self.bookmarksList.callback_activated_add(self.bookmarkDoubleClicked)
        self.bookmarksList.show()

        self.bookmarkModBox = Box(self,
                                  size_hint_weight=EXPAND_HORIZ,
                                  size_hint_align=FILL_HORIZ)
        self.bookmarkModBox.horizontal = True
        self.bookmarkModBox.show()

        con = Icon(self,
                   size_hint_weight=EXPAND_BOTH,
                   size_hint_align=FILL_BOTH)
        con.standard_set("add")
        con.show()

        self.addButton = Button(self,
                                size_hint_weight=EXPAND_HORIZ,
                                size_hint_align=FILL_HORIZ,
                                content=con)
        self.addButton.callback_pressed_add(self.addButtonPressed)
        self.addButton.disabled = True
        self.addButton.show()

        con = Icon(self,
                   size_hint_weight=EXPAND_BOTH,
                   size_hint_align=FILL_BOTH)
        con.standard_set("remove")
        con.show()

        self.removeButton = Button(self,
                                   size_hint_weight=EXPAND_HORIZ,
                                   size_hint_align=FILL_HORIZ,
                                   content=con)
        self.removeButton.callback_pressed_add(self.removeButtonPressed)
        self.removeButton.disabled = True
        self.removeButton.show()

        self.bookmarkModBox.pack_end(self.addButton)
        self.bookmarkModBox.pack_end(self.removeButton)

        self.bookmarkBox.pack_end(self.upButton)
        self.bookmarkBox.pack_end(self.bookmarksList)
        self.bookmarkBox.pack_end(self.bookmarkModBox)

        #Directory List
        self.fileListBox = Box(self,
                               size_hint_weight=EXPAND_BOTH,
                               size_hint_align=FILL_BOTH)
        self.fileListBox.show()

        self.fileSortButton = Button(self,
                                     size_hint_weight=EXPAND_HORIZ,
                                     size_hint_align=FILL_HORIZ)
        self.fileSortButton.text = u"⬆ Name"
        self.fileSortButton.callback_pressed_add(self.sortData)
        self.fileSortButton.show()

        self.fileList = Genlist(self,
                                size_hint_weight=EXPAND_BOTH,
                                size_hint_align=FILL_BOTH,
                                homogeneous=True,
                                mode=ELM_LIST_COMPRESS)
        self.fileList.callback_activated_add(self.fileDoubleClicked)
        self.fileList.show()

        self.previewImage = previewImage = Image(self)
        #previewImage.size_hint_weight = EXPAND_BOTH
        previewImage.size_hint_align = FILL_BOTH
        previewImage.show()

        self.fileListBox.pack_end(self.fileSortButton)
        self.fileListBox.pack_end(self.fileList)
        self.fileListBox.pack_end(self.previewImage)

        self.fileSelectorBox.part_content_set("left", self.bookmarkBox)
        self.fileSelectorBox.part_content_set("right", self.fileListBox)

        #Cancel and Save/Open button
        self.buttonBox = Box(self,
                             size_hint_weight=EXPAND_HORIZ,
                             size_hint_align=(1.0, 0.5))
        self.buttonBox.horizontal = True
        self.buttonBox.show()

        self.actionIcon = Icon(self,
                               size_hint_weight=EXPAND_BOTH,
                               size_hint_align=FILL_BOTH)
        self.actionIcon.standard_set("document-save")
        self.actionIcon.show()

        self.actionButton = Button(self,
                                   size_hint_weight=(0.0, 0.0),
                                   size_hint_align=(1.0, 0.5),
                                   content=self.actionIcon)
        self.actionButton.text = "Save  "
        self.actionButton.callback_pressed_add(self.actionButtonPressed)
        self.actionButton.show()

        cancelIcon = Icon(self,
                          size_hint_weight=EXPAND_BOTH,
                          size_hint_align=FILL_BOTH)
        cancelIcon.standard_set("dialog-cancel")
        cancelIcon.show()

        self.cancelButton = Button(self,
                                   size_hint_weight=(0.0, 0.0),
                                   size_hint_align=(1.0, 0.5),
                                   content=cancelIcon)
        self.cancelButton.text = "Cancel  "
        self.cancelButton.callback_pressed_add(self.cancelButtonPressed)
        self.cancelButton.show()

        con = Icon(self,
                   size_hint_weight=EXPAND_BOTH,
                   size_hint_align=FILL_BOTH)
        con.standard_set("gtk-find")
        con.show()

        self.toggleHiddenButton = Button(self,
                                         size_hint_weight=(0.0, 0.0),
                                         size_hint_align=(1.0, 0.5),
                                         content=con)
        self.toggleHiddenButton.text = "Toggle Hidden  "
        self.toggleHiddenButton.callback_pressed_add(
            self.toggleHiddenButtonPressed)
        self.toggleHiddenButton.show()

        con = Icon(self,
                   size_hint_weight=EXPAND_BOTH,
                   size_hint_align=FILL_BOTH)
        con.standard_set("folder-new")
        con.show()

        self.createFolderButton = Button(self,
                                         size_hint_weight=(0.0, 0.0),
                                         size_hint_align=(1.0, 0.5),
                                         content=con)
        self.createFolderButton.text = "Create Folder  "
        self.createFolderButton.callback_pressed_add(
            self.createFolderButtonPressed)
        self.createFolderButton.show()

        self.buttonBox.pack_end(self.createFolderButton)
        self.buttonBox.pack_end(self.toggleHiddenButton)
        self.buttonBox.pack_end(self.cancelButton)
        self.buttonBox.pack_end(self.actionButton)

        self.pack_end(self.filenameBox)
        self.pack_end(sep)
        self.pack_end(self.filepathBox)
        self.pack_end(self.autocompleteHover)
        self.pack_end(self.fileSelectorBox)
        self.pack_end(self.buttonBox)

        self.populateBookmarks()

        self.createPopup = Popup(self)
        self.createPopup.part_text_set("title,text", "Create Folder:")

        self.createEn = en = Entry(self,
                                   size_hint_weight=EXPAND_HORIZ,
                                   size_hint_align=FILL_HORIZ)
        en.single_line_set(True)
        en.scrollable_set(True)
        en.show()

        self.createPopup.content = en

        bt = Button(self, text="Create")
        bt.callback_clicked_add(self.createFolder)
        self.createPopup.part_content_set("button1", bt)

        bt2 = Button(self, text="Cancel")
        bt2.callback_clicked_add(self.closePopup)
        self.createPopup.part_content_set("button2", bt2)

        if defaultPopulate:
            self.populateFiles(startPath)
示例#23
0
    def __init__(self, parent, path, pos=None, zoom=1.0):
        self.doc_path = path
        self._zoom = zoom
        self.doc_pos = pos
        self.pages = []
        self.doc = None
        self.doc_title = os.path.splitext(os.path.basename(path))[0]
        self.visible_pages = []

        super(Document, self).__init__(parent,
                                       size_hint_weight=EXPAND_BOTH,
                                       size_hint_align=FILL_BOTH)

        scr = self.scr = Scroller(self,
                                  size_hint_weight=EXPAND_BOTH,
                                  size_hint_align=FILL_BOTH)
        scr.callback_scroll_add(self._scrolled)
        self.pack(scr, 0, 0, 4, 1)
        scr.show()

        box = self.page_box = Box(scr,
                                  size_hint_weight=EXPAND_BOTH,
                                  size_hint_align=(0.5, 0.0))
        scr.content = box

        self.on_resize_add(self._resized)

        btn = Button(self, text="Toggle outlines", size_hint_align=ALIGN_LEFT)
        btn.callback_clicked_add(lambda x: self.ol_p.toggle())
        self.pack(btn, 0, 1, 1, 1)
        btn.show()

        spn = self.spn = Spinner(self,
                                 round=1.0,
                                 size_hint_weight=EXPAND_HORIZ,
                                 size_hint_align=FILL_HORIZ)
        spn.special_value_add(1, "First")
        spn.editable = True
        self.pack(spn, 1, 1, 1, 1)
        spn.show()

        btn = Button(self,
                     text="show page",
                     size_hint_weight=EXPAND_HORIZ,
                     size_hint_align=ALIGN_LEFT)
        btn.callback_clicked_add(self._show_page_cb, spn)
        self.pack(btn, 2, 1, 1, 1)
        btn.show()

        menu = Menu(self.top_widget)
        menu.item_add(None, "Zoom In", "zoom-in", lambda x, y: self.zoom_in())
        menu.item_add(None, "Zoom Out", "zoom-out",
                      lambda x, y: self.zoom_out())
        menu.item_add(None, "Zoom 1:1", "zoom-original",
                      lambda x, y: self.zoom_orig())
        menu.item_add(None, "Zoom Fit", "zoom-fit-best",
                      lambda x, y: self.zoom_fit())

        def z_clicked(btn):
            x, y = btn.evas.pointer_canvas_xy_get()
            menu.move(x, y)
            menu.show()

        zlbl = self.zlbl = Button(self,
                                  text="%1.0f %%" % (self.zoom * 100.0),
                                  size_hint_weight=EXPAND_HORIZ,
                                  size_hint_align=ALIGN_RIGHT)
        zlbl.callback_clicked_add(z_clicked)
        self.pack(zlbl, 3, 1, 1, 1)
        zlbl.show()

        n = self.page_notify = Notify(scr, align=(0.02, 0.02))
        b = Box(n, horizontal=True, padding=(6, 0))
        n.content = b

        n = self.load_notify = Notify(scr, align=(0.98, 0.98))
        pb = Progressbar(n, pulse_mode=True, style="wheel")
        n.content = pb
        pb.pulse(True)
        n.show()

        p = self.ol_p = Panel(
            self,
            orient=ELM_PANEL_ORIENT_LEFT,
            size_hint_weight=EXPAND_BOTH,
            size_hint_align=FILL_BOTH,
        )  #scrollable=True, scrollable_content_size=0.35)
        p.hidden = True
        scr.on_move_add(lambda x: p.move(*x.pos))
        scr.on_resize_add(lambda x: p.resize(x.size[0] * 0.35, x.size[1]))

        ol_gl = self.ol_gl = Genlist(p,
                                     size_hint_weight=EXPAND_BOTH,
                                     size_hint_align=FILL_BOTH,
                                     mode=ELM_LIST_COMPRESS,
                                     homogeneous=True,
                                     select_mode=ELM_OBJECT_SELECT_MODE_ALWAYS)
        p.content = ol_gl

        ol_gl.callback_contract_request_add(self._gl_contract_req)
        ol_gl.callback_contracted_add(self._gl_contracted)
        ol_gl.callback_expand_request_add(self._gl_expand_req)
        ol_gl.callback_expanded_add(self._gl_expanded)
        ol_gl.show()

        p.show()
        self.show()

        def read_worker():
            t1 = self.t1 = time.clock()
            try:
                self.doc = PyPDF2.PdfFileReader(path)
                self.page_count = self.doc.getNumPages()
            except Exception as e:
                log.exception("Document could not be opened because: %r", e)
                self.doc = None
                self.display_error(e)
                return
            t2 = time.clock()
            log.info("Reading the doc took: %f", t2 - t1)

        t = Thread(target=read_worker)
        t.daemon = True
        t.start()

        def worker_check(t):
            if t.is_alive():
                return True
            elif self.doc and self.page_count:
                spn.special_value_add(self.page_count, "Last")
                spn.min_max = (1, self.page_count)

                if self.doc.isEncrypted:
                    PasswordPrompt(self)
                    return False

                self.metadata_read()
                self.populate_pages()
                return False

        timer = Timer(0.2, worker_check, t)
        self.parent.callback_delete_request_add(lambda x: timer.delete())
class SignalReceiver(Frame):
    def __init__(self, parent):
        Frame.__init__(self, parent, text="Signals")
        self._parent = parent

        vbox = Box(self)
        vbox.show()
        self.content = vbox

        self.siglist = Genlist(self, homogeneous=True, mode=ELM_LIST_SCROLL)
        self.siglist.size_hint_weight = EVAS_HINT_EXPAND, EVAS_HINT_EXPAND
        self.siglist.size_hint_align = EVAS_HINT_FILL, EVAS_HINT_FILL
        self.siglist.callback_clicked_double_add(self.signal_clicked_cb)
        self.siglist.show()
        vbox.pack_end(self.siglist)
        self.itc = SignalItemClass()

        hbox = Box(self, horizontal=True)
        hbox.size_hint_align = 0.0, 0.5
        hbox.show()
        vbox.pack_end(hbox)

        bt = Button(self, text='Clear')
        bt.callback_clicked_add(lambda b: self.siglist.clear())
        hbox.pack_end(bt)
        bt.show()

        def scroll_on_signal_clicked_cb(chk):
            options.scroll_on_signal = chk.state

        ck = Check(self, text='Scroll on signal')
        ck.state = options.scroll_on_signal
        ck.callback_changed_add(scroll_on_signal_clicked_cb)
        hbox.pack_end(ck)
        ck.show()

        for b in session_bus, system_bus:
            b.add_signal_receiver(self.signal_cb,
                                  sender_keyword='sender',
                                  destination_keyword='dest',
                                  interface_keyword='iface',
                                  member_keyword='signal',
                                  path_keyword='path')

    def signal_cb(self, *args, **kargs):
        # print('*** SIGNAL RECEIVED ***')
        # print(json.dumps(args, indent=2))
        # print(json.dumps(kargs, indent=2))

        kargs['args'] = args
        item = self.siglist.item_append(self.itc, kargs)
        if options.scroll_on_signal is True:
            item.bring_in()

        if self.siglist.items_count > 200:
            self.siglist.first_item.delete()

    def signal_clicked_cb(self, gl, item):
        pp = Popup(self._parent)
        pp.part_text_set('title,text', 'Signal content')

        en = Entry(self, text=prettify_if_needed(item.data['args']))
        en.size_hint_weight = EVAS_HINT_EXPAND, EVAS_HINT_EXPAND
        en.size_hint_align = EVAS_HINT_FILL, EVAS_HINT_FILL
        en.size_hint_min = 800, 800  # TODO: this should be respected :/
        en.editable = False
        en.scrollable = True
        pp.content = en

        bt = Button(pp, text="Close")
        bt.callback_clicked_add(lambda b: pp.delete())
        pp.part_content_set('button2', bt)

        def prettify_clicked_cb(chk):
            options.pretty_output = chk.state
            en.text = prettify_if_needed(item.data['args'])

        ck = Check(pp, text="Prettify")
        ck.state = options.pretty_output
        ck.callback_changed_add(prettify_clicked_cb)
        pp.part_content_set('button1', ck)

        pp.show()
 def __init__(self, canvas, *args, **kwargs):
     Genlist.__init__(self, canvas, *args, **kwargs)
示例#26
0
def genlist2_clicked(obj, item=None):
    win = Window("Genlist",
                 ELM_WIN_BASIC,
                 title="Genlist test 2",
                 autodel=True,
                 size=(320, 320))

    bg = Background(win,
                    file=os.path.join(img_path, "plant_01.jpg"),
                    size_hint_weight=EXPAND_BOTH)
    win.resize_object_add(bg)
    bg.show()

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

    gl = Genlist(win, size_hint_align=FILL_BOTH, size_hint_weight=EXPAND_BOTH)
    gl.show()

    itc1 = GenlistItemClass(item_style="default",
                            text_get_func=gl_text_get,
                            content_get_func=gl_content_get,
                            state_get_func=gl_state_get)

    gl.item_append(itc1, 1001, func=gl_item_sel)
    gl.item_append(itc1, 1002, func=gl_item_sel)
    gl.item_append(itc1, 1003, func=gl_item_sel)
    gl.item_append(itc1, 1004, func=gl_item_sel)
    gl.item_append(itc1, 1005, func=gl_item_sel)
    gl.item_append(itc1, 1006, func=gl_item_sel)
    gl.item_append(itc1, 1007, func=gl_item_sel)

    bx.pack_end(gl)

    bx2 = Box(win,
              horizontal=True,
              homogeneous=True,
              size_hint_weight=EXPAND_HORIZ,
              size_hint_align=FILL_BOTH)

    def my_gl_first(bt, gl):
        gli = gl.first_item
        if gli:
            gli.show()
            gli.selected = True

    bt = Button(win,
                text="/\\",
                size_hint_align=FILL_BOTH,
                size_hint_weight=EXPAND_HORIZ)
    bt.callback_clicked_add(my_gl_first, gl)
    bx2.pack_end(bt)
    bt.show()

    def my_gl_last(bt, gl):
        gli = gl.last_item_get()
        if gli:
            gli.show()
            gli.selected = True

    bt = Button(win,
                text="\\/",
                size_hint_align=FILL_BOTH,
                size_hint_weight=EXPAND_HORIZ)
    bt.callback_clicked_add(my_gl_last, gl)
    bx2.pack_end(bt)
    bt.show()

    def my_gl_disable(bt, gl):
        gli = gl.selected_item
        if gli:
            gli.disabled = True
            gli.selected = False
            gli.update()
        else:
            print("no item selected")

    bt = Button(win,
                text="#",
                size_hint_align=FILL_BOTH,
                size_hint_weight=EXPAND_HORIZ)
    bt.callback_clicked_add(my_gl_disable, gl)
    bx2.pack_end(bt)
    bt.show()

    def my_gl_update_all(bt, gl):
        gli = gl.first_item_get()
        i = 0
        while gli:
            gli.update()
            print(i)
            i = i + 1
            gli = gli.next_get()

    bt = Button(win,
                text="U",
                size_hint_align=FILL_BOTH,
                size_hint_weight=EXPAND_HORIZ)
    bt.callback_clicked_add(my_gl_update_all, gl)
    bx2.pack_end(bt)
    bt.show()

    bx.pack_end(bx2)
    bx2.show()

    bx2 = Box(win,
              horizontal=True,
              homogeneous=True,
              size_hint_weight=EXPAND_HORIZ,
              size_hint_align=FILL_BOTH)

    def my_gl_clear(bt, gl):
        gl.clear()

    bt = Button(win,
                text="X",
                size_hint_align=FILL_BOTH,
                size_hint_weight=EXPAND_HORIZ)
    bt.callback_clicked_add(my_gl_clear, gl)
    bx2.pack_end(bt)
    bt.show()

    class MyGlAdd:
        i = 0

    def my_gl_add(bt, gl, itc1):
        gl.item_append(itc1, MyGlAdd.i, func=gl_item_sel)
        MyGlAdd.i = MyGlAdd.i + 1

    bt = Button(win,
                text="+",
                size_hint_align=FILL_BOTH,
                size_hint_weight=EXPAND_HORIZ)
    bt.callback_clicked_add(my_gl_add, gl, itc1)
    bx2.pack_end(bt)
    bt.show()

    def my_gl_del(bt, gl):
        gli = gl.selected_item_get()
        if gli:
            gli.delete()
        else:
            print("no item selected")

    bt = Button(win,
                text="-",
                size_hint_align=FILL_BOTH,
                size_hint_weight=EXPAND_HORIZ)
    bt.callback_clicked_add(my_gl_del, gl)
    bx2.pack_end(bt)
    bt.show()

    bx.pack_end(bx2)
    bx2.show()

    bx2 = Box(win,
              horizontal=True,
              homogeneous=True,
              size_hint_weight=EXPAND_HORIZ,
              size_hint_align=FILL_BOTH)

    class MyGlInsertBefore:
        i = 0

    def my_gl_insert_before(bt, gl, itc1):
        gli = gl.selected_item_get()
        if gli:
            gl.item_insert_before(itc1,
                                  MyGlInsertBefore.i,
                                  gli,
                                  func=gl_item_sel)
            MyGlInsertBefore.i = MyGlInsertBefore.i + 1
        else:
            print("no item selected")

    bt = Button(win,
                text="+ before",
                size_hint_align=FILL_BOTH,
                size_hint_weight=EXPAND_HORIZ)
    bt.callback_clicked_add(my_gl_insert_before, gl, itc1)
    bx2.pack_end(bt)
    bt.show()

    class MyGlInsertAfter:
        i = 0

    def my_gl_insert_after(bt, gl, itc1):
        gli = gl.selected_item_get()
        if gli:
            gl.item_insert_after(itc1,
                                 MyGlInsertAfter.i,
                                 gli,
                                 func=gl_item_sel)
            MyGlInsertAfter.i = MyGlInsertAfter.i + 1
        else:
            print("no item selected")

    bt = Button(win,
                text="+ after",
                size_hint_align=FILL_BOTH,
                size_hint_weight=EXPAND_HORIZ)
    bt.callback_clicked_add(my_gl_insert_after, gl, itc1)
    bx2.pack_end(bt)
    bt.show()

    def my_gl_flush(bt, gl):
        def my_gl_flush_delay():
            cache_all_flush()

        Timer(1.2, my_gl_flush_delay)

    bt = Button(win,
                text="Flush",
                size_hint_align=FILL_BOTH,
                size_hint_weight=EXPAND_HORIZ)
    bt.callback_clicked_add(my_gl_flush, gl)
    bx2.pack_end(bt)
    bt.show()

    bx.pack_end(bx2)
    bx2.show()

    win.show()
示例#27
0
def genlist_clicked(obj, item=None):
    win = StandardWindow("Genlist", "Genlist test", autodel=True)

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

    gl = Genlist(win, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH)
    gl.callback_selected_add(_gl_selected,
                             "arg1",
                             "arg2",
                             kwarg1="kwarg1",
                             kwarg2="kwarg2")
    gl.callback_clicked_double_add(_gl_clicked_double,
                                   "arg1",
                                   "arg2",
                                   kwarg1="kwarg1",
                                   kwarg2="kwarg2")
    gl.callback_longpressed_add(_gl_longpressed,
                                "arg1",
                                "arg2",
                                kwarg1="kwarg1",
                                kwarg2="kwarg2")
    bx.pack_end(gl)
    gl.show()

    over = Rectangle(win.evas_get())
    over.color_set(0, 0, 0, 0)
    over.event_callback_add(evas.EVAS_CALLBACK_MOUSE_DOWN, _gl_over_click, gl)
    over.repeat_events_set(True)
    over.show()
    over.size_hint_weight_set(evas.EVAS_HINT_EXPAND, evas.EVAS_HINT_EXPAND)
    win.resize_object_add(over)

    vbx = Box(win, horizontal=True)
    bx.pack_end(vbx)
    vbx.show()

    itc1 = GenlistItemClass(item_style="default",
                            text_get_func=gl_text_get,
                            content_get_func=gl_content_get,
                            state_get_func=gl_state_get)

    bt_50 = Button(win, text="Go to 50")
    vbx.pack_end(bt_50)
    bt_50.show()

    bt_1500 = Button(win, text="Go to 1500")
    vbx.pack_end(bt_1500)
    bt_1500.show()

    for i in range(0, 2000):
        gli = gl.item_append(itc1, i, func=gl_item_sel)
        if i == 50:
            bt_50._callback_add("clicked", lambda bt, it: it.bring_in(), gli)
        elif i == 1500:
            bt_1500._callback_add("clicked", lambda bt, it: it.bring_in(), gli)

    win.resize(480, 800)
    win.show()
示例#28
0
    def __init__(self, parent, session):
        self.parent = parent
        self.session = session

        elm_conf = Configuration()
        scale = elm_conf.scale

        self.log = logging.getLogger("epour.gui")

        self.torrentitems = {}

        win = self.win = StandardWindow("epour", "Epour")
        win.callback_delete_request_add(lambda x: elm.exit())
        win.screen_constrain = True
        win.size = 480 * scale, 400 * scale

        mbox = Box(win)
        mbox.size_hint_weight = 1.0, 1.0
        win.resize_object_add(mbox)
        mbox.show()

        tb = Toolbar(win)
        tb.homogeneous = False
        tb.shrink_mode = ELM_TOOLBAR_SHRINK_NONE
        tb.select_mode = ELM_OBJECT_SELECT_MODE_NONE
        tb.size_hint_align = -1.0, 0.0
        tb.menu_parent = win

        item = tb.item_append("document-new", "Add torrent",
                              lambda t, i: self.select_torrent())

        def pause_session(it):
            self.session.pause()
            it.state_set(it.state_next())

        def resume_session(it):
            session.resume()
            del it.state

        item = tb.item_append("media-playback-pause", "Pause Session",
                              lambda tb, it: pause_session(it))
        item.state_add("media-playback-start", "Resume Session",
                       lambda tb, it: resume_session(it))

        item = tb.item_append("preferences-system", "Preferences")
        item.menu = True
        item.menu.item_add(None, "General", "preferences-system",
                           lambda o, i: PreferencesGeneral(self, self.session))
        item.menu.item_add(None, "Proxy", "preferences-system",
                           lambda o, i: PreferencesProxy(self, self.session))
        item.menu.item_add(None, "Session", "preferences-system",
                           lambda o, i: PreferencesSession(self, self.session))

        item = tb.item_append("application-exit", "Exit",
                              lambda tb, it: elm.exit())

        mbox.pack_start(tb)
        tb.show()

        self.tlist = tlist = Genlist(win)
        tlist.select_mode = ELM_OBJECT_SELECT_MODE_NONE
        tlist.mode = ELM_LIST_COMPRESS
        tlist.callback_activated_add(self.item_activated_cb)
        tlist.homogeneous = True
        tlist.size_hint_weight = 1.0, 1.0
        tlist.size_hint_align = -1.0, -1.0
        tlist.show()

        mbox.pack_end(tlist)

        pad = Rectangle(win.evas)
        pad.size_hint_weight = 1.0, 1.0

        p = Panel(win)
        p.color = 200, 200, 200, 200
        p.size_hint_weight = 1.0, 1.0
        p.size_hint_align = -1.0, -1.0
        p.orient = ELM_PANEL_ORIENT_BOTTOM
        p.content = SessionStatus(win, session)
        p.hidden = True
        p.show()

        topbox = Box(win)
        topbox.horizontal = True
        topbox.size_hint_weight = 1.0, 1.0
        win.resize_object_add(topbox)

        topbox.pack_end(pad)
        topbox.pack_end(p)
        topbox.stack_above(mbox)
        topbox.show()

        session.alert_manager.callback_add("torrent_added_alert",
                                           self.torrent_added_cb)
        session.alert_manager.callback_add("torrent_removed_alert",
                                           self.torrent_removed_cb)

        for a_name in "torrent_paused_alert", "torrent_resumed_alert":
            session.alert_manager.callback_add(a_name, self.update_icon)

        session.alert_manager.callback_add("state_changed_alert",
                                           self.state_changed_cb)

        Timer(
            15.0, lambda: session.alert_manager.callback_add(
                "torrent_finished_alert", self.torrent_finished_cb))
示例#29
0
    def __init__(self, app):
        self.app = app
        self.prog_popup = None

        # the window
        StandardWindow.__init__(self, 'epack', 'Epack')
        self.autodel_set(True)
        self.callback_delete_request_add(lambda o: self.app.exit())

        ### main table (inside a padding frame)
        frame = Frame(self,
                      style='pad_small',
                      size_hint_weight=EXPAND_BOTH,
                      size_hint_align=FILL_BOTH)
        self.resize_object_add(frame)
        frame.content = table = Table(frame)
        frame.show()

        ### header horiz box
        self.header_box = Box(self,
                              horizontal=True,
                              size_hint_weight=EXPAND_HORIZ,
                              size_hint_align=FILL_HORIZ)
        table.pack(self.header_box, 0, 0, 3, 1)
        self.header_box.show()

        # genlist with archive content (inside a small padding frame)
        frame = Frame(self,
                      style='pad_small',
                      size_hint_weight=EXPAND_BOTH,
                      size_hint_align=FILL_BOTH)
        table.pack(frame, 0, 1, 3, 1)

        self.file_itc = GenlistItemClass(item_style="no_icon",
                                         text_get_func=self._gl_file_text_get)
        self.fold_itc = GenlistItemClass(
            item_style="one_icon",
            text_get_func=self._gl_fold_text_get,
            content_get_func=self._gl_fold_icon_get)
        self.file_list = Genlist(frame, homogeneous=True)
        self.file_list.callback_expand_request_add(self._gl_expand_req_cb)
        self.file_list.callback_contract_request_add(self._gl_contract_req_cb)
        self.file_list.callback_expanded_add(self._gl_expanded_cb)
        self.file_list.callback_contracted_add(self._gl_contracted_cb)
        frame.content = self.file_list
        frame.show()

        # rect hack to force a min size on the genlist
        r = evas.Rectangle(table.evas,
                           size_hint_min=(250, 250),
                           size_hint_weight=EXPAND_BOTH,
                           size_hint_align=FILL_BOTH)
        table.pack(r, 0, 1, 3, 1)

        # FileSelectorButton
        self.fsb = DestinationButton(app, self)
        table.pack(self.fsb, 0, 2, 3, 1)
        self.fsb.show()

        sep = Separator(table, horizontal=True, size_hint_weight=EXPAND_HORIZ)
        table.pack(sep, 0, 3, 3, 1)
        sep.show()

        # extract button
        self.extract_btn = Button(table, text=_('Extract'))
        self.extract_btn.callback_clicked_add(self.extract_btn_cb)
        table.pack(self.extract_btn, 0, 4, 1, 2)
        self.extract_btn.show()

        sep = Separator(table, horizontal=False)
        table.pack(sep, 1, 4, 1, 2)
        sep.show()

        # delete-archive checkbox
        self.del_chk = Check(table,
                             text=_('Delete archive after extraction'),
                             size_hint_weight=EXPAND_HORIZ,
                             size_hint_align=(0.0, 1.0))
        self.del_chk.callback_changed_add(self.del_check_cb)
        table.pack(self.del_chk, 2, 4, 1, 1)
        self.del_chk.show()

        # create-archive-folder checkbox
        self.create_folder_chk = Check(table,
                                       text=_('Create archive folder'),
                                       size_hint_weight=EXPAND_HORIZ,
                                       size_hint_align=(0.0, 1.0))
        table.pack(self.create_folder_chk, 2, 5, 1, 1)
        self.create_folder_chk.callback_changed_add(
            lambda c: self.update_fsb_label())
        self.create_folder_chk.show()

        # set the correct ui state
        self.update_ui()

        # show the window
        self.show()