deskbar-applet r2026 - in trunk: . deskbar/core deskbar/handlers deskbar/ui/cuemiac



Author: sebp
Date: Wed Mar 19 23:16:00 2008
New Revision: 2026
URL: http://svn.gnome.org/viewvc/deskbar-applet?rev=2026&view=rev

Log:
2008-03-20  Sebastian PÃlsterl  <sebp cvs gnome org>

    * deskbar/core/Utils.py:
    * deskbar/handlers/programs.py:
    Find programs in $PATH that start
    with the search term

2008-03-20  Sebastian PÃlsterl  <sebp cvs gnome org>

    * deskbar/ui/cuemiac/CuemiacModel.py:
    Added more logger calls for debugging


Modified:
   trunk/ChangeLog
   trunk/deskbar/core/Utils.py
   trunk/deskbar/handlers/programs.py
   trunk/deskbar/ui/cuemiac/CuemiacModel.py

Modified: trunk/deskbar/core/Utils.py
==============================================================================
--- trunk/deskbar/core/Utils.py	(original)
+++ trunk/deskbar/core/Utils.py	Wed Mar 19 23:16:00 2008
@@ -11,6 +11,9 @@
 
 LOGGER = logging.getLogger(__name__)
 
+PATH = [path for path in os.getenv("PATH").split(os.path.pathsep)
+        if path.strip() != "" and exists(path) and isdir(path)]
+
 ICON_THEME = gtk.icon_theme_get_default()
 factory = gnome.ui.ThumbnailFactory(deskbar.ICON_HEIGHT)
 
@@ -112,15 +115,17 @@
         pixbuf = pixbuf.scale_simple(width, height, gtk.gdk.INTERP_BILINEAR)
     return pixbuf
 
-PATH = [path for path in os.getenv("PATH").split(os.path.pathsep) if path.strip() != "" and exists(path) and isdir(path)]
 def is_program_in_path(program):
     """
     Whether C{program} is in PATH
     """
     for path in PATH:
         prog_path = join(path, program)
-        if exists(prog_path) and isfile(prog_path) and os.access(prog_path, os.F_OK | os.R_OK | os.X_OK):
+        if exists(prog_path) and isfile(prog_path) and is_executable(prog_path):
             return True
+        
+def is_executable(prog_path):
+    return os.access(prog_path, os.F_OK | os.R_OK | os.X_OK)
 
 def spawn_async(args):
     try:

Modified: trunk/deskbar/handlers/programs.py
==============================================================================
--- trunk/deskbar/handlers/programs.py	(original)
+++ trunk/deskbar/handlers/programs.py	Wed Mar 19 23:16:00 2008
@@ -1,14 +1,14 @@
 import re
 import glob
 import os
-from os.path import join, expanduser
+from os.path import join, expanduser, isdir
 from gettext import gettext as _
 from deskbar.defs import VERSION
 import gobject
 import gtk
 import deskbar, deskbar.core.Indexer, deskbar.core.Utils
 import deskbar.interfaces.Module, deskbar.interfaces.Match, deskbar.core.gnomedesktop
-from deskbar.core.Utils import get_xdg_data_dirs, is_program_in_path, spawn_async
+from deskbar.core.Utils import get_xdg_data_dirs, is_program_in_path, spawn_async, is_executable, PATH
 from deskbar.handlers.actions.OpenWithApplicationAction import OpenWithApplicationAction
 from deskbar.handlers.actions.OpenDesktopFileAction import OpenDesktopFileAction, parse_desktop_file, parse_desktop_filename
 import deskbar.interfaces.Action
@@ -208,12 +208,12 @@
                 import subprocess
 
                 prog = subprocess.Popen(
-                    text.split(" "),
+                    self._name.split(" "),
                     stdout=subprocess.PIPE,
                     stderr=subprocess.STDOUT)
                 
                 zenity = subprocess.Popen(
-                    ["zenity", "--title="+text,
+                    ["zenity", "--title="+self._name,
                         "--window-icon="+join(deskbar.ART_DATA_DIR, "generic.png"),
                         "--width=700",
                         "--height=500",
@@ -228,7 +228,7 @@
                 #No zenity, get out of the if, and launch without GUI
                 pass
         
-        spawn_async(text.split(" "))
+        spawn_async(self._name.split(" "))
         
     def get_hash(self):
         if self.use_terminal:
@@ -238,9 +238,9 @@
 
     def get_verb(self):
         if self.use_terminal:
-            return _("Execute %s in terminal") % "<b>%(text)s</b>"
+            return _("Execute %s in terminal") % "<b>%(name)s</b>"
         else:
-            return _("Execute %s") % "<b>%(text)s</b>"
+            return _("Execute %s") % "<b>%(name)s</b>"
 
 class PathProgramMatch(deskbar.interfaces.Match):
     
@@ -250,8 +250,19 @@
         self.add_action( OpenPathProgramAction(command, False), True )
         self.add_action( OpenPathProgramAction(command, True) )
         
-    def get_hash(self, text=None):
-        return text
+    def get_hash(self):
+        return self._name
+   
+class StartsWithPathProgramMatch(deskbar.interfaces.Match):
+    
+    def __init__(self, command, priority=0, **args):
+        deskbar.interfaces.Match.__init__(self, name=command, icon="gtk-execute", category="actions", **args)
+        self._command = command
+        self.add_action( OpenPathProgramAction(command, False), True )
+        self.add_action( OpenPathProgramAction(command, True) )
+        
+    def get_hash(self):
+        return self._command
         
 class ProgramsHandler(deskbar.interfaces.Module):
     
@@ -274,11 +285,23 @@
         self._emit_query_ready(query, result )
         
     def query_path_programs(self, query):
-        program = query.split(" ")[0]
-        if is_program_in_path(program):
-            return [PathProgramMatch(program, query)]
+        args = query.split(" ")     
+        program = args[0]
+        
+        if len(args) == 1:
+            results = []
+            for pathdir in PATH:
+                for f in os.listdir(pathdir):
+                    pathprog = join(pathdir, f)
+                    if not isdir(pathprog) and f.lower().startswith(program) and is_executable(pathprog):
+                        results.append( StartsWithPathProgramMatch(f) )
+            return results
         else:
-            return []
+            # We have arguments, execute the command as typed in by the user
+            if is_program_in_path(program):
+                return [PathProgramMatch(program, query)]
+            else:
+                return []
     
     def query_desktop_programs(self, query):
         result = []

Modified: trunk/deskbar/ui/cuemiac/CuemiacModel.py
==============================================================================
--- trunk/deskbar/ui/cuemiac/CuemiacModel.py	(original)
+++ trunk/deskbar/ui/cuemiac/CuemiacModel.py	Wed Mar 19 23:16:00 2008
@@ -115,6 +115,7 @@
         """
         match_iter = self.__match_hashes[hash]
         match_obj = self[match_iter][self.MATCHES]
+        logger.debug ("Adding %i actions to match %r" % (len(actions), match_obj))
         match_obj.add_all_actions(actions)
     
     def __append_match(self, match_obj, query_string):
@@ -131,6 +132,7 @@
             iter = self.__append ( query_string, match_obj )
             self.__add_to_hash_iter_map(match_obj.get_hash(), iter)
         else:
+            LOGGER.debug("Match %r has the same hash (%s) as a match that has already been added" % (match_obj, match_obj.get_hash()))
             self.__add_actions_to_match(match_obj.get_actions(), match_obj.get_hash())
     
     def append (self, match_obj, query_string):



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]