Commits

Anonymous committed 07b3783

Code refactoring to optimize indentation levels

Comments (0)

Files changed (13)

 #!/usr/bin/env python
+
+#    This file is part of the vectorlinux multimedia bonus disc.
+#
+#    os-hunter is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License v2 as published by
+#    the Free Software Foundation.
+#
+#    This file is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with this file.  If not, see <http://www.gnu.org/licenses/>.
+
 #!/usr/bin/env python
 
+#    This file is part of the vectorlinux multimedia bonus disc.
+#
+#    This file is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License v2 as published by
+#    the Free Software Foundation.
+#
+#    This file is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with this file.  If not, see <http://www.gnu.org/licenses/>.
+
+
 import gtk
-from view import widgets
+import time
+import threading
 from utils import repository
 from utils import vl
-import time
-import threading
-#import processing
+from view import widgets
 
-gtk.gdk.threads_init()
+__author__ = 'Moises Henriquez'
+__author_email__ = 'moc.liamg@xnl.E0M'[::-1]
 
 def _(str):
-        return str
-
+    return str
 
 class Window(gtk.Window):
+    """ Top-level window for the vectorlinux multimedia
+    add-on"""
+    def _get_menubar(self):
+        mb = gtk.MenuBar()
+        filemenu = gtk.Menu()
+        filem = gtk.MenuItem('_%s'% _('File'))
+        filem.set_submenu(filemenu)
+        exit = gtk.MenuItem('_%s'% _('Exit'))
+        exit.connect('activate', gtk.main_quit)
+        filemenu.append(exit)
 
-        def _get_menubar(self):
-                mb = gtk.MenuBar()
+        mb.append(filem)
 
-                filemenu = gtk.Menu()
-                filem = gtk.MenuItem('_File')
-                filem.set_submenu(filemenu)
+        return mb
 
-                exit = gtk.MenuItem('_Exit')
-                exit.connect('activate', gtk.main_quit)
-                filemenu.append(exit)
+    def __init__(self):
+        gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
+        self.set_title(_('Vectorlinux Multimedia Bonus Disc'))
+        self.connect('destroy', self.exit)
+        self.set_position(gtk.WIN_POS_CENTER)
 
-                mb.append(filem) # item added must be a MenuItem
+        body = gtk.VBox()
+        menu = self._get_menubar()
+        body.pack_start(menu, False, True, 0)
+        banner = gtk.Label()
+        banner.set_property('use-markup', True)
+        banner.set_markup(
+                '<span font_size="xx-large">%s</span>' 
+                        % _('Vectorlinux Multimedia Bonus Disc'))
+        body.pack_start(banner, False, True, 4)
+        self.add(body)
 
-                helpmenu = gtk.Menu()
-                helpa = gtk.MenuItem('_Help') # This is the one to add
-                helpa.set_submenu(helpmenu)
-                helpabout = gtk.MenuItem('_About')
-                helpmenu.append(helpabout)
-                mb.append(helpa)
+        pane = gtk.HPaned()
+        pane.set_position(100)
+        body.pack_start(pane, True, True, 0)
 
-                
+        app_pool = repository.repository('data/PACKAGES.TXT')
 
-                return mb
+        # Categories
+        rpane = gtk.VBox()
+        scrolled = gtk.ScrolledWindow()
+        scrolled.set_policy(gtk.POLICY_AUTOMATIC,
+                gtk.POLICY_AUTOMATIC)
+        app_display = widgets.FancyAppList()
+        self.display = app_display
+        scrolled.add(app_display)
+        rpane.pack_start(scrolled, True, True, 0)
+        cache = vl.PackageCache()
 
-        def __init__(self):
-                gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
-                self.set_title('Vectorlinux Multimedia Bonus Disc')
-                self.connect('destroy', self.exit)
-                self.set_position(gtk.WIN_POS_CENTER)
+        lpane = widgets.CategoryPanel(
+                app_pool, 
+                cache, 
+                app_display)
+        for cat in (_('All'),
+                _('Audio'),
+                _('Video'),
+                _('Bonus')):
+            lpane.add_category(cat)
+            
+        pane.pack1(lpane)
+        pane.pack2(rpane)
+        self._catpanel = lpane
+        bottombar = gtk.HBox()
+        btSelectAll = gtk.Button(_('Select All'))
+        btSelectAll.connect('clicked', self.selectall_event)
+        img = gtk.Image()
+        img.set_from_stock(gtk.STOCK_REFRESH,
+                gtk.ICON_SIZE_BUTTON)
+        btSelectAll.set_image(img)
+        bottombar.pack_start(btSelectAll, False, False, 2)
+        rpane.pack_start(bottombar, False, False, 2)
 
-                body = gtk.VBox()
-                menu = self._get_menubar()
-                body.pack_start(menu, False, True, 0)
-                banner = gtk.Label()
-                banner.set_property('use-markup', True)
-                banner.set_markup(
-                        '<span font_size="xx-large">'+ \
-                        'VectorLinux Multimedia Bonus Disc</span>')
-                body.pack_start(banner, False, True, 8)
-                self.add(body)
+        btInstallSelected = gtk.Button(_('Install Selected'))
+        img = gtk.Image()
+        img.set_from_stock(gtk.STOCK_APPLY,
+                gtk.ICON_SIZE_BUTTON)
+        btInstallSelected.set_image(img)
+        bottombar.pack_end(btInstallSelected, False, False, 2)
 
-                pane = gtk.HPaned()
-                pane.set_position(100)
-                body.pack_start(pane, True, True, 0)
+        self.statusbar = gtk.Statusbar()
+        body.pack_start(self.statusbar, False, False, 0)
 
-                app_pool = repository.repository('data/PACKAGES.TXT')
-                # Categories
-                rpane = gtk.VBox()
-                scrolled = gtk.ScrolledWindow()
-                scrolled.set_policy(gtk.POLICY_AUTOMATIC,
-                                    gtk.POLICY_AUTOMATIC)
-                app_display = widgets.FancyAppList()
-                self.display = app_display
-                scrolled.add(app_display)
-                rpane.pack_start(scrolled, True, True, 0)
+        self.resize(600, 400)
+        self._stop_monitor = False
+        self.monitor_thread = threading.Thread(
+                target = self.monitor)
 
-                cache = vl.PackageCache()
-                                       
-                lpane = widgets.CategoryPanel(app_pool, cache, app_display)
-                for cat in ('All', 'Audio', 'Video', 'Bonus'):
-                        lpane.add_category(cat)
+    def exit(self, caller):
+        """ Exit procedure. Necessary because we cannot call
+        gtk.main_quit directly when we have threads running
+        in the background, so these must be killed first.
+        """
+        self._stop_monitor = True
+        time.sleep(0.25)
+        gtk.main_quit()
+        return
+    
+    def monitor(self):
+        # Get the number of selected items
+       i = 0
+       if self._stop_monitor is True:
+           return
+       while self._stop_monitor is False:
+           time.sleep(0.25)
+           i = 0
+           model = self.display.get_model()
+           for item in model:
+               if item[0] is True:
+                   i += 1
 
-                pane.pack1(lpane)
-                pane.pack2(rpane)
-                
-                self._catpanel = lpane
-                bottombar = gtk.HBox()
-                btSelectAll = gtk.Button('Select All')
-                btSelectAll.connect('clicked', self.selectall_event)
-                # set image for button
-                img = gtk.Image()
-                img.set_from_stock(gtk.STOCK_REFRESH,
-                                   gtk.ICON_SIZE_BUTTON)
-                btSelectAll.set_image(img)
-                bottombar.pack_start(btSelectAll, False, False, 0)
-                rpane.pack_start(bottombar, False, False, 2)
+           if i > 0:
+               if self._stop_monitor is True:
+                   return
+               gtk.gdk.threads_enter()
+               self.statusbar.push(0, '%i %s'% (i,
+                   _('items selected')))
+               gtk.gdk.threads_leave()
+           else:
+               if self._stop_monitor is True:
+                   return
+               gtk.gdk.threads_enter()
+               self.statusbar.push(0, '%i %s'% (
+                   len(model), _('items displayed')))
+               gtk.gdk.threads_leave()
 
-                btInstallSelected = gtk.Button('Installed Selected')
-                img = gtk.Image()
-                img.set_from_stock(gtk.STOCK_APPLY,
-                                   gtk.ICON_SIZE_BUTTON)
-                btInstallSelected.set_image(img)
-                bottombar.pack_end(btInstallSelected, False, False, 2)
-
-                self.statusbar = gtk.Statusbar()
-                body.pack_start(self.statusbar, False, False, 0)
-                
-          
-                self.resize(600, 400)
-#                self.banner = gtk.Label()
-                
-#                body.pack_start(self.banner, True, False, 0)
-                self._stop_monitors = False
-                self.monitor_thread = threading.Thread(
-                        target = self.monitor)
-                     
-        def exit(self, arg):
-                self._stop_monitors = True
-                time.sleep(1)
-#                if self.monitor_thread.pid:
-#                        os.kill(self.monitor_thread.pid, 9)
-                gtk.main_quit()                        
-
-
-        def monitor(self):
-#                i = 0
-                while self._stop_monitors is False:
-#                        i += 1
-                        time.sleep(1)
-                        gtk.gdk.threads_enter()
-                        try:
-                                i = len(self.display.get_model())
-                        except:
-                                pass
-#                        i = len(self.display.get_model())
-                        try:
-                                self.statusbar.push(
-                                        0, str(i))
-                        except:
-                                pass
-#                        self.statusbar.push(
-#                                0, str(i))
-                        gtk.gdk.threads_leave()
-               
-
-
-        def selectall_event(self, widget):
-                if widget.get_label() == 'Select All':
-                        widget.set_property('label', 'Un-select All')
-                        self._do_select('All')
-                        
-                else:
-                        widget.set_property('label', 'Select All')
-                        self._do_select(None)
-        
-        def _do_select(self, selection):
-                
-                model = self.display.get_model()
-                if selection is None:
-                        for item in model:
-                                item[0] = False
-                                self.statusbar.push(0,'')
-                else:
-                        for item in model:
-                                item[0] = True
-                                self.statusbar.push(0,
-                                                    '%i items selected'% len(model))
-          
-
+    def selectall_event(self, widget):
+        if widget.get_label() == _('Select All'):
+            widget.set_property('label', _('Un-select All'))
+            self._do_select('All')
+        else:
+            widget.set_property('label', _('Select All'))
+            self._do_select(None)
+            return
+        return
+    
+    def _do_select(self, selection):
+        model = self.display.get_model()
+        if selection is None:
+            for item in model:
+                item[0] = False
+                self.statusbar.push(0, '')
+        else:
+            for item in model:
+                item[0] = True
+                self.statusbar.push(0,
+                        '%s items selected' % len(model))
+        return
 
 
 if __name__ == '__main__':
-        w = Window()
-        w.show_all()
-        w.monitor_thread.start()
-        gtk.gdk.threads_enter()
-        gtk.main()
-#        w.monitor_thread.start()
-#        gtk.gdk.threads_leave()
-
-                
+    gtk.gdk.threads_init()
+    w = Window()
+    w.show_all()
+    w.monitor_thread.start()
+    gtk.gdk.threads_enter()
+    gtk.main()
+    gtk.gdk.threads_leave()

utils/__init__.py

+#!/usr/bin/env python
 
+#    This file is part of the vectorlinux multimedia bonus disc.
+#
+#    os-hunter is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License v2 as published by
+#    the Free Software Foundation.
+#
+#    This file is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with this file.  If not, see <http://www.gnu.org/licenses/>.
+
+

utils/__init__.pyc

Binary file modified.
 #!/usr/bin/env python
 
+#    This file is part of the vectorlinux multimedia bonus disc.
+#
+#    This file is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License v2 as published by
+#    the Free Software Foundation.
+#
+#    This file is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with this file.  If not, see <http://www.gnu.org/licenses/>.
+
 import gtk
 
-def Error(parent=None, text=None, title='Error'):
-        dia = gtk.MessageDialog(parent = parent,
-                               type = gtk.MESSAGE_ERROR,
-                               buttons = gtk.BUTTONS_OK, 
-                               
-                               )
-       
-        dia.set_markup(text)
-        dia.set_title(title)
-        
-        return dia
+__author__ = 'Moises Henriquez'
+__author_email__ = 'moc.liamg@xnl.E0M'[::-1]
+
+
+def _(str):
+    return str
+
+def Error(parent = None, text = None, title = 'Error'):
+    """Generic error message dialog"""
+    dia = gtk.MessageDialog(
+            parent = parent,
+            type = gtk.MESSAGE_ERROR,
+            buttons = gtk.BUTTONS_OK,
+            )
+    dia.set_markup(text)
+    dia.set_title(title)
+    return dia
+
 
 def Info(parent = None, text = None, title = 'Info'):
-        dia = gtk.MessageDialog(parent = parent,
-                                type = gtk.MESSAGE_INFO,
-                                buttons = gtk.BUTTONS_OK,
-                               )
-        dia.set_markup(text)
-        dia.set_title(title)
-        return dia
-                               
-        
+    dia = gtk.MessageDialog(
+            parent = parent,
+            type = gtk.MESSAGE_INFO,
+            buttons = gtk.BUTTONS_OK,
+            )
+    dia.set_markup(text)
+    dia.set_title(title)
+    return dia
+
+

utils/repository.pyc

Binary file modified.
 #!/usr/bin/env python
 
+#    This file is part of the vectorlinux multimedia bonus disc.
+#
+#    This file is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License v2 as published by
+#    the Free Software Foundation.
+#
+#    This file is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with this file.  If not, see <http://www.gnu.org/licenses/>.
+
 import os
-from processing import Process
 import subprocess as sp
 
+__author__ = 'Moises Henriquez'
+__author_email__ = 'moc.liamg@xnl.E0M'[::-1]
+
+
 def check_root():
-        return os.getuid() is 0
+    return os.getuid() is 0
+
 def _get_popen(cmd):
-        return sp.Popen(cmd.split(), stdout = sp.PIPE, stderr = sp.STDOUT)
+    proc = sp.Popen(
+            cmd.split(),
+            stdout = sp.PIPE,
+            stderr = sp.STDOUT,
+            )
+    return proc
 
 def get_vl_version():
-        """ Find the vector version that is currently running.
-        WARNING: This results are based on the vlconfig2 package
-        FIXME: The vlconfig2 package **should** be updated on
-        every release"""
-        for item in os.listdir('/var/log/packages'):
-                (app, version, arch, build) = item.rsplit('-', 3)
-                if app == 'vlconfig2':
-                        return build[-2:] 
-        return None                
+    """ Find the version of the running vectorlinux install
+    WARNING: This result is based on the naming scheme of the
+    vlconfig2 package"""
+    for item in os.listdir('/var/log/packages'):
+        (app, ver, arch, build) = item.rsplit('-', 3)
+        if app == 'vlconfig2':
+            return build[-2:]
+    return None
 
 def find_latest(pkg1, pkg2):
-        """ Compares 2 package build strings, and
-        finds the version of a package that is most suitable 
-        for the running installation
-        
-        Handy when comparing two packages with the exact ssame
-        name and version, but diff builds
-        """
-        if 'vl' in pkg1 and not 'vl' in pkg2:
-                return pkg1
-        if 'vl' in pkg2 and not 'vl' in pkg1:
-                return pkg2
-        ## Check the vl version, always prefer the version that matches
-        ## the vl version installed
-        if 'vl' in pkg1 and 'vl' in pkg2:
-                vlver = get_vl_version().replace('.', '')
-                if pkg1.endswith(vlver) and not pkg2.endswith(vlver):
-                        return pkg
-                elif pkg2.endswith(vlver) and not pkg1.endswith(vlver):
-                        return pkg2
-        return max(pkg1, pkg2)                
-                               
+    """
+    Compares 2 package's build strings and find the version that is
+    more suitable for the running installation
+
+    handy when comparing 2 packages with the exact same name and 
+    version, but different build numbers
+    """
+    if 'vl' in pkg1 and not 'vl' in pkg2:
+        return pkg1
+    if 'vl' in pkg2 and not 'vl' in pkg1:
+        return pkg2
+    # Check the vl version, and always prefer the one that
+    # matches the vl version
+    if 'vl' in pkg1 and 'vl' in pkg2:
+        vlver = get_vl_version().replace('.','')
+        if pkg1.endswith(vlver) and not pkg2.endswith(vlver):
+            return pkg1
+        elif pkg2.endswith(vlver) and not pkg1.endswith(vlver):
+            return pkg2
+    return max(pkg1, pkg2)
+
 
 class PackageManager(object):
-        """
-        Package manager functions tied to VL
-        """
-        manager = '/usr/sbin/slapt-get'
+    """
+    Package manager functions tied to VL"""
+    manager = '/usr/sbin/slapt-get'
 
-        def __init__(self, configfile = None):
-                if configfile is None:
-                        self.configfile = '/etc/slapt-get/slapt-getrc'
-                else:
-                        self.configfile = configfile
-        
-        def update_cache(self):
-                proc = _get_popen("%s -c %s -y -u"% (self.manager, self.configfile))
-                out = proc.communicate()
-                return out
-        
-        def install_package(self, pkgname):
-                proc = _get_popen("%s -c %s -y -i %s"% (self.manager,
-                                                        self.configfile, 
-                                                        pkgname))
-                out = proc.communicate()
-                return out
+    def __init__(self, configfile = '/etc/slapt-get/slapt-getrc'):
+        if configfile is None:
+            self.configfile = '/etc/slapt-get/slapt-getrc'
+        else:
+            self.configfile = configfile
 
+    def update(cache):
+        proc = _get_popen(
+                "%s -c %s -y -u"% (self.manager,
+                    self.configfile))
+        out = proc.communicate()
+        return out
 
-
+    def install_package(self, pkgname):
+        proc = _get_popen(
+                "%s -c %s -y -i %s" (self.manager,
+                    self.configfile, 
+                    pkgname))
+        out = proc.communicate()
+        return out
 
 
 class PackageCache(object):
+    """ Cache of currently installed packages """
+    def __init__(self, cachedir='/var/log/packages'):
+        self.installed = os.listdir(cachedir)
+
+    def search_installed(self, term):
         """
-        Cache of currently installed packages.
+        Searches the local cache for a package
+        ARGUMENTS:
+                term - A package name
+                        ie, 'foo-bar-1.2-i586-1vl70'
+        RETURNS:
+                True if a package is installed
+        WARNING:
+                Term must be a full package name, not
+                just the application name
+                """
+        return tem in self.installed
+    
+    def is_app_installed(self, pkg):
         """
+        Search the cache for an application
+        Returns true when the application is found. Result
+        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)
+            if app == pkg:
+                return True
+        return False
 
-        def __init__(self, installedpath='/var/log/packages'):
-                self.installed = os.listdir(installedpath)
-        def search_installed(self, term):
-                """ Search the local cache for package
-                Arguments:
-                        term - A package name (without file extension)
-                        ie, 'foo-bar-1.2-i586-1vl70'
-                Returns:
-                        True if package is intalled,
-                        False otherwise
-                
-                WARNING: term must be a full package name, not just an
-                        app name.
-                """
-                return term in self.installed
-        def is_app_installed(self, pkg):
-                """
-                Search the local cache for an app.
-                Arguments:
-                        pkg - an application name (case sensitive)
-                Returns:
-                        True when the app is found,
-                        False otherwise
-                WARNING:
-                        Does not look for matching or best version or
-                        release numbers... this is just a vague search"""
-                for item in self.installed:
-                        (app, ver, arch, build) = item.rsplit('-', 3)
-                        if app == pkg:
-                                return True
-                return False                        
-        def get_installed_version(self, pkg):
-                """ Find the version number for an installed package
-                Arguments:
-                        pkg - A valid package name (case sensitive)
-                Returns:
-                        version - String representing the installed version
-                                queried package
-                        None - When package is not installed                                
-                                
-                                """
-                for item in self.installed:
-                        (app, ver, arch, build) = item.rsplit('-', 3)
-                        if app == pkg:
-                                return ver
-                        else: 
-                                continue
-                return None
+    def get_installed_version(self, pkg):
+        """ Find the version of an installed package
+        required an application name as argument and returns
+        a string representing the version found in the running
+        system. Returns None is app is not found"""
+        for item in self.installed:
+            (app, ver, arch, build) = item.rsplit('-', 3)
+            if app == pkg:
+                return ver
+            else:
+                continue
+        return None
 
+
+
+
+
Binary file modified.
 #!/usr/bin/env python
 
+#    This file is part of the vectorlinux multimedia bonus disc.
+#
+#    This file is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License v2 as published by
+#    the Free Software Foundation.
+#
+#    This file is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with this file.  If not, see <http://www.gnu.org/licenses/>.
 
+

view/__init__.pyc

Binary file modified.

view/app.py

-#!/usr/bin/env python
-
-import gtk
-import widgets
-
-class w(gtk.Window):
-        def __init__(self):
-                gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
-                self.connect('destroy', gtk.main_quit)
-
-                self.resize(300,200)
-                apps = widgets.FancyAppList()
-                apps.list_app(
-                        app_name = "foo",
-                        app_short_description = "foo app",
-                        app_icon_path = "/usr/share/pixmaps/games.png"
-                )
-
-                self.add(apps)
-
-if __name__ == '__main__':
-        window = w()
-        window.show_all()
-        gtk.main()
 #!/usr/bin/env python
 
+#    This file is part of the vectorlinux multimedia bonus disc.
+#
+#    This is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License v2 as published by
+#    the Free Software Foundation.
+#
+#    This file is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with this file.  If not, see <http://www.gnu.org/licenses/>.
+
+import gtk
 import gobject
-import gtk
 import glib
 from .utils import repository
 
+__author__ = 'Moises Henriquez'
+__author_email__ = 'moc.liamg@xnl.E0M'[::-1]
+
+
+def _(str):
+    return str
+
 class CategoryPanel(gtk.TreeView):
-        """
-        Treeview used to display application categories
+    """
+    Tree used to display software categories
 
-        Arguments:
-                repo - a repository object containing a pool of apps
-        """
+    Arguments:
+        repo - a repository object containing a pool of apps
+        cache - a PackageCache object
+        detail_view - a FancyAppList object
+    """
+    def __init__(self, repo, cache, detail_view):
+        gtk.TreeView.__init__(self)
+        self.model = gtk.ListStore(str)
+        self.set_model(self.model)
+        rend = gtk.CellRendererText()
+        col = gtk.TreeViewColumn(None, rend)
+        col.add_attribute(rend, 'text', 0)
 
-        def __init__(self, repo, cache, detail_view):
-                gtk.TreeView.__init__(self)
-                self.model = gtk.ListStore(str)
-                self.set_model(self.model)
-                rend = gtk.CellRendererText()
-                col = gtk.TreeViewColumn(None, rend)
-                col.add_attribute(rend, 'text', 0)
-                
-                self.set_headers_visible(False)
-                self.connect('cursor-changed', self.click_event)
-                self.repo = []
-                self.view = detail_view
-                self.cache = cache
-                self._visible_model = self.view.get_model()
-                for app in repo:
-                        self.repo.append(app)
-                
-                self.append_column(col)
+        self.set_headers_visible(False)
+        self.connect('cursor-changed', self.click_event)
+        self.repo = []
+        self.view = detail_view
+        self.cache = cache
+        self.append_column(col)
+        for app in repo:
+            self.repo.append(app)
         
-        def click_event(self, column):
-                row = column.get_selection().get_selected_rows()[1][0][0]
-                selected = self.model[row][0]
-                self.show_category(selected)
+    def click_event(self, column):
+        row = column.get_selection().get_selected_rows()[1][0][0]
+        sel = self.model[row][0]
+        self.show_category(sel)
+        return
 
-        def show_category(self, category):
-                model = self.view.get_model()
-                model.clear()
-                cache = self.cache
-                self.view._selected = 0
-                if category == "All":
-                        for app in self.repo:
-                                if 'deps' not in app.location:
-                                        _installed = cache.is_app_installed(app.name)
-                                        _shortdesc = repository.ShortDescribe(app)
-                                        self.view.list_app(
-                                                app_name = app.name,
-                                                app_short_description = _shortdesc,
-                                                installed_indicator = _installed)
-#                        self._visible_model = self.view.get_model()
-                                                
-                elif category == "Audio":
-                        for app in self.repo:
-                                if 'Audio' in app.location:
-                                        _installed = cache.is_app_installed(app.name)
-                                        _short = repository.ShortDescribe(app)
-                                        self.view.list_app(
-                                                app_name = app.name,
-                                                app_short_description = _short,
-                                                installed_indicator = _installed)
-                elif category == "Video":
-                        for app in self.repo:
-                                if 'Video' in app.location:
-                                        _installed = cache.is_app_installed(app.name)
-                                        _short = repository.ShortDescribe(app)
-                                        self.view.list_app(
-                                                app_name = app.name,
-                                                app_short_description = _short,
-                                                installed_indicator = _installed)
-                else:
-                        for app in self.repo:
-                                if app.location not in ('Audio',
-                                                        'Video',
-                                                        'deps',
-                                                        './AudioApps',
-                                                        './VideoApps',
-                                                        './deps'):
-                                        _installed = cache.is_app_installed(app.name)
-                                        _short = repository.ShortDescribe(app)
-                                        self.view.list_app(
-                                                app_name = app.name,
-                                                app_short_description = _short,
-                                                installed_indicator = _installed)
-                self._visible_model = self.view.get_model()
-                return
+    def show_category(self, category):
+        model = self.view.get_model()
+        model.clear()
+        cache = self.cache
 
-        def add_category(self, label):
-                self.model.append([label])
-                
-       
+        if category == _('All'):
+            for app in self.repo:
+                if 'deps' not in app.location:
+                    _overlay = cache.is_app_installed(app.name)
+                    _sdesc = repository.ShortDescribe(app)
+                    self.view.list_app(app_name = app.name,
+                            app_short_description = _sdesc,
+                            installed_indicator = _overlay)
+        elif category == _('Audio'):
+            for app in self.repo:
+                _overlay = cache.is_app_installed(app.name)
+                _sdesc = repository.ShortDescribe(app)
+                if 'Audio' in app.location:
+                    self.view.list_app(
+                            app_name = app.name,
+                            app_short_description = _sdesc,
+                            installed_indicator = _overlay)
+        elif category == _('Video'):
+            for app in self.repo:
+                _overlay = cache.is_app_installed(app.name)
+                _sdesc = repository.ShortDescribe(app)
+                if 'Video' in app.location:
+                    self.view.list_app(
+                            app_name = app.name,
+                            app_short_description = _sdesc,
+                            installed_indicator = _overlay)
+        else:
+            for app in self.repo:
+                _overlay = cache.is_app_installed(app.name)
+                _sdesc = repository.ShortDescribe(app)
+                if app.location not in (
+                        'Audio',
+                        'Video',
+                        'deps',
+                        './AudioApps',
+                        './VideoApps',
+                        './deps'):
+                    self.view.list_app(
+                            app_name = app.name,
+                            app_short_description = _sdesc,
+                            installed_indicator = _overlay)
+
+    def add_category(self, label):
+        self.model.append([label])
+        return
+
 class FancyPixbuf(gtk.CellRendererPixbuf):
-        """
-        Fancy CellRendererPixbuf that can display an overlay icon
-        by setting it's 'overlay' property to True
-        """
-        OFFSET_X = 14
-        OFFSET_Y = 16
-        OVERLAY_SIZE = 16
+    """ Fancy pixbuf that can display an overlay icon
+    by setting it's 'overlay' property to True. 
+    Used to indicate when an app is installed in the system
+    """
+    OFFSET_X = 14
+    OFFSET_Y = 16
+    OVERLAY_SIZE = 16
 
-        __gproperties__ = {
-                'overlay' : (bool, 'overlay',
-                             'Show an overlay icon',
-                             False,
-                             gobject.PARAM_READWRITE)}
-        def __init__(self, overlay_icon_name):
-                gtk.CellRendererPixbuf.__init__(self)
-                icons = gtk.icon_theme_get_default()
-                icons.append_search_path(
-                        '/usr/share/icons/Tango/16x16/emblems/')
-                self.overlay = False
-                try:
-                        self._installed = icons.load_icon(overlay_icon_name,
-                                                          self.OVERLAY_SIZE,
-                                                          0)
-                except glib.GError:
-                        # maybe icon was not found
-                        self._installed = icons.load_icon(
-                                'emblem-system', self.OVERLAY_SIZE, 0)
-        def do_set_property(self, pspec, value):
-                setattr(self, pspec.name, value)
-                return
-        def do_get_property(self, pspec):
-                return getattr(self, pspec.name)
-        def do_render(self, window, widget, background_area,
-                      cell_area, expose_area, flags):
-                gtk.CellRendererPixbuf.do_render(self, window,
-                                                 widget,
-                                                 background_area,
-                                                 cell_area, expose_area, flags)
-                overlay = self.get_property('overlay')
-                if overlay:
-                        dest_x = cell_area.x + self.OFFSET_X
-                        dest_y = cell_area.y + self.OFFSET_Y
-                        window.draw_pixbuf(None,
-                                           self._installed,     # overlay
-                                           0, 0,                # src pixbuf
-                                           dest_x, dest_y,      # dest in window
-                                           -1, -1,              # size
-                                           0, 0, 0)             # dither
-gobject.type_register(FancyPixbuf)                                
-                
+    __gproperties__ = {
+            'overlay' : (bool, 'overlay', 
+                'Show an overlay icon',
+                False, 
+                gobject.PARAM_READWRITE)
+            }
+    def __init__(self, overlay_icon_name):
+        gtk.CellRendererPixbuf.__init__(self)
+        icons = gtk.icon_theme_get_default()
+        icons.append_search_path(
+                '/usr/share/icons/Tango/16x16/emblems/')
+        self.overlay = False
+        try:
+            self._installed = icons.load_icon(
+                    overlay_icon_name,
+                    self.OVERLAY_SIZE,
+                    0)
+        except glib.GError:
+            ## Maybe the icon was not found
+            self._installed = icons.load_icon(
+                    'emblem-system', self.OVERLAY_SIZE, 0)
+        return
+
+    def do_set_property(self, pspec, value):
+        setattr(self, pspec.name, value)
+        return
+
+    def do_get_property(self, pspec):
+        return getattr(self, pspec.name)
+
+    def do_render(self, window, widget,
+            background_area, cell_area,
+            expose_area, flags):
+        gtk.CellRendererPixbuf.do_render(self,
+                window,
+                widget,
+                background_area,
+                cell_area,
+                expose_area, 
+                flags)
+        overlay = self.get_property('overlay')
+        if overlay:
+            dest_x = cell_area.x + self.OFFSET_X
+            dest_y = cell_area.y + self.OFFSET_Y
+            window.draw_pixbuf(None,
+                    self._installed,            # overlay
+                    0, 0,                       # src pixbuf
+                    dest_x, dest_y,             # dest in window
+                    -1, -1,                     # size
+                    0, 0, 0)                    # dither
+
+gobject.type_register(FancyPixbuf)
 
 class FancyAppList(gtk.TreeView):
-        """
-        Fancy treeview used fot displaying apps
-        
-        To add a row:
-                model = FancyAppList.get_model()
-                model.append([False, 'your app', pixbuf, False])
-        """
-        def __init__(self):
-                gtk.TreeView.__init__(self)
-                self.set_headers_visible(False)
-                tp = FancyPixbuf('emblem-app-installed')
-                
-                tg = gtk.CellRendererToggle()
-#                tg.connect('toggled', self.toggle_event, self.get_model())
-                col_tg = gtk.TreeViewColumn('install',
-                                            tg,
-                                            active = 0)
-                col_icon = gtk.TreeViewColumn('icon',
-                                              tp,
-                                              pixbuf = 2, # app icon
-                                              overlay = 3 # true or false
-                                             )
-                col_icon.set_fixed_width(36)
-                col_icon.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
-                crt = gtk.CellRendererText()
-                col_app = gtk.TreeViewColumn('App', crt,
-                                             markup = 1)
-                # Add the columns
-                for col in (col_tg, col_icon, col_app): 
-                        self.append_column(col)
-                
-                # Add a model
-                model = gtk.ListStore(bool, str, gtk.gdk.Pixbuf, bool)
-                self.set_model(model)
-                tg.connect('toggled', self.toggle_event, model)
-                self._selected = 0
+    """
+    Fancy treeview used for displaying apps on the screen.
+    To add a row:
+    model = FantyAppList.get_model()
+    model.append([False, 'your app', pixbuf, False])
+    """
+    def __init__(self):
+        gtk.TreeView.__init__(self)
+        self.set_headers_visible(False)
+        fp = FancyPixbuf('emblem-app-installed')
+        tg = gtk.CellRendererToggle()
+        col_tg = gtk.TreeViewColumn('Toggle', 
+                tg,
+                active = 0)
+        col_icon = gtk.TreeViewColumn('Icon',
+                fp,
+                pixbuf = 2,     # Icon path
+                overlay = 3     # overlay value : True or False
+                )
+        col_icon.set_fixed_width(26)
+        col_icon.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
+        crt = gtk.CellRendererText()
+        col_app = gtk.TreeViewColumn('App', crt,
+                markup = 1)
 
-        def toggle_event(self, cell, path, model):
-                _model = self.get_model()
-                model[path][0] =  not model[path][0]
+        # Add the columns
+        for col in (col_tg, col_icon, col_app):
+            self.append_column(col)
 
+        # Add the model
+        model = gtk.ListStore(bool, str, gtk.gdk.Pixbuf, bool)
+        self.set_model(model)
+        tg.connect('toggled', self.toggle_event, model)
 
-        def list_app(self, default_state = False,
-                     app_name = str,
-                     app_short_description = str,
-                     app_icon_path = None,
-                     installed_indicator = False):
-                
-                if app_icon_path is None:
-                        #app_icon_path = '/usr/share/pixmaps/cdrom.png'
-                        app_icon_path = '/usr/share/icons/Tango/32x32/categories/applications-other.png'
+    def toggle_event(self, cell, path, model):
+        model[path][0] = not model[path][0]
+        return
 
-                
-                pic = gtk.gdk.pixbuf_new_from_file_at_size(
-                        app_icon_path, 32, 32)
-                markup = '<b>%s</b>\n'% app_name + ' ' * 4 + \
-                                '<small>%s</small>'% app_short_description
-                self.get_model().append([
-                        default_state,
-                        markup,
-                        pic,
-                        installed_indicator])
+    def list_app(self, default_state = False,
+            app_name = str,
+            app_short_description = str,
+            app_icon_path = None,
+            installed_indicator = False):
+        if app_icon_path is None:
+            app_icon_path = '/usr/share/icons/Tango/32x32/categories/applications-other.png'
 
+            pic = gtk.gdk.pixbuf_new_from_file_at_size(
+                    app_icon_path, 24, 24)
+            markup = '<b>%s</b>\n'% app_name + ' '*4 + \
+                    '<small>%s</small>'% app_short_description
+            self.get_model().append([
+                default_state,
+                markup,
+                pic,
+                installed_indicator])
+        return
+
+
+
+

view/widgets.pyc

Binary file modified.