further cleanup, mostly coding style

This commit is contained in:
gm10 2019-01-22 21:16:59 +01:00
parent cc75da5868
commit 8b42c0f32f
No known key found for this signature in database
GPG Key ID: A981D4EA8CF993A9
11 changed files with 1145 additions and 1165 deletions

View File

@ -1,6 +1,5 @@
#!/usr/bin/python2
import gc
import gettext
import os
@ -21,6 +20,7 @@ import pointerMonitor
import setproctitle
from plugins.execute import Execute
GObject.threads_init()
# Rename the process
@ -50,7 +50,6 @@ class MainWindow( object ):
sys.path.append(os.path.join(self.path, "plugins"))
self.de = de
self.icon = "/usr/lib/linuxmint/mintMenu/visualisation-logo.png"
self.toggle = toggleButton
@ -222,7 +221,7 @@ class MainWindow( object ):
Align1.show()
Label1.show()
if not hasattr( MyPlugin, 'sticky' ) or MyPlugin.sticky == True:
if not hasattr(MyPlugin, 'sticky') or MyPlugin.sticky:
heading = Gtk.EventBox()
Align1.set_padding(0, 0, 10, 0)
heading.set_visible_window(False)
@ -400,8 +399,8 @@ class MainWindow( object ):
if hasattr(plugin, "onShowMenu"):
plugin.onShowMenu()
if ( "applications" in self.plugins ) and ( hasattr( self.plugins["applications"], "focusSearchEntry" ) ):
if (self.startWithFavorites):
if "applications" in self.plugins and hasattr(self.plugins["applications"], "focusSearchEntry"):
if self.startWithFavorites:
self.plugins["applications"].changeTab(0)
self.plugins["applications"].focusSearchEntry()
@ -430,6 +429,7 @@ class MainWindow( object ):
self.loseFocusBlocked = True
class MenuWin(object):
def __init__(self, applet, iid):
self.applet = applet
self.detect_desktop_environment()

View File

@ -22,6 +22,7 @@ from plugins.easybuttons import (CategoryButton, FavApplicationLauncher,
from plugins.easygsettings import EasyGSettings
from plugins.execute import Execute
# i18n
gettext.install("mintmenu", "/usr/share/linuxmint/locale")
@ -477,8 +478,8 @@ class pluginclass( object ):
# Hide vertical dotted separator
self.hideseparator = self.settings.get("bool", "hide-separator")
def SetHidden( self, state ):
if state == True:
def SetHidden(self, minimized):
if minimized:
self.settings.set("bool", "minimized", True)
else:
self.settings.set("bool", "minimized", False)
@ -647,9 +648,9 @@ class pluginclass( object ):
values = string.split(pkg, "###")
if len(values) == 4:
status = values[0]
if (status == "ERROR"):
if status == "ERROR":
print "Could not refresh APT cache"
elif (status == "CACHE"):
elif status == "CACHE":
name = values[1]
summary = values[2]
description = values[3].replace("~~~", "\n")
@ -776,7 +777,7 @@ class pluginclass( object ):
shownList = []
for i in self.applicationsBox.get_children():
shown = i.filterText(text)
if (shown):
if shown:
dupe = False
for item in shownList:
if i.desktopFile == item.desktopFile:
@ -790,7 +791,7 @@ class pluginclass( object ):
if(not showns):
i.grab_focus()
showns = True
if (not showns and os.path.exists("/usr/bin/mintinstall")):
if not showns and os.path.exists("/usr/bin/mintinstall"):
if len(text) >= 3:
if self.current_suggestion is not None and self.current_suggestion in text:
# We're restricting our search...
@ -1146,13 +1147,13 @@ class pluginclass( object ):
applet_list = panel_schema.get_strv("object-id-list")
while True:
test_obj = "object_%d" % (i)
test_obj = "object_%d" % i
if test_obj in applet_list:
i += 1
else:
break
path = "/org/mate/panel/objects/%s/" % (test_obj)
path = "/org/mate/panel/objects/%s/" % test_obj
new_schema = Gio.Settings.new_with_path("org.mate.panel.object", path)
new_schema.set_string("launcher-location", desktopEntry.desktopFile)
new_schema.set_string("object-type", "launcher")
@ -1224,7 +1225,6 @@ class pluginclass( object ):
else:
self.buildFavorites()
def onUninstallApp(self, menu, widget):
widget.uninstall()
self.mintMenuWin.hide()
@ -1300,9 +1300,7 @@ class pluginclass( object ):
space.set_visible_window(False)
space.connect("button-press-event", self.favPopup)
space.type = "space"
space.show()
return space
def favoritesBuildSeparator(self):
@ -1368,12 +1366,12 @@ class pluginclass( object ):
def buildFavorites(self):
try:
if (not os.path.exists(home + "/.linuxmint/mintMenu/applications.list")):
os.system("mkdir -p " + home + "/.linuxmint/mintMenu/applications")
os.system("cp /usr/lib/linuxmint/mintMenu/applications.list " + home + "/.linuxmint/mintMenu/applications.list")
path = os.path.join(home, ".linuxmint/mintMenu/applications.list")
if not os.path.exists(path):
os.system("mkdir -p " + path)
os.system("cp /usr/lib/linuxmint/mintMenu/applications.list " + path)
applicationsFile = open ( os.path.join( os.path.expanduser( "~" ), ".linuxmint", "mintMenu", "applications.list" ), "r" )
applicationsList = applicationsFile.readlines()
applicationsList = open(path).readlines() # TODO py3 encoding="UTF-8"
self.favorites = []
@ -1392,7 +1390,7 @@ class pluginclass( object ):
elif app == "separator":
favButton = self.favoritesBuildSeparator()
else:
if ( app.endswith( ".desktop" ) ):
if app.endswith(".desktop"):
favButton = self.favoritesBuildLauncher(app)
else:
favButton = None
@ -1493,17 +1491,15 @@ class pluginclass( object ):
def favoritesSave(self):
try:
self.checkMintMenuFolder()
appListFile = open( os.path.join( os.path.expanduser( "~"), ".linuxmint", "mintMenu", "applications.list" ) , "w" )
with open(os.path.join(home, ".linuxmint/mintMenu/applications.list") , "w") as appListFile:
for favorite in self.favorites:
if favorite.type == "location":
appListFile.write("location:" + favorite.desktopFile + "\n")
else:
appListFile.write(favorite.type + "\n")
appListFile.close( )
except Exception, 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 = 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()
msgDlg.destroy()
@ -1543,11 +1539,9 @@ class pluginclass( object ):
return
self.rebuildLock = True
self.menuChangedTimer = None
try:
self.loadMenuFiles()
# Find added and removed categories than update the category list
@ -1578,7 +1572,7 @@ class pluginclass( object ):
if not found:
removedCategories.append(item)
if self.showcategoryicons == True:
if self.showcategoryicons:
categoryIconSize = self.iconSize
else:
categoryIconSize = 0
@ -1631,7 +1625,6 @@ class pluginclass( object ):
except Exception, e:
print e
# Find added and removed applications add update the application list
newApplicationList = self.buildApplicationList()
addedApplications = []
@ -1690,7 +1683,6 @@ class pluginclass( object ):
else:
item["button"].destroy()
sortedApplicationList.sort()
launcherNames = [] # Keep track of launcher names so we don't add them twice in the list..
for item in sortedApplicationList:
@ -1715,9 +1707,7 @@ 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}]
num = 1
for menu in self.menuFiles:
for child in menu.directory.get_contents():
if child.get_type() == matemenu.TYPE_DIRECTORY:
@ -1727,7 +1717,6 @@ class pluginclass( object ):
#if (icon != "applications-system" and icon != "applications-other"):
newCategoryList.append({"name": child.name, "icon": child.icon, "tooltip": child.name, "filter": child.name, "index": num})
num += 1
return newCategoryList
# Build a list containing the DesktopEntry object and the category of each application in the menu

View File

@ -1,7 +1,6 @@
#!/usr/bin/python2
import os.path
import re
import shutil
import xdg.DesktopEntry
@ -12,7 +11,6 @@ gi.require_version('MateDesktop', '2.0')
from gi.repository import Gtk, Gdk, GLib
from gi.repository import Pango
from gi.repository import GObject
from gi.repository import MateDesktop
from plugins.execute import Execute
from plugins.filemonitor import monitor as filemonitor
@ -491,8 +489,8 @@ class MenuApplicationLauncher( ApplicationLauncher ):
#else:
#appName = "<b>%s</b>" % (appName);
#appComment = "<b>%s</b>" % (appComment);
appName = "<b>%s</b>" % (appName);
appComment = "<b>%s</b>" % (appComment);
appName = "<b>%s</b>" % appName
appComment = "<b>%s</b>" % appComment
except Exception, detail:
print detail
pass

View File

@ -2,6 +2,7 @@
import urllib
def GetFilePath(uri):
path = urllib.url2pathname(uri) # escape special chars
path = path.strip('\r\n\x00') # remove \r\n and NULL

View File

@ -1,8 +1,8 @@
#!/usr/bin/python2
from gi.repository import Gio
class EasyGSettings:
def __init__(self, schema = None):

View File

@ -3,6 +3,7 @@
import os
from gi.repository import Gio
def RemoveArgs(Execline):
if isinstance(Execline, list):
Execline = ' '.join(Execline)

View File

@ -12,7 +12,9 @@ try:
except ImportError:
hasInotify = False
if hasInotify:
class FileMonitor(object):
def __init__(self):
self.monitorId = 0
@ -48,7 +50,6 @@ if hasInotify:
else:
GLib.idle_add(callback[0])
else:
class _MonitoredFile(object):
@ -91,8 +92,6 @@ else:
self.monitor.checkFiles()
time.sleep(1)
class FileMonitor(object):
def __init__(self):
self.monitorId = 0
@ -120,5 +119,4 @@ else:
else:
GLib.idle_add(monitored.callback)
monitor = FileMonitor()

View File

@ -15,6 +15,7 @@ from plugins.easybuttons import easyButton
from plugins.easygsettings import EasyGSettings
from plugins.execute import Execute
# i18n
gettext.install("mintmenu", "/usr/share/linuxmint/locale")
@ -67,7 +68,7 @@ class pluginclass( object ):
self.content_holder.set_size_request(self.width, self.height)
def wake(self):
if ( self.showtrash == True ):
if self.showtrash:
self.refreshTrash()
def destroy(self):
@ -76,7 +77,7 @@ class pluginclass( object ):
def changePluginSize(self, settings, key, args = None):
self.allowScrollbar = self.settings.get("bool", "allow-scrollbar")
self.width = self.settings.get("int", "width")
if (self.allowScrollbar == False):
if not self.allowScrollbar:
self.height = -1
self.scrolledWindow.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.NEVER)
else:
@ -98,7 +99,7 @@ class pluginclass( object ):
self.scrolledWindow.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
self.height = self.settings.get("int", "height")
self.content_holder.set_size_request(self.width, self.height)
if (self.allowScrollbar == False):
if not self.allowScrollbar:
self.height = -1
self.scrolledWindow.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.NEVER)
self.content_holder.set_size_request(self.width, self.height)
@ -135,21 +136,21 @@ class pluginclass( object ):
#Add standard places
def do_standard_places(self):
if ( self.showcomputer == True ):
if self.showcomputer:
Button1 = easyButton("computer", self.iconsize, [_("Computer")], -1, -1)
Button1.connect("clicked", self.ButtonClicked, "xdg-open computer:")
Button1.show()
self.placesBtnHolder.pack_start(Button1, False, False, 0)
self.mintMenuWin.setTooltip(Button1, _("Browse all local and remote disks and folders accessible from this computer"))
if ( self.showhomefolder == True ):
if self.showhomefolder:
Button2 = easyButton("user-home", self.iconsize, [_("Home Folder")], -1, -1)
Button2.connect("clicked", self.ButtonClicked, "xdg-open %s " % home)
Button2.show()
self.placesBtnHolder.pack_start(Button2, False, False, 0)
self.mintMenuWin.setTooltip(Button2, _("Open your personal folder"))
if ( self.shownetwork == True and self.de == "mate"):
if self.shownetwork and self.de == "mate":
mate_settings = Gio.Settings.new("org.mate.interface")
icon_theme = mate_settings.get_string("icon-theme")
if "Mint-X" in icon_theme:
@ -161,7 +162,7 @@ class pluginclass( object ):
self.placesBtnHolder.pack_start(Button3, False, False, 0)
self.mintMenuWin.setTooltip(Button3, _("Browse bookmarked and local network locations"))
if ( self.showdesktop == True ):
if self.showdesktop:
# Determine where the Desktop folder is (could be localized)
desktopDir = home + "/Desktop"
try:
@ -180,7 +181,7 @@ class pluginclass( object ):
self.placesBtnHolder.pack_start(Button4, False, False, 0)
self.mintMenuWin.setTooltip(Button4, _("Browse items placed on the desktop"))
if ( self.showtrash == True ):
if self.showtrash:
self.trashButton = easyButton("user-trash", self.iconsize, [_("Trash")], -1, -1)
self.trashButton.connect("clicked", self.ButtonClicked, "xdg-open trash:")
self.trashButton.show()
@ -194,7 +195,7 @@ class pluginclass( object ):
for index in range(len(self.custompaths)):
path = self.custompaths[index]
path = path.replace("~", home)
command = ( "xdg-open \"" + path + "\"")
command = 'xdg-open "%s"' % path
currentbutton = easyButton("folder", self.iconsize, [self.customnames[index]], -1, -1)
currentbutton.connect("clicked", self.ButtonClicked, command)
currentbutton.show()

View File

@ -103,8 +103,8 @@ class pluginclass:
RecentHelper.iconSize = self.appSettings.get("int", "icon-size")
self.RebuildPlugin()
def SetHidden( self, state ):
if state == True:
def SetHidden(self, minimized):
if minimized:
self.settings.set("bool", "minimized", True)
else:
self.settings.set("bool", "minimized", False)

View File

@ -9,6 +9,7 @@ from gi.repository import Gtk
from plugins.easybuttons import ApplicationLauncher
recentApps = []
mintMenuWin = None
recentAppBox = None
@ -17,9 +18,7 @@ iconSize = 16
def recentAppsAdd(recentAppsButton):
if recentAppsButton:
recentApps.insert(0, recentAppsButton)
counter = 0
for recentApp in recentApps:
if counter != 0 and (recentApp.desktopFile == recentAppsButton.desktopFile or counter >= numentries):
@ -28,20 +27,18 @@ def recentAppsAdd( recentAppsButton ):
def recentAppsSave():
try:
if (not os.path.exists(home + "/.linuxmint/mintMenu/recentApplications.list")):
os.system("touch " + home + "/.linuxmint/mintMenu/recentApplications.list")
recentAppListFile = open( os.path.join( os.path.expanduser( "~"), ".linuxmint", "mintMenu", "recentApplications.list" ) , "w" )
path = os.path.join(home, ".linuxmint/mintMenu/recentApplications.list")
with open(path, "w") as recentAppListFile:
for recentApp in recentApps:
if not hasattr(recentApp, "type") or recentApp.type == "location":
recentAppListFile.write("location:" + recentApp.desktopFile + "\n")
else:
recentAppListFile.write(recentApp.type + "\n")
recentAppListFile.close( )
except Exception, 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 = 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()
msgDlg.destroy()
@ -82,7 +79,6 @@ def recentAppBuildLauncher( location ):
return None
def buildRecentApps():
print "-- recentHelper.buildRecentApps"
del recentApps[:]
@ -90,7 +86,6 @@ def buildRecentApps():
path = os.path.join(home, ".linuxmint/mintMenu/recentApplications.list")
if not os.path.exists(path):
print "does not exist"
#os.system("touch " + path)
recentApplicationsList = []
else:
recentApplicationsList = open(path).readlines()
@ -124,10 +119,8 @@ def doRecentApps():
# recent apps
buildRecentApps()
for AButton in recentApps:
AButton.set_size_request(200, -1)
AButton.set_relief(Gtk.ReliefStyle.NONE)
recentAppBox.pack_start(AButton, False, True, 0)
return True

View File

@ -22,7 +22,6 @@ class pluginclass( object ):
self.toggleButton = toggleButton
self.de = de
self.builder = Gtk.Builder()
self.builder.add_from_file(os.path.join(os.path.dirname(__file__), "system_management.glade"))
@ -75,7 +74,7 @@ class pluginclass( object ):
if key == "width":
self.width = settings.get_int(key)
elif key == "height":
if (self.allowScrollbar == False):
if not self.allowScrollbar:
self.height = -1
self.scrolledWindow.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.NEVER)
else:
@ -97,7 +96,7 @@ class pluginclass( object ):
self.scrolledWindow.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
self.height = self.settings.get("int", "height")
self.content_holder.set_size_request(self.width, self.height)
if (self.allowScrollbar == False):
if not self.allowScrollbar:
self.height = -1
self.scrolledWindow.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.NEVER)
self.content_holder.set_size_request(self.width, self.height)
@ -150,7 +149,7 @@ class pluginclass( object ):
#Add standard items
def do_standard_items(self):
if ( self.showSoftwareManager == True ):
if self.showSoftwareManager:
if os.path.exists("/usr/bin/mintinstall"):
Button1 = easyButton("mintinstall", self.iconsize, [_("Software Manager")], -1, -1)
Button1.connect("clicked", self.ButtonClicked, "mintinstall")
@ -158,21 +157,21 @@ class pluginclass( object ):
self.systemBtnHolder.pack_start(Button1, False, False, 0)
self.mintMenuWin.setTooltip(Button1, _("Browse and install available software"))
if ( self.showPackageManager == True ):
if self.showPackageManager:
Button2 = easyButton("applications-system", self.iconsize, [_("Package Manager")], -1, -1)
Button2.connect("clicked", self.ButtonClicked, "synaptic-pkexec")
Button2.show()
self.systemBtnHolder.pack_start(Button2, False, False, 0)
self.mintMenuWin.setTooltip(Button2, _("Install, remove and upgrade software packages"))
if ( self.showControlCenter == True ):
if self.showControlCenter:
Button3 = easyButton("gtk-preferences", self.iconsize, [_("Control Center")], -1, -1)
Button3.connect("clicked", self.ButtonClicked, self.settings_cmd)
Button3.show()
self.systemBtnHolder.pack_start(Button3, False, False, 0)
self.mintMenuWin.setTooltip(Button3, _("Configure your system"))
if ( self.showTerminal == True ):
if self.showTerminal:
Button4 = easyButton("terminal", self.iconsize, [_("Terminal")], -1, -1)
if os.path.exists(self.terminal_cmd):
Button4.connect("clicked", self.ButtonClicked, self.terminal_cmd)
@ -182,21 +181,21 @@ class pluginclass( object ):
self.systemBtnHolder.pack_start(Button4, False, False, 0)
self.mintMenuWin.setTooltip(Button4, _("Use the command line"))
if ( self.showLockScreen == True ):
if self.showLockScreen:
Button5 = easyButton("system-lock-screen", self.iconsize, [_("Lock Screen")], -1, -1)
Button5.connect("clicked", self.ButtonClicked, self.lock_cmd)
Button5.show()
self.systemBtnHolder.pack_start(Button5, False, False, 0)
self.mintMenuWin.setTooltip(Button5, _("Requires password to unlock"))
if ( self.showLogout == True ):
if self.showLogout:
Button6 = easyButton("system-log-out", self.iconsize, [_("Logout")], -1, -1)
Button6.connect("clicked", self.ButtonClicked, self.logout_cmd)
Button6.show()
self.systemBtnHolder.pack_start(Button6, False, False, 0)
self.mintMenuWin.setTooltip(Button6, _("Log out or switch user"))
if ( self.showQuit == True ):
if self.showQuit:
Button7 = easyButton("system-shutdown", self.iconsize, [_("Quit")], -1, -1)
Button7.connect("clicked", self.ButtonClicked, self.shutdown_cmd)
Button7.show()