diff --git a/debian/control b/debian/control index 91df6bb..a6bed66 100644 --- a/debian/control +++ b/debian/control @@ -11,15 +11,18 @@ Depends: ${python:Depends}, ${misc:Depends}, python (>= 2.4), python (<< 3), - mint-common, - python-mate-menu, python-xdg, xdg-utils, python-apt, python-configobj, python-setproctitle, - mate-menus, - gvfs-bin, python-xlib, - gir1.2-mate-panel, gir1.2-gtk-3.0, gir1.2-mate-desktop, + python-xdg, + xdg-utils, + libglib2.0-bin, + mate-menus, + python-mate-menu, + gir1.2-matepanelapplet-4.0, + gir1.2-gtk-3.0, + gir1.2-mate-desktop, mozo Description: Advanced MATE menu One of the most advanced menus under Linux. MintMenu supports filtering, diff --git a/debian/postinst b/debian/postinst index 76fe3a1..d858a4f 100644 --- a/debian/postinst +++ b/debian/postinst @@ -1,5 +1,5 @@ #!/bin/sh -# postinst script +# postinst script # see: dh_installdeb(1) set -e @@ -18,7 +18,8 @@ set -e case "$1" in configure) - glib-compile-schemas /usr/share/glib-2.0/schemas + glib-compile-schemas /usr/share/glib-2.0/schemas + python -m compileall -qf /usr/lib/linuxmint/mintMenu/ ;; abort-upgrade|abort-remove|abort-deconfigure) diff --git a/usr/lib/linuxmint/mintMenu/compile.py b/usr/lib/linuxmint/mintMenu/compile.py deleted file mode 100755 index 33e5cfe..0000000 --- a/usr/lib/linuxmint/mintMenu/compile.py +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/python2 - -import compileall - -compileall.compile_dir(".", force=1) diff --git a/usr/lib/linuxmint/mintMenu/keybinding.py b/usr/lib/linuxmint/mintMenu/keybinding.py index d6dd6d9..4e59964 100644 --- a/usr/lib/linuxmint/mintMenu/keybinding.py +++ b/usr/lib/linuxmint/mintMenu/keybinding.py @@ -29,7 +29,7 @@ gi.require_version("Gtk", "3.0") from Xlib.display import Display from Xlib import X, error -from gi.repository import Gtk, Gdk, GdkX11, GObject, GLib +from gi.repository import Gtk, Gdk, GObject, GLib import threading SPECIAL_MODS = (["Super_L", ""], diff --git a/usr/lib/linuxmint/mintMenu/mintMenu.py b/usr/lib/linuxmint/mintMenu/mintMenu.py index ea5aa85..088829c 100755 --- a/usr/lib/linuxmint/mintMenu/mintMenu.py +++ b/usr/lib/linuxmint/mintMenu/mintMenu.py @@ -20,7 +20,6 @@ import pointerMonitor import setproctitle from plugins.execute import Execute - GObject.threads_init() # Rename the process @@ -71,7 +70,7 @@ class MainWindow(object): self.window.stick() - plugindir = os.path.join(os.path.expanduser("~"), ".linuxmint/mintMenu/plugins") + plugindir = os.path.join(os.environ["HOME"], ".linuxmint/mintMenu/plugins") sys.path.append(plugindir) self.panelSettings = Gio.Settings.new("org.mate.panel") @@ -162,7 +161,7 @@ class MainWindow(object): for plugin in self.pluginlist: if plugin in self.plugins: - print u"Duplicate plugin in list: ", plugin + print("Duplicate plugin in list: %s" % plugin) continue if plugin != "newpane": @@ -205,8 +204,7 @@ class MainWindow(object): MyPlugin.add(MyPlugin.content_holder) MyPlugin.width = 270 MyPlugin.icon = 'mate-logo-icon.png' - print u"Unable to load " + plugin + " plugin :-(" - + print("Unable to load %s plugin" % plugin) self.panesToColor.append(MyPlugin.content_holder) MyPlugin.content_holder.show() @@ -352,7 +350,6 @@ class MainWindow(object): widget.set_tooltip_text(tip) def RegenPlugins(self, *args, **kargs): - #print #print u"Reloading Plugins..." for item in self.paneholder: item.destroy() @@ -473,11 +470,11 @@ class MenuWin(object): self.keybinder.connect("activate", self.onBindingPress) self.keybinder.start() self.settings.connect("changed::hot-key", self.hotkeyChanged) - print "Binding to Hot Key: " + self.hotkeyText - except Exception, cause: + print("Binding to Hot Key: %s" % self.hotkeyText) + except Exception as e: self.keybinder = None - print "** WARNING ** - Keybinder Error" - print "Error Report :\n", str(cause) + print("** WARNING ** - Keybinder Error") + print("Error Report :\n", e) self.applet.set_can_focus(False) @@ -485,9 +482,9 @@ class MenuWin(object): self.pointerMonitor = pointerMonitor.PointerMonitor() self.pointerMonitor.connect("activate", self.onPointerOutside) self.mainwin.window.connect("realize", self.onRealize) - except Exception, cause: - print "** WARNING ** - Pointer Monitor Error" - print "Error Report :\n", str(cause) + except Exception as e: + print("** WARNING ** - Pointer Monitor Error") + print("Error Report :\n", e) def onWindowMap(self, *args): self.applet.get_style_context().set_state(Gtk.StateFlags.SELECTED) @@ -522,9 +519,9 @@ class MenuWin(object): def leave_notify(self, applet, event): # Hack for mate-panel-test-applets focus issue (this can be commented) - if event.state & Gdk.ModifierType.BUTTON1_MASK and applet.get_style_context().get_state() & Gtk.StateFlags.SELECTED: - if event.x >= 0 and event.y >= 0 and event.x < applet.get_window().get_width() and event.y < applet.get_window().get_height(): - self.mainwin.stopHiding() + # if event.state & Gdk.ModifierType.BUTTON1_MASK and applet.get_style_context().get_state() & Gtk.StateFlags.SELECTED: + # if event.x >= 0 and event.y >= 0 and event.x < applet.get_window().get_width() and event.y < applet.get_window().get_height(): + # self.mainwin.stopHiding() self.do_image(self.buttonIcon, False) @@ -542,13 +539,14 @@ class MenuWin(object): self.do_image(self.buttonIcon, False) self.systemlabel = Gtk.Label(label= "%s " % self.buttonText) if os.path.isfile("/etc/linuxmint/info"): - info = open("/etc/linuxmint/info").readlines() #TODO py3 encoding="utf-8" - for line in info: - if line.startswith("DESCRIPTION="): - tooltip = line.split("=",1)[1].replace('"','') - self.systemlabel.set_tooltip_text(tooltip) - self.button_icon.set_tooltip_text(tooltip) - break + with open("/etc/linuxmint/info") as info: + for line in info: + line = line.decode("utf-8") + if line.startswith("DESCRIPTION="): + tooltip = line.split("=",1)[1].strip('"\n') + self.systemlabel.set_tooltip_text(tooltip) + self.button_icon.set_tooltip_text(tooltip) + break if self.applet.get_orient() == MatePanelApplet.AppletOrient.UP or self.applet.get_orient() == MatePanelApplet.AppletOrient.DOWN: self.button_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) self.button_box.pack_start(self.button_icon, False, False, 0) @@ -568,17 +566,13 @@ class MenuWin(object): self.button_box.pack_start(self.button_icon , False, False, 0) self.button_icon.set_padding(0, 5) - self.button_box.set_homogeneous(False) self.button_box.show_all() self.sizeButton() - self.button_box.get_style_context().add_class('mintmenu') - self.applet.add(self.button_box) self.applet.set_background_widget(self.applet) - def loadSettings(self, *args, **kargs): self.hideIcon = self.settings.get_boolean("hide-applet-icon") self.buttonText = self.settings.get_string("applet-text") @@ -637,7 +631,6 @@ class MenuWin(object): self.updateButton() self.applet.add(self.button_box) - def updateButton(self): self.systemlabel.set_text(self.buttonText) self.button_icon.clear() @@ -676,22 +669,17 @@ class MenuWin(object): self.updateButton() def showAboutDialog(self, action, userdata = None): - about = Gtk.AboutDialog() about.set_name("mintMenu") - import commands - version = commands.getoutput("/usr/lib/linuxmint/common/version.py mintmenu") - about.set_version(version) + import subprocess + (stdout, stderr) = subprocess.Popen(["/usr/lib/linuxmint/common/version.py", "mintmenu"], + stdout=subprocess.PIPE).communicate() + about.set_version(stdout.strip()) try: - h = open('/usr/share/common-licenses/GPL','r') - s = h.readlines() - gpl = "" - for line in s: - gpl += line - h.close() + gpl = open('/usr/share/common-licenses/GPL','r').read() about.set_license(gpl) - except Exception, detail: - print detail + except Exception as e: + print(e) about.set_comments(_("Advanced MATE Menu")) # about.set_authors(["Clement Lefebvre ", "Lars-Peter Clausen "]) about.set_translator_credits(("translator-credits")) @@ -700,7 +688,6 @@ class MenuWin(object): about.connect("response", lambda dialog, r: dialog.destroy()) about.show() - def showPreferences(self, action, userdata = None): # Execute("mateconf-editor /apps/mintMenu") Execute(os.path.join(PATH, "mintMenuConfig.py")) @@ -831,8 +818,8 @@ class MenuWin(object): self.de = "mate" elif os.path.exists("/usr/bin/thunar"): self.de = "xfce" - except Exception, detail: - print detail + except Exception as e: + print(e) def applet_factory(applet, iid, data): MenuWin(applet, iid) diff --git a/usr/lib/linuxmint/mintMenu/mintMenuConfig.py b/usr/lib/linuxmint/mintMenu/mintMenuConfig.py index 2b9b01c..27cb9fe 100755 --- a/usr/lib/linuxmint/mintMenu/mintMenuConfig.py +++ b/usr/lib/linuxmint/mintMenu/mintMenuConfig.py @@ -1,41 +1,34 @@ #!/usr/bin/python2 +import gettext +import os import sys +from glob import glob import gi gi.require_version("Gtk", "3.0") - from gi.repository import Gtk, Gdk, GdkPixbuf + import keybinding +from plugins.easygsettings import EasyGSettings +PATH = os.path.abspath(os.path.dirname(sys.argv[0])) -try: - import gettext - import os - import commands -except Exception, e: - print e - sys.exit( 1 ) - -PATH = os.path.abspath( os.path.dirname( sys.argv[0] ) ) - -sys.path.append( os.path.join( PATH , "plugins") ) +sys.path.append(os.path.join(PATH , "plugins")) # i18n gettext.install("mintmenu", "/usr/share/linuxmint/locale") -from easygsettings import EasyGSettings +class mintMenuConfig(object): -class mintMenuConfig( object ): + def __init__(self): - def __init__( self ): - - self.path = os.path.abspath( os.path.dirname( sys.argv[0] ) ) + self.path = os.path.abspath(os.path.dirname(sys.argv[0])) # Load glade file and extract widgets self.builder = Gtk.Builder() - self.builder.add_from_file (os.path.join(self.path, "mintMenuConfig.glade" )) + self.builder.add_from_file(os.path.join(self.path, "mintMenuConfig.glade")) self.mainWindow=self.builder.get_object("mainWindow") #i18n @@ -106,40 +99,40 @@ class mintMenuConfig( object ): self.builder.get_object("logoutcheckbutton").set_label(_("Log Out")) self.builder.get_object("quitcheckbutton").set_label(_("Quit")) - self.editPlaceDialogTitle = (_("Edit Place")) - self.newPlaceDialogTitle = (_("New Place")) - self.folderChooserDialogTitle = (_("Select a folder")) + self.editPlaceDialogTitle = _("Edit Place") + self.newPlaceDialogTitle = _("New Place") + self.folderChooserDialogTitle = _("Select a folder") - self.startWithFavorites = self.builder.get_object( "startWithFavorites" ) - self.showAppComments = self.builder.get_object( "showAppComments" ) - self.useAPT = self.builder.get_object( "use_apt" ) - self.showCategoryIcons = self.builder.get_object( "showCategoryIcons" ) - self.showRecentPlugin = self.builder.get_object( "showRecentPlugin" ) - self.showApplicationsPlugin = self.builder.get_object( "showApplicationsPlugin" ) - self.showSystemPlugin = self.builder.get_object( "showSystemPlugin" ) - self.showPlacesPlugin = self.builder.get_object( "showPlacesPlugin" ) + self.startWithFavorites = self.builder.get_object("startWithFavorites") + self.showAppComments = self.builder.get_object("showAppComments") + self.useAPT = self.builder.get_object("use_apt") + self.showCategoryIcons = self.builder.get_object("showCategoryIcons") + self.showRecentPlugin = self.builder.get_object("showRecentPlugin") + self.showApplicationsPlugin = self.builder.get_object("showApplicationsPlugin") + self.showSystemPlugin = self.builder.get_object("showSystemPlugin") + self.showPlacesPlugin = self.builder.get_object("showPlacesPlugin") self.swapGeneric = self.builder.get_object("swapGeneric") - self.hover = self.builder.get_object( "hover" ) - self.hoverDelay = self.builder.get_object( "hoverDelay" ) - self.rememberFilter = self.builder.get_object( "remember_filter" ) - self.iconSize = self.builder.get_object( "iconSize" ) - self.favIconSize = self.builder.get_object( "favIconSize" ) - self.placesIconSize = self.builder.get_object( "placesIconSize" ) - self.systemIconSize = self.builder.get_object( "systemIconSize" ) - self.favCols = self.builder.get_object( "numFavCols" ) - self.useCustomColors = self.builder.get_object( "useCustomColors" ) - self.backgroundColor = self.builder.get_object( "backgroundColor" ) - self.headingColor = self.builder.get_object( "headingColor" ) - self.backgroundColorLabel = self.builder.get_object( "backgroundColorLabel" ) - self.headingColorLabel = self.builder.get_object( "headingColorLabel" ) - self.showButtonIcon = self.builder.get_object( "showButtonIcon" ) - self.enableInternetSearch = self.builder.get_object( "enableInternetSearch" ) - self.buttonText = self.builder.get_object( "buttonText" ) - self.hotkeyWidget = keybinding.KeybindingWidget(_("Keyboard shortcut:") ) - grid = self.builder.get_object( "main_grid" ) + self.hover = self.builder.get_object("hover") + self.hoverDelay = self.builder.get_object("hoverDelay") + self.rememberFilter = self.builder.get_object("remember_filter") + self.iconSize = self.builder.get_object("iconSize") + self.favIconSize = self.builder.get_object("favIconSize") + self.placesIconSize = self.builder.get_object("placesIconSize") + self.systemIconSize = self.builder.get_object("systemIconSize") + self.favCols = self.builder.get_object("numFavCols") + self.useCustomColors = self.builder.get_object("useCustomColors") + self.backgroundColor = self.builder.get_object("backgroundColor") + self.headingColor = self.builder.get_object("headingColor") + self.backgroundColorLabel = self.builder.get_object("backgroundColorLabel") + self.headingColorLabel = self.builder.get_object("headingColorLabel") + self.showButtonIcon = self.builder.get_object("showButtonIcon") + self.enableInternetSearch = self.builder.get_object("enableInternetSearch") + self.buttonText = self.builder.get_object("buttonText") + self.hotkeyWidget = keybinding.KeybindingWidget(_("Keyboard shortcut:")) + grid = self.builder.get_object("main_grid") grid.attach(self.hotkeyWidget, 0, 2, 2, 1) - self.buttonIcon = self.builder.get_object( "buttonIcon" ) - self.buttonIconChooser = self.builder.get_object( "button_icon_chooser" ) + self.buttonIcon = self.builder.get_object("buttonIcon") + self.buttonIconChooser = self.builder.get_object("button_icon_chooser") self.image_filter = Gtk.FileFilter() self.image_filter.set_name(_("Images")) self.image_filter.add_pattern("*.png") @@ -152,115 +145,115 @@ class mintMenuConfig( object ): self.buttonIconChooser.add_filter(self.image_filter) self.buttonIconChooser.set_filter(self.image_filter) self.buttonIconImage = self.builder.get_object("image_button_icon") - self.searchCommand = self.builder.get_object( "search_command" ) - self.computertoggle = self.builder.get_object( "computercheckbutton" ) - self.homefoldertoggle = self.builder.get_object( "homecheckbutton" ) - self.networktoggle = self.builder.get_object( "networkcheckbutton" ) - self.desktoptoggle = self.builder.get_object( "desktopcheckbutton" ) - self.trashtoggle = self.builder.get_object( "trashcheckbutton" ) - self.customplacestree = self.builder.get_object( "customplacestree" ) - self.allowPlacesScrollbarToggle = self.builder.get_object( "allowscrollbarcheckbutton" ) - self.showgtkbookmarksToggle = self.builder.get_object( "showgtkbookmarkscheckbutton" ) - self.placesHeightButton = self.builder.get_object( "placesHeightSpinButton" ) - if (self.allowPlacesScrollbarToggle.get_active() == False): + self.searchCommand = self.builder.get_object("search_command") + self.computertoggle = self.builder.get_object("computercheckbutton") + self.homefoldertoggle = self.builder.get_object("homecheckbutton") + self.networktoggle = self.builder.get_object("networkcheckbutton") + self.desktoptoggle = self.builder.get_object("desktopcheckbutton") + self.trashtoggle = self.builder.get_object("trashcheckbutton") + self.customplacestree = self.builder.get_object("customplacestree") + self.allowPlacesScrollbarToggle = self.builder.get_object("allowscrollbarcheckbutton") + self.showgtkbookmarksToggle = self.builder.get_object("showgtkbookmarkscheckbutton") + self.placesHeightButton = self.builder.get_object("placesHeightSpinButton") + if not self.allowPlacesScrollbarToggle.get_active(): self.placesHeightButton.set_sensitive(False) - self.allowPlacesScrollbarToggle.connect("toggled", self.togglePlacesHeightEnabled ) - self.softwareManagerToggle = self.builder.get_object( "softwaremanagercheckbutton" ) - self.packageManagerToggle = self.builder.get_object( "packagemanagercheckbutton" ) - self.controlCenterToggle = self.builder.get_object( "controlcentercheckbutton" ) - self.terminalToggle = self.builder.get_object( "terminalcheckbutton" ) - self.lockToggle = self.builder.get_object( "lockcheckbutton" ) - self.logoutToggle = self.builder.get_object( "logoutcheckbutton" ) - self.quitToggle = self.builder.get_object( "quitcheckbutton" ) - self.allowSystemScrollbarToggle = self.builder.get_object( "allowscrollbarcheckbutton1" ) - self.systemHeightButton = self.builder.get_object( "systemHeightSpinButton" ) - if (self.allowSystemScrollbarToggle.get_active() == False): self.systemHeightButton.set_sensitive(False) - self.allowSystemScrollbarToggle.connect("toggled", self.toggleSystemHeightEnabled ) + self.allowPlacesScrollbarToggle.connect("toggled", self.togglePlacesHeightEnabled) + self.softwareManagerToggle = self.builder.get_object("softwaremanagercheckbutton") + self.packageManagerToggle = self.builder.get_object("packagemanagercheckbutton") + self.controlCenterToggle = self.builder.get_object("controlcentercheckbutton") + self.terminalToggle = self.builder.get_object("terminalcheckbutton") + self.lockToggle = self.builder.get_object("lockcheckbutton") + self.logoutToggle = self.builder.get_object("logoutcheckbutton") + self.quitToggle = self.builder.get_object("quitcheckbutton") + self.allowSystemScrollbarToggle = self.builder.get_object("allowscrollbarcheckbutton1") + self.systemHeightButton = self.builder.get_object("systemHeightSpinButton") + if not self.allowSystemScrollbarToggle.get_active(): + self.systemHeightButton.set_sensitive(False) + self.allowSystemScrollbarToggle.connect("toggled", self.toggleSystemHeightEnabled) if os.path.exists("/usr/bin/mintinstall"): - self.builder.get_object( "softwaremanagercheckbutton" ).show() + self.builder.get_object("softwaremanagercheckbutton").show() else: - self.builder.get_object( "softwaremanagercheckbutton" ).hide() + self.builder.get_object("softwaremanagercheckbutton").hide() - self.builder.get_object( "closeButton" ).connect("clicked", Gtk.main_quit ) + self.builder.get_object("closeButton").connect("clicked", Gtk.main_quit) + self.settings = EasyGSettings("com.linuxmint.mintmenu") + self.settingsApplications = EasyGSettings("com.linuxmint.mintmenu.plugins.applications") + self.settingsPlaces = EasyGSettings("com.linuxmint.mintmenu.plugins.places") + self.settingsSystem = EasyGSettings("com.linuxmint.mintmenu.plugins.system_management") - self.settings = EasyGSettings( "com.linuxmint.mintmenu" ) - self.settingsApplications = EasyGSettings( "com.linuxmint.mintmenu.plugins.applications" ) - self.settingsPlaces = EasyGSettings( "com.linuxmint.mintmenu.plugins.places" ) - self.settingsSystem = EasyGSettings( "com.linuxmint.mintmenu.plugins.system_management" ) + self.useCustomColors.connect("toggled", self.toggleUseCustomColors) - self.useCustomColors.connect( "toggled", self.toggleUseCustomColors ) + self.bindGSettingsValueToWidget(self.settings, "bool", "start-with-favorites", self.startWithFavorites, "toggled", self.startWithFavorites.set_active, self.startWithFavorites.get_active) + self.bindGSettingsValueToWidget(self.settingsApplications, "bool", "show-application-comments", self.showAppComments, "toggled", self.showAppComments.set_active, self.showAppComments.get_active) + self.bindGSettingsValueToWidget(self.settingsApplications, "bool", "use-apt", self.useAPT, "toggled", self.useAPT.set_active, self.useAPT.get_active) + self.bindGSettingsValueToWidget(self.settingsApplications, "bool", "show-category-icons", self.showCategoryIcons, "toggled", self.showCategoryIcons.set_active, self.showCategoryIcons.get_active) + self.bindGSettingsValueToWidget(self.settingsApplications, "bool", "categories-mouse-over", self.hover, "toggled", self.hover.set_active, self.hover.get_active) + self.bindGSettingsValueToWidget(self.settingsApplications, "bool", "swap-generic-name", self.swapGeneric, "toggled", self.swapGeneric.set_active, self.swapGeneric.get_active) - self.bindGSettingsValueToWidget( self.settings, "bool", "start-with-favorites", self.startWithFavorites, "toggled", self.startWithFavorites.set_active, self.startWithFavorites.get_active ) - self.bindGSettingsValueToWidget( self.settingsApplications, "bool", "show-application-comments", self.showAppComments, "toggled", self.showAppComments.set_active, self.showAppComments.get_active ) - self.bindGSettingsValueToWidget( self.settingsApplications, "bool", "use-apt", self.useAPT, "toggled", self.useAPT.set_active, self.useAPT.get_active ) - self.bindGSettingsValueToWidget( self.settingsApplications, "bool", "show-category-icons", self.showCategoryIcons, "toggled", self.showCategoryIcons.set_active, self.showCategoryIcons.get_active ) - self.bindGSettingsValueToWidget( self.settingsApplications, "bool", "categories-mouse-over", self.hover, "toggled", self.hover.set_active, self.hover.get_active ) - self.bindGSettingsValueToWidget( self.settingsApplications, "bool", "swap-generic-name", self.swapGeneric, "toggled", self.swapGeneric.set_active, self.swapGeneric.get_active ) + self.bindGSettingsValueToWidget(self.settingsApplications, "int", "category-hover-delay", self.hoverDelay, "value-changed", self.hoverDelay.set_value, self.hoverDelay.get_value) + self.bindGSettingsValueToWidget(self.settingsApplications, "int", "icon-size", self.iconSize, "value-changed", self.iconSize.set_value, self.iconSize.get_value) + self.bindGSettingsValueToWidget(self.settingsApplications, "int", "favicon-size", self.favIconSize, "value-changed", self.favIconSize.set_value, self.favIconSize.get_value) + self.bindGSettingsValueToWidget(self.settingsApplications, "int", "fav-cols", self.favCols, "value-changed", self.favCols.set_value, self.favCols.get_value) + self.bindGSettingsValueToWidget(self.settingsApplications, "bool", "remember-filter", self.rememberFilter, "toggled", self.rememberFilter.set_active, self.rememberFilter.get_active) + self.bindGSettingsValueToWidget(self.settingsApplications, "bool", "enable-internet-search", self.enableInternetSearch, "toggled", self.enableInternetSearch.set_active, self.enableInternetSearch.get_active) - self.bindGSettingsValueToWidget( self.settingsApplications, "int", "category-hover-delay", self.hoverDelay, "value-changed", self.hoverDelay.set_value, self.hoverDelay.get_value ) - self.bindGSettingsValueToWidget( self.settingsApplications, "int", "icon-size", self.iconSize, "value-changed", self.iconSize.set_value, self.iconSize.get_value ) - self.bindGSettingsValueToWidget( self.settingsApplications, "int", "favicon-size", self.favIconSize, "value-changed", self.favIconSize.set_value, self.favIconSize.get_value ) - self.bindGSettingsValueToWidget( self.settingsApplications, "int", "fav-cols", self.favCols, "value-changed", self.favCols.set_value, self.favCols.get_value ) - self.bindGSettingsValueToWidget( self.settingsApplications, "bool", "remember-filter", self.rememberFilter, "toggled", self.rememberFilter.set_active, self.rememberFilter.get_active) - self.bindGSettingsValueToWidget( self.settingsApplications, "bool", "enable-internet-search", self.enableInternetSearch, "toggled", self.enableInternetSearch.set_active, self.enableInternetSearch.get_active) + self.bindGSettingsValueToWidget(self.settingsPlaces, "int", "icon-size", self.placesIconSize, "value-changed", self.placesIconSize.set_value, self.placesIconSize.get_value) + self.bindGSettingsValueToWidget(self.settingsSystem, "int", "icon-size", self.systemIconSize, "value-changed", self.systemIconSize.set_value, self.systemIconSize.get_value) - self.bindGSettingsValueToWidget( self.settingsPlaces, "int", "icon-size", self.placesIconSize, "value-changed", self.placesIconSize.set_value, self.placesIconSize.get_value ) - self.bindGSettingsValueToWidget( self.settingsSystem, "int", "icon-size", self.systemIconSize, "value-changed", self.systemIconSize.set_value, self.systemIconSize.get_value ) - - self.bindGSettingsValueToWidget( self.settings, "bool", "use-custom-color", self.useCustomColors, "toggled", self.useCustomColors.set_active, self.useCustomColors.get_active ) - self.bindGSettingsValueToWidget( self.settings, "color", "custom-color", self.backgroundColor, "color-set", self.backgroundColor.set_rgba, self.getBackgroundColor ) - self.bindGSettingsValueToWidget( self.settings, "color", "custom-heading-color", self.headingColor, "color-set", self.headingColor.set_rgba, self.getHeadingColor ) - self.bindGSettingsValueToWidget( self.settings, "bool", "hide-applet-icon", self.showButtonIcon, "toggled", self.setShowButtonIcon, self.getShowButtonIcon ) - self.bindGSettingsValueToWidget( self.settings, "string", "applet-text", self.buttonText, "changed", self.buttonText.set_text, self.buttonText.get_text ) - self.bindGSettingsValueToWidget( self.settings, "string", "hot-key", self.hotkeyWidget, "accel-edited", self.hotkeyWidget.set_val, self.hotkeyWidget.get_val ) - self.bindGSettingsValueToWidget( self.settings, "string", "applet-icon", self.buttonIconChooser, "file-set", self.setButtonIcon, self.buttonIconChooser.get_filename ) - self.bindGSettingsValueToWidget( self.settingsApplications, "string", "search-command", self.searchCommand, "changed", self.searchCommand.set_text, self.searchCommand.get_text ) + self.bindGSettingsValueToWidget(self.settings, "bool", "use-custom-color", self.useCustomColors, "toggled", self.useCustomColors.set_active, self.useCustomColors.get_active) + self.bindGSettingsValueToWidget(self.settings, "color", "custom-color", self.backgroundColor, "color-set", self.backgroundColor.set_rgba, self.getBackgroundColor) + self.bindGSettingsValueToWidget(self.settings, "color", "custom-heading-color", self.headingColor, "color-set", self.headingColor.set_rgba, self.getHeadingColor) + self.bindGSettingsValueToWidget(self.settings, "bool", "hide-applet-icon", self.showButtonIcon, "toggled", self.setShowButtonIcon, self.getShowButtonIcon) + self.bindGSettingsValueToWidget(self.settings, "string", "applet-text", self.buttonText, "changed", self.buttonText.set_text, self.buttonText.get_text) + self.bindGSettingsValueToWidget(self.settings, "string", "hot-key", self.hotkeyWidget, "accel-edited", self.hotkeyWidget.set_val, self.hotkeyWidget.get_val) + self.bindGSettingsValueToWidget(self.settings, "string", "applet-icon", self.buttonIconChooser, "file-set", self.setButtonIcon, self.buttonIconChooser.get_filename) + self.bindGSettingsValueToWidget(self.settingsApplications, "string", "search-command", self.searchCommand, "changed", self.searchCommand.set_text, self.searchCommand.get_text) self.getPluginsToggle() - self.showRecentPlugin.connect("toggled", self.setPluginsLayout ) - self.showApplicationsPlugin.connect("toggled", self.setPluginsLayout ) - self.showSystemPlugin.connect("toggled", self.setPluginsLayout ) - self.showPlacesPlugin.connect("toggled", self.setPluginsLayout ) + self.showRecentPlugin.connect("toggled", self.setPluginsLayout) + self.showApplicationsPlugin.connect("toggled", self.setPluginsLayout) + self.showSystemPlugin.connect("toggled", self.setPluginsLayout) + self.showPlacesPlugin.connect("toggled", self.setPluginsLayout) - self.bindGSettingsValueToWidget( self.settingsPlaces, "bool", "show-computer", self.computertoggle, "toggled", self.computertoggle.set_active, self.computertoggle.get_active ) - self.bindGSettingsValueToWidget( self.settingsPlaces, "bool", "show-home-folder", self.homefoldertoggle, "toggled", self.homefoldertoggle.set_active, self.homefoldertoggle.get_active ) - self.bindGSettingsValueToWidget( self.settingsPlaces, "bool", "show-network", self.networktoggle, "toggled", self.networktoggle.set_active, self.networktoggle.get_active ) - self.bindGSettingsValueToWidget( self.settingsPlaces, "bool", "show-desktop", self.desktoptoggle, "toggled", self.desktoptoggle.set_active, self.desktoptoggle.get_active ) - self.bindGSettingsValueToWidget( self.settingsPlaces, "bool", "show-trash", self.trashtoggle, "toggled", self.trashtoggle.set_active, self.trashtoggle.get_active ) - self.bindGSettingsValueToWidget( self.settingsPlaces, "int", "height", self.placesHeightButton, "value-changed", self.placesHeightButton.set_value, self.placesHeightButton.get_value_as_int ) - self.bindGSettingsValueToWidget( self.settingsPlaces, "bool", "allow-scrollbar", self.allowPlacesScrollbarToggle, "toggled", self.allowPlacesScrollbarToggle.set_active, self.allowPlacesScrollbarToggle.get_active ) - self.bindGSettingsValueToWidget( self.settingsPlaces, "bool", "show-gtk-bookmarks", self.showgtkbookmarksToggle, "toggled", self.showgtkbookmarksToggle.set_active, self.showgtkbookmarksToggle.get_active ) + self.bindGSettingsValueToWidget(self.settingsPlaces, "bool", "show-computer", self.computertoggle, "toggled", self.computertoggle.set_active, self.computertoggle.get_active) + self.bindGSettingsValueToWidget(self.settingsPlaces, "bool", "show-home-folder", self.homefoldertoggle, "toggled", self.homefoldertoggle.set_active, self.homefoldertoggle.get_active) + self.bindGSettingsValueToWidget(self.settingsPlaces, "bool", "show-network", self.networktoggle, "toggled", self.networktoggle.set_active, self.networktoggle.get_active) + self.bindGSettingsValueToWidget(self.settingsPlaces, "bool", "show-desktop", self.desktoptoggle, "toggled", self.desktoptoggle.set_active, self.desktoptoggle.get_active) + self.bindGSettingsValueToWidget(self.settingsPlaces, "bool", "show-trash", self.trashtoggle, "toggled", self.trashtoggle.set_active, self.trashtoggle.get_active) + self.bindGSettingsValueToWidget(self.settingsPlaces, "int", "height", self.placesHeightButton, "value-changed", self.placesHeightButton.set_value, self.placesHeightButton.get_value_as_int) + self.bindGSettingsValueToWidget(self.settingsPlaces, "bool", "allow-scrollbar", self.allowPlacesScrollbarToggle, "toggled", self.allowPlacesScrollbarToggle.set_active, self.allowPlacesScrollbarToggle.get_active) + self.bindGSettingsValueToWidget(self.settingsPlaces, "bool", "show-gtk-bookmarks", self.showgtkbookmarksToggle, "toggled", self.showgtkbookmarksToggle.set_active, self.showgtkbookmarksToggle.get_active) - self.bindGSettingsValueToWidget( self.settingsSystem, "bool", "show-software-manager", self.softwareManagerToggle, "toggled", self.softwareManagerToggle.set_active, self.softwareManagerToggle.get_active ) - self.bindGSettingsValueToWidget( self.settingsSystem, "bool", "show-package-manager", self.packageManagerToggle, "toggled", self.packageManagerToggle.set_active, self.packageManagerToggle.get_active ) - self.bindGSettingsValueToWidget( self.settingsSystem, "bool", "show-control-center", self.controlCenterToggle, "toggled", self.controlCenterToggle.set_active, self.controlCenterToggle.get_active ) - self.bindGSettingsValueToWidget( self.settingsSystem, "bool", "show-terminal", self.terminalToggle, "toggled", self.terminalToggle.set_active, self.terminalToggle.get_active ) - self.bindGSettingsValueToWidget( self.settingsSystem, "bool", "show-lock-screen", self.lockToggle, "toggled", self.lockToggle.set_active, self.lockToggle.get_active ) - self.bindGSettingsValueToWidget( self.settingsSystem, "bool", "show-logout", self.logoutToggle, "toggled", self.logoutToggle.set_active, self.logoutToggle.get_active ) - self.bindGSettingsValueToWidget( self.settingsSystem, "bool", "show-quit", self.quitToggle, "toggled", self.quitToggle.set_active, self.quitToggle.get_active ) - self.bindGSettingsValueToWidget( self.settingsSystem, "int", "height", self.systemHeightButton, "value-changed", self.systemHeightButton.set_value, self.systemHeightButton.get_value_as_int ) - self.bindGSettingsValueToWidget( self.settingsSystem, "bool", "allow-scrollbar", self.allowSystemScrollbarToggle, "toggled", self.allowSystemScrollbarToggle.set_active, self.allowSystemScrollbarToggle.get_active ) + self.bindGSettingsValueToWidget(self.settingsSystem, "bool", "show-software-manager", self.softwareManagerToggle, "toggled", self.softwareManagerToggle.set_active, self.softwareManagerToggle.get_active) + self.bindGSettingsValueToWidget(self.settingsSystem, "bool", "show-package-manager", self.packageManagerToggle, "toggled", self.packageManagerToggle.set_active, self.packageManagerToggle.get_active) + self.bindGSettingsValueToWidget(self.settingsSystem, "bool", "show-control-center", self.controlCenterToggle, "toggled", self.controlCenterToggle.set_active, self.controlCenterToggle.get_active) + self.bindGSettingsValueToWidget(self.settingsSystem, "bool", "show-terminal", self.terminalToggle, "toggled", self.terminalToggle.set_active, self.terminalToggle.get_active) + self.bindGSettingsValueToWidget(self.settingsSystem, "bool", "show-lock-screen", self.lockToggle, "toggled", self.lockToggle.set_active, self.lockToggle.get_active) + self.bindGSettingsValueToWidget(self.settingsSystem, "bool", "show-logout", self.logoutToggle, "toggled", self.logoutToggle.set_active, self.logoutToggle.get_active) + self.bindGSettingsValueToWidget(self.settingsSystem, "bool", "show-quit", self.quitToggle, "toggled", self.quitToggle.set_active, self.quitToggle.get_active) + self.bindGSettingsValueToWidget(self.settingsSystem, "int", "height", self.systemHeightButton, "value-changed", self.systemHeightButton.set_value, self.systemHeightButton.get_value_as_int) + self.bindGSettingsValueToWidget(self.settingsSystem, "bool", "allow-scrollbar", self.allowSystemScrollbarToggle, "toggled", self.allowSystemScrollbarToggle.set_active, self.allowSystemScrollbarToggle.get_active) - self.customplacepaths = self.settingsPlaces.get( "list-string", "custom-paths" ) - self.customplacenames = self.settingsPlaces.get( "list-string", "custom-names" ) + self.customplacepaths = self.settingsPlaces.get("list-string", "custom-paths") + self.customplacenames = self.settingsPlaces.get("list-string", "custom-names") - self.customplacestreemodel = Gtk.ListStore( str, str) + self.customplacestreemodel = Gtk.ListStore(str, str) self.cell = Gtk.CellRendererText() - for count in range( len(self.customplacepaths) ): - self.customplacestreemodel.append( [ self.customplacenames[count], self.customplacepaths[count] ] ) + for count in range(len(self.customplacepaths)): + self.customplacestreemodel.append([self.customplacenames[count], self.customplacepaths[count]]) self.customplacestreemodel.connect("row-inserted", self.updatePlacesGSettings) self.customplacestreemodel.connect("row-deleted", self.updatePlacesGSettings) self.customplacestreemodel.connect("rows-reordered", self.updatePlacesGSettings) self.customplacestreemodel.connect("row-changed", self.updatePlacesGSettings) - self.customplacestree.set_model( self.customplacestreemodel ) - self.namescolumn = Gtk.TreeViewColumn( _("Name"), self.cell, text = 0 ) - self.placescolumn = Gtk.TreeViewColumn( _("Path"), self.cell, text = 1 ) - self.customplacestree.append_column( self.namescolumn ) - self.customplacestree.append_column( self.placescolumn ) + self.customplacestree.set_model(self.customplacestreemodel) + self.namescolumn = Gtk.TreeViewColumn(_("Name"), self.cell, text = 0) + self.placescolumn = Gtk.TreeViewColumn(_("Path"), self.cell, text = 1) + self.customplacestree.append_column(self.namescolumn) + self.customplacestree.append_column(self.placescolumn) self.builder.get_object("newButton").connect("clicked", self.newPlace) self.builder.get_object("editButton").connect("clicked", self.editPlace) self.builder.get_object("upButton").connect("clicked", self.moveUp) @@ -268,9 +261,8 @@ class mintMenuConfig( object ): self.builder.get_object("removeButton").connect("clicked", self.removePlace) #Detect themes and show theme here - theme_name = self.settings.get ("string", "theme-name") - themes = commands.getoutput("find /usr/share/themes -name gtkrc") - themes = themes.split("\n") + theme_name = self.settings.get("string", "theme-name") + themes = glob("/usr/share/themes/*/*/gtkrc") model = Gtk.ListStore(str, str) self.builder.get_object("themesCombo").set_model(model) selected_theme = model.append([_("Desktop theme"), "default"]) @@ -295,10 +287,10 @@ class mintMenuConfig( object ): model = widget.get_model() iter = widget.get_active_iter() theme_name = model.get_value(iter, 1) - self.settings.set( "string", "theme-name", theme_name) + self.settings.set("string", "theme-name", theme_name) def getPluginsToggle(self): - array = self.settings.get ("list-string", "plugins-list") + array = self.settings.get("list-string", "plugins-list") if "recent" in array: self.showRecentPlugin.set_active(True) else: @@ -316,7 +308,7 @@ class mintMenuConfig( object ): else: self.showPlacesPlugin.set_active(False) - def setPluginsLayout (self, widget): + def setPluginsLayout(self, widget): visiblePlugins = [] if self.showPlacesPlugin.get_active(): visiblePlugins.append("places") @@ -330,79 +322,80 @@ class mintMenuConfig( object ): if self.showApplicationsPlugin.get_active() or self.showPlacesPlugin.get_active() or self.showSystemPlugin.get_active(): visiblePlugins.append("newpane") visiblePlugins.append("recent") - self.settings.set ("list-string", "plugins-list", visiblePlugins) + self.settings.set("list-string", "plugins-list", visiblePlugins) - def setShowButtonIcon( self, value ): - self.showButtonIcon.set_active(not value ) + def setShowButtonIcon(self, value): + self.showButtonIcon.set_active(not value) - def setButtonIcon( self, value ): + def setButtonIcon(self, value): self.buttonIconChooser.set_filename(value) pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(value, -1, 22) self.buttonIconImage.set_from_pixbuf(pixbuf) - def getShowButtonIcon( self ): + def getShowButtonIcon(self): return not self.showButtonIcon.get_active() - def bindGSettingsValueToWidget( self, settings, setting_type, key, widget, changeEvent, setter, getter ): - settings.notifyAdd( key, self.callSetter, args = [ setting_type, setter ] ) + def bindGSettingsValueToWidget(self, settings, setting_type, key, widget, changeEvent, setter, getter): + settings.notifyAdd(key, self.callSetter, args = [setting_type, setter]) if setting_type == "color": color = Gdk.RGBA() - color.parse( settings.get( setting_type, key ) ) - setter( color ) + color.parse(settings.get(setting_type, key)) + setter(color) else: - setter( settings.get( setting_type, key ) ) - widget.connect( changeEvent, lambda *args: self.callGetter( settings, setting_type, key, getter ) ) + setter(settings.get(setting_type, key)) + widget.connect(changeEvent, lambda *args: self.callGetter(settings, setting_type, key, getter)) - def callSetter( self, settings, key, args ): + def callSetter(self, settings, key, args): if args[0] == "bool": - args[1]( settings.get_boolean(key) ) + args[1](settings.get_boolean(key)) elif args[0] == "string": - args[1]( settings.get_string(key) ) + args[1](settings.get_string(key)) elif args[0] == "int": - args[1]( settings.get_int(key) ) + args[1](settings.get_int(key)) elif args[0] == "color": color = Gdk.RGBA() - color.parse( settings.get_string(key) ) - args[1]( color ) + color.parse(settings.get_string(key)) + args[1](color) - def callGetter( self, settings, setting_type, key, getter ): - if (setting_type == "int"): - settings.set( setting_type, key, int(getter())) + def callGetter(self, settings, setting_type, key, getter): + if setting_type == "int": + settings.set(setting_type, key, int(getter())) else: - settings.set( setting_type, key, getter()) + settings.set(setting_type, key, getter()) - def toggleUseCustomColors( self, widget ): - self.backgroundColor.set_sensitive( widget.get_active() ) - self.headingColor.set_sensitive( widget.get_active() ) - self.backgroundColorLabel.set_sensitive( widget.get_active() ) - self.headingColorLabel.set_sensitive( widget.get_active() ) + def toggleUseCustomColors(self, widget): + self.backgroundColor.set_sensitive(widget.get_active()) + self.headingColor.set_sensitive(widget.get_active()) + self.backgroundColorLabel.set_sensitive(widget.get_active()) + self.headingColorLabel.set_sensitive(widget.get_active()) - def getBackgroundColor( self ): + def getBackgroundColor(self): color = self.backgroundColor.get_rgba() - return self.gdkRGBAToString( color ) + return self.gdkRGBAToString(color) - def getHeadingColor( self ): + def getHeadingColor(self): color = self.headingColor.get_rgba() - return self.gdkRGBAToString( color ) + return self.gdkRGBAToString(color) - def gdkRGBAToString( self, gdkRGBA ): - return "#%.2X%.2X%.2X" % ( gdkRGBA.red * 256, gdkRGBA.green * 256, gdkRGBA.blue * 256 ) + def gdkRGBAToString(self, gdkRGBA): + return "#%.2X%.2X%.2X" % (gdkRGBA.red * 256, gdkRGBA.green * 256, gdkRGBA.blue * 256) - def moveUp( self, upButton ): + def moveUp(self, upButton): treeselection = self.customplacestree.get_selection() - currentiter = (treeselection.get_selected())[1] + currentiter = treeselection.get_selected()[1] - if ( treeselection != None ): + if treeselection: lagiter = self.customplacestreemodel.get_iter_first() nextiter = self.customplacestreemodel.get_iter_first() - while ( (self.customplacestreemodel.get_path(nextiter) != self.customplacestreemodel.get_path(currentiter)) & (nextiter != None)): + while nextiter and self.customplacestreemodel.get_path(nextiter) != \ + self.customplacestreemodel.get_path(currentiter): lagiter = nextiter nextiter = self.customplacestreemodel.iter_next(nextiter) - if (nextiter != None): + if nextiter: self.customplacestreemodel.swap(currentiter, lagiter) return @@ -410,51 +403,51 @@ class mintMenuConfig( object ): def newPlace(self, newButton): self.builder.get_object("label2").set_text(_("Name:")) self.builder.get_object("label1").set_text(_("Path:")) - newPlaceDialog = self.builder.get_object( "editPlaceDialog" ) - folderChooserDialog = self.builder.get_object( "fileChooserDialog" ) + newPlaceDialog = self.builder.get_object("editPlaceDialog") + folderChooserDialog = self.builder.get_object("fileChooserDialog") newPlaceDialog.set_transient_for(self.mainWindow) newPlaceDialog.set_icon_from_file("/usr/lib/linuxmint/mintMenu/icon.svg") newPlaceDialog.set_title(self.newPlaceDialogTitle) folderChooserDialog.set_title(self.folderChooserDialogTitle) newPlaceDialog.set_default_response(Gtk.ResponseType.OK) - newPlaceName = self.builder.get_object( "nameEntryBox" ) - newPlacePath = self.builder.get_object( "pathEntryBox" ) - folderButton = self.builder.get_object( "folderButton" ) + newPlaceName = self.builder.get_object("nameEntryBox") + newPlacePath = self.builder.get_object("pathEntryBox") + folderButton = self.builder.get_object("folderButton") def chooseFolder(folderButton): currentPath = newPlacePath.get_text() - if (currentPath!=""): + if currentPath: folderChooserDialog.select_filename(currentPath) response = folderChooserDialog.run() folderChooserDialog.hide() - if (response == Gtk.ResponseType.OK): - newPlacePath.set_text( folderChooserDialog.get_filenames()[0] ) + if response == Gtk.ResponseType.OK: + newPlacePath.set_text(folderChooserDialog.get_filenames()[0]) folderButton.connect("clicked", chooseFolder) response = newPlaceDialog.run() newPlaceDialog.hide() - if (response == Gtk.ResponseType.OK ): + if response == Gtk.ResponseType.OK: name = newPlaceName.get_text() path = newPlacePath.get_text() - if (name != "" and path !=""): - self.customplacestreemodel.append( (name, path) ) + if name and path: + self.customplacestreemodel.append((name, path)) def editPlace(self, editButton): self.builder.get_object("label2").set_text(_("Name:")) self.builder.get_object("label1").set_text(_("Path:")) - editPlaceDialog = self.builder.get_object( "editPlaceDialog" ) - folderChooserDialog = self.builder.get_object( "fileChooserDialog" ) + editPlaceDialog = self.builder.get_object("editPlaceDialog") + folderChooserDialog = self.builder.get_object("fileChooserDialog") editPlaceDialog.set_transient_for(self.mainWindow) editPlaceDialog.set_icon_from_file("/usr/lib/linuxmint/mintMenu/icon.svg") editPlaceDialog.set_title(self.editPlaceDialogTitle) folderChooserDialog.set_title(self.folderChooserDialogTitle) editPlaceDialog.set_default_response(Gtk.ResponseType.OK) - editPlaceName = self.builder.get_object( "nameEntryBox" ) - editPlacePath = self.builder.get_object( "pathEntryBox" ) - folderButton = self.builder.get_object( "folderButton" ) + editPlaceName = self.builder.get_object("nameEntryBox") + editPlacePath = self.builder.get_object("pathEntryBox") + folderButton = self.builder.get_object("folderButton") treeselection = self.customplacestree.get_selection() - currentiter = (treeselection.get_selected())[1] + currentiter = treeselection.get_selected()[1] - if (currentiter != None): + if currentiter: initName = self.customplacestreemodel.get_value(currentiter, 0) initPath = self.customplacestreemodel.get_value(currentiter, 1) @@ -463,70 +456,69 @@ class mintMenuConfig( object ): editPlacePath.set_text(initPath) def chooseFolder(folderButton): currentPath = editPlacePath.get_text() - if (currentPath!=""): + if currentPath: folderChooserDialog.select_filename(currentPath) response = folderChooserDialog.run() folderChooserDialog.hide() - if (response == Gtk.ResponseType.OK): - editPlacePath.set_text( folderChooserDialog.get_filenames()[0] ) + if response == Gtk.ResponseType.OK: + editPlacePath.set_text(folderChooserDialog.get_filenames()[0]) folderButton.connect("clicked", chooseFolder) response = editPlaceDialog.run() editPlaceDialog.hide() - if (response == Gtk.ResponseType.OK): + if response == Gtk.ResponseType.OK: name = editPlaceName.get_text() path = editPlacePath.get_text() - if (name != "" and path != ""): + if name and path: self.customplacestreemodel.set_value(currentiter, 0, name) self.customplacestreemodel.set_value(currentiter, 1, path) def moveDown(self, downButton): treeselection = self.customplacestree.get_selection() - currentiter = (treeselection.get_selected())[1] + currentiter = treeselection.get_selected()[1] nextiter = self.customplacestreemodel.iter_next(currentiter) - if (nextiter != None): + if nextiter: self.customplacestreemodel.swap(currentiter, nextiter) return - def removePlace(self, removeButton): treeselection = self.customplacestree.get_selection() - currentiter = (treeselection.get_selected())[1] + currentiter = treeselection.get_selected()[1] - if (currentiter != None): + if currentiter: self.customplacestreemodel.remove(currentiter) return def togglePlacesHeightEnabled(self, toggle): - if (toggle.get_active() == True): + if toggle.get_active(): self.placesHeightButton.set_sensitive(True) else: self.placesHeightButton.set_sensitive(False) def toggleSystemHeightEnabled(self, toggle): - if (toggle.get_active() == True): + if toggle.get_active(): self.systemHeightButton.set_sensitive(True) else: self.systemHeightButton.set_sensitive(False) def updatePlacesGSettings(self, treemodel, path, iter = None, new_order = None): - # Do only if not partway though an append operation; Append = insert+change+change and each creates a signal - if ((iter == None) or (self.customplacestreemodel.get_value(iter, 1) != None)): + # Do only if not partway though an append operation; + # Append = insert+change+change and each creates a signal + if not iter or self.customplacestreemodel.get_value(iter, 1): treeiter = self.customplacestreemodel.get_iter_first() - customplacenames = [ ] - customplacepaths = [ ] - while( treeiter != None ): - customplacenames = customplacenames + [ self.customplacestreemodel.get_value(treeiter, 0 ) ] - customplacepaths = customplacepaths + [ self.customplacestreemodel.get_value(treeiter, 1 ) ] + customplacenames = [] + customplacepaths = [] + while treeiter: + customplacenames = customplacenames + [self.customplacestreemodel.get_value(treeiter, 0)] + customplacepaths = customplacepaths + [self.customplacestreemodel.get_value(treeiter, 1)] treeiter = self.customplacestreemodel.iter_next(treeiter) - self.settingsPlaces.set( "list-string", "custom-paths", customplacepaths) - self.settingsPlaces.set( "list-string", "custom-names", customplacenames) - + self.settingsPlaces.set("list-string", "custom-paths", customplacepaths) + self.settingsPlaces.set("list-string", "custom-names", customplacenames) window = mintMenuConfig() Gtk.main() diff --git a/usr/lib/linuxmint/mintMenu/plugins/applications.py b/usr/lib/linuxmint/mintMenu/plugins/applications.py index 766eade..b6cdb7f 100755 --- a/usr/lib/linuxmint/mintMenu/plugins/applications.py +++ b/usr/lib/linuxmint/mintMenu/plugins/applications.py @@ -1,30 +1,29 @@ #!/usr/bin/python2 -import commands +import cgi import filecmp import gettext import os -import pipes import string import subprocess import threading -import time -from user import home +import urllib import gi gi.require_version("Gtk", "3.0") -from gi.repository import Gtk, Pango, Gdk, Gio, GLib +from gi.repository import Gtk, Gdk, GdkPixbuf, Gio, GLib import matemenu import plugins.recentHelper as RecentHelper -from plugins.easybuttons import (CategoryButton, FavApplicationLauncher, +from plugins.easybuttons import (ApplicationLauncher, CategoryButton, + FavApplicationLauncher, MenuApplicationLauncher) from plugins.easygsettings import EasyGSettings from plugins.execute import Execute - # i18n gettext.install("mintmenu", "/usr/share/linuxmint/locale") +home = os.environ.get("HOME") class PackageDescriptor(): def __init__(self, name, summary, description): @@ -32,23 +31,24 @@ class PackageDescriptor(): self.summary = summary self.description = description -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 +# import time +# 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 # Helper function for retrieving the user's location for storing new or modified menu items def get_user_item_path(): item_dir = None - if os.environ.has_key('XDG_DATA_HOME'): + if 'XDG_DATA_HOME' in os.environ: item_dir = os.path.join(os.environ['XDG_DATA_HOME'], 'applications') else: - item_dir = os.path.join(os.environ['HOME'], '.local', 'share', 'applications') + item_dir = os.path.join(home, '.local/share/applications') if not os.path.isdir(item_dir): os.makedirs(item_dir) @@ -57,33 +57,32 @@ def get_user_item_path(): def get_system_item_paths(): item_dirs = [] - if os.environ.has_key('XDG_DATA_DIRS'): + if 'XDG_DATA_DIRS' in os.environ: item_dirs = os.environ['XDG_DATA_DIRS'].split(":") item_dirs.append(os.path.join('/usr', 'share')) return item_dirs def rel_path(target, base=os.curdir): - if not os.path.exists(target): - raise OSError, 'Target does not exist: '+target + raise OSError("Target does not exist: %s" % target) if not os.path.isdir(base): - raise OSError, 'Base is not a directory or does not exist: '+base + raise OSError("Base is not a directory or does not exist: %s" % base) base_list = (os.path.abspath(base)).split(os.sep) target_list = (os.path.abspath(target)).split(os.sep) for i in range(min(len(base_list), len(target_list))): - if base_list[i] <> target_list[i]: break + if base_list[i] != target_list[i]: + break else: i += 1 - rel_list = [os.pardir] * (len(base_list)-i) + target_list[i:] - + rel_list = [os.pardir] * (len(base_list) - i) + target_list[i:] return os.path.join(*rel_list) - class Menu: + def __init__(self, MenuToLookup): self.tree = matemenu.lookup_tree(MenuToLookup) self.directory = self.tree.get_root_directory() @@ -99,7 +98,9 @@ class Menu: def getItems(self, menu): for item in menu.get_contents(): - if item.get_type() == matemenu.TYPE_ENTRY and item.get_desktop_file_id()[-19:] != '-usercustom.desktop' and self.__isVisible(item): + if item.get_type() == matemenu.TYPE_ENTRY and \ + item.get_desktop_file_id()[-19:] != '-usercustom.desktop' and \ + self.__isVisible(item): yield item def __isVisible(self, item): @@ -108,36 +109,31 @@ class Menu: if item.get_type() == matemenu.TYPE_DIRECTORY and len(item.get_contents()): return True - - class SuggestionButton(Gtk.Button): def __init__(self, iconName, iconSize, label): Gtk.Button.__init__(self) - self.iconName = iconName self.set_relief(Gtk.ReliefStyle.NONE) self.set_size_request(-1, -1) Align1 = Gtk.Alignment() Align1.set(0, 0.5, 1.0, 0) HBox1 = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) labelBox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=2) - self.image = Gtk.Image() - self.image.set_from_icon_name(self.iconName, Gtk.IconSize.INVALID) - self.image.set_pixel_size(iconSize) - self.image.show() + if iconName.startswith("/"): + self.image = Gtk.Image.new_from_pixbuf(GdkPixbuf.Pixbuf.new_from_file_at_size(iconName, iconSize, iconSize)) + else: + self.image = Gtk.Image.new_from_icon_name(iconName, Gtk.IconSize.DIALOG) + self.image.set_pixel_size(iconSize) HBox1.pack_start(self.image, False, False, 5) self.label = Gtk.Label() - self.label.set_ellipsize(Pango.EllipsizeMode.END) + self.label.set_markup(label) + self.label.set_ellipsize(3) self.label.set_alignment(0.0, 1.0) - self.label.show() labelBox.pack_start(self.label, True, True, 2) - labelBox.show() HBox1.pack_start(labelBox, True, True, 2) - HBox1.show() Align1.add(HBox1) - Align1.show() self.add(Align1) - self.show() + self.show_all() def set_image(self, path): self.image.set_from_file(path) @@ -155,13 +151,11 @@ class pluginclass(object): toFav = (Gtk.TargetEntry.new("FAVORITES", Gtk.TargetFlags.SAME_APP, 81), Gtk.TargetEntry.new("text/plain", 0, 100), Gtk.TargetEntry.new("text/uri-list", 0, 101)) fromFav = (Gtk.TargetEntry.new("FAVORITES", Gtk.TargetFlags.SAME_APP, 81), Gtk.TargetEntry.new("FAVORITES", Gtk.TargetFlags.SAME_APP, 81)) - @print_timing + #@print_timing def __init__(self, mintMenuWin, toggleButton, de): self.mintMenuWin = mintMenuWin RecentHelper.mintMenuWin = mintMenuWin - self.mainMenus = [] - self.toggleButton = toggleButton self.de = de @@ -199,7 +193,7 @@ class pluginclass(object): # These properties are NECESSARY to maintain consistency # Set 'window' property for the plugin (Must be the root widget) - self.window =self.builder.get_object("mainWindow") + self.window = self.builder.get_object("mainWindow") # Set 'heading' property for plugin self.heading = ""#_("Applications") @@ -217,7 +211,6 @@ class pluginclass(object): self.keyPress_handler = self.mintMenuWin.window.connect("key-press-event", self.keyPress) self.favoritesBox.connect("drag-data-received", self.ReceiveCallback) - self.favoritesBox.drag_dest_set (Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT | Gtk.DestDefaults.DROP, self.toButton, Gdk.DragAction.COPY) self.showFavoritesButton.connect("drag-data-received", self.ReceiveCallback) self.showFavoritesButton.drag_dest_set (Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT | Gtk.DestDefaults.DROP, self.toButton, Gdk.DragAction.COPY) @@ -245,8 +238,8 @@ class pluginclass(object): self.settings.bindGSettingsEntryToVar("bool", "enable-internet-search", self, "enableInternetSearch") self.settings.bindGSettingsEntryToVar("string", "search-command", self, "searchtool") self.settings.bindGSettingsEntryToVar("int", "default-tab", self, "defaultTab") - except Exception, detail: - print detail + except Exception as e: + print(e) self.currentFavCol = 0 self.favorites = [] @@ -280,13 +273,15 @@ class pluginclass(object): self.builder.get_object("searchButton").connect("button-press-event", self.searchPopup) - self.icon_theme = Gtk.IconTheme.get_default() - self.icon_theme.connect("changed", self.on_icon_theme_changed) + # self.icon_theme = Gtk.IconTheme.get_default() + # self.icon_theme.connect("changed", self.on_icon_theme_changed) def refresh_apt_cache(self): if self.useAPT: - os.system("mkdir -p %s/.linuxmint/mintMenu/" % home) - os.system("/usr/lib/linuxmint/mintMenu/plugins/get_apt_cache.py > %s/.linuxmint/mintMenu/apt.cache &" % home) + path = "%s/.linuxmint/mintMenu" % home + if not os.path.exists(path): + os.makedirs(path) + subprocess.Popen(["/usr/lib/linuxmint/mintMenu/plugins/get_apt_cache.py", "%s/apt.cache" % path]) def get_panel(self): panelsettings = Gio.Settings.new("org.mate.panel") @@ -301,17 +296,19 @@ class pluginclass(object): self.panel_position = object_schema.get_int("position") + 1 def apturl_install(self, widget, pkg_name): - if os.path.exists("/usr/bin/apturl"): - os.system("/usr/bin/apturl apt://%s &" % pkg_name) - else: - os.system("xdg-open apt://" + pkg_name + " &") + subprocess.Popen(["xdg-open", "apt://%s" % pkg_name]) + # if os.path.exists("/usr/bin/apturl"): + # os.system("/usr/bin/apturl apt://%s &" % pkg_name) + # else: + # os.system("xdg-open apt://" + pkg_name + " &") self.mintMenuWin.hide() def __del__(self): - print u"Applications plugin deleted" + #print("Applications plugin deleted") + return def wake(self): - pass + return def destroy(self): self.content_holder.destroy() @@ -431,13 +428,22 @@ class pluginclass(object): self.GetGSettingsEntries() # if the config hasn't changed return - if oldcategories_mouse_over == self.categories_mouse_over and oldiconsize == self.iconSize and oldfaviconsize == self.faviconsize and oldswapgeneric == self.swapgeneric and oldshowcategoryicons == self.showcategoryicons and oldcategoryhoverdelay == self.categoryhoverdelay and oldsticky == self.sticky and oldminimized == self.minimized and oldicon == self.icon and oldhideseparator == self.hideseparator and oldshowapplicationcomments == self.showapplicationcomments: + if (oldcategories_mouse_over == self.categories_mouse_over and + oldiconsize == self.iconSize and + oldfaviconsize == self.faviconsize and + oldswapgeneric == self.swapgeneric and + oldshowcategoryicons == self.showcategoryicons and + oldcategoryhoverdelay == self.categoryhoverdelay and + oldsticky == self.sticky and + oldminimized == self.minimized and + oldicon == self.icon and + oldhideseparator == self.hideseparator and + oldshowapplicationcomments == self.showapplicationcomments + ): return self.Todos() self.buildFavorites() - # TODO all this runs whether the plugin is enabled or not - print "applications.RegenPlugin calling buildRecentApps" RecentHelper.buildRecentApps() self.RebuildPlugin() @@ -461,7 +467,6 @@ class pluginclass(object): self.lastActiveTab = self.settings.get("int", "last-active-tab") self.defaultTab = self.settings.get("int", "default-tab") - # Allow plugin to be minimized to the left plugin pane self.sticky = self.settings.get("bool", "sticky") self.minimized = self.settings.get("bool", "minimized") @@ -495,11 +500,10 @@ class pluginclass(object): return True except: pass - return False def onShowMenu(self): - if len(self.favorites): + if self.favorites: if self.defaultTab == -1: self.changeTab(self.lastActiveTab) else: @@ -523,7 +527,6 @@ class pluginclass(object): self.focusSearchEntry(clear) self.lastActiveTab = tabNum - def Todos(self): self.searchEntry.connect("popup-menu", self.blockOnPopup) self.searchEntry.connect("button-press-event", self.blockOnRightPress) @@ -557,9 +560,7 @@ class pluginclass(object): self.stopBuildingButtonList = True GLib.timeout_add(100, self.buildButtonList) return - self.stopBuildingButtonList = False - self.updateBoxes(False) def categoryBtnFocus(self, widget, event, category): @@ -577,60 +578,33 @@ class pluginclass(object): GLib.source_remove(self.filterTimer) self.filterTimer = None + def add_suggestion(self, icon=None, label=None, tooltip=None, callback=None, *args): + if icon: + item = SuggestionButton(icon, self.iconSize, label) + item.connect("clicked", callback, *args) + if tooltip: + item.set_tooltip_text(tooltip) + else: + item = Gtk.SeparatorMenuItem() + item.show_all() + self.applicationsBox.add(item) + self.suggestions.append(item) + def add_search_suggestions(self, text): - - text = "%s" % text - + text = "%s" % cgi.escape(text) if self.enableInternetSearch: - suggestionButton = SuggestionButton("list-add", self.iconSize, "") - suggestionButton.connect("clicked", self.search_ddg) - suggestionButton.set_text(_("Search DuckDuckGo for %s") % text) - suggestionButton.set_image("/usr/lib/linuxmint/mintMenu/search_engines/ddg.png") - self.applicationsBox.add(suggestionButton) - self.suggestions.append(suggestionButton) + self.add_suggestion("/usr/lib/linuxmint/mintMenu/search_engines/ddg.svg", _("Search DuckDuckGo for %s") % text, None, self.search_ddg) + self.add_suggestion("/usr/lib/linuxmint/mintMenu/search_engines/wikipedia.svg", _("Search Wikipedia for %s") % text, None, self.search_wikipedia) + self.add_suggestion() - suggestionButton = SuggestionButton("list-add", self.iconSize, "") - suggestionButton.connect("clicked", self.search_wikipedia) - suggestionButton.set_text(_("Search Wikipedia for %s") % text) - suggestionButton.set_image("/usr/lib/linuxmint/mintMenu/search_engines/wikipedia.png") - self.applicationsBox.add(suggestionButton) - self.suggestions.append(suggestionButton) + self.add_suggestion("accessories-dictionary", _("Lookup %s in Dictionary") % text, None, self.search_dictionary) + self.add_suggestion("edit-find", _("Search Computer for %s") % text, None, self.Search) - separator = Gtk.EventBox() - separator.add(Gtk.Separator(orientation=Gtk.Orientation.HORIZONTAL)) - separator.set_visible_window(False) - separator.set_size_request(-1, 20) - separator.type = "separator" - separator.show_all() - self.applicationsBox.add(separator) - self.suggestions.append(separator) - - suggestionButton = SuggestionButton("list-add", self.iconSize, "") - suggestionButton.connect("clicked", self.search_dictionary) - suggestionButton.set_text(_("Lookup %s in Dictionary") % text) - suggestionButton.set_image("/usr/lib/linuxmint/mintMenu/search_engines/dictionary.png") - self.applicationsBox.add(suggestionButton) - self.suggestions.append(suggestionButton) - - suggestionButton = SuggestionButton("edit-find", self.iconSize, "") - suggestionButton.connect("clicked", self.Search) - suggestionButton.set_text(_("Search Computer for %s") % text) - self.applicationsBox.add(suggestionButton) - self.suggestions.append(suggestionButton) - - #self.last_separator = Gtk.EventBox() - #self.last_separator.add(Gtk.Separator(orientation=Gtk.Orientation.HORIZONTAL)) - #self.last_separator.set_size_request(-1, 20) - #self.last_separator.type = "separator" - #self.mintMenuWin.SetPaneColors([ self.last_separator]) - #self.last_separator.show_all() - #self.applicationsBox.add(self.last_separator) - #self.suggestions.append(self.last_separator) + self.applicationsBox.get_children()[-1].grab_focus() def add_apt_filter_results(self, keyword): try: # Wait to see if the keyword has changed.. before doing anything - current_keyword = keyword current_keyword = self.searchEntry.get_text() if keyword != current_keyword: return @@ -638,18 +612,17 @@ class pluginclass(object): found_in_name = [] found_elsewhere = [] keywords = keyword.split(" ") - command = "cat %(home)s/.linuxmint/mintMenu/apt.cache" % {'home':home} - for word in keywords: - command = "%(command)s | grep %(word)s" % {'command':command, 'word':pipes.quote(word)} - pkgs = commands.getoutput(command) - pkgs = pkgs.split("\n") - num_pkg_found = 0 + path = os.path.join(home, ".linuxmint/mintMenu/apt.cache") + if not os.path.isfile(path): + return + with open(path) as aptcache: + pkgs = [line for line in aptcache.readlines() if all(keyword in line for keyword in keywords)] for pkg in pkgs: - values = string.split(pkg, "###") + values = pkg.split("###") if len(values) == 4: status = values[0] if status == "ERROR": - print "Could not refresh APT cache" + print("Could not refresh APT cache") elif status == "CACHE": name = values[1] summary = values[2] @@ -667,21 +640,12 @@ class pluginclass(object): found_in_name.append(package) else: found_elsewhere.append(package) - num_pkg_found+=1 else: - print "Invalid status code: " + status - + print("Invalid status code:",status) found_packages.extend(found_in_name) found_packages.extend(found_elsewhere) if keyword == self.searchEntry.get_text() and len(found_packages) > 0: - last_separator = Gtk.EventBox() - last_separator.add(Gtk.HSeparator()) - last_separator.set_visible_window(False) - last_separator.set_size_request(-1, 20) - last_separator.type = "separator" - last_separator.show_all() - self.applicationsBox.add(last_separator) - self.suggestions.append(last_separator) + self.add_suggestion() #Reduce the number of results to 10 max... it takes a HUGE amount of time to add the GTK box in the menu otherwise.. if len(found_packages) > 10: found_packages = found_packages[:10] @@ -690,13 +654,10 @@ class pluginclass(object): for word in keywords: if word != "": name = name.replace(word, "%s" % word) - 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, pkg.description)) - suggestionButton.set_icon_size(self.iconSize) - self.applicationsBox.add(suggestionButton) - self.suggestions.append(suggestionButton) + self.add_suggestion(Gtk.STOCK_ADD, + _("Install package '%s'") % name, + "%s\n\n%s\n\n%s" % (pkg.name, pkg.summary, pkg.description), + self.apturl_install, pkg.name) #if cache != self.current_results: # self.current_results.append(pkg) @@ -708,9 +669,8 @@ class pluginclass(object): # finally: # gtk.gdk.threads_leave() - except Exception, detail: - print detail - + except Exception as e: + print(e) def add_apt_filter_results_sync(self, cache, keyword): try: @@ -729,34 +689,24 @@ class pluginclass(object): found_packages.append(pkg) if len(found_packages) > 0: - last_separator = Gtk.EventBox() - last_separator.add(Gtk.HSeparator()) - last_separator.set_visible_window(False) - last_separator.set_size_request(-1, 20) - last_separator.type = "separator" - last_separator.show_all() - self.applicationsBox.add(last_separator) - self.suggestions.append(last_separator) + self.add_suggestion() for pkg in found_packages: name = pkg.name for word in keywords: if word != "": name = name.replace(word, "%s" % word) - 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.add_suggestion(Gtk.STOCK_ADD, + _("Install package '%s'") % name, + "%s\n\n%s\n\n%s" % (pkg.name, pkg.summary, pkg.description), + self.apturl_install, pkg.name) #if len(found_packages) == 0: # self.applicationsBox.remove(self.last_separator) # self.suggestions.remove(self.last_separator) - except Exception, detail: - print detail + except Exception as e: + print(e) def Filter(self, widget, category = None): self.filterTimer = None @@ -854,222 +804,171 @@ class pluginclass(object): return False def favPopup(self, widget, event): - if event.button == 3: - if event.y > widget.get_allocation().height / 2: - insertBefore = False - else: - insertBefore = True + if not event.button == 3: + return + if event.y > widget.get_allocation().height / 2: + insertBefore = False + else: + insertBefore = True - if widget.type == "location": - mTree = Gtk.Menu() - mTree.set_events(Gdk.EventMask.POINTER_MOTION_MASK | Gdk.EventMask.POINTER_MOTION_HINT_MASK | - Gdk.EventMask.BUTTON_PRESS_MASK | Gdk.EventMask.BUTTON_RELEASE_MASK) - #i18n - - desktopMenuItem = Gtk.MenuItem(_("Add to desktop")) - panelMenuItem = Gtk.MenuItem(_("Add to panel")) - separator1 = Gtk.SeparatorMenuItem() - insertSpaceMenuItem = Gtk.MenuItem(_("Insert space")) - insertSeparatorMenuItem = Gtk.MenuItem(_("Insert separator")) - separator2 = Gtk.SeparatorMenuItem() - startupMenuItem = Gtk.CheckMenuItem(_("Launch when I log in")) - separator3 = Gtk.SeparatorMenuItem() - launchMenuItem = Gtk.MenuItem(_("Launch")) - removeFromFavMenuItem = Gtk.MenuItem(_("Remove from favorites")) - separator4 = Gtk.SeparatorMenuItem() - propsMenuItem = Gtk.MenuItem(_("Edit properties")) - - desktopMenuItem.connect("activate", self.add_to_desktop, widget) - panelMenuItem.connect("activate", self.add_to_panel, widget) - insertSpaceMenuItem.connect("activate", self.onFavoritesInsertSpace, widget, insertBefore) - insertSeparatorMenuItem.connect("activate", self.onFavoritesInsertSeparator, widget, insertBefore) - if widget.isInStartup(): - startupMenuItem.set_active(True) - startupMenuItem.connect("toggled", self.onRemoveFromStartup, widget) - else: - startupMenuItem.set_active(False) - startupMenuItem.connect("toggled", self.onAddToStartup, widget) - launchMenuItem.connect("activate", self.onLaunchApp, widget) - removeFromFavMenuItem.connect("activate", self.onFavoritesRemove, widget) - propsMenuItem.connect("activate", self.onPropsApp, widget) - - if self.de == "mate": - mTree.append(desktopMenuItem) - mTree.append(panelMenuItem) - mTree.append(separator1) - mTree.append(insertSpaceMenuItem) - mTree.append(insertSeparatorMenuItem) - mTree.append(separator2) - mTree.append(startupMenuItem) - mTree.append(separator3) - mTree.append(launchMenuItem) - mTree.append(removeFromFavMenuItem) - mTree.append(separator4) - mTree.append(propsMenuItem) - - mTree.show_all() - self.mintMenuWin.stopHiding() - mTree.attach_to_widget(widget, None) - mTree.popup(None, None, None, None, event.button, event.time) - else: - mTree = Gtk.Menu() - mTree.set_events(Gdk.EventMask.POINTER_MOTION_MASK | Gdk.EventMask.POINTER_MOTION_HINT_MASK | - Gdk.EventMask.BUTTON_PRESS_MASK | Gdk.EventMask.BUTTON_RELEASE_MASK) - - #i18n - removeMenuItem = Gtk.MenuItem(_("Remove")) - insertSpaceMenuItem = Gtk.MenuItem(_("Insert space")) - insertSeparatorMenuItem = Gtk.MenuItem(_("Insert separator")) - mTree.append(removeMenuItem) - mTree.append(insertSpaceMenuItem) - mTree.append(insertSeparatorMenuItem) - mTree.show_all() - - removeMenuItem.connect("activate", self.onFavoritesRemove, widget) - insertSpaceMenuItem.connect("activate", self.onFavoritesInsertSpace, widget, insertBefore) - insertSeparatorMenuItem.connect("activate", self.onFavoritesInsertSeparator, widget, insertBefore) - self.mintMenuWin.stopHiding() - mTree.attach_to_widget(widget, None) - mTree.popup(None, None, None, None, event.button, event.time) - - def menuPopup(self, widget, event): - if event.button == 3: + if widget.type == "location": mTree = Gtk.Menu() + mTree.set_events(Gdk.EventMask.POINTER_MOTION_MASK | Gdk.EventMask.POINTER_MOTION_HINT_MASK | + Gdk.EventMask.BUTTON_PRESS_MASK | Gdk.EventMask.BUTTON_RELEASE_MASK) #i18n desktopMenuItem = Gtk.MenuItem(_("Add to desktop")) panelMenuItem = Gtk.MenuItem(_("Add to panel")) separator1 = Gtk.SeparatorMenuItem() - favoriteMenuItem = Gtk.CheckMenuItem(_("Show in my favorites")) - startupMenuItem = Gtk.CheckMenuItem(_("Launch when I log in")) + insertSpaceMenuItem = Gtk.MenuItem(_("Insert space")) + insertSeparatorMenuItem = Gtk.MenuItem(_("Insert separator")) separator2 = Gtk.SeparatorMenuItem() - launchMenuItem = Gtk.MenuItem(_("Launch")) - uninstallMenuItem = Gtk.MenuItem(_("Uninstall")) - deleteMenuItem = Gtk.MenuItem(_("Delete from menu")) + startupMenuItem = Gtk.CheckMenuItem(_("Launch when I log in")) separator3 = Gtk.SeparatorMenuItem() + launchMenuItem = Gtk.MenuItem(_("Launch")) + removeFromFavMenuItem = Gtk.MenuItem(_("Remove from favorites")) + separator4 = Gtk.SeparatorMenuItem() propsMenuItem = Gtk.MenuItem(_("Edit properties")) - if self.de == "mate": - mTree.append(desktopMenuItem) - mTree.append(panelMenuItem) - mTree.append(separator1) - - mTree.append(favoriteMenuItem) - mTree.append(startupMenuItem) - - mTree.append(separator2) - - mTree.append(launchMenuItem) - mTree.append(uninstallMenuItem) - if home in widget.desktopFile: - mTree.append(deleteMenuItem) - deleteMenuItem.connect("activate", self.delete_from_menu, widget) - - mTree.append(separator3) - - mTree.append(propsMenuItem) - - mTree.show_all() - desktopMenuItem.connect("activate", self.add_to_desktop, widget) panelMenuItem.connect("activate", self.add_to_panel, widget) - - launchMenuItem.connect("activate", self.onLaunchApp, widget) - propsMenuItem.connect("activate", self.onPropsApp, widget) - uninstallMenuItem.connect("activate", self.onUninstallApp, widget) - - if self.isLocationInFavorites(widget.desktopFile): - favoriteMenuItem.set_active(True) - favoriteMenuItem.connect("toggled", self.onRemoveFromFavorites, widget) - else: - favoriteMenuItem.set_active(False) - favoriteMenuItem.connect("toggled", self.onAddToFavorites, widget) - + insertSpaceMenuItem.connect("activate", self.onFavoritesInsertSpace, widget, insertBefore) + insertSeparatorMenuItem.connect("activate", self.onFavoritesInsertSeparator, widget, insertBefore) if widget.isInStartup(): startupMenuItem.set_active(True) startupMenuItem.connect("toggled", self.onRemoveFromStartup, widget) else: startupMenuItem.set_active(False) startupMenuItem.connect("toggled", self.onAddToStartup, widget) + launchMenuItem.connect("activate", self.onLaunchApp, widget) + removeFromFavMenuItem.connect("activate", self.onFavoritesRemove, widget) + propsMenuItem.connect("activate", self.onPropsApp, widget) - self.mintMenuWin.stopHiding() - mTree.attach_to_widget(widget, None) + if self.de == "mate": + mTree.append(desktopMenuItem) + mTree.append(panelMenuItem) + mTree.append(separator1) + mTree.append(insertSpaceMenuItem) + mTree.append(insertSeparatorMenuItem) + mTree.append(separator2) + mTree.append(startupMenuItem) + mTree.append(separator3) + mTree.append(launchMenuItem) + mTree.append(removeFromFavMenuItem) + mTree.append(separator4) + mTree.append(propsMenuItem) + else: + mTree = Gtk.Menu() + mTree.set_events(Gdk.EventMask.POINTER_MOTION_MASK | Gdk.EventMask.POINTER_MOTION_HINT_MASK | + Gdk.EventMask.BUTTON_PRESS_MASK | Gdk.EventMask.BUTTON_RELEASE_MASK) + + #i18n + removeMenuItem = Gtk.MenuItem(_("Remove")) + insertSpaceMenuItem = Gtk.MenuItem(_("Insert space")) + insertSeparatorMenuItem = Gtk.MenuItem(_("Insert separator")) + mTree.append(removeMenuItem) + mTree.append(insertSpaceMenuItem) + mTree.append(insertSeparatorMenuItem) + + removeMenuItem.connect("activate", self.onFavoritesRemove, widget) + insertSpaceMenuItem.connect("activate", self.onFavoritesInsertSpace, widget, insertBefore) + insertSeparatorMenuItem.connect("activate", self.onFavoritesInsertSeparator, widget, insertBefore) + mTree.show_all() + self.mintMenuWin.stopHiding() + mTree.attach_to_widget(widget, None) + if (Gtk.MAJOR_VERSION, Gtk.MINOR_VERSION) >= (3, 22): + mTree.popup_at_pointer(event) + else: mTree.popup(None, None, None, None, event.button, event.time) + def menuPopup(self, widget, event): + if not event.button == 3: + return + mTree = Gtk.Menu() + #i18n + desktopMenuItem = Gtk.MenuItem(_("Add to desktop")) + panelMenuItem = Gtk.MenuItem(_("Add to panel")) + separator1 = Gtk.SeparatorMenuItem() + favoriteMenuItem = Gtk.CheckMenuItem(_("Show in my favorites")) + startupMenuItem = Gtk.CheckMenuItem(_("Launch when I log in")) + separator2 = Gtk.SeparatorMenuItem() + launchMenuItem = Gtk.MenuItem(_("Launch")) + uninstallMenuItem = Gtk.MenuItem(_("Uninstall")) + deleteMenuItem = Gtk.MenuItem(_("Delete from menu")) + separator3 = Gtk.SeparatorMenuItem() + propsMenuItem = Gtk.MenuItem(_("Edit properties")) + + if self.de == "mate": + mTree.append(desktopMenuItem) + mTree.append(panelMenuItem) + mTree.append(separator1) + + mTree.append(favoriteMenuItem) + mTree.append(startupMenuItem) + mTree.append(separator2) + mTree.append(launchMenuItem) + mTree.append(uninstallMenuItem) + if home in widget.desktopFile: + mTree.append(deleteMenuItem) + deleteMenuItem.connect("activate", self.delete_from_menu, widget) + mTree.append(separator3) + mTree.append(propsMenuItem) + mTree.show_all() + + desktopMenuItem.connect("activate", self.add_to_desktop, widget) + panelMenuItem.connect("activate", self.add_to_panel, widget) + launchMenuItem.connect("activate", self.onLaunchApp, widget) + propsMenuItem.connect("activate", self.onPropsApp, widget) + uninstallMenuItem.connect("activate", self.onUninstallApp, widget) + + if self.isLocationInFavorites(widget.desktopFile): + favoriteMenuItem.set_active(True) + favoriteMenuItem.connect("toggled", self.onRemoveFromFavorites, widget) + else: + favoriteMenuItem.set_active(False) + favoriteMenuItem.connect("toggled", self.onAddToFavorites, widget) + + if widget.isInStartup(): + startupMenuItem.set_active(True) + startupMenuItem.connect("toggled", self.onRemoveFromStartup, widget) + else: + startupMenuItem.set_active(False) + startupMenuItem.connect("toggled", self.onAddToStartup, widget) + + self.mintMenuWin.stopHiding() + mTree.attach_to_widget(widget, None) + mTree.popup(None, None, None, None, event.button, event.time) + + def searchPopup(self, widget, event): + def add_menu_item(icon=None, text=None, callback=None): + box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) + if icon == None: + menuItem = Gtk.SeparatorMenuItem() + else: + if icon.startswith("/"): + icon = Gtk.Image.new_from_pixbuf(GdkPixbuf.Pixbuf.new_from_file_at_size(icon, 16, 16)) + else: + icon = Gtk.Image.new_from_icon_name(icon, Gtk.IconSize.SMALL_TOOLBAR) + box.add(icon) + box.pack_start(Gtk.Label.new(text), False, False, 5) + menuItem = Gtk.MenuItem() + menuItem.connect("activate", callback) + menuItem.add(box) + menu.append(menuItem) - def searchPopup(self, widget=None, event=None): menu = Gtk.Menu() if self.enableInternetSearch: + add_menu_item('/usr/lib/linuxmint/mintMenu/search_engines/ddg.svg', _("Search DuckDuckGo"), self.search_ddg) + add_menu_item('/usr/lib/linuxmint/mintMenu/search_engines/wikipedia.svg', _("Search Wikipedia"), self.search_wikipedia) - menuItem = Gtk.ImageMenuItem(_("Search DuckDuckGo")) - img = Gtk.Image() - img.set_from_file('/usr/lib/linuxmint/mintMenu/search_engines/ddg.png') - menuItem.set_image(img) - menuItem.connect("activate", self.search_ddg) - menu.append(menuItem) - - menuItem = Gtk.ImageMenuItem(_("Search Wikipedia")) - img = Gtk.Image() - img.set_from_file('/usr/lib/linuxmint/mintMenu/search_engines/wikipedia.png') - menuItem.set_image(img) - menuItem.connect("activate", self.search_wikipedia) - menu.append(menuItem) - - menuItem = Gtk.SeparatorMenuItem() - menu.append(menuItem) - - menuItem = Gtk.ImageMenuItem(_("Lookup Dictionary")) - img = Gtk.Image() - img.set_from_file('/usr/lib/linuxmint/mintMenu/search_engines/dictionary.png') - menuItem.set_image(img) - menuItem.connect("activate", self.search_dictionary) - menu.append(menuItem) - - menuItem = Gtk.ImageMenuItem(_("Search Computer")) - img = Gtk.Image() - img.set_from_icon_name("edit-find", Gtk.IconSize.INVALID) - img.set_pixel_size(self.iconSize) - menuItem.set_image(img) - menuItem.connect("activate", self.Search) - menu.append(menuItem) - - menuItem = Gtk.SeparatorMenuItem() - menu.append(menuItem) - - menuItem = Gtk.ImageMenuItem(_("Find Software")) - img = Gtk.Image() - img.set_from_file('/usr/lib/linuxmint/mintMenu/search_engines/software.png') - menuItem.set_image(img) - menuItem.connect("activate", self.search_mint_software) - menu.append(menuItem) - - menuItem = Gtk.ImageMenuItem(_("Find Tutorials")) - img = Gtk.Image() - img.set_from_file('/usr/lib/linuxmint/mintMenu/search_engines/tutorials.png') - menuItem.set_image(img) - menuItem.connect("activate", self.search_mint_tutorials) - menu.append(menuItem) - - menuItem = Gtk.ImageMenuItem(_("Find Hardware")) - img = Gtk.Image() - img.set_from_file('/usr/lib/linuxmint/mintMenu/search_engines/hardware.png') - menuItem.set_image(img) - menuItem.connect("activate", self.search_mint_hardware) - menu.append(menuItem) - - menuItem =Gtk.ImageMenuItem(_("Find Ideas")) - img = Gtk.Image() - img.set_from_file('/usr/lib/linuxmint/mintMenu/search_engines/ideas.png') - menuItem.set_image(img) - menuItem.connect("activate", self.search_mint_ideas) - menu.append(menuItem) - - menuItem = Gtk.ImageMenuItem(_("Find Users")) - img = Gtk.Image() - img.set_from_file('/usr/lib/linuxmint/mintMenu/search_engines/users.png') - menuItem.set_image(img) - menuItem.connect("activate", self.search_mint_users) - menu.append(menuItem) + add_menu_item('accessories-dictionary', _("Search Dictionary"), self.search_dictionary) + add_menu_item("edit-find", _("Search Computer"), self.Search) + add_menu_item() + add_menu_item('/usr/lib/linuxmint/mintMenu/search_engines/software.png', _("Find Software"), self.search_mint_software) + add_menu_item('/usr/lib/linuxmint/mintMenu/search_engines/tutorials.png', _("Find Tutorials"), self.search_mint_tutorials) + add_menu_item('/usr/lib/linuxmint/mintMenu/search_engines/hardware.png', _("Find Hardware"), self.search_mint_hardware) + add_menu_item('/usr/lib/linuxmint/mintMenu/search_engines/ideas.png', _("Find Ideas"), self.search_mint_ideas) + add_menu_item('/usr/lib/linuxmint/mintMenu/search_engines/users.png', _("Find Users"), self.search_mint_users) menu.show_all() @@ -1077,68 +976,55 @@ class pluginclass(object): menu.attach_to_widget(self.searchButton, None) menu.popup(None, None, None, None, event.button, event.time) - #menu.reposition() - #menu.reposition() - #self.mintMenuWin.grab() self.focusSearchEntry(clear = False) - return True - - # TODO: Is this in use? - # def pos_func(self, menu=None): - # rect = self.searchButton.get_allocation() - # x = rect.x + rect.width - # y = rect.y + rect.height - # return (x, y, False) def search_ddg(self, widget): - text = self.searchEntry.get_text() - text = text.replace(" ", "+") - os.system("xdg-open \"https://duckduckgo.com/?q=%s&t=lm&ia=web\" &" % text) + text = urllib.quote_plus(self.searchEntry.get_text().strip()) + subprocess.Popen(["xdg-open", "https://duckduckgo.com/?q=%s" % text]) + self.mintMenuWin.hide() + + def search_google(self, widget): + text = urllib.quote_plus(self.searchEntry.get_text().strip()) + subprocess.Popen(["xdg-open", "https://www.google.com/search?q=%s" % text]) self.mintMenuWin.hide() def search_wikipedia(self, widget): - text = self.searchEntry.get_text() - text = text.replace(" ", "+") - os.system("xdg-open \"https://%s.wikipedia.org/wiki/Special:Search?search=%s\" &" % (self.lang, text)) + text = urllib.quote_plus(self.searchEntry.get_text().strip()) + subprocess.Popen(["xdg-open", "https://en.wikipedia.org/wiki/Special:Search?search=%s" % text]) self.mintMenuWin.hide() def search_dictionary(self, widget): - text = self.searchEntry.get_text() - os.system("mate-dictionary \"" + text + "\" &") + text = self.searchEntry.get_text().strip() + subprocess.Popen(["mate-dictionary", "%s" % text]) self.mintMenuWin.hide() def search_mint_tutorials(self, widget): - text = self.searchEntry.get_text() - text = text.replace(" ", "%20") - os.system("xdg-open \"https://community.linuxmint.com/index.php/tutorial/search/0/" + text + "\" &") + text = urllib.quote(self.searchEntry.get_text().strip()) + subprocess.Popen(["xdg-open", "https://community.linuxmint.com/index.php/tutorial/search/0/%s" % text]) self.mintMenuWin.hide() def search_mint_ideas(self, widget): - text = self.searchEntry.get_text() - text = text.replace(" ", "%20") - os.system("xdg-open \"https://community.linuxmint.com/index.php/idea/search/0/" + text + "\" &") + text = urllib.quote(self.searchEntry.get_text().strip()) + subprocess.Popen(["xdg-open", "https://community.linuxmint.com/index.php/idea/search/0/%s" % text]) self.mintMenuWin.hide() def search_mint_users(self, widget): - text = self.searchEntry.get_text() - text = text.replace(" ", "%20") - os.system("xdg-open \"https://community.linuxmint.com/index.php/user/search/0/" + text + "\" &") + text = urllib.quote(self.searchEntry.get_text().strip()) + subprocess.Popen(["xdg-open", "https://community.linuxmint.com/index.php/user/search/0/%s" % text]) self.mintMenuWin.hide() def search_mint_hardware(self, widget): - text = self.searchEntry.get_text() - text = text.replace(" ", "%20") - os.system("xdg-open \"https://community.linuxmint.com/index.php/hardware/search/0/" + text + "\" &") + text = urllib.quote(self.searchEntry.get_text().strip()) + subprocess.Popen(["xdg-open", "https://community.linuxmint.com/index.php/hardware/search/0/%s" % text]) self.mintMenuWin.hide() def search_mint_software(self, widget): - text = self.searchEntry.get_text() - text = text.replace(" ", "%20") - os.system("xdg-open \"https://community.linuxmint.com/index.php/software/search/0/" + text + "\" &") + text = urllib.quote(self.searchEntry.get_text()) + subprocess.Popen(["xdg-open", "https://community.linuxmint.com/index.php/software/search/0/%s" % text]) self.mintMenuWin.hide() def add_to_desktop(self, widget, desktopEntry): - os.system("xdg-desktop-icon install --novendor %s" % desktopEntry.desktopFile) + subprocess.Popen(["xdg-desktop-icon", "install", "--novendor", desktopEntry.desktopFile]) def add_to_panel(self, widget, desktopEntry): self.get_panel() @@ -1164,22 +1050,20 @@ class pluginclass(object): def delete_from_menu(self, widget, desktopEntry): try: - os.system("rm \"%s\" &" % desktopEntry.desktopFile) - except Exception, detail: - print detail + os.unlink(desktopEntry.desktopFile) + except Exception as e: + print(e) def onLaunchApp(self, menu, widget): widget.execute() self.mintMenuWin.hide() def onPropsApp(self, menu, widget): - newFileFlag = False sysPaths = get_system_item_paths() for path in sysPaths: path = os.path.join(path, "applications") - relPath = os.path.relpath(widget.desktopFile, path) if widget.desktopFile == os.path.join(path, relPath): @@ -1205,23 +1089,18 @@ class pluginclass(object): subprocess.Popen.communicate(editProcess) if newFileFlag: - if filecmp.cmp(widget.desktopFile, filePath): os.remove(filePath) - else: favoriteChange = 0 - for favorite in self.favorites: if favorite.type == "location": if favorite.desktopFile == widget.desktopFile: favorite.desktopFile = filePath favoriteChange = 1 - if favoriteChange == 1: self.favoritesSave() self.buildFavorites() - else: self.buildFavorites() @@ -1280,9 +1159,6 @@ class pluginclass(object): def do_plugin(self): self.Todos() self.buildFavorites() - # TODO all this runs whether the plugin is enabled or not - # print "applications.do_plugin calling buildRecentApps" - # RecentHelper.buildRecentApps() # Scroll button into view def scrollItemIntoView(self, widget, event = None): @@ -1322,7 +1198,7 @@ class pluginclass(object): try: ButtonIcon = None # For Folders and Network Shares - location = string.join(location.split("%20")) + location = "".join(location.split("%20")) if location.startswith("file"): ButtonIcon = "mate-fs-directory" @@ -1330,6 +1206,7 @@ class pluginclass(object): if location.startswith("smb") or location.startswith("ssh") or location.startswith("network"): ButtonIcon = "mate-fs-network" + # TODO: Do we still need this? #For Special locations if location == "x-nautilus-desktop:///computer": location = "/usr/share/applications/nautilus-computer.desktop" @@ -1359,8 +1236,8 @@ class pluginclass(object): self.mintMenuWin.setTooltip(favButton, favButton.getTooltip()) favButton.type = "location" return favButton - except Exception, e: - print u"File in favorites not found: '" + location + "'", e + except Exception as e: + print("File in favorites not found: '%s': %s" % (location, e)) return None @@ -1371,7 +1248,7 @@ class pluginclass(object): os.system("mkdir -p " + path) os.system("cp /usr/lib/linuxmint/mintMenu/applications.list " + path) - applicationsList = open(path).readlines() # TODO py3 encoding="UTF-8" + applicationsList = open(path).readlines() self.favorites = [] @@ -1395,7 +1272,6 @@ class pluginclass(object): else: favButton = None - if favButton: favButton.position = position self.favorites.append(favButton) @@ -1407,8 +1283,8 @@ class pluginclass(object): position += 1 self.favoritesSave() - except Exception, e: - print e + except Exception as e: + print(e) def favoritesPositionOnGrid(self, favorite): row = 0 @@ -1423,7 +1299,6 @@ class pluginclass(object): if fav.type == "separator" or fav.type == "space": row += 1 col = 0 - if col >= self.favCols: row += 1 col = 0 @@ -1497,7 +1372,7 @@ class pluginclass(object): appListFile.write("location:" + favorite.desktopFile + "\n") else: appListFile.write(favorite.type + "\n") - except Exception, e: + except Exception as e: msgDlg = Gtk.MessageDialog(None, Gtk.DialogFlags.MODAL, Gtk.MessageType.ERROR, Gtk.ButtonsType.OK, _("Couldn't save favorites. Check if you have write access to ~/.linuxmint/mintMenu")+"\n(" + e.__str__() + ")") msgDlg.run() @@ -1507,33 +1382,33 @@ class pluginclass(object): for fav in self.favorites: if fav.type == "location" and fav.desktopFile == location: return True - return False def on_drag_data_get(self, widget, context, selection, info, time): if info == self.TARGET_TYPE_FAV: self.drag_origin = widget.position + # FIXME: This fails in python3: selection.set(selection.get_target(), 8, str(widget.position)) def on_drag_data_received(self, widget, context, x, y, selection, info, time): if info == self.TARGET_TYPE_FAV: self.favoritesReorder(int(selection.get_data()), widget.position) - def on_icon_theme_changed(self, theme): - print "on_icon_theme_changed" - self.menuChanged(0, 0) + # def on_icon_theme_changed(self, theme): + # print("on_icon_theme_changed") + # self.menuChanged(0, 0) def menuChanged(self, x, y): - print("menuChanged") + # print("menuChanged") # wait 1s, to avoid building the menu multiple times concurrently if self.menuChangedTimer: GLib.source_remove(self.menuChangedTimer) self.menuChangedTimer = GLib.timeout_add(1000, self.updateBoxes, True) - @print_timing + #@print_timing def updateBoxes(self, menu_has_changed): - print("updateBoxes") + # print("updateBoxes") # FIXME: This is really bad! if self.rebuildLock: return @@ -1583,8 +1458,8 @@ class pluginclass(object): self.categoryList.remove(item) button.destroy() del item - except Exception, e: - print e + except Exception as e: + print(e) if addedCategories: sortedCategoryList = [] @@ -1592,10 +1467,10 @@ class pluginclass(object): try: self.categoriesBox.remove(item["button"]) sortedCategoryList.append((str(item["index"]) + item["name"], item["button"])) - except Exception, e: - print e + except Exception as e: + print(e) - # Create new category buttons and add the to the list + # Create new category buttons and add them to the list for item in addedCategories: try: item["button"] = CategoryButton(item["icon"], categoryIconSize, [item["name"]], item["filter"]) @@ -1614,16 +1489,16 @@ class pluginclass(object): self.categoryList.append(item) sortedCategoryList.append((str(item["index"]) + item["name"], item["button"])) - except Exception, e: - print e + except Exception as e: + print(e) sortedCategoryList.sort() for item in sortedCategoryList: try: self.categoriesBox.pack_start(item[1], False, False, 0) - except Exception, e: - print e + except Exception as e: + print(e) # Find added and removed applications add update the application list newApplicationList = self.buildApplicationList() @@ -1693,8 +1568,8 @@ class pluginclass(object): button.hide() else: launcherNames.append(launcherName) - except Exception, e: - print e + except Exception as e: + print(e) self.rebuildLock = False @@ -1721,7 +1596,6 @@ class pluginclass(object): # Build a list containing the DesktopEntry object and the category of each application in the menu def buildApplicationList(self): - newApplicationsList = [] def find_applications_recursively(app_list, directory, catName): diff --git a/usr/lib/linuxmint/mintMenu/plugins/easybuttons.py b/usr/lib/linuxmint/mintMenu/plugins/easybuttons.py index fbc864c..da78e8a 100755 --- a/usr/lib/linuxmint/mintMenu/plugins/easybuttons.py +++ b/usr/lib/linuxmint/mintMenu/plugins/easybuttons.py @@ -7,10 +7,9 @@ import xdg.DesktopEntry import xdg.Menu import gi -gi.require_version('MateDesktop', '2.0') -from gi.repository import Gtk, Gdk, GLib -from gi.repository import Pango -from gi.repository import GObject +gi.require_version("Gtk", "3.0") +gi.require_version("MateDesktop", "2.0") +from gi.repository import Gtk, Gdk, GdkPixbuf, GLib, GObject, Pango, MateDesktop from plugins.execute import Execute from plugins.filemonitor import monitor as filemonitor @@ -37,7 +36,7 @@ class IconManager(GObject.GObject): #self.themes = map( createTheme, [d for d in os.listdir("/usr/share/icons") if os.path.isdir(os.path.join("/usr/share/icons", d))]) self.defaultTheme = Gtk.IconTheme.get_default() - defaultKdeTheme = createTheme("kde.default") + #defaultKdeTheme = createTheme("kde.default") # Setup and clean up the temp icon dir configDir = GLib.get_user_config_dir() @@ -49,19 +48,17 @@ class IconManager(GObject.GObject): os.remove(os.path.join(self.iconDir, fn)) self.defaultTheme.append_search_path(self.iconDir) - # Themes with the same content as the default them aren't needed #self.themes = [theme for theme in self.themes if theme.list_icons() != defaultTheme.list_icons()] - self.themes = [self.defaultTheme, defaultKdeTheme] + #self.themes = [self.defaultTheme, defaultKdeTheme] + self.themes = [self.defaultTheme] # Listen for changes in the themes - for theme in self.themes: - theme.connect("changed", self.themeChanged) - + # for theme in self.themes: + # theme.connect("changed", self.themeChanged) def getIcon(self, iconName, iconSize): - if not iconName: return None @@ -89,22 +86,12 @@ class IconManager(GObject.GObject): shutil.copyfile(iconFileName, os.path.join(self.iconDir, tmpIconName)) self.defaultTheme.append_search_path(self.iconDir) - image = Gtk.Image() - icon_found = False - for theme in self.themes: - if theme.lookup_icon(realIconName, 0, Gtk.IconLookupFlags.FORCE_REGULAR): - icon_found = True - break - - if icon_found: - image.set_from_icon_name(realIconName, Gtk.IconSize.DND) - image.set_pixel_size(iconSize) - else: - image = None - + image = Gtk.Image.new_from_icon_name(realIconName, Gtk.IconSize.DND) + image.set_pixel_size(iconSize) return image - except Exception, e: - print "Exception " + e.__class__.__name__ + ": " + e.message + + except Exception as e: + print("Exception %s: %s" % (e.__class__.__name__, e)) return None def themeChanged(self, theme): @@ -128,14 +115,11 @@ class easyButton(Gtk.Button): HBox1 = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) self.labelBox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=2) + self.buttonImage = self.getIcon(self.iconSize) + if not self.buttonImage: + self.buttonImage = Gtk.Image() + self.buttonImage.set_size_request(self.iconSize, self.iconSize) - self.buttonImage = Gtk.Image() - icon = self.getIcon(self.iconSize) - if icon: - self.buttonImage = icon - else: - #[iW, iH] = iconManager.getIconSize(self.iconSize) - self.buttonImage.set_size_request(self.iconSize, self.iconSize ) self.image_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) self.image_box.pack_start(self.buttonImage, False, False, 5) self.image_box.show_all() @@ -158,7 +142,7 @@ class easyButton(Gtk.Button): self.connectSelf("destroy", self.onDestroy) self.connect("released", self.onRelease) # Reload icons when the theme changed - self.themeChangedHandlerId = iconManager.connect("changed", self.themeChanged) + # self.themeChangedHandlerId = iconManager.connect("changed", self.themeChanged) def connectSelf(self, event, callback): self.connections.append(self.connect(event, callback)) @@ -168,12 +152,11 @@ class easyButton(Gtk.Button): def onDestroy(self, widget): self.buttonImage.clear() - iconManager.disconnect(self.themeChangedHandlerId) + # iconManager.disconnect(self.themeChangedHandlerId) for connection in self.connections: self.disconnect(connection) del self.connections - def addLabel(self, text, styles = None): label = Gtk.Label() if "" in text or "%s' % appName) - self.addLabel('%s' % appComment) + self.addLabel('%s\n%s' % + (appName, appComment)) else: - self.addLabel(appName) - self.addLabel('%s' % appComment) + self.addLabel('%s\n%s' % + (appName, appComment)) else: self.addLabel(appName) @@ -548,12 +518,10 @@ class FavApplicationLauncher(ApplicationLauncher): self.setupLabels() - class CategoryButton(easyButton): def __init__(self, iconName, iconSize, labels , f): easyButton.__init__(self, iconName, iconSize, labels) self.filter = f - iconManager = IconManager() diff --git a/usr/lib/linuxmint/mintMenu/plugins/execute.py b/usr/lib/linuxmint/mintMenu/plugins/execute.py index 1b8a3ea..7835f2e 100755 --- a/usr/lib/linuxmint/mintMenu/plugins/execute.py +++ b/usr/lib/linuxmint/mintMenu/plugins/execute.py @@ -37,6 +37,6 @@ def Execute(cmd , commandCwd=None, desktopFile=None): os.chdir(cwd) os.system(cmd + " &") return True - except Exception as err: - print err + except Exception as e: + print(e) return False diff --git a/usr/lib/linuxmint/mintMenu/plugins/filemonitor.py b/usr/lib/linuxmint/mintMenu/plugins/filemonitor.py index 06e6817..482d170 100755 --- a/usr/lib/linuxmint/mintMenu/plugins/filemonitor.py +++ b/usr/lib/linuxmint/mintMenu/plugins/filemonitor.py @@ -32,7 +32,7 @@ if hasInotify: mId = self.wm.add_watch(filename, mask, rec = True)[filename] if mId >= 0: self.callbacks[mId] = (callback, args) - except Exception, detail: + except: mId = 0 return mId @@ -43,7 +43,7 @@ if hasInotify: def fileChanged(self, event): if event.wd in self.callbacks: - # print event.path + #print event.path callback = self.callbacks[event.wd] if callback[1]: GLib.idle_add(callback[0], callback[1]) diff --git a/usr/lib/linuxmint/mintMenu/plugins/get_apt_cache.py b/usr/lib/linuxmint/mintMenu/plugins/get_apt_cache.py index 6ef3c99..50c6a78 100755 --- a/usr/lib/linuxmint/mintMenu/plugins/get_apt_cache.py +++ b/usr/lib/linuxmint/mintMenu/plugins/get_apt_cache.py @@ -1,16 +1,27 @@ #!/usr/bin/python2 -import apt, sys +import sys -try: - cache = apt.Cache() - for pkg in cache: - if not pkg.is_installed: - name = pkg.name - summary = pkg.candidate.summary.capitalize() - description = pkg.candidate.description.replace("\n", "~~~") - print "CACHE" + "###" + str(name) + "###" + str(summary) + "###" + str(description) -except Exception, detail: - print "ERROR###ERROR###ERROR###ERROR" - print detail +import apt_pkg + +if len(sys.argv) != 2: + sys.exit(1) +try: + apt_pkg.init() + cache = apt_pkg.Cache() + package_records = apt_pkg.PackageRecords(cache) + known_packages = set() + with open(sys.argv[1], "w") as f: + for pkg in cache.packages: + if pkg.selected_state or not pkg.version_list or pkg.name in known_packages: + continue + name = pkg.name + package_records.lookup(pkg.version_list.pop(0).translated_description.file_list.pop(0)) + summary = package_records.short_desc + description = package_records.long_desc.replace(summary + "\n ", "").replace("\n .\n ", "~~~").replace("\n", "") + f.write("CACHE###%s###%s###%s\n" % (name, summary, description)) + known_packages.add(name) +except Exception as e: + print("ERROR###ERROR###ERROR###ERROR") + print(e) sys.exit(1) diff --git a/usr/lib/linuxmint/mintMenu/plugins/places.py b/usr/lib/linuxmint/mintMenu/plugins/places.py index 4bb8d94..36be7ff 100755 --- a/usr/lib/linuxmint/mintMenu/plugins/places.py +++ b/usr/lib/linuxmint/mintMenu/plugins/places.py @@ -1,11 +1,10 @@ #!/usr/bin/python2 -from glob import glob import gettext import os import string +from glob import glob from urllib import unquote -from user import home import gi gi.require_version("Gtk", "3.0") @@ -18,6 +17,7 @@ from plugins.execute import Execute # i18n gettext.install("mintmenu", "/usr/share/linuxmint/locale") +home = os.environ.get("HOME") class pluginclass(object): @@ -173,8 +173,8 @@ class pluginclass(object): tmpdesktopDir = config['XDG_DESKTOP_DIR'] if os.path.exists(os.path.expandvars(tmpdesktopDir)): desktopDir = tmpdesktopDir - except Exception, detail: - print detail + except Exception as e: + print(e) Button4 = easyButton("desktop", self.iconsize, [_("Desktop")], -1, -1) Button4.connect("clicked", self.ButtonClicked, "xdg-open \"" + desktopDir + "\"") Button4.show() diff --git a/usr/lib/linuxmint/mintMenu/plugins/recent.py b/usr/lib/linuxmint/mintMenu/plugins/recent.py index 6141702..b585ee3 100755 --- a/usr/lib/linuxmint/mintMenu/plugins/recent.py +++ b/usr/lib/linuxmint/mintMenu/plugins/recent.py @@ -1,14 +1,15 @@ #!/usr/bin/python2 import os +import subprocess import gi gi.require_version("Gtk", "3.0") -from gi.repository import Gtk, Pango +from gi.repository import Gtk -from plugins.execute import Execute import plugins.recentHelper as RecentHelper from plugins.easygsettings import EasyGSettings +from plugins.execute import Execute class pluginclass: @@ -70,7 +71,7 @@ class pluginclass: self.builder.get_object("ClrBtn").connect("clicked", self.clrmenu) def wake(self): - pass + return def destroy(self): self.recentBox.destroy() @@ -111,8 +112,6 @@ class pluginclass: def RebuildPlugin(self): self.content_holder.set_size_request(self.recentw, self.recenth) - # TODO - print "recent.RebuildPlugin calling recent.DoRecent" self.DoRecent() def DoRecent(self, *args, **kargs): @@ -135,18 +134,13 @@ class pluginclass: self.AddRecentBtn(Name, self.IconList[loc]) loc = loc + 1 - # TODO - print "recent.DoRecent calling RecentHelper.doRecentApps" RecentHelper.doRecentApps() return True def clrmenu(self, *args, **kargs): self.RecManagerInstance.purge_items() - # TODO - print "recent.clrmenu calling recent.DoRecent" self.DoRecent() - return def AddRecentBtn(self, Name, RecentImage): DispName=os.path.basename(Name) @@ -166,7 +160,7 @@ class pluginclass: Box1.add(ButtonIcon) Label1 = Gtk.Label(DispName) - Label1.set_ellipsize(Pango.EllipsizeMode.END) + Label1.set_ellipsize(3) Box1.add(Label1) AButton.add(Box1) @@ -174,27 +168,22 @@ class pluginclass: self.recentBox.pack_start(AButton, False, True, 0) - def callback(self, widget, filename=None): + def callback(self, widget, filename): self.Win.hide() - x = os.system("gvfs-open \""+filename+"\"") - if x == 256: - dia = Gtk.Dialog('File not found!', - None, #the toplevel wgt of your app - Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT, #binary flags or'ed together - ("Ok", 77)) - dia.vbox.pack_start(Gtk.Label('The location or file could not be found!'), False, False, 0) - dia.vbox.show_all() - dia.show() - result = dia.run() - if result == 77: - dia.destroy() + try: + subprocess.check_call(["xdg-open", filename]) + except subprocess.CalledProcessError: + dialog = Gtk.MessageDialog(self.window, Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT, + Gtk.MessageType.ERROR, Gtk.ButtonsType.OK, _("The file or location could not be opened.")) + dialog.set_title("mintMenu") + dialog.run() + dialog.destroy() def GetRecent(self, *args, **kargs): FileString=[] IconString=[] RecentInfo=self.RecManagerInstance.get_items() - # print RecentInfo[0].get_icon(Gtk.IconSize.MENU) count=0 MaxEntries=self.numentries if self.numentries == -1: @@ -205,7 +194,7 @@ class pluginclass: count+=1 if count >= MaxEntries: break - return FileString, IconString + return FileString, IconString def ButtonClicked(self, widget, event, Exec): self.press_x = event.x @@ -225,7 +214,6 @@ class pluginclass: self.Win.plugins["applications"].wTree.get_widget("entry1").grab_focus() Execute(w, self.Exec) - # TODO - skipping this because we're already doing this on __init__ - # def do_plugin(self): - # print "recent.do_plugin calling recent.DoRecent" - # self.DoRecent() + def do_plugin(self): + return + # self.DoRecent() diff --git a/usr/lib/linuxmint/mintMenu/plugins/recentHelper.py b/usr/lib/linuxmint/mintMenu/plugins/recentHelper.py index 5d61a56..30bf6ff 100644 --- a/usr/lib/linuxmint/mintMenu/plugins/recentHelper.py +++ b/usr/lib/linuxmint/mintMenu/plugins/recentHelper.py @@ -1,7 +1,6 @@ #!/usr/bin/python2 import os -from user import home import gi gi.require_version("Gtk", "3.0") @@ -9,7 +8,7 @@ from gi.repository import Gtk from plugins.easybuttons import ApplicationLauncher - +home = os.environ.get("HOME") recentApps = [] mintMenuWin = None recentAppBox = None @@ -35,8 +34,8 @@ def recentAppsSave(): else: recentAppListFile.write(recentApp.type + "\n") - except Exception, e: - print e + except Exception as e: + print(e) msgDlg = Gtk.MessageDialog(None, Gtk.DialogFlags.MODAL, Gtk.MessageType.ERROR, Gtk.ButtonsType.OK, _("Couldn't save recent apps. Check if you have write access to ~/.linuxmint/mintMenu")+"\n(" + e.__str__() + ")") msgDlg.run() @@ -74,18 +73,16 @@ def recentAppBuildLauncher(location): appButton.connect("clicked", applicationButtonClicked) appButton.type = "location" return appButton - except Exception, e: - print u"File in recentapp not found: '" + location + "'", e + except Exception as e: + print("File in recentapp not found: '%s': %s" % (location, e)) return None def buildRecentApps(): - print "-- recentHelper.buildRecentApps" del recentApps[:] try: path = os.path.join(home, ".linuxmint/mintMenu/recentApplications.list") if not os.path.exists(path): - print "does not exist" recentApplicationsList = [] else: recentApplicationsList = open(path).readlines() @@ -103,12 +100,11 @@ def buildRecentApps(): if appButton: recentApps.append(appButton) - except Exception, e: - print e + except Exception as e: + print(e) return recentApps def doRecentApps(): - print "-- recentHelper.doRecentApps" if recentAppBox is not None: # recentAppBox is initiated by the recent plugin # only build UI widgets if it's enabled diff --git a/usr/lib/linuxmint/mintMenu/plugins/system_management.py b/usr/lib/linuxmint/mintMenu/plugins/system_management.py index e47edaa..4f90615 100755 --- a/usr/lib/linuxmint/mintMenu/plugins/system_management.py +++ b/usr/lib/linuxmint/mintMenu/plugins/system_management.py @@ -66,7 +66,7 @@ class pluginclass(object): def destroy(self): self.settings.notifyRemoveAll() - def wake(self) : + def wake(self): pass def changePluginSize(self, settings, key, args): diff --git a/usr/lib/linuxmint/mintMenu/pointerMonitor.py b/usr/lib/linuxmint/mintMenu/pointerMonitor.py index 2ee8ce0..f9da7a8 100644 --- a/usr/lib/linuxmint/mintMenu/pointerMonitor.py +++ b/usr/lib/linuxmint/mintMenu/pointerMonitor.py @@ -66,7 +66,7 @@ class PointerMonitor(GObject.GObject, threading.Thread): else: self.display.allow_events(X.ReplayPointer, X.CurrentTime) except Exception as e: - print "Unexpected error: " + str(e) + print("Unexpected error:", e) def stop(self): self.running = False diff --git a/usr/lib/linuxmint/mintMenu/search_engines/ddg.png b/usr/lib/linuxmint/mintMenu/search_engines/ddg.png deleted file mode 100644 index 7cdf03d..0000000 Binary files a/usr/lib/linuxmint/mintMenu/search_engines/ddg.png and /dev/null differ diff --git a/usr/lib/linuxmint/mintMenu/search_engines/ddg.svg b/usr/lib/linuxmint/mintMenu/search_engines/ddg.svg new file mode 100644 index 0000000..30a428d --- /dev/null +++ b/usr/lib/linuxmint/mintMenu/search_engines/ddg.svg @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/usr/lib/linuxmint/mintMenu/search_engines/dictionary.png b/usr/lib/linuxmint/mintMenu/search_engines/dictionary.png deleted file mode 100644 index b52281d..0000000 Binary files a/usr/lib/linuxmint/mintMenu/search_engines/dictionary.png and /dev/null differ diff --git a/usr/lib/linuxmint/mintMenu/search_engines/wikipedia.png b/usr/lib/linuxmint/mintMenu/search_engines/wikipedia.png deleted file mode 100644 index 440e9f1..0000000 Binary files a/usr/lib/linuxmint/mintMenu/search_engines/wikipedia.png and /dev/null differ diff --git a/usr/lib/linuxmint/mintMenu/search_engines/wikipedia.svg b/usr/lib/linuxmint/mintMenu/search_engines/wikipedia.svg new file mode 100644 index 0000000..146794d --- /dev/null +++ b/usr/lib/linuxmint/mintMenu/search_engines/wikipedia.svg @@ -0,0 +1,5 @@ + + + + +