diff --git a/usr/lib/linuxmint/mintMenu/mintMenu.py b/usr/lib/linuxmint/mintMenu/mintMenu.py index 53e6dcb..ea5aa85 100755 --- a/usr/lib/linuxmint/mintMenu/mintMenu.py +++ b/usr/lib/linuxmint/mintMenu/mintMenu.py @@ -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 @@ -30,60 +30,59 @@ setproctitle.setproctitle('mintmenu') gettext.install("mintmenu", "/usr/share/linuxmint/locale") NAME = _("Menu") -PATH = os.path.abspath( os.path.dirname( sys.argv[0] ) ) +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")) windowManager = os.getenv("DESKTOP_SESSION") if not windowManager: windowManager = "MATE" -xdg.Config.setWindowManager( windowManager.upper() ) +xdg.Config.setWindowManager(windowManager.upper()) -class MainWindow( object ): +class MainWindow(object): """This is the main class for the application""" - def __init__( self, toggleButton, settings, de ): + def __init__(self, toggleButton, settings, de): self.settings = settings self.path = PATH - sys.path.append( os.path.join( self.path, "plugins") ) + sys.path.append(os.path.join(self.path, "plugins")) self.de = de - self.icon = "/usr/lib/linuxmint/mintMenu/visualisation-logo.png" self.toggle = toggleButton # Load UI file and extract widgets builder = Gtk.Builder() - builder.add_from_file(os.path.join( self.path, "mintMenu.glade" )) - self.window = builder.get_object( "mainWindow" ) - self.paneholder = builder.get_object( "paneholder" ) + builder.add_from_file(os.path.join(self.path, "mintMenu.glade")) + self.window = builder.get_object("mainWindow") + self.paneholder = builder.get_object("paneholder") builder.connect_signals(self) - self.panesToColor = [ ] - self.headingsToColor = [ ] + self.panesToColor = [] + self.headingsToColor = [] - self.window.connect( "key-press-event", self.onKeyPress ) - self.window.connect( "focus-in-event", self.onFocusIn ) - self.loseFocusId = self.window.connect( "focus-out-event", self.onFocusOut ) + self.window.connect("key-press-event", self.onKeyPress) + self.window.connect("focus-in-event", self.onFocusIn) + self.loseFocusId = self.window.connect("focus-out-event", self.onFocusOut) self.loseFocusBlocked = False self.window.stick() - plugindir = os.path.join( os.path.expanduser( "~" ), ".linuxmint/mintMenu/plugins" ) - sys.path.append( plugindir ) + plugindir = os.path.join(os.path.expanduser("~"), ".linuxmint/mintMenu/plugins") + sys.path.append(plugindir) self.panelSettings = Gio.Settings.new("org.mate.panel") - self.panelSettings.connect( "changed::tooltips-enabled", self.toggleTooltipsEnabled ) + self.panelSettings.connect("changed::tooltips-enabled", self.toggleTooltipsEnabled) - self.settings.connect( "changed::plugins-list", self.RegenPlugins ) - self.settings.connect( "changed::start-with-favorites", self.toggleStartWithFavorites ) - self.settings.connect( "changed::tooltips-enabled", self.toggleTooltipsEnabled ) - self.settings.connect( "changed::use-custom-color", self.toggleUseCustomColor ) - self.settings.connect( "changed::custom-heading-color", self.toggleCustomHeadingColor ) - self.settings.connect( "changed::custom-color", self.toggleCustomBackgroundColor ) + self.settings.connect("changed::plugins-list", self.RegenPlugins) + self.settings.connect("changed::start-with-favorites", self.toggleStartWithFavorites) + self.settings.connect("changed::tooltips-enabled", self.toggleTooltipsEnabled) + self.settings.connect("changed::use-custom-color", self.toggleUseCustomColor) + self.settings.connect("changed::custom-heading-color", self.toggleCustomHeadingColor) + self.settings.connect("changed::custom-color", self.toggleCustomBackgroundColor) self.getSetGSettingEntries() @@ -91,7 +90,7 @@ class MainWindow( object ): if self.globalEnableTooltips and self.enableTooltips: self.tooltipsEnable() else: - self.tooltipsEnable( False ) + self.tooltipsEnable(False) self.PopulatePlugins() self.firstTime = True @@ -101,13 +100,13 @@ class MainWindow( object ): Gtk.main_quit() sys.exit(0) - def wakePlugins( self ): + def wakePlugins(self): # Call each plugin and let them know we're showing up for plugin in self.plugins.values(): - if hasattr( plugin, "wake" ): + if hasattr(plugin, "wake"): plugin.wake() - def toggleTooltipsEnabled( self, settings, key, args = None): + def toggleTooltipsEnabled(self, settings, key, args = None): if key == "tooltips-enabled": self.globalEnableTooltips = settings.get_boolean(key) else: @@ -116,48 +115,48 @@ class MainWindow( object ): if self.globalEnableTooltips and self.enableTooltips: self.tooltipsEnable() else: - self.tooltipsEnable( False ) + self.tooltipsEnable(False) - def toggleStartWithFavorites( self, settings, key ): + def toggleStartWithFavorites(self, settings, key): self.startWithFavorites = settings.get_boolean(key) - def toggleUseCustomColor( self, settings, key ): + def toggleUseCustomColor(self, settings, key): self.usecustomcolor = settings.get_boolean(key) self.loadTheme() - def toggleCustomBackgroundColor( self, settings, key ): + def toggleCustomBackgroundColor(self, settings, key): self.customcolor = settings.get_string(key) - self.SetPaneColors( self.panesToColor ) + self.SetPaneColors(self.panesToColor) - def toggleCustomHeadingColor( self, settings, key ): + def toggleCustomHeadingColor(self, settings, key): self.customheadingcolor = settings.get_string(key) - self.SetHeadingStyle( self.headingsToColor ) + self.SetHeadingStyle(self.headingsToColor) - def getSetGSettingEntries( self ): - self.dottedfile = os.path.join( self.path, "dotted.png") + def getSetGSettingEntries(self): + self.dottedfile = os.path.join(self.path, "dotted.png") - self.pluginlist = self.settings.get_strv( "plugins-list" ) - self.usecustomcolor = self.settings.get_boolean( "use-custom-color" ) - self.customcolor = self.settings.get_string( "custom-color" ) - self.customheadingcolor = self.settings.get_string( "custom-heading-color" ) - self.offset = self.settings.get_int( "offset" ) - self.enableTooltips = self.settings.get_boolean( "tooltips-enabled" ) - self.startWithFavorites = self.settings.get_boolean( "start-with-favorites" ) + self.pluginlist = self.settings.get_strv("plugins-list") + self.usecustomcolor = self.settings.get_boolean("use-custom-color") + self.customcolor = self.settings.get_string("custom-color") + self.customheadingcolor = self.settings.get_string("custom-heading-color") + self.offset = self.settings.get_int("offset") + self.enableTooltips = self.settings.get_boolean("tooltips-enabled") + self.startWithFavorites = self.settings.get_boolean("start-with-favorites") - self.globalEnableTooltips = self.panelSettings.get_boolean( "tooltips-enabled" ) + self.globalEnableTooltips = self.panelSettings.get_boolean("tooltips-enabled") - def PopulatePlugins( self ): - self.panesToColor = [ ] - self.headingsToColor = [ ] + def PopulatePlugins(self): + self.panesToColor = [] + self.headingsToColor = [] PluginPane = Gtk.EventBox() PluginPane.show() - PaneLadder = Gtk.Box( orientation=Gtk.Orientation.VERTICAL ) - PluginPane.add( PaneLadder ) + PaneLadder = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) + PluginPane.add(PaneLadder) ImageBox = Gtk.EventBox() ImageBox.show() - self.panesToColor.extend( [ PluginPane, ImageBox ] ) + self.panesToColor.extend([PluginPane, ImageBox]) - seperatorImage = GdkPixbuf.Pixbuf.new_from_file( self.dottedfile ) + seperatorImage = GdkPixbuf.Pixbuf.new_from_file(self.dottedfile) self.plugins = {} @@ -168,22 +167,22 @@ class MainWindow( object ): if plugin != "newpane": try: - X = __import__( plugin ) + X = __import__(plugin) # If no parameter passed to plugin it is autonomous if X.pluginclass.__init__.func_code.co_argcount == 1: MyPlugin = X.pluginclass() else: # pass mintMenu and togglebutton instance so that the plugin can use it - MyPlugin = X.pluginclass( self, self.toggle, self.de ) + MyPlugin = X.pluginclass(self, self.toggle, self.de) if not MyPlugin.icon: MyPlugin.icon = "mate-logo-icon.png" - #if hasattr( MyPlugin, "hideseparator" ) and not MyPlugin.hideseparator: + #if hasattr(MyPlugin, "hideseparator") and not MyPlugin.hideseparator: # Image1 = Gtk.Image() - # Image1.set_from_pixbuf( seperatorImage ) + # Image1.set_from_pixbuf(seperatorImage) # if not ImageBox.get_child(): - # ImageBox.add( Image1 ) + # ImageBox.add(Image1) # Image1.show() #print u"Loading plugin '" + plugin + "' : sucessful" @@ -195,55 +194,55 @@ class MainWindow( object ): # create traceback info = sys.exc_info() - errorLabel = Gtk.Label( "\n".join(traceback.format_exception( info[0], info[1], info[2] )).replace("\\n", "\n") ) - errorLabel.set_selectable( True ) - errorLabel.set_line_wrap( True ) - errorLabel.set_alignment( 0.0, 0.0 ) - errorLabel.set_padding( 5, 5 ) + errorLabel = Gtk.Label("\n".join(traceback.format_exception(info[0], info[1], info[2])).replace("\\n", "\n")) + errorLabel.set_selectable(True) + errorLabel.set_line_wrap(True) + errorLabel.set_alignment(0.0, 0.0) + errorLabel.set_padding(5, 5) errorLabel.show() - MyPlugin.content_holder.add( errorLabel ) - MyPlugin.add( MyPlugin.content_holder ) + MyPlugin.content_holder.add(errorLabel) + MyPlugin.add(MyPlugin.content_holder) MyPlugin.width = 270 MyPlugin.icon = 'mate-logo-icon.png' print u"Unable to load " + plugin + " plugin :-(" - self.panesToColor.append( MyPlugin.content_holder ) + self.panesToColor.append(MyPlugin.content_holder) MyPlugin.content_holder.show() - VBox1 = Gtk.Box( orientation=Gtk.Orientation.VERTICAL ) + VBox1 = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) if MyPlugin.heading != "": - Label1 = Gtk.Label(label= MyPlugin.heading ) - Align1 = Gtk.Alignment.new( 0, 0, 0, 0 ) - Align1.set_padding( 10, 5, 10, 0 ) - Align1.add( Label1 ) - self.headingsToColor.append( Label1 ) + Label1 = Gtk.Label(label= MyPlugin.heading) + Align1 = Gtk.Alignment.new(0, 0, 0, 0) + Align1.set_padding(10, 5, 10, 0) + Align1.add(Label1) + self.headingsToColor.append(Label1) 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 ) - heading.set_size_request( MyPlugin.width, 30 ) + Align1.set_padding(0, 0, 10, 0) + heading.set_visible_window(False) + heading.set_size_request(MyPlugin.width, 30) else: - heading = Gtk.Box( orientation=Gtk.Orientation.HORIZONTAL ) - #heading.set_relief( Gtk.ReliefStyle.NONE ) - heading.set_size_request( MyPlugin.width, -1 ) + heading = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) + #heading.set_relief(Gtk.ReliefStyle.NONE) + heading.set_size_request(MyPlugin.width, -1) #heading.set_sensitive(False) - #heading.connect( "button_press_event", self.TogglePluginView, VBox1, MyPlugin.icon, MyPlugin.heading, MyPlugin ) + #heading.connect("button_press_event", self.TogglePluginView, VBox1, MyPlugin.icon, MyPlugin.heading, MyPlugin) - heading.add( Align1 ) + heading.add(Align1) heading.show() - VBox1.pack_start( heading, False, False, 0 ) + VBox1.pack_start(heading, False, False, 0) VBox1.show() #Add plugin to Plugin Box under heading button MyPlugin.content_holder.get_parent().remove(MyPlugin.content_holder) - VBox1.add( MyPlugin.content_holder ) + VBox1.add(MyPlugin.content_holder) #Add plugin to main window - PaneLadder.pack_start( VBox1 , True, True, 0) + PaneLadder.pack_start(VBox1 , True, True, 0) PaneLadder.show() try: @@ -252,84 +251,84 @@ class MainWindow( object ): pass try: - if hasattr( MyPlugin, 'do_plugin' ): + if hasattr(MyPlugin, 'do_plugin'): MyPlugin.do_plugin() - if hasattr( MyPlugin, 'height' ): - MyPlugin.content_holder.set_size_request( -1, MyPlugin.height ) - if hasattr( MyPlugin, 'itemstocolor' ): - self.panesToColor.extend( MyPlugin.itemstocolor ) - if hasattr( MyPlugin, 'headingstocolor' ): - self.headingsToColor.extend( MyPlugin.headingstocolor ) + if hasattr(MyPlugin, 'height'): + MyPlugin.content_holder.set_size_request(-1, MyPlugin.height) + if hasattr(MyPlugin, 'itemstocolor'): + self.panesToColor.extend(MyPlugin.itemstocolor) + if hasattr(MyPlugin, 'headingstocolor'): + self.headingsToColor.extend(MyPlugin.headingstocolor) except: # create traceback info = sys.exc_info() - error = _("Couldn't initialize plugin") + " " + plugin + " : " + "\n".join(traceback.format_exception( info[0], info[1], info[2] )).replace("\\n", "\n") - msgDlg = Gtk.MessageDialog( None, Gtk.DialogFlags.MODAL, Gtk.MessageType.ERROR, Gtk.ButtonsType.OK, error ) + error = _("Couldn't initialize plugin") + " " + plugin + " : " + "\n".join(traceback.format_exception(info[0], info[1], info[2])).replace("\\n", "\n") + msgDlg = Gtk.MessageDialog(None, Gtk.DialogFlags.MODAL, Gtk.MessageType.ERROR, Gtk.ButtonsType.OK, error) msgDlg.run() msgDlg.destroy() self.plugins[plugin] = MyPlugin else: - self.paneholder.pack_start( ImageBox, False, False, 0 ) - self.paneholder.pack_start( PluginPane, False, False, 0 ) + self.paneholder.pack_start(ImageBox, False, False, 0) + self.paneholder.pack_start(PluginPane, False, False, 0) PluginPane = Gtk.EventBox() - PaneLadder = Gtk.Box( orientation=Gtk.Orientation.VERTICAL ) - PluginPane.add( PaneLadder ) + PaneLadder = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) + PluginPane.add(PaneLadder) ImageBox = Gtk.EventBox() - self.panesToColor.extend( [ PluginPane, ImageBox ] ) + self.panesToColor.extend([PluginPane, ImageBox]) ImageBox.show() PluginPane.show_all() - if self.plugins and hasattr( MyPlugin, 'hideseparator' ) and not MyPlugin.hideseparator: + if self.plugins and hasattr(MyPlugin, 'hideseparator') and not MyPlugin.hideseparator: Image1 = Gtk.Image() - Image1.set_from_pixbuf( seperatorImage ) + Image1.set_from_pixbuf(seperatorImage) Image1.show() - #ImageBox.add( Image1 ) + #ImageBox.add(Image1) Align1 = Gtk.Alignment.new(0, 0, 0, 0) - Align1.set_padding( 0, 0, 6, 6 ) + Align1.set_padding(0, 0, 6, 6) Align1.add(Image1) ImageBox.add(Align1) ImageBox.show_all() - self.paneholder.pack_start( ImageBox, False, False, 0 ) - self.paneholder.pack_start( PluginPane, False, False, 0 ) - self.tooltipsEnable( False ) + self.paneholder.pack_start(ImageBox, False, False, 0) + self.paneholder.pack_start(PluginPane, False, False, 0) + self.tooltipsEnable(False) # A little bit hacky but works. - def getDefaultColors( self ): + def getDefaultColors(self): widget = Gtk.EventBox() widget.show() context = widget.get_style_context() - context.set_state( Gtk.StateFlags.NORMAL ) - context.add_class( Gtk.STYLE_CLASS_DEFAULT ) - context.add_class( Gtk.STYLE_CLASS_BACKGROUND ) + context.set_state(Gtk.StateFlags.NORMAL) + context.add_class(Gtk.STYLE_CLASS_DEFAULT) + context.add_class(Gtk.STYLE_CLASS_BACKGROUND) - fgColor = context.get_color( context.get_state() ) - bgColor = context.get_background_color( context.get_state() ) + fgColor = context.get_color(context.get_state()) + bgColor = context.get_background_color(context.get_state()) - return { "fg": fgColor, "bg": bgColor } + return {"fg": fgColor, "bg": bgColor} - def loadTheme( self ): + def loadTheme(self): colors = self.getDefaultColors() - self.SetPaneColors( self.panesToColor, colors["bg"] ) - self.SetHeadingStyle( self.headingsToColor ) + self.SetPaneColors(self.panesToColor, colors["bg"]) + self.SetHeadingStyle(self.headingsToColor) - def SetPaneColors( self, items, color = None ): + def SetPaneColors(self, items, color = None): for item in items: context = item.get_style_context() if self.usecustomcolor: bgColor = Gdk.RGBA() - bgColor.parse( self.customcolor ) - item.override_background_color( context.get_state(), bgColor ) + bgColor.parse(self.customcolor) + item.override_background_color(context.get_state(), bgColor) elif color is not None: - item.override_background_color( context.get_state(), color ) + item.override_background_color(context.get_state(), color) - def SetHeadingStyle( self, items ): + def SetHeadingStyle(self, items): if self.usecustomcolor: color = self.customheadingcolor else: @@ -342,24 +341,24 @@ class MainWindow( object ): markup = '%s' % (text) else: markup = '%s' % (color, text) - item.set_markup( markup ) + item.set_markup(markup) - def tooltipsEnable( self, enable = True ): + def tooltipsEnable(self, enable = True): for widget in self.tooltipsWidgets: - widget.set_has_tooltip( enable ) + widget.set_has_tooltip(enable) - def setTooltip( self, widget, tip ): - self.tooltipsWidgets.append( widget ) - widget.set_tooltip_text( tip ) + def setTooltip(self, widget, tip): + self.tooltipsWidgets.append(widget) + widget.set_tooltip_text(tip) - def RegenPlugins( self, *args, **kargs ): + def RegenPlugins(self, *args, **kargs): #print #print u"Reloading Plugins..." for item in self.paneholder: item.destroy() for plugin in self.plugins.values(): - if hasattr( plugin, "destroy" ): + if hasattr(plugin, "destroy"): plugin.destroy() try: @@ -380,13 +379,13 @@ class MainWindow( object ): #print NAME+u" reloaded" - def onKeyPress( self, widget, event ): + def onKeyPress(self, widget, event): if event.keyval == Gdk.KEY_Escape: self.hide() return True return False - def show( self ): + def show(self): self.window.present() # Hack for opacity not showing on first composited draw @@ -394,43 +393,44 @@ class MainWindow( object ): self.firstTime = False self.window.set_opacity(1.0) - self.window.get_window().focus( Gdk.CURRENT_TIME ) + self.window.get_window().focus(Gdk.CURRENT_TIME) for plugin in self.plugins.values(): - if hasattr( plugin, "onShowMenu" ): + 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() - def hide( self ): + def hide(self): for plugin in self.plugins.values(): - if hasattr( plugin, "onHideMenu" ): + if hasattr(plugin, "onHideMenu"): plugin.onHideMenu() self.window.hide() - def onFocusIn( self, *args ): + def onFocusIn(self, *args): if self.loseFocusBlocked: - self.window.handler_unblock( self.loseFocusId ) + self.window.handler_unblock(self.loseFocusId) self.loseFocusBlocked = False return False - def onFocusOut( self, *args): + def onFocusOut(self, *args): if self.window.get_visible(): self.hide() return False - def stopHiding( self ): + def stopHiding(self): if not self.loseFocusBlocked: - self.window.handler_block( self.loseFocusId ) + self.window.handler_block(self.loseFocusId) self.loseFocusBlocked = True -class MenuWin( object ): - def __init__( self, applet, iid ): +class MenuWin(object): + + def __init__(self, applet, iid): self.applet = applet self.detect_desktop_environment() self.settings = Gio.Settings.new("com.linuxmint.mintmenu") @@ -439,40 +439,40 @@ class MenuWin( object ): self.createPanelButton() self.mate_settings = Gio.Settings.new("org.mate.interface") - self.mate_settings.connect( "changed::gtk-theme", self.changeTheme ) + self.mate_settings.connect("changed::gtk-theme", self.changeTheme) - self.settings.connect( "changed::applet-text", self.reloadSettings ) - self.settings.connect( "changed::theme-name", self.changeTheme ) - self.settings.connect( "changed::hot-key", self.reloadSettings ) - self.settings.connect( "changed::applet-icon", self.reloadSettings ) - self.settings.connect( "changed::hide-applet-icon", self.reloadSettings ) - self.settings.connect( "changed::applet-icon-size", self.reloadSettings ) + self.settings.connect("changed::applet-text", self.reloadSettings) + self.settings.connect("changed::theme-name", self.changeTheme) + self.settings.connect("changed::hot-key", self.reloadSettings) + self.settings.connect("changed::applet-icon", self.reloadSettings) + self.settings.connect("changed::hide-applet-icon", self.reloadSettings) + self.settings.connect("changed::applet-icon-size", self.reloadSettings) - self.applet.set_flags( MatePanelApplet.AppletFlags.EXPAND_MINOR ) - self.applet.connect( "button-press-event", self.showMenu ) - self.applet.connect( "change-orient", self.changeOrientation ) + self.applet.set_flags(MatePanelApplet.AppletFlags.EXPAND_MINOR) + self.applet.connect("button-press-event", self.showMenu) + self.applet.connect("change-orient", self.changeOrientation) self.applet.connect("enter-notify-event", self.enter_notify) self.applet.connect("leave-notify-event", self.leave_notify) - self.mainwin = MainWindow( self.button_box, self.settings, self.de ) - self.mainwin.window.connect( "map-event", self.onWindowMap ) - self.mainwin.window.connect( "unmap-event", self.onWindowUnmap ) - self.mainwin.window.connect( "size-allocate", lambda *args: self.positionMenu() ) + self.mainwin = MainWindow(self.button_box, self.settings, self.de) + self.mainwin.window.connect("map-event", self.onWindowMap) + self.mainwin.window.connect("unmap-event", self.onWindowUnmap) + self.mainwin.window.connect("size-allocate", lambda *args: self.positionMenu()) self.mainwin.window.set_name("mintmenu") # Name used in Gtk RC files self.applyTheme() self.mainwin.loadTheme() if self.mainwin.icon: - Gtk.Window.set_default_icon_name( self.mainwin.icon ) + Gtk.Window.set_default_icon_name(self.mainwin.icon) try: self.keybinder = keybinding.GlobalKeyBinding() if self.hotkeyText != "": - self.keybinder.grab( self.hotkeyText ) + self.keybinder.grab(self.hotkeyText) self.keybinder.connect("activate", self.onBindingPress) self.keybinder.start() - self.settings.connect( "changed::hot-key", self.hotkeyChanged ) + self.settings.connect("changed::hot-key", self.hotkeyChanged) print "Binding to Hot Key: " + self.hotkeyText except Exception, cause: self.keybinder = None @@ -484,28 +484,28 @@ class MenuWin( object ): try: self.pointerMonitor = pointerMonitor.PointerMonitor() self.pointerMonitor.connect("activate", self.onPointerOutside) - self.mainwin.window.connect( "realize", self.onRealize ) + self.mainwin.window.connect("realize", self.onRealize) except Exception, cause: print "** WARNING ** - Pointer Monitor Error" print "Error Report :\n", str(cause) - def onWindowMap( self, *args ): - self.applet.get_style_context().set_state( Gtk.StateFlags.SELECTED ) - self.button_box.get_style_context().set_state( Gtk.StateFlags.SELECTED ) + def onWindowMap(self, *args): + self.applet.get_style_context().set_state(Gtk.StateFlags.SELECTED) + self.button_box.get_style_context().set_state(Gtk.StateFlags.SELECTED) if self.keybinder is not None: - self.keybinder.set_focus_window( self.mainwin.window.get_window() ) + self.keybinder.set_focus_window(self.mainwin.window.get_window()) return False - def onWindowUnmap( self, *args ): - self.applet.get_style_context().set_state( Gtk.StateFlags.NORMAL ) - self.button_box.get_style_context().set_state( Gtk.StateFlags.NORMAL ) + def onWindowUnmap(self, *args): + self.applet.get_style_context().set_state(Gtk.StateFlags.NORMAL) + self.button_box.get_style_context().set_state(Gtk.StateFlags.NORMAL) if self.keybinder is not None: self.keybinder.set_focus_window() return False - def onRealize( self, *args): - self.pointerMonitor.addWindowToMonitor( self.mainwin.window.get_window() ) - self.pointerMonitor.addWindowToMonitor( self.applet.get_window() ) + def onRealize(self, *args): + self.pointerMonitor.addWindowToMonitor(self.mainwin.window.get_window()) + self.pointerMonitor.addWindowToMonitor(self.applet.get_window()) self.pointerMonitor.start() return False @@ -537,10 +537,10 @@ class MenuWin( object ): GdkPixbuf.Pixbuf.saturate_and_pixelate(pixbuf, pixbuf, 1.5, False) self.button_icon.set_from_pixbuf(pixbuf) - def createPanelButton( self ): + def createPanelButton(self): self.button_icon = Gtk.Image() self.do_image(self.buttonIcon, False) - self.systemlabel = Gtk.Label(label= "%s " % self.buttonText ) + 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: @@ -550,44 +550,44 @@ class MenuWin( object ): 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 ) - self.button_box.pack_start( self.systemlabel, False, False, 0 ) - self.button_icon.set_padding( 5, 0 ) + self.button_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) + self.button_box.pack_start(self.button_icon, False, False, 0) + self.button_box.pack_start(self.systemlabel, False, False, 0) + self.button_icon.set_padding(5, 0) # if we have a vertical panel elif self.applet.get_orient() == MatePanelApplet.AppletOrient.LEFT: - self.button_box = Gtk.Box( orientation=Gtk.Orientation.VERTICAL ) - self.systemlabel.set_angle( 270 ) - self.button_box.pack_start( self.button_icon , False, False, 0) - self.button_box.pack_start( self.systemlabel , False, False, 0) - self.button_icon.set_padding( 0, 5 ) + self.button_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) + self.systemlabel.set_angle(270) + self.button_box.pack_start(self.button_icon , False, False, 0) + self.button_box.pack_start(self.systemlabel , False, False, 0) + self.button_icon.set_padding(0, 5) elif self.applet.get_orient() == MatePanelApplet.AppletOrient.RIGHT: - self.button_box = Gtk.Box( orientation=Gtk.Orientation.VERTICAL ) - self.systemlabel.set_angle( 90 ) - self.button_box.pack_start( self.systemlabel , False, False, 0) - self.button_box.pack_start( self.button_icon , False, False, 0) - self.button_icon.set_padding( 0, 5 ) + self.button_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) + self.systemlabel.set_angle(90) + self.button_box.pack_start(self.systemlabel , False, False, 0) + 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.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 ) + 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" ) + def loadSettings(self, *args, **kargs): + self.hideIcon = self.settings.get_boolean("hide-applet-icon") self.buttonText = self.settings.get_string("applet-text") - self.theme_name = self.settings.get_string( "theme-name" ) - self.hotkeyText = self.settings.get_string( "hot-key" ) + self.theme_name = self.settings.get_string("theme-name") + self.hotkeyText = self.settings.get_string("hot-key") if not os.path.exists(self.settings.get_string("applet-icon")): self.settings.reset("applet-icon") - self.buttonIcon = self.settings.get_string( "applet-icon" ) - self.iconSize = self.settings.get_int( "applet-icon-size" ) + self.buttonIcon = self.settings.get_string("applet-icon") + self.iconSize = self.settings.get_int("applet-icon-size") def changeTheme(self, *args): self.reloadSettings() @@ -605,28 +605,28 @@ class MenuWin( object ): except: style_settings.set_property("gtk-theme-name", desktop_theme) - def changeOrientation( self, *args, **kargs ): + def changeOrientation(self, *args, **kargs): if self.applet.get_orient() == MatePanelApplet.AppletOrient.UP or self.applet.get_orient() == MatePanelApplet.AppletOrient.DOWN: - tmpbox = Gtk.Box( orientation=Gtk.Orientation.HORIZONTAL ) - self.systemlabel.set_angle( 0 ) - self.button_box.reorder_child( self.button_icon, 0 ) - self.button_icon.set_padding( 5, 0 ) + tmpbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) + self.systemlabel.set_angle(0) + self.button_box.reorder_child(self.button_icon, 0) + self.button_icon.set_padding(5, 0) elif self.applet.get_orient() == MatePanelApplet.AppletOrient.LEFT: - tmpbox = Gtk.Box( orientation=Gtk.Orientation.VERTICAL ) - self.systemlabel.set_angle( 270 ) - self.button_box.reorder_child( self.button_icon, 0 ) - self.button_icon.set_padding( 0, 5 ) + tmpbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) + self.systemlabel.set_angle(270) + self.button_box.reorder_child(self.button_icon, 0) + self.button_icon.set_padding(0, 5) elif self.applet.get_orient() == MatePanelApplet.AppletOrient.RIGHT: - tmpbox = Gtk.Box( orientation=Gtk.Orientation.VERTICAL ) - self.systemlabel.set_angle( 90 ) - self.button_box.reorder_child( self.button_icon, 1 ) - self.button_icon.set_padding( 0, 5 ) + tmpbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) + self.systemlabel.set_angle(90) + self.button_box.reorder_child(self.button_icon, 1) + self.button_icon.set_padding(0, 5) - tmpbox.set_homogeneous( False ) + tmpbox.set_homogeneous(False) # reparent all the hboxes to the new tmpbox for i in self.button_box: - i.reparent( tmpbox ) + i.reparent(tmpbox) self.button_box.destroy() @@ -635,20 +635,20 @@ class MenuWin( object ): # this call makes sure width stays intact self.updateButton() - self.applet.add( self.button_box ) + self.applet.add(self.button_box) - def updateButton( self ): - self.systemlabel.set_text( self.buttonText ) + def updateButton(self): + self.systemlabel.set_text(self.buttonText) self.button_icon.clear() self.do_image(self.buttonIcon, False) self.sizeButton() - def hotkeyChanged (self, schema, key ): - self.hotkeyText = self.settings.get_string( "hot-key" ) + def hotkeyChanged (self, schema, key): + self.hotkeyText = self.settings.get_string("hot-key") self.keybinder.rebind(self.hotkeyText) - def sizeButton( self ): + def sizeButton(self): if self.hideIcon: self.button_icon.hide() else: @@ -662,20 +662,20 @@ class MenuWin( object ): sl_scale = self.systemlabel.get_scale_factor() if self.applet.get_orient() == MatePanelApplet.AppletOrient.UP or self.applet.get_orient() == MatePanelApplet.AppletOrient.DOWN: if self.hideIcon: - self.applet.set_size_request( sl_req.width / sl_scale + 2, bi_req.height ) + self.applet.set_size_request(sl_req.width / sl_scale + 2, bi_req.height) else: - self.applet.set_size_request( sl_req.width / sl_scale + bi_req.width / bi_scale + 5, bi_req.height ) + self.applet.set_size_request(sl_req.width / sl_scale + bi_req.width / bi_scale + 5, bi_req.height) else: if self.hideIcon: - self.applet.set_size_request( bi_req.width, sl_req.height / sl_scale + 2 ) + self.applet.set_size_request(bi_req.width, sl_req.height / sl_scale + 2) else: - self.applet.set_size_request( bi_req.width, sl_req.height / sl_scale + bi_req.height / bi_scale + 5 ) + self.applet.set_size_request(bi_req.width, sl_req.height / sl_scale + bi_req.height / bi_scale + 5) - def reloadSettings( self, *args ): + def reloadSettings(self, *args): self.loadSettings() self.updateButton() - def showAboutDialog( self, action, userdata = None ): + def showAboutDialog(self, action, userdata = None): about = Gtk.AboutDialog() about.set_name("mintMenu") @@ -692,23 +692,23 @@ class MenuWin( object ): about.set_license(gpl) except Exception, detail: print detail - about.set_comments( _("Advanced MATE Menu") ) - # about.set_authors( ["Clement Lefebvre ", "Lars-Peter Clausen "] ) - about.set_translator_credits(("translator-credits") ) - #about.set_copyright( _("Based on USP from S.Chanderbally") ) - about.set_logo( GdkPixbuf.Pixbuf.new_from_file("/usr/lib/linuxmint/mintMenu/icon.svg") ) - about.connect( "response", lambda dialog, r: dialog.destroy() ) + about.set_comments(_("Advanced MATE Menu")) + # about.set_authors(["Clement Lefebvre ", "Lars-Peter Clausen "]) + about.set_translator_credits(("translator-credits")) + # about.set_copyright(_("Based on USP from S.Chanderbally")) + about.set_logo(GdkPixbuf.Pixbuf.new_from_file("/usr/lib/linuxmint/mintMenu/icon.svg")) + 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" ) ) + def showPreferences(self, action, userdata = None): + # Execute("mateconf-editor /apps/mintMenu") + Execute(os.path.join(PATH, "mintMenuConfig.py")) - def showMenuEditor( self, action, userdata = None): - Execute( "mozo" ) + def showMenuEditor(self, action, userdata = None): + Execute("mozo") - def showMenu( self, widget=None, event=None ): + def showMenu(self, widget=None, event=None): if event == None or event.button == 1: self.toggleMenu() # show right click menu @@ -718,7 +718,7 @@ class MenuWin( object ): elif event.button == 2: self.mainwin.hide() - def toggleMenu( self ): + def toggleMenu(self): if self.applet.get_style_context().get_state() & Gtk.StateFlags.SELECTED: self.mainwin.hide() else: @@ -726,10 +726,10 @@ class MenuWin( object ): self.mainwin.show() self.wakePlugins() - def wakePlugins( self ): + def wakePlugins(self): self.mainwin.wakePlugins() - def positionMenu( self ): + def positionMenu(self): # Get our own dimensions & position ourWidth = self.mainwin.window.get_size()[0] ourHeight = self.mainwin.window.get_size()[1] + self.mainwin.offset @@ -796,7 +796,7 @@ class MenuWin( object ): newY -= entryHeight # Move window - self.mainwin.window.move( newX, newY ) + self.mainwin.window.move(newX, newY) # this callback is to create a context menu def create_menu(self): @@ -815,7 +815,7 @@ class MenuWin( object ): action_group.add_action(action) action_group.set_translation_domain ("mintmenu") - xml = os.path.join( os.path.join( os.path.dirname( __file__ )), "popup.xml" ) + xml = os.path.join(os.path.join(os.path.dirname(__file__)), "popup.xml") self.applet.setup_menu_from_file(xml, action_group) def detect_desktop_environment (self): @@ -834,8 +834,8 @@ class MenuWin( object ): except Exception, detail: print detail -def applet_factory( applet, iid, data ): - MenuWin( applet, iid ) +def applet_factory(applet, iid, data): + MenuWin(applet, iid) applet.show() return True diff --git a/usr/lib/linuxmint/mintMenu/plugins/applications.py b/usr/lib/linuxmint/mintMenu/plugins/applications.py index f59d0ff..766eade 100755 --- a/usr/lib/linuxmint/mintMenu/plugins/applications.py +++ b/usr/lib/linuxmint/mintMenu/plugins/applications.py @@ -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") @@ -83,83 +84,83 @@ def rel_path(target, base=os.curdir): class Menu: - def __init__( self, MenuToLookup ): - self.tree = matemenu.lookup_tree( MenuToLookup ) + def __init__(self, MenuToLookup): + self.tree = matemenu.lookup_tree(MenuToLookup) self.directory = self.tree.get_root_directory() - def getMenus( self, parent=None ): + def getMenus(self, parent=None): if parent == None: #gives top-level "Applications" item yield self.tree.root else: for menu in parent.get_contents(): - if menu.get_type() == matemenu.TYPE_DIRECTORY and self.__isVisible( menu ): + if menu.get_type() == matemenu.TYPE_DIRECTORY and self.__isVisible(menu): yield menu - def getItems( self, 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 ): + def __isVisible(self, item): if item.get_type() == matemenu.TYPE_ENTRY: - return not ( item.get_is_excluded() or item.get_is_nodisplay() ) - if item.get_type() == matemenu.TYPE_DIRECTORY and len( item.get_contents() ): + return not(item.get_is_excluded() or item.get_is_nodisplay()) + if item.get_type() == matemenu.TYPE_DIRECTORY and len(item.get_contents()): return True -class SuggestionButton ( Gtk.Button ): +class SuggestionButton(Gtk.Button): - def __init__( self, iconName, iconSize, label ): - Gtk.Button.__init__( self ) + 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 ) + 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 ) + 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.set_from_icon_name(self.iconName, Gtk.IconSize.INVALID) + self.image.set_pixel_size(iconSize) self.image.show() - HBox1.pack_start( self.image, False, False, 5 ) + HBox1.pack_start(self.image, False, False, 5) self.label = Gtk.Label() - self.label.set_ellipsize( Pango.EllipsizeMode.END ) - self.label.set_alignment( 0.0, 1.0 ) + self.label.set_ellipsize(Pango.EllipsizeMode.END) + self.label.set_alignment(0.0, 1.0) self.label.show() - labelBox.pack_start( self.label, True, True, 2 ) + labelBox.pack_start(self.label, True, True, 2) labelBox.show() - HBox1.pack_start( labelBox, True, True, 2 ) + HBox1.pack_start(labelBox, True, True, 2) HBox1.show() - Align1.add( HBox1 ) + Align1.add(HBox1) Align1.show() - self.add( Align1 ) + self.add(Align1) self.show() def set_image(self, path): self.image.set_from_file(path) - def set_text( self, text): + def set_text(self, text): self.label.set_markup(text) def set_icon_size (self, size): - self.image.set_pixel_size( size ) + self.image.set_pixel_size(size) -class pluginclass( object ): +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 ): + def __init__(self, mintMenuWin, toggleButton, de): self.mintMenuWin = mintMenuWin RecentHelper.mintMenuWin = mintMenuWin - self.mainMenus = [ ] + self.mainMenus = [] self.toggleButton = toggleButton self.de = de @@ -172,17 +173,17 @@ class pluginclass( object ): self.builder = Gtk.Builder() # The Glade file for the plugin - self.builder.add_from_file (os.path.join( os.path.dirname( __file__ ), "applications.glade" )) + 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") #i18n self.builder.get_object("searchLabel").set_text("" + _("Search:") + "") @@ -198,60 +199,60 @@ 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") # 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 self.menuChangedTimer = None # Hookup for text input - self.keyPress_handler = self.mintMenuWin.window.connect( "key-press-event", self.keyPress ) + self.keyPress_handler = self.mintMenuWin.window.connect("key-press-event", self.keyPress) - self.favoritesBox.connect( "drag-data-received", self.ReceiveCallback ) + 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 ) + 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.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" ) + self.settings = EasyGSettings("com.linuxmint.mintmenu.plugins.applications") self.GetGSettingsEntries() - self.settings.notifyAdd( "icon-size", self.changeIconSize ) - self.settings.notifyAdd( "favicon-size", self.changeFavIconSize ) - self.settings.notifyAdd( "height", self.changePluginSize ) - self.settings.notifyAdd( "width", self.changePluginSize ) - self.settings.notifyAdd( "categories-mouse-over", self.changeCategoriesMouseOver ) - self.settings.notifyAdd( "swap-generic-name", self.changeSwapGenericName ) - self.settings.notifyAdd( "show-category-icons", self.changeShowCategoryIcons ) - self.settings.notifyAdd( "show-application-comments", self.changeShowApplicationComments ) - self.settings.notifyAdd( "use-apt", self.switchAPTUsage) - self.settings.notifyAdd( "fav-cols", self.changeFavCols ) - self.settings.notifyAdd( "remember-filter", self.changeRememberFilter) - self.settings.notifyAdd( "enable-internet-search", self.changeEnableInternetSearch) + self.settings.notifyAdd("icon-size", self.changeIconSize) + self.settings.notifyAdd("favicon-size", self.changeFavIconSize) + self.settings.notifyAdd("height", self.changePluginSize) + self.settings.notifyAdd("width", self.changePluginSize) + self.settings.notifyAdd("categories-mouse-over", self.changeCategoriesMouseOver) + self.settings.notifyAdd("swap-generic-name", self.changeSwapGenericName) + self.settings.notifyAdd("show-category-icons", self.changeShowCategoryIcons) + self.settings.notifyAdd("show-application-comments", self.changeShowApplicationComments) + self.settings.notifyAdd("use-apt", self.switchAPTUsage) + self.settings.notifyAdd("fav-cols", self.changeFavCols) + self.settings.notifyAdd("remember-filter", self.changeRememberFilter) + self.settings.notifyAdd("enable-internet-search", self.changeEnableInternetSearch) - self.settings.bindGSettingsEntryToVar( "int", "category-hover-delay", self, "categoryhoverdelay" ) - self.settings.bindGSettingsEntryToVar( "bool", "do-not-filter", self, "donotfilterapps" ) - 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" ) + self.settings.bindGSettingsEntryToVar("int", "category-hover-delay", self, "categoryhoverdelay") + self.settings.bindGSettingsEntryToVar("bool", "do-not-filter", self, "donotfilterapps") + 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 self.currentFavCol = 0 self.favorites = [] - self.content_holder.set_size_request( self.width, self.height ) - self.categoriesBox.set_size_request( self.width / 3, -1 ) - self.applicationsBox.set_size_request( self.width / 2, -1 ) + self.content_holder.set_size_request(self.width, self.height) + self.categoriesBox.set_size_request(self.width / 3, -1) + self.applicationsBox.set_size_request(self.width / 2, -1) self.buildingButtonList = False self.stopBuildingButtonList = False @@ -267,9 +268,9 @@ class pluginclass( object ): self.adminMenu = None - for mainitems in [ "mate-applications.menu", "mate-settings.menu" ]: - mymenu = Menu( mainitems ) - mymenu.tree.add_monitor( self.menuChanged, None ) + for mainitems in ["mate-applications.menu", "mate-settings.menu"]: + mymenu = Menu(mainitems) + mymenu.tree.add_monitor(self.menuChanged, None) self.refresh_apt_cache() self.suggestions = [] @@ -277,7 +278,7 @@ class pluginclass( object ): self.panel = "top" self.panel_position = -1 - self.builder.get_object("searchButton").connect( "button-press-event", self.searchPopup ) + 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) @@ -306,13 +307,13 @@ class pluginclass( object ): os.system("xdg-open apt://" + pkg_name + " &") self.mintMenuWin.hide() - def __del__( self ): + def __del__(self): print u"Applications plugin deleted" - def wake (self) : + def wake(self): pass - def destroy( self ): + def destroy(self): self.content_holder.destroy() self.searchEntry.destroy() self.searchButton.destroy() @@ -326,24 +327,24 @@ class pluginclass( object ): self.settings.notifyRemoveAll() - def changePluginSize( self, settings, key, args ): + def changePluginSize(self, settings, key, args): if key == "width": self.width = settings.get_int(key) - self.categoriesBox.set_size_request( self.width / 3, -1 ) - self.applicationsBox.set_size_request( self.width / 2, -1 ) + self.categoriesBox.set_size_request(self.width / 3, -1) + self.applicationsBox.set_size_request(self.width / 2, -1) elif key == "height": self.heigth = settings.get_int(key) - self.content_holder.set_size_request( self.width, self.height ) + self.content_holder.set_size_request(self.width, self.height) - def changeSwapGenericName( self, settings, key, args ): + def changeSwapGenericName(self, settings, key, args): self.swapgeneric = settings.get_boolean(key) for child in self.favoritesBox: - if isinstance( child, FavApplicationLauncher): - child.setSwapGeneric( self.swapgeneric ) + if isinstance(child, FavApplicationLauncher): + child.setSwapGeneric(self.swapgeneric) - def changeShowCategoryIcons( self, settings, key, args ): + def changeShowCategoryIcons(self, settings, key, args): self.showcategoryicons = settings.get_boolean(key) if self.showcategoryicons: @@ -352,9 +353,9 @@ class pluginclass( object ): categoryIconSize = 0 for child in self.categoriesBox: - child.setIconSize( categoryIconSize ) + child.setIconSize(categoryIconSize) - def changeIconSize( self, settings, key, args ): + def changeIconSize(self, settings, key, args): self.iconSize = settings.get_int(key) if self.showcategoryicons: @@ -363,55 +364,55 @@ class pluginclass( object ): categoryIconSize = 0 for child in self.categoriesBox: - child.setIconSize( categoryIconSize ) + child.setIconSize(categoryIconSize) for child in self.applicationsBox: try: - child.setIconSize( self.iconSize ) + child.setIconSize(self.iconSize) except: pass - def changeFavIconSize( self, settings, key, args ): + def changeFavIconSize(self, settings, key, args): self.faviconsize = settings.get_int(key) for child in self.favoritesBox: - if isinstance( child, FavApplicationLauncher): - child.setIconSize( self.faviconsize ) + if isinstance(child, FavApplicationLauncher): + child.setIconSize(self.faviconsize) - def switchAPTUsage( self, settings, key, args ): + def switchAPTUsage(self, settings, key, args): self.useAPT = settings.get_boolean(key) self.refresh_apt_cache() - def changeRememberFilter( self, settings, key, args): + def changeRememberFilter(self, settings, key, args): self.rememberFilter = settings.get_boolean(key) - def changeEnableInternetSearch( self, settings, key, args): + def changeEnableInternetSearch(self, settings, key, args): self.enableInternetSearch = settings.get_boolean(key) - def changeShowApplicationComments( self, settings, key, args ): + def changeShowApplicationComments(self, settings, key, args): self.showapplicationcomments = settings.get_boolean(key) for child in self.applicationsBox: - child.setShowComment( self.showapplicationcomments ) + child.setShowComment(self.showapplicationcomments) - def changeCategoriesMouseOver( self, settings, key, args ): + def changeCategoriesMouseOver(self, settings, key, args): self.categories_mouse_over = settings.get_boolean(key) for child in self.categoriesBox: if self.categories_mouse_over and not child.mouseOverHandlerIds: - startId = child.connect( "enter", self.StartFilter, child.filter ) - stopId = child.connect( "leave", self.StopFilter ) - child.mouseOverHandlerIds = ( startId, stopId ) + startId = child.connect("enter", self.StartFilter, child.filter) + stopId = child.connect("leave", self.StopFilter) + child.mouseOverHandlerIds = (startId, stopId) elif not self.categories_mouse_over and child.mouseOverHandlerIds: - child.disconnect( child.mouseOverHandlerIds[0] ) - child.disconnect( child.mouseOverHandlerIds[1] ) + child.disconnect(child.mouseOverHandlerIds[0]) + child.disconnect(child.mouseOverHandlerIds[1]) child.mouseOverHandlerIds = None def changeFavCols(self, settings, key, args): self.favCols = settings.get_int(key) for fav in self.favorites: - self.favoritesBox.remove( fav ) - self.favoritesPositionOnGrid( fav ) + self.favoritesBox.remove(fav) + self.favoritesPositionOnGrid(fav) - def RegenPlugin( self, *args, **kargs ): + 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 @@ -440,140 +441,140 @@ class pluginclass( object ): RecentHelper.buildRecentApps() self.RebuildPlugin() - def GetGSettingsEntries( self ): + def GetGSettingsEntries(self): - self.categories_mouse_over = self.settings.get( "bool", "categories-mouse-over") - self.width = self.settings.get( "int", "width") - self.height = self.settings.get( "int", "height") - self.donotfilterapps = self.settings.get( "bool", "do-not-filter") - self.iconSize = self.settings.get( "int", "icon-size") - self.faviconsize = self.settings.get( "int", "favicon-size") - self.favCols = self.settings.get( "int", "fav-cols") - self.swapgeneric = self.settings.get( "bool", "swap-generic-name") - self.showcategoryicons = self.settings.get( "bool", "show-category-icons") - self.categoryhoverdelay = self.settings.get( "int", "category-hover-delay") - self.showapplicationcomments = self.settings.get( "bool", "show-application-comments") - self.useAPT = self.settings.get( "bool", "use-apt") - self.rememberFilter = self.settings.get( "bool", "remember-filter") - self.enableInternetSearch = self.settings.get( "bool", "enable-internet-search") + self.categories_mouse_over = self.settings.get("bool", "categories-mouse-over") + self.width = self.settings.get("int", "width") + self.height = self.settings.get("int", "height") + self.donotfilterapps = self.settings.get("bool", "do-not-filter") + self.iconSize = self.settings.get("int", "icon-size") + self.faviconsize = self.settings.get("int", "favicon-size") + self.favCols = self.settings.get("int", "fav-cols") + self.swapgeneric = self.settings.get("bool", "swap-generic-name") + self.showcategoryicons = self.settings.get("bool", "show-category-icons") + self.categoryhoverdelay = self.settings.get("int", "category-hover-delay") + self.showapplicationcomments = self.settings.get("bool", "show-application-comments") + self.useAPT = self.settings.get("bool", "use-apt") + self.rememberFilter = self.settings.get("bool", "remember-filter") + self.enableInternetSearch = self.settings.get("bool", "enable-internet-search") - self.lastActiveTab = self.settings.get( "int", "last-active-tab") - self.defaultTab = self.settings.get( "int", "default-tab") + 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") + self.sticky = self.settings.get("bool", "sticky") + self.minimized = self.settings.get("bool", "minimized") # Search tool - self.searchtool = self.settings.get( "string", "search-command") + self.searchtool = self.settings.get("string", "search-command") if self.searchtool == "beagle-search SEARCH_STRING": self.searchtool = "mate-search-tool --named \"%s\" --start" - self.settings.set( "string", "search-command", "mate-search-tool --named \"%s\" --start" ) + self.settings.set("string", "search-command", "mate-search-tool --named \"%s\" --start") # Plugin icon - self.icon = self.settings.get( "string", "icon" ) + self.icon = self.settings.get("string", "icon") # Hide vertical dotted separator - self.hideseparator = self.settings.get( "bool", "hide-separator") + self.hideseparator = self.settings.get("bool", "hide-separator") - def SetHidden( self, state ): - if state == True: - self.settings.set( "bool", "minimized", True ) + def SetHidden(self, minimized): + if minimized: + self.settings.set("bool", "minimized", True) else: - self.settings.set( "bool", "minimized", False ) + self.settings.set("bool", "minimized", False) def RebuildPlugin(self): - self.content_holder.set_size_request( self.width, self.height ) + self.content_holder.set_size_request(self.width, self.height) - def checkMintMenuFolder( self ): - if os.path.exists( os.path.join( os.path.expanduser( "~" ), ".linuxmint", "mintMenu", "applications" ) ): + def checkMintMenuFolder(self): + if os.path.exists(os.path.join(os.path.expanduser("~"), ".linuxmint", "mintMenu", "applications")): return True try: - os.makedirs( os.path.join( os.path.expanduser( "~" ), ".linuxmint", "mintMenu", "applications" ) ) + os.makedirs(os.path.join(os.path.expanduser("~"), ".linuxmint", "mintMenu", "applications")) return True except: pass return False - def onShowMenu( self ): - if len( self.favorites ): + def onShowMenu(self): + if len(self.favorites): if self.defaultTab == -1: - self.changeTab( self.lastActiveTab) + self.changeTab(self.lastActiveTab) else: - self.changeTab( (self.defaultTab - 1) * -1 ) + self.changeTab((self.defaultTab - 1) * -1) else: - self.changeTab( 1 ) + self.changeTab(1) if self.rememberFilter and self.searchEntry.get_text().strip() != "": self.Filter(self.activeFilter[2], self.activeFilter[1]) - def onHideMenu( self ): - self.settings.set( "int", "last-active-tab", self.lastActiveTab ) + def onHideMenu(self): + self.settings.set("int", "last-active-tab", self.lastActiveTab) - def changeTab( self, tabNum, clear = True ): - notebook = self.builder.get_object( "notebook2" ) + def changeTab(self, tabNum, clear = True): + notebook = self.builder.get_object("notebook2") if tabNum == 0: - notebook.set_current_page( 0 ) + notebook.set_current_page(0) elif tabNum == 1: - notebook.set_current_page( 1 ) + notebook.set_current_page(1) self.focusSearchEntry(clear) self.lastActiveTab = tabNum - def Todos( self ): - self.searchEntry.connect( "popup-menu", self.blockOnPopup ) - self.searchEntry.connect( "button-press-event", self.blockOnRightPress ) - self.searchEntry.connect( "changed", self.Filter ) - self.searchEntry.connect( "activate", self.Search ) - self.showAllAppsButton.connect( "clicked", lambda widget: self.changeTab( 1 ) ) - self.showFavoritesButton.connect( "clicked", lambda widget: self.changeTab( 0 ) ) + def Todos(self): + self.searchEntry.connect("popup-menu", self.blockOnPopup) + self.searchEntry.connect("button-press-event", self.blockOnRightPress) + self.searchEntry.connect("changed", self.Filter) + self.searchEntry.connect("activate", self.Search) + self.showAllAppsButton.connect("clicked", lambda widget: self.changeTab(1)) + self.showFavoritesButton.connect("clicked", lambda widget: self.changeTab(0)) self.buildButtonList() - def blockOnPopup( self, *args ): + def blockOnPopup(self, *args): self.mintMenuWin.stopHiding() return False - def blockOnRightPress( self, widget, event ): + def blockOnRightPress(self, widget, event): if event.button == 3: self.mintMenuWin.stopHiding() return False - def focusSearchEntry( self, clear = True ): + def focusSearchEntry(self, clear = True): # grab_focus() does select all text, # restoring the original selection is somehow broken, so just select the end # of the existing text, that's the most likely candidate anyhow self.searchEntry.grab_focus() if self.rememberFilter or not clear: - self.searchEntry.select_region( 0, -1 ) + self.searchEntry.select_region(0, -1) else: self.searchEntry.set_text("") - def buildButtonList( self ): + def buildButtonList(self): if self.buildingButtonList: self.stopBuildingButtonList = True - GLib.timeout_add( 100, self.buildButtonList ) + GLib.timeout_add(100, self.buildButtonList) return self.stopBuildingButtonList = False self.updateBoxes(False) - def categoryBtnFocus( self, widget, event, category ): - self.scrollItemIntoView( widget ) - self.StartFilter( widget, category ) + def categoryBtnFocus(self, widget, event, category): + self.scrollItemIntoView(widget) + self.StartFilter(widget, category) - def StartFilter( self, widget, category ): + def StartFilter(self, widget, category): # if there is a timer for a different category running stop it if self.filterTimer: - GLib.source_remove( self.filterTimer ) - self.filterTimer = GLib.timeout_add( self.categoryhoverdelay, self.Filter, widget, category ) + GLib.source_remove(self.filterTimer) + self.filterTimer = GLib.timeout_add(self.categoryhoverdelay, self.Filter, widget, category) - def StopFilter( self, widget ): + def StopFilter(self, widget): if self.filterTimer: - GLib.source_remove( self.filterTimer ) + GLib.source_remove(self.filterTimer) self.filterTimer = None def add_search_suggestions(self, text): @@ -596,7 +597,7 @@ class pluginclass( object ): self.suggestions.append(suggestionButton) separator = Gtk.EventBox() - separator.add(Gtk.Separator( orientation=Gtk.Orientation.HORIZONTAL )) + separator.add(Gtk.Separator(orientation=Gtk.Orientation.HORIZONTAL)) separator.set_visible_window(False) separator.set_size_request(-1, 20) separator.type = "separator" @@ -618,10 +619,10 @@ class pluginclass( object ): self.suggestions.append(suggestionButton) #self.last_separator = Gtk.EventBox() - #self.last_separator.add(Gtk.Separator( orientation=Gtk.Orientation.HORIZONTAL )) + #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.mintMenuWin.SetPaneColors([ self.last_separator]) #self.last_separator.show_all() #self.applicationsBox.add(self.last_separator) #self.suggestions.append(self.last_separator) @@ -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") @@ -757,7 +758,7 @@ class pluginclass( object ): except Exception, detail: print detail - def Filter( self, widget, category = None ): + def Filter(self, widget, category = None): self.filterTimer = None for suggestion in self.suggestions: @@ -766,17 +767,17 @@ class pluginclass( object ): if widget == self.searchEntry: if self.donotfilterapps: - widget.set_text( "" ) + widget.set_text("") else: text = widget.get_text() if self.lastActiveTab != 1: - self.changeTab( 1, clear = False ) + self.changeTab(1, clear = False) text = widget.get_text() showns = False # Are any app shown? shownList = [] for i in self.applicationsBox.get_children(): - shown = i.filterText( text ) - if (shown): + shown = i.filterText(text) + 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... @@ -798,11 +799,11 @@ class pluginclass( object ): #if (len(self.current_results) > 0): #self.add_apt_filter_results_sync(self.current_results, text) #else: - GLib.timeout_add (300, self.add_apt_filter_results, text) + GLib.timeout_add(300, self.add_apt_filter_results, text) else: self.current_results = [] self.add_search_suggestions(text) - GLib.timeout_add (300, self.add_apt_filter_results, text) + GLib.timeout_add(300, self.add_apt_filter_results, text) self.current_suggestion = text else: @@ -814,10 +815,10 @@ class pluginclass( object ): for i in self.categoriesBox.get_children(): i.released() - i.set_relief( Gtk.ReliefStyle.NONE ) + i.set_relief(Gtk.ReliefStyle.NONE) allButton = self.categoriesBox.get_children()[0] - allButton.set_relief( Gtk.ReliefStyle.HALF ) + allButton.set_relief(Gtk.ReliefStyle.HALF) self.activeFilter = (0, text, widget) else: #print "CATFILTER" @@ -826,33 +827,33 @@ class pluginclass( object ): listedDesktopFiles = [] for i in self.applicationsBox.get_children(): if not i.desktop_file_path in listedDesktopFiles: - listedDesktopFiles.append( i.desktop_file_path ) + listedDesktopFiles.append(i.desktop_file_path) i.show_all() else: i.hide() else: for i in self.applicationsBox.get_children(): - i.filterCategory( category ) + i.filterCategory(category) for i in self.categoriesBox.get_children(): i.released() - i.set_relief( Gtk.ReliefStyle.NONE ) - widget.set_relief( Gtk.ReliefStyle.HALF ) + i.set_relief(Gtk.ReliefStyle.NONE) + widget.set_relief(Gtk.ReliefStyle.HALF) - self.applicationsScrolledWindow.get_vadjustment().set_value( 0 ) + self.applicationsScrolledWindow.get_vadjustment().set_value(0) - def FilterAndClear( self, widget, category = None ): - self.searchEntry.set_text( "" ) - self.Filter( widget, category ) + def FilterAndClear(self, widget, category = None): + self.searchEntry.set_text("") + self.Filter(widget, category) - def keyPress( self, widget, event ): + def keyPress(self, widget, event): """ Forward all text to the search box """ if event.string.strip() or event.keyval == Gdk.KEY_space: - self.searchEntry.event( event ) + self.searchEntry.event(event) return True return False - def favPopup( self, widget, event ): + def favPopup(self, widget, event): if event.button == 3: if event.y > widget.get_allocation().height / 2: insertBefore = False @@ -880,17 +881,17 @@ class pluginclass( object ): 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 ) + 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 ) + 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) + 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) @@ -924,14 +925,14 @@ class pluginclass( object ): 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 ) + 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 ): + def menuPopup(self, widget, event): if event.button == 3: mTree = Gtk.Menu() #i18n @@ -972,30 +973,30 @@ class pluginclass( object ): 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 ) + 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 ) + 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 ) + favoriteMenuItem.set_active(False) + favoriteMenuItem.connect("toggled", self.onAddToFavorites, widget) if widget.isInStartup(): - startupMenuItem.set_active( True ) - startupMenuItem.connect( "toggled", self.onRemoveFromStartup, widget ) + startupMenuItem.set_active(True) + startupMenuItem.connect("toggled", self.onRemoveFromStartup, widget) else: - startupMenuItem.set_active( False ) - startupMenuItem.connect( "toggled", self.onAddToStartup, widget ) + 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=None, event=None ): + def searchPopup(self, widget=None, event=None): menu = Gtk.Menu() if self.enableInternetSearch: @@ -1027,7 +1028,7 @@ class pluginclass( object ): menuItem = Gtk.ImageMenuItem(_("Search Computer")) img = Gtk.Image() img.set_from_icon_name("edit-find", Gtk.IconSize.INVALID) - img.set_pixel_size( self.iconSize ) + img.set_pixel_size(self.iconSize) menuItem.set_image(img) menuItem.connect("activate", self.Search) menu.append(menuItem) @@ -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") @@ -1167,11 +1168,11 @@ class pluginclass( object ): except Exception, detail: print detail - def onLaunchApp( self, menu, widget ): + def onLaunchApp(self, menu, widget): widget.execute() self.mintMenuWin.hide() - def onPropsApp( self, menu, widget ): + def onPropsApp(self, menu, widget): newFileFlag = False sysPaths = get_system_item_paths() @@ -1224,60 +1225,59 @@ class pluginclass( object ): else: self.buildFavorites() - - def onUninstallApp( self, menu, widget ): + def onUninstallApp(self, menu, widget): widget.uninstall() self.mintMenuWin.hide() - def onFavoritesInsertSpace( self, menu, widget, insertBefore ): + def onFavoritesInsertSpace(self, menu, widget, insertBefore): if insertBefore: - self.favoritesAdd( self.favoritesBuildSpace(), widget.position ) + self.favoritesAdd(self.favoritesBuildSpace(), widget.position) else: - self.favoritesAdd( self.favoritesBuildSpace(), widget.position + 1 ) + self.favoritesAdd(self.favoritesBuildSpace(), widget.position + 1) - def onFavoritesInsertSeparator( self, menu, widget, insertBefore ): + def onFavoritesInsertSeparator(self, menu, widget, insertBefore): if insertBefore: - self.favoritesAdd( self.favoritesBuildSeparator(), widget.position ) + self.favoritesAdd(self.favoritesBuildSeparator(), widget.position) else: - self.favoritesAdd( self.favoritesBuildSeparator(), widget.position + 1 ) + self.favoritesAdd(self.favoritesBuildSeparator(), widget.position + 1) - def onFavoritesRemove( self, menu, widget ): - self.favoritesRemove( widget.position ) + def onFavoritesRemove(self, menu, widget): + self.favoritesRemove(widget.position) - def onAddToStartup( self, menu, widget ): + def onAddToStartup(self, menu, widget): widget.addToStartup() - def onRemoveFromStartup( self, menu, widget ): + def onRemoveFromStartup(self, menu, widget): widget.removeFromStartup() - def onAddToFavorites( self, menu, widget ): - self.favoritesAdd( self.favoritesBuildLauncher( widget.desktopFile ) ) + def onAddToFavorites(self, menu, widget): + self.favoritesAdd(self.favoritesBuildLauncher(widget.desktopFile)) - def onRemoveFromFavorites( self, menu, widget ): - self.favoritesRemoveLocation( widget.desktopFile ) + def onRemoveFromFavorites(self, menu, widget): + self.favoritesRemoveLocation(widget.desktopFile) - def ReceiveCallback( self, widget, context, x, y, selection, targetType, time ): + def ReceiveCallback(self, widget, context, x, y, selection, targetType, time): if targetType == self.TARGET_TYPE_TEXT: for uri in selection.get_uris(): - self.favoritesAdd( self.favoritesBuildLauncher( uri ) ) + self.favoritesAdd(self.favoritesBuildLauncher(uri)) - def Search( self, widget ): + def Search(self, widget): text = self.searchEntry.get_text().strip() if text != "": for app_button in self.applicationsBox.get_children(): - if( isinstance(app_button, ApplicationLauncher) and app_button.filterText( text ) ): + if(isinstance(app_button, ApplicationLauncher) and app_button.filterText(text)): app_button.execute() self.mintMenuWin.hide() return self.mintMenuWin.hide() - fullstring = self.searchtool.replace( "%s", text ) + fullstring = self.searchtool.replace("%s", text) os.system(fullstring + " &") - def SearchWithButton( self, widget, event ): - self.Search( widget ) + def SearchWithButton(self, widget, event): + self.Search(widget) - def do_plugin( self ): + def do_plugin(self): self.Todos() self.buildFavorites() # TODO all this runs whether the plugin is enabled or not @@ -1285,30 +1285,28 @@ class pluginclass( object ): # RecentHelper.buildRecentApps() # Scroll button into view - def scrollItemIntoView( self, widget, event = None ): + def scrollItemIntoView(self, widget, event = None): viewport = widget.get_parent() - while not isinstance( viewport, Gtk.Viewport ): + while not isinstance(viewport, Gtk.Viewport): if not viewport.get_parent(): return viewport = viewport.get_parent() aloc = widget.get_allocation() viewport.get_vadjustment().clamp_page(aloc.y, aloc.y + aloc.height) - def favoritesBuildSpace( self ): + def favoritesBuildSpace(self): space = Gtk.EventBox() - space.set_size_request( -1, 20 ) + space.set_size_request(-1, 20) space.set_visible_window(False) - space.connect( "button-press-event", self.favPopup ) + space.connect("button-press-event", self.favPopup) space.type = "space" - space.show() - return space - def favoritesBuildSeparator( self ): - separator = Gtk.Separator( orientation=Gtk.Orientation.HORIZONTAL ) - separator.set_margin_top( 5 ) - separator.set_margin_bottom( 5 ) + def favoritesBuildSeparator(self): + separator = Gtk.Separator(orientation=Gtk.Orientation.HORIZONTAL) + separator.set_margin_top(5) + separator.set_margin_bottom(5) separator.type = "separator" separator.show_all() @@ -1316,20 +1314,20 @@ class pluginclass( object ): box.type = "separator" box.add(separator) box.set_visible_window(False) - box.connect( "button-press-event", self.favPopup ) + box.connect("button-press-event", self.favPopup) box.show_all() return box - def favoritesBuildLauncher( self, location ): + def favoritesBuildLauncher(self, location): try: ButtonIcon = None # For Folders and Network Shares - location = string.join( location.split( "%20" ) ) + location = string.join(location.split("%20")) - if location.startswith( "file" ): + if location.startswith("file"): ButtonIcon = "mate-fs-directory" - if location.startswith( "smb" ) or location.startswith( "ssh" ) or location.startswith( "network" ): + if location.startswith("smb") or location.startswith("ssh") or location.startswith("network"): ButtonIcon = "mate-fs-network" #For Special locations @@ -1339,10 +1337,10 @@ class pluginclass( object ): location = "/usr/share/applications/nautilus-home.desktop" elif location == "x-nautilus-desktop:///network": location = "/usr/share/applications/network-scheme.desktop" - elif location.startswith( "x-nautilus-desktop:///" ): + elif location.startswith("x-nautilus-desktop:///"): location = "/usr/share/applications/nautilus-computer.desktop" - if location.startswith( "file://" ): + if location.startswith("file://"): location = location[7:] # Don't add a location twice @@ -1350,15 +1348,15 @@ class pluginclass( object ): if fav.type == "location" and fav.desktopFile == location: return None - favButton = FavApplicationLauncher( location, self.faviconsize, self.swapgeneric ) + favButton = FavApplicationLauncher(location, self.faviconsize, self.swapgeneric) if favButton.appExec: favButton.show() - favButton.connect( "popup-menu", self.favPopup ) - favButton.connect( "button-press-event", self.favPopup ) - favButton.connect( "focus-in-event", self.scrollItemIntoView ) - favButton.connect( "clicked", RecentHelper.applicationButtonClicked ) + favButton.connect("popup-menu", self.favPopup) + favButton.connect("button-press-event", self.favPopup) + favButton.connect("focus-in-event", self.scrollItemIntoView) + favButton.connect("clicked", RecentHelper.applicationButtonClicked) - self.mintMenuWin.setTooltip( favButton, favButton.getTooltip() ) + self.mintMenuWin.setTooltip(favButton, favButton.getTooltip()) favButton.type = "location" return favButton except Exception, e: @@ -1366,14 +1364,14 @@ class pluginclass( object ): return None - def buildFavorites( self ): + 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 = [] @@ -1386,23 +1384,23 @@ class pluginclass( object ): app = app.strip() if app[0:9] == "location:": - favButton = self.favoritesBuildLauncher( app[9:] ) + favButton = self.favoritesBuildLauncher(app[9:]) elif app == "space": favButton = self.favoritesBuildSpace() elif app == "separator": favButton = self.favoritesBuildSeparator() else: - if ( app.endswith( ".desktop" ) ): - favButton = self.favoritesBuildLauncher( app ) + if app.endswith(".desktop"): + favButton = self.favoritesBuildLauncher(app) else: favButton = None if favButton: favButton.position = position - self.favorites.append( favButton ) - self.favoritesPositionOnGrid( favButton ) - favButton.drag_source_set (Gdk.ModifierType.BUTTON1_MASK, self.toFav, Gdk.DragAction.COPY) + 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.connect("drag-data-get", self.on_drag_data_get) favButton.connect("drag-data-received", self.on_drag_data_received) @@ -1412,11 +1410,11 @@ class pluginclass( object ): except Exception, e: print e - def favoritesPositionOnGrid( self, favorite ): + def favoritesPositionOnGrid(self, favorite): row = 0 col = 0 for fav in self.favorites: - if ( fav.type == "separator" or fav.type == "space" ) and col != 0: + if (fav.type == "separator" or fav.type == "space") and col != 0: row += 1 col = 0 if fav.position == favorite.position: @@ -1431,83 +1429,81 @@ class pluginclass( object ): col = 0 if favorite.type == "separator" or favorite.type == "space": - self.favoritesBox.attach( favorite, col, row, self.favCols, 1 ) + self.favoritesBox.attach(favorite, col, row, self.favCols, 1) else: - self.favoritesBox.attach( favorite, col, row, 1, 1 ) + self.favoritesBox.attach(favorite, col, row, 1, 1) - def favoritesReorder( self, oldposition, newposition ): + def favoritesReorder(self, oldposition, newposition): if oldposition == newposition: return - tmp = self.favorites[ oldposition ] + 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 ] - self.favorites[ i ].position = i + for i in range(oldposition, newposition): + self.favorites[i] = self.favorites[i + 1] + self.favorites[i].position = i elif newposition < oldposition: - for i in range( 0, oldposition - newposition ): - self.favorites[ oldposition - i ] = self.favorites[ oldposition - i - 1 ] - self.favorites[ oldposition - i ] .position = oldposition - i - self.favorites[ newposition ] = tmp - self.favorites[ newposition ].position = newposition + for i in range(0, oldposition - newposition): + self.favorites[oldposition - i] = self.favorites[oldposition - i - 1] + self.favorites[oldposition - i] .position = oldposition - i + self.favorites[newposition] = tmp + self.favorites[newposition].position = newposition for fav in self.favorites: - self.favoritesBox.remove( fav ) - self.favoritesPositionOnGrid( fav ) + self.favoritesBox.remove(fav) + self.favoritesPositionOnGrid(fav) self.favoritesSave() - def favoritesAdd( self, favButton, position = -1 ): + def favoritesAdd(self, favButton, position = -1): if favButton: - favButton.position = len( self.favorites ) - self.favorites.append( favButton ) - self.favoritesPositionOnGrid( favButton ) + favButton.position = len(self.favorites) + self.favorites.append(favButton) + 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.connect("drag-data-get", self.on_drag_data_get) - favButton.drag_source_set (Gdk.ModifierType.BUTTON1_MASK, self.toFav, Gdk.DragAction.COPY) + favButton.drag_source_set(Gdk.ModifierType.BUTTON1_MASK, self.toFav, Gdk.DragAction.COPY) if position >= 0: - self.favoritesReorder( favButton.position, position ) + self.favoritesReorder(favButton.position, position) self.favoritesSave() - def favoritesRemove( self, position ): - tmp = self.favorites[ position ] - self.favorites.remove( self.favorites[ position ] ) + def favoritesRemove(self, position): + tmp = self.favorites[position] + self.favorites.remove(self.favorites[position]) tmp.destroy() - for i in range( position, len( self.favorites ) ): - self.favorites[ i ].position = i - self.favoritesBox.remove( self.favorites[ i ] ) - self.favoritesPositionOnGrid( self.favorites[ i ] ) + for i in range(position, len(self.favorites)): + self.favorites[i].position = i + self.favoritesBox.remove(self.favorites[i]) + self.favoritesPositionOnGrid(self.favorites[i]) self.favoritesSave() - def favoritesRemoveLocation( self, location ): + def favoritesRemoveLocation(self, location): for fav in self.favorites: if fav.type == "location" and fav.desktopFile == location: - self.favoritesRemove( fav.position ) + self.favoritesRemove(fav.position) - def favoritesSave( self ): + def favoritesSave(self): try: self.checkMintMenuFolder() - appListFile = open( os.path.join( os.path.expanduser( "~"), ".linuxmint", "mintMenu", "applications.list" ) , "w" ) - - for favorite in self.favorites: - if favorite.type == "location": - appListFile.write( "location:" + favorite.desktopFile + "\n" ) - else: - appListFile.write( favorite.type + "\n" ) - - appListFile.close( ) + 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") 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() - def isLocationInFavorites( self, location ): + def isLocationInFavorites(self, location): for fav in self.favorites: if fav.type == "location" and fav.desktopFile == location: return True @@ -1519,35 +1515,33 @@ class pluginclass( object ): self.drag_origin = widget.position selection.set(selection.get_target(), 8, str(widget.position)) - def on_drag_data_received( self, widget, context, x, y, selection, info, time): + 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 ) + self.favoritesReorder(int(selection.get_data()), widget.position) def on_icon_theme_changed(self, theme): print "on_icon_theme_changed" - self.menuChanged (0, 0) + self.menuChanged(0, 0) - def menuChanged( self, x, y ): - print ("menuChanged") + def menuChanged(self, x, y): + print("menuChanged") # wait 1s, to avoid building the menu multiple times concurrently if self.menuChangedTimer: - GLib.source_remove( self.menuChangedTimer ) + GLib.source_remove(self.menuChangedTimer) - self.menuChangedTimer = GLib.timeout_add( 1000, self.updateBoxes, True ) + self.menuChangedTimer = GLib.timeout_add(1000, self.updateBoxes, True) @print_timing - def updateBoxes( self, menu_has_changed ): - print ("updateBoxes") + def updateBoxes(self, menu_has_changed): + print("updateBoxes") # FIXME: This is really bad! if self.rebuildLock: return self.rebuildLock = True - self.menuChangedTimer = None try: - self.loadMenuFiles() # Find added and removed categories than update the category list @@ -1576,9 +1570,9 @@ class pluginclass( object ): found = True break if not found: - removedCategories.append( item ) + removedCategories.append(item) - if self.showcategoryicons == True: + if self.showcategoryicons: categoryIconSize = self.iconSize else: categoryIconSize = 0 @@ -1596,30 +1590,30 @@ class pluginclass( object ): sortedCategoryList = [] for item in self.categoryList: try: - self.categoriesBox.remove( item["button"] ) - sortedCategoryList.append( ( str(item["index"]) + item["name"], item["button"] ) ) + self.categoriesBox.remove(item["button"]) + sortedCategoryList.append((str(item["index"]) + item["name"], item["button"])) except Exception, e: print e # Create new category buttons and add the to the list for item in addedCategories: try: - item["button"] = CategoryButton( item["icon"], categoryIconSize, [ item["name"] ], item["filter"] ) - self.mintMenuWin.setTooltip( item["button"], item["tooltip"] ) + item["button"] = CategoryButton(item["icon"], categoryIconSize, [item["name"]], item["filter"]) + self.mintMenuWin.setTooltip(item["button"], item["tooltip"]) if self.categories_mouse_over: - startId = item["button"].connect( "enter", self.StartFilter, item["filter"] ) - stopId = item["button"].connect( "leave", self.StopFilter ) - item["button"].mouseOverHandlerIds = ( startId, stopId ) + startId = item["button"].connect("enter", self.StartFilter, item["filter"]) + stopId = item["button"].connect("leave", self.StopFilter) + item["button"].mouseOverHandlerIds = (startId, stopId) else: item["button"].mouseOverHandlerIds = None - item["button"].connect( "clicked", self.FilterAndClear, item["filter"] ) - item["button"].connect( "focus-in-event", self.categoryBtnFocus, item["filter"] ) + item["button"].connect("clicked", self.FilterAndClear, item["filter"]) + item["button"].connect("focus-in-event", self.categoryBtnFocus, item["filter"]) item["button"].show() - self.categoryList.append( item ) - sortedCategoryList.append( ( str(item["index"]) + item["name"], item["button"] ) ) + self.categoryList.append(item) + sortedCategoryList.append((str(item["index"]) + item["name"], item["button"])) except Exception, e: print e @@ -1627,11 +1621,10 @@ class pluginclass( object ): for item in sortedCategoryList: try: - self.categoriesBox.pack_start( item[1], False, False, 0 ) + self.categoriesBox.pack_start(item[1], False, False, 0) except Exception, e: print e - # Find added and removed applications add update the application list newApplicationList = self.buildApplicationList() addedApplications = [] @@ -1671,32 +1664,31 @@ class pluginclass( object ): if addedApplications: sortedApplicationList = [] for item in self.applicationList: - self.applicationsBox.remove( item["button"] ) - sortedApplicationList.append( ( item["button"].appName, item["button"] ) ) + 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 ) - item["button"].connect( "focus-in-event", self.scrollItemIntoView ) - item["button"].connect( "clicked", RecentHelper.applicationButtonClicked ) + self.mintMenuWin.setTooltip(item["button"], item["button"].getTooltip()) + item["button"].connect("button-press-event", self.menuPopup) + item["button"].connect("focus-in-event", self.scrollItemIntoView) + item["button"].connect("clicked", RecentHelper.applicationButtonClicked) if self.activeFilter[0] == 0: - item["button"].filterText( self.activeFilter[1] ) + item["button"].filterText(self.activeFilter[1]) else: - item["button"].filterCategory( self.activeFilter[1] ) + item["button"].filterCategory(self.activeFilter[1]) item["button"].desktop_file_path = item["entry"].get_desktop_file_path() - sortedApplicationList.append( ( item["button"].appName.upper(), item["button"] ) ) - self.applicationList.append( item ) + sortedApplicationList.append((item["button"].appName.upper(), item["button"])) + self.applicationList.append(item) 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: launcherName = item[0] button = item[1] - self.applicationsBox.add( button ) + self.applicationsBox.add(button) if launcherName in launcherNames: button.hide() else: @@ -1707,17 +1699,15 @@ class pluginclass( object ): self.rebuildLock = False # Reload the menufiles from the filesystem - def loadMenuFiles( self ): + def loadMenuFiles(self): self.menuFiles = [] - for mainitems in [ "mate-applications.menu", "mate-settings.menu" ]: - self.menuFiles.append( Menu( mainitems) ) - - # 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 } ] + for mainitems in ["mate-applications.menu", "mate-settings.menu"]: + self.menuFiles.append(Menu(mainitems)) + # 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: @@ -1725,20 +1715,19 @@ 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 # Build a list containing the DesktopEntry object and the category of each application in the menu - def buildApplicationList( self ): + def buildApplicationList(self): newApplicationsList = [] def find_applications_recursively(app_list, directory, catName): for item in directory.get_contents(): if item.get_type() == matemenu.TYPE_ENTRY: - app_list.append( { "entry": item, "category": catName } ) + app_list.append({"entry": item, "category": catName}) elif item.get_type() == matemenu.TYPE_DIRECTORY: find_applications_recursively(app_list, item, catName) @@ -1755,10 +1744,10 @@ class pluginclass( object ): if item.get_type() == matemenu.TYPE_DIRECTORY: find_applications_recursively(newApplicationsList, item, entry.name) elif item.get_type() == matemenu.TYPE_ENTRY: - newApplicationsList.append( { "entry": item, "category": entry.name } ) + newApplicationsList.append({"entry": item, "category": entry.name}) #elif entry.get_type() == matemenu.TYPE_ENTRY: # if not (entry.get_is_excluded() or entry.get_is_nodisplay()): # print "=======>>> " + item.name + " = top level" - # newApplicationsList.append( { "entry": item, "category": "" } ) + # newApplicationsList.append({"entry": item, "category": ""}) return newApplicationsList diff --git a/usr/lib/linuxmint/mintMenu/plugins/easybuttons.py b/usr/lib/linuxmint/mintMenu/plugins/easybuttons.py index c8b2945..fbc864c 100755 --- a/usr/lib/linuxmint/mintMenu/plugins/easybuttons.py +++ b/usr/lib/linuxmint/mintMenu/plugins/easybuttons.py @@ -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 @@ -21,25 +19,25 @@ from plugins.filemonitor import monitor as filemonitor class IconManager(GObject.GObject): __gsignals__ = { - "changed" : (GObject.SignalFlags.RUN_LAST, None, () ) - } + "changed" : (GObject.SignalFlags.RUN_LAST, None, ()) + } - def __init__( self ): - GObject.GObject.__init__( self ) - self.icons = { } + def __init__(self): + GObject.GObject.__init__(self) + 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 ): + def createTheme(d): theme = Gtk.IconTheme() - theme.set_custom_theme( d ) + 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 ) ) ] ) + #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() @@ -53,16 +51,16 @@ class IconManager(GObject.GObject): 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 = [theme for theme in self.themes if theme.list_icons() != defaultTheme.list_icons()] - self.themes = [ self.defaultTheme, defaultKdeTheme ] + self.themes = [self.defaultTheme, defaultKdeTheme] # Listen for changes in the themes for theme in self.themes: - theme.connect("changed", self.themeChanged ) + theme.connect("changed", self.themeChanged) - def getIcon( self, iconName, iconSize ): + def getIcon(self, iconName, iconSize): if not iconName: return None @@ -71,11 +69,11 @@ class IconManager(GObject.GObject): iconFileName = "" realIconName = "" needTempFile = False - #[ iconWidth, iconHeight ] = self.getIconSize( iconSize ) + #[iconWidth, iconHeight] = self.getIconSize(iconSize) if iconSize <= 0: return None - elif os.path.isabs( iconName ): + elif os.path.isabs(iconName): iconFileName = iconName needTempFile = True else: @@ -84,7 +82,7 @@ class IconManager(GObject.GObject): else: realIconName = iconName - if iconFileName and needTempFile and os.path.exists( iconFileName ): + if iconFileName and needTempFile and os.path.exists(iconFileName): tmpIconName = iconFileName.replace("/", "-") realIconName = tmpIconName[:-4] if not os.path.exists(os.path.join(self.iconDir, tmpIconName)): @@ -109,74 +107,74 @@ class IconManager(GObject.GObject): print "Exception " + e.__class__.__name__ + ": " + e.message return None - def themeChanged( self, theme ): - self.emit( "changed" ) + def themeChanged(self, theme): + self.emit("changed") GObject.type_register(IconManager) -class easyButton( Gtk.Button ): +class easyButton(Gtk.Button): - def __init__( self, iconName, iconSize, labels = None, buttonWidth = -1, buttonHeight = -1 ): - GObject.GObject.__init__( self ) - self.connections = [ ] + def __init__(self, iconName, iconSize, labels = None, buttonWidth = -1, buttonHeight = -1): + GObject.GObject.__init__(self) + self.connections = [] self.iconName = iconName self.iconSize = iconSize self.showIcon = True - self.set_relief( Gtk.ReliefStyle.NONE ) - self.set_size_request( buttonWidth, buttonHeight ) + self.set_relief(Gtk.ReliefStyle.NONE) + self.set_size_request(buttonWidth, buttonHeight) - Align1 = Gtk.Alignment.new( 0, 0.5, 1.0, 0 ) - HBox1 = Gtk.Box( orientation=Gtk.Orientation.HORIZONTAL ) - self.labelBox = Gtk.Box( orientation=Gtk.Orientation.VERTICAL, spacing=2 ) + Align1 = Gtk.Alignment.new(0, 0.5, 1.0, 0) + HBox1 = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) + self.labelBox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=2) self.buttonImage = Gtk.Image() - icon = self.getIcon( self.iconSize ) + 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 ) + #[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() - HBox1.pack_start( self.image_box, False, False, 0 ) + HBox1.pack_start(self.image_box, False, False, 0) if labels: for label in labels: - if isinstance( label, basestring ): - self.addLabel( label ) - elif isinstance( label, list ): - self.addLabel( label[0], label[1] ) + if isinstance(label, basestring): + self.addLabel(label) + elif isinstance(label, list): + self.addLabel(label[0], label[1]) self.labelBox.show() - HBox1.pack_start( self.labelBox , True, True, 0) + HBox1.pack_start(self.labelBox , True, True, 0) HBox1.show() - Align1.add( HBox1 ) + Align1.add(HBox1) Align1.show() - self.add( Align1 ) + self.add(Align1) - self.connectSelf( "destroy", self.onDestroy ) - self.connect( "released", self.onRelease ) + 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 ) ) + def connectSelf(self, event, callback): + self.connections.append(self.connect(event, callback)) - def onRelease( self, widget ): - widget.get_style_context().set_state( Gtk.StateFlags.NORMAL ) + def onRelease(self, widget): + widget.get_style_context().set_state(Gtk.StateFlags.NORMAL) - def onDestroy( self, widget ): + def onDestroy(self, widget): self.buttonImage.clear() - iconManager.disconnect( self.themeChangedHandlerId ) + iconManager.disconnect(self.themeChangedHandlerId) for connection in self.connections: - self.disconnect( connection ) + self.disconnect(connection) del self.connections - def addLabel( self, text, styles = None ): + def addLabel(self, text, styles = None): label = Gtk.Label() if "" in text or " 0 and color[0] == "#": #appName = "%s" % (color, appName); #appComment = "%s" % (color, appComment); @@ -491,59 +489,59 @@ class MenuApplicationLauncher( ApplicationLauncher ): #else: #appName = "%s" % (appName); #appComment = "%s" % (appComment); - appName = "%s" % (appName); - appComment = "%s" % (appComment); + appName = "%s" % appName + appComment = "%s" % appComment except Exception, detail: print detail pass if self.showComment and self.appComment != "": if self.iconSize <= 2: - self.addLabel( '%s' % appName) - self.addLabel( '%s' % appComment) + self.addLabel('%s' % appName) + self.addLabel('%s' % appComment) else: - self.addLabel( appName ) - self.addLabel( '%s' % appComment) + self.addLabel(appName) + self.addLabel('%s' % appComment) else: - self.addLabel( appName ) + self.addLabel(appName) - def execute( self, *args ): + def execute(self, *args): self.highlight = False for child in self.labelBox: child.destroy() self.setupLabels() return super(MenuApplicationLauncher, self).execute(*args) - def setShowComment( self, showComment ): + def setShowComment(self, showComment): self.showComment = showComment for child in self.labelBox: child.destroy() self.setupLabels() -class FavApplicationLauncher( ApplicationLauncher ): +class FavApplicationLauncher(ApplicationLauncher): - def __init__( self, desktopFile, iconSize, swapGeneric = False ): + def __init__(self, desktopFile, iconSize, swapGeneric = False): self.swapGeneric = swapGeneric - ApplicationLauncher.__init__( self, desktopFile, iconSize ) + ApplicationLauncher.__init__(self, desktopFile, iconSize) - def setupLabels( self ): + def setupLabels(self): if self.appGenericName: if self.swapGeneric: - self.addLabel( '%s' % self.appName ) - self.addLabel( self.appGenericName ) + self.addLabel('%s' % self.appName) + self.addLabel(self.appGenericName) else: - self.addLabel( '%s' % self.appGenericName ) - self.addLabel( self.appName ) + self.addLabel('%s' % self.appGenericName) + self.addLabel(self.appName) else: - self.addLabel( '%s' % self.appName ) + self.addLabel('%s' % self.appName) if self.appComment != "": - self.addLabel( self.appComment ) + self.addLabel(self.appComment) else: - self.addLabel ( "" ) + self.addLabel("") - def setSwapGeneric( self, swapGeneric ): + def setSwapGeneric(self, swapGeneric): self.swapGeneric = swapGeneric for child in self.labelBox: child.destroy() @@ -551,10 +549,10 @@ class FavApplicationLauncher( ApplicationLauncher ): self.setupLabels() -class CategoryButton( easyButton ): +class CategoryButton(easyButton): - def __init__( self, iconName, iconSize, labels , f ): - easyButton.__init__( self, iconName, iconSize, labels ) + def __init__(self, iconName, iconSize, labels , f): + easyButton.__init__(self, iconName, iconSize, labels) self.filter = f diff --git a/usr/lib/linuxmint/mintMenu/plugins/easyfiles.py b/usr/lib/linuxmint/mintMenu/plugins/easyfiles.py index f266738..d2b1385 100755 --- a/usr/lib/linuxmint/mintMenu/plugins/easyfiles.py +++ b/usr/lib/linuxmint/mintMenu/plugins/easyfiles.py @@ -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 diff --git a/usr/lib/linuxmint/mintMenu/plugins/easygsettings.py b/usr/lib/linuxmint/mintMenu/plugins/easygsettings.py index c101823..96891da 100644 --- a/usr/lib/linuxmint/mintMenu/plugins/easygsettings.py +++ b/usr/lib/linuxmint/mintMenu/plugins/easygsettings.py @@ -1,92 +1,92 @@ #!/usr/bin/python2 - from gi.repository import Gio + class EasyGSettings: - def __init__( self, schema = None ): + def __init__(self, schema = None): self.schema = schema self.settings = Gio.Settings.new(self.schema) - self.handlerIds = [ ] + self.handlerIds = [] - def get( self, type, key ): + def get(self, type, key): if type == "bool": - return self.settings.get_boolean( key ) + return self.settings.get_boolean(key) if type == "string": - return self.settings.get_string( key ) + return self.settings.get_string(key) if type == "int": - return self.settings.get_int( key ) + return self.settings.get_int(key) if type == "color": - color = self.settings.get_string( key ) - if not self.evalColor( color ): + color = self.settings.get_string(key) + if not self.evalColor(color): self.settings.set_string(key, "#ffffff") return "#ffffff" return color t = type.split("-") if len(t) == 2 and t[0] == "list": - return self.settings.get_strv( key ) + return self.settings.get_strv(key) - return self.settings.get( key ) + return self.settings.get(key) - def set( self, type, key, value ): + def set(self, type, key, value): if type == "bool": - return self.settings.set_boolean( key, value ) + return self.settings.set_boolean(key, value) if type == "string": - return self.settings.set_string( key, value ) + return self.settings.set_string(key, value) if type == "int": - return self.settings.set_int( key, value ) + return self.settings.set_int(key, value) if type == "color": - if self.evalColor( value ): - return self.settings.set_string( key, value ) + if self.evalColor(value): + return self.settings.set_string(key, value) else: - return self.settings.set_string( key, "#ffffff" ) + return self.settings.set_string(key, "#ffffff") t = type.split("-") if len(t) == 2 and t[0] == "list": - return self.settings.set_strv( key, value ) + return self.settings.set_strv(key, value) - return self.settings.set( key, value ) + return self.settings.set(key, value) - def notifyAdd( self, key, callback, args = None ): + def notifyAdd(self, key, callback, args = None): handlerId = self.settings.connect("changed::"+key, callback, args) - self.handlerIds.append( handlerId ) + self.handlerIds.append(handlerId) return handlerId - def notifyRemove( self, handlerId ): + def notifyRemove(self, handlerId): return self.settings.disconnect(handlerId) - def notifyRemoveAll( self ): + def notifyRemoveAll(self): for handlerId in self.handlerIds: - self.settings.disconnect( handlerId ) + self.settings.disconnect(handlerId) - def evalColor(self, colorToTest ): - if colorToTest[0] != '#' or len( colorToTest ) != 7: + def evalColor(self, colorToTest): + if colorToTest[0] != '#' or len(colorToTest) != 7: return False for i in colorToTest[1:]: if i not in ['a', 'A', 'b', 'B', 'c', 'C', 'd', 'D', 'e', 'E', 'f', 'F', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9']: return False return True - def bindGSettingsEntryToVar( self, type, key, obj, varName ): - return self.notifyAdd( key, self.setVar, ( type, obj, varName ) ) + def bindGSettingsEntryToVar(self, type, key, obj, varName): + return self.notifyAdd(key, self.setVar, (type, obj, varName)) - def setVar( self, settings, key, args ): + def setVar(self, settings, key, args): type, obj, varName = args if type == "string": - setattr( obj, varName, settings.get_string(key) ) + setattr(obj, varName, settings.get_string(key)) elif type == "int": - setattr( obj, varName, settings.get_int(key) ) + setattr(obj, varName, settings.get_int(key)) elif type == "float": - setattr( obj, varName, settings.get_float(key) ) + setattr(obj, varName, settings.get_float(key)) elif type == "bool": - setattr( obj, varName, settings.get_boolean(key) ) + setattr(obj, varName, settings.get_boolean(key)) else: - setattr( obj, varName, settings.get_value(key) ) + setattr(obj, varName, settings.get_value(key)) diff --git a/usr/lib/linuxmint/mintMenu/plugins/execute.py b/usr/lib/linuxmint/mintMenu/plugins/execute.py index e021dfb..1b8a3ea 100755 --- a/usr/lib/linuxmint/mintMenu/plugins/execute.py +++ b/usr/lib/linuxmint/mintMenu/plugins/execute.py @@ -3,6 +3,7 @@ import os from gi.repository import Gio + def RemoveArgs(Execline): if isinstance(Execline, list): Execline = ' '.join(Execline) diff --git a/usr/lib/linuxmint/mintMenu/plugins/filemonitor.py b/usr/lib/linuxmint/mintMenu/plugins/filemonitor.py index d711c66..06e6817 100755 --- a/usr/lib/linuxmint/mintMenu/plugins/filemonitor.py +++ b/usr/lib/linuxmint/mintMenu/plugins/filemonitor.py @@ -12,65 +12,66 @@ try: except ImportError: hasInotify = False + if hasInotify: + class FileMonitor(object): - def __init__( self ): + def __init__(self): self.monitorId = 0 self.wm = pyinotify.WatchManager() self.wdds = {} self.callbacks = {} self.notifier = pyinotify.ThreadedNotifier(self.wm, self.fileChanged) - self.notifier.setDaemon( True ) + self.notifier.setDaemon(True) self.notifier.start() - def addMonitor( self, filename, callback, args = None ): + def addMonitor(self, filename, callback, args = None): try: mask = pyinotify.IN_DELETE | pyinotify.IN_CREATE | pyinotify.IN_MODIFY - mId = self.wm.add_watch( filename, mask, rec = True)[filename] + mId = self.wm.add_watch(filename, mask, rec = True)[filename] if mId >= 0: - self.callbacks[mId] = ( callback, args ) + self.callbacks[mId] = (callback, args) except Exception, detail: mId = 0 return mId - def removeMonitor( self, monitorId ): + def removeMonitor(self, monitorId): if monitorId in self.callbacks: - self.wm.rm_watch( monitorId ) + self.wm.rm_watch(monitorId) del self.callbacks[monitorId] - def fileChanged(self, event ): + def fileChanged(self, event): if event.wd in self.callbacks: # print event.path callback = self.callbacks[event.wd] if callback[1]: - GLib.idle_add( callback[0], callback[1] ) + GLib.idle_add(callback[0], callback[1]) else: - GLib.idle_add( callback[0] ) - + GLib.idle_add(callback[0]) else: - class _MonitoredFile( object ): - def __init__( self, filename, callback, monitorId, args ): + class _MonitoredFile(object): + def __init__(self, filename, callback, monitorId, args): self.filename = filename self.callback = callback self.monitorId = monitorId self.args = args - self.exists = os.path.exists( self.filename ) + self.exists = os.path.exists(self.filename) if self.exists: - self.mtime = os.stat( filename ).st_mtime + self.mtime = os.stat(filename).st_mtime else: self.mtime = 0 - def hasChanged( self ): - if os.path.exists( self.filename ): + def hasChanged(self): + if os.path.exists(self.filename): if not self.exists: self.exists = True - self.mtime = os.stat( self.filename ).st_mtime + self.mtime = os.stat(self.filename).st_mtime return True else: - mtime = os.stat( self.filename ).st_mtime + mtime = os.stat(self.filename).st_mtime if mtime != self.mtime: self.mtime = mtime return True @@ -83,7 +84,7 @@ else: class MonitorThread(threading.Thread): def __init__(self, monitor): - threading.Thread.__init__ ( self ) + threading.Thread.__init__(self) self.monitor = monitor def run(self): @@ -91,34 +92,31 @@ else: self.monitor.checkFiles() time.sleep(1) - - class FileMonitor(object): - def __init__( self ): + def __init__(self): self.monitorId = 0 self.monitoredFiles = [] - self.monitorThread = MonitorThread( self ) - self.monitorThread.setDaemon( True ) + self.monitorThread = MonitorThread(self) + self.monitorThread.setDaemon(True) self.monitorThread.start() - def addMonitor( self, filename, callback, args = None ): + def addMonitor(self, filename, callback, args = None): self.monitorId += 1 - self.monitoredFiles.append( _MonitoredFile( filename, callback, self.monitorId, args ) ) + self.monitoredFiles.append(_MonitoredFile(filename, callback, self.monitorId, args)) return self.monitorId - def removeMonitor( self, monitorId ): + def removeMonitor(self, monitorId): for monitored in self.monitoredFiles: if monitorId == monitored.monitorId: - self.monitoredFiles.remove( monitored ) + self.monitoredFiles.remove(monitored) break - def checkFiles( self ): + def checkFiles(self): for monitored in self.monitoredFiles: if monitored.hasChanged(): if monitored.args: - GLib.idle_add( monitored.callback, monitored.args ) + GLib.idle_add(monitored.callback, monitored.args) else: - GLib.idle_add( monitored.callback ) - + GLib.idle_add(monitored.callback) monitor = FileMonitor() diff --git a/usr/lib/linuxmint/mintMenu/plugins/places.py b/usr/lib/linuxmint/mintMenu/plugins/places.py index 1b27367..4bb8d94 100755 --- a/usr/lib/linuxmint/mintMenu/plugins/places.py +++ b/usr/lib/linuxmint/mintMenu/plugins/places.py @@ -15,12 +15,13 @@ from plugins.easybuttons import easyButton from plugins.easygsettings import EasyGSettings from plugins.execute import Execute + # i18n gettext.install("mintmenu", "/usr/share/linuxmint/locale") -class pluginclass( object ): +class pluginclass(object): - def __init__( self, mintMenuWin, toggleButton, de ): + def __init__(self, mintMenuWin, toggleButton, de): self.mintMenuWin = mintMenuWin self.toggleButton = toggleButton @@ -28,103 +29,103 @@ class pluginclass( object ): # Read UI file builder = Gtk.Builder() - builder.add_from_file(os.path.join( os.path.dirname( __file__ ), "places.glade" )) + builder.add_from_file(os.path.join(os.path.dirname(__file__), "places.glade")) - self.placesBtnHolder = builder.get_object( "places_button_holder" ) - self.editableBtnHolder = builder.get_object( "editable_button_holder" ) + 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" ) + 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" ) + self.content_holder = builder.get_object("Places") # Items to get custom colors - self.itemstocolor = [ builder.get_object( "viewport2" ) ] + self.itemstocolor = [builder.get_object("viewport2")] # Settings self.settings = EasyGSettings("com.linuxmint.mintmenu.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.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 ) + self.content_holder.set_size_request(self.width, self.height) - def wake (self) : - if ( self.showtrash == True ): + def wake(self): + if self.showtrash: self.refreshTrash() - def destroy( self ): + 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): + def changePluginSize(self, settings, key, args = None): + self.allowScrollbar = self.settings.get("bool", "allow-scrollbar") + self.width = self.settings.get("int", "width") + if not self.allowScrollbar: self.height = -1 - self.scrolledWindow.set_policy( Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.NEVER ) + 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 ) + 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 ): + 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): + 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 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 ) - self.iconsize = self.settings.get( "int", "icon-size" ) + 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" ) + 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" ) + self.custompaths = self.settings.get("list-string", "custom-paths") # Get names for custom items - self.customnames = self.settings.get( "list-string", "custom-names" ) + self.customnames = self.settings.get("list-string", "custom-names") # Hide vertical dotted separator - self.hideseparator = self.settings.get( "bool", "hide-separator" ) + self.hideseparator = self.settings.get("bool", "hide-separator") # Plugin icon - self.icon = self.settings.get( "string", "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") + self.sticky = self.settings.get("bool", "sticky") + self.minimized = self.settings.get("bool", "minimized") def ClearAll(self): for child in self.placesBtnHolder.get_children(): @@ -133,35 +134,35 @@ class pluginclass( object ): child.destroy() #Add standard places - def do_standard_places( self ): + 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:" ) + 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") ) + 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 ): - Button2 = easyButton( "user-home", self.iconsize, [_("Home Folder")], -1, -1 ) - Button2.connect( "clicked", self.ButtonClicked, "xdg-open %s " % home ) + 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") ) + 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" ) + icon_theme = mate_settings.get_string("icon-theme") if "Mint-X" in icon_theme: - Button3 = easyButton( "notification-network-ethernet-connected", self.iconsize, [_("Network")], -1, -1) + Button3 = easyButton("notification-network-ethernet-connected", self.iconsize, [_("Network")], -1, -1) else: - Button3 = easyButton( "network-workgroup", self.iconsize, [_("Network")], -1, -1) - Button3.connect( "clicked", self.ButtonClicked, "xdg-open network:" ) + 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.mintMenuWin.setTooltip( Button3, _("Browse bookmarked and local network locations") ) + 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: @@ -174,33 +175,33 @@ class pluginclass( object ): desktopDir = tmpdesktopDir except Exception, detail: print detail - Button4 = easyButton( "desktop", self.iconsize, [_("Desktop")], -1, -1 ) - Button4.connect( "clicked", self.ButtonClicked, "xdg-open \"" + desktopDir + "\"") + 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.mintMenuWin.setTooltip( Button4, _("Browse items placed on the desktop") ) + self.placesBtnHolder.pack_start(Button4, False, False, 0) + self.mintMenuWin.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:" ) + 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() - self.trashButton.connect( "button-release-event", self.trashPopup ) + self.trashButton.connect("button-release-event", self.trashPopup) self.trash_path = os.path.join(home, "/.local/share/Trash/info") self.refreshTrash() - self.placesBtnHolder.pack_start( self.trashButton, False, False, 0) - self.mintMenuWin.setTooltip( self.trashButton, _("Browse deleted files") ) + self.placesBtnHolder.pack_start(self.trashButton, False, False, 0) + self.mintMenuWin.setTooltip(self.trashButton, _("Browse deleted files")) - def do_custom_places( self ): - for index in range( len(self.custompaths) ): + def do_custom_places(self): + for index in range(len(self.custompaths)): path = self.custompaths[index] path = path.replace("~", home) - command = ( "xdg-open \"" + path + "\"") - currentbutton = easyButton( "folder", self.iconsize, [self.customnames[index]], -1, -1 ) - currentbutton.connect( "clicked", self.ButtonClicked, command ) + command = 'xdg-open "%s"' % 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) + self.placesBtnHolder.pack_start(currentbutton, False, False, 0) - def do_gtk_bookmarks( self ): + 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): @@ -225,42 +226,42 @@ class pluginclass( object ): 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 = 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) + self.placesBtnHolder.pack_start(currentbutton, False, False, 0) - def launch_gtk_bookmark (self, widget, path): + def launch_gtk_bookmark(self, widget, path): self.mintMenuWin.hide() os.system("xdg-open \"%s\" &" % path) - def trashPopup( self, widget, event ): + 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 ) + emptyTrashMenuItem.connect("activate", self.emptyTrash, widget) self.mintMenuWin.stopHiding() trashMenu.attach_to_widget(widget, None) trashMenu.popup(None, None, None, None, 3, 0) - def emptyTrash( self, menu, widget): + def emptyTrash(self, menu, widget): os.system("rm -rf " + home + "/.local/share/Trash/info/*") os.system("rm -rf " + home + "/.local/share/Trash/files/*") self.trashButton.setIcon("user-trash") - def ButtonClicked( self, widget, Exec ): + def ButtonClicked(self, widget, Exec): self.mintMenuWin.hide() if Exec: - Execute( Exec ) + Execute(Exec) - def do_plugin( self ): + def do_plugin(self): self.do_standard_places() self.do_custom_places() self.do_gtk_bookmarks() - def refreshTrash (self): + def refreshTrash(self): if os.path.exists(self.trash_path) and glob(os.path.join(self.trash_path, "*")): iconName = "user-trash-full" else: diff --git a/usr/lib/linuxmint/mintMenu/plugins/recent.py b/usr/lib/linuxmint/mintMenu/plugins/recent.py index 12d2d27..6141702 100755 --- a/usr/lib/linuxmint/mintMenu/plugins/recent.py +++ b/usr/lib/linuxmint/mintMenu/plugins/recent.py @@ -16,7 +16,7 @@ class pluginclass: It MUST be named pluginclass """ - def __init__( self, mintMenuWin, toggleButton, de ): + def __init__(self, mintMenuWin, toggleButton, de): self.Win = mintMenuWin self.toggleButton = toggleButton @@ -24,16 +24,16 @@ class pluginclass: self.builder = Gtk.Builder() #The Glade file for the plugin - self.builder.add_from_file (os.path.join( os.path.dirname( __file__ ), "recent.glade" )) + self.builder.add_from_file(os.path.join(os.path.dirname(__file__), "recent.glade")) #Set 'window' property for the plugin (Must be the root widget) - self.window = self.builder.get_object( "window1" ) + self.window = self.builder.get_object("window1") #Set 'heading' property for plugin self.heading = _("Recently used") #This should be the first item added to the window in glade - self.content_holder = self.builder.get_object( "eventbox1" ) + self.content_holder = self.builder.get_object("eventbox1") self.recentBox = self.builder.get_object("RecentBox") self.recentAppBox = self.builder.get_object("RecentApps") @@ -41,7 +41,7 @@ class pluginclass: #self.recentApps = [] - self.recentVBox = self.builder.get_object( "vbox1" ) + self.recentVBox = self.builder.get_object("vbox1") #Specify plugin width self.width = 250 @@ -49,90 +49,90 @@ class pluginclass: #Plugin icon self.icon = 'mate-folder.png' - self.settings = EasyGSettings ("com.linuxmint.mintmenu.plugins.recent") + self.settings = EasyGSettings("com.linuxmint.mintmenu.plugins.recent") - self.settings.notifyAdd( 'height', self.RegenPlugin ) - self.settings.notifyAdd( 'width', self.RegenPlugin ) - self.settings.notifyAdd( 'num-recent-docs', self.RegenPlugin ) - self.settings.notifyAdd( 'recent-font-size', self.RegenPlugin ) + self.settings.notifyAdd('height', self.RegenPlugin) + self.settings.notifyAdd('width', self.RegenPlugin) + self.settings.notifyAdd('num-recent-docs', self.RegenPlugin) + self.settings.notifyAdd('recent-font-size', self.RegenPlugin) - self.appSettings = EasyGSettings( "com.linuxmint.mintmenu.plugins.applications" ) - self.appSettings.notifyAdd( "icon-size", self.RegenPlugin ) + self.appSettings = EasyGSettings("com.linuxmint.mintmenu.plugins.applications") + self.appSettings.notifyAdd("icon-size", self.RegenPlugin) self.FileList=[] self.RecManagerInstance = Gtk.RecentManager.get_default() self.recentManagerId = self.RecManagerInstance.connect("changed", self.DoRecent) self.RegenPlugin() - self.builder.get_object( "RecentTabs" ).set_current_page(0) + self.builder.get_object("RecentTabs").set_current_page(0) #Connect event handlers self.builder.get_object("ClrBtn").connect("clicked", self.clrmenu) - def wake (self) : + def wake(self): pass - def destroy( self ): + def destroy(self): self.recentBox.destroy() self.recentVBox.destroy() - self.builder.get_object( "RecentTabs" ).destroy() + self.builder.get_object("RecentTabs").destroy() self.builder.get_object("ClrBtn").destroy() self.content_holder.destroy() self.settings.notifyRemoveAll() if self.recentManagerId: self.RecManagerInstance.disconnect(self.recentManagerId) - def RegenPlugin( self, *args, **kargs ): + def RegenPlugin(self, *args, **kargs): self.GetGSettingsEntries() - def GetGSettingsEntries( self ): - self.recenth = self.settings.get( 'int', 'height' ) - self.recentw = self.settings.get( 'int', 'width' ) - self.numentries = self.settings.get( 'int', 'num-recent-docs' ) + def GetGSettingsEntries(self): + self.recenth = self.settings.get('int', 'height') + self.recentw = self.settings.get('int', 'width') + self.numentries = self.settings.get('int', 'num-recent-docs') RecentHelper.numentries = self.numentries - self.recentfontsize = self.settings.get( 'int', 'recent-font-size' ) + self.recentfontsize = self.settings.get('int', 'recent-font-size') # Hide vertical dotted separator - self.hideseparator = self.settings.get( "bool", "hide-separator" ) + self.hideseparator = self.settings.get("bool", "hide-separator") # Plugin icon - self.icon = self.settings.get( "string", '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" ) - RecentHelper.iconSize = self.appSettings.get( "int", "icon-size") + self.sticky = self.settings.get("bool", "sticky") + self.minimized = self.settings.get("bool", "minimized") + RecentHelper.iconSize = self.appSettings.get("int", "icon-size") self.RebuildPlugin() - def SetHidden( self, state ): - if state == True: - self.settings.set( "bool", "minimized", True ) + def SetHidden(self, minimized): + if minimized: + self.settings.set("bool", "minimized", True) else: - self.settings.set( "bool", "minimized", False ) + self.settings.set("bool", "minimized", False) def RebuildPlugin(self): - self.content_holder.set_size_request(self.recentw, self.recenth ) + self.content_holder.set_size_request(self.recentw, self.recenth) # TODO print "recent.RebuildPlugin calling recent.DoRecent" self.DoRecent() - def DoRecent( self, *args, **kargs ): + def DoRecent(self, *args, **kargs): for i in self.recentBox.get_children(): i.destroy() - self.recentVBox.set_size_request( self.recentw, self.recenth ) - if len( self.recentBox.get_children() ) < self.numentries: - n=len( self.recentBox.get_children() )-1 + self.recentVBox.set_size_request(self.recentw, self.recenth) + if len(self.recentBox.get_children()) < self.numentries: + n=len(self.recentBox.get_children())-1 else: n=self.numentries-1 while n >= 0: - self.recentBox.remove( self.recentBox.get_children()[n] ) + self.recentBox.remove(self.recentBox.get_children()[n]) n-=1 self.FileList, self.IconList = self.GetRecent() loc = 0 for Name in self.FileList: if Name != None: - self.AddRecentBtn( Name, self.IconList[loc] ) + self.AddRecentBtn(Name, self.IconList[loc]) loc = loc + 1 # TODO @@ -148,14 +148,14 @@ class pluginclass: self.DoRecent() return - def AddRecentBtn( self, Name, RecentImage ): - DispName=os.path.basename( Name ) + def AddRecentBtn(self, Name, RecentImage): + DispName=os.path.basename(Name) - AButton = Gtk.Button( "", "ok", True ) - AButton.remove( AButton.get_children()[0] ) - AButton.set_size_request( 200, -1 ) - AButton.set_relief( Gtk.ReliefStyle.NONE ) - AButton.connect( "clicked", self.callback, Name ) + AButton = Gtk.Button("", "ok", True) + AButton.remove(AButton.get_children()[0]) + AButton.set_size_request(200, -1) + AButton.set_relief(Gtk.ReliefStyle.NONE) + AButton.connect("clicked", self.callback, Name) AButton.show() Box1 = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=5) @@ -165,14 +165,14 @@ class pluginclass: ButtonIcon.set_from_pixbuf(RecentImage) Box1.add(ButtonIcon) - Label1 = Gtk.Label( DispName ) - Label1.set_ellipsize( Pango.EllipsizeMode.END ) - Box1.add( Label1 ) + Label1 = Gtk.Label(DispName) + Label1.set_ellipsize(Pango.EllipsizeMode.END) + Box1.add(Label1) - AButton.add( Box1 ) + AButton.add(Box1) AButton.show_all() - self.recentBox.pack_start( AButton, False, True, 0 ) + self.recentBox.pack_start(AButton, False, True, 0) def callback(self, widget, filename=None): self.Win.hide() @@ -207,23 +207,23 @@ class pluginclass: break return FileString, IconString - def ButtonClicked( self, widget, event, Exec ): + def ButtonClicked(self, widget, event, Exec): self.press_x = event.x self.press_y = event.y self.Exec = Exec - def ButtonReleased( self, w, ev, ev2 ): + def ButtonReleased(self, w, ev, ev2): if ev.button == 1: - if not hasattr( self, "press_x" ) or \ - not w.drag_check_threshold( int( self.press_x ), - int( self.press_y ), - int( ev.x ), - int( ev.y ) ): + if not hasattr(self, "press_x") or \ + not w.drag_check_threshold(int(self.press_x), + int(self.press_y), + int(ev.x), + int(ev.y)): if self.Win.pinmenu == False: - self.Win.wTree.get_widget( "window1" ).hide() + self.Win.wTree.get_widget("window1").hide() if "applications" in self.Win.plugins: - self.Win.plugins["applications"].wTree.get_widget( "entry1" ).grab_focus() - Execute( w, self.Exec ) + 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): diff --git a/usr/lib/linuxmint/mintMenu/plugins/recentHelper.py b/usr/lib/linuxmint/mintMenu/plugins/recentHelper.py index 377bcfc..5d61a56 100644 --- a/usr/lib/linuxmint/mintMenu/plugins/recentHelper.py +++ b/usr/lib/linuxmint/mintMenu/plugins/recentHelper.py @@ -9,53 +9,50 @@ from gi.repository import Gtk from plugins.easybuttons import ApplicationLauncher + recentApps = [] mintMenuWin = None recentAppBox = None numentries = 10 iconSize = 16 -def recentAppsAdd( recentAppsButton ): +def recentAppsAdd(recentAppsButton): if recentAppsButton: - - recentApps.insert(0, recentAppsButton ) - + recentApps.insert(0, recentAppsButton) counter = 0 for recentApp in recentApps: - if counter != 0 and ( recentApp.desktopFile == recentAppsButton.desktopFile or counter >= numentries ): + if counter != 0 and (recentApp.desktopFile == recentAppsButton.desktopFile or counter >= numentries): del recentApps[counter] counter = counter + 1 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") - 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() -def recentAppBuildLauncher( location ): +def recentAppBuildLauncher(location): try: # For Folders and Network Shares - location = "".join( location.split( "%20" ) ) + location = "".join(location.split("%20")) # ButtonIcon = None - # if location.startswith( "file" ): + # if location.startswith("file"): # ButtonIcon = "mate-fs-directory" - # if location.startswith( "smb" ) or location.startswith( "ssh" ) or location.startswith( "network" ): + # if location.startswith("smb") or location.startswith("ssh") or location.startswith("network"): # ButtonIcon = "mate-fs-network" #For Special locations @@ -65,16 +62,16 @@ def recentAppBuildLauncher( location ): location = "/usr/share/applications/nautilus-home.desktop" elif location == "x-nautilus-desktop:///network": location = "/usr/share/applications/network-scheme.desktop" - elif location.startswith( "x-nautilus-desktop:///" ): + elif location.startswith("x-nautilus-desktop:///"): location = "/usr/share/applications/nautilus-computer.desktop" - if location.startswith( "file://" ): + if location.startswith("file://"): location = location[7:] - appButton = ApplicationLauncher( location, iconSize) + appButton = ApplicationLauncher(location, iconSize) if appButton.appExec: appButton.show() - appButton.connect( "clicked", applicationButtonClicked ) + appButton.connect("clicked", applicationButtonClicked) appButton.type = "location" return appButton except Exception, e: @@ -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() @@ -99,15 +94,15 @@ def buildRecentApps(): app = app.strip() if app[0:9] == "location:": - appButton = recentAppBuildLauncher( app[9:] ) + appButton = recentAppBuildLauncher(app[9:]) else: - if ( app.endswith( ".desktop" ) ): - appButton = recentAppBuildLauncher( app ) + if (app.endswith(".desktop")): + appButton = recentAppBuildLauncher(app) else: appButton = None if appButton: - recentApps.append( appButton ) + recentApps.append(appButton) except Exception, e: print e return recentApps @@ -124,15 +119,13 @@ 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 ) + AButton.set_size_request(200, -1) + AButton.set_relief(Gtk.ReliefStyle.NONE) + recentAppBox.pack_start(AButton, False, True, 0) return True -def applicationButtonClicked( widget ): +def applicationButtonClicked(widget): # TODO all this runs whether the plugin is enabled or not mintMenuWin.hide() recentAppsAdd(widget) diff --git a/usr/lib/linuxmint/mintMenu/plugins/system_management.py b/usr/lib/linuxmint/mintMenu/plugins/system_management.py index 78f432c..e47edaa 100755 --- a/usr/lib/linuxmint/mintMenu/plugins/system_management.py +++ b/usr/lib/linuxmint/mintMenu/plugins/system_management.py @@ -14,103 +14,102 @@ from plugins.execute import Execute # i18n gettext.install("mintmenu", "/usr/share/linuxmint/locale") -class pluginclass( object ): +class pluginclass(object): - def __init__( self, mintMenuWin, toggleButton, de ): + def __init__(self, mintMenuWin, toggleButton, de): self.mintMenuWin = mintMenuWin 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" )) + self.builder.add_from_file(os.path.join(os.path.dirname(__file__), "system_management.glade")) - self.systemBtnHolder = self.builder.get_object( "system_button_holder" ) - self.editableBtnHolder = self.builder.get_object( "editable_button_holder" ) - self.scrolledWindow = self.builder.get_object( "scrolledwindow2" ) + self.systemBtnHolder = self.builder.get_object("system_button_holder") + self.editableBtnHolder = self.builder.get_object("editable_button_holder") + self.scrolledWindow = self.builder.get_object("scrolledwindow2") # 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 = _("System") # This should be the first item added to the window in glade - self.content_holder = self.builder.get_object( "System" ) + self.content_holder = self.builder.get_object("System") # Items to get custom colors - self.itemstocolor = [ self.builder.get_object( "viewport2" ) ] + self.itemstocolor = [self.builder.get_object("viewport2")] # Gconf stuff - self.settings = EasyGSettings( "com.linuxmint.mintmenu.plugins.system_management" ) + self.settings = EasyGSettings("com.linuxmint.mintmenu.plugins.system_management") - self.settings.notifyAdd( "icon-size", self.RegenPlugin ) - self.settings.notifyAdd( "show-control-center", self.RegenPlugin ) - self.settings.notifyAdd( "show-lock-screen", self.RegenPlugin ) - self.settings.notifyAdd( "show-logout", self.RegenPlugin ) - self.settings.notifyAdd( "show-package-manager", self.RegenPlugin ) - self.settings.notifyAdd( "show-software-manager", self.RegenPlugin ) - self.settings.notifyAdd( "show-terminal", self.RegenPlugin ) - self.settings.notifyAdd( "show-quit", self.RegenPlugin ) - self.settings.notifyAdd( "allow-scrollbar", self.RegenPlugin ) - self.settings.notifyAdd( "height", self.changePluginSize ) - self.settings.notifyAdd( "width", self.changePluginSize ) - self.settings.bindGSettingsEntryToVar( "bool", "sticky", self, "sticky" ) + self.settings.notifyAdd("icon-size", self.RegenPlugin) + self.settings.notifyAdd("show-control-center", self.RegenPlugin) + self.settings.notifyAdd("show-lock-screen", self.RegenPlugin) + self.settings.notifyAdd("show-logout", self.RegenPlugin) + self.settings.notifyAdd("show-package-manager", self.RegenPlugin) + self.settings.notifyAdd("show-software-manager", self.RegenPlugin) + self.settings.notifyAdd("show-terminal", self.RegenPlugin) + self.settings.notifyAdd("show-quit", self.RegenPlugin) + self.settings.notifyAdd("allow-scrollbar", self.RegenPlugin) + self.settings.notifyAdd("height", self.changePluginSize) + self.settings.notifyAdd("width", self.changePluginSize) + self.settings.bindGSettingsEntryToVar("bool", "sticky", self, "sticky") self.GetGSettingsEntries() - self.content_holder.set_size_request( self.width, self.height ) + self.content_holder.set_size_request(self.width, self.height) - def destroy( self ): + def destroy(self): self.settings.notifyRemoveAll() - def wake (self) : + def wake(self) : pass - def changePluginSize( self, settings, key, args ): - self.allowScrollbar = self.settings.get( "bool", "allow-scrollbar") + def changePluginSize(self, settings, key, args): + self.allowScrollbar = self.settings.get("bool", "allow-scrollbar") 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 ) + self.scrolledWindow.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.NEVER) else: - self.scrolledWindow.set_policy( Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC ) + self.scrolledWindow.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) self.height = settings.get_int(key) - self.content_holder.set_size_request( self.width, self.height ) + self.content_holder.set_size_request(self.width, self.height) - def RegenPlugin( self, *args, **kargs ): + def RegenPlugin(self, *args, **kargs): self.GetGSettingsEntries() self.ClearAll() self.do_standard_items() - def GetGSettingsEntries( self ): + def GetGSettingsEntries(self): - self.width = self.settings.get( "int", "width") - self.allowScrollbar = self.settings.get( "bool", "allow-scrollbar") - 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.width = self.settings.get("int", "width") + self.allowScrollbar = self.settings.get("bool", "allow-scrollbar") + 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 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 ) - self.iconsize = self.settings.get( "int","icon-size") + 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 toggles - self.showSoftwareManager = self.settings.get( "bool", "show-software-manager") - self.showPackageManager = self.settings.get( "bool", "show-package-manager") - self.showControlCenter = self.settings.get( "bool", "show-control-center") - self.showTerminal = self.settings.get( "bool", "show-terminal") - self.showLockScreen = self.settings.get( "bool", "show-lock-screen") - self.showLogout = self.settings.get( "bool", "show-logout") - self.showQuit = self.settings.get( "bool", "show-quit") + self.showSoftwareManager = self.settings.get("bool", "show-software-manager") + self.showPackageManager = self.settings.get("bool", "show-package-manager") + self.showControlCenter = self.settings.get("bool", "show-control-center") + self.showTerminal = self.settings.get("bool", "show-terminal") + self.showLockScreen = self.settings.get("bool", "show-lock-screen") + self.showLogout = self.settings.get("bool", "show-logout") + self.showQuit = self.settings.get("bool", "show-quit") if self.de == "cinnamon": self.lock_cmd = "cinnamon-screensaver-command --lock" @@ -134,12 +133,12 @@ class pluginclass( object ): self.settings_cmd = "mate-control-center" # Hide vertical dotted separator - self.hideseparator = self.settings.get( "bool", "hide-separator") + self.hideseparator = self.settings.get("bool", "hide-separator") # Plugin icon - self.icon = self.settings.get( "string", "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") + self.sticky = self.settings.get("bool", "sticky") + self.minimized = self.settings.get("bool", "minimized") def ClearAll(self): for child in self.systemBtnHolder.get_children(): @@ -148,65 +147,65 @@ class pluginclass( object ): child.destroy() #Add standard items - def do_standard_items( self ): + 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" ) + Button1 = easyButton("mintinstall", self.iconsize, [_("Software Manager")], -1, -1) + Button1.connect("clicked", self.ButtonClicked, "mintinstall") Button1.show() - self.systemBtnHolder.pack_start( Button1, False, False, 0) - self.mintMenuWin.setTooltip( Button1, _("Browse and install available software") ) + self.systemBtnHolder.pack_start(Button1, False, False, 0) + self.mintMenuWin.setTooltip(Button1, _("Browse and install available software")) - if ( self.showPackageManager == True ): - Button2 = easyButton( "applications-system", self.iconsize, [_("Package Manager")], -1, -1 ) - Button2.connect( "clicked", self.ButtonClicked, "synaptic-pkexec" ) + 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") ) + self.systemBtnHolder.pack_start(Button2, False, False, 0) + self.mintMenuWin.setTooltip(Button2, _("Install, remove and upgrade software packages")) - if ( self.showControlCenter == True ): - Button3 = easyButton( "gtk-preferences", self.iconsize, [_("Control Center")], -1, -1 ) - Button3.connect( "clicked", self.ButtonClicked, self.settings_cmd ) + 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") ) + self.systemBtnHolder.pack_start(Button3, False, False, 0) + self.mintMenuWin.setTooltip(Button3, _("Configure your system")) - if ( self.showTerminal == True ): - Button4 = easyButton( "terminal", self.iconsize, [_("Terminal")], -1, -1 ) + 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 ) + Button4.connect("clicked", self.ButtonClicked, self.terminal_cmd) else: - Button4.connect( "clicked", self.ButtonClicked, "x-terminal-emulator" ) + Button4.connect("clicked", self.ButtonClicked, "x-terminal-emulator") Button4.show() - self.systemBtnHolder.pack_start( Button4, False, False, 0 ) - self.mintMenuWin.setTooltip( Button4, _("Use the command line") ) + self.systemBtnHolder.pack_start(Button4, False, False, 0) + self.mintMenuWin.setTooltip(Button4, _("Use the command line")) - if ( self.showLockScreen == True ): - Button5 = easyButton( "system-lock-screen", self.iconsize, [_("Lock Screen")], -1, -1 ) - Button5.connect( "clicked", self.ButtonClicked, self.lock_cmd ) + 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") ) + self.systemBtnHolder.pack_start(Button5, False, False, 0) + self.mintMenuWin.setTooltip(Button5, _("Requires password to unlock")) - if ( self.showLogout == True ): - Button6 = easyButton( "system-log-out", self.iconsize, [_("Logout")], -1, -1 ) - Button6.connect( "clicked", self.ButtonClicked, self.logout_cmd ) + 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") ) + self.systemBtnHolder.pack_start(Button6, False, False, 0) + self.mintMenuWin.setTooltip(Button6, _("Log out or switch user")) - if ( self.showQuit == True ): - Button7 = easyButton( "system-shutdown", self.iconsize, [_("Quit")], -1, -1 ) - Button7.connect( "clicked", self.ButtonClicked, self.shutdown_cmd ) + if self.showQuit: + Button7 = easyButton("system-shutdown", self.iconsize, [_("Quit")], -1, -1) + Button7.connect("clicked", self.ButtonClicked, self.shutdown_cmd) Button7.show() - self.systemBtnHolder.pack_start( Button7, False, False, 0 ) - self.mintMenuWin.setTooltip( Button7, _("Shutdown, restart, suspend or hibernate") ) + self.systemBtnHolder.pack_start(Button7, False, False, 0) + self.mintMenuWin.setTooltip(Button7, _("Shutdown, restart, suspend or hibernate")) - def ButtonClicked( self, widget, Exec ): + def ButtonClicked(self, widget, Exec): self.mintMenuWin.hide() if Exec: - Execute( Exec ) + Execute(Exec) - def do_plugin( self ): + def do_plugin(self): self.do_standard_items()