2015-06-26 01:36:36 +01:00
|
|
|
#!/usr/bin/python2
|
2009-07-27 11:45:34 +01:00
|
|
|
|
2017-05-04 09:19:03 +01:00
|
|
|
import gi
|
|
|
|
gi.require_version('MateDesktop', '2.0')
|
2013-11-25 16:06:22 +00:00
|
|
|
from gi.repository import Gtk, Gdk, GLib
|
2013-03-04 16:50:14 +00:00
|
|
|
from gi.repository import Pango
|
|
|
|
from gi.repository import GObject
|
2017-04-28 16:00:31 +01:00
|
|
|
from gi.repository import MateDesktop
|
2009-07-27 11:45:34 +01:00
|
|
|
import os.path
|
|
|
|
import shutil
|
|
|
|
import re
|
2013-03-06 01:31:58 +00:00
|
|
|
from execute import *
|
2009-07-27 11:45:34 +01:00
|
|
|
import xdg.DesktopEntry
|
|
|
|
import xdg.Menu
|
|
|
|
from filemonitor import monitor as filemonitor
|
|
|
|
|
2013-03-04 16:50:14 +00:00
|
|
|
class IconManager(GObject.GObject):
|
2009-07-27 11:45:34 +01:00
|
|
|
|
2010-09-13 15:54:23 +01:00
|
|
|
__gsignals__ = {
|
2017-08-26 16:35:45 +01:00
|
|
|
"changed" : (GObject.SignalFlags.RUN_LAST, None, () )
|
2010-09-13 15:54:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
def __init__( self ):
|
2013-03-04 16:50:14 +00:00
|
|
|
GObject.GObject.__init__( self )
|
2010-09-13 15:54:23 +01:00
|
|
|
self.icons = { }
|
|
|
|
self.count = 0
|
|
|
|
|
|
|
|
# Some apps don't put a default icon in the default theme folder, so we will search all themes
|
|
|
|
def createTheme( d ):
|
2013-03-04 16:50:14 +00:00
|
|
|
theme = Gtk.IconTheme()
|
2010-09-13 15:54:23 +01:00
|
|
|
theme.set_custom_theme( d )
|
|
|
|
return theme
|
|
|
|
|
|
|
|
# This takes to much time and there are only a very few applications that use icons from different themes
|
|
|
|
#self.themes = map( createTheme, [ d for d in os.listdir( "/usr/share/icons" ) if os.path.isdir( os.path.join( "/usr/share/icons", d ) ) ] )
|
|
|
|
|
2013-05-21 02:18:38 +01:00
|
|
|
self.defaultTheme = Gtk.IconTheme.get_default()
|
2010-09-13 15:54:23 +01:00
|
|
|
defaultKdeTheme = createTheme( "kde.default" )
|
|
|
|
|
2013-05-21 02:18:38 +01:00
|
|
|
# Setup and clean up the temp icon dir
|
|
|
|
configDir = GLib.get_user_config_dir()
|
|
|
|
self.iconDir = os.path.join(configDir, "mintmenu")
|
|
|
|
if not os.path.exists(self.iconDir):
|
|
|
|
os.makedirs(self.iconDir)
|
|
|
|
contents = os.listdir(self.iconDir)
|
|
|
|
for fn in contents:
|
|
|
|
os.remove(os.path.join(self.iconDir, fn))
|
|
|
|
|
|
|
|
self.defaultTheme.append_search_path(self.iconDir)
|
|
|
|
|
2010-09-13 15:54:23 +01:00
|
|
|
# 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() ]
|
|
|
|
|
2013-05-21 02:18:38 +01:00
|
|
|
self.themes = [ self.defaultTheme, defaultKdeTheme ]
|
2010-09-13 15:54:23 +01:00
|
|
|
|
|
|
|
# Listen for changes in the themes
|
|
|
|
for theme in self.themes:
|
|
|
|
theme.connect("changed", self.themeChanged )
|
|
|
|
|
|
|
|
|
2013-05-09 11:02:08 +01:00
|
|
|
def getIcon( self, iconName, iconSize ):
|
2016-05-21 17:11:36 +01:00
|
|
|
|
2010-09-13 15:54:23 +01:00
|
|
|
if not iconName:
|
|
|
|
return None
|
|
|
|
|
|
|
|
try:
|
2013-05-08 13:57:55 +01:00
|
|
|
iconFileName = ""
|
2013-05-21 02:18:38 +01:00
|
|
|
realIconName = ""
|
|
|
|
needTempFile = False
|
2010-09-23 17:55:02 +01:00
|
|
|
#[ iconWidth, iconHeight ] = self.getIconSize( iconSize )
|
|
|
|
if iconSize <= 0:
|
2010-09-13 15:54:23 +01:00
|
|
|
return None
|
|
|
|
|
|
|
|
elif os.path.isabs( iconName ):
|
|
|
|
iconFileName = iconName
|
2013-05-21 02:18:38 +01:00
|
|
|
needTempFile = True
|
2010-09-13 15:54:23 +01:00
|
|
|
else:
|
|
|
|
if iconName[-4:] in [".png", ".xpm", ".svg", ".gif"]:
|
|
|
|
realIconName = iconName[:-4]
|
|
|
|
else:
|
|
|
|
realIconName = iconName
|
|
|
|
|
2013-05-21 02:18:38 +01:00
|
|
|
if iconFileName and needTempFile and os.path.exists( iconFileName ):
|
|
|
|
tmpIconName = iconFileName.replace("/", "-")
|
|
|
|
realIconName = tmpIconName[:-4]
|
2013-05-21 15:38:23 +01:00
|
|
|
if not os.path.exists(os.path.join(self.iconDir, tmpIconName)):
|
|
|
|
shutil.copyfile(iconFileName, os.path.join(self.iconDir, tmpIconName))
|
2013-05-21 02:18:38 +01:00
|
|
|
self.defaultTheme.append_search_path(self.iconDir)
|
|
|
|
|
|
|
|
image = Gtk.Image()
|
|
|
|
icon_found = False
|
|
|
|
for theme in self.themes:
|
2017-04-29 11:00:45 +01:00
|
|
|
if theme.lookup_icon(realIconName, 0, Gtk.IconLookupFlags.FORCE_REGULAR):
|
2013-05-21 02:18:38 +01:00
|
|
|
icon_found = True
|
|
|
|
break
|
|
|
|
|
|
|
|
if icon_found:
|
|
|
|
image.set_from_icon_name(realIconName, Gtk.IconSize.DND)
|
|
|
|
image.set_pixel_size(iconSize)
|
2010-09-13 15:54:23 +01:00
|
|
|
else:
|
2013-05-08 13:57:55 +01:00
|
|
|
image = None
|
2010-09-13 15:54:23 +01:00
|
|
|
|
2013-05-08 13:57:55 +01:00
|
|
|
return image
|
2010-09-13 15:54:23 +01:00
|
|
|
except Exception, e:
|
|
|
|
print "Exception " + e.__class__.__name__ + ": " + e.message
|
|
|
|
return None
|
|
|
|
|
|
|
|
def themeChanged( self, theme ):
|
|
|
|
self.emit( "changed" )
|
|
|
|
|
2013-03-04 16:50:14 +00:00
|
|
|
GObject.type_register(IconManager)
|
2009-07-27 11:45:34 +01:00
|
|
|
|
2013-03-04 16:50:14 +00:00
|
|
|
class easyButton( Gtk.Button ):
|
2009-07-27 11:45:34 +01:00
|
|
|
|
2010-09-13 15:54:23 +01:00
|
|
|
def __init__( self, iconName, iconSize, labels = None, buttonWidth = -1, buttonHeight = -1 ):
|
2013-03-04 16:50:14 +00:00
|
|
|
GObject.GObject.__init__( self )
|
2010-09-13 15:54:23 +01:00
|
|
|
self.connections = [ ]
|
|
|
|
self.iconName = iconName
|
|
|
|
self.iconSize = iconSize
|
|
|
|
self.showIcon = True
|
|
|
|
|
2013-03-04 16:50:14 +00:00
|
|
|
self.set_relief( Gtk.ReliefStyle.NONE )
|
2010-09-13 15:54:23 +01:00
|
|
|
self.set_size_request( buttonWidth, buttonHeight )
|
|
|
|
|
2013-03-04 16:50:14 +00:00
|
|
|
Align1 = Gtk.Alignment.new( 0, 0.5, 1.0, 0 )
|
2016-09-06 15:58:34 +01:00
|
|
|
HBox1 = Gtk.Box( orientation=Gtk.Orientation.HORIZONTAL )
|
|
|
|
self.labelBox = Gtk.Box( orientation=Gtk.Orientation.VERTICAL, spacing=2 )
|
2010-09-13 15:54:23 +01:00
|
|
|
|
|
|
|
|
2013-03-04 16:50:14 +00:00
|
|
|
self.buttonImage = Gtk.Image()
|
2010-09-13 15:54:23 +01:00
|
|
|
icon = self.getIcon( self.iconSize )
|
|
|
|
if icon:
|
2013-05-08 13:57:55 +01:00
|
|
|
self.buttonImage = icon
|
2010-09-13 15:54:23 +01:00
|
|
|
else:
|
2010-09-23 17:55:02 +01:00
|
|
|
#[ iW, iH ] = iconManager.getIconSize( self.iconSize )
|
|
|
|
self.buttonImage.set_size_request( self.iconSize, self.iconSize )
|
2016-09-06 15:58:34 +01:00
|
|
|
self.image_box = Gtk.Box( orientation=Gtk.Orientation.HORIZONTAL )
|
2013-05-08 13:57:55 +01:00
|
|
|
self.image_box.pack_start(self.buttonImage, False, False, 5)
|
|
|
|
self.image_box.show_all()
|
|
|
|
HBox1.pack_start( self.image_box, False, False, 0 )
|
2010-09-13 15:54:23 +01:00
|
|
|
|
|
|
|
if labels:
|
|
|
|
for label in labels:
|
|
|
|
if isinstance( label, basestring ):
|
2016-05-21 17:11:36 +01:00
|
|
|
self.addLabel( label )
|
2010-09-13 15:54:23 +01:00
|
|
|
elif isinstance( label, list ):
|
|
|
|
self.addLabel( label[0], label[1] )
|
|
|
|
|
|
|
|
self.labelBox.show()
|
2013-03-04 16:50:14 +00:00
|
|
|
HBox1.pack_start( self.labelBox , True, True, 0)
|
2010-09-13 15:54:23 +01:00
|
|
|
HBox1.show()
|
|
|
|
Align1.add( HBox1 )
|
|
|
|
Align1.show()
|
|
|
|
self.add( Align1 )
|
|
|
|
|
|
|
|
self.connectSelf( "destroy", self.onDestroy )
|
|
|
|
self.connect( "released", self.onRelease )
|
|
|
|
# Reload icons when the theme changed
|
|
|
|
self.themeChangedHandlerId = iconManager.connect("changed", self.themeChanged )
|
|
|
|
|
|
|
|
def connectSelf( self, event, callback ):
|
|
|
|
self.connections.append( self.connect( event, callback ) )
|
|
|
|
|
|
|
|
def onRelease( self, widget ):
|
2016-09-06 15:58:34 +01:00
|
|
|
widget.get_style_context().set_state( Gtk.StateFlags.NORMAL )
|
2010-09-13 15:54:23 +01:00
|
|
|
|
|
|
|
def onDestroy( self, widget ):
|
|
|
|
self.buttonImage.clear()
|
|
|
|
iconManager.disconnect( self.themeChangedHandlerId )
|
|
|
|
for connection in self.connections:
|
|
|
|
self.disconnect( connection )
|
|
|
|
del self.connections
|
|
|
|
|
|
|
|
|
|
|
|
def addLabel( self, text, styles = None ):
|
2013-03-04 16:50:14 +00:00
|
|
|
label = Gtk.Label()
|
2013-03-08 00:50:53 +00:00
|
|
|
if "<b>" in text or "<span" in text:
|
2014-05-22 14:44:38 +01:00
|
|
|
label.set_markup(text.replace('&', '&')) # don't remove our pango
|
2010-09-13 15:54:23 +01:00
|
|
|
else:
|
2013-03-18 22:50:56 +00:00
|
|
|
label.set_text(text)
|
2010-09-13 15:54:23 +01:00
|
|
|
|
|
|
|
if styles:
|
2013-03-04 16:50:14 +00:00
|
|
|
labelStyle = Pango.AttrList()
|
2010-09-13 15:54:23 +01:00
|
|
|
for attr in styles:
|
|
|
|
labelStyle.insert( attr )
|
|
|
|
label.set_attributes( labelStyle )
|
|
|
|
|
2013-03-04 16:50:14 +00:00
|
|
|
label.set_ellipsize( Pango.EllipsizeMode.END )
|
2010-09-13 15:54:23 +01:00
|
|
|
label.set_alignment( 0.0, 1.0 )
|
2016-09-06 15:58:34 +01:00
|
|
|
label.set_max_width_chars(0)
|
2010-09-13 15:54:23 +01:00
|
|
|
label.show()
|
2013-03-04 16:50:14 +00:00
|
|
|
self.labelBox.pack_start( label , True, True, 0)
|
2010-09-13 15:54:23 +01:00
|
|
|
|
|
|
|
|
|
|
|
def getIcon ( self, iconSize ):
|
|
|
|
if not self.iconName:
|
|
|
|
return None
|
|
|
|
|
|
|
|
icon = iconManager.getIcon( self.iconName, iconSize )
|
2016-05-21 17:11:36 +01:00
|
|
|
if icon is None:
|
2010-09-13 15:54:23 +01:00
|
|
|
icon = iconManager.getIcon( "application-default-icon", iconSize )
|
|
|
|
|
|
|
|
return icon
|
|
|
|
|
|
|
|
def setIcon ( self, iconName ):
|
|
|
|
self.iconName = iconName
|
|
|
|
self.iconChanged()
|
|
|
|
|
|
|
|
# IconTheme changed, setup new button icons
|
|
|
|
def themeChanged( self, theme ):
|
2013-05-08 13:57:55 +01:00
|
|
|
self.iconChanged()
|
2010-09-13 15:54:23 +01:00
|
|
|
|
|
|
|
def iconChanged( self ):
|
|
|
|
icon = self.getIcon( self.iconSize )
|
2013-05-08 13:57:55 +01:00
|
|
|
self.buttonImage.destroy()
|
2010-09-13 15:54:23 +01:00
|
|
|
if icon:
|
2013-05-08 13:57:55 +01:00
|
|
|
self.buttonImage = icon
|
|
|
|
self.image_box.pack_start(self.buttonImage, False, False, 5)
|
|
|
|
self.image_box.show_all()
|
2010-09-13 15:54:23 +01:00
|
|
|
else:
|
2010-09-23 17:55:02 +01:00
|
|
|
#[iW, iH ] = iconManager.getIconSize( self.iconSize )
|
|
|
|
self.buttonImage.set_size_request( self.iconSize, self.iconSize )
|
2010-09-13 15:54:23 +01:00
|
|
|
|
|
|
|
def setIconSize( self, size ):
|
|
|
|
self.iconSize = size
|
|
|
|
icon = self.getIcon( self.iconSize )
|
2013-05-08 13:57:55 +01:00
|
|
|
self.buttonImage.destroy()
|
2010-09-13 15:54:23 +01:00
|
|
|
if icon:
|
2013-05-08 13:57:55 +01:00
|
|
|
self.buttonImage = icon
|
|
|
|
self.image_box.pack_start(self.buttonImage, False, False, 5)
|
|
|
|
self.image_box.show_all()
|
2010-09-13 15:54:23 +01:00
|
|
|
elif self.iconSize:
|
2010-09-23 17:55:02 +01:00
|
|
|
#[ iW, iH ] = iconManager.getIconSize( self.iconSize )
|
|
|
|
self.buttonImage.set_size_request( self.iconSize, self.iconSize )
|
2009-07-27 11:45:34 +01:00
|
|
|
|
|
|
|
class ApplicationLauncher( easyButton ):
|
|
|
|
|
2010-09-13 15:54:23 +01:00
|
|
|
def __init__( self, desktopFile, iconSize):
|
|
|
|
|
|
|
|
if isinstance( desktopFile, xdg.Menu.MenuEntry ):
|
|
|
|
desktopItem = desktopFile.DesktopEntry
|
|
|
|
desktopFile = desktopItem.filename
|
|
|
|
self.appDirs = desktop.desktopFile.AppDirs
|
|
|
|
elif isinstance( desktopFile, xdg.Menu.DesktopEntry ):
|
|
|
|
desktopItem = desktopFile
|
|
|
|
desktopFile = desktopItem.filename
|
|
|
|
self.appDirs = [ os.path.dirname( desktopItem.filename ) ]
|
|
|
|
else:
|
|
|
|
desktopItem = xdg.DesktopEntry.DesktopEntry( desktopFile )
|
|
|
|
self.appDirs = [ os.path.dirname( desktopFile ) ]
|
|
|
|
|
|
|
|
self.desktopFile = desktopFile
|
|
|
|
self.startupMonitorId = 0
|
|
|
|
|
|
|
|
self.loadDesktopEntry( desktopItem )
|
|
|
|
|
|
|
|
self.desktopEntryMonitors = []
|
|
|
|
|
|
|
|
base = os.path.basename( self.desktopFile )
|
|
|
|
for dir in self.appDirs:
|
2013-05-08 17:27:04 +01:00
|
|
|
self.desktopEntryMonitors.append( filemonitor.addMonitor( os.path.join(dir, base) , self.desktopEntryFileChangedCallback ) )
|
2010-09-13 15:54:23 +01:00
|
|
|
|
|
|
|
easyButton.__init__( self, self.appIconName, iconSize )
|
|
|
|
self.setupLabels()
|
|
|
|
|
|
|
|
# Drag and Drop
|
2013-03-08 16:41:19 +00:00
|
|
|
self.connectSelf( "drag-data-get", self.dragDataGet )
|
|
|
|
|
2016-09-06 15:58:34 +01:00
|
|
|
targets = ( Gtk.TargetEntry.new( "text/plain", 0, 100 ), Gtk.TargetEntry.new( "text/uri-list", 0, 101 ) )
|
|
|
|
self.drag_source_set( Gdk.ModifierType.BUTTON1_MASK, targets, Gdk.DragAction.COPY )
|
2010-09-13 15:54:23 +01:00
|
|
|
|
2013-05-08 14:05:09 +01:00
|
|
|
icon = self.getIcon( Gtk.IconSize.DND )
|
2013-05-08 14:16:55 +01:00
|
|
|
if icon:
|
2013-05-21 02:18:38 +01:00
|
|
|
iconName, s = icon.get_icon_name()
|
2016-09-06 15:58:34 +01:00
|
|
|
self.drag_source_set_icon_name( iconName )
|
2010-09-13 15:54:23 +01:00
|
|
|
|
|
|
|
self.connectSelf( "focus-in-event", self.onFocusIn )
|
|
|
|
self.connectSelf( "focus-out-event", self.onFocusOut )
|
|
|
|
self.connectSelf( "clicked", self.execute )
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def loadDesktopEntry( self, desktopItem ):
|
|
|
|
try:
|
2013-05-02 23:08:56 +01:00
|
|
|
self.appName = self.strip_accents(desktopItem.getName())
|
|
|
|
self.appGenericName = self.strip_accents(desktopItem.getGenericName())
|
|
|
|
self.appComment = self.strip_accents(desktopItem.getComment())
|
2016-10-05 10:21:21 +01:00
|
|
|
self.appExec = self.strip_accents(desktopItem.getExec().replace('\\\\', '\\'))
|
2010-09-13 15:54:23 +01:00
|
|
|
self.appIconName = desktopItem.getIcon()
|
|
|
|
self.appCategories = desktopItem.getCategories()
|
2014-03-28 06:48:47 +00:00
|
|
|
self.appMateDocPath = desktopItem.get( "X-MATE-DocPath" ) or ""
|
2010-09-13 15:54:23 +01:00
|
|
|
self.useTerminal = desktopItem.getTerminal()
|
2013-02-10 16:31:00 +00:00
|
|
|
self.appPath = desktopItem.getPath()
|
2010-09-13 15:54:23 +01:00
|
|
|
|
2014-03-28 06:48:47 +00:00
|
|
|
if not self.appMateDocPath:
|
2010-09-13 15:54:23 +01:00
|
|
|
self.appKdeDocPath = desktopItem.getDocPath() or ""
|
|
|
|
|
|
|
|
self.appName = self.appName.strip()
|
|
|
|
self.appGenericName = self.appGenericName.strip()
|
|
|
|
self.appComment = self.appComment.strip()
|
|
|
|
|
|
|
|
basename = os.path.basename( self.desktopFile )
|
|
|
|
self.startupFilePath = os.path.join( os.path.expanduser("~"), ".config", "autostart", basename )
|
|
|
|
if self.startupMonitorId:
|
|
|
|
filemonitor.removeMonitor( self.startupMonitorId )
|
2013-03-10 23:47:02 +00:00
|
|
|
if os.path.exists (self.startupFilePath):
|
|
|
|
self.startupMonitorId = filemonitor.addMonitor( self.startupFilePath, self.startupFileChanged )
|
2010-09-13 15:54:23 +01:00
|
|
|
|
|
|
|
except Exception, e:
|
|
|
|
print e
|
|
|
|
self.appName = ""
|
|
|
|
self.appGenericName = ""
|
|
|
|
self.appComment = ""
|
|
|
|
self.appExec = ""
|
|
|
|
self.appIconName = ""
|
|
|
|
self.appCategories = ""
|
|
|
|
self.appDocPath = ""
|
|
|
|
self.startupMonitorId = 0
|
|
|
|
|
|
|
|
|
|
|
|
def onFocusIn( self, widget, event ):
|
2013-03-04 16:50:14 +00:00
|
|
|
self.set_relief( Gtk.ReliefStyle.HALF )
|
2010-09-13 15:54:23 +01:00
|
|
|
|
|
|
|
def onFocusOut( self, widget, event ):
|
2013-03-04 16:50:14 +00:00
|
|
|
self.set_relief( Gtk.ReliefStyle.NONE )
|
2010-09-13 15:54:23 +01:00
|
|
|
|
|
|
|
def setupLabels( self ):
|
|
|
|
self.addLabel( self.appName )
|
2016-05-21 17:11:36 +01:00
|
|
|
|
2010-09-13 15:54:23 +01:00
|
|
|
def filterText( self, text ):
|
|
|
|
keywords = text.lower().split()
|
2013-05-03 00:12:24 +01:00
|
|
|
appName = self.appName.lower()
|
|
|
|
appGenericName = self.appGenericName.lower()
|
|
|
|
appComment = self.appComment.lower()
|
|
|
|
appExec = self.appExec.lower()
|
2010-09-13 15:54:23 +01:00
|
|
|
for keyword in keywords:
|
|
|
|
keyw = self.strip_accents(keyword)
|
|
|
|
if keyw != "" and appName.find( keyw ) == -1 and appGenericName.find( keyw ) == -1 and appComment.find( keyw ) == -1 and appExec.find( keyw ) == -1:
|
|
|
|
self.hide()
|
|
|
|
return False
|
|
|
|
|
|
|
|
self.show()
|
|
|
|
return True
|
|
|
|
|
2016-05-21 17:11:36 +01:00
|
|
|
def strip_accents(self, string):
|
2013-05-21 21:24:30 +01:00
|
|
|
value = string
|
2013-05-21 11:00:55 +01:00
|
|
|
if isinstance(string, unicode):
|
|
|
|
try:
|
2016-05-21 17:11:36 +01:00
|
|
|
value = string.encode('UTF8', 'ignore')
|
2013-05-21 11:00:55 +01:00
|
|
|
except:
|
2013-05-21 21:24:30 +01:00
|
|
|
pass
|
2016-05-21 17:11:36 +01:00
|
|
|
return value
|
2010-09-13 15:54:23 +01:00
|
|
|
|
|
|
|
def getTooltip( self ):
|
|
|
|
tooltip = self.appName
|
|
|
|
if self.appComment != "" and self.appComment != self.appName:
|
|
|
|
tooltip = tooltip + "\n" + self.appComment
|
|
|
|
|
|
|
|
return tooltip
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def dragDataGet( self, widget, context, selection, targetType, eventTime ):
|
|
|
|
if targetType == 100: # text/plain
|
|
|
|
selection.set_text( "'" + self.desktopFile + "'", -1 )
|
|
|
|
elif targetType == 101: # text/uri-list
|
|
|
|
if self.desktopFile[0:7] == "file://":
|
|
|
|
selection.set_uris( [ self.desktopFile ] )
|
|
|
|
else:
|
|
|
|
selection.set_uris( [ "file://" + self.desktopFile ] )
|
|
|
|
|
|
|
|
def execute( self, *args ):
|
|
|
|
if self.appExec:
|
|
|
|
if self.useTerminal:
|
|
|
|
cmd = "x-terminal-emulator -e \"" + self.appExec + "\""
|
2014-01-20 15:04:28 +00:00
|
|
|
if os.path.exists("/usr/bin/mate-terminal"):
|
|
|
|
cmd = "mate-terminal -e \"" + self.appExec + "\""
|
2013-02-10 16:31:00 +00:00
|
|
|
Execute(cmd, self.appPath)
|
2010-09-13 15:54:23 +01:00
|
|
|
else:
|
2013-02-10 16:31:00 +00:00
|
|
|
Execute(self.appExec, self.appPath)
|
2010-09-13 15:54:23 +01:00
|
|
|
|
|
|
|
def uninstall (self, *args ):
|
2018-03-13 15:05:17 +00:00
|
|
|
Execute("mint-remove-application " + self.desktopFile)
|
2010-09-13 15:54:23 +01:00
|
|
|
|
|
|
|
# IconTheme changed, setup new icons for button and drag 'n drop
|
|
|
|
def iconChanged( self ):
|
|
|
|
easyButton.iconChanged( self )
|
|
|
|
|
2013-05-08 14:05:09 +01:00
|
|
|
icon = self.getIcon( Gtk.IconSize.DND )
|
2013-05-08 14:16:55 +01:00
|
|
|
if icon:
|
2013-05-21 02:18:38 +01:00
|
|
|
iconName, size = icon.get_icon_name()
|
2016-09-06 15:58:34 +01:00
|
|
|
self.drag_source_set_icon_name( iconName )
|
2010-09-13 15:54:23 +01:00
|
|
|
|
|
|
|
def startupFileChanged( self, *args ):
|
|
|
|
self.inStartup = os.path.exists( self.startupFilePath )
|
|
|
|
|
|
|
|
def addToStartup( self ):
|
|
|
|
startupDir = os.path.join( os.path.expanduser("~"), ".config", "autostart" );
|
|
|
|
if not os.path.exists( startupDir ):
|
|
|
|
os.makedirs( startupDir )
|
|
|
|
|
|
|
|
shutil.copyfile( self.desktopFile, self.startupFilePath )
|
|
|
|
|
2014-03-28 06:48:47 +00:00
|
|
|
# Remove %u, etc. from Exec entry, because MATE will not replace them when it starts the app
|
2017-04-28 16:00:31 +01:00
|
|
|
item = MateDesktop.DesktopItem.new_from_uri(self.startupFilePath, MateDesktop.DesktopItemLoadFlags.ONLY_IF_EXISTS)
|
2010-09-13 15:54:23 +01:00
|
|
|
if item:
|
|
|
|
r = re.compile("%[A-Za-z]");
|
2017-04-28 16:00:31 +01:00
|
|
|
tmp = r.sub("", item.get_string( MateDesktop.DESKTOP_ITEM_EXEC ) ).strip()
|
|
|
|
item.set_string( MateDesktop.DESKTOP_ITEM_EXEC, tmp )
|
2010-09-13 15:54:23 +01:00
|
|
|
item.save( self.startupFilePath, 0 )
|
|
|
|
|
|
|
|
def removeFromStartup( self ):
|
|
|
|
if os.path.exists( self.startupFilePath ):
|
|
|
|
os.remove( self.startupFilePath )
|
|
|
|
|
|
|
|
def addToFavourites( self ):
|
|
|
|
favouritesDir = os.path.join( os.path.expanduser("~"), ".linuxmint", "mintMenu", "applications" );
|
|
|
|
if not os.path.exists( favouritesDir ):
|
|
|
|
os.makedirs( favouritesDir )
|
|
|
|
|
|
|
|
shutil.copyfile( self.desktopFile, self.favouritesFilePath )
|
|
|
|
|
|
|
|
def removeFromFavourites( self ):
|
|
|
|
if os.path.exists( self.favouritesFilePath ):
|
|
|
|
os.remove( self.favouritesFilePath )
|
|
|
|
|
|
|
|
def isInStartup( self ):
|
|
|
|
#return self.inStartup
|
|
|
|
return os.path.exists( self.startupFilePath )
|
|
|
|
|
|
|
|
def onDestroy( self, widget ):
|
|
|
|
easyButton.onDestroy( self, widget )
|
|
|
|
if self.startupMonitorId:
|
|
|
|
filemonitor.removeMonitor( self.startupMonitorId )
|
|
|
|
for id in self.desktopEntryMonitors:
|
|
|
|
filemonitor.removeMonitor( id )
|
|
|
|
|
2013-05-08 17:27:04 +01:00
|
|
|
def desktopEntryFileChangedCallback (self):
|
|
|
|
GLib.timeout_add(200, self.onDesktopEntryFileChanged)
|
|
|
|
|
2010-09-13 15:54:23 +01:00
|
|
|
def onDesktopEntryFileChanged( self ):
|
|
|
|
exists = False
|
|
|
|
base = os.path.basename( self.desktopFile )
|
|
|
|
for dir in self.appDirs:
|
|
|
|
if os.path.exists( os.path.join( dir, base ) ):
|
2013-05-08 19:45:29 +01:00
|
|
|
# print os.path.join( dir, base ), self.desktopFile
|
2010-09-13 15:54:23 +01:00
|
|
|
self.loadDesktopEntry( xdg.DesktopEntry.DesktopEntry( os.path.join( dir, base ) ) )
|
|
|
|
for child in self.labelBox:
|
|
|
|
child.destroy()
|
|
|
|
|
2013-05-08 13:57:55 +01:00
|
|
|
self.iconName = self.appIconName
|
2010-09-13 15:54:23 +01:00
|
|
|
|
|
|
|
self.setupLabels()
|
2013-05-08 13:57:55 +01:00
|
|
|
self.iconChanged()
|
2010-09-13 15:54:23 +01:00
|
|
|
exists = True
|
|
|
|
break
|
|
|
|
|
|
|
|
if not exists:
|
|
|
|
# FIXME: What to do in this case?
|
|
|
|
self.destroy()
|
2013-05-08 17:27:04 +01:00
|
|
|
return False
|
2009-07-27 11:45:34 +01:00
|
|
|
|
|
|
|
class MenuApplicationLauncher( ApplicationLauncher ):
|
|
|
|
|
2010-09-13 15:54:23 +01:00
|
|
|
def __init__( self, desktopFile, iconSize, category, showComment, highlight=False ):
|
|
|
|
|
|
|
|
self.showComment = showComment
|
|
|
|
self.appCategory = category
|
|
|
|
self.highlight = highlight
|
|
|
|
|
|
|
|
ApplicationLauncher.__init__( self, desktopFile, iconSize )
|
|
|
|
|
|
|
|
|
|
|
|
def filterCategory( self, category ):
|
|
|
|
if self.appCategory == category or category == "":
|
|
|
|
self.show()
|
|
|
|
else:
|
|
|
|
self.hide()
|
|
|
|
|
2016-05-21 17:11:36 +01:00
|
|
|
def setupLabels( self ):
|
2010-09-13 15:54:23 +01:00
|
|
|
appName = self.appName
|
|
|
|
appComment = self.appComment
|
2016-05-21 17:11:36 +01:00
|
|
|
if self.highlight:
|
2010-09-13 15:54:23 +01:00
|
|
|
try:
|
2016-09-06 15:58:34 +01:00
|
|
|
#color = self.labelBox.get_style_context().get_color( Gtk.StateFlags.SELECTED ).to_string()
|
2010-10-26 13:59:17 +01:00
|
|
|
#if len(color) > 0 and color[0] == "#":
|
|
|
|
#appName = "<span foreground=\"%s\"><b>%s</b></span>" % (color, appName);
|
|
|
|
#appComment = "<span foreground=\"%s\"><b>%s</b></span>" % (color, appComment);
|
|
|
|
#appName = "<b>%s</b>" % (appName);
|
|
|
|
#appComment = "<b>%s</b>" % (appComment);
|
|
|
|
#else:
|
|
|
|
#appName = "<b>%s</b>" % (appName);
|
|
|
|
#appComment = "<b>%s</b>" % (appComment);
|
|
|
|
appName = "<b>%s</b>" % (appName);
|
|
|
|
appComment = "<b>%s</b>" % (appComment);
|
2010-09-13 15:54:23 +01:00
|
|
|
except Exception, detail:
|
|
|
|
print detail
|
|
|
|
pass
|
2016-05-21 17:11:36 +01:00
|
|
|
|
2013-03-08 00:50:53 +00:00
|
|
|
if self.showComment and self.appComment != "":
|
|
|
|
if self.iconSize <= 2:
|
|
|
|
self.addLabel( '<span size="small">%s</span>' % appName)
|
|
|
|
self.addLabel( '<span size="x-small">%s</span>' % appComment)
|
|
|
|
else:
|
|
|
|
self.addLabel( appName )
|
|
|
|
self.addLabel( '<span size="small">%s</span>' % appComment)
|
|
|
|
else:
|
|
|
|
self.addLabel( appName )
|
2016-05-21 17:11:36 +01:00
|
|
|
|
|
|
|
def execute( self, *args ):
|
2010-09-13 15:54:23 +01:00
|
|
|
self.highlight = False
|
|
|
|
for child in self.labelBox:
|
|
|
|
child.destroy()
|
|
|
|
self.setupLabels()
|
|
|
|
return super(MenuApplicationLauncher, self).execute(*args)
|
|
|
|
|
|
|
|
def setShowComment( self, showComment ):
|
|
|
|
self.showComment = showComment
|
|
|
|
for child in self.labelBox:
|
|
|
|
child.destroy()
|
|
|
|
self.setupLabels()
|
2009-07-27 11:45:34 +01:00
|
|
|
|
|
|
|
class FavApplicationLauncher( ApplicationLauncher ):
|
|
|
|
|
2010-09-13 15:54:23 +01:00
|
|
|
def __init__( self, desktopFile, iconSize, swapGeneric = False ):
|
|
|
|
|
|
|
|
self.swapGeneric = swapGeneric
|
2009-07-27 11:45:34 +01:00
|
|
|
|
2010-09-13 15:54:23 +01:00
|
|
|
ApplicationLauncher.__init__( self, desktopFile, iconSize )
|
2009-07-27 11:45:34 +01:00
|
|
|
|
2010-09-13 15:54:23 +01:00
|
|
|
def setupLabels( self ):
|
|
|
|
if self.appGenericName:
|
|
|
|
if self.swapGeneric:
|
2013-03-08 00:50:53 +00:00
|
|
|
self.addLabel( '<span weight="bold">%s</span>' % self.appName )
|
2010-09-13 15:54:23 +01:00
|
|
|
self.addLabel( self.appGenericName )
|
|
|
|
else:
|
2013-03-08 00:50:53 +00:00
|
|
|
self.addLabel( '<span weight="bold">%s</span>' % self.appGenericName )
|
2010-09-13 15:54:23 +01:00
|
|
|
self.addLabel( self.appName )
|
|
|
|
else:
|
2013-03-08 00:50:53 +00:00
|
|
|
self.addLabel( '<span weight="bold">%s</span>' % self.appName )
|
2010-09-13 15:54:23 +01:00
|
|
|
if self.appComment != "":
|
|
|
|
self.addLabel( self.appComment )
|
|
|
|
else:
|
2011-06-29 12:34:23 +01:00
|
|
|
self.addLabel ( "" )
|
2016-05-21 17:11:36 +01:00
|
|
|
|
2010-09-13 15:54:23 +01:00
|
|
|
def setSwapGeneric( self, swapGeneric ):
|
|
|
|
self.swapGeneric = swapGeneric
|
|
|
|
for child in self.labelBox:
|
|
|
|
child.destroy()
|
2009-07-27 11:45:34 +01:00
|
|
|
|
2010-09-13 15:54:23 +01:00
|
|
|
self.setupLabels()
|
2009-07-27 11:45:34 +01:00
|
|
|
|
|
|
|
|
|
|
|
class CategoryButton( easyButton ):
|
2010-09-13 15:54:23 +01:00
|
|
|
|
|
|
|
def __init__( self, iconName, iconSize, labels , f ):
|
|
|
|
easyButton.__init__( self, iconName, iconSize, labels )
|
|
|
|
self.filter = f
|
2009-07-27 11:45:34 +01:00
|
|
|
|
|
|
|
|
|
|
|
iconManager = IconManager()
|