def __init__(self, parent, commit, show_full_msg=False): self.commit = commit Table.__init__(self, parent, padding=(5,5)) self.show() pic = GravatarPict(self) pic.size_hint_align = 0.0, 0.0 pic.email_set(commit.author_email) self.pack(pic, 0, 0, 1, 1) pic.show() if commit.committer and commit.committer != commit.author: committed = '<name>Committed by:</name> <b>{}</b><br>'.format( commit.committer) else: committed = '' text = '<name>{}</name> <b>{}</b> {}<br>{}<br>{}'.format( commit.sha[:9], commit.author, format_date(commit.commit_date), committed, utf8_to_markup(commit.title)) if show_full_msg: text += '<br><br>{}'.format(utf8_to_markup(commit.message)) en = Entry(self, text=text, line_wrap=ELM_WRAP_NONE, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) self.pack(en, 1, 0, 1, 1) en.show()
def select_torrent(self): sel = Fileselector(self.win) sel.expandable = False sel.path_set(os.path.expanduser("~")) sel.size_hint_weight_set(1.0, 1.0) sel.size_hint_align_set(-1.0, -1.0) sel.show() sf = Frame(self.win) sf.size_hint_weight_set(1.0, 1.0) sf.size_hint_align_set(-1.0, -1.0) sf.text = "Select torrent file" sf.content = sel sf.show() magnet = Entry(self.win) magnet.single_line = True magnet.scrollable = True if hasattr(magnet, "cnp_selection_get"): magnet.cnp_selection_get(ELM_SEL_TYPE_CLIPBOARD, ELM_SEL_FORMAT_TEXT) else: import pyperclip t = pyperclip.paste() if t is not None and t.startswith("magnet:"): magnet.entry = t magnet.show() mf = Frame(self.win) mf.size_hint_weight_set(1.0, 0.0) mf.size_hint_align_set(-1.0, 0.0) mf.text = "Or enter magnet URI here" mf.content = magnet mf.show() mbtn = Button(self.win) mbtn.text = "Done" mbtn.show() mbox = Box(self.win) mbox.size_hint_weight_set(1.0, 0.0) mbox.size_hint_align_set(-1.0, 0.0) mbox.horizontal = True mbox.pack_end(mf) mbox.pack_end(mbtn) mbox.show() box = Box(self.win) box.size_hint_weight = (1.0, 1.0) box.size_hint_align = (-1.0, -1.0) box.pack_end(sf) box.pack_end(mbox) box.show() inwin = InnerWindow(self.win) inwin.content = box sel.callback_done_add(self.add_torrent_cb) sel.callback_done_add(lambda x, y: inwin.delete()) mbtn.callback_clicked_add(self.add_magnet_uri_cb, magnet) mbtn.callback_clicked_add(lambda x: inwin.delete()) inwin.activate()
def _add_cb(bt, win, bx): en = Entry(win, scrollable=True, single_line=True, text="An entry", size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ) en.callback_focused_add(_focused_cb) en.callback_unfocused_add(_unfocused_cb) bx.pack_start(en) en.show()
def grid_clicked(obj): win = StandardWindow("grid", "Grid test", autodel=True, size=(480, 480)) if obj is None: win.callback_delete_request_add(lambda o: elementary.exit()) gd = Grid(win, size=(100, 100), size_hint_weight=EXPAND_BOTH) win.resize_object_add(gd) gd.show() en = Entry(win, scrollable=True, text="Entry text 2", single_line=True) gd.pack(en, 60, 20, 30, 10) en.show() bt = Button(win, text="Next API function", disabled=True) gd.pack(bt, 30, 0, 40, 10) bt.disabled = True bt.show() bt = Button(win, text="Button") gd.pack(bt, 0, 0, 20, 20) bt.show() bt = Button(win, text="Button") gd.pack(bt, 10, 10, 40, 20) bt.show() bt = Button(win, text="Button") gd.pack(bt, 10, 30, 20, 50) bt.show() bt = Button(win, text="Button") gd.pack(bt, 80, 80, 20, 20) bt.show() bt = Button(win, text="Change") bt.callback_clicked_add(cb_change) gd.pack(bt, 40, 40, 20, 20) bt.show() re = Rectangle(win.evas, color=(128, 0, 0, 128)) gd.pack(re, 40, 70, 20, 10) re.show() re = Rectangle(win.evas, color=(0, 128, 0, 128)) gd.pack(re, 60, 70, 10, 10) re.show() re = Rectangle(win.evas, color=(0, 0, 128, 128)) gd.pack(re, 40, 80, 10, 10) re.show() re = Rectangle(win.evas, color=(128, 0, 128, 128)) gd.pack(re, 50, 80, 10, 10) re.show() re = Rectangle(win.evas, color=(128, 64, 0, 128)) gd.pack(re, 60, 80, 10, 10) re.show() win.show()
def __init__(self, repo, win): self.repo = repo self.win = win self.confirmed = False StandardWindow.__init__(self, 'Egitu', 'Egitu', autodel=True) vbox = Box(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) self.resize_object_add(vbox) vbox.show() # title en = Entry(self, editable=False, text='<title><align=center>Commit changes</align></title>', size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ) vbox.pack_end(en) en.show() panes = Panes(self, content_left_size = 0.2, horizontal=True, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) vbox.pack_end(panes) panes.show() # message entry en = Entry(self, editable=True, scrollable=True, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) en.part_text_set('guide', 'Enter commit message here') panes.part_content_set("left", en) en.show() self.msg_entry = en # diff entry self.diff_entry = DiffedEntry(self) panes.part_content_set("right", self.diff_entry) self.diff_entry.show() # buttons hbox = Box(self, horizontal=True, size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ) vbox.pack_end(hbox) hbox.show() bt = Button(self, text="Cancel") bt.callback_clicked_add(lambda b: self.delete()) hbox.pack_end(bt) bt.show() bt = Button(self, text="Commit") bt.callback_clicked_add(self.commit_button_cb) hbox.pack_end(bt) bt.show() # show the window and give focus to the editable entry self.size = 500, 500 self.show() en.focus = True # load the diff repo.request_diff(self.diff_done_cb, only_staged=True)
def __init__(self, rent): Box.__init__(self, rent) self.parent = rent #This appears on the button in the main swmai window self.name = "Light DM" #The section in the main window the button is added to self.section = "System Settings" #Search terms that this module should appear for self.searchData = ["lightdm", "autologin", "login", "display"] #Command line argument to open this module directly self.launchArg = "--lightdm" #Should be none by default. This value is used internally by swami self.button = None self.icon = Icon(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) #Use FDO icons -> http://standards.freedesktop.org/icon-naming-spec/latest/ar01s04.html self.icon.standard_set('video-display') self.icon.show() self.mainBox = Box(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) self.mainBox.show() self.config = {} with open(LightDMConf) as f: for line in f: #Sections start with [ - such as [SeatDefaults] if line[0] != "[": setting, value = line.replace("\n", "").split("=") e = Entry(self) e.single_line_set(True) e.text = value e.show() f = Frame(self, size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ) f.text = setting f.content = e f.show() self.mainBox.pack_end(f) self.config[setting] = f buttonBox = Box(self, size_hint_weight = EXPAND_HORIZ, size_hint_align = FILL_BOTH) buttonBox.horizontal = True buttonSave = StandardButton(self, "Save Changes", "ok", self.savePressed) buttonSave.show() buttonReturn = StandardButton(self, "Back", "go-previous", self.returnPressed) buttonReturn.show() buttonBox.pack_end(buttonSave) buttonBox.pack_end(buttonReturn) buttonBox.show() self.pack_end(self.mainBox) self.pack_end(buttonBox)
def __init__(self, cmd, exec_cb): DialogWindow.__init__(self, _app_instance.win, 'egitu-review', 'Git Command Review', autodel=True, size=(300,50)) # main table (inside a padding frame) fr = Frame(self, style='default', text='Command to execute', size_hint_expand=EXPAND_BOTH, size_hint_fill=FILL_BOTH) self.resize_object_add(fr) fr.show() tb = Table(self, padding=(6,6), size_hint_expand=EXPAND_BOTH, size_hint_fill=FILL_BOTH) fr.content = tb tb.show() # cmd entry en = Entry(self, single_line=True, scrollable=True, text=utf8_to_markup(cmd), size_hint_expand=EXPAND_BOTH, size_hint_fill=FILL_BOTH) tb.pack(en, 0, 0, 2, 1) en.show() # buttons bt = Button(self, text='Close', size_hint_expand=EXPAND_HORIZ, size_hint_fill=FILL_HORIZ) bt.callback_clicked_add(lambda b: self.delete()) tb.pack(bt, 0, 1, 1, 1) bt.show() bt = Button(self, text='Execute', size_hint_expand=EXPAND_HORIZ, size_hint_fill=FILL_HORIZ) bt.callback_clicked_add(self._exec_clicked_cb, en, exec_cb) tb.pack(bt, 1, 1, 1, 1) bt.show() # self.show()
def focus3_clicked(obj, item=None): win = StandardWindow("focus3", "Focus 3", autodel=True, size=(320, 480)) win.focus_highlight_enabled = True bx = Box(win, size_hint_weight=EXPAND_BOTH) win.resize_object_add(bx) bx.show() en = Entry(win, scrollable=True, single_line=True, text="An entry", size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ) en.callback_focused_add(_focused_cb) en.callback_unfocused_add(_unfocused_cb) bx.pack_end(en) en.show() bt = Button(win, text="Add", focus_allow=False, size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ) bt.callback_clicked_add(_add_cb, win, bx) bx.pack_end(bt) bt.show() bt = Button(win, text="Del", focus_allow=False, size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ) bt.callback_clicked_add(_del_cb, bx) bx.pack_end(bt) bt.show() bt = Button(win, text="hide", focus_allow=False, size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ) bt.callback_clicked_add(_hide_cb) bx.pack_end(bt) bt.show() win.show()
def entry_anchor_clicked(obj, item=None): win = StandardWindow("entry", "Entry Anchor", autodel=True, size=(400, 400)) box = Box(win, size_hint_weight=EXPAND_BOTH) win.resize_object_add(box) entry = Entry(win, anchor_hover_style="popout", anchor_hover_parent=win) entry.text = "<a href=url:http://www.enlightenment.org/>Enlightenment</a>" entry.callback_anchor_clicked_add(anchor_clicked) entry.callback_anchor_hover_opened_add(anchor_hover_opened) entry.show() frame = Frame(win, size_hint_align=FILL_BOTH, text="Entry test", content=entry) frame.show() box.pack_end(frame) box.show() win.show()
def __init__(self, parent): InnerWindow.__init__(self, parent) vbox = Box(self) vbox.show() self.content = vbox title = Label(self, scale=2.0, text='Edone %s' % VERSION) title.show() vbox.pack_end(title) en = Entry(self, text=INFO, editable=False, scrollable=True, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) en.show() vbox.pack_end(en) sep = Separator(self, horizontal=True) sep.show() vbox.pack_end(sep) close = Button(self, text='Close') close.callback_clicked_add(lambda b: self.delete()) close.show() vbox.pack_end(close) self.activate()
def __init__(self, parent, app, branch): self.app = app self.branch = branch Popup.__init__(self, parent) self.part_text_set("title,text", "Delete branch") self.part_content_set("title,icon", Icon(self, standard="user-trash")) # main vertical box box = Box(self) self.content = box box.show() # sep sep = Separator(self, horizontal=True, size_hint_expand=EXPAND_BOTH) box.pack_end(sep) sep.show() # label en = Entry( self, editable=False, text="%s<br><br><hilight>%s</hilight><br>" % ("Are you sure you want to delete this branch?", branch.name), size_hint_expand=EXPAND_BOTH, size_hint_fill=FILL_BOTH, ) box.pack_end(en) en.show() # force checkbox ck = Check( self, text="Force delete (even if not fully merged)", size_hint_expand=EXPAND_BOTH, size_hint_align=(0.0, 0.5), ) box.pack_end(ck) ck.show() self.force_chk = ck # buttons sep = Separator(self, horizontal=True, size_hint_expand=EXPAND_BOTH) box.pack_end(sep) sep.show() bt = Button(self, text="Cancel") bt.callback_clicked_add(lambda b: self.delete()) self.part_content_set("button1", bt) bt.show() bt = Button(self, text="Delete branch") bt.callback_clicked_add(self._delete_btn_cb) self.part_content_set("button2", bt) bt.show() # self.show()
def __init__(self, parent, repo): self.repo = repo Popup.__init__(self, parent) self.part_text_set("title,text", "Add remote") tb = Table(self, padding=(3, 3), size_hint_expand=EXPAND_BOTH) self.content = tb tb.show() # name lb = Label(tb, text="Name") tb.pack(lb, 0, 0, 1, 1) lb.show() en = Entry( tb, editable=True, single_line=True, scrollable=True, size_hint_expand=EXPAND_BOTH, size_hint_fill=FILL_BOTH ) en.part_text_set("guide", "Name for the new remote") en.callback_changed_user_add(lambda e: self.err_unset()) tb.pack(en, 1, 0, 1, 1) en.show() self.name_entry = en # url lb = Label(tb, text="URL") tb.pack(lb, 0, 1, 1, 1) lb.show() en = Entry( tb, editable=True, single_line=True, scrollable=True, size_hint_expand=EXPAND_BOTH, size_hint_fill=FILL_BOTH ) en.part_text_set("guide", "git://git.example.com/repo.git") en.callback_changed_user_add(lambda e: self.err_unset()) tb.pack(en, 1, 1, 1, 1) en.show() self.url_entry = en # error label lb = Label(tb, text="", size_hint_expand=EXPAND_HORIZ) tb.pack(lb, 0, 2, 2, 1) lb.show() self.error_label = lb # buttons bt = Button(self, text="Cancel") bt.callback_clicked_add(lambda b: self.delete()) self.part_content_set("button1", bt) bt.show() bt = Button(self, text="Add remote") bt.callback_clicked_add(self._add_btn_cb) self.part_content_set("button2", bt) bt.show() self.show()
def entry_clicked(obj, item=None): win = StandardWindow("entry", "Entry", autodel=True) bx = Box(win, size_hint_weight=EXPAND_BOTH) win.resize_object_add(bx) bx.show() en = Entry(win, line_wrap=False, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) en.entry_set("This is an entry widget in this window that<br>" "uses markup <b>like this</> for styling and<br>" "formatting <em>like this</>, as well as<br>" "<a href=X><link>links in the text</></a>, so enter text<br>" "in here to edit it. By the way, links are<br>" "called <a href=anc-02>Anchors</a> so you will need<br>" "to refer to them this way.") en.callback_anchor_clicked_add(my_entry_anchor_test, en) bx.pack_end(en) en.show() bx2 = Box(win, horizontal=True, size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_BOTH) bt = Button(win, text="Clear", size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_BOTH) bt.callback_clicked_add(my_entry_bt_1, en) bx2.pack_end(bt) bt.show() bt = Button(win, text="Print", size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_BOTH) bt.callback_clicked_add(my_entry_bt_2, en) bx2.pack_end(bt) bt.show() bt = Button(win, text="Selection", size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_BOTH) bt.callback_clicked_add(my_entry_bt_3, en) bx2.pack_end(bt) bt.show() bt = Button(win, text="Insert", size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_BOTH) bt.callback_clicked_add(my_entry_bt_4, en) bx2.pack_end(bt) bt.show() bx.pack_end(bx2) bx2.show() en.focus_set(True) win.show()
def __init__(self, parent, app): self.app = app Popup.__init__(self, parent) self.part_text_set('title,text', 'Save current status') self.part_content_set('title,icon', SafeIcon(self, 'git-stash')) # main vertical box box = Box(self, size_hint_expand=EXPAND_BOTH, size_hint_fill=FILL_BOTH) self.content = box box.show() # separator sep = Separator(self, horizontal=True, size_hint_expand=EXPAND_HORIZ) box.pack_end(sep) sep.show() # description en = Entry(self, single_line=True, scrollable=True, size_hint_expand=EXPAND_BOTH, size_hint_fill=FILL_BOTH) en.part_text_set('guide', 'Stash description (or empty for the default)') en.text = 'WIP on ' + app.repo.status.head_describe box.pack_end(en) en.show() # include untracked ck = Check(self, text='Include untracked files', state=True, size_hint_expand=EXPAND_HORIZ, size_hint_align=(0.0,0.5)) box.pack_end(ck) ck.show() # separator sep = Separator(self, horizontal=True, size_hint_expand=EXPAND_HORIZ) box.pack_end(sep) sep.show() # buttons bt = Button(self, text='Close') bt.callback_clicked_add(lambda b: self.delete()) self.part_content_set('button1', bt) bt.show() bt = Button(self, text='Stash', content=SafeIcon(self, 'git-stash')) bt.callback_clicked_add(self._stash_clicked_cb, en, ck) self.part_content_set('button2', bt) bt.show() # focus to the entry and show en.select_all() en.focus = True self.show()
def cnp_clicked(obj): win = StandardWindow("copypaste", "CopyPaste", autodel=True) if obj is None: win.callback_delete_request_add(lambda o: elementary.exit()) gd = Grid(win, size=(100, 100), size_hint_weight=EXPAND_BOTH) win.resize_object_add(gd) gd.show() en = Entry(win, scrollable=True, line_wrap=ELM_WRAP_CHAR, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH, text="Elementary provides ") gd.pack(en, 10, 10, 60, 30) en.show() bt = Button(win, text="Copy from left entry") bt.callback_clicked_add(bt_copy_clicked, en) gd.pack(bt, 70, 10, 22, 30) bt.show() bt = Button(win, text="Clear clipboard") bt.callback_clicked_add(bt_clear_clicked, en) gd.pack(bt, 70, 70, 22, 20) bt.show() en = Entry(win, scrollable=True, line_wrap=ELM_WRAP_CHAR, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH, text="rich copying and pasting functionality,") gd.pack(en, 10, 40, 60, 30) en.show() bt = Button(win, text="Paste to left entry") bt.callback_clicked_add(bt_paste_clicked, en) gd.pack(bt, 70, 40, 22, 30) bt.show() lb = Label(win, text="<b>Clipboard:</b>", size_hint_weight=(0.0, 0.0), size_hint_align=FILL_BOTH) gd.pack(lb, 10, 70, 60, 10) lb.show() global glb glb = Label(win, text="", size_hint_weight=(0.0, 0.0), size_hint_align=FILL_BOTH) gd.pack(glb, 10, 80, 60, 10) glb.show() win.size = 480, 200 win.show()
def cursor_clicked(obj, item=None): win = StandardWindow("cursors", "Cursors", autodel=True, size=(320, 480)) win.autodel_set(True) bx = Box(win, size_hint_weight=EXPAND_BOTH) win.resize_object_add(bx) bx.show() ck = Clock(win, cursor="clock") bx.pack_end(ck) ck.show() bt = Button(win, text="Coffee Mug", cursor="coffee_mug") bx.pack_end(bt) bt.show() bt = Button(win, text="Cursor unset", cursor="bogosity") bt.cursor_unset() bx.pack_end(bt) bt.show() lst = List(win, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH, cursor="watch") lst.item_append("watch over list") lst.item_append("watch over list") bx.pack_end(lst) lst.go() lst.show() en = Entry(win, scrollable=True, single_line=True, entry="Xterm cursor", size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ, cursor="xterm") bx.pack_end(en) en.show() win.show()
def __init__(self, parent, repo, commit): self.repo = repo self.commit = commit Table.__init__(self, parent, padding=(5,5)) self.show() pic = GravatarPict(self) pic.email_set(commit.author_email) self.pack(pic, 0, 0, 1, 1) pic.show() text = u'<name>{}</name> <b>{}</b> {}<br><br>{}'.format(commit.sha[:9], commit.author, format_date(commit.commit_date), commit.title) en = Entry(self, text=text) en.line_wrap = ELM_WRAP_NONE en.size_hint_weight = EXPAND_BOTH en.size_hint_align = FILL_BOTH self.pack(en, 1, 0, 1, 1) en.show()
def entry_anchor_clicked(obj, item=None): win = StandardWindow("entry", "Entry Anchor", autodel=True, size=(400,400)) box = Box(win, size_hint_weight=EXPAND_BOTH) win.resize_object_add(box) entry = Entry(win, anchor_hover_style="popout", anchor_hover_parent=win) entry.text = "<a href=url:http://www.enlightenment.org/>Enlightenment</a>" entry.callback_anchor_clicked_add(anchor_clicked) entry.callback_anchor_hover_opened_add(anchor_hover_opened) entry.show() frame = Frame(win, size_hint_align=FILL_BOTH, text="Entry test", content=entry) frame.show() box.pack_end(frame) box.show() win.show()
def elm_input_events_clicked(obj, item=None): win = StandardWindow("inputevents", "Input Events Test", autodel=True) if obj is None: win.callback_delete_request_add(lambda o: elementary.exit()) box = Box(win, size_hint_weight=EXPAND_BOTH) win.resize_object_add(box) box.show() entry = Entry(win, scrollable=True, size_hint_align=FILL_BOTH, size_hint_weight=(1.0, 0.2)) entry.text = ( "This example will show how Elementary input events are handled. " "Typing in this entry will log in the entry box below all events " "caught by event handlers set to this Entry widget and its parent, " "the Window widget. Key up events are checked for in the callback " "and won't propagate to a parent widget." ) entry.show() log_entry = Entry(win, editable=False, scrollable=True, focus_allow=False, size_hint_align=FILL_BOTH, size_hint_weight=(1.0, 0.8)) log_entry.callback_changed_add(changed_cb) log_entry.show() btn = Button(win, text="Clear log", focus_allow=False) btn.callback_clicked_add(lambda x: setattr(log_entry, "entry", "")) btn.show() box.pack_end(entry) box.pack_end(log_entry) box.pack_end(btn) entry.elm_event_callback_add(events_cb, log_entry) entry.markup_filter_append(filter_cb) win.elm_event_callback_add(events_cb, log_entry) win.resize(640, 480) win.show() entry.focus = True
def __init__(self, parent, done_cb, title, text=None, guide=None, not_empty=True): self.done_cb = done_cb Popup.__init__(self, parent) self.part_text_set('title,text', title) box = Box(self, padding=(0,4)) self.content = box box.show() if text: lb = Label(self, text=text) box.pack_end(lb) lb.show() en = Entry(self, single_line=True, scrollable=True, size_hint_expand=EXPAND_BOTH, size_hint_fill=FILL_BOTH) if guide is not None: en.part_text_set('guide', guide) box.pack_end(en) en.show() sep = Separator(self, horizontal=True, size_hint_expand=EXPAND_HORIZ) box.pack_end(sep) sep.show() b = Button(self, text='Cancel') b.callback_clicked_add(lambda b: self.delete()) self.part_content_set('button1', b) b.show() b = Button(self, text='OK', disabled=not_empty) b.callback_clicked_add(self._confirmed_cb, en, done_cb) self.part_content_set('button2', b) b.show() if not_empty is True: en.callback_changed_user_add(self._entry_changed, b) en.focus = True self.show()
def __init__(self, parent, title=None, msg=None, ok_cb=None): Popup.__init__(self, parent) self.part_text_set('title,text', title or 'Are you sure?') en = Entry(self, scrollable=False, editable=False, text=msg or 'Please confirm', size_hint_expand=EXPAND_BOTH, size_hint_fill=FILL_BOTH) self.content = en en.show() b = Button(self, text='Cancel') b.callback_clicked_add(lambda b: self.delete()) self.part_content_set('button1', b) b.show() b = Button(self, text='Yes, do it!') b.callback_clicked_add(self._confirmed_cb, ok_cb) self.part_content_set('button2', b) b.show() self.show()
def cursor_clicked(obj, item=None): win = StandardWindow("cursors", "Cursors", autodel=True, size=(320,480)) win.autodel_set(True) bx = Box(win, size_hint_weight=EXPAND_BOTH) win.resize_object_add(bx) bx.show() ck = Clock(win, cursor="clock") bx.pack_end(ck) ck.show() bt = Button(win, text="Coffee Mug", cursor="coffee_mug") bx.pack_end(bt) bt.show() bt = Button(win, text="Cursor unset", cursor="bogosity") bt.cursor_unset() bx.pack_end(bt) bt.show() lst = List(win, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH, cursor="watch") lst.item_append("watch over list") lst.item_append("watch over list") bx.pack_end(lst) lst.go() lst.show() en = Entry(win, scrollable=True, single_line=True, entry="Xterm cursor", size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ, cursor="xterm") bx.pack_end(en) en.show() win.show()
def __init__(self, app): self.app = app Popup.__init__(self, app.win) self.part_text_set('title,text', 'Discard local changes') self.part_content_set('title,icon', Icon(self, standard='user-trash')) # main table tb = Table(self, padding=(0,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, 1, 1) sep.show() # warning label en = Entry(self, editable=False, text='<warning>WARNING: This operation is not reversible!</warning><br>' \ 'Selected files (or ALL files, if nothing is selected) will be ' \ 'reverted to the state of the last commit.', size_hint_expand=EXPAND_BOTH, size_hint_fill=FILL_BOTH) tb.pack(en, 0, 1, 1, 1) en.show() # changes list r = Rectangle(self.evas, size_hint_min=(300,200), size_hint_expand=EXPAND_BOTH, size_hint_fill=FILL_BOTH) li = List(self, multi_select=True, size_hint_expand=EXPAND_BOTH, size_hint_fill=FILL_BOTH) li.callback_selected_add(self._list_selection_changed_cb) li.callback_unselected_add(self._list_selection_changed_cb) tb.pack(li, 0, 2, 1, 1) tb.pack(r, 0, 2, 1, 1) for path in sorted(self.app.repo.status.changes): mod, staged, name, new_name = self.app.repo.status.changes[path] icon = Icon(self, standard='git-mod-'+mod) check = Check(self, text='', state=staged, disabled=True) label = '{} → {}'.format(name, new_name) if new_name else name it = li.item_append(label, icon, check) it.data['mod'] = mod li.go() li.show() self.file_list = li # delete untracked check ck = Check(self, text='Also delete untracked files', state=True, size_hint_expand=EXPAND_BOTH, size_hint_align=(0.0,0.5)) tb.pack(ck, 0, 3, 1, 1) ck.show() self.untracked_chk = ck # sep sep = Separator(self, horizontal=True, size_hint_expand=EXPAND_BOTH) tb.pack(sep, 0, 4, 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.show() bt = Button(self, text="Discard EVERYTHING!", content=Icon(self, standard='user-trash')) bt.callback_clicked_add(self._confirm_clicked_cb) self.part_content_set('button2', bt) bt.show() self.confirm_btn = bt # self.show()
class AboutWindow(Window): __initialized = False def __init__(self, parent, title="About", standardicon="dialog-information", \ version="N/A", authors="No One", \ licen="GPL", webaddress="", info="Something, something, turtles"): if AboutWindow.__initialized: raise InstanceError("You can't create more than 1 instance of AboutWindow") AboutWindow.__initialized = True Window.__init__(self, title, ELM_WIN_DIALOG_BASIC, autodel=True) self.callback_delete_request_add(self.close_inst) background = Background(self, size_hint_weight=EXPAND_BOTH) self.resize_object_add(background) background.show() fr = Frame(self, style='pad_large', size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) self.resize_object_add(fr) fr.show() hbox = Box(self, horizontal=True, padding=(12,12)) fr.content = hbox hbox.show() vbox = Box(self, align=(0.0,0.0), padding=(6,6), size_hint_weight=EXPAND_VERT, size_hint_align=FILL_VERT) hbox.pack_end(vbox) vbox.show() # icon + version ic = Icon(self, size_hint_min=(64,64)) ic.standard_set(standardicon) vbox.pack_end(ic) ic.show() lb = Label(self, text=('Version: %s') % version) vbox.pack_end(lb) lb.show() sep = Separator(self, horizontal=True) vbox.pack_end(sep) sep.show() # buttons bt = Button(self, text=(title), size_hint_align=FILL_HORIZ) bt.callback_clicked_add(lambda b: self.entry.text_set(info)) vbox.pack_end(bt) bt.show() bt = Button(self, text=('Website'),size_hint_align=FILL_HORIZ) bt.callback_clicked_add(lambda b: xdg_open(webaddress)) vbox.pack_end(bt) bt.show() bt = Button(self, text=('Authors'), size_hint_align=FILL_HORIZ) bt.callback_clicked_add(lambda b: self.entry.text_set(authors)) vbox.pack_end(bt) bt.show() bt = Button(self, text=('License'), size_hint_align=FILL_HORIZ) bt.callback_clicked_add(lambda b: self.entry.text_set(licen)) vbox.pack_end(bt) bt.show() # main text self.entry = Entry(self, editable=False, scrollable=True, text=info, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) self.entry.callback_anchor_clicked_add(lambda e,i: xdg_open(i.name)) hbox.pack_end(self.entry) self.entry.show() self.resize(400, 200) self.show() def close_inst(self, obj): AboutWindow.__initialized = False
def __init__(self, parent, app): self.app = app Popup.__init__(self, parent) # title self.part_text_set('title,text', 'Clone') self.part_content_set('title,icon', SafeIcon(self, 'egitu')) # main table tb = Table(self, padding=(0,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_HORIZ) tb.pack(sep, 0, 0, 2, 1) sep.show() # url en = Entry(self, single_line=True, scrollable=True, size_hint_expand=EXPAND_BOTH, size_hint_fill=FILL_BOTH) en.part_text_set('guide', 'Path or URL to clone') tb.pack(en, 0, 1, 2, 1) en.show() self.url_entry = en # parent folder en = Entry(self, single_line=True, scrollable=True, size_hint_expand=EXPAND_BOTH, size_hint_fill=FILL_BOTH) en.part_text_set('guide', 'Parent folder to clone into') tb.pack(en, 0, 2, 1, 1) en.show() bt = Button(self, text='', content=SafeIcon(self, 'folder')) bt.callback_clicked_add(self._folder_clicked_cb) tb.pack(bt, 1, 2, 1, 1) bt.show() self.folder_entry = en # shallow check ck = Check(self, text='Shallow (no history and no branches, faster)', size_hint_expand=EXPAND_BOTH, size_hint_align=(0.0,0.5)) tb.pack(ck, 0, 3, 2, 1) ck.show() self.shallow_check = ck # output entry en = CommandOutputEntry(self, min_size=(400, 150)) tb.pack(en, 0, 4, 2, 1) en.show() self.output_entry = en # sep sep = Separator(self, horizontal=True, size_hint_expand=EXPAND_HORIZ) tb.pack(sep, 0, 5, 2, 1) sep.show() # bottons bt = Button(self, text='Close') bt.callback_clicked_add(lambda b: self.delete()) self.part_content_set('button1', bt) bt.show() self.close_btn = bt bt = Button(self, text='Clone') bt.callback_clicked_add(self._clone_clicked_cb) self.part_content_set('button2', bt) bt.show() self.clone_btn = bt # self.show()
class Interface(object): def __init__( self ): self.mainWindow = StandardWindow("epad", "Untitled - ePad", size=(600, 400)) self.mainWindow.callback_delete_request_add(self.closeChecks) self.mainWindow.elm_event_callback_add(self.eventsCb) icon = Icon(self.mainWindow) icon.size_hint_weight_set(EVAS_HINT_EXPAND, EVAS_HINT_EXPAND) icon.size_hint_align_set(EVAS_HINT_FILL, EVAS_HINT_FILL) icon.standard_set('accessories-text-editor') # assumes image icon is in local dir, may need to change later icon.show() self.mainWindow.icon_object_set(icon.object_get()) self.mainBox = Box(self.mainWindow, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) self.mainBox.show() self.mainTb = Toolbar(self.mainWindow, homogeneous=False, size_hint_weight=(0.0, 0.0), size_hint_align=(EVAS_HINT_FILL, 0.0)) self.mainTb.menu_parent = self.mainWindow self.mainTb.item_append("document-new", "New", self.newPress) self.mainTb.item_append("document-open", "Open", self.openPress) self.mainTb.item_append("document-save", "Save", self.savePress) self.mainTb.item_append("document-save-as", "Save As", self.saveAsPress) # -- Edit Dropdown Menu -- tb_it = self.mainTb.item_append("edit", "Edit") tb_it.menu = True menu = tb_it.menu menu.item_add(None, "Copy", "edit-copy", self.copyPress) menu.item_add(None, "Paste", "edit-paste", self.pastePress) menu.item_add(None, "Cut", "edit-cut", self.cutPress) menu.item_separator_add() menu.item_add(None, "Select All", "edit-select-all", self.selectAllPress) # ----------------------- # self.mainTb.item_append("settings", "Options", self.optionsPress) self.mainTb.item_append("dialog-information", "About", self.aboutPress) self.mainEn = Entry(self.mainWindow, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) self.mainEn.callback_changed_user_add(self.textEdited) self.mainEn.scrollable_set(True) # creates scrollbars rather than enlarge window self.mainEn.line_wrap_set(False) # does not allow line wrap (can be changed by user) self.mainEn.autosave_set(False) # set to false to reduce disk I/O self.mainEn.elm_event_callback_add(self.eventsCb) self.mainEn.markup_filter_append(self.textFilter) self.mainEn.show() self.mainTb.show() self.mainBox.pack_end(self.mainTb) self.mainBox.pack_end(self.mainEn) #Build our file selector for saving/loading files self.fileBox = Box(self.mainWindow, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) self.fileBox.show() self.fileLabel = Label(self.mainWindow, size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_BOTH) self.fileLabel.text = "" self.fileLabel.show() self.fileSelector = Fileselector(self.mainWindow, is_save=False, expandable=False, folder_only=False, path=os.getenv("HOME"), size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) self.fileSelector.callback_done_add(self.fileSelected) #self.fileSelector.callback_selected_add(fs_cb_selected, win) #self.fileSelector.callback_directory_open_add(fs_cb_directory_open, win) self.fileSelector.show() self.fileBox.pack_end(self.fileLabel) self.fileBox.pack_end(self.fileSelector) # the flip object has the file selector on one side and the GUI on the other self.flip = Flip(self.mainWindow, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) self.flip.part_content_set("front", self.mainBox) self.flip.part_content_set("back", self.fileBox) self.mainWindow.resize_object_add(self.flip) self.flip.show() self.isSaved = True self.isNewFile = False self.confirmPopup = None def newPress( self, obj, it ): self.newFile() it.selected_set(False) def openPress( self, obj, it ): self.openFile() it.selected_set(False) def savePress( self, obj, it ): self.saveFile() it.selected_set(False) def saveAsPress( self, obj, it ): self.saveAs() it.selected_set(False) def optionsPress( self, obj, it ): it.selected_set(False) def copyPress( self, obj, it ): self.mainEn.selection_copy() it.selected_set(False) def pastePress( self, obj, it ): self.mainEn.selection_paste() it.selected_set(False) def cutPress( self, obj, it ): self.mainEn.selection_cut() it.selected_set(False) def selectAllPress( self, obj, it ): self.mainEn.select_all() it.selected_set(False) def textEdited( self, obj ): ourFile = self.mainEn.file_get()[0] if ourFile and not self.isNewFile: self.mainWindow.title_set("*%s - ePad"%self.mainEn.file_get()[0].split("/")[len(self.mainEn.file_get()[0].split("/"))-1]) else: self.mainWindow.title_set("*Untitlted - ePad") self.isSaved = False def fileSelected( self, fs, file_selected, onStartup=False ): if not onStartup: self.flip.go(ELM_FLIP_INTERACTION_ROTATE) print(file_selected) IsSave = fs.is_save_get() if file_selected: if IsSave: newfile = open(file_selected,'w') # creates new file tmp_text = self.mainEn.entry_get() newfile.write(tmp_text) newfile.close() self.mainEn.file_set(file_selected, ELM_TEXT_FORMAT_PLAIN_UTF8) self.mainEn.entry_set(tmp_text) self.mainEn.file_save() self.mainWindow.title_set("%s - ePad" % file_selected.split("/")[len(file_selected.split("/"))-1]) self.isSaved = True self.isNewFile = False else: try: self.mainEn.file_set(file_selected, ELM_TEXT_FORMAT_PLAIN_UTF8) except RuntimeError: print("Empty file: {0}".format(file_selected)) self.mainWindow.title_set("%s - ePad" % file_selected.split("/")[len(file_selected.split("/"))-1]) def aboutPress( self, obj, it ): #About popup self.popupAbout = Popup(self.mainWindow, size_hint_weight=EXPAND_BOTH) self.popupAbout.text = "ePad - A simple text editor written in python and elementary<br><br> " \ "By: Jeff Hoogland" bt = Button(self.mainWindow, text="Done") bt.callback_clicked_add(self.aboutClose) self.popupAbout.part_content_set("button1", bt) self.popupAbout.show() it.selected_set(False) def aboutClose( self, bt ): self.popupAbout.delete() def newFile( self , obj=None, ignoreSave=False ): if self.isSaved == True or ignoreSave == True: trans = Transit() trans.object_add(self.mainEn) trans.auto_reverse = True trans.effect_wipe_add( ELM_TRANSIT_EFFECT_WIPE_TYPE_HIDE, ELM_TRANSIT_EFFECT_WIPE_DIR_RIGHT) trans.duration = 0.5 trans.go() time.sleep(0.5) self.mainWindow.title_set("Untitlted - ePad") self.mainEn.delete() self.mainEn = Entry(self.mainWindow, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) self.mainEn.callback_changed_user_add(self.textEdited) self.mainEn.scrollable_set(True) # creates scrollbars rather than enlarge window self.mainEn.line_wrap_set(False) # does not allow line wrap (can be changed by user) self.mainEn.autosave_set(False) # set to false to reduce disk I/O self.mainEn.elm_event_callback_add(self.eventsCb) self.mainEn.markup_filter_append(self.textFilter) self.mainEn.show() self.mainBox.pack_end(self.mainEn) self.isNewFile = True elif self.confirmPopup == None: self.confirmSave(self.newFile) def openFile( self, obj=None, ignoreSave=False ): if self.isSaved == True or ignoreSave == True: self.fileSelector.is_save_set(False) self.fileLabel.text = "<b>Select a text file to open:</b>" self.flip.go(ELM_FLIP_ROTATE_YZ_CENTER_AXIS) elif self.confirmPopup == None: self.confirmSave(self.openFile) def confirmSave( self, ourCallback=None ): self.confirmPopup = Popup(self.mainWindow, size_hint_weight=EXPAND_BOTH) self.confirmPopup.part_text_set("title,text","File Unsaved") if self.mainEn.file_get()[0]: self.confirmPopup.text = "Save changes to '%s'?" % self.mainEn.file_get()[0].split("/")[len(self.mainEn.file_get()[0].split("/"))-1] else: self.confirmPopup.text = "Save changes to 'Untitlted'?" # Close without saving button no_btt = Button(self.mainWindow) no_btt.text = "No" no_btt.callback_clicked_add(self.closePopup, self.confirmPopup) if ourCallback is not None: no_btt.callback_clicked_add(ourCallback, True) no_btt.show() # cancel close request cancel_btt = Button(self.mainWindow) cancel_btt.text = "Cancel" cancel_btt.callback_clicked_add(self.closePopup, self.confirmPopup) cancel_btt.show() # Save the file and then close button sav_btt = Button(self.mainWindow) sav_btt.text = "Yes" sav_btt.callback_clicked_add(self.saveFile) sav_btt.callback_clicked_add(self.closePopup, self.confirmPopup) sav_btt.show() # add buttons to popup self.confirmPopup.part_content_set("button1", no_btt) self.confirmPopup.part_content_set("button2", cancel_btt) self.confirmPopup.part_content_set("button3", sav_btt) self.confirmPopup.show() def saveAs( self ): self.fileSelector.is_save_set(True) self.fileLabel.text = "<b>Save new file to where:</b>" self.flip.go(ELM_FLIP_ROTATE_XZ_CENTER_AXIS) def saveFile( self, obj=False ): if self.mainEn.file_get()[0] == None or self.isNewFile: self.saveAs() else: self.mainEn.file_save() self.mainWindow.title_set("%s - ePad"%self.mainEn.file_get()[0].split("/")[len(self.mainEn.file_get()[0].split("/"))-1]) self.isSaved = True def closeChecks( self, obj ): print(self.isSaved) if self.isSaved == False and self.confirmPopup == None: self.confirmSave(self.closeApp) else: self.closeApp() def closePopup( self, bt, confirmPopup ): self.confirmPopup.delete() self.confirmPopup = None def closeApp( self, obj=False, trash=False ): elementary.exit() def eventsCb( self, obj, src, event_type, event ): #print event_type #print event.key #print "Control Key Status: %s" %event.modifier_is_set("Control") #print "Shift Key Status: %s" %event.modifier_is_set("Shift") #print event.modifier_is_set("Alt") if event.modifier_is_set("Control"): if event.key.lower() == "n": self.newFile() elif event.key.lower() == "s" and event.modifier_is_set("Shift"): self.saveAs() elif event.key.lower() == "s": self.saveFile() elif event.key.lower() == "o": self.openFile() def textFilter( self, obj, theText, data ): #print theText #Block ctrl+hot keys if theText == "" or theText == "" or theText == "": return None else: return theText def launch( self, startingFile=False ): if startingFile: self.fileSelected(self.fileSelector, startingFile, True) self.mainWindow.show()
class CommandOutputEntry(Table): def __init__(self, parent, min_size=(0,0)): Table.__init__(self, parent, size_hint_expand=EXPAND_BOTH, size_hint_fill=FILL_BOTH) self._entry = Entry(self, scrollable=True, editable=False, line_wrap=ELM_WRAP_NONE, size_hint_expand=EXPAND_BOTH, size_hint_fill=FILL_BOTH) self._wheel = Progressbar(self, style='wheel', pulse_mode=True, size_hint_expand=EXPAND_BOTH) self._rect = Rectangle(self.evas, size_hint_min=min_size, size_hint_expand=EXPAND_BOTH, color=(0,0,0,0)) self.pack(self._entry, 0, 0, 1, 1) self.pack(self._rect, 0, 0, 1, 1) self.pack(self._wheel, 0, 0, 1, 1) self._last_was_carriage = False self._entry.show() self._rect.show() self.show() @property def text(self): return self._entry.text @text.setter def text(self, text): self._entry.text = text def pulse_start(self): self._rect.repeat_events = False self._wheel.pulse(True) self._wheel.show() def pulse_stop(self): self._rect.repeat_events = True self._wheel.pulse(False) self._wheel.hide() def successfull(self): self._entry.entry_append('<success>Operation successfully completed.</success><br>') def failure(self): self._entry.entry_append('<failure>Error! Something goes wrong.</failure><br>') def error_set(self, text): self._entry.text = '<failure>Error:</failure><br>%s' % text def append_raw(self, line, sep=None): if self._last_was_carriage is True: self._entry.cursor_selection_begin() self._entry.cursor_line_end_set() self._entry.cursor_selection_end() self._entry.entry_insert('') if sep == '\n': self._entry.entry_append(line + '<br>') self._entry.cursor_end_set() self._last_was_carriage = False elif sep == '\r': self._entry.entry_append(line) self._last_was_carriage = True else: self._entry.entry_append(line) self._last_was_carriage = False
class AboutWin(DialogWindow): def __init__(self, parent): DialogWindow.__init__(self, parent, 'egitu-info', 'Egitu', autodel=True) fr = Frame(self, style='pad_large', size_hint_expand=EXPAND_BOTH, size_hint_align=FILL_BOTH) self.resize_object_add(fr) fr.show() hbox = Box(self, horizontal=True, padding=(12,12)) fr.content = hbox hbox.show() vbox = Box(self, align=(0.0,0.0), padding=(6,6), size_hint_expand=EXPAND_VERT, size_hint_fill=FILL_VERT) hbox.pack_end(vbox) vbox.show() # icon + version ic = SafeIcon(self, 'egitu', size_hint_min=(64,64)) vbox.pack_end(ic) ic.show() lb = Label(self, text='Version: %s' % __version__) vbox.pack_end(lb) lb.show() sep = Separator(self, horizontal=True) vbox.pack_end(sep) sep.show() # buttons bt = Button(self, text='Egitu', size_hint_fill=FILL_HORIZ) bt.callback_clicked_add(lambda b: self.entry.text_set(INFO)) vbox.pack_end(bt) bt.show() bt = Button(self, text='Website',size_hint_align=FILL_HORIZ) bt.callback_clicked_add(lambda b: xdg_open(HOMEPAGE)) vbox.pack_end(bt) bt.show() bt = Button(self, text='Authors', size_hint_align=FILL_HORIZ) bt.callback_clicked_add(lambda b: self.entry.text_set(AUTHORS)) vbox.pack_end(bt) bt.show() bt = Button(self, text='License', size_hint_align=FILL_HORIZ) bt.callback_clicked_add(lambda b: self.entry.text_set(LICENSE)) vbox.pack_end(bt) bt.show() # main text self.entry = Entry(self, editable=False, scrollable=True, text=INFO, size_hint_expand=EXPAND_BOTH, size_hint_fill=FILL_BOTH) self.entry.callback_anchor_clicked_add(lambda e,i: xdg_open(i.name)) hbox.pack_end(self.entry) self.entry.show() self.resize(400, 200) self.show()
class Interface(object): def __init__(self): self.mainWindow = StandardWindow("epad", "Untitled - ePad", size=(600, 400)) self.mainWindow.callback_delete_request_add(self.closeChecks) self.mainWindow.elm_event_callback_add(self.eventsCb) icon = Icon(self.mainWindow, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) icon.standard_set('accessories-text-editor') icon.show() self.mainWindow.icon_object_set(icon.object_get()) self.mainBox = Box(self.mainWindow, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) self.mainBox.show() self.mainTb = ePadToolbar(self, self.mainWindow) self.mainTb.show() self.mainBox.pack_end(self.mainTb) # Initialize Text entry box print("Word wrap Initialized: {0}".format(self.wordwrap)) self.entryInit() # Add label to show current cursor position if SHOW_POS: self.line_label = Label(self.mainWindow, size_hint_weight=EXPAND_HORIZ, size_hint_align=ALIGN_RIGHT) self.curChanged(self.mainEn, self.line_label) self.line_label.show() self.mainBox.pack_end(self.line_label) self.mainEn.callback_cursor_changed_add(self.curChanged, self.line_label) # Build our file selector for saving/loading files self.fileBox = Box(self.mainWindow, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) self.fileBox.show() self.fileLabel = Label(self.mainWindow, size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_BOTH, text="") self.fileLabel.show() self.fileSelector = Fileselector(self.mainWindow, is_save=False, expandable=False, folder_only=False, path=os.getenv("HOME"), size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) self.fileSelector.callback_done_add(self.fileSelected) self.fileSelector.show() self.fileBox.pack_end(self.fileLabel) self.fileBox.pack_end(self.fileSelector) # Flip object has the file selector on one side # and the GUI on the other self.flip = Flip(self.mainWindow, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) self.flip.part_content_set("front", self.mainBox) self.flip.part_content_set("back", self.fileBox) self.mainWindow.resize_object_add(self.flip) self.flip.show() self.isSaved = True self.isNewFile = False self.confirmPopup = None def entryInit(self): self.mainEn = Entry(self.mainWindow, scrollable=True, line_wrap=self.wordwrap, autosave=False, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) self.mainEn.callback_changed_user_add(self.textEdited) self.mainEn.elm_event_callback_add(self.eventsCb) # self.mainEn.markup_filter_append(self.textFilter) self.mainEn.show() self.mainBox.pack_end(self.mainEn) def curChanged(self, entry, label): # get linear index into current text index = entry.cursor_pos_get() # Replace <br /> tag with single char # to simplify (line, col) calculation tmp_text = entry.entry_get().replace("<br/>", "\n") line = tmp_text[:index].count("\n") + 1 col = len(tmp_text[:index].split("\n")[-1]) + 1 # Update label text with line, col label.text = "Ln {0} Col {1} ".format(line, col) def textEdited(self, obj): current_file = self.mainEn.file[0] current_file = \ os.path.basename(current_file) if \ current_file and not self.isNewFile else \ "Untitled" self.mainWindow.title = "*%s - ePad" % (current_file) self.isSaved = False def fileSelected(self, fs, file_selected, onStartup=False): if not onStartup: self.flip.go(ELM_FLIP_INTERACTION_ROTATE) print(file_selected) IsSave = fs.is_save_get() if file_selected: if IsSave: newfile = open(file_selected, 'w') tmp_text = self.mainEn.entry_get() newfile.write(tmp_text) newfile.close() self.mainEn.file_set(file_selected, ELM_TEXT_FORMAT_PLAIN_UTF8) self.mainEn.entry_set(tmp_text) self.mainEn.file_save() self.mainWindow.title_set("%s - ePad" % os.path.basename(file_selected)) self.isSaved = True self.isNewFile = False else: try: self.mainEn.file_set(file_selected, ELM_TEXT_FORMAT_PLAIN_UTF8) except RuntimeError: print("Empty file: {0}".format(file_selected)) self.mainWindow.title_set("%s - ePad" % os.path.basename(file_selected)) def newFile(self, obj=None, ignoreSave=False): if self.isSaved is True or ignoreSave is True: trans = Transit() trans.object_add(self.mainEn) trans.auto_reverse = True trans.effect_wipe_add(ELM_TRANSIT_EFFECT_WIPE_TYPE_HIDE, ELM_TRANSIT_EFFECT_WIPE_DIR_RIGHT) trans.duration = 0.5 trans.go() time.sleep(0.5) self.mainWindow.title_set("Untitled - ePad") self.mainEn.delete() self.entryInit() self.isNewFile = True elif self.confirmPopup is None: self.confirmSave(self.newFile) def openFile(self, obj=None, ignoreSave=False): if self.isSaved is True or ignoreSave is True: self.fileSelector.is_save_set(False) self.fileLabel.text = "<b>Select a text file to open:</b>" self.flip.go(ELM_FLIP_ROTATE_YZ_CENTER_AXIS) elif self.confirmPopup is None: self.confirmSave(self.openFile) def confirmSave(self, ourCallback=None): self.confirmPopup = Popup(self.mainWindow, size_hint_weight=EXPAND_BOTH) self.confirmPopup.part_text_set("title,text", "File Unsaved") current_file = self.mainEn.file[0] current_file = \ os.path.basename(current_file) if current_file else "Untitled" self.confirmPopup.text = "Save changes to '%s'?" % (current_file) # Close without saving button no_btt = Button(self.mainWindow) no_btt.text = "No" no_btt.callback_clicked_add(self.closePopup, self.confirmPopup) if ourCallback is not None: no_btt.callback_clicked_add(ourCallback, True) no_btt.show() # cancel close request cancel_btt = Button(self.mainWindow) cancel_btt.text = "Cancel" cancel_btt.callback_clicked_add(self.closePopup, self.confirmPopup) cancel_btt.show() # Save the file and then close button sav_btt = Button(self.mainWindow) sav_btt.text = "Yes" sav_btt.callback_clicked_add(self.saveFile) sav_btt.callback_clicked_add(self.closePopup, self.confirmPopup) sav_btt.show() # add buttons to popup self.confirmPopup.part_content_set("button1", no_btt) self.confirmPopup.part_content_set("button2", cancel_btt) self.confirmPopup.part_content_set("button3", sav_btt) self.confirmPopup.show() def saveAs(self): self.fileSelector.is_save_set(True) self.fileLabel.text = "<b>Save new file to where:</b>" self.flip.go(ELM_FLIP_ROTATE_XZ_CENTER_AXIS) def saveFile(self, obj=False): if self.mainEn.file_get()[0] is None or self.isNewFile: self.saveAs() else: self.mainEn.file_save() self.mainWindow.title_set("%s - ePad" % os.path.basename(self.mainEn.file[0])) self.isSaved = True def closeChecks(self, obj): print(self.isSaved) if self.isSaved is False and self.confirmPopup is None: self.confirmSave(self.closeApp) else: self.closeApp() def closePopup(self, bt, confirmPopup): self.confirmPopup.delete() self.confirmPopup = None def closeApp(self, obj=False, trash=False): elementary.exit() def eventsCb(self, obj, src, event_type, event): if event.modifier_is_set("Control"): if event.key.lower() == "n": self.newFile() elif event.key.lower() == "s" and event.modifier_is_set("Shift"): self.saveAs() elif event.key.lower() == "s": self.saveFile() elif event.key.lower() == "o": self.openFile() # Legacy hack no longer needed # there was an issue in elementary entry where it would # accept those character controls # def textFilter( self, obj, theText, data ): # # Block ctrl+hot keys used in eventsCb # # # # Ctrl O Ctrl N Ctrl S # ctrl_block = [chr(14), chr(15), chr(19)] # if theText in ctrl_block: # return None # else: # return theText def launch(self, startingFile=False): if startingFile: self.fileSelected(self.fileSelector, startingFile, True) self.mainWindow.show()
class FontSelector(Box): def __init__(self, parent_widget, *args, **kwargs): Box.__init__(self, parent_widget, *args, **kwargs) self.cancelCallback = None self.actionCallback = None self.__first_run = True self.use_theme = False self.override_theme_font_size = True self.override_font_size = 14 self.theme_data = None self.default_font = 'Sans' self.default_font_style = 'Regular' self.default_font_size = 14 self.selected_font = self.default_font self.selected_font_style = self.default_font_style self.selected_font_size = self.default_font_size self.font_style_str = self.get_text_style(self.selected_font, self.selected_font_style, self.selected_font_size) self.preview_text = 'abcdefghijk ABCDEFGHIJK' # Font size min and max self.fs_min = 8 self.fs_max = 72 lb = Label(self, text="<br><hilight><i>Select Font</i></hilight>", size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_BOTH) lb.show() self.pack_end(lb) sp = Separator(self, horizontal=True, size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ) sp.show() self.pack_end(sp) # A horizontal box to hold our font list and font styles fontBox = Box(self, horizontal=True, homogeneous=True, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) fontBox.show() self.pack_end(fontBox) # A vertical box to hold label and list of font families vBoxFL = Box(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) vBoxFL.show() fontBox.pack_end(vBoxFL) # A vertical box to hold label and list of font styles vBoxFS = Box(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) vBoxFS.show() fontBox.pack_end(vBoxFS) # Generate our needed font data #now =time.time() fonts = [] fonts_raw = self.evas.font_available_list() # populate with default font families # see elm_font_available_hash_add Function in EFL f_families = ['Sans', 'Serif', 'Monospace'] f_styles = ['Regular', 'Italic', 'Bold', 'Bold Italic'] fonts_raw += [i + ':style=' + s for i in f_families for s in f_styles] self.fonts_hash = {} for font in fonts_raw: a = font_properties_get(font) # if font name contains a '-' a.name will replace with '\\-' # This needs removed to properly display the name fn = a.name.replace('\\', '') fonts.append(fn) if fn in self.fonts_hash: self.fonts_hash.setdefault(fn, []).append(a.styles[0]) else: self.fonts_hash[fn] = [a.styles[0]] # Deal with some problematic special cases for a, s in self.fonts_hash.items(): #print(a,s) if s: if len(s) == 1: s[0] = s[0].rstrip() if s[0] == u'regular': s[0] = u'Regular' if s[0] == u'Medium Italic': self.fonts_hash.setdefault(a, []).append(u'Bold Italic') elif s[0] == u'Italic': if a != u'Romande ADF Script Std': self.fonts_hash.setdefault(a, []).append(u'Regular') self.fonts_hash.setdefault(a, []).append(u'Bold') self.fonts_hash.setdefault(a, []).append(u'Bold Italic') else: self.fonts_hash.setdefault(a, []).append(u'Italic') self.fonts_hash.setdefault(a, []).append(u'Bold') self.fonts_hash.setdefault(a, []).append(u'Bold Italic') elif len(s) == 2: if any(u'Oblique' in w for w in s): if a not in { u'Baskervald ADF Std Heavy', u'Latin Modern Roman Demi' }: self.fonts_hash.setdefault(a, []).append(u'Bold') self.fonts_hash.setdefault( a, []).append(u'Bold Oblique') elif any(u'Italic' in w for w in s): self.fonts_hash.setdefault(a, []).append(u'Bold') self.fonts_hash.setdefault(a, []).append(u'Bold Italic') else: self.fonts_hash.setdefault(a, []).append(u'Italic') self.fonts_hash.setdefault(a, []).append(u'Bold Italic') elif len(s) == 3 and set(s) == { u'Bold', u'Oblique', u'Medium' }: # case GWMonospace self.fonts_hash.setdefault(a, []).append(u'Bold Oblique') elif len(s) == 3 and set(s) == { u'Italic', u'Regular', u'Bold' }: # Case Eden Mills self.fonts_hash.setdefault(a, []).append(u'Bold Italic') elif len(s) < 4: print("may need fixed Font style for %s: %s" % (a, s)) #print(self.fonts_hash) # for some strange reason many fonts are displayed multiple times. The following lines remove # all duplicates and then sort them alphabetically. # FIXME: Is this still true fonts = list(set(fonts)) fonts.sort(cmp=locale.strcoll) # Elm List for holding font options self.font_list = List(self, size_hint_align=FILL_BOTH, size_hint_weight=EXPAND_BOTH, mode=ELM_LIST_LIMIT) #self.font_list.callback_selected_add(self.__font_demo_name_set) for font in fonts: self.font_list.item_append(font.replace('\\', '')) if font == self.selected_font: font_it = self.font_list.last_item_get() #print (time.time()- now) self.font_list.go() self.font_list.show() font_family_label = Label(self) font_family_label.text = "<br><b>Font:</b>" font_family_label.show() vBoxFL.pack_end(font_family_label) vBoxFL.pack_end(self.font_list) # Elm List for hold font styles self.font_style = List(self, size_hint_align=FILL_BOTH, size_hint_weight=EXPAND_BOTH, mode=ELM_LIST_LIMIT) #self.font_style.callback_selected_add(self.__font_demo_style_set) self.__reset_font_style_list(font_it.text_get()) self.font_style.go() self.font_style.show() font_style_label = Label(self) font_style_label.text = "<br><b>Style:</b>" font_style_label.show() vBoxFS.pack_end(font_style_label) vBoxFS.pack_end(self.font_style) # A table to hold font size Spinner and set theme default Check tb = Table(self, homogeneous=True, size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ) self.pack_end(tb) tb.show() # spinner to choose the font size self.font_sizer = Spinner(self) self.font_sizer.min_max_set(self.fs_min, self.fs_max) self.font_sizer.value_set(self.selected_font_size) #self.font_sizer.callback_changed_add(self.__font_demo_size_set) self.font_sizer.show() # Label for Spinner font_sizer_label = Label(self) font_sizer_label.text = "Font Size: " font_sizer_label.show() size_box = Box(self, size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ) size_box.horizontal_set(True) size_box.pack_end(font_sizer_label) size_box.pack_end(self.font_sizer) size_box.show() tb.pack(size_box, 33, 0, 34, 34) self.use_theme_ck = Check(self, text="Theme Default ", size_hint_weight=EXPAND_HORIZ, size_hint_align=(1, 0.5)) self.use_theme_ck.callback_changed_add(self.__use_theme_checked) self.use_theme_ck.show() tb.pack(self.use_theme_ck, 67, 0, 33, 34) # Entry to hold sample text self.font_demo = Entry(self, single_line=True, editable=False, context_menu_disabled=True, text=self.preview_text, scrollable=True, size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ) self.font_demo.show() demo_box = Frame(self, size_hint_align=FILL_BOTH, text="Preview:", content=self.font_demo) demo_box.show() # Fixme: move this shit font_it.selected_set(True) font_it.show() # Ensure focus is on Font List self.font_list.focus_set(True) self.pack_end(demo_box) # cancel and OK buttons ok_button = Button(self) ok_button.text = "OK" ok_button.callback_pressed_add(self.__ok_button_pressed) ok_button.show() cancel_button = Button(self) cancel_button.text = "Cancel" cancel_button.callback_pressed_add(self.__cancel_button_pressed) cancel_button.show() # box for buttons button_box = Box(self) button_box.horizontal_set(True) button_box.show() button_box.pack_end(cancel_button) button_box.pack_end(ok_button) self.pack_end(button_box) def callback_activated_add(self, cb): self.actionCallback = cb def callback_cancel_add(self, cb): self.cancelCallback = cb def set_preview_text(self, text): self.preview_text = text self.font_demo.entry_set(text) def __cancel_button_pressed(self, btn): self.use_theme = self.show.use_theme_init #print("cancel", self.use_theme) self.selected_font = self.default_font self.selected_font_style = self.default_font_style self.selected_font_size = self.default_font_size self.font_style_str = self.get_text_style(self.selected_font, self.selected_font_style, self.selected_font_size) if self.cancelCallback: self.cancelCallback(self) def __ok_button_pressed(self, btn): # Set selections # if use_theme is set any of these could be potentially unset try: self.selected_font = self.font_list.selected_item_get().text_get() self.selected_font_style = self.font_style.selected_item_get( ).text_get() self.selected_font_size = self.font_sizer.value_get() self.font_style_str = self.get_text_style(self.selected_font, self.selected_font_style, self.selected_font_size) except AttributeError: self.selected_font = self.default_font if self.default_font_style in self.fonts_hash[self.selected_font]: self.selected_font_style = self.default_font_style else: #print("OK attribute error", self.selected_font, self.default_font_style) self.selected_font_style = self.fonts_hash.items[ self.selected_font][0] self.selected_font_size = self.default_font_size self.font_style_str = self.get_text_style(self.selected_font, self.selected_font_style, self.selected_font_size) self.use_theme = self.use_theme_ck.state_get() if self.actionCallback: self.actionCallback(self) def __use_theme_checked(self, ck): self.use_theme = ck.state_get() #print ( '__use_theme_checked') if self.use_theme: if not self.theme_data: self._set_theme_data() self.set_font(*self.theme_data) while self.font_demo.text_style_user_peek(): self.font_demo.text_style_user_pop() if self.theme_data[1] == None: try: self.font_style.selected_item_get().selected = False except AttributeError: pass if self.override_theme_font_size: self.font_demo.text_style_user_push( "DEFAULT='font_size={0}'".format(self.override_font_size)) self.font_sizer.value_set(self.override_font_size) # Ensure these are unchanged ck.state = self.use_theme = True else: # ensure style is selected self.selected_font = self.default_font self.selected_font_style = self.default_font_style self.selected_font_size = self.default_font_size self.font_style_str = self.get_text_style(self.selected_font, self.selected_font_style, self.selected_font_size) self.set_font(self.default_font, self.default_font_style, self.default_font_size) # Ensure these are unchanged ck.state = self.use_theme = False def _set_theme_data(self): tb_style = self.font_demo.textblock.style_get() font = tb_style.split('text_class=entry_text')[1].split( 'font=')[1].split("'em=")[0] # font may or may not have style associated with it if ':style=' in font: font, style = font.split(':style=') else: style = None # If font name or styyle has spaces in it # textblock.style_get() inserts '\' before space # then the python string split function adds another space # To set the style with a font name that has spaces spaces need to be removed font = font.replace('\\ ', ' ') if style: style = style.replace('\\ ', ' ') size = tb_style.split('text_class=entry_text')[1].split( 'font_size=')[1].split(' ')[0] self.theme_data = [font, style, float(size)] def set_font(self, font, style=None, size=None): found_font = found_style = False #print(self.set_font.__name__, font, style, size, self.use_theme) for font_it in self.font_list.items: if '\\' in font: # Special characters in font names cause problems # need to remove the escape characters before comparison font = font.replace('\\', '') if font == font_it.text: found = True self.selected_font = font_it.text font_it.selected = True font_it.show() break if size and self.fs_min <= size <= self.fs_max: self.selected_font_size = size self.font_sizer.value_set(size) if found_font: self.__reset_font_style_list(font) if style in self.fonts_hash[font_it.text]: for style_it in self.font_style.items: if style == style_it.text: self.selected_font_style = style_it.text style_it.selected = True style_it.show() found_style = True break if not found_style: self.__font_style_set(self.selected_font) # Ensure focus is on Font List self.font_list.focus_set(True) def __font_demo_name_set(self, f_list, font): if self.use_theme: self.use_theme = self.use_theme_ck.state = False self.__reset_font_style_list(font.text_get()) self.__font_style_set(font.text_get()) # Ensure focus is on Font List self.font_list.focus_set(True) def __font_demo_style_set(self, s_list, style): if self.use_theme: self.use_theme = self.use_theme_ck.state = False self.__font_style_set(self.font_list.selected_item_get().text_get()) def __font_demo_size_set(self, sizer): if self.use_theme: self.use_theme = self.use_theme_ck.state = False self.__font_style_set(self.font_list.selected_item_get().text_get()) def __font_style_set(self, font_name): #print (" __font_style_set", font_name) while self.font_demo.text_style_user_peek(): self.font_demo.text_style_user_pop() if self.font_style.selected_item_get(): font_style = self.font_style.selected_item_get().text_get() else: font_style = self.font_style.first_item_get().text_get() font_size = self.font_sizer.value_get() style = self.get_text_style(font_name, font_style, font_size) self.font_demo.text_style_user_push(style) self.font_style_str = style def __reset_font_style_list(self, font_name): self.font_style.clear() self.__normalize_font_style_list(font_name) for style in self.fonts_hash[font_name]: self.font_style.item_append(style) if font_name == self.default_font and style == self.selected_font_style: self.font_style.last_item_get().selected_set(True) if font_name != self.default_font: self.font_style.first_item_get().selected_set(True) #print(self.font_style.first_item_get()) #self.font_style.first_item_get().selected_set(True) self.font_style.first_item_get().show() def get_text_style(self, font_name, font_style_str, font_size): if "'" in font_name: # Special characters in font name issue font_name = font_name.replace("'", "\\'") if font_style_str: style = "DEFAULT='font_size={0} font={1}:style={2}'".format( font_size, font_name.replace(' ', '\ '), font_style_str.replace(' ', '\ ')) else: style = "DEFAULT='font_size={0} font={1}'".format( font_size, font_name.replace(' ', '\ ')) return style def __normalize_font_style_list(self, font_name): styles_list = self.fonts_hash[font_name] if 'Regular' in styles_list and styles_list[0] != 'Regular': styles_list.remove('Regular') styles_list.insert(0, 'Regular') def show(self): #print("SHOW Selected ", self.use_theme, self.selected_font, self.selected_font_style) #print("SHOW default ", self.use_theme, self.default_font, self.default_font_style) if self.__first_run: # only set the callbacks once # needed when called from another window repeatedly #print("__first_run__") self.font_list.callback_selected_add(self.__font_demo_name_set) self.font_style.callback_selected_add(self.__font_demo_style_set) self.font_sizer.callback_changed_add(self.__font_demo_size_set) self.__first_run = False self.show.__func__.use_theme_init = self.use_theme self.use_theme_ck.state = self.use_theme if self.use_theme: self.__use_theme_checked(self.use_theme_ck) #print("selected", self.font_list.selected_item_get().text_get()) if not self.use_theme: self.set_font(self.selected_font, self.selected_font_style, self.selected_font_size) super(FontSelector, self).show()
class ConjectureGUI(object): def __init__(self, windowGrid, name): offset = 0 if (name == 'Yau'): offset = 50 self.BaseBox = Box(windowGrid, size_hint_weight=(EVAS_HINT_EXPAND, EVAS_HINT_EXPAND), size_hint_align=(EVAS_HINT_FILL, EVAS_HINT_FILL)) windowGrid.pack(self.BaseBox, offset, 0, 50, 100) self.BaseBox.show() self.frame = Frame(self.BaseBox, size_hint_weight=(EVAS_HINT_EXPAND, EVAS_HINT_EXPAND), size_hint_align=(EVAS_HINT_FILL, EVAS_HINT_FILL), text=name) self.BaseBox.pack_end(self.frame) self.frame.show() self.FrameBox = Box(self.BaseBox, size_hint_weight=(EVAS_HINT_EXPAND, EVAS_HINT_EXPAND), size_hint_align=(EVAS_HINT_FILL, EVAS_HINT_FILL)) self.frame.content_set(self.FrameBox) self.FrameBox.show() self.FrameCheck = Check(self.BaseBox, size_hint_weight=(EVAS_HINT_EXPAND, 0.0), size_hint_align=(EVAS_HINT_FILL, 0.5), text="{0} Frame Check".format(name)) self.FrameBox.pack_end(self.FrameCheck) self.FrameCheck.show() self.FrameSeparator = Separator(self.BaseBox, horizontal=True, size_hint_weight=(EVAS_HINT_EXPAND, 0.0), size_hint_align=(EVAS_HINT_FILL, 0.5)) self.FrameBox.pack_end(self.FrameSeparator) self.FrameSeparator.show() self.FrameScroller = Scroller( self.BaseBox, content_min_limit=(True, False), size_hint_weight=(EVAS_HINT_EXPAND, EVAS_HINT_EXPAND), size_hint_align=(EVAS_HINT_FILL, EVAS_HINT_FILL), scrollbar_policy=(ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_OFF)) self.FrameBox.pack_end(self.FrameScroller) self.FrameScroller.show() self.FrameTable = Table(self.BaseBox, size_hint_weight=(EVAS_HINT_EXPAND, 0.0), size_hint_align=(EVAS_HINT_FILL, 0.0)) self.FrameScroller.content_set(self.FrameTable) self.FrameTable.show() self.BaseLabel = Label(self.FrameTable, size_hint_weight=(0.0, 0.0), size_hint_align=(0.0, 0.5), text="Base:") self.FrameTable.pack(self.BaseLabel, 0, 0, 1, 1) self.BaseLabel.show() self.BaseEntry = Entry(self.FrameTable, size_hint_weight=(EVAS_HINT_EXPAND, 0.0), size_hint_align=(EVAS_HINT_FILL, 0.5), single_line=True, scrollable=True, text="") self.FrameTable.pack(self.BaseEntry, 1, 0, 1, 1) self.BaseEntry.show() self.SecretLabel = Label(self.FrameTable, size_hint_weight=(0.0, 0.0), size_hint_align=(0.0, 0.5), text="Secret:") self.FrameTable.pack(self.SecretLabel, 2, 0, 1, 1) self.SecretLabel.show() self.SecretEntry = Entry(self.FrameTable, size_hint_weight=(EVAS_HINT_EXPAND, 0.0), size_hint_align=(EVAS_HINT_FILL, 0.5), single_line=True, scrollable=True, text="") self.FrameTable.pack(self.SecretEntry, 3, 0, 1, 1) self.SecretEntry.show() self.SignalLabel = Label(self.FrameTable, size_hint_weight=(0.0, 0.0), size_hint_align=(0.0, 0.5), text="Signal:") self.FrameTable.pack(self.SignalLabel, 4, 0, 1, 1) self.SignalLabel.show() self.SignalEntry = Entry(self.FrameTable, size_hint_weight=(EVAS_HINT_EXPAND, 0.0), size_hint_align=(EVAS_HINT_FILL, 0.5), single_line=True, scrollable=True, text="") self.FrameTable.pack(self.SignalEntry, 5, 0, 1, 1) self.SignalEntry.show() self.ChannelLabel = Label(self.FrameTable, size_hint_weight=(0.0, 0.0), size_hint_align=(0.0, 0.5), text="Channel:") self.FrameTable.pack(self.ChannelLabel, 0, 1, 1, 1) self.ChannelLabel.show() self.ChannelEntry = Entry(self.FrameTable, size_hint_weight=(EVAS_HINT_EXPAND, 0.0), size_hint_align=(EVAS_HINT_FILL, 0.5), single_line=True, scrollable=True, text="") self.FrameTable.pack(self.ChannelEntry, 1, 1, 1, 1) self.ChannelEntry.show() self.PoleLabel = Label(self.FrameTable, size_hint_weight=(0.0, 0.0), size_hint_align=(0.0, 0.5), text="Pole:") self.FrameTable.pack(self.PoleLabel, 2, 1, 1, 1) self.PoleLabel.show() self.PoleEntry = Entry(self.FrameTable, size_hint_weight=(EVAS_HINT_EXPAND, 0.0), size_hint_align=(EVAS_HINT_FILL, 0.5), single_line=True, scrollable=True, text="") self.FrameTable.pack(self.PoleEntry, 3, 1, 1, 1) self.PoleEntry.show() self.IdentityLabel = Label(self.FrameTable, size_hint_weight=(0.0, 0.0), size_hint_align=(0.0, 0.5), text="Identity:") self.FrameTable.pack(self.IdentityLabel, 4, 1, 1, 1) self.IdentityLabel.show() self.IdentityEntry = Entry(self.FrameTable, size_hint_weight=(EVAS_HINT_EXPAND, 0.0), size_hint_align=(EVAS_HINT_FILL, 0.5), single_line=True, scrollable=True, text="") self.FrameTable.pack(self.IdentityEntry, 5, 1, 1, 1) self.IdentityEntry.show() self.FoundationLabel = Label(self.FrameTable, size_hint_weight=(0.0, 0.0), size_hint_align=(0.0, 0.5), text="Foundation:") self.FrameTable.pack(self.FoundationLabel, 0, 2, 1, 1) self.FoundationLabel.show() self.FoundationEntry = Entry(self.FrameTable, size_hint_weight=(EVAS_HINT_EXPAND, 0.0), size_hint_align=(EVAS_HINT_FILL, 0.5), single_line=True, scrollable=True, text="") self.FrameTable.pack(self.FoundationEntry, 1, 2, 1, 1) self.FoundationEntry.show() self.ElementLabel = Label(self.FrameTable, size_hint_weight=(0.0, 0.0), size_hint_align=(0.0, 0.5), text="Element:") self.FrameTable.pack(self.ElementLabel, 2, 2, 1, 1) self.ElementLabel.show() self.ElementEntry = Entry(self.FrameTable, size_hint_weight=(EVAS_HINT_EXPAND, 0.0), size_hint_align=(EVAS_HINT_FILL, 0.5), single_line=True, scrollable=True, text="") self.FrameTable.pack(self.ElementEntry, 3, 2, 1, 1) self.ElementEntry.show() self.DynamoLabel = Label(self.FrameTable, size_hint_weight=(0.0, 0.0), size_hint_align=(0.0, 0.5), text="Dynamo:") self.FrameTable.pack(self.DynamoLabel, 4, 2, 1, 1) self.DynamoLabel.show() self.DynamoEntry = Entry(self.FrameTable, size_hint_weight=(EVAS_HINT_EXPAND, 0.0), size_hint_align=(EVAS_HINT_FILL, 0.5), single_line=True, scrollable=True, text="") self.FrameTable.pack(self.DynamoEntry, 5, 2, 1, 1) self.DynamoEntry.show() self.ManifoldLabel = Label(self.FrameTable, size_hint_weight=(0.0, 0.0), size_hint_align=(0.0, 0.5), text="Manifold:") self.FrameTable.pack(self.ManifoldLabel, 0, 3, 1, 1) self.ManifoldLabel.show() self.ManifoldEntry = Entry(self.FrameTable, size_hint_weight=(EVAS_HINT_EXPAND, 0.0), size_hint_align=(EVAS_HINT_FILL, 0.5), single_line=True, scrollable=True, text="") self.FrameTable.pack(self.ManifoldEntry, 1, 3, 1, 1) self.ManifoldEntry.show() self.RingLabel = Label(self.FrameTable, size_hint_weight=(0.0, 0.0), size_hint_align=(0.0, 0.5), text="Ring:") self.FrameTable.pack(self.RingLabel, 2, 3, 1, 1) self.RingLabel.show() self.RingEntry = Entry(self.FrameTable, size_hint_weight=(EVAS_HINT_EXPAND, 0.0), size_hint_align=(EVAS_HINT_FILL, 0.5), single_line=True, scrollable=True, text="") self.FrameTable.pack(self.RingEntry, 3, 3, 1, 1) self.RingEntry.show() self.BarnLabel = Label(self.FrameTable, size_hint_weight=(0.0, 0.0), size_hint_align=(0.0, 0.5), text="Barn:") self.FrameTable.pack(self.BarnLabel, 4, 3, 1, 1) self.BarnLabel.show() self.BarnEntry = Entry(self.FrameTable, size_hint_weight=(EVAS_HINT_EXPAND, 0.0), size_hint_align=(EVAS_HINT_FILL, 0.5), single_line=True, scrollable=True, text="") self.FrameTable.pack(self.BarnEntry, 5, 3, 1, 1) self.BarnEntry.show() self.VoltpereLabel = Label(self.FrameTable, size_hint_weight=(0.0, 0.0), size_hint_align=(0.0, 0.5), text="Voltpere:") self.FrameTable.pack(self.VoltpereLabel, 0, 4, 1, 1) self.VoltpereLabel.show() self.VoltpereEntry = Entry(self.FrameTable, size_hint_weight=(EVAS_HINT_EXPAND, 0.0), size_hint_align=(EVAS_HINT_FILL, 0.5), single_line=True, scrollable=True, text="") self.FrameTable.pack(self.VoltpereEntry, 1, 4, 5, 1) self.VoltpereEntry.show() self.AmpereLabel = Label(self.FrameTable, size_hint_weight=(0.0, 0.0), size_hint_align=(0.0, 0.5), text="Ampere:") self.FrameTable.pack(self.AmpereLabel, 0, 5, 1, 1) self.AmpereLabel.show() self.AmpereEntry = Entry(self.FrameTable, size_hint_weight=(EVAS_HINT_EXPAND, 0.0), size_hint_align=(EVAS_HINT_FILL, 0.5), single_line=True, scrollable=True, text="") self.FrameTable.pack(self.AmpereEntry, 1, 5, 2, 1) self.AmpereEntry.show() self.HenryLabel = Label(self.FrameTable, size_hint_weight=(0.0, 0.0), size_hint_align=(0.0, 0.5), text="Henry:") self.FrameTable.pack(self.HenryLabel, 0, 6, 1, 1) self.HenryLabel.show() self.HenryEntry = Entry(self.FrameTable, size_hint_weight=(EVAS_HINT_EXPAND, 0.0), size_hint_align=(EVAS_HINT_FILL, 0.5), single_line=True, scrollable=True, text="") self.FrameTable.pack(self.HenryEntry, 1, 6, 2, 1) self.HenryEntry.show() self.MaxwellLabel = Label(self.FrameTable, size_hint_weight=(0.0, 0.0), size_hint_align=(0.0, 0.5), text="Maxwell:") self.FrameTable.pack(self.MaxwellLabel, 0, 7, 1, 1) self.MaxwellLabel.show() self.MaxwellEntry = Entry(self.FrameTable, size_hint_weight=(EVAS_HINT_EXPAND, 0.0), size_hint_align=(EVAS_HINT_FILL, 0.5), single_line=True, scrollable=True, text="") self.FrameTable.pack(self.MaxwellEntry, 1, 7, 2, 1) self.MaxwellEntry.show() self.FermatLabel = Label(self.FrameTable, size_hint_weight=(0.0, 0.0), size_hint_align=(0.0, 0.5), text="Fermat:") self.FrameTable.pack(self.FermatLabel, 0, 8, 1, 1) self.FermatLabel.show() self.FermatEntry = Entry(self.FrameTable, size_hint_weight=(EVAS_HINT_EXPAND, 0.0), size_hint_align=(EVAS_HINT_FILL, 0.5), single_line=True, scrollable=True, text="") self.FrameTable.pack(self.FermatEntry, 1, 8, 2, 1) self.FermatEntry.show() self.PropelButton = Button(self.FrameTable, size_hint_weight=(0.0, 0.0), size_hint_align=(0.0, 0.5), text="Propel") self.FrameTable.pack(self.PropelButton, 4, 8, 1, 1) self.PropelButton.show() self.PropelButton.callback_clicked_add(self.propelClicked) def propelClicked(self, obj): print("clicked")
def calendar2_clicked(obj, item=None): weekdays = [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ] win = StandardWindow("calendar2", "Calendar 2", autodel=True) bx = Box(win, size_hint_weight=EXPAND_BOTH) win.resize_object_add(bx) bx.show() bxh = Box(bx, horizontal=True, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) bxh.show() bx.pack_end(bxh) # Wide cal cal = Calendar(bx, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH, weekdays_names=weekdays, first_day_of_week=ELM_DAY_SATURDAY, interval=0.4, min_max_year=(2010, 2020)) cal.show() bx.pack_end(cal) # Top left cal cal2 = Calendar(bxh, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH, select_mode=ELM_CALENDAR_SELECT_MODE_NONE) cal2.show() bxh.pack_end(cal2) # Top right cal cal3 = Calendar(bxh, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) selected_time = datetime.now() + timedelta(34) cal3.selected_time = selected_time selected_time = datetime.now() + timedelta(1) cal3.mark_add("checked", selected_time, ELM_CALENDAR_UNIQUE) del (cal3.marks) selected_time = datetime.now() cal3.mark_add("checked", selected_time, ELM_CALENDAR_DAILY) cal3.mark_add("holiday", selected_time, ELM_CALENDAR_DAILY) cal3.marks_draw() cal3.show() bxh.pack_end(cal3) en = Entry(win, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH, editable=False) en.show() bx.pack_end(en) win.show() cal3.min_max_year = (-1, -1) # TODO: cal.format_function_set(format_month_year) selected_time = datetime.now() + timedelta(4) cal.mark_add("holiday", selected_time, ELM_CALENDAR_ANNUALLY) selected_time = datetime.now() + timedelta(1) cal.mark_add("checked", selected_time, ELM_CALENDAR_UNIQUE) selected_time = datetime.now() - timedelta(363) cal.mark_add("checked", selected_time, ELM_CALENDAR_MONTHLY) selected_time = datetime.now() - timedelta(5) mark = cal.mark_add("holiday", selected_time, ELM_CALENDAR_WEEKLY) selected_time = datetime.now() + timedelta(1) cal.mark_add("holiday", selected_time, ELM_CALENDAR_WEEKLY) mark.delete() cal.marks_draw() print_cal_info(cal, en) cal.callback_changed_add(print_cal_info_cb, en)
def __init__(self, rent): Box.__init__(self, rent) self.parent = rent #This appears on the button in the main swmai window self.name = "Light DM" #The section in the main window the button is added to self.section = "System Settings" #Search terms that this module should appear for self.searchData = ["lightdm", "autologin", "login", "display"] #Command line argument to open this module directly self.launchArg = "--lightdm" #Should be none by default. This value is used internally by swami self.button = None self.icon = Icon(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) #Use FDO icons -> http://standards.freedesktop.org/icon-naming-spec/latest/ar01s04.html self.icon.standard_set('video-display') self.icon.show() self.mainBox = Box(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) self.mainBox.show() self.config = {"sections": []} with open(LightDMConf) as f: currentSection = None for line in f: #Sections start with [ - such as [SeatDefaults] if line[0] == "[": self.config["sections"].append(line) currentSection = line.rstrip() s = Frame(self, size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ) s.text = currentSection[1:-1] s.show() sectionBox = Box(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) sectionBox.show() s.content = sectionBox self.mainBox.pack_end(s) elif line[0] not in ["[", "\n"]: setting, value = line.replace("\n", "").split("=") e = Entry(self) e.single_line_set(True) e.text = value e.show() f = Frame(self, size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ) f.text = setting f.content = e f.show() sectionBox.pack_end(f) self.config[setting] = [f, currentSection] buttonBox = Box(self, size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_BOTH) buttonBox.horizontal = True buttonSave = StandardButton(self, "Save Changes", "ok", self.savePressed) buttonSave.show() buttonReturn = StandardButton(self, "Back", "go-previous", self.returnPressed) buttonReturn.show() buttonBox.pack_end(buttonSave) buttonBox.pack_end(buttonReturn) buttonBox.show() self.pack_end(self.mainBox) self.pack_end(buttonBox)
def __init__(self, parent, method): StandardWindow.__init__(self, "espionage", "Method", autodel=True) self._method = method self._param_entry = None self._return_entry = None # content is vbox (with surrounding pad frame) pad = Frame(self, style='pad_medium') pad.size_hint_weight = EVAS_HINT_EXPAND, EVAS_HINT_EXPAND pad.size_hint_align = EVAS_HINT_FILL, EVAS_HINT_FILL self.resize_object_add(pad) pad.show() vbox = Box(self) vbox.size_hint_weight = EVAS_HINT_EXPAND, EVAS_HINT_EXPAND vbox.size_hint_align = EVAS_HINT_FILL, EVAS_HINT_FILL pad.content = vbox vbox.show() # title f = "font_size=16 align=0.5 font_weight=Bold" en = Entry(self, text='<font %s>%s()</>' % (f, method.name)) en.size_hint_weight = EVAS_HINT_EXPAND, 0.0 en.size_hint_align = EVAS_HINT_FILL, 0.0 en.editable = False vbox.pack_end(en) en.show() # params label + entry if len(method.params) > 0: label = Entry(self, editable=False) label.size_hint_weight = EVAS_HINT_EXPAND, 0.0 label.size_hint_align = EVAS_HINT_FILL, 0.0 pars = colored_params(method.params, omit_braces=True) label.text = 'Params: %s' % (pars if method.params else 'None') vbox.pack_end(label) label.show() en = Entry(self, editable=True, scrollable=True, single_line=True) en.size_hint_weight = EVAS_HINT_EXPAND, 0.0 en.size_hint_align = EVAS_HINT_FILL, 0.0 self._param_entry = en vbox.pack_end(en) en.show() # returns label + entry label = Entry(self, editable=False) label.size_hint_weight = EVAS_HINT_EXPAND, 0.0 label.size_hint_align = EVAS_HINT_FILL, 0.0 rets = colored_params(method.returns, omit_braces=True) label.text = 'Returns: %s' % (rets if method.returns else 'None') vbox.pack_end(label) label.show() en = Entry(self, editable=False, scrollable=True) en.size_hint_weight = EVAS_HINT_EXPAND, EVAS_HINT_EXPAND en.size_hint_align = EVAS_HINT_FILL, EVAS_HINT_FILL self._return_entry = en vbox.pack_end(en) en.show() # pretty print check button def pretty_output_clicked_cb(chk): options.pretty_output = chk.state ch = Check(self) ch.size_hint_align = 0.0, 0.5 ch.text = "Prettify output (loosing type infos)" ch.state = options.pretty_output ch.callback_changed_add(pretty_output_clicked_cb) ch.show() vbox.pack_end(ch) sep = Separator(self, horizontal=True) vbox.pack_end(sep) sep.show() # buttons hbox = Box(self, horizontal=True) hbox.size_hint_weight = EVAS_HINT_EXPAND, 0.0 hbox.size_hint_align = EVAS_HINT_FILL, 0.5 vbox.pack_end(hbox) hbox.show() btn = Button(self) btn.text = 'Close' btn.callback_clicked_add(lambda b: self.delete()) hbox.pack_end(btn) btn.show() btn = Button(self) btn.text = 'Clear output' btn.callback_clicked_add(lambda b: self._return_entry.entry_set('')) hbox.pack_end(btn) btn.show() btn = Button(self) btn.text = 'Run method' btn.callback_clicked_add(self.run_clicked_cb) hbox.pack_end(btn) btn.show() # show the window self.resize(300, 300) self.show()
def __init__(self, app): self.app = app DialogWindow.__init__(self, app.win, 'egitu-remotes', 'Remotes', autodel=True, size=(600,400)) # main vertical box (inside a padding frame) fr = Frame(self, style='pad_medium', size_hint_weight=EXPAND_BOTH) self.resize_object_add(fr) fr.show() box = Box(fr, padding=(6,6)) fr.content = box box.show() # panes panes = Panes(box, content_left_size=0.25, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) box.pack_end(panes) panes.show() ### remotes List (on the left) li = List(panes) li.callback_selected_add(self._list_selected_cb) panes.part_content_set('left', li) li.show() self.remotes_list = li ### remote info (on the right) tb = Table(self, padding=(4, 4)) panes.part_content_set('right', tb) tb.show() # url lb = Label(self, text='URL', size_hint_align=(0.0,0.5)) tb.pack(lb, 0, 0, 1, 1) lb.show() en = Entry(self, single_line=True, scrollable=True, size_hint_expand=EXPAND_BOTH, size_hint_fill=FILL_BOTH) en.callback_changed_user_add(lambda e: \ setattr(self.save_url_btn, 'disabled', False)) tb.pack(en, 1, 0, 1, 1) en.show() self.url_entry = en # fetch lb = Label(self, text='Fetch', size_hint_align=(0.0,0.5)) tb.pack(lb, 0, 1, 1, 1) lb.show() en = Entry(self, single_line=True, scrollable=True, editable=False, size_hint_expand=EXPAND_BOTH, size_hint_fill=FILL_BOTH) tb.pack(en, 1, 1, 1, 1) en.show() self.fetch_entry = en # save button bt = Button(self, text='Save', disabled=True, size_hint_expand=EXPAND_VERT, size_hint_fill=FILL_VERT) bt.callback_clicked_add(self._save_url_clicked_cb) tb.pack(bt, 2, 0, 1, 1) bt.show() self.save_url_btn = bt # big info entry en = Entry(panes, scrollable=True, editable=False, line_wrap=ELM_WRAP_NONE, size_hint_expand=EXPAND_BOTH, size_hint_fill=FILL_BOTH) en.callback_clicked_add(self._info_clicked_cb) tb.pack(en, 0, 2, 3, 1) en.show() self.info_entry = en ### buttons bar hbox = Box(box, horizontal=True, size_hint_expand=EXPAND_HORIZ, size_hint_fill=FILL_BOTH) box.pack_end(hbox) hbox.show() bt = Button(hbox, text='Add') bt.callback_clicked_add(lambda b: RemoteAddPopup(self, self.app.repo)) hbox.pack_end(bt) bt.show() bt = Button(hbox, text='Remove') bt.callback_clicked_add(self._remove_btn_cb) hbox.pack_end(bt) bt.show() bt = Button(hbox, text='Refresh') bt.callback_clicked_add(lambda b: self.restart_dialog()) hbox.pack_end(bt) bt.show() sep = Separator(hbox, size_hint_expand=EXPAND_HORIZ) hbox.pack_end(sep) bt = Button(hbox, text='Close') bt.callback_clicked_add(lambda b: self.delete()) hbox.pack_end(bt) bt.show() # populate and show the dialog window self.restart_dialog() self.show()
def tooltip_clicked(obj): win = StandardWindow("tooltips", "Tooltips", autodel=True, size=(400, 500)) if obj is None: win.callback_delete_request_add(lambda o: elementary.exit()) bx = Box(win, size_hint_weight=EXPAND_BOTH) win.resize_object_add(bx) bx.show() tb = Toolbar(win, homogeneous=False, size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ) bx.pack_end(tb) tb.show() ti = tb.item_append("folder-new", "Open", None, None) ti.tooltip_text_set("Opens a file") ti = tb.item_append("clock", "Icon", None, None) ti.tooltip_content_cb_set(_tt_item_icon, None) ti.tooltip_style_set("transparent") bt = Button(win, text="Simple text tooltip") bt.tooltip_text_set("Simple text tooltip") bx.pack_end(bt) bt.show() def _tt_text_replace(obj, data): value = data.get("value") if not value: value = 1 obj.tooltip_text_set("count=%d" % value) value += 1 data["value"] = value bt = Button(win, text="Simple text tooltip, click to change") bt.tooltip_text_set("Initial") data = dict() bt.callback_clicked_add(_tt_text_replace, data) bx.pack_end(bt) bt.show() def _tt_text_replace_timer_cb(obj, data): _tt_text_replace(obj, data) return True def _tt_text_replace_timed(obj, data, *args, **kargs): timer = data.get("timer") if timer: timer.delete() del data["timer"] obj.text_set("Simple text tooltip, click to start changed timed") return data["timer"] = Timer(1.5, _tt_text_replace_timer_cb, obj, data) obj.text_set("Simple text tooltip, click to stop changed timed") bt = Button(win, text="Simple text tooltip, click to start changed timed") bt.tooltip_text_set("Initial") data = dict() bt.callback_clicked_add(_tt_text_replace_timed, data) bx.pack_end(bt) bt.show() bt.on_del_add(_tt_timer_del, data) bt = Button(win, text="Icon tooltip") bt.tooltip_content_cb_set(_tt_icon, None) bx.pack_end(bt) bt.show() def _tt_icon_replace_timer_cb(obj, data): value = data.get("value") data["value"] = not value if value: obj.tooltip_content_cb_set(_tt_icon) else: obj.tooltip_content_cb_set(_tt_icon2) return True def _tt_icon_replace_timed(obj, data, *args, **kargs): timer = data.get("timer") if timer: timer.delete() del data["timer"] obj.text_set("Icon tooltip, click to start changed timed") return data["timer"] = timer_add(1.5, _tt_icon_replace_timer_cb, obj, data) obj.text_set("Icon tooltip, click to stop changed timed") bt = Button(win, text="Icon tooltip, click to start changed timed") bt.tooltip_content_cb_set(_tt_icon) data = dict() bt.callback_clicked_add(_tt_icon_replace_timed, data) bx.pack_end(bt) bt.show() bt.on_del_add(_tt_timer_del, data) bt = Button(win, text="Transparent Icon tooltip") bt.tooltip_content_cb_set(_tt_icon, None) bt.tooltip_style_set("transparent") bx.pack_end(bt) bt.show() def _tt_style_replace_timer_cb(obj, data): value = data.get("value") data["value"] = not value if value: obj.tooltip_style_set() else: obj.tooltip_style_set("transparent") return True def _tt_style_replace_timed(obj, data, *args, **kargs): timer = data.get("timer") if timer: timer.delete() del data["timer"] obj.text_set("Icon tooltip style, click to start changed timed") return data["timer"] = timer_add(1.5, _tt_style_replace_timer_cb, obj, data) obj.text_set("Icon tooltip, click to stop changed timed") bt = Button(win, text="Icon tooltip style, click to start changed timed") bt.tooltip_content_cb_set(_tt_icon, None) data = dict() bt.callback_clicked_add(_tt_style_replace_timed, data) bx.pack_end(bt) bt.show() bt.on_del_add(_tt_timer_del, data) def _tt_visible_lock_toggle(obj, data, *args, **kargs): value = data.get("value") data["value"] = not value if value: obj.text_set("Unlocked tooltip visibility") obj.tooltip_hide() else: obj.text_set("Locked tooltip visibility") obj.tooltip_show() bt = Button(win, text="Unlocked tooltip visibility") bt.tooltip_text_set( "This tooltip is unlocked visible,<br> click the button to lock!") data = dict() bt.callback_clicked_add(_tt_visible_lock_toggle, data) bx.pack_end(bt) bt.show() def _tt_move_freeze_toggle(obj, *args, **kargs): if obj.tooltip_move_freeze_get(): obj.text_set("Unfreezed tooltip movement") obj.tooltip_move_freeze_pop() else: obj.text_set("Freezed tooltip movement") obj.tooltip_move_freeze_push() bt = Button(win, text="Freezed tooltip movement") bt.tooltip_text_set( "This tooltip has freezed movement,<br> click the button to unfreeze!") bt.tooltip_move_freeze_push() bt.callback_clicked_add(_tt_move_freeze_toggle) bx.pack_end(bt) bt.show() en = Entry(win, scrollable=True, single_line=True, entry="Hello, some scrolled entry here!", size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ) en.tooltip_text_set("Type something here!") bx.pack_end(en) en.show() lst = List(win, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH, size_hint_min=(100, 100)) li = lst.item_append("Hello") li.tooltip_text_set("Something useful here?") li = lst.item_append("Icon Tooltip") li.tooltip_content_cb_set(_tt_item_icon, None) bx.pack_end(lst) lst.go() lst.show() win.show()
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)
box0.pack_end(bx1) bx1.show() lb = Label(win, text="Filter:") bx1.pack_end(lb) lb.show() en = Entry(win, single_line=True, scrollable=True, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) en.part_text_set("guide", "Type widget name here to search.") en.callback_changed_add(cb_filter, win) bx1.pack_end(en) en.show() en.focus_set(True) sc = Scroller(win, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH, bounce=(False, True)) sc.show() box0.pack_end(sc) tbx = Box(win, size_hint_weight=(EVAS_HINT_EXPAND, 0.0), size_hint_align=(EVAS_HINT_FILL, 0.0)) sc.content_set(tbx) tbx.show()
class Interface(object): def __init__(self): self.mainWindow = StandardWindow("epad", "Untitled - ePad", size=(600, 400)) self.mainWindow.callback_delete_request_add(self.closeChecks) self.mainWindow.elm_event_callback_add(self.eventsCb) icon = Icon(self.mainWindow) icon.size_hint_weight_set(EVAS_HINT_EXPAND, EVAS_HINT_EXPAND) icon.size_hint_align_set(EVAS_HINT_FILL, EVAS_HINT_FILL) icon.standard_set( 'accessories-text-editor' ) # assumes image icon is in local dir, may need to change later icon.show() self.mainWindow.icon_object_set(icon.object_get()) self.mainBox = Box(self.mainWindow, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) self.mainBox.show() self.mainTb = Toolbar(self.mainWindow, homogeneous=False, size_hint_weight=(0.0, 0.0), size_hint_align=(EVAS_HINT_FILL, 0.0)) self.mainTb.menu_parent = self.mainWindow self.mainTb.item_append("document-new", "New", self.newPress) self.mainTb.item_append("document-open", "Open", self.openPress) self.mainTb.item_append("document-save", "Save", self.savePress) self.mainTb.item_append("document-save-as", "Save As", self.saveAsPress) # -- Edit Dropdown Menu -- tb_it = self.mainTb.item_append("edit", "Edit") tb_it.menu = True menu = tb_it.menu menu.item_add(None, "Copy", "edit-copy", self.copyPress) menu.item_add(None, "Paste", "edit-paste", self.pastePress) menu.item_add(None, "Cut", "edit-cut", self.cutPress) menu.item_separator_add() menu.item_add(None, "Select All", "edit-select-all", self.selectAllPress) # ----------------------- # self.mainTb.item_append("settings", "Options", self.optionsPress) self.mainTb.item_append("dialog-information", "About", self.aboutPress) self.mainEn = Entry(self.mainWindow, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) self.mainEn.callback_changed_user_add(self.textEdited) self.mainEn.scrollable_set( True) # creates scrollbars rather than enlarge window self.mainEn.line_wrap_set( False) # does not allow line wrap (can be changed by user) self.mainEn.autosave_set(False) # set to false to reduce disk I/O self.mainEn.elm_event_callback_add(self.eventsCb) self.mainEn.markup_filter_append(self.textFilter) self.mainEn.show() self.mainTb.show() self.mainBox.pack_end(self.mainTb) self.mainBox.pack_end(self.mainEn) #Build our file selector for saving/loading files self.fileBox = Box(self.mainWindow, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) self.fileBox.show() self.fileLabel = Label(self.mainWindow, size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_BOTH) self.fileLabel.text = "" self.fileLabel.show() self.fileSelector = Fileselector(self.mainWindow, is_save=False, expandable=False, folder_only=False, path=os.getenv("HOME"), size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) self.fileSelector.callback_done_add(self.fileSelected) #self.fileSelector.callback_selected_add(fs_cb_selected, win) #self.fileSelector.callback_directory_open_add(fs_cb_directory_open, win) self.fileSelector.show() self.fileBox.pack_end(self.fileLabel) self.fileBox.pack_end(self.fileSelector) # the flip object has the file selector on one side and the GUI on the other self.flip = Flip(self.mainWindow, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) self.flip.part_content_set("front", self.mainBox) self.flip.part_content_set("back", self.fileBox) self.mainWindow.resize_object_add(self.flip) self.flip.show() self.isSaved = True self.isNewFile = False self.confirmPopup = None def newPress(self, obj, it): self.newFile() it.selected_set(False) def openPress(self, obj, it): self.openFile() it.selected_set(False) def savePress(self, obj, it): self.saveFile() it.selected_set(False) def saveAsPress(self, obj, it): self.saveAs() it.selected_set(False) def optionsPress(self, obj, it): it.selected_set(False) def copyPress(self, obj, it): self.mainEn.selection_copy() it.selected_set(False) def pastePress(self, obj, it): self.mainEn.selection_paste() it.selected_set(False) def cutPress(self, obj, it): self.mainEn.selection_cut() it.selected_set(False) def selectAllPress(self, obj, it): self.mainEn.select_all() it.selected_set(False) def textEdited(self, obj): ourFile = self.mainEn.file_get()[0] if ourFile and not self.isNewFile: self.mainWindow.title_set( "*%s - ePad" % self.mainEn.file_get()[0].split("/")[ len(self.mainEn.file_get()[0].split("/")) - 1]) else: self.mainWindow.title_set("*Untitlted - ePad") self.isSaved = False def fileSelected(self, fs, file_selected, onStartup=False): if not onStartup: self.flip.go(ELM_FLIP_INTERACTION_ROTATE) print(file_selected) IsSave = fs.is_save_get() if file_selected: if IsSave: newfile = open(file_selected, 'w') # creates new file tmp_text = self.mainEn.entry_get() newfile.write(tmp_text) newfile.close() self.mainEn.file_set(file_selected, ELM_TEXT_FORMAT_PLAIN_UTF8) self.mainEn.entry_set(tmp_text) self.mainEn.file_save() self.mainWindow.title_set( "%s - ePad" % file_selected.split("/")[len(file_selected.split("/")) - 1]) self.isSaved = True self.isNewFile = False else: try: self.mainEn.file_set(file_selected, ELM_TEXT_FORMAT_PLAIN_UTF8) except RuntimeError: print("Empty file: {0}".format(file_selected)) self.mainWindow.title_set( "%s - ePad" % file_selected.split("/")[len(file_selected.split("/")) - 1]) def aboutPress(self, obj, it): #About popup self.popupAbout = Popup(self.mainWindow, size_hint_weight=EXPAND_BOTH) self.popupAbout.text = "ePad - A simple text editor written in python and elementary<br><br> " \ "By: Jeff Hoogland" bt = Button(self.mainWindow, text="Done") bt.callback_clicked_add(self.aboutClose) self.popupAbout.part_content_set("button1", bt) self.popupAbout.show() it.selected_set(False) def aboutClose(self, bt): self.popupAbout.delete() def newFile(self, obj=None, ignoreSave=False): if self.isSaved == True or ignoreSave == True: trans = Transit() trans.object_add(self.mainEn) trans.auto_reverse = True trans.effect_wipe_add(ELM_TRANSIT_EFFECT_WIPE_TYPE_HIDE, ELM_TRANSIT_EFFECT_WIPE_DIR_RIGHT) trans.duration = 0.5 trans.go() time.sleep(0.5) self.mainWindow.title_set("Untitlted - ePad") self.mainEn.delete() self.mainEn = Entry(self.mainWindow, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) self.mainEn.callback_changed_user_add(self.textEdited) self.mainEn.scrollable_set( True) # creates scrollbars rather than enlarge window self.mainEn.line_wrap_set( False) # does not allow line wrap (can be changed by user) self.mainEn.autosave_set(False) # set to false to reduce disk I/O self.mainEn.elm_event_callback_add(self.eventsCb) self.mainEn.markup_filter_append(self.textFilter) self.mainEn.show() self.mainBox.pack_end(self.mainEn) self.isNewFile = True elif self.confirmPopup == None: self.confirmSave(self.newFile) def openFile(self, obj=None, ignoreSave=False): if self.isSaved == True or ignoreSave == True: self.fileSelector.is_save_set(False) self.fileLabel.text = "<b>Select a text file to open:</b>" self.flip.go(ELM_FLIP_ROTATE_YZ_CENTER_AXIS) elif self.confirmPopup == None: self.confirmSave(self.openFile) def confirmSave(self, ourCallback=None): self.confirmPopup = Popup(self.mainWindow, size_hint_weight=EXPAND_BOTH) self.confirmPopup.part_text_set("title,text", "File Unsaved") if self.mainEn.file_get()[0]: self.confirmPopup.text = "Save changes to '%s'?" % self.mainEn.file_get( )[0].split("/")[len(self.mainEn.file_get()[0].split("/")) - 1] else: self.confirmPopup.text = "Save changes to 'Untitlted'?" # Close without saving button no_btt = Button(self.mainWindow) no_btt.text = "No" no_btt.callback_clicked_add(self.closePopup, self.confirmPopup) if ourCallback is not None: no_btt.callback_clicked_add(ourCallback, True) no_btt.show() # cancel close request cancel_btt = Button(self.mainWindow) cancel_btt.text = "Cancel" cancel_btt.callback_clicked_add(self.closePopup, self.confirmPopup) cancel_btt.show() # Save the file and then close button sav_btt = Button(self.mainWindow) sav_btt.text = "Yes" sav_btt.callback_clicked_add(self.saveFile) sav_btt.callback_clicked_add(self.closePopup, self.confirmPopup) sav_btt.show() # add buttons to popup self.confirmPopup.part_content_set("button1", no_btt) self.confirmPopup.part_content_set("button2", cancel_btt) self.confirmPopup.part_content_set("button3", sav_btt) self.confirmPopup.show() def saveAs(self): self.fileSelector.is_save_set(True) self.fileLabel.text = "<b>Save new file to where:</b>" self.flip.go(ELM_FLIP_ROTATE_XZ_CENTER_AXIS) def saveFile(self, obj=False): if self.mainEn.file_get()[0] == None or self.isNewFile: self.saveAs() else: self.mainEn.file_save() self.mainWindow.title_set( "%s - ePad" % self.mainEn.file_get()[0].split("/")[ len(self.mainEn.file_get()[0].split("/")) - 1]) self.isSaved = True def closeChecks(self, obj): print(self.isSaved) if self.isSaved == False and self.confirmPopup == None: self.confirmSave(self.closeApp) else: self.closeApp() def closePopup(self, bt, confirmPopup): self.confirmPopup.delete() self.confirmPopup = None def closeApp(self, obj=False, trash=False): elementary.exit() def eventsCb(self, obj, src, event_type, event): #print event_type #print event.key #print "Control Key Status: %s" %event.modifier_is_set("Control") #print "Shift Key Status: %s" %event.modifier_is_set("Shift") #print event.modifier_is_set("Alt") if event.modifier_is_set("Control"): if event.key.lower() == "n": self.newFile() elif event.key.lower() == "s" and event.modifier_is_set("Shift"): self.saveAs() elif event.key.lower() == "s": self.saveFile() elif event.key.lower() == "o": self.openFile() def textFilter(self, obj, theText, data): #print theText #Block ctrl+hot keys if theText == "" or theText == "" or theText == "": return None else: return theText def launch(self, startingFile=False): if startingFile: self.fileSelected(self.fileSelector, startingFile, True) self.mainWindow.show()
class MainWin(StandardWindow): def __init__(self, app): # create the main window StandardWindow.__init__(self, "eepdater", "eepDater - System Updater", autodel=True, size=(320, 320)) self.callback_delete_request_add(lambda o: elementary.exit()) self.app = app icon = Icon(self) icon.size_hint_weight_set(EVAS_HINT_EXPAND, EVAS_HINT_EXPAND) icon.size_hint_align_set(EVAS_HINT_FILL, EVAS_HINT_FILL) icon.standard_set('software-center') icon.show() self.icon_object_set(icon.object_get()) # build the two main boxes self.mainBox = self.buildMainBox() self.loadBox = self.buildLoadBox() # build the information details inwin object self.buildDetailsWin() # the flip object has the load screen on one side and the GUI on the other self.flip = Flip(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) self.flip.part_content_set("front", self.mainBox) self.flip.part_content_set("back", self.loadBox) self.resize_object_add(self.flip) self.flip.show() # show the window self.show() def buildDetailsWin(self): self.updateText = Entry(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) self.updateText.editable_set(False) self.updateText.scrollable_set(True) self.updateText.show() closebtn = Button(self) closebtn.text_set("Done") closebtn.callback_pressed_add(self.innerWinHide) closebtn.show() box = Box(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) box.pack_end(self.updateText) box.pack_end(closebtn) box.show() self.innerWin = InnerWindow(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_HORIZ) self.innerWin.content_set(box) def innerWinShow(self, obj=False): self.innerWin.show() self.innerWin.activate() def innerWinHide(self, obj=False): self.innerWin.hide() def buildLoadBox(self): # build the load label loadLable = Label(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_HORIZ) loadLable.text = "<b>Processing</b>" loadLable.show() # build the spinning wheel wheel = Progressbar(self, pulse_mode=True, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_HORIZ) wheel.pulse(True) wheel.show() detailsbtn = Button(self, style="anchor") detailsbtn.text_set("Details") detailsbtn.callback_pressed_add(self.innerWinShow) detailsbtn.show() # build the status label self.statusLabel = Label(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_HORIZ) self.statusLabel.show() # put all the built objects in a vertical box box = Box(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) box.pack_end(loadLable) box.pack_end(wheel) box.pack_end(self.statusLabel) box.pack_end(detailsbtn) box.show() return box def buildMainBox(self): # build our toolbar self.mainTb = Toolbar(self, homogeneous=False, size_hint_weight=(0.0, 0.0), size_hint_align=(EVAS_HINT_FILL, 0.0)) self.mainTb.item_append("remove", "Clear", self.clearPressed) self.mainTb.item_append("system-run", "Select All", self.selectAllPressed) self.mainTb.item_append("view-refresh", "Refresh", self.refreshPressed) self.mainTb.item_append("info", "Log", self.detailsPressed) self.mainTb.item_append("ok", "Apply", self.installUpdatesPressed) self.mainTb.show() # build our sortable list that displays packages that need updates titles = [("Upgrade", True), ("Package", True), ("Installed", True), ("Available", True)] scr = Scroller(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) self.packageList = sl.SortedList(scr, titles=titles, homogeneous=False, size_hint_weight=EXPAND_HORIZ) scr.content = self.packageList scr.show() # build the label that shows the package's description self.currentDescription = Label(self, size_hint_weight=FILL_BOTH) self.currentDescription.text = "Select a package for information" self.currentDescription.line_wrap_set(True) self.currentDescription.show() self.desFrame = Frame(self, size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ) self.desFrame.text = "Description" self.desFrame.content = self.currentDescription self.desFrame.show() # add all of our objects to the box box = Box(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) box.pack_end(self.mainTb) box.pack_end(scr) box.pack_end(self.desFrame) box.show() return box def detailsPressed(self, obj, it): it.selected = False self.innerWinShow() def clearPressed(self, obj, it): it.selected = False for rw in self.packageList.rows: rw[0].state = False self.app.checkChange(rw[0]) def selectAllPressed(self, obj, it): it.selected = False for rw in self.packageList.rows: rw[0].state = True self.app.checkChange(rw[0]) def refreshPressed(self, obj, it): it.selected = False self.app.refreshPackages() def installUpdatesPressed(self, obj, it): it.selected = False self.app.installUpdates() def packagePressed(self, obj): self.desFrame.text = "Description - %s" % obj.text self.currentDescription.text = obj.data["packageDes"] def addPackage(self, pak): row = [] ourCheck = Check(self) ourCheck.data['packageName'] = pak.name ourCheck.callback_changed_add(self.app.checkChange) ourCheck.show() row.append(ourCheck) ourName = Button(self, style="anchor", size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ) ourName.text = pak.name ourName.data["packageDes"] = pak.candidate.description ourName.callback_pressed_add(self.packagePressed) ourName.show() row.append(ourName) ourVersion = Label(self, size_hint_weight=EXPAND_HORIZ, size_hint_align=(0.1, 0.5)) ourVersion.text = pak.installed.version ourVersion.show() row.append(ourVersion) newVersion = Label(self, size_hint_weight=EXPAND_HORIZ, size_hint_align=(0.1, 0.5)) newVersion.text = pak.candidate.version newVersion.show() row.append(newVersion) self.app.packagesToUpdate[pak.name] = { 'check': ourCheck, 'selected': False } self.packageList.row_pack(row, sort=False) def showDialog(self, title, msg): dia = Popup(self) dia.part_text_set("title,text", title) dia.part_text_set("default", msg) bt = Button(dia, text="Ok") bt.callback_clicked_add(lambda b: dia.delete()) dia.part_content_set("button1", bt) dia.show()
class EmbeddedTerminal(Box): def __init__(self, parent_widget, titles=None, *args, **kwargs): Box.__init__(self, parent_widget, *args, **kwargs) self.outPut = Entry(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) self.outPut.editable_set(False) self.outPut.scrollable_set(True) self.outPut.callback_changed_add(self.changedCb) self.outPut.show() frame = Frame(self, size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ) frame.text = "Input:" frame.autocollapse_set(True) frame.collapse_go(True) frame.show() bx = Box(self, size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ) bx.horizontal = True bx.show() frame.content = bx self.inPut = Entry(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) self.inPut.single_line_set(True) self.inPut.callback_activated_add(self.enterPressed) self.inPut.show() enterButton = Button(self) enterButton.text = "Execute" enterButton.callback_pressed_add(self.enterPressed) enterButton.show() bx.pack_end(self.inPut) bx.pack_end(enterButton) self.pack_end(self.outPut) self.pack_end(frame) self.cmd_exe = None self.done_cb = None def changedCb(self, obj): obj.cursor_end_set() def enterPressed(self, btn): if not self.cmd_exe: self.runCommand(self.inPut.text) self.inPut.text = "" else: ourResult = self.cmd_exe.send("%s\n" % self.inPut.text) self.inPut.text = "" def runCommand(self, command, done_cb=None): self.cmd_exe = cmd = ecore.Exe( command, ecore.ECORE_EXE_PIPE_READ | ecore.ECORE_EXE_PIPE_ERROR | ecore.ECORE_EXE_PIPE_WRITE) cmd.on_add_event_add(self.command_started) cmd.on_data_event_add(self.received_data) cmd.on_error_event_add(self.received_error) cmd.on_del_event_add(self.command_done) self.done_cb = done_cb def command_started(self, cmd, event, *args, **kwargs): self.outPut.entry_append("---------------------------------") self.outPut.entry_append("<br>") def received_data(self, cmd, event, *args, **kwargs): self.outPut.entry_append("%s" % event.data) self.outPut.entry_append("<br>") def received_error(self, cmd, event, *args, **kwargs): self.outPut.entry_append("Error: %s" % event.data) def command_done(self, cmd, event, *args, **kwargs): self.outPut.entry_append("---------------------------------") self.outPut.entry_append("<br>") self.cmd_exe = None if self.done_cb: if callable(self.done_cb): self.done_cb()
def __init__(self, parent, method): Popup.__init__(self, parent) self._method = method self._param_entry = None self._return_entry = None # title self.part_text_set('title,text', 'Method: %s()' % method.name) self.show() # content is vbox vbox = Box(parent) vbox.show() self.content = vbox # params label + entry if len(method.params) > 0: label = Label(parent) label.size_hint_align = 0.0, 0.5 label.text = 'Params: ' + method.params_str label.show() vbox.pack_end(label) en = Entry(parent) self._param_entry = en en.editable = True en.scrollable = True en.single_line = True en.entry = '' en.size_hint_weight = evas.EVAS_HINT_EXPAND, evas.EVAS_HINT_EXPAND en.size_hint_align = evas.EVAS_HINT_FILL, evas.EVAS_HINT_FILL en.show() vbox.pack_end(en) sp = Separator(win) sp.horizontal = True sp.show() vbox.pack_end(sp) # returns label + entry label = Label(parent) label.size_hint_align = 0.0, 0.5 label.text = 'Returns: ' label.text += method.returns_str if method.returns_str else 'None' label.show() vbox.pack_end(label) en = Entry(parent) self._return_entry = en en.size_hint_weight = evas.EVAS_HINT_EXPAND, evas.EVAS_HINT_EXPAND en.size_hint_align = evas.EVAS_HINT_FILL, evas.EVAS_HINT_FILL en.editable = False en.scrollable = True en.disabled = True en.single_line = True # TODO this is wrong, but the only way to show the entry :/ en.entry = '<br> <br> <br>' en.show() vbox.pack_end(en) # pretty print check button def pretty_output_clicked_cb(chk): options.pretty_output = chk.state ch = Check(parent) ch.size_hint_align = 0.0, 0.5 ch.text = "Prettify output (loosing type infos)" ch.state = options.pretty_output ch.callback_changed_add(pretty_output_clicked_cb) ch.show() vbox.pack_end(ch) # popup buttons btn = Button(parent) btn.text = 'Close' btn.callback_clicked_add(lambda b: self.delete()) self.part_content_set('button1', btn) btn = Button(parent) btn.text = 'Clear output' btn.callback_clicked_add(lambda b: self._return_entry.entry_set('')) self.part_content_set('button2', btn) btn = Button(parent) btn.text = 'Run method' btn.callback_clicked_add(self.run_clicked_cb) self.part_content_set('button3', btn)
class EmbeddedTerminal(Box): '''Embedded Terminal class.''' def __init__(self, parent_widget, *args, **kwargs): Box.__init__(self, parent_widget, *args, **kwargs) self.output = Entry(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) self.output.editable_set(False) self.output.scrollable_set(True) self.output.callback_changed_add(self.cb_changed) self.output.show() frame = Frame(self, size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ) frame.text = 'Input:' frame.autocollapse_set(True) frame.collapse_go(True) frame.show() hbx = Box(self, size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ) hbx.horizontal = True hbx.show() frame.content = hbx self.input = Entry(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) self.input.single_line_set(True) self.input.callback_activated_add(self.cb_enter) self.input.show() enter_btn = Button(self) enter_btn.text = 'Execute' enter_btn.callback_pressed_add(self.cb_enter) enter_btn.show() hbx.pack_end(self.input) hbx.pack_end(enter_btn) self.pack_end(self.output) self.pack_end(frame) self.cmd_exe = None self.done_cb = None # pylint: disable=no-self-use def cb_changed(self, obj): '''Output changed, move cursor''' obj.cursor_end_set() def cb_enter(self, btn): '''Enter pressed on input''' if not self.cmd_exe: self.run_cmd(self.input.text) self.input.text = '' else: self.cmd_exe.send(f'{self.input.text}\n') self.input.text = '' def run_cmd(self, command, done_cb=None): '''Run command capture ouput''' command = markup_to_utf8(command) # pylint: disable=c-extension-no-member self.cmd_exe = cmd = ecore.Exe( command, ecore.ECORE_EXE_PIPE_READ | ecore.ECORE_EXE_PIPE_ERROR | ecore.ECORE_EXE_PIPE_WRITE) cmd.on_add_event_add(self.cb_started) cmd.on_data_event_add(self.cb_data) cmd.on_error_event_add(self.cb_error) cmd.on_del_event_add(self.cb_done) self.done_cb = done_cb def cb_started(self, cmd, event, *args, **kwargs): '''Command start''' self.output.entry_append('---------------------------------') self.output.entry_append('<br>') def cb_data(self, cmd, event, *args, **kwargs): '''Stdout callback''' self.output.entry_append(f'{event.data}') self.output.entry_append('<br>') def cb_error(self, cmd, event, *args, **kwargs): '''Stderr callback''' self.output.entry_append(f'Error: {event.data}') def cb_done(self, cmd, event, *args, **kwargs): '''Command finished callback''' self.output.entry_append('---------------------------------') self.output.entry_append('<br>') self.cmd_exe = None if self.done_cb: if callable(self.done_cb): self.done_cb()
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}'
def populate(self): # main vertical box box = Box(self, size_hint_weight = EXPAND_BOTH) self.resize_object_add(box) box.show() ### header fr = Frame(self, style='outdent_bottom', size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_BOTH) box.pack_end(fr) fr.show() tb = Table(self, padding=(3,3), size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_BOTH) fr.content = tb tb.show() # main menu button bt = MainMenuButton(self.app) tb.pack(bt, 0, 0, 1, 1) bt.show() # editable description entry self.caption_label = EditableDescription(self.app) tb.pack(self.caption_label, 1, 0, 1, 1) self.caption_label.show() # status label + button lb = Entry(self, editable=False, line_wrap=ELM_WRAP_NONE) lb.text_style_user_push("DEFAULT='align=center'") tb.pack(lb, 2, 0, 1, 1) lb.show() self.status_label = lb # branch selector self.branch_selector = Hoversel(self, text='HEAD', disabled=True, content=SafeIcon(self, 'git-branch')) self.branch_selector.callback_selected_add(self.branch_selected_cb) tb.pack(self.branch_selector, 3, 0, 1, 1) self.branch_selector.show() # pull button bt = Button(self, text='Pull', disabled=True, content=SafeIcon(self, 'git-pull')) bt.callback_clicked_add(self.app.action_pull) tb.pack(bt, 4, 0, 1, 1) bt.show() self.pull_btn = bt # push button bt = Button(self, text='Push', disabled=True, content=SafeIcon(self, 'git-push')) bt.callback_clicked_add(self.app.action_push) tb.pack(bt, 5, 0, 1, 1) bt.show() self.push_btn = bt ### Tree panes panes1 = Panes(self, content_left_min_size=200, content_left_size=0.0, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) box.pack_end(panes1) panes1.show() # the sidebar on the left self.sidebar = Sidebar(self, self.app) panes1.part_content_set('left', self.sidebar) ### Main content (left + right panes) panes2 = Panes(self, content_left_size=0.5, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) panes1.part_content_set('right', panes2) panes2.show() # the dag graph in the center self.graph = DagGraph(self, self.app) panes2.part_content_set('left', self.graph) # the diff viewer on the right self.diff_view = DiffViewer(self, self.app) self.diff_view.size_hint_weight = EXPAND_BOTH self.diff_view.size_hint_align = 0.0, 0.0 panes2.part_content_set('right', self.diff_view) # self.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)
class ourCommand(object): def __init__(self, cmd): self.cmd = cmd self.cmd_exe = None win = self.win = Window("ecore-ex", ELM_WIN_DIALOG_BASIC) win.title = "Ecore Example" win.size_hint_weight = evas.EVAS_HINT_EXPAND, evas.EVAS_HINT_EXPAND win.size_hint_align = evas.EVAS_HINT_FILL, evas.EVAS_HINT_FILL win.resize(300, 200) win.callback_delete_request_add(lambda o: elementary.exit()) win.show() win.activate() self.sendEntry = Entry(win, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) self.sendEntry.show() self.sendButton = Button(win, size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ) self.sendButton.text = "Send!" self.sendButton.callback_pressed_add(self.sendPressed) self.sendButton.show() box = Box(win, size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ) box.pack_end(self.sendEntry) box.pack_end(self.sendButton) box.show() win.resize_object_add(box) self.run_command(cmd) def sendPressed(self, btn): print "Sending Data: %s"%(self.sendEntry.text) if self.cmd_exe: ourResult = self.cmd_exe.send("%s\n"%self.sendEntry.text) print("Send Success: %s"%ourResult) self.sendEntry.text = "" def run_command(self, command): self.cmd_exe = cmd = ecore.Exe( command, ecore.ECORE_EXE_PIPE_READ | ecore.ECORE_EXE_PIPE_ERROR | ecore.ECORE_EXE_PIPE_WRITE ) cmd.on_add_event_add(self.command_started) cmd.on_data_event_add(self.received_data) cmd.on_error_event_add(self.received_error) cmd.on_del_event_add(self.command_done) def command_started(self, cmd, event, *args, **kwargs): print("Command started.\n") def received_data(self, cmd, event, *args, **kwargs): print("Output: %s"%event.data) def received_error(self, cmd, event, *args, **kwargs): print("Error: %s" % event.data) def command_done(self, cmd, event, *args, **kwargs): print("Command done.") elementary.exit()
def web_clicked(obj): if not elementary.need_web(): print("EFL-webkit not available!") return win = StandardWindow("web", "Web", autodel=True, size=(800, 600)) if obj is None: win.callback_delete_request_add(lambda o: elementary.exit()) vbx = Box(win, size_hint_weight=EXPAND_BOTH) win.resize_object_add(vbx) vbx.show() web = Web(win, url="http://enlightenment.org/", size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH, size_hint_min=(100, 100)) vbx.pack_end(web) web.show() # Debug: def dbg(*args): print(("DEBUG: %s" % args[-1], " ".join(repr(x) for x in args[1:-1]))) web.callback_link_hover_in_add(dbg, "link in") web.callback_link_hover_out_add(dbg, "link out") web.callback_uri_changed_add(dbg, "uri") web.callback_title_changed_add(dbg, "title") web.callback_load_finished_add(dbg, "load finished") web.callback_load_finished_add(dbg, "load error") web.callback_load_progress_add(dbg, "load progress") web.callback_load_provisional_add(dbg, "load provisional") web.callback_load_started_add(dbg, "load started") # JS debug to console: def console_msg(obj, msg, line, src): print(("CONSOLE: %s:%d %r" % (src, line, msg))) web.console_message_hook_set(console_msg) # navigation bar: hbx = Box(win, horizontal=True, size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ) vbx.pack_start(hbx) hbx.show() bt = Button(win, text="Back") bt.callback_clicked_add(lambda x: web.back()) hbx.pack_end(bt) bt.show() bt = Button(win, text="Forward") bt.callback_clicked_add(lambda x: web.forward()) hbx.pack_end(bt) bt.show() bt = Button(win, text="Reload") bt.callback_clicked_add(lambda x: web.reload()) hbx.pack_end(bt) bt.show() bt = Button(win, text="Stop") bt.callback_clicked_add(lambda x: web.stop()) hbx.pack_end(bt) bt.show() en = Entry(win, scrollable=True, editable=True, single_line=True, size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_BOTH) hbx.pack_end(en) en.show() # Sync navigation entry and current URI def do_change_uri(en): web.uri = en.entry def did_change_uri(web, uri, en): en.entry = uri en.callback_activated_add(do_change_uri) web.callback_uri_changed_add(did_change_uri, en) # Sync title def did_change_title(web, title, win): win.title_set("Web - %s" % title) web.callback_title_changed_add(did_change_title, win) win.show()
def map_clicked(obj): win = StandardWindow("map", "Map test", autodel=True, size=(600, 600)) if obj is None: win.callback_delete_request_add(lambda o: elementary.exit()) vbox = Box(win) vbox.size_hint_weight = EXPAND_BOTH vbox.size_hint_align = FILL_BOTH win.resize_object_add(vbox) vbox.show() map_obj = Map(win, zoom=2) map_obj.size_hint_weight = EXPAND_BOTH map_obj.size_hint_align = FILL_BOTH map_obj.callback_tile_load_add(cb_map_load) map_obj.callback_tile_loaded_add(cb_map_load) map_obj.event_callback_add(EVAS_CALLBACK_MOUSE_DOWN, cb_map_mouse_down) vbox.pack_end(map_obj) map_obj.show() ### lb = Label(win, text="load_status: 0 / 0") vbox.pack_end(lb) lb.show() map_obj.data["lb_load_status"] = lb ### hbox = Box(win, horizontal=True) hbox.size_hint_weight = EXPAND_HORIZ hbox.size_hint_align = FILL_HORIZ vbox.pack_end(hbox) hbox.show() bt = Button(win, text="Goto") bt.callback_clicked_add(cb_btn_goto, map_obj) hbox.pack_end(bt) bt.show() bt = Button(win, text="Zoom +") bt.callback_clicked_add(cb_btn_zoom, map_obj, 1) hbox.pack_end(bt) bt.show() bt = Button(win, text="Zoom -") bt.callback_clicked_add(cb_btn_zoom, map_obj, -1) hbox.pack_end(bt) bt.show() sl = Slider(win, text="Rotation:", min_max=(0, 360), value=0, indicator_format="%3.0f") sl.callback_changed_add(cb_slider_rot, map_obj) hbox.pack_end(sl) sl.show() src_type = ELM_MAP_SOURCE_TYPE_TILE ho = Hoversel(win, hover_parent=win, text="Tiles: %s" % (map_obj.source_get(src_type))) for src in map_obj.sources_get(src_type): ho.item_add(src) ho.callback_selected_add(cb_hovsel_selected, map_obj, src_type, "Tiles") hbox.pack_end(ho) ho.show() ### hbox = Box(win, horizontal=True) hbox.size_hint_weight = EXPAND_HORIZ hbox.size_hint_align = FILL_HORIZ vbox.pack_end(hbox) hbox.show() ck = Check(win, text="wheel_disabled") ck.callback_changed_add(lambda bt: map_obj.wheel_disabled_set(bt.state)) hbox.pack_end(ck) ck.show() ck = Check(win, text="paused") ck.callback_changed_add(lambda bt: map_obj.paused_set(bt.state)) hbox.pack_end(ck) ck.show() ck = Check(win, text="hide overlays") ck.callback_changed_add(cb_chk_overlays_hidden, map_obj) hbox.pack_end(ck) ck.show() ck = Check(win, text="pause overlays") ck.callback_changed_add(cb_chk_overlays_paused, map_obj) hbox.pack_end(ck) ck.show() ### sp = Separator(win, horizontal=True) sp.show() vbox.pack_end(sp) hbox = Box(win, horizontal=True) hbox.size_hint_weight = EXPAND_HORIZ hbox.size_hint_align = FILL_HORIZ vbox.pack_end(hbox) hbox.show() src_type = ELM_MAP_SOURCE_TYPE_ROUTE ho = Hoversel(win, hover_parent=win, text="Routes: %s" % (map_obj.source_get(src_type))) for src in map_obj.sources_get(src_type): ho.item_add(src) ho.callback_selected_add(cb_hovsel_selected, map_obj, src_type, "Routes") hbox.pack_end(ho) ho.show() lb = Label(win, text="Set Start and End point to calculate route") hbox.pack_end(lb) lb.show() map_obj.data["lb_distance"] = lb bt = Button(win, text="Calc route") bt.callback_clicked_add(cb_btn_calc_route, map_obj) hbox.pack_end(bt) bt.show() ### sp = Separator(win, horizontal=True) sp.show() vbox.pack_end(sp) hbox = Box(win, horizontal=True) hbox.size_hint_weight = EXPAND_HORIZ hbox.size_hint_align = FILL_HORIZ vbox.pack_end(hbox) hbox.show() src_type = ELM_MAP_SOURCE_TYPE_NAME ho = Hoversel(win, hover_parent=win, text="Names: %s" % (map_obj.source_get(src_type))) for src in map_obj.sources_get(src_type): ho.item_add(src) ho.callback_selected_add(cb_hovsel_selected, map_obj, src_type, "Names") hbox.pack_end(ho) ho.show() en = Entry(win, scrollable=True, text="type an address here") en.size_hint_weight = EXPAND_BOTH en.size_hint_align = FILL_BOTH en.single_line = True hbox.pack_end(en) en.show() bt = Button(win, text="Search address") bt.callback_clicked_add(cb_btn_search_name, map_obj, en) hbox.pack_end(bt) bt.show() bt = Button(win, text="Search start point") bt.callback_clicked_add(cb_btn_search_region, map_obj, en) hbox.pack_end(bt) bt.show() print_map_info(map_obj) win.show()
def __init__(self, parent, title, rfunc, wfunc): Frame.__init__(self, parent) self.size_hint_weight = EXPAND_HORIZ self.size_hint_align = FILL_HORIZ self.text = title t = Table(self, homogeneous=True, padding=(3, 3)) t.size_hint_weight = EXPAND_HORIZ t.size_hint_align = FILL_HORIZ t.show() l = Label(self, text="Proxy type") l.size_hint_align = 0.0, 0.5 l.show() ptype = Hoversel(parent) ptype.size_hint_align = -1.0, 0.5 ptype.text = rfunc().type.name for n in self.proxy_types.iterkeys(): ptype.item_add(n, callback=lambda x, y, z=n: ptype.text_set(z)) ptype.show() t.pack(l, 0, 0, 1, 1) t.pack(ptype, 1, 0, 1, 1) l = Label(self, text="Hostname") l.size_hint_align = 0.0, 0.5 l.show() phost = Entry(parent) phost.size_hint_weight = EXPAND_HORIZ phost.size_hint_align = FILL_HORIZ phost.single_line = True phost.scrollable = True phost.entry = rfunc().hostname phost.show() t.pack(l, 0, 1, 1, 1) t.pack(phost, 1, 1, 1, 1) l = Label(self, text="Port") l.size_hint_align = 0.0, 0.5 l.show() pport = Spinner(parent) pport.size_hint_align = -1.0, 0.5 pport.min_max = 0, 65535 pport.value = rfunc().port pport.show() t.pack(l, 0, 2, 1, 1) t.pack(pport, 1, 2, 1, 1) l = Label(self, text="Username") l.size_hint_align = 0.0, 0.5 l.show() puser = Entry(parent) puser.size_hint_weight = EXPAND_HORIZ puser.size_hint_align = FILL_HORIZ puser.single_line = True puser.scrollable = True puser.entry = rfunc().username puser.show() t.pack(l, 0, 3, 1, 1) t.pack(puser, 1, 3, 1, 1) l = Label(self, text="Password") l.size_hint_align = 0.0, 0.5 l.show() ppass = Entry(parent) ppass.size_hint_weight = EXPAND_HORIZ ppass.size_hint_align = FILL_HORIZ ppass.single_line = True ppass.scrollable = True ppass.password = True ppass.entry = rfunc().password ppass.show() t.pack(l, 0, 4, 1, 1) t.pack(ppass, 1, 4, 1, 1) entries = [ptype, phost, pport, puser, ppass] save = Button(parent, text="Apply") save.callback_clicked_add(self.save_conf, wfunc, entries) save.show() t.pack(save, 0, 5, 2, 1) self.content = t
def __init__(self, parent, h): if not h.is_valid(): Information(parent.win, "Invalid torrent handle.") return if not h.has_metadata(): Information(parent.win, "Torrent contains no metadata.") return i = h.get_torrent_info() InnerWindow.__init__(self, parent.win) box = Box(self) box.size_hint_align = -1.0, -1.0 box.size_hint_weight = 1.0, 1.0 tname = Label(self) tname.size_hint_align = -1.0, 0.5 tname.line_wrap = ELM_WRAP_CHAR tname.ellipsis = True tname.text = "{}".format(cgi.escape(i.name())) tname.show() box.pack_end(tname) for func in i.comment, i.creation_date, i.creator: try: w = func() except Exception as e: log.debug(e) else: if w: f = Frame(self) f.size_hint_align = -1.0, 0.0 f.text = func.__name__.replace("_", " ").capitalize() l = Label(self) l.ellipsis = True l.text = cgi.escape(str(w)) l.show() f.content = l f.show() box.pack_end(f) tpriv = Check(self) tpriv.size_hint_align = 0.0, 0.0 tpriv.text = "Private" tpriv.tooltip_text_set("Whether this torrent is private.<br> \ i.e., it should not be distributed on the trackerless network<br> \ (the kademlia DHT).") tpriv.disabled = True tpriv.state = i.priv() magnet_uri = lt.make_magnet_uri(h) f = Frame(self) f.size_hint_align = -1.0, 0.0 f.text = "Magnet URI" me_box = Box(self) me_box.horizontal = True me = Entry(self) me.size_hint_align = -1.0, 0.0 me.size_hint_weight = 1.0, 0.0 #me.editable = False me.entry = magnet_uri me_box.pack_end(me) me.show() me_btn = Button(self) me_btn.text = "Copy" if hasattr(me, "cnp_selection_set"): me_btn.callback_clicked_add( lambda x: me.top_widget.cnp_selection_set( ELM_SEL_TYPE_CLIPBOARD, ELM_SEL_FORMAT_TEXT, me.text)) else: import pyperclip me_btn.callback_clicked_add(lambda x: pyperclip.copy(magnet_uri)) me_btn.show() me_box.pack_end(me_btn) me_box.show() f.content = me_box f.show() box.pack_end(f) fl_btn = Button(self) fl_btn.text = "Files ->" fl_btn.callback_clicked_add(self.file_list_cb, h) xbtn = Button(self) xbtn.text_set("Close") xbtn.callback_clicked_add(lambda x: self.delete()) for w in tpriv, fl_btn, xbtn: w.show() box.pack_end(w) box.show() nf = self.nf = Naviframe(self) nf.item_simple_push(box) self.content_set(nf) self.activate()
class AboutWindow(Window): ''' A standardized About Window Class for EFL ''' __initialized = False # pylint: disable=too-many-arguments, too-many-locals, too-many-statements def __init__(self, parent, title='About', standardicon='dialog-information', version='N/A', authors='No One', licen='GPL', webaddress='', info='Something, something, turtles'): if AboutWindow.__initialized: raise InstanceError( "You can't create more than 1 instance of AboutWindow") AboutWindow.__initialized = True self.parent = parent Window.__init__(self, title, ELM_WIN_DIALOG_BASIC, autodel=True) self.callback_delete_request_add(self.cb_close) background = Background(self, size_hint_weight=EXPAND_BOTH) self.resize_object_add(background) background.show() frame = Frame(self, style='pad_large', size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) self.resize_object_add(frame) frame.show() hbox = Box(self, horizontal=True, padding=(12, 12)) frame.content = hbox hbox.show() vbox = Box(self, align=(0.0, 0.0), padding=(6, 6), size_hint_weight=EXPAND_VERT, size_hint_align=FILL_VERT) hbox.pack_end(vbox) vbox.show() # icon + version icon = Icon(self, size_hint_min=(64, 64)) icon.standard_set(standardicon) vbox.pack_end(icon) icon.show() ver_lb = Label(self, text=f'Version: {version}') vbox.pack_end(ver_lb) ver_lb.show() sep = Separator(self, horizontal=True) vbox.pack_end(sep) sep.show() # buttons btn = Button(self, text=(title), size_hint_align=FILL_HORIZ) btn.callback_clicked_add(lambda b: self.entry.text_set(info)) vbox.pack_end(btn) btn.show() btn = Button(self, text=('Website'), size_hint_align=FILL_HORIZ) btn.callback_clicked_add(lambda b: xdg_open(webaddress)) vbox.pack_end(btn) btn.show() btn = Button(self, text=('Authors'), size_hint_align=FILL_HORIZ) btn.callback_clicked_add(lambda b: self.entry.text_set(authors)) vbox.pack_end(btn) btn.show() btn = Button(self, text=('License'), size_hint_align=FILL_HORIZ) btn.callback_clicked_add(lambda b: self.entry.text_set(licen)) vbox.pack_end(btn) btn.show() # main text self.entry = Entry(self, editable=False, scrollable=True, text=info, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) self.entry.callback_anchor_clicked_add(lambda e, i: xdg_open(i.name)) hbox.pack_end(self.entry) self.entry.show() self.resize(400, 200) self.show() # pylint: disable=no-self-use def cb_close(self, obj): '''Callback on close''' AboutWindow.__initialized = False