Zheme changer script

From Openmoko

(Difference between revisions)
Jump to: navigation, search
 
(2 intermediate revisions by one user not shown)
Line 1: Line 1:
 +
'''Note: This version is outdated! We are currently working on a better solution to keep this script updated...'''
 +
 +
 
Replace /usr/bin/zheme.py with this block of code:
 
Replace /usr/bin/zheme.py with this block of code:
  
If you want to create your own Zheme, just copy the directory of an already existing one, rename the directory and put your files (with the same naming convention!!) in this new directory. (Improvements to come: a combobox instead of buttons, a button to create your Zheme more easily)  
+
If you want to create your own Zheme, just copy the directory of an already existing one, rename the directory and put your files (with the same naming convention!! Don't forget to rename the .edj file) in this new directory. (Improvements to come: a combobox instead of buttons, a button to create your Zheme more easily)  
  
'''This script doesn't change Zhone's background (yet...)'''
+
'''This script doesn't change Zhone's background for custom Zhemes (yet...) You'll have to recompile the .edj file in your Zheme's directory if you want to do that.'''
  
 
<pre>
 
<pre>
Line 28: Line 31:
 
pygtk.require('2.0')
 
pygtk.require('2.0')
 
import gtk
 
import gtk
import time
 
import gobject
 
import fcntl
 
import struct
 
import ConfigParser
 
 
import os.path
 
import os.path
import array
 
 
import getpass
 
import getpass
  

Latest revision as of 01:22, 30 July 2009

Note: This version is outdated! We are currently working on a better solution to keep this script updated...


Replace /usr/bin/zheme.py with this block of code:

If you want to create your own Zheme, just copy the directory of an already existing one, rename the directory and put your files (with the same naming convention!! Don't forget to rename the .edj file) in this new directory. (Improvements to come: a combobox instead of buttons, a button to create your Zheme more easily)

This script doesn't change Zhone's background for custom Zhemes (yet...) You'll have to recompile the .edj file in your Zheme's directory if you want to do that.


#!/usr/bin/python
"""
 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
"""


import pygtk
pygtk.require('2.0')
import gtk
import os.path
import getpass


class zhemes:

	#check which user is running this script
	#(taken from the freeyourphone forum, user Sajut)                                                                                                                                                                                
        global user                                                                                                                                                                                                              
        global home                                                                                                                                                                                                              
        user = getpass.getuser()                                                                                                                                                                                                 
        if user == 'root':                                                                                                                                                                                                       
                home = '/root/'                                                                                                                                                                                                  
        else:                                                                                                                                                                                                                    
                home = '/home/' + user +  '/' 

	def btnClicked(self, widget, data = None):
		name = widget.get_label()

		os.system("cp " + home + ".fyp/zhemes/" + name + "/" + name + ".edj /usr/share/zhone/zhone.edj")
                os.system("cp " + home + ".fyp/zhemes/" + name + "/wallpaper.jpg /root/.fyp/wallpaper.jpg")
                os.system("cp " + home + ".fyp/zhemes/" + name + "/panel.png /usr/share/lxpanel/images/background.png")
		os.system("cp " + home + ".fyp/zhemes/" + name + "/emblem.png /usr/share/lxde/images/lxde-icon.png")

		print "Installed theme: " + name
		print "Please reboot your device"

		for i in self.buttons:
			if i.get_label() == name:
				i.set_sensitive( False )
			else:
				i.set_sensitive( True )

		self.winMain.set_title( "Please reboot" )

		return True

		
	def btnRestartClicked( self, widget, data = None ):
	
		exit()
		
		return true
   
	def __init__( self ):
        
		self.winMain = gtk.Window()
		self.winMain.connect( 'delete-event', gtk.main_quit )
		self.vboxMain = gtk.VBox( homogeneous = True, spacing = 0 )
		self.vboxBtns = gtk.VBox( homogeneous = True, spacing = 0 )
		self.vboxConfig = gtk.VBox( homogeneous = True, spacing = 0 )
		self.winMain.set_title( "Zhemes" )
		self.winMain.set_size_request(480,480)
	
		""" buttons """
		self.buttons = []

		""" reads the sub-directories in ~/.fyp/zhemes and packs the needed buttons """
		direc = home + ".fyp/zhemes"
		for d in os.listdir(direc):
			if os.path.isdir(os.path.join(direc, d)):
				tmp = gtk.Button( d ) 
				tmp.connect( "clicked", self.btnClicked)
				self.vboxBtns.pack_start( tmp )
				self.buttons.append( tmp )
		
		self.btnRestart = gtk.Button( "Restart Zhone" )
            
		""" Connect buttons with their functions """    
		self.btnRestartClicked = self.btnRestart.connect( "clicked", self.btnRestartClicked )


		""" Put them on the window """
		self.vboxMain.pack_start( self.vboxBtns, padding = 1 )


		self.winMain.add( self.vboxMain )
          
		self.winMain.show_all()
        
	def main( self ):
			gtk.main()

if __name__ == "__main__":
    zhemes = zhemes()
    zhemes.main()



Personal tools

Replace /usr/bin/zheme.py with this block of code:

If you want to create your own Zheme, just copy the directory of an already existing one, rename the directory and put your files (with the same naming convention!!) in this new directory. (Improvements to come: a combobox instead of buttons, a button to create your Zheme more easily)

This script doesn't change Zhone's background (yet...)


#!/usr/bin/python
"""
 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
"""


import pygtk
pygtk.require('2.0')
import gtk
import time
import gobject
import fcntl
import struct
import ConfigParser
import os.path
import array
import getpass


class zhemes:

	#check which user is running this script
	#(taken from the freeyourphone forum, user Sajut)                                                                                                                                                                                
        global user                                                                                                                                                                                                              
        global home                                                                                                                                                                                                              
        user = getpass.getuser()                                                                                                                                                                                                 
        if user == 'root':                                                                                                                                                                                                       
                home = '/root/'                                                                                                                                                                                                  
        else:                                                                                                                                                                                                                    
                home = '/home/' + user +  '/' 

	def btnClicked(self, widget, data = None):
		name = widget.get_label()

		os.system("cp " + home + ".fyp/zhemes/" + name + "/" + name + ".edj /usr/share/zhone/zhone.edj")
                os.system("cp " + home + ".fyp/zhemes/" + name + "/wallpaper.jpg /root/.fyp/wallpaper.jpg")
                os.system("cp " + home + ".fyp/zhemes/" + name + "/panel.png /usr/share/lxpanel/images/background.png")
		os.system("cp " + home + ".fyp/zhemes/" + name + "/emblem.png /usr/share/lxde/images/lxde-icon.png")

		print "Installed theme: " + name
		print "Please reboot your device"

		for i in self.buttons:
			if i.get_label() == name:
				i.set_sensitive( False )
			else:
				i.set_sensitive( True )

		self.winMain.set_title( "Please reboot" )

		return True

		
	def btnRestartClicked( self, widget, data = None ):
	
		exit()
		
		return true
   
	def __init__( self ):
        
		self.winMain = gtk.Window()
		self.winMain.connect( 'delete-event', gtk.main_quit )
		self.vboxMain = gtk.VBox( homogeneous = True, spacing = 0 )
		self.vboxBtns = gtk.VBox( homogeneous = True, spacing = 0 )
		self.vboxConfig = gtk.VBox( homogeneous = True, spacing = 0 )
		self.winMain.set_title( "Zhemes" )
		self.winMain.set_size_request(480,480)
	
		""" buttons """
		self.buttons = []

		""" reads the sub-directories in ~/.fyp/zhemes and packs the needed buttons """
		direc = home + ".fyp/zhemes"
		for d in os.listdir(direc):
			if os.path.isdir(os.path.join(direc, d)):
				tmp = gtk.Button( d ) 
				tmp.connect( "clicked", self.btnClicked)
				self.vboxBtns.pack_start( tmp )
				self.buttons.append( tmp )
		
		self.btnRestart = gtk.Button( "Restart Zhone" )
            
		""" Connect buttons with their functions """    
		self.btnRestartClicked = self.btnRestart.connect( "clicked", self.btnRestartClicked )


		""" Put them on the window """
		self.vboxMain.pack_start( self.vboxBtns, padding = 1 )


		self.winMain.add( self.vboxMain )
          
		self.winMain.show_all()
        
	def main( self ):
			gtk.main()

if __name__ == "__main__":
    zhemes = zhemes()
    zhemes.main()