Convert system management plugin

This commit is contained in:
Michael Webster 2013-03-05 21:14:11 -05:00
parent 3884197e01
commit 1b1781d78f
5 changed files with 271 additions and 119 deletions

View File

@ -868,7 +868,7 @@ class pluginclass( object ):
insertBefore = True
if widget.type == "location":
mTree = self.builder( "favoritesMenu" )
mTree = self.builder.get_object( "favoritesMenu" )
#i18n
desktopMenuItem = Gtk.MenuItem(_("Add to desktop"))
@ -899,44 +899,44 @@ class pluginclass( object ):
propsMenuItem.connect( "activate", self.onPropsApp, widget)
if self.de == "mate":
mTree.get_widget("favoritesMenu").append(desktopMenuItem)
mTree.get_widget("favoritesMenu").append(panelMenuItem)
mTree.get_widget("favoritesMenu").append(separator1)
mTree.get_widget("favoritesMenu").append(insertSpaceMenuItem)
mTree.get_widget("favoritesMenu").append(insertSeparatorMenuItem)
mTree.get_widget("favoritesMenu").append(separator2)
mTree.get_widget("favoritesMenu").append(startupMenuItem)
mTree.get_widget("favoritesMenu").append(separator3)
mTree.get_widget("favoritesMenu").append(launchMenuItem)
mTree.get_widget("favoritesMenu").append(removeFromFavMenuItem)
mTree.get_widget("favoritesMenu").append(separator4)
mTree.get_widget("favoritesMenu").append(propsMenuItem)
mTree.append(desktopMenuItem)
mTree.append(panelMenuItem)
mTree.append(separator1)
mTree.append(insertSpaceMenuItem)
mTree.append(insertSeparatorMenuItem)
mTree.append(separator2)
mTree.append(startupMenuItem)
mTree.append(separator3)
mTree.append(launchMenuItem)
mTree.append(removeFromFavMenuItem)
mTree.append(separator4)
mTree.append(propsMenuItem)
mTree.get_widget("favoritesMenu").show_all()
mTree.show_all()
mTree.get_widget( "favoritesMenu" ).popup( None, None, None, ev.button, ev.time )
mTree.popup( None, None, None, ev.button, ev.time )
self.mintMenuWin.grab()
else:
mTree = self.builder( "favoritesMenuExtra" )
mTree = self.builder.get_object( "favoritesMenuExtra" )
#i18n
removeMenuItem = Gtk.MenuItem(_("Remove"))
insertSpaceMenuItem = Gtk.MenuItem(_("Insert space"))
insertSeparatorMenuItem = Gtk.MenuItem(_("Insert separator"))
mTree.get_widget("favoritesMenuExtra").append(removeMenuItem)
mTree.get_widget("favoritesMenuExtra").append(insertSpaceMenuItem)
mTree.get_widget("favoritesMenuExtra").append(insertSeparatorMenuItem)
mTree.get_widget("favoritesMenuExtra").show_all()
mTree.append(removeMenuItem)
mTree.append(insertSpaceMenuItem)
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 )
mTree.get_widget( "favoritesMenuExtra" ).popup( None, None, None, ev.button, ev.time )
mTree.popup( None, None, None, ev.button, ev.time )
self.mintMenuWin.grab()
def menuPopup( self, widget, event ):
if event.button == 3:
mTree = self.builder ( "applicationsMenu" )
mTree = self.builder.get_object ( "applicationsMenu" )
#i18n
desktopMenuItem = Gtk.MenuItem(_("Add to desktop"))
@ -952,26 +952,26 @@ class pluginclass( object ):
propsMenuItem = Gtk.MenuItem(_("Edit properties"))
if self.de == "mate":
mTree.get_widget("applicationsMenu").append(desktopMenuItem)
mTree.get_widget("applicationsMenu").append(panelMenuItem)
mTree.get_widget("applicationsMenu").append(separator1)
mTree.append(desktopMenuItem)
mTree.append(panelMenuItem)
mTree.append(separator1)
mTree.get_widget("applicationsMenu").append(favoriteMenuItem)
mTree.get_widget("applicationsMenu").append(startupMenuItem)
mTree.append(favoriteMenuItem)
mTree.append(startupMenuItem)
mTree.get_widget("applicationsMenu").append(separator2)
mTree.append(separator2)
mTree.get_widget("applicationsMenu").append(launchMenuItem)
mTree.get_widget("applicationsMenu").append(uninstallMenuItem)
mTree.append(launchMenuItem)
mTree.append(uninstallMenuItem)
if home in widget.desktopFile:
mTree.get_widget("applicationsMenu").append(deleteMenuItem)
mTree.append(deleteMenuItem)
deleteMenuItem.connect("activate", self.delete_from_menu, widget)
mTree.get_widget("applicationsMenu").append(separator3)
mTree.append(separator3)
mTree.get_widget("applicationsMenu").append(propsMenuItem)
mTree.append(propsMenuItem)
mTree.get_widget("applicationsMenu").show_all()
mTree.show_all()
desktopMenuItem.connect("activate", self.add_to_desktop, widget)
panelMenuItem.connect("activate", self.add_to_panel, widget)
@ -994,8 +994,8 @@ class pluginclass( object ):
startupMenuItem.set_active( False )
startupMenuItem.connect( "toggled", self.onAddToStartup, widget )
mTree.get_widget( "applicationsMenu" ).connect( 'deactivate', self.onMenuPopupDeactivate)
mTree.get_widget( "applicationsMenu" ).popup( None, None, None, event.button, event.time )
mTree.connect( 'deactivate', self.onMenuPopupDeactivate)
mTree.popup( None, None, None, event.button, event.time )
def onMenuPopupDeactivate( self, widget):
self.mintMenuWin.grab()

View File

@ -1,56 +1,56 @@
<?xml version="1.0"?>
<glade-interface>
<interface>
<!-- interface-requires gtk+ 2.6 -->
<!-- interface-naming-policy toplevel-contextual -->
<widget class="GtkWindow" id="mainWindow">
<signal name="destroy" handler="on_window1_destroy"/>
<object class="GtkWindow" id="mainWindow">
<signal handler="on_window1_destroy" name="destroy"/>
<child>
<widget class="GtkEventBox" id="System">
<object class="GtkEventBox" id="System">
<property name="visible">True</property>
<child>
<widget class="GtkScrolledWindow" id="scrolledwindow2">
<object class="GtkScrolledWindow" id="scrolledwindow2">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hscrollbar_policy">automatic</property>
<property name="vscrollbar_policy">automatic</property>
<signal name="drag_motion" handler="on_scrolledwindow_drag_motion"/>
<signal name="drag_drop" handler="on_scrolledwindow_drag_drop"/>
<signal name="drag_data_received" handler="on_scrolledwindow_drag_data_received"/>
<signal handler="on_scrolledwindow_drag_motion" name="drag_motion"/>
<signal handler="on_scrolledwindow_drag_drop" name="drag_drop"/>
<signal handler="on_scrolledwindow_drag_data_received" name="drag_data_received"/>
<child>
<widget class="GtkViewport" id="viewport2">
<object class="GtkViewport" id="viewport2">
<property name="visible">True</property>
<property name="shadow_type">none</property>
<child>
<widget class="GtkVBox" id="vbox1">
<object class="GtkVBox" id="vbox1">
<property name="visible">True</property>
<child>
<widget class="GtkVBox" id="system_button_holder">
<object class="GtkVBox" id="system_button_holder">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="spacing">2</property>
</widget>
</object>
<packing>
<property name="position">0</property>
</packing>
</child>
<child>
<widget class="GtkVButtonBox" id="editable_button_holder">
<object class="GtkVButtonBox" id="editable_button_holder">
<property name="visible">True</property>
<property name="layout_style">start</property>
</widget>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</widget>
</object>
</child>
</widget>
</object>
</child>
</widget>
</object>
</child>
</widget>
</object>
</child>
</widget>
</glade-interface>
</object>
</interface>

View File

@ -0,0 +1,56 @@
<?xml version="1.0"?>
<glade-interface>
<!-- interface-requires gtk+ 2.6 -->
<!-- interface-naming-policy toplevel-contextual -->
<widget class="GtkWindow" id="mainWindow">
<signal name="destroy" handler="on_window1_destroy"/>
<child>
<widget class="GtkEventBox" id="System">
<property name="visible">True</property>
<child>
<widget class="GtkScrolledWindow" id="scrolledwindow2">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hscrollbar_policy">automatic</property>
<property name="vscrollbar_policy">automatic</property>
<signal name="drag_motion" handler="on_scrolledwindow_drag_motion"/>
<signal name="drag_drop" handler="on_scrolledwindow_drag_drop"/>
<signal name="drag_data_received" handler="on_scrolledwindow_drag_data_received"/>
<child>
<widget class="GtkViewport" id="viewport2">
<property name="visible">True</property>
<property name="shadow_type">none</property>
<child>
<widget class="GtkVBox" id="vbox1">
<property name="visible">True</property>
<child>
<widget class="GtkVBox" id="system_button_holder">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="spacing">2</property>
</widget>
<packing>
<property name="position">0</property>
</packing>
</child>
<child>
<widget class="GtkVButtonBox" id="editable_button_holder">
<property name="visible">True</property>
<property name="layout_style">start</property>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</widget>
</child>
</widget>
</child>
</widget>
</child>
</widget>
</child>
</widget>
</glade-interface>

View File

@ -1,14 +1,16 @@
#!/usr/bin/env python
import gtk
import gtk.glade
import gi
gi.require_version("Gtk", "2.0")
from gi.repository import Gtk
import os
import string
import gettext
from easybuttons import *
from execute import Execute
from easygconf import EasyGConf
from easygsettings import EasyGSettings
# i18n
gettext.install("mintmenu", "/usr/share/linuxmint/locale")
@ -21,103 +23,104 @@ class pluginclass( object ):
self.toggleButton = toggleButton
self.de = de
# Read GLADE file
gladefile = os.path.join( os.path.dirname( __file__ ), "system_management.glade" )
wTree = gtk.glade.XML( gladefile, "mainWindow" )
self.systemBtnHolder = wTree.get_widget( "system_button_holder" )
self.editableBtnHolder = wTree.get_widget( "editable_button_holder" )
self.scrolledWindow = wTree.get_widget( "scrolledwindow2" )
self.builder = Gtk.Builder()
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" )
# These properties are NECESSARY to maintain consistency
# Set 'window' property for the plugin (Must be the root widget)
self.window = wTree.get_widget( "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 = wTree.get_widget( "System" )
self.content_holder = self.builder.get_object( "System" )
# Items to get custom colors
self.itemstocolor = [ wTree.get_widget( "viewport2" ) ]
self.itemstocolor = [ self.builder.get_object( "viewport2" ) ]
# Gconf stuff
self.gconf = EasyGConf( "/apps/mintMenu/plugins/system-management/" )
self.settings = EasyGSettings( "com.linuxmint.mintmenu.plugins.system_management" )
self.gconf.notifyAdd( "icon_size", self.RegenPlugin )
self.gconf.notifyAdd( "show_control_center", self.RegenPlugin )
self.gconf.notifyAdd( "show_lock_screen", self.RegenPlugin )
self.gconf.notifyAdd( "show_logout", self.RegenPlugin )
self.gconf.notifyAdd( "show_package_manager", self.RegenPlugin )
self.gconf.notifyAdd( "show_software_manager", self.RegenPlugin )
self.gconf.notifyAdd( "show_terminal", self.RegenPlugin )
self.gconf.notifyAdd( "show_quit", self.RegenPlugin )
self.gconf.notifyAdd( "allowScrollbar", self.RegenPlugin )
self.gconf.notifyAdd( "height", self.changePluginSize )
self.gconf.notifyAdd( "width", self.changePluginSize )
self.gconf.bindGconfEntryToVar( "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.GetGconfEntries()
self.GetGSettingsEntries()
self.content_holder.set_size_request( self.width, self.height )
def destroy( self ):
self.gconf.notifyRemoveAll()
self.settings.notifyRemoveAll()
def wake (self) :
pass
def changePluginSize( self, client, connection_id, entry, args ):
self.allowScrollbar = self.gconf.get( "bool", "allowScrollbar", False)
if entry.get_key() == self.gconf.gconfDir+"width":
self.width = entry.get_value().get_int()
elif entry.get_key() == self.gconf.gconfDir+"height":
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):
self.height = -1
self.scrolledWindow.set_policy( gtk.POLICY_AUTOMATIC, gtk.POLICY_NEVER )
self.scrolledWindow.set_policy( Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.NEVER )
else:
self.scrolledWindow.set_policy( gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC )
self.height = entry.get_value().get_int()
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 )
def RegenPlugin( self, *args, **kargs ):
self.GetGconfEntries()
def RegenPlugin( self, settings, key, args ):
self.GetGSettingsEntries()
self.ClearAll()
self.do_standard_items()
def GetGconfEntries( self ):
def GetGSettingsEntries( self ):
self.width = self.gconf.get( "int", "width", 200 )
self.allowScrollbar = self.gconf.get( "bool", "allowScrollbar", False)
self.scrolledWindow.set_policy( gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC )
self.height = self.gconf.get( "int", "height", 180 )
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.height = -1
self.scrolledWindow.set_policy( gtk.POLICY_AUTOMATIC, gtk.POLICY_NEVER )
self.scrolledWindow.set_policy( Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.NEVER )
self.content_holder.set_size_request( self.width, self.height )
self.iconsize = self.gconf.get( "int","icon_size", 16 )
self.iconsize = self.settings.get( "int","icon-size")
# Check toggles
self.showSoftwareManager = self.gconf.get( "bool", "show_software_manager", True )
self.showPackageManager = self.gconf.get( "bool", "show_package_manager", True )
self.showControlCenter = self.gconf.get( "bool", "show_control_center", True )
self.showTerminal = self.gconf.get( "bool", "show_terminal", True )
self.showLockScreen = self.gconf.get( "bool", "show_lock_screen", True )
self.showLogout = self.gconf.get( "bool", "show_logout", True )
self.showQuit = self.gconf.get( "bool", "show_quit", True )
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")
# Hide vertical dotted separator
self.hideseparator = self.gconf.get( "bool", "hide_separator", False )
self.hideseparator = self.settings.get( "bool", "hide-separator")
# Plugin icon
self.icon = self.gconf.get( "string", 'icon', "preferences-system" )
self.icon = self.settings.get( "string", "icon" )
# Allow plugin to be minimized to the left plugin pane
self.sticky = self.gconf.get( "bool", "sticky", False )
self.minimized = self.gconf.get( "bool", "minimized", False )
self.sticky = self.settings.get( "bool", "sticky")
self.minimized = self.settings.get( "bool", "minimized")
def ClearAll(self):
for child in self.systemBtnHolder.get_children():
@ -133,14 +136,14 @@ class pluginclass( object ):
Button1 = easyButton( "/usr/lib/linuxmint/mintInstall/icon.svg", self.iconsize, [_("Software Manager")], -1, -1 )
Button1.connect( "clicked", self.ButtonClicked, "gksu mintinstall" )
Button1.show()
self.systemBtnHolder.pack_start( Button1, False, False )
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, "gksu /usr/sbin/synaptic" )
Button2.show()
self.systemBtnHolder.pack_start( Button2, False, False )
self.systemBtnHolder.pack_start( Button2, False, False, 0 )
self.mintMenuWin.setTooltip( Button2, _("Install, remove and upgrade software packages") )
if ( self.showControlCenter == True ):
@ -150,7 +153,7 @@ class pluginclass( object ):
else:
Button3.connect( "clicked", self.ButtonClicked, "mate-control-center" )
Button3.show()
self.systemBtnHolder.pack_start( Button3, False, False )
self.systemBtnHolder.pack_start( Button3, False, False, 0 )
self.mintMenuWin.setTooltip( Button3, _("Configure your system") )
if ( self.showTerminal == True ):
@ -160,14 +163,14 @@ class pluginclass( object ):
else:
Button4.connect( "clicked", self.ButtonClicked, "x-terminal-emulator" )
Button4.show()
self.systemBtnHolder.pack_start( Button4, False, False )
self.systemBtnHolder.pack_start( Button4, False, False, 0 )
self.mintMenuWin.setTooltip( Button4, _("Use the command line") )
if self.de == "xfce":
Button6 = easyButton( "system-log-out", self.iconsize, [_("Logout")], -1, -1 )
Button6.connect( "clicked", self.ButtonClicked, "xfce4-session-logout" )
Button6.show()
self.systemBtnHolder.pack_start( Button6, False, False )
self.systemBtnHolder.pack_start( Button6, False, False, 0 )
self.mintMenuWin.setTooltip( Button6, _("Log out or switch user") )
else:
if ( self.showLockScreen == True ):
@ -177,21 +180,21 @@ class pluginclass( object ):
else:
Button5.connect( "clicked", self.ButtonClicked, "xdg-screensaver lock" )
Button5.show()
self.systemBtnHolder.pack_start( Button5, False, False )
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, "mate-session-save --logout-dialog" )
Button6.show()
self.systemBtnHolder.pack_start( Button6, False, False )
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, "mate-session-save --shutdown-dialog" )
Button7.show()
self.systemBtnHolder.pack_start( Button7, False, False )
self.systemBtnHolder.pack_start( Button7, False, False, 0 )
self.mintMenuWin.setTooltip( Button7, _("Shutdown, restart, suspend or hibernate") )
def ButtonClicked( self, widget, Exec ):

View File

@ -312,9 +312,102 @@
<summary></summary>
<description></description>
</key>
</schema>
<schema id="com.linuxmint.mintmenu.plugins.system_management" path="/com/linuxmint/mintmenu/plugins/system_management/">
<key type="i" name="width">
<default>200</default>
<summary></summary>
<description></description>
</key>
<key type="i" name="height">
<default>180</default>
<summary></summary>
<description></description>
</key>
<key type="b" name="allow-scrollbar">
<default>false</default>
<summary></summary>
<description></description>
</key>
<key type="i" name="icon-size">
<default>16</default>
<summary></summary>
<description></description>
</key>
<key type="b" name="show-software-manager">
<default>true</default>
<summary></summary>
<description></description>
</key>
<key type="b" name="show-package-manager">
<default>true</default>
<summary></summary>
<description></description>
</key>
<key type="b" name="show-control-center">
<default>true</default>
<summary></summary>
<description></description>
</key>
<key type="b" name="show-terminal">
<default>true</default>
<summary></summary>
<description></description>
</key>
<key type="b" name="show-lock-screen">
<default>true</default>
<summary></summary>
<description></description>
</key>
<key type="b" name="show-logout">
<default>true</default>
<summary></summary>
<description></description>
</key>
<key type="b" name="show-quit">
<default>true</default>
<summary></summary>
<description></description>
</key>
<key type="b" name="hide-separator">
<default>false</default>
<summary></summary>
<description></description>
</key>
<key type="b" name="sticky">
<default>false</default>
<summary></summary>
<description></description>
</key>
<key type="b" name="minimized">
<default>false</default>
<summary></summary>
<description></description>
</key>
<key type="s" name="icon">
<default>"preferences-system"</default>
<summary></summary>
<description></description>
</key>
</schema>
</schemalist>