CrunchBang Linux Pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

CrunchBang Linux Pastebin

Posted by iggykoopa on Fri 28th Aug 13:58 (modification of post by view diff)
download | new post

  1. #!/usr/bin/env python
  2.  
  3. import pygtk,gtk,gtk.glade,os,sys,tarfile,shutil,commands
  4.  
  5.  
  6.  
  7. class crunch_themer:
  8.     def __init__(self):
  9.         self.gladefile = "crunch-themer.glade"
  10.         self.wTree = gtk.glade.XML (self.gladefile)
  11.         dic = { "openFileChooser" : self.openFileChooser,
  12.                     "chooser_ok_clicked" : self.chooser_ok_clicked,
  13.                     "chooser_cancel_clicked" : self.chooser_cancel_clicked,
  14.                     "invalid_file_ok_clicked" : self.invalid_file_ok_clicked,
  15.                     "applied_ok_clicked" : self.applied_ok_clicked,
  16.                     "apply_button_clicked" : self.apply_theme,
  17.                     "main_quit" : self.main_quit}
  18.         self.wTree.signal_autoconnect(dic)
  19.         self.main_window = self.wTree.get_widget("main_window")
  20.         self.file_chooser = self.wTree.get_widget("filechooserdialog")
  21.         self.invalid_file_dialog = self.wTree.get_widget("invalid_file_dialog")
  22.         self.theme_applied_dialog = self.wTree.get_widget("theme_applied_dialog")
  23.         self.cb_ob = self.wTree.get_widget("cb_ob")
  24.         self.cb_gtk = self.wTree.get_widget("cb_gtk")
  25.         self.cb_gdm = self.wTree.get_widget("cb_gdm")
  26.         self.cb_mouse = self.wTree.get_widget("cb_mouse")
  27.         self.cb_icon = self.wTree.get_widget("cb_icon")
  28.         self.cb_conky = self.wTree.get_widget("cb_conky")
  29.         self.cb_wallpaper = self.wTree.get_widget("cb_wallpaper")
  30.         self.preview_image = self.wTree.get_widget("preview_image")
  31.         self.theme_selected = False
  32.         self.user = commands.getoutput("logname")
  33.         self.home = "/home/" + self.user
  34.    
  35.         self.main_window.show()
  36.  
  37.     def openFileChooser(self,widget,item):
  38.         self.file_chooser.show()
  39.  
  40.     def chooser_ok_clicked(self,widget):
  41.         self.file_chooser.hide()
  42.         self.file_selected(self.file_chooser.get_filename())
  43.  
  44.     def applied_ok_clicked(self,widget):
  45.         self.theme_applied_dialog.hide()
  46.  
  47.     def apply_theme(self,widget):
  48.         if self.cb_ob.get_active():
  49.             if not os.path.exists(self.home + "/.themes/" + self.ob_theme):
  50.                 shutil.copytree("/tmp/crunch_theme/" + self.theme_name + "/ob_theme/" + self.ob_theme, self.home + "/.themes/" + self.ob_theme)
  51.             self.rc = open(self.home + "/.config/openbox/rc.xml")
  52.             self.intheme = 0
  53.             self.rc_new = ""
  54.             for line in self.rc:
  55.                 if "<theme>" in line:
  56.                     self.intheme = 1
  57.                 if self.intheme:
  58.                     if "<name>" in line:
  59.                         line = "<name>" + self.ob_theme + "</name>\n"
  60.                         self.intheme = 0
  61.                 self.rc_new = self.rc_new + line
  62.             self.rc_old = open(self.home + "/.config/openbox/rc.xml", "w")
  63.             self.rc_old.write(self.rc_new)
  64.         self.theme_applied_dialog.show()
  65.  
  66.         if self.cb_gtk.get_active():
  67.             if not os.path.exists(self.home + "/.themes/" + self.gtk_theme):
  68.                 shutil.copytree("/tmp/crunch_theme/" + self.theme_name + "/gtk_theme/" + self.gtk_theme, self.home + "/.themes/" + self.gtk_theme)
  69.  
  70.         if self.cb_icon.get_active():
  71.             if not os.path.exists(self.home + "/.icons/" + self.icon_theme):
  72.                 shutil.copytree("/tmp/crunch_theme/" + self.theme_name + "/icon_theme/" + self.icon_theme, self.home + "/.icons/" + self.icon_theme)
  73.  
  74.         if self.cb_gdm.get_active():
  75.             if not os.path.exists("/usr/share/gdm/themes/" + self.gdm_theme):
  76.                 shutil.copytree("/tmp/crunch_theme/" + self.theme_name + "/gdm_theme/" + self.gdm_theme, "/usr/share/gdm/themes/" + self.gdm_theme)
  77.             self.gdm_conf = open("/etc/gdm/gdm.conf-custom")
  78.             self.gdm_conf_new = ""
  79.             for line in self.gdm_conf:
  80.                 if "GraphicalTheme=" in line:
  81.                     line = "GraphicalTheme=" + self.gdm_theme + "\n"
  82.                 if "GraphicalThemes=" in line:
  83.                     line = "GraphicalThemes=" + self.gdm_theme + "\n"
  84.                 self.gdm_conf_new = self.gdm_conf_new + line
  85.             self.gdm_conf_old = open("/etc/gdm/gdm.conf-custom", "w")
  86.             self.gdm_conf_old.write(self.gdm_conf_new)
  87.  
  88.         if self.cb_mouse.get_active():
  89.             if not os.path.exists(self.home + "/.icons/" + self.mouse_theme):
  90.                 shutil.copytree("/tmp/crunch_theme/" + self.theme_name + "/mouse_theme/" + self.mouse_theme, self.home + "/.icons/" + self.mouse_theme)
  91.             if not os.path.exists(self.home + "/.Xdefaults"):
  92.                 os.system("touch " + self.home + "/.Xdefaults")
  93.             self.mouse_index = open(self.home + "/.Xdefaults")
  94.             self.new_mouse_index = ""
  95.             cursor_set = 0
  96.             for line in self.mouse_index.read().split("\n"):
  97.                 if "Xcursor.theme" in line:
  98.                     line = "Xcursor.theme:" + self.mouse_theme + "\n"
  99.                     cursor_set = 1
  100.                 self.new_mouse_index = self.new_mouse_index + line
  101.             if not cursor_set:
  102.                 self.new_mouse_index = self.new_mouse_index + "Xcursor.theme:" + self.mouse_theme
  103.             self.old_mouse_index = open(self.home + "/.Xdefaults", "w")
  104.             self.old_mouse_index.write(self.new_mouse_index)
  105.  
  106.         if self.cb_wallpaper.get_active():
  107.             bg_cfg_old = open("/tmp/crunch_theme/" + self.theme_name + "/wallpaper_theme/bg-saved.cfg")
  108.             bg_cfg_new = open(self.home + "/.config/nitrogen/bg-saved.cfg", "w")
  109.             bg_cfg = ""
  110.             for line in bg_cfg_old.read().split("\n"):
  111.                 if "file" in line:
  112.                     line = "file=" + self.home + "/images/wallpaper/wallpaper.png"
  113.                 bg_cfg = bg_cfg + line + "\n"
  114.             bg_cfg_new.write(bg_cfg)
  115.             bg_cfg_new.close()
  116.             shutil.copy("/tmp/crunch_theme/" + self.theme_name + "/wallpaper_theme/wallpaper.png", self.home + "/images/wallpaper")
  117.             os.system("nitrogen --restore")
  118.  
  119.         if self.cb_gtk.get_active() or self.cb_mouse.get_active():
  120.             self.gtk = open("/tmp/crunch_theme/" + self.theme_name + "/.gtkrc-2.0").read()
  121.             self.gtk = self.gtk.replace("*homedir*", self.home)
  122.             self.gtk_old = open(self.home + "/.gtkrc-2.0", "w")
  123.             self.gtk_old.write(self.gtk)
  124.            
  125.         os.system("chown " + self.user + ":" + self.user + " " + self.home + "/images/wallpaper/*")
  126.         os.system("chown " + self.user + ":" + self.user + " " + self.home + "/.themes/*")
  127.         os.system("chown " + self.user + ":" + self.user + " " + self.home + "/.config/nitrogen/bg-saved.cfg")
  128.         os.system("chown " + self.user + ":" + self.user + " " + self.home + "/.gtkrc-2.0")
  129.         os.system("chown " + self.user + ":" + self.user + " " + self.home + "/.Xdefaults")
  130.         os.system("chown " + self.user + ":" + self.user + " " + self.home + "/.icons/*")
  131.  
  132.     def check_theme(self,theme_file):
  133.         self.theme_name = theme_file.replace(".tar.bz2","").split("/")
  134.         self.theme_name = self.theme_name[-1]
  135.         self.ob_theme = os.listdir("/tmp/crunch_theme/" + self.theme_name + "/ob_theme")
  136.         if self.ob_theme:
  137.             self.ob_theme = self.ob_theme[0]
  138.         self.gtk_theme = os.listdir("/tmp/crunch_theme/" + self.theme_name + "/gtk_theme")
  139.         if self.gtk_theme:
  140.             self.gtk_theme = self.gtk_theme[0]
  141.         self.icon_theme = os.listdir("/tmp/crunch_theme/" + self.theme_name + "/icon_theme")
  142.         if self.icon_theme:
  143.             self.icon_theme = self.icon_theme[0]
  144.         self.gdm_theme = os.listdir("/tmp/crunch_theme/" + self.theme_name + "/gdm_theme")
  145.         if self.gdm_theme:
  146.             self.gdm_theme = self.gdm_theme[0]
  147.         self.mouse_theme = os.listdir("/tmp/crunch_theme/" + self.theme_name + "/mouse_theme")
  148.         if self.mouse_theme:
  149.             self.mouse_theme = self.mouse_theme[0]
  150.         self.wallpaper_theme = os.listdir("/tmp/crunch_theme/" + self.theme_name + "/wallpaper_theme")
  151.         self.main_dir = os.listdir("/tmp/crunch_theme/" + self.theme_name)
  152.         if self.ob_theme:
  153.             self.cb_ob.set_active(True)
  154.         else:
  155.             self.cb_ob.set_active(False)
  156.         if self.gtk_theme:
  157.             self.cb_gtk.set_active(True)
  158.         else:
  159.             self.cb_gtk.set_active(False)
  160.         if self.icon_theme:
  161.             self.cb_icon.set_active(True)
  162.         else:
  163.             self.cb_icon.set_active(False)
  164.         if self.gdm_theme:
  165.             self.cb_gdm.set_active(True)
  166.         else:
  167.             self.cb_gdm.set_active(False)
  168.         if self.mouse_theme:
  169.             self.cb_mouse.set_active(True)
  170.         else:
  171.             self.cb_mouse.set_active(False)
  172.         if self.wallpaper_theme:
  173.             self.cb_wallpaper.set_active(True)
  174.         else:
  175.             self.cb_wallpaper.set_active(False)
  176.         if "preview.png" in self.main_dir:
  177.             self.preview_image.set_from_file("/tmp/crunch_theme/" + self.theme_name + "/preview.png")
  178.  
  179.     def file_selected(self,selected_file):
  180.         if ".tar.bz2" in selected_file:
  181.             theme = tarfile.open(selected_file)
  182.             #setup temp directory
  183.             if os.path.exists("/tmp/crunch_theme"):
  184.                 shutil.rmtree("/tmp/crunch_theme")
  185.             theme.extractall("/tmp/crunch_theme")
  186.             self.theme_selected = True
  187.             self.check_theme(selected_file)
  188.         else:
  189.             self.invalid_file_dialog.show()
  190.  
  191.     def invalid_file_ok_clicked(self,widget):
  192.         self.invalid_file_dialog.hide()
  193.  
  194.     def chooser_cancel_clicked(self,widget):
  195.         self.file_chooser.hide()
  196.  
  197.     def main_quit(self,widget,item):
  198.         gtk.main_quit()
  199.  
  200. if __name__ == "__main__":
  201.    
  202.     themer = crunch_themer()
  203.     gtk.main()

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me