5c50b09f9bdf610ac391848e0f1c2a418661b216
[lxde/lxadmin.git] / src / lxcc / lxcc.py
1 #!/usr/bin/python
2 # -*- coding: UTF-8 -*-
3 #**************************************************************************
4 # *
5 # Copyright (c) 2010 by Elfriede Apfelkuchen <elfriede@sidux.com> *
6 # *
7 # This program is free software: you can redistribute it and/or modify *
8 # it under the terms of the GNU General Public License as published by *
9 # the Free Software Foundation, either version 3 of the License, or *
10 # (at your option) any later version. *
11 # *
12 # This program is distributed in the hope that it will be useful, *
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 # GNU General Public License for more details. *
16 # *
17 # You should have received a copy of the GNU General Public License *
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. *
19 # *
20 #**************************************************************************
21
22 control_center_icons=[
23 ["name","icon","command"],
24 ["Login Screen","config-users",'su-to-root -X -c "/usr/bin/lxdmconf"'],
25 ["Configure Openbox","obconf",'obconf'],
26 ["Preferred Applications","applications-system",'libfm-pref-apps'],
27 ["Openbox Keyboard Shortcuts","input-keyboard",'openbox-keyconf'],
28 ["Keyboard Layout","input-keyboard",'keyboardconf'],
29 ["Mouse&Keyboard","input-keyboard",'lxinput'],
30 ["Set Wallpaper","desktop",'pcmanfm --desktop-pref'],
31 ["Screensaver Settings","xscreensaver",'xscreensaver-demo'],
32 ["Appearance","preferences-desktop-theme",'lxappearance'],
33 ["configure Fonts","format-text-bold",'fontconfig.py'],
34 ["PCManFM Settings","file-manager",'pcmanfm --show-pref=1'],
35 ["PCManFM Superuser Mode","file-manager",'su-to-root -X -c "pcmanfm --no-desktop"'],
36 ["Refresh Panel","gtk-refresh",'lxpanelctl restart'],
37 ["Search Software","search",'apt-leo'],
38 ["Session Settings","gnome-window-manager",'lxsession-edit'],
39 ["Monitor Settings","computer",'lxrandr'],
40 ]
41
42
43
44
45 import locale
46 locale.setlocale(locale.LC_ALL, '') #set locale from 'LANG'
47 Xcodec=locale.getpreferredencoding(False)
48 import os
49 import sys
50 import string
51 import pygtk
52 pygtk.require('2.0')
53 import gtk
54 import codecs
55 import pango
56
57 from gettext import gettext as _
58
59 I18N={}
60
61 def i18n(text):
62 #liefert einen Internationialisierungstext zurück
63 if I18N_ready:
64 if I18N.has_key(text): return I18N[text]
65 else: return text
66 else: return text
67
68 def load_i18n(filename):
69 #lädt das Internationalisierung.moo file
70 ready=False
71 lang=os.getenv('LANG')
72 if not lang: return ready
73 lang2='/usr/share/locale/'+lang[0:2] +'/LC_MESSAGES/'+filename
74 lang3='/usr/share/locale/'+lang[0:5] +'/LC_MESSAGES/'+filename
75 lang='no file'
76 if os.access(lang3,os.R_OK): lang=lang3
77 elif os.access(lang2,os.R_OK): lang=lang2
78 if lang != 'no file':
79 f=codecs.open(lang,'r','utf_8')
80 if f:
81 lang=f.readlines()
82 f.close()
83 ready=True
84 for z in lang:
85 s=z.replace('\n','').split('=')
86 if s[0]=='': continue
87 I18N[s[0]]=s[1]
88 return ready
89
90
91 class Simple:
92
93 def destroy(self, widget, data=None):
94 #wird beim beenden ausgeführt
95 gtk.main_quit()
96
97
98 def mouse(self, widget, event, data=None):
99 if event.button==1:
100 pathinfo=widget.get_path_at_pos(int(event.x),int(event.y))
101 if pathinfo==None: return False
102 pathnr=pathinfo[0]
103 command=self.liststore[pathnr][2]
104 if command=='xscreensaver-demo':
105 if not os.path.exists('/usr/bin/xscreensaver-demo'):
106 dialog = gtk.MessageDialog(self.window, gtk.DIALOG_MODAL,gtk.MESSAGE_INFO,gtk.BUTTONS_OK, "apt-get install xscreensaver")
107 result = dialog.run()
108 dialog.destroy()
109 os.system(command+' &')
110 return True
111 return False
112
113
114 def __init__(self):
115 # create a new window
116 window = gtk.Window(gtk.WINDOW_TOPLEVEL)
117 self.window=window
118 window.set_title(_('LXDE-Control-Center'))
119 window.connect("destroy", self.destroy)
120 window.set_border_width(3)
121 window.set_position(gtk.WIN_POS_CENTER_ALWAYS)
122
123 it=gtk.icon_theme_get_default()
124 gtk.window_set_default_icon(it.load_icon("gtk-preferences",48,gtk.ICON_LOOKUP_FORCE_SVG))
125 window.resize(800,400)
126 self.liststore=gtk.ListStore(gtk.gdk.Pixbuf,str,str)
127 self.iv=gtk.IconView(self.liststore)
128 self.iv.set_pixbuf_column(0)
129 self.iv.set_text_column(1)
130 self.iv.set_events(self.iv.get_events() | gtk.gdk.BUTTON_PRESS_MASK)
131 self.iv.connect("button-press-event", self.mouse)
132 sw = gtk.ScrolledWindow()
133 sw.set_shadow_type(gtk.SHADOW_ETCHED_IN)
134 sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
135 sw.add(self.iv)
136 window.add(sw)
137
138 first=True
139 for line in control_center_icons:
140 if first:
141 first=False
142 continue
143 try:
144 if '/' in line[1]:
145 pixbuf=gtk.gdk.pixbuf_new_from_file(line[1])
146 else:
147 pixbuf=it.load_icon(line[1],48,gtk.ICON_LOOKUP_FORCE_SVG)
148 except:
149 pixbuf=it.load_icon('gtk-stop',48,gtk.ICON_LOOKUP_FORCE_SVG)
150 namen=i18n(line[0])
151 self.liststore.append([ pixbuf,namen,line[2] ])
152 window.show_all()
153
154
155 def main(self):
156 # All PyGTK applications must have a gtk.main(). Control ends here
157 # and waits for an event to occur (like a key press or mouse event).
158 gtk.main()
159
160
161 # If the program is run directly or passed as an argument to the python
162 # interpreter then create a HelloWorld instance and show it
163 if __name__ == "__main__":
164 I18N_ready = load_i18n('lxcc.moo')
165 app = Simple()
166 app.main()