Commits

Moises Henriquez  committed aec4c7f

begin implementing uninstall option to remove packages

  • Participants
  • Parent commits ae1981d

Comments (0)

Files changed (6)

 from utils import vl
 from view import widgets
 from view import dialog
+from view import message
 import os
 import tempfile as tmp
 
         self.add(body)
 
         pane = gtk.HPaned()
-        pane.set_position(100)
+        pane.set_position(150)
         body.pack_start(pane, True, True, 0)
         self.body = body
 
                 app_pool,
                 cache,
                 app_display)
-        lpane.add_category(Icon = 'data/icons/All-apps.png',
-                label = _('All'))
-        lpane.add_category(Icon = 'data/icons/Audio.png',
-                label = _('Audio'))
-        lpane.add_category(Icon = 'data/icons/Video.png',
-                label = _('Video'))
-        lpane.add_category(Icon = 'data/icons/Graphics.png',
-                label = _('Graphics'))
-        lpane.add_category(Icon = 'data/icons/Other.png',
-                label = _('Bonus'))
+        lpane.add_category(icon = 'data/icons/All-apps.png',
+                label = _('All'), overlay = False)
+        lpane.add_category(icon = 'data/icons/Audio.png',
+                label = _('Audio'), overlay = False)
+        lpane.add_category(icon = 'data/icons/Video.png',
+                label = _('Video'), overlay = False)
+        lpane.add_category(icon = 'data/icons/Graphics.png',
+                label = _('Graphics'), overlay = False)
+        lpane.add_category(icon = 'data/icons/Other.png',
+                label = _('Bonus'), overlay = False)
+        lpane.add_category(icon = 'data/icons/applications-other.png',
+                label = _('Installed Only'),
+                overlay = True)
+        self.categoriespanel = lpane
+        vpanel = gtk.VBox()
+        vpanel.pack_start(lpane, True, True, 0)
 
-        self.categoriespanel = lpane
-        pane.pack1(lpane)
+        pane.pack1(vpanel)
         pane.pack2(rpane)
         self._catpanel = lpane
         bottombar = gtk.HBox()
 
         # Get the number of selected items
         i = 0
+        rimg = gtk.Image()
+        rimg.set_from_stock(gtk.STOCK_REMOVE, gtk.ICON_SIZE_BUTTON)
+        iimg = gtk.Image()
+        iimg.set_from_stock(gtk.STOCK_APPLY, gtk.ICON_SIZE_BUTTON)
         model = self.display.get_model()
         if self._stop_monitor is True:
            return
                     len(model), _('items displayed')))
                 self.actionbtn.set_property('sensitive', False)
                 gtk.gdk.threads_leave()
+            if self.categoriespanel._get_selected() == _('Installed Only'):
+                gtk.gdk.threads_enter()
+                self.actionbtn.set_property('label', _('Uninstall Selected'))
+                self.actionbtn.set_image(rimg)
+                gtk.gdk.threads_leave()
+            else:
+                gtk.gdk.threads_enter()
+                self.actionbtn.set_property('label', _('Install Selected'))
+                self.actionbtn.set_image(iimg)
+                gtk.gdk.threads_leave()
 
     def selectall_event(self, widget):
         if widget.get_label() == _('Select All'):
 
     def install_btn_event(self, widget):
         todo = self._do_get_selected_items()
-        installer = dialog.InstallWindow(
-                parent = self,
-                pkglist = todo,
-                slaptconfig = self.slaptgetrc
-                )
-        if installer.run():
+        if self.categoriespanel._get_selected() == _('Installed Only'):
+            #        if widget.get_label() in (_('Installed Only')):
+            #           if _('Installed') in widget.get_label():
+            dia = message.Error(parent = self,
+                    text = _('Uninstall function not yet implemented'))
+        else:
+            dia = dialog.InstallWindow(
+                    parent = self,
+                    pkglist = todo,
+                    slaptconfig = self.slaptgetrc)
+        if dia.run():
             self.body.set_property('sensitive', False)
-            installer.destroy()
+            dia.destroy()
+#        gtk.gdk.threads_enter()
         self.body.set_property('sensitive', True)
-        # recreate repo to pick up newly installed apps
         self.categoriespanel.cache = vl.PackageCache()
-
-
-        # Refresh shown apps after installation is complete
-        # To show newly installed apps.
         self.categoriespanel.refresh_view()
-
-#        print todo
+        self.selbtn.set_property('label', _('Select All'))
+#        gtk.gdk.threads_leave()
 
     def _do_get_selected_items(self):
         ret = []

File install.desktop

 
 [Desktop Entry]
 Encoding=UTF-8
-Exec=vsuper python app.py
-Name=Install Vectorlinux Multimedia Software
+Exec=/bin/vsuper /usr/bin/python app.py
+Name=Install VLMMBD
 GenericName=Install Multimedia Software
 Comment=Install, remove and upgrade software packages
 Icon=gslapt.png
-Terminal=false
+Terminal=False
+Type=Application
 import os
 import subprocess as sp
 
-__author__ = 'Moises Henriquez'
+try:
+    from ..view import message
+except:
+    import sys
+    sys.path.append(os.path.join(os.getcwd(), '..'))
+
+from view import message
+
+_author__ = 'Moises Henriquez'
 __author_email__ = 'moc.liamg@xnl.E0M'[::-1]
 
 
         else:
             self.configfile = configfile
 
+        if not os.path.exists(self.manager):
+           dia = message.Error(
+                   text = _('slapt-get not installed in the system')
+                   )
+           if dia.run():
+               dia.destroy()
+
+
     def update_cache(self):
         proc = _get_popen(
                 "%s -c %s -y -u"% (self.manager,
         does not match version or release number, just the
         application name. Requires an app name as argument"""
         for item in self.installed:
-            (app, ver, arch, build) = item.rsplit('-', 3)
+            try:
+                (app, ver, arch, build) = item.rsplit('-', 3)
+            except:
+                continue
             if app == pkg:
                 return True
         return False

File view/dialog.py

 import threading
 import sys
 import os
+import message
 
 try:
     sys.path.append(os.path.join(os.getcwd(),'..'))
         self.monitor = threading.Thread(target = self.move)
         self.resize(400, 150)
         self.current = ""
+        self.failed_installs = []
 
         self.show_all()
         self._icurrent = 0.0
         """ Append our start_process() method to the dialog's
         .run method"""
         self.start_process()
-        return gtk.Dialog.run(self)
+#        return gtk.Dialog.run(self)
 
     def start_process(self, widget = None):
         """ Start installation process"""
         i = self.packagemanager.update_cache()
 
         # FIXME: ^^ Error checking ??? ^^
-        #print i
-        # ====== Brief error checking ======
+       # ====== Brief error checking ======
         if i[1] > 0:
             # Something went wrong during cache update
+            # FIXME: Error out at this point or proceed? 
             pass
-        
+
         self._icurrent = 0.0
         for pkg in self.pkglist:
             self.current = pkg
             # FIXME: Instead of this wait time, call the slapt-get
             # install method to install the package and process the
             # output.
-#            time.sleep(3)
             ret = self.packagemanager.install_package(pkg)
-            
+
             # === Brief Error Checking ========
-            if ret[1] > 0 or ret[0][1] is not None:
-                print 'Error installing %s'%pkg
-                print ret[0][1]
-#            print ret[1]
-#            print ret[0][1]
-            # FIXME: ^^ Error checking ?? ^^
-#            print ret
+            if ret[1] > 0 or 'unmet dependencies' in ret[0][1]:
+                self.failed_installs.append((pkg, ret[0][1]))
             self._icurrent += 1
 
         # When done, stop the monitor thread
         self.stopbar = True
         # Change the cancel button to 'Close'
-        self.change_cancel_button()
-
+        time.sleep(0.5)
+        if len(self.failed_installs) > 0:
+            dia = message.FailedPackagesDialog(
+                    self.failed_installs)
+            gtk.gdk.threads_enter()
+            if dia.run():
+                dia.destroy()
+            gtk.gdk.threads_leave()
+        else:
+            gtk.gdk.threads_enter()
+            self.change_cancel_button()
+            gtk.gdk.threads_leave()
 
     def exit(self, widget=None):
         """ Do a clean exit when closing the dialog
 
     def move(self):
         """ Move the progressbar according to the progress made"""
+        val = 0.0
         while not self.stopbar:
-            while self._icurrent == -1.0:
-                gtk.gdk.threads_enter()
-                self.progress.pulse()
-                gtk.gdk.threads_leave()
-                time.sleep(0.25)
-            val = float(float(self._icurrent) / float(len(self.pkglist)))
-            valstr = str(int(val) * 100)
+            time.sleep(0.1)
             gtk.gdk.threads_enter()
             self.progress.pulse()
+            gtk.gdk.threads_leave()
+
+#            gtk.gdk.threads_enter()
+#            self.progress.pulse()
+#            gtk.threads_leave()
+#            time.sleep(0.25)
+#            time.sleep(0.125)
+#            while self._icurrent == -1.0:
+                #                gtk.gdk.threads_enter()
+#                self.progress.set_text(_('Updating Cache'))
+#                self.progress.pulse()
+#                gtk.gdk.threads_leave()
+#                time.sleep(0.25)
+#                val = float(float(self._icurrent) / float(len(self.pkglist)))
+#                valstr = str(int(val) * 100)
+#                gtk.gdk.threads_enter()
+#                self.progress.pulse()
+#                self.progress.set_fraction(val)
+#                gtk.gdk.threads_leave()
 #            self.progress.set_fraction(val)
-            self.progress.set_text('%i'% (val * 100) + ' %')
+#            gtk.gdk.threads_leave()
+#            time.sleep(0.125)
+
+        time.sleep(0.5)
+
+
+        gtk.gdk.threads_enter()
+        self.progress.set_text('%i'% (val * 100) + ' %')
+        if len(self.failed_installs) > 0:
+            self.banner.set_property('label',
+                    _('Install process complete'))
+            self.progress.set_text('')
+            self.status.set_property('label',
+                    _('WARNING: Some packages failed to install.'))
+        else:
             self.banner.set_property('label',
                     _('Installation complete'))
+            self.progress.set_text('100 %')
             self.status.set_property('label',
-                    _('The software you selected has been installed'))
-            gtk.gdk.threads_leave()
-            time.sleep(0.1)
-        gtk.gdk.threads_enter()
+                    _('All packages installed successfully'))
+        time.sleep(0.125)
         self.progress.set_fraction(1.0)
-        self.progress.set_text('100 %')
         gtk.gdk.threads_leave()
 

File view/message.py

 def _(str):
     return str
 
+class FailedPackagesDialog(gtk.Dialog):
+    """Dialog used to show that some packages failed to install
+    """
+    def __init__(self, list_reason = []):
+        gtk.Dialog.__init__(self)
+        self.set_title(_('Errors during installation'))
+        carea = self.get_content_area()
+        aarea = self.get_action_area()
+        bannerc = gtk.HBox()
+        img = gtk.Image()
+        img.set_from_stock(gtk.STOCK_DIALOG_WARNING, gtk.ICON_SIZE_DIALOG)
+        bannerc.pack_start(img, False, False, 8)
+        banner = gtk.Label()
+        banner.set_property('label',
+                _('The following packages failed to install.') + '\n\n' + \
+                        _('Please report this error to the developer'))
+        bannerc.pack_start(banner, False, False, 8)
+        carea.pack_start(bannerc, False, False, 0)
+        scv = gtk.ScrolledWindow()
+#        carea.pack_start(scv, True, True, 0)
+        store = gtk.ListStore(str, str)
+        for item in list_reason:
+            store.append([item[0], item[1].strip().replace('\\n ','\n')])
+        tree = gtk.TreeView(model = store)
+        cr0 = gtk.CellRendererText()
+        cr1 = gtk.CellRendererText()
+        col0 = gtk.TreeViewColumn('Application', cr0)
+        col0.add_attribute(cr0, 'markup', 0)
+        col1 = gtk.TreeViewColumn('Returned Error', cr1)
+        col1.add_attribute(cr1, 'markup', 1)
+        tree = gtk.TreeView()
+        tree.set_model(store)
+        tree.set_headers_visible(True)
+        scv.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
+        tree.append_column(col0)
+        tree.append_column(col1)
+        scv.add(tree)
+        carea.pack_start(scv, True, True, 0)
+
+        btClose = gtk.Button(stock = gtk.STOCK_CLOSE)
+        btClose.connect('clicked', self._close)
+        aarea.pack_start(btClose, False, False, 0)
+        self.resize(480, 300)
+
+        self.show_all()
+
+    def _close(self, widget=None):
+        self.destroy()
+
 def Error(parent = None, text = None, title = 'Error'):
     """Generic error message dialog"""
     dia = gtk.MessageDialog(

File view/widgets.py

     """
     def __init__(self, repo, cache, detail_view):
         gtk.TreeView.__init__(self)
-        self.model = gtk.ListStore(gtk.gdk.Pixbuf, str)
+        self.model = gtk.ListStore(gtk.gdk.Pixbuf, str, bool)
         self.set_model(self.model)
-        pb = gtk.CellRendererPixbuf()
-        col = gtk.TreeViewColumn('None', pb, pixbuf = 0)
+        pb = FancyPixbuf('emblem-app-installed')
+#        pb = gtk.CellRendererPixbuf()
+        col = gtk.TreeViewColumn('None', pb, pixbuf = 0, overlay=2)
+        col.set_fixed_width(36)
+        col.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
         self.append_column(col)
         rend = gtk.CellRendererText()
         col = gtk.TreeViewColumn(None, rend)
             self.repo.append(app)
 
     def refresh_view(self):
-        sel = self.get_selection().get_selected_rows()[1][0][0]
-        self.show_category(sel)
+        #        sel = self.get_selection().get_selected_rows()[1][0][0]
+        self.show_category(self._get_selected())
+#        self.show_category(sel)
+
+    def _get_selected(self):
+        row = self.get_selection().get_selected_rows()[1][0][0]
+        return self.model[row][1]
 
     def click_event(self, column):
         row = column.get_selection().get_selected_rows()[1][0][0]
                             app_name = app.name,
                             app_short_description = _sdesc,
                             installed_indicator = _overlay)
+        elif category == _('Installed Only'):
+            for app in self.repo:
+                _overlay = cache.is_app_installed(app.name)
+                if _overlay is True:
+                    if 'deps' not in app.location:
+                        self.view.list_app(
+                                app_name = app.name,
+                                app_short_description = app.summary,
+                                installed_indicator = _overlay)
         else:
             for app in self.repo:
                 _overlay = cache.is_app_installed(app.name)
                             app_short_description = _sdesc,
                             installed_indicator = _overlay)
 
-    def add_category(self, Icon = None, label=''):
+    def add_category(self, icon = None, label='', overlay=False):
+        if icon is None:
+            self.model.append([None, label, overlay])
+            return
         self.model.append([
             gtk.gdk.pixbuf_new_from_file_at_size(
-                Icon, 24, 24), label])
+                icon, 32, 32), label, overlay])
         #        self.model.append([Icon, label])
         return