Using APT to search for pkg and apturl to install them

This commit is contained in:
Clement Lefebvre 2010-09-06 15:21:26 +01:00
parent cf6b1e7a53
commit e8380e8584
2 changed files with 1396 additions and 1378 deletions

6
debian/changelog vendored
View File

@ -1,3 +1,9 @@
mintmenu (5.0.0) julia; urgency=low
* Filtering now uses APT to fetch results and apturl to install packages
-- Clement Lefebvre <root@linuxmint.com> Mon, 06 Sep 2010 15:21:00 +0000
mintmenu (4.9.9) isadora; urgency=low
* Custom places: now understands ~ signs and listens to changes in the path

View File

@ -25,11 +25,23 @@ from filemonitor import monitor as filemonitor
#import xdg.Menu
import gmenu
import apt
from user import home
# i18n
gettext.install("mintmenu", "/usr/share/linuxmint/locale")
def print_timing(func):
def wrapper(*arg):
t1 = time.time()
res = func(*arg)
t2 = time.time()
print '%s took %0.3f ms' % (func.func_name, (t2-t1)*1000.0)
return res
return wrapper
# Evil patching
#def xdgParsePatched(filename=None):
# # conver to absolute path
@ -152,11 +164,15 @@ class Menu:
class SuggestionButton ( gtk.Button ):
def __init__( self, iconName, iconSize, label ):
gtk.Button.__init__( self )
iconSize = self.get_icon_size(iconSize)
self.iconName = iconName
self.set_relief( gtk.RELIEF_NONE )
self.set_size_request( 10, 10 )
self.set_size_request( -1, -1 )
Align1 = gtk.Alignment( 0, 0.5, 1.0, 0 )
HBox1 = gtk.HBox()
labelBox = gtk.VBox( False, 2 )
@ -177,6 +193,11 @@ class SuggestionButton ( gtk.Button ):
self.add( Align1 )
self.show()
def get_icon_size (self, iconSize):
if isinstance(iconSize, int):
if iconSize >= 4:
@ -190,7 +211,7 @@ class SuggestionButton ( gtk.Button ):
return iconSize
def set_text( self, text):
self.label.set_text(text)
self.label.set_markup(text)
def set_icon_size (self, size):
size = self.get_icon_size(size)
@ -203,8 +224,11 @@ class pluginclass( object ):
toFav = [ ( "FAVORITES", gtk.TARGET_SAME_APP, TARGET_TYPE_FAV ), ( "text/plain", 0, 100 ), ( "text/uri-list", 0, 101 ) ]
fromFav = [ ( "FAVORITES", gtk.TARGET_SAME_APP, TARGET_TYPE_FAV ) ]
@print_timing
def __init__( self, mintMenuWin, toggleButton ):
self.apt_cache = apt.Cache()
self.mintMenuWin = mintMenuWin
self.mainMenus = [ ]
@ -322,17 +346,8 @@ class pluginclass( object ):
return ( 0, 0 )
#sizeIcon = gtk.icon_size_lookup( sizeIcon )
#self.suggestSearchAppButton = SuggestionButton(gtk.STOCK_FIND, self.iconSize, "")
self.suggestSearchButton = SuggestionButton(gtk.STOCK_FIND, self.iconSize, "")
self.suggestShowButton = SuggestionButton(gtk.STOCK_INFO, self.iconSize, "")
self.suggestInstallButton = SuggestionButton(gtk.STOCK_ADD, self.iconSize, "")
#self.suggestSearchAppButton.connect("clicked", self.search_mint)
self.suggestSearchButton.connect("clicked", self.search_apt)
self.suggestShowButton.connect("clicked", self.show_apt)
self.suggestInstallButton.connect("clicked", self.install_apt)
self.suggestions = []
self.current_suggestion = None
self.get_panel()
def get_panel(self):
@ -345,20 +360,8 @@ class pluginclass( object ):
self.panel = gconf.client_get_default().get_string("/apps/panel/applets/" + applet + "/toplevel_id")
self.panel_position = gconf.client_get_default().get_int("/apps/panel/applets/" + applet + "/position") + 1
def search_mint(self, widget):
os.system("/usr/bin/mint-search-portal " + self.suggestion + " &")
self.mintMenuWin.hide()
def search_apt(self, widget):
os.system("/usr/bin/mint-search-apt " + self.suggestion + " &")
self.mintMenuWin.hide()
def show_apt(self, widget):
os.system("/usr/bin/mint-show-apt " + self.suggestion + " &")
self.mintMenuWin.hide()
def install_apt(self, widget):
os.system("/usr/bin/mint-make-cmd " + self.suggestion + " &")
def apturl_install(self, widget, pkg_name):
os.system("xdg-open apt://" + pkg_name + " &")
self.mintMenuWin.hide()
def __del__( self ):
@ -427,12 +430,6 @@ class pluginclass( object ):
except:
pass
#self.suggestSearchAppButton.set_icon_size( self.iconSize )
self.suggestSearchButton.set_icon_size( self.iconSize )
self.suggestShowButton.set_icon_size( self.iconSize )
self.suggestInstallButton.set_icon_size( self.iconSize )
def changeFavIconSize( self, client, connection_id, entry, args ):
self.faviconsize = entry.get_value().get_int()
@ -608,10 +605,9 @@ class pluginclass( object ):
start = time.time()
#print "FILTER"
#self.applicationsBox.remove(self.suggestSearchAppButton)
self.applicationsBox.remove(self.suggestSearchButton)
self.applicationsBox.remove(self.suggestShowButton)
self.applicationsBox.remove(self.suggestInstallButton)
for suggestion in self.suggestions:
self.applicationsBox.remove(suggestion)
self.suggestions = []
if widget == self.searchEntry:
if self.donotfilterapps:
@ -626,23 +622,40 @@ class pluginclass( object ):
showns = True
if (not showns and os.path.exists("/usr/lib/linuxmint/mintInstall/icon.svg")):
self.suggestion = text
if len(text) >= 3:
if self.current_suggestion is not None and self.current_suggestion in text:
# We're restricting our search...
for pkg in self.current_results:
if text in pkg.name:
name = pkg.name.replace(text, "<b>%s</b>" % text);
suggestionButton = SuggestionButton(gtk.STOCK_ADD, self.iconSize, "")
suggestionButton.connect("clicked", self.apturl_install, pkg.name)
suggestionButton.set_text(_("Install package '%s'") % name)
suggestionButton.set_tooltip_text(_("%s\n\n%s\n\n\n%s") % (pkg.name, pkg.summary.capitalize(), pkg.description))
suggestionButton.set_icon_size(self.iconSize)
self.applicationsBox.add(suggestionButton)
self.suggestions.append(suggestionButton)
else:
self.current_results = []
for pkg in self.apt_cache:
if text in pkg.name:
name = pkg.name.replace(text, "<b>%s</b>" % text);
suggestionButton = SuggestionButton(gtk.STOCK_ADD, self.iconSize, "")
suggestionButton.connect("clicked", self.apturl_install, pkg.name)
suggestionButton.set_text(_("Install package '%s'") % name)
suggestionButton.set_tooltip_text(_("%s\n\n%s\n\n%s") % (pkg.name, pkg.summary.capitalize(), pkg.description))
suggestionButton.set_icon_size(self.iconSize)
self.applicationsBox.add(suggestionButton)
self.suggestions.append(suggestionButton)
self.current_results.append(pkg)
#self.applicationsBox.add(self.suggestSearchAppButton)
#self.suggestSearchAppButton.set_text(_("Search portal for '%s'") % text)
#self.suggestSearchAppButton.set_tooltip_text(_("Search portal for '%s'") % text)
self.applicationsBox.add(self.suggestSearchButton)
self.suggestSearchButton.set_text(_("Search repositories for '%s'") % text)
self.suggestSearchButton.set_tooltip_text(_("Search repositories for '%s'") % text)
self.applicationsBox.add(self.suggestShowButton)
self.suggestShowButton.set_text(_("Show package '%s'") % text)
self.suggestShowButton.set_tooltip_text(_("Show package '%s'") % text)
self.applicationsBox.add(self.suggestInstallButton)
self.suggestInstallButton.set_text(_("Install package '%s'") % text)
self.suggestInstallButton.set_tooltip_text(_("Install package '%s'") % text)
self.current_suggestion = text
else:
self.current_suggestion = None
self.current_results = []
else:
self.current_suggestion = None
self.current_results = []
for i in self.categoriesBox.get_children():
i.set_relief( gtk.RELIEF_NONE )
@ -1454,4 +1467,3 @@ class pluginclass( object ):
# newApplicationsList.append( { "entry": item, "category": "" } )
return newApplicationsList