From 37cd852738f9e8321fdef71f73d153bf3b2cc773 Mon Sep 17 00:00:00 2001 From: gm10 <13855078+gm10@users.noreply.github.com> Date: Mon, 11 Feb 2019 21:28:16 +0100 Subject: [PATCH] Applications.py: Clean up more whitespace and line lengths --- .../mintMenu/plugins/applications.py | 119 ++++++++++++------ 1 file changed, 83 insertions(+), 36 deletions(-) diff --git a/usr/lib/linuxmint/mintMenu/plugins/applications.py b/usr/lib/linuxmint/mintMenu/plugins/applications.py index 1c13b16..1211567 100755 --- a/usr/lib/linuxmint/mintMenu/plugins/applications.py +++ b/usr/lib/linuxmint/mintMenu/plugins/applications.py @@ -144,10 +144,14 @@ class SuggestionButton(Gtk.Button): class pluginclass(object): TARGET_TYPE_TEXT = 80 - toButton = (Gtk.TargetEntry.new("text/uri-list", 0, TARGET_TYPE_TEXT), Gtk.TargetEntry.new("text/uri-list", 0, TARGET_TYPE_TEXT)) + toButton = (Gtk.TargetEntry.new("text/uri-list", 0, TARGET_TYPE_TEXT), + Gtk.TargetEntry.new("text/uri-list", 0, TARGET_TYPE_TEXT)) TARGET_TYPE_FAV = 81 - 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)) + 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 def __init__(self, mintMenuWin, toggleButton, de): @@ -168,14 +172,14 @@ class pluginclass(object): self.builder.add_from_file (os.path.join(os.path.dirname(__file__), "applications.glade")) # Read GLADE file - self.searchEntry =self.builder.get_object("searchEntry") - self.searchButton =self.builder.get_object("searchButton") - self.showAllAppsButton =self.builder.get_object("showAllAppsButton") - self.showFavoritesButton =self.builder.get_object("showFavoritesButton") - self.applicationsBox =self.builder.get_object("applicationsBox") - self.categoriesBox =self.builder.get_object("categoriesBox") - self.favoritesBox =self.builder.get_object("favoritesBox") - self.applicationsScrolledWindow =self.builder.get_object("applicationsScrolledWindow") + self.searchEntry = self.builder.get_object("searchEntry") + self.searchButton = self.builder.get_object("searchButton") + self.showAllAppsButton = self.builder.get_object("showAllAppsButton") + self.showFavoritesButton = self.builder.get_object("showFavoritesButton") + self.applicationsBox = self.builder.get_object("applicationsBox") + self.categoriesBox = self.builder.get_object("categoriesBox") + self.favoritesBox = self.builder.get_object("favoritesBox") + self.applicationsScrolledWindow = self.builder.get_object("applicationsScrolledWindow") self.headingstocolor = [self.builder.get_object("label6"), self.builder.get_object("label2")] @@ -189,10 +193,12 @@ class pluginclass(object): self.heading = ""#_("Applications") # This should be the first item added to the window in glade - self.content_holder =self.builder.get_object("Applications") + self.content_holder = self.builder.get_object("Applications") # Items to get custom colors - self.itemstocolor = [self.builder.get_object("viewport1"),self.builder.get_object("viewport2"),self.builder.get_object("viewport3")] + self.itemstocolor = [self.builder.get_object("viewport1"), + self.builder.get_object("viewport2"), + self.builder.get_object("viewport3")] # Unset all timers self.filterTimer = None @@ -201,11 +207,17 @@ 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.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) + self.showFavoritesButton.drag_dest_set(Gtk.DestDefaults.MOTION | + Gtk.DestDefaults.HIGHLIGHT | + Gtk.DestDefaults.DROP, + self.toButton, Gdk.DragAction.COPY) - # self.searchButton.connect("button_release_event", self.SearchWithButton) + # self.searchButton.connect("button_release_event", self.SearchWithButton) try: # GSettings stuff self.settings = EasyGSettings("com.linuxmint.mintmenu.plugins.applications") @@ -278,7 +290,7 @@ class pluginclass(object): panelsettings = Gio.Settings.new("org.mate.panel") applet_list = panelsettings.get_strv("object-id-list") for applet in applet_list: - object_schema = Gio.Settings.new_with_path("org.mate.panel.object", "/org/mate/panel/objects/%s/" % (applet)) + object_schema = Gio.Settings.new_with_path("org.mate.panel.object", "/org/mate/panel/objects/%s/" % applet) keys = object_schema.list_keys() if "applet-iid" in keys: iid = object_schema.get_string("applet-iid") @@ -400,7 +412,9 @@ class pluginclass(object): def RegenPlugin(self, *args, **kargs): self.refresh_apt_cache() - # save old config - this is necessary because the app will notified when it sets the default values and you don't want the to reload itself several times + # save old config - this is necessary because the app will notified + # when it sets the default values and you don't want the to reload + # itself several times oldcategories_mouse_over = self.categories_mouse_over oldiconsize = self.iconSize oldfaviconsize = self.faviconsize @@ -581,11 +595,14 @@ class pluginclass(object): def add_search_suggestions(self, text): text = "%s" % cgi.escape(text) if self.enableInternetSearch: - 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("/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() - self.add_suggestion("accessories-dictionary", _("Lookup %s in Dictionary") % text, None, self.search_dictionary) + 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) self.applicationsBox.get_children()[-1].grab_focus() @@ -616,7 +633,7 @@ class pluginclass(object): summary = values[2] description = values[3].replace("~~~", "\n") package = PackageDescriptor(name, summary, description) - #See if all keywords are in the name (so we put these results at the top of the list) + # See if all keywords are in the name (so we put these results at the top of the list) some_found = False some_not_found = False for word in keywords: @@ -634,7 +651,8 @@ class pluginclass(object): found_packages.extend(found_elsewhere) if keyword == self.searchEntry.get_text() and len(found_packages) > 0: 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.. + # 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] for pkg in found_packages: @@ -784,8 +802,10 @@ class pluginclass(object): 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) + 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")) @@ -829,8 +849,10 @@ class pluginclass(object): 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) + 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")) @@ -1248,7 +1270,10 @@ class pluginclass(object): self.favorites.append(favButton) self.favoritesPositionOnGrid(favButton) favButton.drag_source_set(Gdk.ModifierType.BUTTON1_MASK, self.toFav, Gdk.DragAction.COPY) - favButton.drag_dest_set(Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT | Gtk.DestDefaults.DROP, self.toFav, Gdk.DragAction.COPY) + favButton.drag_dest_set(Gtk.DestDefaults.MOTION | + Gtk.DestDefaults.HIGHLIGHT | + Gtk.DestDefaults.DROP, + self.toFav, Gdk.DragAction.COPY) favButton.connect("drag-data-get", self.on_drag_data_get) favButton.connect("drag-data-received", self.on_drag_data_received) position += 1 @@ -1284,7 +1309,8 @@ class pluginclass(object): return tmp = self.favorites[oldposition] if newposition > oldposition: - if (self.favorites[newposition - 1].type == "space" or self.favorites[newposition - 1].type == "separator") and self.favCols > 1: + if (self.favorites[newposition - 1].type == "space" or + self.favorites[newposition - 1].type == "separator") and self.favCols > 1: newposition = newposition - 1 for i in range(oldposition, newposition): self.favorites[i] = self.favorites[i + 1] @@ -1309,7 +1335,10 @@ class pluginclass(object): self.favoritesPositionOnGrid(favButton) favButton.connect("drag-data-received", self.on_drag_data_received) - favButton.drag_dest_set(Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT | Gtk.DestDefaults.DROP, self.toFav, Gdk.DragAction.COPY) + favButton.drag_dest_set(Gtk.DestDefaults.MOTION | + Gtk.DestDefaults.HIGHLIGHT | + Gtk.DestDefaults.DROP, + self.toFav, Gdk.DragAction.COPY) favButton.connect("drag-data-get", self.on_drag_data_get) favButton.drag_source_set(Gdk.ModifierType.BUTTON1_MASK, self.toFav, Gdk.DragAction.COPY) @@ -1345,7 +1374,8 @@ class pluginclass(object): appListFile.write(favorite.type + "\n") 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__() + ")") + _("Couldn't save favorites. Check if you have write access to ~/.linuxmint/mintMenu") + + "\n(" + e.__str__() + ")") msgDlg.run() msgDlg.destroy() @@ -1403,7 +1433,11 @@ class pluginclass(object): found = False for item2 in self.categoryList: pass - if item["name"] == item2["name"] and item["icon"] == item2["icon"] and item["tooltip"] == item2["tooltip"] and item["index"] == item2["index"]: + if (item["name"] == item2["name"] and + item["icon"] == item2["icon"] and + item["tooltip"] == item2["tooltip"] and + item["index"] == item2["index"] + ): found = True break if not found: @@ -1412,7 +1446,11 @@ class pluginclass(object): for item in self.categoryList: found = False for item2 in newCategoryList: - if item["name"] == item2["name"] and item["icon"] == item2["icon"] and item["tooltip"] == item2["tooltip"] and item["index"] == item2["index"]: + if (item["name"] == item2["name"] and + item["icon"] == item2["icon"] and + item["tooltip"] == item2["tooltip"] and + item["index"] == item2["index"] + ): found = True break if not found: @@ -1513,7 +1551,9 @@ class pluginclass(object): self.applicationsBox.remove(item["button"]) sortedApplicationList.append((item["button"].appName, item["button"])) for item in addedApplications: - item["button"] = MenuApplicationLauncher(item["entry"].get_desktop_file_path(), self.iconSize, item["category"], self.showapplicationcomments, highlight=(True and menu_has_changed)) + item["button"] = MenuApplicationLauncher(item["entry"].get_desktop_file_path(), + self.iconSize, item["category"], self.showapplicationcomments, + highlight=(True and menu_has_changed)) if item["button"].appExec: self.mintMenuWin.setTooltip(item["button"], item["button"].getTooltip()) item["button"].connect("button-press-event", self.menuPopup) @@ -1552,7 +1592,10 @@ class pluginclass(object): # Build a list of all categories in the menu ([{"name", "icon", tooltip"}] def buildCategoryList(self): - newCategoryList = [{"name": _("All"), "icon": "edit-select-all", "tooltip": _("Show all applications"), "filter":"", "index": 0}] + newCategoryList = [{"name": _("All"), + "icon": "edit-select-all", + "tooltip": _("Show all applications"), + "filter":"", "index": 0}] num = 1 for menu in self.menuFiles: for child in menu.directory.get_contents(): @@ -1561,7 +1604,11 @@ class pluginclass(object): #if (icon == "preferences-system"): # self.adminMenu = child.name #if (icon != "applications-system" and icon != "applications-other"): - newCategoryList.append({"name": child.name, "icon": child.icon, "tooltip": child.name, "filter": child.name, "index": num}) + newCategoryList.append({"name": child.name, + "icon": child.icon, + "tooltip": child.name, + "filter": child.name, + "index": num}) num += 1 return newCategoryList