~ubuntu-branches/ubuntu/oneiric/alarm-clock/oneiric

1 by Marco Rodrigues
Import upstream version 0.9.3
1
#!/usr/bin/env python
2
3
# Alarm Clock is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
8
# Alarm Clock is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
13
# You should have received a copy of the GNU General Public License
14
# along with Alarm Clock; if not, write to the Free Software Foundation, Inc.,
15
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
16
17
# Copyright 2007-2008 Tomasz Salacinski <tsalacinski@gmail.com>
18
19
try:
20
	import gtk
21
	import pygtk
22
	import gtk.glade
23
	import gobject
24
	import shutil
25
	import time
26
except:
27
	print "Error loading GTK+ libraries. Check if they are properly"
28
	print "installed on your system."
29
	exit(1)
30
31
import os
32
33
34
class Setup:
35
	def __init__(self):
36
		self.gui = gtk.glade.XML('setup.glade', 'main_dialog')
37
		self.g = self.gui.get_widget('main_dialog')
38
		self.dic = { "delete" : self.deleteme, 
39
			     "cancel_click" : self.deleteme2,
40
			     "ok_click" : self.proceed, }
41
		self.gui.signal_autoconnect(self.dic)
42
43
		self.p = "/usr/share/alarm-clock"
44
		self.gui.get_widget('path_entry').set_text(self.p)
45
46
		self.g.show()
47
48
		
49
50
	def deleteme(self,obj,v):
51
		if self.gui.get_widget('notebook1').get_current_page() == 1:
52
			gtk.main_quit()
53
			return
54
		self.msgDialog = gtk.MessageDialog(self.g, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO, "Are you sure you want to quit the setup program?")
55
56
		self.value = self.msgDialog.run()
57
		if self.value == gtk.RESPONSE_YES:
58
			gtk.main_quit()
59
		else:
60
			self.msgDialog.destroy()
61
			return True
62
63
	def deleteme2(self,obj):
64
		if self.gui.get_widget('notebook1').get_current_page() == 1:
65
			gtk.main_quit()
66
		self.deleteme(self.g, None)
67
68
69
	def proceed(self,obj):
70
71
		if self.gui.get_widget('notebook1').get_current_page() == 1:
72
			gtk.main_quit()
73
			return
74
75
		if self.gui.get_widget('path_entry').get_text() == "":
76
			self.msgDialog = gtk.MessageDialog(self.g, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE, "Wrong path entered.")
77
			self.msgDialog.run()
78
			self.msgDialog.destroy()
79
			return
80
81
		#try:
82
		try:
83
			os.mkdir(self.gui.get_widget('path_entry').get_text())
84
		except:
85
			pass
86
		try:
87
			os.mkdir(self.gui.get_widget('path_entry').get_text() + "/gfx")
88
		except:
89
			pass
90
		try:
91
			os.mkdir(self.gui.get_widget('path_entry').get_text() + "/sound")
92
		except:
93
			pass
94
		shutil.copyfile('gfx/alarm-clock.svg', self.gui.get_widget('path_entry').get_text() + '/gfx/alarm-clock.svg')
95
		shutil.copyfile('gfx/alarm-clock.svg', '/usr/share/pixmaps/alarm-clock.svg')
96
		shutil.copyfile('gfx/alarm-caution.svg', self.gui.get_widget('path_entry').get_text() + '/gfx/alarm-caution.svg')
97
		shutil.copyfile('main.glade', self.gui.get_widget('path_entry').get_text() + '/main.glade')
98
		shutil.copyfile('pyalarm.py', self.gui.get_widget('path_entry').get_text() + '/pyalarm.py')
99
		shutil.copyfile('alarm-clock.py', self.gui.get_widget('path_entry').get_text() + '/alarm-clock.py')
100
		shutil.copyfile('sound/ring.wav', self.gui.get_widget('path_entry').get_text() + '/sound/ring.wav')
101
		shutil.copyfile('alarm-clock.desktop', "/usr/share/applications/alarm-clock.desktop")
102
		#except:
103
	#		msgDialog = gtk.MessageDialog(None, 0, gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE, "Error!")
104
	#		msgDialog.format_secondary_text("Error installing the program. You need to be root in order to install alarm-clock.")
105
	#		msgDialog.run()
106
	#		msgDialog.destroy()	
107
108
109
110
		#Installing language files
111
112
			## POLISH ##
113
114
		try:
115
			os.system('msgfmt po/pl.po -o po/pyalarm.mo')
116
			shutil.copyfile('po/pyalarm.mo', '/usr/share/locale/pl/LC_MESSAGES/pyalarm.mo')
117
			os.system('rm -fr po/pyalarm.mo')
118
		except:
119
			msgDialog = gtk.MessageDialog(None, 0, gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE, "Error!")
120
			msgDialog.format_secondary_text("Setup wizard is unable to install POLISH translation. Please report bug to tsalacinski@gmail.com.")
121
			msgDialog.run()
122
			msgDialog.destroy()			
123
124
		## SERBIAN @ CYRILIC ##
125
	
126
		try:
127
			os.system('msgfmt po/sr.po -o po/pyalarm.mo')
128
			shutil.copyfile('po/pyalarm.mo', '/usr/share/locale/sr/LC_MESSAGES/pyalarm.mo')
129
			os.system('rm -fr po/pyalarm.mo')
130
		except:
131
			msgDialog = gtk.MessageDialog(None, 0, gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE, "Error!")
132
			msgDialog.format_secondary_text("Setup wizard is unable to install SERBIAN translation. Please report bug to tsalacinski@gmail.com.")
133
			msgDialog.run()
134
			msgDialog.destroy()			
135
136
		## SERBIAN @ LATIN ##
137
138
		try:
139
			os.system('msgfmt po/sr@latin.po -o po/pyalarm.mo')
140
			shutil.copyfile('po/pyalarm.mo', '/usr/share/locale/sr@Latn/LC_MESSAGES/pyalarm.mo')
141
			os.system('rm -fr po/pyalarm.mo')
142
		except:
143
			msgDialog = gtk.MessageDialog(None, 0, gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE, "Error!")
144
			msgDialog.format_secondary_text("Setup wizard is unable to install SERBIAN LATIN translation. Please report bug to tsalacinski@gmail.com.")
145
			msgDialog.run()
146
			msgDialog.destroy()			
147
148
		## GERMAN ##
149
150
		try:
151
			os.system('msgfmt po/de_DE.po -o po/pyalarm.mo')
152
			shutil.copyfile('po/pyalarm.mo', '/usr/share/locale/de/LC_MESSAGES/pyalarm.mo')
153
			os.system('rm -fr po/pyalarm.mo')
154
		except:
155
			msgDialog = gtk.MessageDialog(None, 0, gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE, "Error!")
156
			msgDialog.format_secondary_text("Setup wizard is unable to install GERMAN translation. Please report bug to tsalacinski@gmail.com.")
157
			msgDialog.run()
158
			msgDialog.destroy()			
159
160
		## SPANISH ##
161
162
		try:
163
			os.system('msgfmt po/es.po -o po/pyalarm.mo')
164
			shutil.copyfile('po/pyalarm.mo', '/usr/share/locale/es/LC_MESSAGES/pyalarm.mo')
165
			os.system('rm -fr po/pyalarm.mo')
166
		except:
167
			msgDialog = gtk.MessageDialog(None, 0, gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE, "Error!")
168
			msgDialog.format_secondary_text("Setup wizard is unable to install SPANISH translation. Please report bug to tsalacinski@gmail.com.")
169
			msgDialog.run()
170
			msgDialog.destroy()			
171
172
		self.d = file("/usr/bin/alarm-clock", "w")
173
		self.d.write ("cd %s\n" % self.gui.get_widget('path_entry').get_text())
174
		self.d.write ("./alarm-clock.py $1\n")
175
		self.d.close()
176
		os.system('chmod +x /usr/bin/alarm-clock')
177
		os.system('chmod +x /usr/share/alarm-clock/alarm-clock.py')
178
179
180
		
181
		self.gui.get_widget('cancelbutton1').hide()
182
		self.gui.get_widget('notebook1').set_current_page(1)
183
184
if __name__ == '__main__':
185
	Setup()
186
	gtk.main()