2 # -*- coding: utf-8 -*-
4 # Copyright 2011, Gimick (bbtgaf@googlemail.com)
5 #This program is free software: you can redistribute it and/or modify
6 #it under the terms of the GNU Affero General Public License as published by
7 #the Free Software Foundation, version 3 of the License.
9 #This program is distributed in the hope that it will be useful,
10 #but WITHOUT ANY WARRANTY; without even the implied warranty of
11 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 #GNU General Public License for more details.
14 #You should have received a copy of the GNU Affero General Public License
15 #along with this program. If not, see <http://www.gnu.org/licenses/>.
16 #In the "official" distribution you can find the license in agpl-3.0.txt.
18 ########################################################################
24 global_modules_to_test
= ["gobject",
35 windows_modules_to_test
= ["win32gui",
43 linux_modules_to_test
= ["wnck"]
44 mac_modules_to_test
= []
45 posix_modules_to_test
= []
47 def win_output(message
):
51 win
.geometry("600x400")
52 listbox
= Listbox(win
)
54 listbox
.insert(END
,item
)
55 listbox
.pack(fill
=BOTH
, expand
=YES
)
58 def try_import(modulename
):
61 module
= __import__(modulename
)
64 failure( _('File not found')+ ": " +modulename
)
65 if modulename
in ["cairo", "gobject", "pygtk"]:
66 failure(_("Unable to load PyGTK modules required for GUI. Please install PyCairo, PyGObject, and PyGTK from www.pygtk.org."))
67 if modulename
in ["win32console"]:
68 failure (_("We appear to be running in Windows, but the Windows Python Extensions are not loading. Please install the PYWIN32 package from http://sourceforge.net/projects/pywin32/"))
69 if modulename
in ["pytz"]:
70 failure (_("Unable to import PYTZ library. Please install PYTZ from http://pypi.python.org/pypi/pytz/"))
73 if modulename
== "pygtk":
79 failure("pygtk 2.0 " + _('File not found'))
82 if modulename
== "matplotlib":
85 success("matplotlib/gtk")
88 failure("matplotlib/gtk")
96 success_list
.append(message
)
100 print _("Error:"), message
101 failure_list
.append(message
)
104 class ChooseLanguage
:
106 def __init__(self
, win
, language_dict
):
107 win
.title("Choose a language for FPDB")
108 win
.geometry("350x350")
109 self
.listbox
= Listbox(win
)
111 self
.listbox
.insert(END
,("Use the system language settings"))
112 self
.listbox
.insert(END
,("en -- Always use English for FPDB"))
113 for key
in sorted(language_dict
.iterkeys()):
114 self
.listbox
.insert(END
,(key
+ " -- " + language_dict
[key
]))
115 self
.listbox
.pack(fill
=BOTH
, expand
=1)
116 self
.listbox
.select_set(0)
118 self
.listbox
.bind('<Double-1>', self
.callbackLanguage
)
121 def callbackLanguage(self
, event
):
122 index
= self
.listbox
.curselection()[0]
124 self
.selected_language
= ""
126 self
.selected_language
= self
.listbox
.get(index
)
129 def getLanguage(self
):
131 return string
.split(self
.selected_language
, " -- ", 1)[0]
133 #=====================================================================
136 # check for gross failures first, no translation on the first
137 # two messages because L10n not guaranteed to be available
140 from Tkinter
import *
143 module
= __import__("sys")
145 failure("python failure - could not import sys module")
146 win_output(failure_list
)
150 module
= __import__("L10n")
152 failure("fpdb modules cannot be loaded, check that fpdb is installed in an English path")
153 win_output(failure_list
)
158 if sys
.argv
[1] == "-v":
164 _
= L10n
.get_translation()
166 config
= Configuration
.Config()
168 if config
.python_version
not in("2.6", "2.7"):
169 failure(_("Python 2.6-2.7 not found, please install python 2.6 or 2.7 for fpdb."))
172 # next, check for individual modules existing
175 for i
in global_modules_to_test
:
177 if config
.os_family
in ("XP", "Win7"):
178 for i
in windows_modules_to_test
:
180 elif config
.os_family
== "Linux":
181 for i
in linux_modules_to_test
:
183 elif config
.os_family
== "Mac":
184 for i
in mac_modules_to_test
:
187 for i
in posix_modules_to_test
:
190 if len(failure_list
):
191 win_output(failure_list
)
194 # finished validation, work out how to exit
196 if config
.install_method
== "exe":
197 if len(failure_list
):
200 if len(failure_list
):
201 if config
.os_family
in ("XP", "Win7"):
204 sys
.exit(failure_list
)
207 # If initial run (example_copy==True), prompt for language
209 if config
.example_copy
:
211 # Ask user for their preferred language, save their choice in the
214 language_dict
,null
=L10n
.get_installed_translations()
216 chosen_lang
= ChooseLanguage(win
, language_dict
).getLanguage()
219 conf
=Configuration
.Config()
220 conf
.set_general(lang
=chosen_lang
)
223 # signal fpdb.pyw to trigger the config created dialog
228 if config
.install_method
== "exe":
235 # finally, invoke fpdb
238 os
.chdir(os
.path
.join(config
.fpdb_program_path
, u
"pyfpdb"))
240 if config
.os_family
in ("XP", "Win7"):
241 os
.execvpe('pythonw.exe', list(('pythonw.exe', 'fpdb.pyw', initial_run
, '-r'))+sys
.argv
[1:], os
.environ
)
243 os
.execvpe('python', list(('python', 'fpdb.pyw', initial_run
, '-r'))+sys
.argv
[1:], os
.environ
)
245 # DO NOT INSERT ANY LINES BELOW HERE
246 # os.execvpe above transfers control to fpdb.pyw immediately