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()
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()
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()
class DiffViewer(Table): def __init__(self, parent, app): self.app = app self.commit = None self.win = parent Table.__init__(self, parent, padding=(5,5)) self.show() # description entry self.entry = Entry(self, text='Unknown', line_wrap=ELM_WRAP_MIXED, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH, editable=False) self.pack(self.entry, 0, 0, 1, 1) self.entry.show() # gravatar picture self.picture = GravatarPict(self) self.picture.size_hint_align = 1.0, 0.0 self.picture.show() self.pack(self.picture, 1, 0, 1, 1) # action buttons box self.action_box = Box(self, horizontal=True, size_hint_weight=EXPAND_HORIZ, size_hint_align=(1.0, 1.0)) self.pack(self.action_box, 0, 1, 2, 1) self.action_box.show() # panes panes = Panes(self, content_left_size = 0.3, horizontal=True, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) self.pack(panes, 0, 2, 2, 1) panes.show() # file list self.itc = GenlistItemClass(item_style='default', text_get_func=self._gl_text_get, content_get_func=self._gl_content_get) self.diff_list = Genlist(self, homogeneous=True, mode=ELM_LIST_COMPRESS, select_mode=ELM_OBJECT_SELECT_MODE_ALWAYS, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) self.diff_list.callback_selected_add(self._list_selected_cb) panes.part_content_set('left', self.diff_list) # diff entry self.diff_entry = DiffedEntry(self) panes.part_content_set('right', self.diff_entry) def _gl_text_get(self, li, part, item_data): if isinstance(item_data, tuple): # in real commits mod, staged, name, new = item_data else: # in local changes (item_data is the path) mod, staged, name, new = self.app.repo.status.changes[item_data] return '{} → {}'.format(name, new) if new else name def _gl_content_get(self, li, part, item_data): if isinstance(item_data, tuple): # in real commits mod, staged, name, new = item_data else: # in local changes (item_data is the path) mod, staged, name, new = self.app.repo.status.changes[item_data] if part == 'elm.swallow.icon': return Icon(self, standard='git-mod-'+mod) elif part == 'elm.swallow.end' and staged is not None: ck = Check(self, state=staged, propagate_events=False) ck.callback_changed_add(self._stage_unstage_check_cb) ck.data['path'] = name return ck def update_action_buttons(self, buttons): self.action_box.clear() if 'checkout' in buttons: bt = Button(self, text='Checkout') bt.callback_clicked_add(lambda b: \ self.app.checkout_ref(self.commit.sha)) self.action_box.pack_end(bt) bt.show() if 'revert' in buttons: bt = Button(self, text='Revert') bt.callback_clicked_add(lambda b: \ CommitDialog(self.app, revert_commit=self.commit)) self.action_box.pack_end(bt) bt.show() if 'cherrypick' in buttons: bt = Button(self, text='Cherry-pick') bt.callback_clicked_add(lambda b: \ CommitDialog(self.app, cherrypick_commit=self.commit)) self.action_box.pack_end(bt) bt.show() if 'commit' in buttons: bt = Button(self, text='Commit', content=Icon(self, standard='git-commit')) bt.callback_clicked_add(lambda b: \ CommitDialog(self.app)) self.action_box.pack_end(bt) bt.show() if 'stash' in buttons: bt = Button(self, text='Stash', content=Icon(self, standard='git-stash')) bt.callback_clicked_add(lambda b: self.app.action_stash_save()) self.action_box.pack_end(bt) bt.show() if 'discard' in buttons: bt = Button(self, text='Discard', content=Icon(self, standard='user-trash')) bt.callback_clicked_add(lambda b: DiscardDialog(self.app)) self.action_box.pack_end(bt) bt.show() def show_commit(self, commit): self.commit = commit self.picture.email_set(commit.author_email) line1 = '<name>{}</name> <b>{}</b> {}<br>'.format(commit.sha[:9], commit.author, format_date(commit.commit_date)) line2 = line3 = line4 = '' if commit.committer and commit.committer != commit.author: line2 = '<name>Committed by:</name> <b>{}</b><br>'.format( commit.committer) if commit.title: line3 = '<bigger><b>{}</b></bigger><br>'.format( utf8_to_markup(commit.title.strip())) if commit.message: line4 = '<br>{}'.format(utf8_to_markup(commit.message.strip())) text = line1 + line2 + line3 + line4 self.entry.text = text self.update_action_buttons(['checkout', 'revert', 'cherrypick']) self.diff_entry.text = '' self.diff_list.clear() self.app.repo.request_changes(self._changes_done_cb, commit1=commit) def show_local_status(self): self.commit = None self.entry.text = '<bigger><b>Local status</b></bigger>' self.diff_entry.text = '' self.picture.email_set(None) self.update_action_buttons(['commit', 'stash', 'discard']) self.diff_list.clear() for path in sorted(self.app.repo.status.changes): self.diff_list.item_append(self.itc, path) def refresh_diff(self): if self.diff_list.selected_item: self._list_selected_cb(self.diff_list, self.diff_list.selected_item) def _stage_unstage_check_cb(self, check): path = check.data['path'] if check.state is True: self.app.repo.stage_file(self._stage_unstage_done_cb, path, path) else: self.app.repo.unstage_file(self._stage_unstage_done_cb, path, path) def _stage_unstage_done_cb(self, success, path): self.app.action_update_header() self.diff_list.realized_items_update() def _changes_done_cb(self, success, lines): for mod, name, new_name in lines: item_data = (mod, None, name, new_name) self.diff_list.item_append(self.itc, item_data) self.diff_list.first_item.selected = True def _list_selected_cb(self, li, item): if isinstance(item.data, tuple): # in real commits mod, staged, name, new = item.data else: # in local changes (item_data is the path) mod, staged, name, new = self.app.repo.status.changes[item.data] self.app.repo.request_diff(self._diff_done_cb, ref1=self.commit.sha if self.commit else None, path=name) self.diff_entry.line_wrap = \ ELM_WRAP_MIXED if options.diff_text_wrap else ELM_WRAP_NONE self.diff_entry.loading_set() def _diff_done_cb(self, lines, success): self.diff_entry.lines_set(lines)
def __init__(self, app): self.app = app Popup.__init__(self, app.win) # title self.part_text_set('title,text', 'Recent Repositories') self.part_content_set('title,icon', SafeIcon(self, 'egitu')) # main table tb = Table(self, padding=(0,4), size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) self.content = tb tb.show() # sep sep = Separator(self, horizontal=True, size_hint_expand=EXPAND_BOTH) tb.pack(sep, 0, 0, 1, 1) sep.show() # recent list itc = GenlistItemClass(item_style='no_icon', text_get_func=self._gl_text_get) li = Genlist(self, homogeneous=True, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) li.callback_selected_add(self._recent_selected_cb) recents = recent_history_get() if recents: for path in recents: li.item_append(itc, path) else: item = li.item_append(itc, None) item.disabled = True li.show() r = Rectangle(self.evas, color=(0,0,0,0), size_hint_min=(300,200), size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) tb.pack(r, 0, 1, 1, 1) tb.pack(li, 0, 1, 1, 1) # sep sep = Separator(self, horizontal=True, size_hint_expand=EXPAND_BOTH) tb.pack(sep, 0, 2, 1, 1) sep.show() # buttons bt = Button(self, text='Close') bt.callback_clicked_add(lambda b: self.delete()) self.part_content_set('button1', bt) bt = Button(self, text='Clone') bt.callback_clicked_add(self._clone_btn_cb) self.part_content_set('button2', bt) bt = Button(self, text='Open') bt.callback_clicked_add(self._load_btn_cb) self.part_content_set('button3', bt) # self.show()
class ComboBox(Entry): def __init__(self, parent, text=None, icon=None): Entry.__init__(self, parent, scrollable=True, single_line=True, size_hint_expand=EXPAND_BOTH, size_hint_fill=FILL_BOTH) self.show() if text: self.text = text if icon: self.icon = icon ic = SafeIcon(self, 'go-down') ic.size_hint_min = 16, 16 # TODO file a bug for elm on phab ic.callback_clicked_add(self.activate) self.part_content_set('end', ic) self._itc = GenlistItemClass(item_style='default', text_get_func=self._gl_text_get, content_get_func=self._gl_content_get) self._list = Genlist(self) self._list.callback_selected_add(self._list_selected_cb) self._hover = Hover(self.parent, target=self) self._bg = Background(self, size_hint_expand=EXPAND_BOTH, size_hint_fill=FILL_BOTH) fr = Frame(self, style='pad_medium', size_hint_expand=EXPAND_BOTH, size_hint_fill=FILL_BOTH) fr.content = self._list fr.show() self._table = Table(self, size_hint_expand=EXPAND_BOTH, size_hint_fill=FILL_BOTH) self._table.pack(self._bg, 0, 0, 1, 1) self._table.pack(fr, 0, 0, 1, 1) self._selected_func = None def callback_selected_add(self, func): self._selected_func = func @property def icon(self): return self.part_content_get('icon') @icon.setter def icon(self, icon): icon.size_hint_min = 16, 16 # TODO file a bug for elm on phab self.part_content_set('icon', icon) @property def guide(self): self.part_text_get('guide') @guide.setter def guide(self, text): self.part_text_set('guide', text) def item_append(self, label=None, icon=None, end=None): item_data = (label, icon, end) self._list.item_append(self._itc, item_data) def clear(self): self._list.clear() def activate(self, source=None): self.focus = False # :/ # TODO calculate this based on _list and parent size # print(self._list.size) # print(self._list.geometry) self._bg.size_hint_min = 0, 200 loc = self._hover.best_content_location_get(ELM_HOVER_AXIS_VERTICAL) self._hover.part_content_set(loc, self._table) self._hover.show() self._table.show() self._bg.show() self._list.show() def dismiss(self): self._hover.dismiss() def _list_selected_cb(self, gl, item): label, icon, end = item.data self.text = label if icon: self.icon = SafeIcon(self, icon) item.selected = False self.dismiss() if callable(self._selected_func): self._selected_func(self) def _gl_text_get(self, gl, part, item_data): label, icon, end = item_data return label def _gl_content_get(self, gl, part, item_data): label, icon, end = item_data if icon and part == 'elm.swallow.icon': return SafeIcon(gl, icon) elif end and part == 'elm.swallow.end': return SafeIcon(gl, end)
def __init__(self, parent, app): self.app = app DialogWindow.__init__(self, parent, 'Egitu-tags', 'Tags', size=(350,350), autodel=True) # main vertical box (inside a padding frame) vbox = Box(self, padding=(0, 6), size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) fr = Frame(self, style='pad_medium', size_hint_weight=EXPAND_BOTH) self.resize_object_add(fr) fr.content = vbox fr.show() vbox.show() # title en = Entry(self, editable=False, single_line=True, text='<title>%s</title>' % 'Tags', size_hint_expand=EXPAND_HORIZ) vbox.pack_end(en) en.show() # tag list self.itc = GenlistItemClass(item_style='one_icon', text_get_func=self._gl_text_get, content_get_func=self._gl_content_get) li = Genlist(self, homogeneous=True, size_hint_expand=EXPAND_BOTH, size_hint_fill=FILL_BOTH) li.callback_selected_add(self._list_selected_cb) vbox.pack_end(li) li.show() self.tags_list = li # buttons hbox = Box(self, horizontal=True, size_hint_expand=EXPAND_HORIZ, size_hint_fill=FILL_BOTH) vbox.pack_end(hbox) hbox.show() bt = Button(self, text='Create', content=Icon(self, standard='git-tag')) bt.callback_clicked_add(lambda b: CreateTagPopup(self, self.app)) hbox.pack_end(bt) bt.show() bt = Button(self, text='Delete', content=Icon(self, standard='user-trash')) bt.callback_clicked_add(self._delete_clicked_cb) hbox.pack_end(bt) bt.show() self.delete_btn = bt bt = Button(self, text='Checkout') bt.callback_clicked_add(self._checkout_clicked_cb) hbox.pack_end(bt) bt.show() self.checkout_btn = bt sep = Separator(self, size_hint_expand=EXPAND_HORIZ) hbox.pack_end(sep) bt = Button(self, text='Close') bt.callback_clicked_add(lambda b: self.delete()) hbox.pack_end(bt) bt.show() # self.populate() self.show()
def __init__(self, parent, app, branch=None): self.app = app Popup.__init__(self, parent) self.part_text_set('title,text', 'Create a new local branch') self.part_content_set('title,icon', SafeIcon(self, 'git-branch')) # main table tb = Table(self, padding=(4,4), size_hint_expand=EXPAND_BOTH, size_hint_fill=FILL_BOTH) self.content = tb tb.show() # sep sep = Separator(self, horizontal=True, size_hint_expand=EXPAND_BOTH) tb.pack(sep, 0, 0, 2, 1) sep.show() # branch name lb = Label(self, text='Branch name', size_hint_align=(0.0, 0.5)) tb.pack(lb, 0, 1, 1, 1) lb.show() en = Entry(self, single_line=True, scrollable=True, size_hint_expand=EXPAND_BOTH, size_hint_fill=FILL_BOTH) tb.pack(en, 1, 1, 1, 1) en.show() self.name_entry = en # branch type lb = Label(self, text='Branch type', size_hint_align=(0.0, 0.5)) tb.pack(lb, 0, 2, 1, 1) lb.show() hbox = Box(self, horizontal=True, padding=(6,0), size_hint_expand=EXPAND_BOTH, size_hint_align=(0.0, 0.5)) tb.pack(hbox, 1, 2, 1, 1) hbox.show() rdg = Radio(self, state_value=0, text='Local branch') rdg.callback_changed_add(self._type_radio_changed_cb) hbox.pack_end(rdg) rdg.show() rd = Radio(self, state_value=1, text='Tracking branch') rd.callback_changed_add(self._type_radio_changed_cb) rd.group_add(rdg) hbox.pack_end(rd) rd.show() self.type_radio = rdg # starting revision fr = Frame(self, text='Starting revision', size_hint_expand=EXPAND_BOTH, size_hint_fill=FILL_BOTH) tb.pack(fr, 0, 3, 2, 1) fr.show() r = Rectangle(self.evas, size_hint_min=(300,200), size_hint_expand=EXPAND_BOTH) tb.pack(r, 0, 3, 2, 1) # TODO: use genlist to speedup population self.itc = GenlistItemClass(item_style='one_icon', text_get_func=self._gl_text_get, content_get_func=self._gl_content_get) li = Genlist(self, homogeneous=True, size_hint_expand=EXPAND_BOTH, size_hint_fill=FILL_BOTH) li.callback_selected_add(self._revision_selected_cb) fr.content = li li.show() self.rev_list = li # sep sep = Separator(self, horizontal=True, size_hint_expand=EXPAND_BOTH) tb.pack(sep, 0, 4, 2, 1) sep.show() # buttons hbox = Box(self, horizontal=True, size_hint_expand=EXPAND_HORIZ, size_hint_fill=FILL_BOTH) tb.pack(hbox, 0, 5, 2, 1) hbox.show() bt = Button(self, text='Close') bt.callback_clicked_add(lambda b: self.delete()) hbox.pack_end(bt) bt.show() sep = Separator(self, size_hint_expand=EXPAND_HORIZ) hbox.pack_end(sep) bt = Button(self, text='Create') bt.callback_clicked_add(self._create_clicked_cb) hbox.pack_end(bt) bt.show() # populate the revision list and show the popup self.populate() self.show() self.name_entry.focus = True