Re: [Deskbar] how to return multiple matches from query
- From: "John Russell" <jjrussell gmail com>
- To: "Mikkel Kamstrup Erlandsen" <mikkel kamstrup gmail com>
- Cc: deskbar-applet-list gnome org
- Subject: Re: [Deskbar] how to return multiple matches from query
- Date: Sat, 21 Apr 2007 10:53:58 -0400
Excellent, thanks a lot.
I've attached a patch relative to the
/usr/lib/deskbar/handlers/programs.py file in the 2.18.0 version of
deskbar-applet.
This alters the behavior of the path search to glob for partial
matches in the path instead of just matching the full query.
The is_program_glob_in_path should probably be in the deskbar.Utils.py
file but I wanted to keep it contained to get some opinions.
You'll have to delete the corresponidng .pyc and .pyo files for this
to work. Let me know what you think and thanks again for the help.
John
On 4/19/07, Mikkel Kamstrup Erlandsen <mikkel kamstrup gmail com> wrote:
2007/4/18, John Russell <jjrussell gmail com>:
> Sure. Attached. Please don't make fun of my Python. I'm still having
> trouble with mixed tabs and spaces.
Hi,
CCing deskbar-applet list (I hope you intended too :-D)
You should use " self.name" instead of "text" in your match objects
get_hash() and action() methods. The "text" argument is the search string as
typed by the user. self.name is the actual prog you found by globbing. It
looks like it works here now.
Modified version attached.
Cheers, and good luck!
Mikkel
> On 4/18/07, Mikkel Kamstrup Erlandsen <mikkel kamstrup gmail com> wrote:
> > 2007/4/18, John Russell <jjrussell gmail com >:
> >
> > > I'm writing a handler that searches the path for the query string.
> > > Its based on the existing program one except I want it to show partial
> > > matches. I've got the logic working except deskbar only shows the
> > > first match in my list of match objects returned from the query method
> > > in the Handler.
> > >
> > > Is there some setting that needs setting for it to display multiple
> > matches?
> >
> > Can you post the source? It should work without any effort if you just
> > return a list of Match objects.
> >
> > Cheers,
> > Mikkel
> >
> >
> >
>
>
--- programs.py 2007-04-21 10:48:09.000000000 -0400
+++ programs.py.orig 2007-04-20 23:04:15.000000000 -0400
@@ -1,6 +1,6 @@
import os, ConfigParser, cgi, re
import glob
-from os.path import join, isfile, abspath, splitext, expanduser, exists, isdir, basename, islink, realpath
+from os.path import join, isfile, abspath, splitext, expanduser, exists, isdir
from gettext import gettext as _
from deskbar.defs import VERSION
import gobject
@@ -34,7 +34,6 @@
EXACT_MATCH_PRIO = 100
EXACT_WORD_PRIO = 50
-PATH = [path for path in os.getenv("PATH").split(os.path.pathsep) if path.strip() != "" and exists(path) and isdir(path)]
class GenericProgramMatch(deskbar.Match.Match):
def __init__(self, backend, use_arg=False, desktop=None, desktop_file=None, **args):
@@ -186,20 +185,20 @@
def get_hash(self, text=None):
if not self.use_terminal:
- return self.name
+ return text
else:
- return (self.name, True)
-
+ return (text, True)
+
def action(self, text=None):
if self.use_terminal:
try:
prog = subprocess.Popen(
- self.name.split(" "),
+ text.split(" "),
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
zenity = subprocess.Popen(
- ["zenity", "--title="+self.name,
+ ["zenity", "--title="+text,
"--window-icon="+join(deskbar.ART_DATA_DIR, "generic.png"),
"--width=700",
"--height=500",
@@ -213,15 +212,15 @@
except:
#No zenity, get out of the if, and launch without GUI
pass
-
- spawn_async(self.name.split(" "))
+
+ spawn_async(text.split(" "))
def get_category(self):
return "actions"
def get_verb(self):
- return _("Execute %s") % "<b>%(name)s</b>"
-
+ return _("Execute %s") % "<b>%(text)s</b>"
+
class ProgramsHandler(deskbar.Handler.Handler):
def __init__(self):
deskbar.Handler.Handler.__init__(self, gtk.STOCK_EXECUTE)
@@ -229,18 +228,21 @@
def initialize(self):
self._scan_desktop_files()
-
- def query(self, query, num_to_return=10):
+
+ def query(self, query):
result = self.query_path_programs(query)
result += self.query_desktop_programs(query)
return result
def query_path_programs(self, query):
args = query.split(" ")
- matches = self._check_program(args[0])
-
- return matches
+ match = self._check_program(args[0])
+ if match != None:
+ return [match]
+ else:
+ return []
+
def query_desktop_programs(self, query):
result = []
for match in self._indexer.look_up(query):
@@ -251,20 +253,17 @@
def on_key_press(self, query, shortcut):
if shortcut == gtk.keysyms.t:
- matches = self._check_program(query.split(" ")[0])
- for match in matches:
+ match = self._check_program(query.split(" ")[0])
+ if match != None:
match.set_with_terminal(True)
- if len(matches) > 0:
- return matches
+ return match
+
return None
-
+
def _check_program(self, program):
- results = []
- matches = is_program_glob_in_path(program)
- for match in matches:
- results.append(PathProgramMatch(self, match))
- return results
-
+ if is_program_in_path(program):
+ return PathProgramMatch(self, program)
+
def _scan_desktop_files(self):
for dir in get_xdg_data_dirs():
for f in glob.glob(join(dir, "applications", "*.desktop")):
@@ -284,19 +283,6 @@
result.get_string(deskbar.gnomedesktop.KEY_COMMENT),
), match)
-def is_program_glob_in_path(program):
- results = []
- if len(program) > 2:
- for path in PATH:
- prog_path = join(path, program)
- possible_matches = glob.glob(prog_path + "*")
- for possible in possible_matches:
- if exists(possible) and isfile(possible) and os.access(possible, os.F_OK | os.X_OK):
- #use realpath to reduce symlink dups
- results.append(basename(realpath(possible)))
- results.sort()
- return results
-
def get_priority_for_name(query, name):
if name.split(" ")[0].endswith(query):
return EXACT_MATCH_PRIO
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]