Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

add xml background support

  • Loading branch information...
commit fffe727652566470bdc570725e2c2c51750f08e8 1 parent a18081f
Nelson Da Silva authored

Showing 2 changed files with 197 additions and 57 deletions. Show diff stats Hide diff stats

  1. +45 28 gdm3setup-daemon.py
  2. +152 29 gdm3setup.py
73 gdm3setup-daemon.py
@@ -6,6 +6,7 @@
6 6 from dbus.mainloop.glib import DBusGMainLoop
7 7 import subprocess
8 8 import os
  9 +import shutil
9 10 from gi.repository import GObject
10 11
11 12 subprocess.call("echo $LANG",shell=True)
@@ -76,37 +77,53 @@ def Get_Bus():
76 77
77 78 return dbus_address,dbus_pid
78 79
79   -def HackShellTheme(b):
80   - if b :
81   - os.rename('/usr/share/gnome-shell/theme','/usr/share/gnome-shell/theme.original')
82   - os.symlink('/usr/share/gnome-shell/theme.original','/usr/share/gnome-shell/theme')
83   - os.symlink('/usr/share/gnome-shell/theme.original','/usr/share/themes/Adwaita/gnome-shell')
84   - else :
85   - os.remove('/usr/share/themes/Adwaita/gnome-shell')
86   - os.remove('/usr/share/gnome-shell/theme')
87   - os.rename('/usr/share/gnome-shell/theme.original','/usr/share/gnome-shell/theme')
88   -
89 80 def Get_Shell_theme():
90   - if os.path.islink('/usr/share/gnome-shell/theme'):
91   - theme_path = os.readlink('/usr/share/gnome-shell/theme')
92   - if theme_path == '/usr/share/gnome-shell/theme.original':
93   - shell_theme='Adwaita'
94   - else :
95   - tb_path = theme_path.split('/')
96   - shell_theme = tb_path[len(tb_path)-2]
97   - else :
98   - shell_theme='Adwaita'
  81 + shell_theme = 'Adwaita'
  82 + ifile = file('/usr/share/gnome-shell/theme/gnome-shell.css',"r")
  83 + lines = ifile.readlines()
  84 + for i in range(len(lines)) :
  85 + line = lines[i].strip()
  86 + if line[0:2] == "/*" and line[len(line)-2:len(line)] == "*/" :
  87 + comment = line[2:len(line)-2]
  88 + if comment[0:6] == "theme=" :
  89 + shell_theme = comment[6:len(comment)]
99 90
100 91 return shell_theme
101 92
102   -def Set_Shell_theme(value):
103   - if value=='Adwaita':
104   - HackShellTheme(False)
105   - else:
106   - if not os.path.islink('/usr/share/gnome-shell/theme'):
107   - HackShellTheme(True)
108   - os.remove('/usr/share/gnome-shell/theme')
109   - os.symlink('/usr/share/themes/'+value+'/gnome-shell','/usr/share/gnome-shell/theme')
  93 +def Set_Shell_theme(new_theme) :
  94 + theme = Get_Shell_theme()
  95 + if theme == "Adwaita" and new_theme != "Adwaita":
  96 + if os.path.isdir('/usr/share/themes/'+new_theme+'/gnome-shell') :
  97 + if not os.path.islink('/usr/share/gnome-shell/theme') :
  98 + if os.path.isdir('/usr/share/gnome-shell/theme.original/') :
  99 + shutil.rmtree('/usr/share/gnome-shell/theme.original/')
  100 + shutil.move('/usr/share/gnome-shell/theme/','/usr/share/gnome-shell/theme.original/')
  101 + shutil.copytree('/usr/share/themes/'+new_theme+'/gnome-shell','/usr/share/gnome-shell/theme/')
  102 + elif os.path.isdir('/usr/share/gnome-shell/theme.original/') :
  103 + os.remove('/usr/share/gnome-shell/theme')
  104 + shutil.copytree('/usr/share/themes/'+new_theme+'/gnome-shell','/usr/share/gnome-shell/theme/')
  105 + ifile = file('/usr/share/gnome-shell/theme/gnome-shell.css','r')
  106 + lines = ifile.readlines()
  107 + lines.insert(0,"/*theme="+new_theme+"*/\n")
  108 + ifile.close()
  109 + ofile = file('/usr/share/gnome-shell/theme/gnome-shell.css','w')
  110 + ofile.writelines(lines)
  111 + ofile.close()
  112 +
  113 + if theme != "Adwaita" and new_theme == "Adwaita" and os.path.isdir('/usr/share/gnome-shell/theme.original/') :
  114 + shutil.rmtree('/usr/share/gnome-shell/theme/')
  115 + shutil.move('/usr/share/gnome-shell/theme.original/','/usr/share/gnome-shell/theme/')
  116 +
  117 + if theme != "Adwaita" and new_theme != "Adwaita" and os.path.isdir('/usr/share/themes/'+new_theme+'/gnome-shell') :
  118 + shutil.rmtree('/usr/share/gnome-shell/theme/')
  119 + shutil.copytree('/usr/share/themes/'+new_theme+'/gnome-shell','/usr/share/gnome-shell/theme/')
  120 + ifile = file('/usr/share/gnome-shell/theme/gnome-shell.css','r')
  121 + lines = ifile.readlines()
  122 + lines.insert(0,"/*theme="+new_theme+"*/\n")
  123 + ifile.close()
  124 + ofile = file('/usr/share/gnome-shell/theme/gnome-shell.css','w')
  125 + ofile.writelines(lines)
  126 + ofile.close()
110 127
111 128 class GDM3SetupDBusService(dbus.service.Object):
112 129 def __init__(self):
@@ -124,7 +141,7 @@ def policykit_test(self,sender,connexion,action):
124 141
125 142 Subject = ('unix-process', {'pid': dbus.UInt32(sender_pid, variant_level=1),
126 143 'start-time': dbus.UInt64(0, variant_level=1)})
127   - (is_authorized,is_challenge,details) = policykit_authority.CheckAuthorization(Subject, action, {'': ''}, dbus.UInt32(1), '') #, timeout=5000
  144 + (is_authorized,is_challenge,details) = policykit_authority.CheckAuthorization(Subject, action, {'': ''}, dbus.UInt32(1), '')
128 145 return is_authorized
129 146
130 147 @dbus.service.method('apps.nano77.gdm3setup',in_signature='ss', out_signature='s',
181 gdm3setup.py
@@ -4,8 +4,8 @@
4 4 import os
5 5 import gettext
6 6 import dbus
7   -import mimetypes
8 7 import subprocess
  8 +from lxml import etree
9 9
10 10 from gi.repository import Gtk
11 11 from gi.repository import Gdk
@@ -35,30 +35,59 @@ def __init__(self):
35 35 self.Box.pack_end(self.Image,False,False,2)
36 36 self.Box.pack_end(self.Separator,False,False,2)
37 37 self.Box.show_all()
38   - self.PreviewImage = Gtk.Image()
  38 + self.filterImage = Gtk.FileFilter()
  39 + self.filterImage.add_pixbuf_formats()
  40 + self.filterImage.set_name(_('Image'))
  41 + self.filterXml = Gtk.FileFilter()
  42 + self.filterXml.add_pattern("*.xml")
  43 + self.filterXml.set_name(_('XML Background'))
  44 + self.filterAll = Gtk.FileFilter()
  45 + self.filterAll.add_pixbuf_formats()
  46 + self.filterAll.add_pattern("*.xml")
  47 + self.filterAll.set_name(_('All'))
39 48 self.PreviewBox = Gtk.VBox.new(False, 16)
40   - self.Label_Size = Gtk.Label("0 x 0")
41   - self.PreviewBox.set_size_request(200,-1);
  49 + self.PreviewBox.set_size_request(200,-1)
  50 + self.LabelInfo = Gtk.Label("No Image")
  51 + self.PreviewBox.pack_start(self.LabelInfo, False, False, 0)
  52 + self.PreviewImage = Gtk.Image()
42 53 self.PreviewBox.pack_start(self.PreviewImage, False, False, 0)
43 54 self.PreviewImage.show()
  55 + self.Label_Size = Gtk.Label("0 x 0")
44 56 self.PreviewBox.pack_start(self.Label_Size, False, False, 0)
45 57 self.Label_Size.show()
  58 + self.xmlBox = Gtk.HBox.new(False, 16)
  59 + self.PreviewBox.pack_start(self.xmlBox, False, False, 0)
  60 + self.xmlButtonLeft = Gtk.Button.new()
  61 + self.xmlButtonLeftImage = Gtk.Image.new_from_stock("gtk-go-back",Gtk.IconSize.BUTTON)
  62 + self.xmlButtonLeft.set_image(self.xmlButtonLeftImage)
  63 + self.xmlBox.pack_start(self.xmlButtonLeft, False, False, 0)
  64 + self.xmlButtonLeft.show()
  65 + self.xmlLabel = Gtk.Label("0/0")
  66 + self.xmlBox.pack_start(self.xmlLabel, True, True, 0)
  67 + self.xmlLabel.show()
  68 + self.xmlButtonRight = Gtk.Button.new()
  69 + self.xmlButtonRightImage = Gtk.Image.new_from_stock("gtk-go-forward",Gtk.IconSize.BUTTON)
  70 + self.xmlButtonRight.set_image(self.xmlButtonRightImage)
  71 + self.xmlBox.pack_end(self.xmlButtonRight, False, False, 0)
  72 + self.xmlButtonRight.show()
  73 + self.listImage = list()
46 74 self.Filename = ""
  75 + self.isWallpaper = False
47 76 self.connect("clicked",self._Clicked)
  77 + self.xmlButtonLeft.connect("clicked",self.change_pixbuf,-1)
  78 + self.xmlButtonRight.connect("clicked",self.change_pixbuf,1)
48 79 self.FileChooserDialog = None
49 80
50 81 def _Clicked(self,e) :
51 82 if self.FileChooserDialog == None :
52 83
53 84 self.FileChooserDialog = Gtk.FileChooserDialog(title=_("Select a File"),action=Gtk.FileChooserAction.OPEN,buttons=(Gtk.STOCK_CANCEL,Gtk.ResponseType.CANCEL,Gtk.STOCK_CLEAR,Gtk.ResponseType.NONE,Gtk.STOCK_OPEN,Gtk.ResponseType.ACCEPT))
54   - filter = Gtk.FileFilter()
55   - filter.add_pixbuf_formats()
56   - filter.set_name('Image')
57   - self.FileChooserDialog.add_filter(filter)
  85 + self.FileChooserDialog.add_filter(self.filterImage)
  86 + self._update_isWallpaper(True)
58 87 self.FileChooserDialog.set_filename(self.Filename)
59   - self.FileChooserDialog.add_shortcut_folder('/usr/share/backgrounds')
60 88 self.FileChooserDialog.set_preview_widget(self.PreviewBox)
61 89 self.FileChooserDialog.set_preview_widget_active(False)
  90 + self.PreviewBox.show_all()
62 91 self.FileChooserDialog.connect("update-preview",self._UpdatePreview)
63 92 self.FileChooserDialog.connect("response",self.response_cb)
64 93 self.FileChooserDialog.connect("destroy",self.dialog_destroy)
@@ -89,34 +118,128 @@ def set_filename(self,filename=""):
89 118 else :
90 119 self.Label.set_label(_("(None)"))
91 120
  121 + def get_isWallpaper(self):
  122 + return self.isWallpaper
  123 +
  124 + def set_isWallpaper(self,isWallpaper=False):
  125 + if self.isWallpaper != isWallpaper :
  126 + self.isWallpaper = isWallpaper
  127 + if self.FileChooserDialog :
  128 + self._update_isWallpaper(False)
  129 +
  130 + def _update_isWallpaper(self,creation) :
  131 +
  132 + if self.isWallpaper :
  133 + self.FileChooserDialog.add_shortcut_folder('/usr/share/backgrounds')
  134 + self.FileChooserDialog.add_filter(self.filterXml)
  135 + self.FileChooserDialog.add_filter(self.filterAll)
  136 + self.FileChooserDialog.set_filter(self.filterAll)
  137 + elif not creation :
  138 + self.FileChooserDialog.remove_shortcut_folder('/usr/share/backgrounds')
  139 + self.FileChooserDialog.remove_filter(self.filterXml)
  140 + self.FileChooserDialog.remove_filter(self.filterAll)
  141 + self.FileChooserDialog.set_filter(self.filterImage)
  142 +
  143 +
92 144 def _UpdatePreview(self,e) :
93 145 PreviewURI = self.FileChooserDialog.get_preview_uri()
94 146 PreviewFile = self.FileChooserDialog.get_preview_file()
95 147 if PreviewURI!=None and PreviewFile !=None :
96 148 if not GLib.file_test(PreviewFile.get_path(),GLib.FileTest.IS_DIR) :
97 149 PreviewFileInfo = PreviewFile.query_info("*",Gio.FileQueryInfoFlags.NONE,None)
98   - mtime = PreviewFileInfo.get_attribute_uint64(Gio.FILE_ATTRIBUTE_TIME_MODIFIED)
99   - ThumbnailFactory = GnomeDesktop.DesktopThumbnailFactory.new(GnomeDesktop.DesktopThumbnailSize.NORMAL)
100   - ThumbnailPath = ThumbnailFactory.lookup(PreviewURI,mtime)
101   - if ThumbnailPath != None :
102   - pixbuf = GdkPixbuf.Pixbuf.new_from_file(ThumbnailPath)
103   - self.PreviewImage.set_from_pixbuf(pixbuf)
104   - self.FileChooserDialog.set_preview_widget_active(True)
105   - else :
106   - mimetype, enc = mimetypes.guess_type(PreviewURI,True)
107   - pixbuf = ThumbnailFactory.generate_thumbnail(PreviewURI,mimetype)
108   - ThumbnailFactory.save_thumbnail(pixbuf,PreviewURI,mtime)
  150 + mimetype = PreviewFileInfo.get_content_type();
  151 + name = PreviewFile.get_basename()
  152 + xml = name[len(name)-3:len(name)].lower() == 'xml'
  153 + if not xml :
  154 + mtime = PreviewFileInfo.get_modification_time().tv_sec
  155 + ThumbnailFactory = GnomeDesktop.DesktopThumbnailFactory.new(GnomeDesktop.DesktopThumbnailSize.NORMAL)
  156 + ThumbnailPath = ThumbnailFactory.lookup(PreviewURI,mtime)
  157 + if ThumbnailPath != None :
  158 + pixbuf = GdkPixbuf.Pixbuf.new_from_file(ThumbnailPath)
  159 + else :
  160 + pixbuf = ThumbnailFactory.generate_thumbnail(PreviewURI,mimetype)
  161 + ThumbnailFactory.save_thumbnail(pixbuf,PreviewURI,mtime)
109 162 self.PreviewImage.set_from_pixbuf(pixbuf)
  163 + PreviewWidth = pixbuf.get_option("tEXt::Thumb::Image::Width")
  164 + PreviewHeight = pixbuf.get_option("tEXt::Thumb::Image::Height")
  165 + self.Label_Size.set_label( PreviewWidth + " x " + PreviewHeight)
110 166 self.FileChooserDialog.set_preview_widget_active(True)
  167 + self.LabelInfo.hide()
  168 + self.PreviewImage.show()
  169 + self.Label_Size.show()
  170 + self.xmlBox.hide()
111 171
112   - PreviewWidth = pixbuf.get_option("tEXt::Thumb::Image::Width")
113   - PreviewHeight = pixbuf.get_option("tEXt::Thumb::Image::Height")
114   - self.Label_Size.set_label( PreviewWidth + " x " + PreviewHeight)
  172 + else :
  173 + xml_file_path = PreviewFile.get_path()
  174 + xml_data = file(xml_file_path,'r').read()
  175 + root = etree.fromstring(xml_data)
  176 + if root.tag == "background" :
  177 + nodeset = root.xpath('/background/static/file')
  178 + for i in range(len(self.listImage)) :
  179 + self.listImage.pop(0)
  180 + if len(nodeset) :
  181 + for i in range(len(nodeset)):
  182 + background_path = nodeset[i].text
  183 + gfile = Gio.File.new_for_path(background_path)
  184 + fileInfo = gfile.query_info("*",Gio.FileQueryInfoFlags.NONE,None)
  185 + mtime = fileInfo.get_modification_time().tv_sec
  186 + mimetype = fileInfo.get_content_type()
  187 + name = fileInfo.get_name()
  188 + uri = gfile.get_uri()
  189 + ThumbnailFactory = GnomeDesktop.DesktopThumbnailFactory.new(GnomeDesktop.DesktopThumbnailSize.NORMAL)
  190 + ThumbnailPath = ThumbnailFactory.lookup(uri,mtime)
  191 + if ThumbnailPath :
  192 + pixbuf = GdkPixbuf.Pixbuf.new_from_file(ThumbnailPath)
  193 + else :
  194 + pixbuf = ThumbnailFactory.generate_thumbnail(uri,mimetype)
  195 + ThumbnailFactory.save_thumbnail(pixbuf,uri,mtime)
  196 + self.listImage.append(pixbuf)
  197 + self.LabelInfo.hide()
  198 + self.PreviewImage.show()
  199 + self.Label_Size.show()
  200 + self.xmlBox.show()
  201 + self.listImageIndex = 0;
  202 + self.change_pixbuf(self,0)
  203 + self.FileChooserDialog.set_preview_widget_active(True)
  204 + else :
  205 + self.LabelInfo.set_text("No Image")
  206 + self.LabelInfo.show()
  207 + self.PreviewImage.hide()
  208 + self.Label_Size.hide()
  209 + self.xmlBox.hide()
  210 + self.FileChooserDialog.set_preview_widget_active(True)
  211 + else :
  212 + self.LabelInfo.set_text("Invalid XML Background")
  213 + self.LabelInfo.show()
  214 + self.PreviewImage.hide()
  215 + self.Label_Size.hide()
  216 + self.xmlBox.hide()
  217 + self.FileChooserDialog.set_preview_widget_active(True)
115 218 else :
116 219 self.FileChooserDialog.set_preview_widget_active(False)
117 220 else :
118 221 self.FileChooserDialog.set_preview_widget_active(False)
119 222
  223 + def change_pixbuf(self,e,b) :
  224 + if self.listImageIndex < len(self.listImage)-1 and b==1 :
  225 + self.listImageIndex = self.listImageIndex +1
  226 + if self.listImageIndex > 0 and b==-1:
  227 + self.listImageIndex = self.listImageIndex -1
  228 + if self.listImageIndex == 0 :
  229 + self.xmlButtonLeft.set_sensitive(False)
  230 + else :
  231 + self.xmlButtonLeft.set_sensitive(True)
  232 + if self.listImageIndex == len(self.listImage)-1 :
  233 + self.xmlButtonRight.set_sensitive(False)
  234 + else :
  235 + self.xmlButtonRight.set_sensitive(True)
  236 + pixbuf = self.listImage[self.listImageIndex]
  237 + self.PreviewImage.set_from_pixbuf(pixbuf)
  238 + PreviewWidth = pixbuf.get_option("tEXt::Thumb::Image::Width")
  239 + PreviewHeight = pixbuf.get_option("tEXt::Thumb::Image::Height")
  240 + self.Label_Size.set_label( PreviewWidth + " x " + PreviewHeight)
  241 + self.xmlLabel.set_text(str(self.listImageIndex+1) + "/" + str(len(self.listImage)))
  242 +
120 243 GObject.signal_new("file-changed", ImageChooserButton, GObject.SIGNAL_RUN_FIRST,GObject.TYPE_NONE, ())
121 244 GObject.type_register(ImageChooserButton)
122 245
@@ -390,6 +513,7 @@ def __init__(self) :
390 513 self.Button_autologin = self.Builder.get_object("Button_autologin")
391 514 self.Switch_clock_date = self.Builder.get_object("Switch_clock_date")
392 515 self.Switch_clock_seconds = self.Builder.get_object("Switch_clock_seconds")
  516 + self.Button_wallpaper.set_isWallpaper(True)
393 517
394 518 proxy = dbus.SystemBus().get_object('apps.nano77.gdm3setup','/apps/nano77/gdm3setup')
395 519 self.SetUI = proxy.get_dbus_method('SetUI','apps.nano77.gdm3setup')
@@ -420,6 +544,7 @@ def __init__(self) :
420 544 self.Button_autologin.connect("changed",self.autologin_changed)
421 545 self.Switch_clock_date.connect("notify::active",self.clock_date_toggled)
422 546 self.Switch_clock_seconds.connect("notify::active",self.clock_seconds_toggled)
  547 + self.AdaptVersion()
423 548
424 549 #https://bugzilla.gnome.org/show_bug.cgi?id=653579
425 550 self.ComboBox_icon.set_entry_text_column(0)
@@ -430,7 +555,6 @@ def __init__(self) :
430 555 self.ComboBox_shell.set_id_column(1)
431 556 self.ComboBox_gtk.set_entry_text_column(0)
432 557 self.ComboBox_gtk.set_id_column(1)
433   - self.AdaptVersion()
434 558
435 559 def load_gtk3_list(self):
436 560 lst_gtk_themes = os.listdir('/usr/share/themes')
@@ -441,8 +565,7 @@ def load_gtk3_list(self):
441 565 def load_shell_list(self):
442 566
443 567 lst_shell_themes = os.listdir('/usr/share/themes')
444   - if not os.path.islink('/usr/share/gnome-shell/theme'):
445   - self.ComboBox_shell.append_text("Adwaita")
  568 + self.ComboBox_shell.append_text("Adwaita")
446 569
447 570 for i in range(len(lst_shell_themes)):
448 571 if os.path.isdir('/usr/share/themes/'+lst_shell_themes[i]+'/gnome-shell') :
@@ -526,10 +649,10 @@ def get_autologin(self):
526 649
527 650 def AdaptVersion(self) :
528 651 p = subprocess.Popen(GDM_BIN_PATH+" --version",stdout=subprocess.PIPE, shell=True)
529   - GDMversion = int(p.stdout.read().split(" ")[1].split(".")[1])
  652 + GdmSubVersion = int(p.stdout.read().split(" ")[1].split(".")[1])
530 653 GSexists = os.path.exists("/usr/bin/gnome-shell")
531 654
532   - if GDMversion >= 3 :
  655 + if GdmSubVersion >= 3 :
533 656 self.Entry_logo_icon.hide()
534 657 self.Builder.get_object("Label_logo_icon").hide()
535 658 self.Button_fallback_logo.show()
@@ -539,7 +662,7 @@ def AdaptVersion(self) :
539 662 self.Builder.get_object("Label_logo_icon").show()
540 663 self.Button_fallback_logo.hide()
541 664 self.Builder.get_object("Label_fallback_logo").hide()
542   - if not GSexists or GDMversion == 0:
  665 + if not GSexists or GdmSubVersion == 0:
543 666 self.Builder.get_object("notebook1").remove_page(1)
544 667
545 668 def gtk3_theme_changed(self,e):

0 comments on commit fffe727

Please sign in to comment.
Something went wrong with that request. Please try again.