Update gettext usage
[lxde/lxadmin.git] / src / lxcc / lxcc.py
CommitLineData
057b8eba
JL
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
5223442b
JL
22from gettext import gettext as _
23
057b8eba
JL
24control_center_icons=[
25["name","icon","command"],
5223442b
JL
26[_("Login Screen"),"config-users",'su-to-root -X -c "/usr/bin/lxdmconf"'],
27[_("Configure Openbox"),"obconf",'obconf'],
28[_("Preferred Applications"),"applications-system",'libfm-pref-apps'],
29[_("Openbox Keyboard Shortcuts"),"input-keyboard",'openbox-keyconf'],
30[_("Keyboard Layout"),"input-keyboard",'keyboardconf'],
31[_("Mouse&Keyboard"),"input-keyboard",'lxinput'],
32[_("Set Wallpaper"),"desktop",'pcmanfm --desktop-pref'],
33[_("Screensaver Settings"),"xscreensaver",'xscreensaver-demo'],
34[_("Appearance"),"preferences-desktop-theme",'lxappearance'],
35[_("configure Fonts"),"format-text-bold",'fontconfig.py'],
36[_("PCManFM Settings"),"file-manager",'pcmanfm --show-pref=1'],
37[_("PCManFM Superuser Mode"),"file-manager",'su-to-root -X -c "pcmanfm --no-desktop"'],
38[_("Refresh Panel"),"gtk-refresh",'lxpanelctl restart'],
39[_("Search Software"),"search",'apt-leo'],
40[_("Session Settings"),"gnome-window-manager",'lxsession-edit'],
41[_("Monitor Settings"),"computer",'lxrandr'],
057b8eba
JL
42]
43
44
45
46
47import locale
48locale.setlocale(locale.LC_ALL, '') #set locale from 'LANG'
49Xcodec=locale.getpreferredencoding(False)
50import os
51import sys
52import string
53import pygtk
54pygtk.require('2.0')
55import gtk
56import codecs
57import pango
58
59I18N={}
60
61def 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
68def 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
91class 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
a48ca210 118 window.set_title(_('LXDE-Control-Center'))
057b8eba
JL
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
163if __name__ == "__main__":
164 I18N_ready = load_i18n('lxcc.moo')
165 app = Simple()
166 app.main()