/usr/lib/python2.7/dist-packages/mate_menu/plugins/places.py is in mate-menu 18.04.3-2ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | # -*- coding: utf-8 -*-
# Copyright (C) 2007-2014 Clement Lefebvre <root@linuxmint.com>
# Copyright (C) 2015 Martin Wimpress <code@ubuntu-mate.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the
# Free Software Foundation, Inc.,
# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
import gettext
import os
import shutil
import subprocess
from gi.repository import GLib, Gio, Gtk
from mate_menu.easybuttons import *
from mate_menu.easygsettings import EasyGSettings
from mate_menu.execute import Execute
from urllib import unquote
# i18n
gettext.install("mate-menu", "/usr/share/locale")
class pluginclass( object ):
def __init__(self, mateMenuWin, toggleButton):
self.mateMenuWin = mateMenuWin
self.toggleButton = toggleButton
# Read UI file
builder = Gtk.Builder()
builder.add_from_file( os.path.join( '/', 'usr', 'share', 'mate-menu', 'plugins', 'places.glade' ))
self.placesBtnHolder = builder.get_object( "places_button_holder" )
self.editableBtnHolder = builder.get_object( "editable_button_holder" )
self.scrolledWindow=builder.get_object("scrolledwindow2")
# These properties are NECESSARY to maintain consistency
# Set 'window' property for the plugin (Must be the root widget)
self.window = builder.get_object( "mainWindow" )
# Set 'heading' property for plugin
self.heading = _("Places")
# This should be the first item added to the window in glade
self.content_holder = builder.get_object( "Places" )
# Items to get custom colors
self.itemstocolor = [ builder.get_object( "viewport2" ) ]
# Settings
self.settings = EasyGSettings("org.mate.mate-menu.plugins.places")
self.settings.notifyAdd( "icon-size", self.RegenPlugin )
self.settings.notifyAdd( "show-computer", self.RegenPlugin )
self.settings.notifyAdd( "show-desktop", self.RegenPlugin )
self.settings.notifyAdd( "show-home_folder", self.RegenPlugin )
self.settings.notifyAdd( "show-network", self.RegenPlugin )
self.settings.notifyAdd( "show-trash", self.RegenPlugin )
self.settings.notifyAdd( "custom-names", self.RegenPlugin )
self.settings.notifyAdd( "allow-scrollbar", self.RegenPlugin )
self.settings.notifyAdd( "show-gtk-bookmarks", self.RegenPlugin )
self.settings.notifyAdd( "height", self.changePluginSize )
self.settings.notifyAdd( "width", self.changePluginSize )
self.loadSettings()
self.content_holder.set_size_request( self.width, self.height )
def wake (self) :
if ( self.showtrash == True ):
self.refreshTrash()
def destroy( self ):
self.settings.notifyRemoveAll()
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):
self.height = -1
self.scrolledWindow.set_policy( Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.NEVER )
else:
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 )
def RegenPlugin( self, *args, **kargs ):
self.loadSettings()
self.ClearAll()
self.do_standard_places()
self.do_custom_places()
self.do_gtk_bookmarks()
def loadSettings( self ):
self.width = self.settings.get( "int", "width" )
self.allowScrollbar = self.settings.get( "bool", "allow-scrollbar" )
self.showGtkBookmarks = self.settings.get( "bool", "show-gtk-bookmarks" )
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):
self.height = -1
self.scrolledWindow.set_policy( Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.NEVER )
self.content_holder.set_size_request( self.width, self.height )
self.iconsize = self.settings.get( "int", "icon-size" )
# Check default items
self.showcomputer = self.settings.get( "bool", "show-computer" )
self.showhomefolder = self.settings.get( "bool", "show-home-folder" )
self.shownetwork = self.settings.get( "bool", "show-network" )
self.showdesktop = self.settings.get( "bool", "show-desktop" )
self.showtrash = self.settings.get( "bool", "show-trash" )
# Get paths for custom items
self.custompaths = self.settings.get( "list-string", "custom-paths" )
# Get names for custom items
self.customnames = self.settings.get( "list-string", "custom-names" )
# Plugin icon
self.icon = self.settings.get( "string", "icon" )
# Allow plugin to be minimized to the left plugin pane
self.sticky = self.settings.get( "bool", "sticky")
self.minimized = self.settings.get( "bool", "minimized")
def ClearAll(self):
for child in self.placesBtnHolder.get_children():
child.destroy()
for child in self.editableBtnHolder.get_children():
child.destroy()
#Add standard places
def do_standard_places( self ):
if ( self.showcomputer == True ):
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.mateMenuWin.setTooltip( Button1, _("Browse all local and remote disks and folders accessible from this computer") )
if ( self.showhomefolder == True ):
Button2 = easyButton( "user-home", self.iconsize, [_("Home Folder")], -1, -1 )
Button2.connect( "clicked", self.ButtonClicked, "xdg-open %s " % os.environ["HOME"])
Button2.show()
self.placesBtnHolder.pack_start( Button2, False, False, 0)
self.mateMenuWin.setTooltip( Button2, _("Open your personal folder") )
if ( self.shownetwork == True):
mate_settings = Gio.Settings.new("org.mate.interface")
icon_theme = mate_settings.get_string( "icon-theme" )
Button3 = easyButton( "network-workgroup", self.iconsize, [_("Network")], -1, -1)
Button3.connect("clicked", self.ButtonClicked, "xdg-open network:")
Button3.show()
self.placesBtnHolder.pack_start( Button3, False, False, 0)
self.mateMenuWin.setTooltip( Button3, _("Browse bookmarked and local network locations") )
if ( self.showdesktop == True ):
# Determine where the Desktop folder is (could be localized)
desktopDir = os.path.join(os.environ["HOME"] + "Desktop")
try:
from configobj import ConfigObj
configPath = os.environ.get("XDG_CONFIG_HOME",
os.path.join( os.environ["HOME"], ".config"))
config = ConfigObj(os.path.join(configPath, "user-dirs.dirs"))
tmpdesktopDir = os.path.expandvars(config['XDG_DESKTOP_DIR'])
if os.path.exists(tmpdesktopDir):
desktopDir = tmpdesktopDir
except Exception, detail:
print detail
Button4 = easyButton( "desktop", self.iconsize, [_("Desktop")], -1, -1 )
Button4.connect("clicked", self.ButtonClicked, "xdg-open \"" + desktopDir + "\"")
Button4.show()
self.placesBtnHolder.pack_start( Button4, False, False, 0)
self.mateMenuWin.setTooltip( Button4, _("Browse items placed on the desktop") )
if ( self.showtrash == True ):
self.trashButton = easyButton( "user-trash", self.iconsize, [_("Trash")], -1, -1 )
self.trashButton.connect("clicked", self.ButtonClicked, "xdg-open trash:")
self.trashButton.show()
self.trashButton.connect( "button-release-event", self.trashPopup )
self.refreshTrash()
self.placesBtnHolder.pack_start( self.trashButton, False, False, 0)
self.mateMenuWin.setTooltip( self.trashButton, _("Browse deleted files") )
def do_custom_places( self ):
for index in range( len(self.custompaths) ):
path = self.custompaths[index]
path = path.replace("~", os.environ["HOME"])
command = ("xdg-open \"" + path + "\"")
currentbutton = easyButton( "folder", self.iconsize, [self.customnames[index]], -1, -1 )
currentbutton.connect( "clicked", self.ButtonClicked, command )
currentbutton.show()
self.placesBtnHolder.pack_start( currentbutton, False, False, 0)
def do_gtk_bookmarks( self ):
if self.showGtkBookmarks:
bookmarksFile = os.path.join(GLib.get_user_config_dir(), "gtk-3.0", "bookmarks")
if not os.path.exists(bookmarksFile):
bookmarksFile = os.path.join(GLib.get_home_dir(), ".gtk-bookmarks")
if not os.path.exists(bookmarksFile):
return
bookmarks = []
with open(bookmarksFile, "r") as f:
for line in f:
#line = line.replace('file://', '')
line = line.rstrip()
if not line:
continue
parts = line.split(' ', 1)
if len(parts) == 2:
path, name = parts
elif len(parts) == 1:
path = parts[0]
name = os.path.basename(os.path.normpath(path))
bookmarks.append((name, path))
for name, path in bookmarks:
name = unquote(name)
currentbutton = easyButton( "folder", self.iconsize, [name], -1, -1 )
currentbutton.connect( "clicked", self.launch_gtk_bookmark, path )
currentbutton.show()
self.placesBtnHolder.pack_start( currentbutton, False, False, 0)
def launch_gtk_bookmark (self, widget, path):
self.mateMenuWin.hide()
subprocess.Popen(['xdg-open', path])
def trashPopup( self, widget, event ):
if event.button == 3:
trashMenu = Gtk.Menu()
emptyTrashMenuItem = Gtk.MenuItem(_("Empty trash"))
trashMenu.append(emptyTrashMenuItem)
trashMenu.show_all()
emptyTrashMenuItem.connect ( "activate", self.emptyTrash, widget )
self.mateMenuWin.stopHiding()
trashMenu.attach_to_widget(widget, None)
trashMenu.popup(None, None, None, None, 3, 0)
def emptyTrash( self, menu, widget):
trash_info = os.path.join(os.path.expanduser('~'), '.local','share','Trash','info')
trash_files = os.path.join(os.path.expanduser('~'), '.local','share','Trash','files')
shutil.rmtree(trash_info)
shutil.rmtree(trash_files)
self.trashButton.setIcon('user-trash')
def ButtonClicked( self, widget, Exec ):
self.mateMenuWin.hide()
if Exec:
Execute( Exec )
def do_plugin( self ):
self.do_standard_places()
self.do_custom_places()
self.do_gtk_bookmarks()
def refreshTrash (self):
iconName = 'user-trash'
trash_info = os.path.join(os.path.expanduser('~'), '.local','share','Trash','info')
if os.path.exists(trash_info) and os.listdir(trash_info):
iconName = 'user-trash-full'
self.trashButton.setIcon(iconName)
|