Example #1
0
File: gui.py Project: lonid/epack
class FileSelectorInwin(Fileselector):
    def __init__(self, parent, title, done_cb, **kargs):
        self._user_cb = done_cb

        self._inwin = InnerWindow(parent)

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

        lb = Label(vbox, text='<b>%s</b>' % title)
        vbox.pack_end(lb)
        lb.show()

        Fileselector.__init__(self, vbox, expandable=False,
                              size_hint_weight=EXPAND_BOTH,
                              size_hint_align=FILL_BOTH, **kargs)
        self.callback_done_add(self._fileselector_done_cb)
        self.callback_activated_add(self._fileselector_done_cb)
        # TODO this filter seems not to work well...need fixing
        # fs.mime_types_filter_append(list(EXTRACT_MAP.keys()), 'Archive files')
        # fs.mime_types_filter_append(['*'], 'All files')
        vbox.pack_end(self)
        self.show()

        self._inwin.activate()

    def delete(self):
        self._inwin.delete()

    def _fileselector_done_cb(self, fs, path):
        if path is not None:
            self._user_cb(path)
        self.delete()
Example #2
0
    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()
Example #3
0
    def __init__(self, parent, title, done_cb, **kargs):
        self._user_cb = done_cb

        self._inwin = InnerWindow(parent)

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

        lb = Label(vbox, text='<b>%s</b>' % title)
        vbox.pack_end(lb)
        lb.show()

        Fileselector.__init__(self,
                              vbox,
                              expandable=False,
                              size_hint_weight=EXPAND_BOTH,
                              size_hint_align=FILL_BOTH,
                              **kargs)
        self.callback_done_add(self._fileselector_done_cb)
        self.callback_activated_add(self._fileselector_done_cb)
        # TODO this filter seems not to work well...need fixing
        # fs.mime_types_filter_append(list(EXTRACT_MAP.keys()), 'Archive files')
        # fs.mime_types_filter_append(['*'], 'All files')
        vbox.pack_end(self)
        self.show()

        self._inwin.activate()
Example #4
0
    def __init__(self, parent, title, done_cb, folder_only=False, **kargs):
        self._user_cb = done_cb

        self._inwin = InnerWindow(parent)

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

        lb = Label(vbox, text='<b>%s</b>' % title)
        vbox.pack_end(lb)
        lb.show()

        Fileselector.__init__(self, vbox, expandable=False,
                              size_hint_weight=EXPAND_BOTH,
                              size_hint_align=FILL_BOTH, **kargs)
        self.folderOnlySet(folder_only)
        self.setMode("Open")
        self.callback_cancel_add(self.delete)
        self.callback_activated_add(self._fileselector_done_cb)
        # TODO this filter seems not to work well...need fixing
        # fs.mime_types_filter_append(list(EXTRACT_MAP.keys()), 'Archive files')
        # fs.mime_types_filter_append(['*'], 'All files')
        vbox.pack_end(self)
        self.show()

        self._inwin.activate()
Example #5
0
    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 inner_window_clicked(obj):
    win = StandardWindow("inner-window", "InnerWindow test", autodel=True,
        size=(320, 320))
    if obj is None:
        win.callback_delete_request_add(lambda o: elementary.exit())

    lb = Label(win)
    lb.text_set("This is an \"inwin\" - a window in a<br/>"
                "window. This is handy for quick popups<br/>"
                "you want centered, taking over the window<br/>"
                "until dismissed somehow. Unlike hovers they<br/>"
                "don't hover over their target.")

    iw = InnerWindow(win, content=lb)
    iw.show()

    win.resize(320, 320)
    win.show()
Example #7
0
    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()
Example #8
0
    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)
Example #9
0
    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)
Example #10
0
    def __init__(self,
                 command=None,
                 win=None,
                 start_callback=None,
                 end_callback=None,
                 *args,
                 **kwargs):
        if not win:
            nowindow = True
            win = self.win = Window("esudo", ELM_WIN_DIALOG_BASIC)
            win.title = "eSudo"
            win.borderless = True
            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.layer_set(11)
            #~ win.fullscreen = True
            win.show()
            win.activate()

            bg = Background(win)
            bg.size_hint_weight = 1.0, 1.0
            win.resize_object_add(bg)
            bg.show()

            self.embedded = False
        else:
            nowindow = False
            self.embedded = True

        self.cmd = command
        self.start_cb = start_callback if callable(start_callback) else None
        self.end_cb = end_callback if callable(end_callback) else None
        self.args = args
        self.kwargs = kwargs

        #--------eSudo Window
        bz = Box(win)
        if nowindow:
            bz.size_hint_weight = evas.EVAS_HINT_EXPAND, 0.0
        else:
            bz.size_hint_weight = evas.EVAS_HINT_EXPAND, evas.EVAS_HINT_EXPAND
        bz.size_hint_align = evas.EVAS_HINT_FILL, 0.0
        bz.show()

        if nowindow:
            lbl = Label(win)
            lbl.style = "marker"
            lbl.color = 170, 170, 170, 255
            lbl.size_hint_align = 0.5, 0.0
            lbl.scale = 2.0
            lbl.text = "<b>eSudo</b>"
            bz.pack_end(lbl)
            lbl.show()

            sep = Separator(win)
            sep.horizontal = True
            bz.pack_end(sep)
            sep.show()

        fr = Frame(win)
        fr.text = "Command:"
        fr.size_hint_align = evas.EVAS_HINT_FILL, 0.0
        bz.pack_end(fr)
        fr.show()

        if nowindow:
            sep = Separator(win)
            sep.horizontal = True
            bz.pack_end(sep)
            sep.show()

        self.cmdline = cmdline = Entry(win)
        cmdline.elm_event_callback_add(self.entry_event)
        cmdline.single_line = True
        if self.cmd:
            cmdline.text = self.cmd
            cmdline.editable = False
        fr.content = cmdline
        cmdline.scrollable_set(True)
        cmdline.show()

        if nowindow:
            fr = Frame(win)
            fr.text = "Password:"******"<b>Password:</b>"
            lb.size_hint_align = 0.0, 0.5
            bz1.pack_end(lb)
            lb.show()

        en = self.en = Entry(win)
        en.name = "password"
        en.elm_event_callback_add(self.entry_event)
        en.single_line = True
        en.password = True
        en.show()

        if nowindow:
            fr.content = en
        else:
            bz1.pack_end(en)

        sep = Separator(win)
        sep.horizontal = True
        bz.pack_end(sep)
        sep.show()

        btnb = Box(win)
        btnb.horizontal = True
        btnb.size_hint_weight = evas.EVAS_HINT_EXPAND, 0.0
        btnb.size_hint_align = evas.EVAS_HINT_FILL, evas.EVAS_HINT_FILL
        bz.pack_end(btnb)
        btnb.show()

        bt = Button(win)
        bt.text = "Cancel"
        bt.callback_clicked_add(self.esudo_cancel, en)
        bt.size_hint_align = evas.EVAS_HINT_FILL, evas.EVAS_HINT_FILL
        bt.size_hint_weight = evas.EVAS_HINT_EXPAND, 0.0
        btnb.pack_end(bt)
        bt.show()

        bt = Button(win)
        bt.text = "OK"
        bt.callback_clicked_add(self.password_check, en)
        bt.size_hint_align = evas.EVAS_HINT_FILL, evas.EVAS_HINT_FILL
        bt.size_hint_weight = evas.EVAS_HINT_EXPAND, 0.0
        btnb.pack_end(bt)
        bt.show()

        self.iw = iw = InnerWindow(win)
        iw.content = bz
        iw.show()
        iw.activate()
        if self.cmd:
            en.focus = True
    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()
Example #12
0
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()
Example #13
0
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()