File look-changer-window of Package windowchanger

#!/usr/bin/python

# This application is released under the GNU General Public License 
# v3 (or, at your option, any later version). You can find the full 
# text of the license under http://www.gnu.org/licenses/gpl.txt. 
# By using, editing and/or distributing this software you agree to 
# the terms and conditions of this license. 
# Thank you for using free software!
# 
# (c) AZorin 2010-2012 <azorin@zoringroup.com>
# (c) Zorink 2010 <zorink@zoringroup.com>
#
# Zorin Look Changer 2.0
# A look changing program for Zorin OS.
# This is free software made available under the GNU public license.

from gi.repository import Gtk
import os
import shutil
from os import path

################################
# Defining all the config links#
################################

home = os.getenv("HOME")                                                                                                         
awn = home + "/.config/desktop-agnostic/avant-window-navigator.ini"
awninstance1 = home + "/.config/desktop-agnostic/instances/avant-window-navigator-panel-1.ini"
awninstance2 = home + "/.config/desktop-agnostic/instances/avant-window-navigator-panel-2.ini"
awninstance3 = home + "/.config/desktop-agnostic/instances/avant-window-navigator-panel-3.ini"
awninstance4 = home + "/.config/desktop-agnostic/instances/avant-window-navigator-panel-4.ini"
awninstance5 = home + "/.config/desktop-agnostic/instances/avant-window-navigator-panel-5.ini"
gpanelautostart = home + "/.config/autostart/gnome-panel.desktop"
sevenawn = home + "/.look-changer/Looks/7/.config/desktop-agnostic/avant-window-navigator.ini"
sevenawninstance1 = home + "/.look-changer/Looks/7/.config/desktop-agnostic/instances/avant-window-navigator-panel-1.ini"
sevengnomenudump = home + "/.look-changer/Looks/7/GnoMenu7.xml"
gnome2awn = home + "/.look-changer/Looks/GNOME2/.config/desktop-agnostic/avant-window-navigator.ini"
gnome2awninstance1 = home + "/.look-changer/Looks/GNOME2/.config/desktop-agnostic/instances/avant-window-navigator-panel-1.ini"
gnome2gpanelautostart = home + "/.look-changer/Looks/GNOME2/.config/autostart/gnome-panel.desktop"
xpawn = home + "/.look-changer/Looks/XP/.config/desktop-agnostic/avant-window-navigator.ini"
xpawninstance1 = home + "/.look-changer/Looks/XP/.config/desktop-agnostic/instances/avant-window-navigator-panel-1.ini"
xpgnomenudump = home + "/.look-changer/Looks/XP/GnoMenuXP.xml"
applogo = "/usr/share/pixmaps/look-changer.png"

def switcharoo(old, new):		# Doing the ol' switcharoo of text, since replacing the AWN files doesn't work properly
    openold = open(old, "r+")
    openold.truncate()
    opennew = open(new)
    textnew = opennew.read()
    openold.write(textnew)

    openold.close()
    opennew.close()

class Changer(Gtk.Window):
    def __init__(self):
        super(Changer, self).__init__()
        
        self.set_title("Zorin Look Changer")
        self.set_size_request(640, 295)
        self.set_resizable(False)
        self.set_icon_from_file(applogo)
        self.set_position(Gtk.WindowPosition.CENTER)
        self.connect("destroy", self.on_destroy)
        
        fixed = Gtk.Fixed()

#########################
# Adding the text labels#
#########################

        changelabel = Gtk.Label()
        changelabel.set_markup("<b>Please choose your desired desktop look:</b>")

        fixed.put(changelabel, 10, 10)
        
        note = Gtk.Label("Changing the look will reset your desktop customizations")
        fixed.put(note, 10, 26)

#####################
# Adding the buttons#
#####################

        win7 = Gtk.Button("Windows 7")			# Windows 7 button
        win7.connect("clicked", self.on_win7)
        win7.set_size_request(110, 30)

        fixed.put(win7, 55, 215)

        win7.set_tooltip_text("Change the desktop to make it look like Windows 7")

        xp = Gtk.Button("Windows XP")			# Windows XP button
        xp.connect("clicked", self.on_xp)
        xp.set_size_request(110, 30)

        fixed.put(xp, 265, 215)

        xp.set_tooltip_text("Change the desktop to make it look like Windows XP")

        gnome2 = Gtk.Button("GNOME 2")			# GNOME 2 button
        gnome2.connect("clicked", self.on_gnome2)
        gnome2.set_size_request(110, 30)

        fixed.put(gnome2, 475, 215)

        gnome2.set_tooltip_text("Change the desktop to make it look like the GNOME 2 interface")

        close = Gtk.Button(stock=Gtk.STOCK_CLOSE)	# Close button
        close.connect("clicked", self.on_close)
        close.set_size_request(85, 30)

        fixed.put(close, 545, 255)

###############################
# Adding the screenshot images#
###############################

        self.base_path = os.path.abspath(os.path.dirname(__file__))
        self.base_path = os.path.join(self.base_path, 'data')

        image7path = path.join(self.base_path, home + "/.look-changer/Screenshots/7.png")
        image7 = Gtk.Image.new_from_file(image7path)
        fixed.put(image7, 10, 50)

        imagexppath = path.join(self.base_path, home + "/.look-changer/Screenshots/XP.png")
        imagexp = Gtk.Image.new_from_file(imagexppath)
        fixed.put(imagexp, 220, 50)

        imagegnome2path = path.join(self.base_path, home + "/.look-changer/Screenshots/GNOME2.png")
        imagegnome2 = Gtk.Image.new_from_file(imagegnome2path)
        fixed.put(imagegnome2, 430, 50)

        self.add(fixed)
        self.show_all()

################################        
# Defining the button functions#
################################
  
    def on_destroy(self, widget):
        Gtk.main_quit()

    def on_win7(self, widget):							# The Windows 7 look changing script
        try:
            os.system('gconftool-2 --load %s' % sevengnomenudump)
            if os.path.exists(awn):
                switcharoo(old = awn, new = sevenawn) 
            if os.path.exists(awninstance1):
                switcharoo(old = awninstance1, new = sevenawninstance1) 
            if os.path.exists(awninstance2):
                os.remove(awninstance2) 
            if os.path.exists(awninstance3):
                os.remove(awninstance3) 
            if os.path.exists(awninstance4):
                os.remove(awninstance4) 
            if os.path.exists(awninstance5):
                os.remove(awninstance5) 
            if os.path.exists(gpanelautostart):
                os.remove(gpanelautostart) 
            os.system('killall gnome-panel')
            os.system('killall gnome-panel')
            md = Gtk.MessageDialog(self, 0, Gtk.MessageType.INFO, Gtk.ButtonsType.OK, "Successfully completed changing your desktop look to Windows 7")
            md.run()
            md.destroy()
        except:
            mde = Gtk.MessageDialog(self, 0, Gtk.MessageType.ERROR, Gtk.ButtonsType.OK, "An error has occured")
            mde.run()
            mde.destroy()

    def on_gnome2(self, widget):						# The GNOME 2 look changing script
        try:
            if os.path.exists(awn):
                switcharoo(old = awn, new = gnome2awn)      
            if os.path.exists(awninstance1):
                switcharoo(old = awninstance1, new = gnome2awninstance1) 
            if os.path.exists(awninstance2):
                os.remove(awninstance2) 
            if os.path.exists(awninstance3):
                os.remove(awninstance3) 
            if os.path.exists(awninstance4):
                os.remove(awninstance4) 
            if os.path.exists(awninstance5):
                os.remove(awninstance5)  
            if os.path.exists(gpanelautostart):
                os.remove(gpanelautostart) 
            if os.path.exists(gnome2gpanelautostart):
                shutil.copy(gnome2gpanelautostart, gpanelautostart) 
            os.system('cd .config/autostart && deskopen ./gnome-panel.desktop')
            md = Gtk.MessageDialog(self, 0, Gtk.MessageType.INFO, Gtk.ButtonsType.OK, "Successfully completed changing your desktop look to GNOME 2")
            md.run()
            md.destroy()
        except:
            mde = Gtk.MessageDialog(self, 0, Gtk.MessageType.ERROR, Gtk.ButtonsType.OK, "An error has occured")
            mde.run()
            mde.destroy()

    def on_xp(self, widget):							# The Windows XP look changing script
        try:
            os.system('gconftool-2 --load %s' % xpgnomenudump)
            if os.path.exists(awn):
                switcharoo(old = awn, new = xpawn) 
            if os.path.exists(awninstance1):
                switcharoo(old = awninstance1, new = xpawninstance1) 
            if os.path.exists(awninstance2):
                os.remove(awninstance2) 
            if os.path.exists(awninstance3):
                os.remove(awninstance3) 
            if os.path.exists(awninstance4):
                os.remove(awninstance4) 
            if os.path.exists(awninstance5):
                os.remove(awninstance5)  
            if os.path.exists(gpanelautostart):
                os.remove(gpanelautostart) 
            os.system('killall gnome-panel')
            os.system('killall gnome-panel')
            md = Gtk.MessageDialog(self, 0, Gtk.MessageType.INFO, Gtk.ButtonsType.OK, "Successfully completed changing your desktop look to Windows XP")
            md.run()
            md.destroy()
        except:
            mde = Gtk.MessageDialog(self, 0, Gtk.MessageType.ERROR, Gtk.ButtonsType.OK, "An error has occured")
            mde.run()
            mde.destroy()

    def on_close(self, widget):
        Gtk.main_quit()

Changer()
Gtk.main()
openSUSE Build Service is sponsored by