def cursor2_clicked(obj, item=None): win = StandardWindow("cursors", "Cursors 2", autodel=True, size=(320, 480)) bx = Box(win, size_hint_weight=EXPAND_BOTH) win.resize_object_add(bx) bx.show() tb = Toolbar(win, size_hint_weight=(0.0, 0.0), size_hint_align=(EVAS_HINT_FILL, 0.0)) ti = tb.item_append("folder-new", "Bogosity", None, None) ti.cursor_set("bogosity") ti = tb.item_append("clock", "Unset", None, None) ti.cursor_unset() ti = tb.item_append("document-print", "Xterm", None, None) ti.cursor_set("xterm") bx.pack_end(tb) tb.show() lst = List(win, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) li = lst.item_append("cursor bogosity") li.cursor_set("bogosity") li = lst.item_append("cursor unset") li.cursor_unset() li = lst.item_append("cursor xterm") li.cursor_set("xterm") bx.pack_end(lst) lst.go() lst.show() win.show()
def __init__(self): self.win = StandardWindow("test", "Toolbar_issue", size=(600, 400)) self.win.callback_delete_request_add(lambda x: elementary.exit()) box0 = Box(self.win) #, size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_BOTH) self.win.resize_object_add(box0) box0.show() tb = Toolbar(self.win, homogeneous=True, size_hint_weight=EXPAND_HORIZ, size_hint_align=(EVAS_HINT_FILL, 0.0), select_mode=ELM_OBJECT_SELECT_MODE_DEFAULT) self.menuItem = tb.item_append("document-save", "Save", self.popup) tb.show() box0.pack_end(tb) lb = Label(self.win) lb.text_set("<br>This is a test program to illustrate a problem <br>" "with the Radiance e19 theme.<br><br>" "Disabling a toolbar item and then re-enabling it does not<br>" "re-enable the toolbar item's <i>callback function</i>.<br><br>" "To test this first click <b>Save</b> when this program is opened<br>" "This opens a popup as expected. Dismiss popup.<br><br>" "Now click the <b>Toggle</b> button to disable <b>Save</b> Toolbar Item<br>" "After this the <b>Save</b> button is disabled and 'looks different'<br><br>" "Click the <b>Toggle</b> button again to enable <b>Save</b><br>" "After this clicking <b>Save</b> does nothing even tho it 'looks' enabled<br><br>" ) lb.show() box0.pack_end(lb) testButton = Button(self.win, text="Toogle") testButton.callback_clicked_add(self.disable) testButton.show() box0.pack_end(testButton) self.win.show()
def __init__(self, parent, session): self.parent = parent self.session = session elm_conf = Configuration() scale = elm_conf.scale self.log = logging.getLogger("epour.gui") self.torrentitems = {} win = self.win = StandardWindow("epour", "Epour") win.callback_delete_request_add(lambda x: elm.exit()) win.screen_constrain = True win.size = 480 * scale, 400 * scale mbox = Box(win) mbox.size_hint_weight = 1.0, 1.0 win.resize_object_add(mbox) mbox.show() tb = Toolbar(win) tb.homogeneous = False tb.shrink_mode = ELM_TOOLBAR_SHRINK_NONE tb.select_mode = ELM_OBJECT_SELECT_MODE_NONE tb.size_hint_align = -1.0, 0.0 tb.menu_parent = win item = tb.item_append("document-new", "Add torrent", lambda t,i: self.select_torrent()) def pause_session(it): self.session.pause() it.state_set(it.state_next()) def resume_session(it): session.resume() del it.state item = tb.item_append("media-playback-pause", "Pause Session", lambda tb, it: pause_session(it)) item.state_add("media-playback-start", "Resume Session", lambda tb, it: resume_session(it)) item = tb.item_append("preferences-system", "Preferences") item.menu = True item.menu.item_add(None, "General", "preferences-system", lambda o,i: PreferencesGeneral(self, self.session)) item.menu.item_add(None, "Proxy", "preferences-system", lambda o,i: PreferencesProxy(self, self.session)) item.menu.item_add(None, "Session", "preferences-system", lambda o,i: PreferencesSession(self, self.session)) item = tb.item_append("application-exit", "Exit", lambda tb, it: elm.exit()) mbox.pack_start(tb) tb.show() self.tlist = tlist = Genlist(win) tlist.select_mode = ELM_OBJECT_SELECT_MODE_NONE tlist.mode = ELM_LIST_COMPRESS tlist.callback_activated_add(self.item_activated_cb) tlist.homogeneous = True tlist.size_hint_weight = 1.0, 1.0 tlist.size_hint_align = -1.0, -1.0 tlist.show() mbox.pack_end(tlist) pad = Rectangle(win.evas) pad.size_hint_weight = 1.0, 1.0 p = Panel(win) p.color = 200,200,200,200 p.size_hint_weight = 1.0, 1.0 p.size_hint_align = -1.0, -1.0 p.orient = ELM_PANEL_ORIENT_BOTTOM p.content = SessionStatus(win, session) p.hidden = True p.show() topbox = Box(win) topbox.horizontal = True topbox.size_hint_weight = 1.0, 1.0 win.resize_object_add(topbox) topbox.pack_end(pad) topbox.pack_end(p) topbox.stack_above(mbox) topbox.show() session.alert_manager.callback_add( "torrent_added_alert", self.torrent_added_cb) session.alert_manager.callback_add( "torrent_removed_alert", self.torrent_removed_cb) for a_name in "torrent_paused_alert", "torrent_resumed_alert": session.alert_manager.callback_add(a_name, self.update_icon) session.alert_manager.callback_add( "state_changed_alert", self.state_changed_cb) Timer(15.0, lambda: session.alert_manager.callback_add( "torrent_finished_alert", self.torrent_finished_cb))
def __init__(self, parent, session): self.parent = parent self.session = session elm_conf = Configuration() scale = elm_conf.scale self.log = logging.getLogger("epour.gui") self.torrentitems = {} win = self.win = StandardWindow("epour", "Epour") win.callback_delete_request_add(lambda x: elm.exit()) win.screen_constrain = True win.size = 480 * scale, 400 * scale mbox = Box(win) mbox.size_hint_weight = 1.0, 1.0 win.resize_object_add(mbox) mbox.show() tb = Toolbar(win) tb.homogeneous = False tb.shrink_mode = ELM_TOOLBAR_SHRINK_NONE tb.select_mode = ELM_OBJECT_SELECT_MODE_NONE tb.size_hint_align = -1.0, 0.0 tb.menu_parent = win item = tb.item_append("document-new", "Add torrent", lambda t, i: self.select_torrent()) def pause_session(it): self.session.pause() it.state_set(it.state_next()) def resume_session(it): session.resume() del it.state item = tb.item_append("media-playback-pause", "Pause Session", lambda tb, it: pause_session(it)) item.state_add("media-playback-start", "Resume Session", lambda tb, it: resume_session(it)) item = tb.item_append("preferences-system", "Preferences") item.menu = True item.menu.item_add(None, "General", "preferences-system", lambda o, i: PreferencesGeneral(self, self.session)) item.menu.item_add(None, "Proxy", "preferences-system", lambda o, i: PreferencesProxy(self, self.session)) item.menu.item_add(None, "Session", "preferences-system", lambda o, i: PreferencesSession(self, self.session)) item = tb.item_append("application-exit", "Exit", lambda tb, it: elm.exit()) mbox.pack_start(tb) tb.show() self.tlist = tlist = Genlist(win) tlist.select_mode = ELM_OBJECT_SELECT_MODE_NONE tlist.mode = ELM_LIST_COMPRESS tlist.callback_activated_add(self.item_activated_cb) tlist.homogeneous = True tlist.size_hint_weight = 1.0, 1.0 tlist.size_hint_align = -1.0, -1.0 tlist.show() mbox.pack_end(tlist) pad = Rectangle(win.evas) pad.size_hint_weight = 1.0, 1.0 p = Panel(win) p.color = 200, 200, 200, 200 p.size_hint_weight = 1.0, 1.0 p.size_hint_align = -1.0, -1.0 p.orient = ELM_PANEL_ORIENT_BOTTOM p.content = SessionStatus(win, session) p.hidden = True p.show() topbox = Box(win) topbox.horizontal = True topbox.size_hint_weight = 1.0, 1.0 win.resize_object_add(topbox) topbox.pack_end(pad) topbox.pack_end(p) topbox.stack_above(mbox) topbox.show() session.alert_manager.callback_add("torrent_added_alert", self.torrent_added_cb) session.alert_manager.callback_add("torrent_removed_alert", self.torrent_removed_cb) for a_name in "torrent_paused_alert", "torrent_resumed_alert": session.alert_manager.callback_add(a_name, self.update_icon) session.alert_manager.callback_add("state_changed_alert", self.state_changed_cb) Timer( 15.0, lambda: session.alert_manager.callback_add( "torrent_finished_alert", self.torrent_finished_cb))
def toolbar_clicked(obj, item=None): win = StandardWindow("toolbar", "Toolbar", autodel=True, size=(320, 300)) 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() tbl = Table(win, size_hint_weight=(0.0, EVAS_HINT_EXPAND), size_hint_align=FILL_BOTH) tb = Toolbar(win, homogeneous=False, size_hint_weight=(0.0, 0.0), size_hint_align=(EVAS_HINT_FILL, 0.0)) ph1 = Photo(win, size=40, file=os.path.join(img_path, "plant_01.jpg"), size_hint_weight=EXPAND_BOTH, size_hint_align=ALIGN_CENTER) tbl.pack(ph1, 0, 0, 1, 1) ph1.show() ph2 = Photo(win, size=80, size_hint_weight=EXPAND_BOTH, size_hint_align=ALIGN_CENTER) tbl.pack(ph2, 1, 0, 1, 1) ph2.show() ph3 = Photo(win, size=40, file=os.path.join(img_path, "sky_01.jpg"), size_hint_weight=EXPAND_BOTH, size_hint_align=ALIGN_CENTER) tbl.pack(ph3, 0, 1, 1, 1) ph3.show() ph4 = Photo(win, size=60, file=os.path.join(img_path, "sky_02.jpg"), size_hint_weight=EXPAND_BOTH, size_hint_align=ALIGN_CENTER) tbl.pack(ph4, 1, 1, 1, 1) ph4.show() item = tb.item_append("document-print", "Hello", tb_1) item.disabled = True item = tb.item_append("clock", "World,", tb_2, ph2) item.selected = True tb.item_append("folder-new", "here", tb_3, ph4) tb.item_append("clock", "comes", tb_4, ph4) tb.item_append("folder-new", "python-elementary!", tb_5, ph4) item = tb.item_append("clock", "Menu", tb_5, ph4) item.menu = True tb.menu_parent = win menu = item.menu menu.item_add(None, "Here", "clock", tb_3, ph4) menu_item = menu.item_add(None, "Comes", "refresh", tb_4, ph4) menu.item_add(menu_item, "hey ho", "folder-new", tb_4, ph4) menu.item_add(None, "python-elementary", "document-print", tb_5, ph4) bx.pack_end(tb) tb.show() bx.pack_end(tbl) tbl.show() win.show()
def toolbar5_clicked(obj, item=None): win = StandardWindow("toolbar5", "Toolbar 5", autodel=True, size=(320, 300)) win.autodel = True bx = Box(win, size_hint_weight=EXPAND_BOTH) win.resize_object_add(bx) bx.show() tbl = Table(win, size_hint_weight=(0.0, EVAS_HINT_EXPAND), size_hint_align=FILL_BOTH) tb = Toolbar(win, homogeneous=False, shrink_mode=ELM_TOOLBAR_SHRINK_MENU, size_hint_weight=(0.0, 0.0), size_hint_align=(EVAS_HINT_FILL, 0.0), select_mode=ELM_OBJECT_SELECT_MODE_NONE) ph1 = Photo(win, size=40, file=os.path.join(img_path, "plant_01.jpg"), size_hint_weight=EXPAND_BOTH, size_hint_align=ALIGN_CENTER) tbl.pack(ph1, 0, 0, 1, 1) ph1.show() ph2 = Photo(win, size=80, size_hint_weight=EXPAND_BOTH, size_hint_align=ALIGN_CENTER) tbl.pack(ph2, 1, 0, 1, 1) ph2.show() ph3 = Photo(win, size=20, file=os.path.join(img_path, "sky_01.jpg"), size_hint_weight=EXPAND_BOTH, size_hint_align=ALIGN_CENTER) tbl.pack(ph3, 0, 1, 1, 1) ph3.show() ph4 = Photo(win, size=60, file=os.path.join(img_path, "sky_02.jpg"), size_hint_weight=EXPAND_BOTH, size_hint_align=ALIGN_CENTER) tbl.pack(ph4, 1, 1, 1, 1) ph4.show() tb_it = tb.item_append("document-print", "Hello", tb_1, ph1) tb_it.disabled = True tb_it.priority = 100 tb_it = tb.item_append(os.path.join(img_path, "icon_04.png"), "World", tb_2, ph1) tb_it.priority = -100 tb_it = tb.item_append("object-rotate-right", "H", tb_3a, ph4) tb_it.state_add("object-rotate-left", "H2", tb_3b, ph4) tb_it.priority = 150 tb_it = tb.item_append("mail-send", "Comes", tb_4a, ph4) tb_it.state_add("emptytrash", "Comes2", tb_4a, ph4) tb_it.state_add("trashcan_full", "Comes3", tb_4a, ph4) tb_it.priority = 0 tb_it = tb.item_append("clock", "Elementary", tb_5, ph4) tb_it.priority = -200 tb_it = tb.item_append("refresh", "Menu") tb_it.menu = True tb_it.priority = -9999 tb.menu_parent = win menu = tb_it.menu menu.item_add(None, "edit-cut", "Shrink", tb_3, ph4) menu_it = menu.item_add(None, "edit-copy", "Mode", tb_4, ph4) menu.item_add(menu_it, "edit-paste", "is set to", tb_4, ph4) menu.item_add(None, "edit-delete", "Menu", tb_5, ph4) bx.pack_end(tb) tb.show() bx.pack_end(tbl) tbl.show() win.show()
def focus_clicked(obj, item=None): win = StandardWindow("focus", "Focus", autodel=True, size=(800,600)) win.focus_highlight_enabled = True tbx = Box(win, size_hint_weight=EXPAND_BOTH) win.resize_object_add(tbx) tbx.show() ### Toolbar tbar = Toolbar(win, shrink_mode=ELM_TOOLBAR_SHRINK_MENU, size_hint_align=(EVAS_HINT_FILL,0.0)) tb_it = tbar.item_append("document-print", "Hello", _tb_sel) tb_it.disabled = True tb_it = tbar.item_append("folder-new", "World", _tb_sel) tb_it = tbar.item_append("object-rotate-right", "H", _tb_sel) tb_it = tbar.item_append("mail-send", "Comes", _tb_sel) tb_it = tbar.item_append("clock", "Elementary", _tb_sel) tb_it = tbar.item_append("refresh", "Menu", _tb_sel) tb_it.menu = True tbar.menu_parent = win menu = tb_it.menu menu.item_add(None, "Shrink", "edit-cut", _tb_sel) menu_it = menu.item_add(None, "Mode", "edit-copy", _tb_sel) menu.item_add(menu_it, "is set to", "edit-paste", _tb_sel) menu.item_add(menu_it, "or to", "edit-paste", _tb_sel) menu.item_add(None, "Menu", "edit-delete", _tb_sel) tbx.pack_end(tbar) tbar.show() mainbx = Box(win, horizontal=True, size_hint_weight=EXPAND_BOTH) tbx.pack_end(mainbx) mainbx.show() ## First Col bx = Box(win, size_hint_weight=EXPAND_BOTH) mainbx.pack_end(bx) bx.show() lb = Label(win, text="<b>Use Tab or Shift+Tab<br/>or Arrow keys</b>", size_hint_align=FILL_BOTH) bx.pack_end(lb) lb.show() tg = Check(win, style="toggle") tg.part_text_set("on", "Yes") tg.part_text_set("off", "No") bx.pack_end(tg) tg.show() en = Entry(win, scrollable=True, single_line=True, text="This is a single line", size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ) bx.pack_end(en) en.show() # bx2 = Box(win, horizontal=True, size_hint_align=FILL_BOTH) bx.pack_end(bx2) bx2.show() for i in range(2): bt = Button(win, text="Box", size_hint_align=FILL_BOTH, disabled=(i % 2)) bx2.pack_end(bt) bt.show() sc = Scroller(win, bounce=(True,True), content_min_limit=(1,1), size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) bx2.pack_end(sc) sc.show() bt = Button(win, text="Scroller", size_hint_align=FILL_BOTH) sc.content = bt bt.show() # bt = Button(win, text="Box", size_hint_align=FILL_BOTH) bx.pack_end(bt) bt.show() # bx2 = Box(win, horizontal=True, size_hint_align=FILL_BOTH) bx.pack_end(bx2) bx2.show() for i in range(2): bx3 = Box(win, size_hint_align=FILL_BOTH) bx2.pack_end(bx3) bx3.show() for j in range(3): bt = Button(win, text="Box", size_hint_align=FILL_BOTH) bx3.pack_end(bt) bt.show() sc = Scroller(win, bounce=(False, True), content_min_limit=(1,0), size_hint_align=FILL_BOTH, size_hint_weight=EXPAND_BOTH) sc.content_min_limit=(1,1) bx2.pack_end(sc) sc.show() bx3 = Box(win, size_hint_align=FILL_BOTH) sc.content = bx3 bx3.show() for i in range(5): bt = Button(win, text="BX Scroller", size_hint_align=FILL_BOTH) bx3.pack_end(bt) bt.show() ## Second Col ly = Layout(win, size_hint_weight=EXPAND_BOTH) ly.file = edj_file, "twolines" mainbx.pack_end(ly) ly.show() bx2 = Box(win, horizontal=True, size_hint_align=FILL_BOTH) ly.part_content_set("element1", bx2) bx2.show() for i in range(3): bt = Button(win, text="Layout", size_hint_align=FILL_BOTH) bx2.pack_end(bt) bt.show() bx2.focus_custom_chain_prepend(bt) bx2 = Box(win, size_hint_align=FILL_BOTH) ly.part_content_set("element2", bx2) bx2.show() bt = Button(win, text="Disable", size_hint_align=FILL_BOTH) bt.callback_clicked_add(lambda b: b.disabled_set(True)) bx2.pack_end(bt) bt.show() bx2.focus_custom_chain_prepend(bt) bt2 = Button(win, text="Enable", size_hint_align=FILL_BOTH) bt2.callback_clicked_add(lambda b, b1: b1.disabled_set(False), bt) bx2.pack_end(bt2) bt2.show() bx2.focus_custom_chain_append(bt2) ## Third Col bx = Box(win, size_hint_weight=EXPAND_BOTH) mainbx.pack_end(bx) bx.show() fr = Frame(win, text="Frame", ) bx.pack_end(fr) fr.show() tb = Table(win, size_hint_weight=EXPAND_BOTH) fr.content = tb tb.show() for j in range(1): for i in range(2): bt = Button(win, text="Table", size_hint_align=FILL_BOTH, size_hint_weight=EXPAND_BOTH) tb.pack(bt, i, j, 1, 1) bt.show() # fr = Bubble(win, text="Bubble", size_hint_align=FILL_BOTH, size_hint_weight=EXPAND_BOTH) bx.pack_end(fr) fr.show() tb = Table(win, size_hint_weight=EXPAND_BOTH) fr.content = tb tb.show() for j in range(2): for i in range(1): bt = Button(win, text="Table", size_hint_align=FILL_BOTH, size_hint_weight=EXPAND_BOTH) tb.pack(bt, i, j, 1, 1) bt.show() win.show()
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 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()
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()
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 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()
def focus_clicked(obj, item=None): win = StandardWindow("focus", "Focus", autodel=True, size=(800, 600)) win.focus_highlight_enabled = True tbx = Box(win, size_hint_weight=EXPAND_BOTH) win.resize_object_add(tbx) tbx.show() ### Toolbar tbar = Toolbar(win, shrink_mode=ELM_TOOLBAR_SHRINK_MENU, size_hint_align=(EVAS_HINT_FILL, 0.0)) tb_it = tbar.item_append("document-print", "Hello", _tb_sel) tb_it.disabled = True tb_it = tbar.item_append("folder-new", "World", _tb_sel) tb_it = tbar.item_append("object-rotate-right", "H", _tb_sel) tb_it = tbar.item_append("mail-send", "Comes", _tb_sel) tb_it = tbar.item_append("clock", "Elementary", _tb_sel) tb_it = tbar.item_append("refresh", "Menu", _tb_sel) tb_it.menu = True tbar.menu_parent = win menu = tb_it.menu menu.item_add(None, "Shrink", "edit-cut", _tb_sel) menu_it = menu.item_add(None, "Mode", "edit-copy", _tb_sel) menu.item_add(menu_it, "is set to", "edit-paste", _tb_sel) menu.item_add(menu_it, "or to", "edit-paste", _tb_sel) menu.item_add(None, "Menu", "edit-delete", _tb_sel) tbx.pack_end(tbar) tbar.show() mainbx = Box(win, horizontal=True, size_hint_weight=EXPAND_BOTH) tbx.pack_end(mainbx) mainbx.show() ## First Col bx = Box(win, size_hint_weight=EXPAND_BOTH) mainbx.pack_end(bx) bx.show() lb = Label(win, text="<b>Use Tab or Shift+Tab<br/>or Arrow keys</b>", size_hint_align=FILL_BOTH) bx.pack_end(lb) lb.show() tg = Check(win, style="toggle") tg.part_text_set("on", "Yes") tg.part_text_set("off", "No") bx.pack_end(tg) tg.show() en = Entry(win, scrollable=True, single_line=True, text="This is a single line", size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ) bx.pack_end(en) en.show() # bx2 = Box(win, horizontal=True, size_hint_align=FILL_BOTH) bx.pack_end(bx2) bx2.show() for i in range(2): bt = Button(win, text="Box", size_hint_align=FILL_BOTH, disabled=(i % 2)) bx2.pack_end(bt) bt.show() sc = Scroller(win, bounce=(True, True), content_min_limit=(1, 1), size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) bx2.pack_end(sc) sc.show() bt = Button(win, text="Scroller", size_hint_align=FILL_BOTH) sc.content = bt bt.show() # bt = Button(win, text="Box", size_hint_align=FILL_BOTH) bx.pack_end(bt) bt.show() # bx2 = Box(win, horizontal=True, size_hint_align=FILL_BOTH) bx.pack_end(bx2) bx2.show() for i in range(2): bx3 = Box(win, size_hint_align=FILL_BOTH) bx2.pack_end(bx3) bx3.show() for j in range(3): bt = Button(win, text="Box", size_hint_align=FILL_BOTH) bx3.pack_end(bt) bt.show() sc = Scroller(win, bounce=(False, True), content_min_limit=(1, 0), size_hint_align=FILL_BOTH, size_hint_weight=EXPAND_BOTH) sc.content_min_limit = (1, 1) bx2.pack_end(sc) sc.show() bx3 = Box(win, size_hint_align=FILL_BOTH) sc.content = bx3 bx3.show() for i in range(5): bt = Button(win, text="BX Scroller", size_hint_align=FILL_BOTH) bx3.pack_end(bt) bt.show() ## Second Col ly = Layout(win, size_hint_weight=EXPAND_BOTH) ly.file = edj_file, "twolines" mainbx.pack_end(ly) ly.show() bx2 = Box(win, horizontal=True, size_hint_align=FILL_BOTH) ly.part_content_set("element1", bx2) bx2.show() for i in range(3): bt = Button(win, text="Layout", size_hint_align=FILL_BOTH) bx2.pack_end(bt) bt.show() bx2.focus_custom_chain_prepend(bt) bx2 = Box(win, size_hint_align=FILL_BOTH) ly.part_content_set("element2", bx2) bx2.show() bt = Button(win, text="Disable", size_hint_align=FILL_BOTH) bt.callback_clicked_add(lambda b: b.disabled_set(True)) bx2.pack_end(bt) bt.show() bx2.focus_custom_chain_prepend(bt) bt2 = Button(win, text="Enable", size_hint_align=FILL_BOTH) bt2.callback_clicked_add(lambda b, b1: b1.disabled_set(False), bt) bx2.pack_end(bt2) bt2.show() bx2.focus_custom_chain_append(bt2) ## Third Col bx = Box(win, size_hint_weight=EXPAND_BOTH) mainbx.pack_end(bx) bx.show() fr = Frame( win, text="Frame", ) bx.pack_end(fr) fr.show() tb = Table(win, size_hint_weight=EXPAND_BOTH) fr.content = tb tb.show() for j in range(1): for i in range(2): bt = Button(win, text="Table", size_hint_align=FILL_BOTH, size_hint_weight=EXPAND_BOTH) tb.pack(bt, i, j, 1, 1) bt.show() # fr = Bubble(win, text="Bubble", size_hint_align=FILL_BOTH, size_hint_weight=EXPAND_BOTH) bx.pack_end(fr) fr.show() tb = Table(win, size_hint_weight=EXPAND_BOTH) fr.content = tb tb.show() for j in range(2): for i in range(1): bt = Button(win, text="Table", size_hint_align=FILL_BOTH, size_hint_weight=EXPAND_BOTH) tb.pack(bt, i, j, 1, 1) bt.show() win.show()