5dac4ea22b
git-svn-id: http://svn.sabayonlinux.org/overlay@1513 d7aec97c-591d-0410-af39-a8856400b30a
198 lines
6.9 KiB
Python
Executable File
198 lines
6.9 KiB
Python
Executable File
#! /usr/bin/python
|
|
|
|
#
|
|
#Screenlets-control - Program for managing Screenlets
|
|
#Copyright (C) 2007 Hendrik Kaju <hendrik@kaju.pri.ee>
|
|
#
|
|
#This program is free software; you can redistribute it and/or
|
|
#modify it under the terms of the GNU General Public License
|
|
#as published by the Free Software Foundation; either version 2
|
|
#of the License, or (at your option) any later version.
|
|
#
|
|
#This program is distributed in the hope that it will be useful,
|
|
#but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
#GNU General Public License for more details.
|
|
#
|
|
#You should have received a copy of the GNU General Public License
|
|
#along with this program; if not, write to the Free Software
|
|
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
#
|
|
|
|
import sys
|
|
import pygtk
|
|
pygtk.require("2.0")
|
|
import gtk
|
|
import gtk.glade
|
|
import os
|
|
import commands
|
|
|
|
class ScreenletsManager:
|
|
"""Settings manager for screenlets"""
|
|
|
|
#Default screenlets that come with the .deb
|
|
default_screenlets = ['Calendar', 'Clock', 'Control', 'Example',
|
|
'Rss', 'Systemstatus', 'CPUMeter', 'Notes',
|
|
'Convert', 'Launcher', 'Ruler', 'Pager',
|
|
'MailCheck', 'Weather', 'Windowlist', 'Calc']
|
|
|
|
#Will be /usr/share/screenlets when 0.0.8 comes out
|
|
screenlets_dir = "/usr/share/screenlets/"
|
|
|
|
def __init__(self):
|
|
#Glade project file
|
|
gladefile = self.screenlets_dir + "controlpanel.glade"
|
|
self.wTree = gtk.glade.XML(gladefile)
|
|
#connect signals
|
|
dic = { "on_install_button_clicked" : self.install_button_clicked,
|
|
"on_MainWindow_destroy" : gtk.main_quit,
|
|
"on_quit_button_clicked" : gtk.main_quit,
|
|
"on_load_button_clicked" : self.load_button_clicked,
|
|
"on_backup_button_clicked" : self.backup_button_clicked,
|
|
"on_restore_button_clicked" : self.restore_button_clicked,
|
|
"on_startstop_button_clicked" : self.startstop_button_clicked,
|
|
"on_screenlets_list_item_activated" : self.item_activated,
|
|
"on_custom_button_clicked" : self.add_custom }
|
|
self.wTree.signal_autoconnect(dic)
|
|
self.icon_view = self.wTree.get_widget("screenlets_list")
|
|
#Model for IconView
|
|
self.model = gtk.ListStore(str, gtk.gdk.Pixbuf)
|
|
#Create default screenlet items in IconView
|
|
for screenlet in self.default_screenlets:
|
|
pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(self.screenlets_dir + screenlet + '/icon.svg', 32, 32)
|
|
self.model.append([screenlet, pixbuf])
|
|
#Set the IconView model
|
|
self.icon_view.set_model(self.model)
|
|
self.icon_view.set_text_column(0)
|
|
self.icon_view.set_pixbuf_column(1)
|
|
#Check the daemon status
|
|
self.get_daemon_status()
|
|
|
|
def install_button_clicked(self, widget):
|
|
"""Installs screenlet from a tarball"""
|
|
os.system("mkdir ~/.screenlets")
|
|
chooser = gtk.FileChooserDialog(title=None,action=gtk.FILE_CHOOSER_ACTION_OPEN,
|
|
buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_OPEN,gtk.RESPONSE_OK))
|
|
response = chooser.run()
|
|
file = chooser.get_filename()
|
|
chooser.destroy()
|
|
if response == gtk.RESPONSE_OK:
|
|
os.system("tar xvvzf " + file + " -C ~/.screenlets/")
|
|
md = gtk.MessageDialog(type=gtk.MESSAGE_INFO,
|
|
buttons=gtk.BUTTONS_OK)
|
|
md.set_title("Done!")
|
|
md.set_markup(file + " installed!")
|
|
md.run()
|
|
md.destroy()
|
|
|
|
def item_activated(self, widget, path):
|
|
"""Load the selected screenlet"""
|
|
#Get the selected item
|
|
selected = self.icon_view.get_selected_items()
|
|
i = selected[0][0]
|
|
name = self.model[i][0]
|
|
#Otherwise, add the screenlet
|
|
os.system("screenletsd add " + name)
|
|
|
|
def load_button_clicked(self, widget):
|
|
"""Callback for the Load button"""
|
|
selected = self.icon_view.get_selected_items()
|
|
self.item_activated(widget, selected[0])
|
|
|
|
def add_custom(self, widget):
|
|
dialog = gtk.Dialog("Add screenlet...")
|
|
dialog.resize(300, 100)
|
|
dialog.add_buttons(gtk.STOCK_OK, gtk.RESPONSE_OK,
|
|
gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)
|
|
entrybox = gtk.Entry()
|
|
entrybox.set_text("Enter screenlet name (without the trailing 'Screenlet')")
|
|
dialog.vbox.add(entrybox)
|
|
entrybox.show()
|
|
response = dialog.run()
|
|
if response == gtk.RESPONSE_OK:
|
|
screenlet = entrybox.get_text()
|
|
os.system("screenletsd add " + screenlet)
|
|
dialog.hide()
|
|
|
|
def backup_button_clicked(self, widget):
|
|
"""Backup settings from ~/.config/Screenlets"""
|
|
print("Backup clicked")
|
|
chooser = gtk.FileChooserDialog(title=None,action=gtk.FILE_CHOOSER_ACTION_SAVE,
|
|
buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_SAVE,gtk.RESPONSE_OK))
|
|
response = chooser.run()
|
|
file = chooser.get_filename()
|
|
chooser.destroy()
|
|
if response == gtk.RESPONSE_OK:
|
|
if file[-7:] == ".tar.gz":
|
|
os.system("cd ~/.config && tar -czf " + file + " Screenlets")
|
|
else:
|
|
#If the filename doesn't have .tar.gz extension, add it
|
|
os.system("cd ~/.config && tar -czf " + file + ".tar.gz Screenlets")
|
|
md = gtk.MessageDialog(type=gtk.MESSAGE_INFO,
|
|
buttons=gtk.BUTTONS_OK)
|
|
md.set_title("Done!")
|
|
md.set_markup("Backup complete!")
|
|
md.run()
|
|
md.destroy()
|
|
|
|
def restore_button_clicked(self, widget):
|
|
"""Restore settings from a tarball"""
|
|
print("Restore clicked")
|
|
chooser = gtk.FileChooserDialog(title=None,action=gtk.FILE_CHOOSER_ACTION_OPEN,
|
|
buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_OPEN,gtk.RESPONSE_OK))
|
|
response = chooser.run()
|
|
file = chooser.get_filename()
|
|
chooser.destroy()
|
|
if response == gtk.RESPONSE_OK:
|
|
print("tere")
|
|
os.system("rm -rf ~/.config/Screenlets")
|
|
os.system("tar xvvzf " + file + " -C ~/.config/")
|
|
#Restart the daemon for the settings to take effect
|
|
self.start_stop_restart_daemon("restart")
|
|
|
|
def startstop_button_clicked(self, widget):
|
|
"""Callback for Start/stop button"""
|
|
print("Startstop clicked")
|
|
img = self.wTree.get_widget("statusimg")
|
|
label = self.wTree.get_widget("status_label")
|
|
status = self.get_daemon_status()
|
|
if status == False:
|
|
#Change the icon and label
|
|
img.set_from_stock(gtk.STOCK_EXECUTE, 3)
|
|
label.set_text("Running")
|
|
self.start_stop_restart_daemon("start")
|
|
self.daemon_running = True
|
|
elif status == True:
|
|
#Change the icon and label
|
|
img.set_from_stock(gtk.STOCK_STOP, 3)
|
|
label.set_text("Stopped")
|
|
self.start_stop_restart_daemon("stop")
|
|
self.daemon_running = False
|
|
|
|
def start_stop_restart_daemon(self, action):
|
|
"""Helper function for starting/stopping/restarting the daemon"""
|
|
os.system("screenletsd " + action)
|
|
|
|
def get_daemon_status(self):
|
|
"""Check if the daemon is running or autostarted"""
|
|
#Get the PID of screenletsd.py, "" if not running
|
|
SL_PID = commands.getoutput("""ps axo "%p,%a" |grep "./screenletsd.py start"|grep -v grep|cut -d',' -f1""")
|
|
img = self.wTree.get_widget("statusimg")
|
|
label = self.wTree.get_widget("status_label")
|
|
if SL_PID == "":
|
|
img.set_from_stock(gtk.STOCK_STOP, 3)
|
|
label.set_text("Stopped")
|
|
print("False")
|
|
return False
|
|
else:
|
|
img.set_from_stock(gtk.STOCK_EXECUTE, 3)
|
|
label.set_text("Running")
|
|
print("True")
|
|
return True
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
hwg = ScreenletsManager()
|
|
gtk.main()
|