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 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()
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()
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()