Remove the base/advance choice page.
[bertos.git] / wizard / bertos.py
1 #!/usr/bin/env python
2 # encoding: utf-8
3 #
4 # This file is part of BeRTOS.
5 #
6 # Bertos is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19 #
20 # As a special exception, you may use this file as part of a free software
21 # library without restriction.  Specifically, if other files instantiate
22 # templates or use macros or inline functions from this file, or you compile
23 # this file and link it with other files to produce an executable, this
24 # file does not by itself cause the resulting executable to be covered by
25 # the GNU General Public License.  This exception does not however
26 # invalidate any other reasons why the executable file might be covered by
27 # the GNU General Public License.
28 #
29 # Copyright 2008 Develer S.r.l. (http://www.develer.com/)
30 #
31 # $Id$
32 #
33 # Author: Lorenzo Berni <duplo@develer.com>
34 #
35
36 import os
37 import sys
38 from distutils.dep_util import newer
39
40 from PyQt4.QtCore import *
41 from PyQt4.QtGui import *
42
43 import exception_handler
44
45 from BProject import BProject
46
47 from BWizard import BWizard
48
49 from BIntroPage import BIntroPage
50 from BFolderPage import BFolderPage
51 from BBoardPage import BBoardPage
52 from BProjectPresets import BProjectPresets
53 from BRoutePage import BRoutePage
54 from BOpenPage import BOpenPage
55 from BVersionPage import BVersionPage
56 from BCpuPage import BCpuPage
57 from BToolchainPage import BToolchainPage
58 from BModulePage import BModulePage
59 from BOutputPage import BOutputPage
60 from BCreationPage import BCreationPage
61 from BFinalPage import BFinalPage
62
63 from BEditingDialog import BEditingDialog, BVersionDialog, BToolchainDialog
64
65 from const import DATA_DIR
66
67 from LoadException import VersionException, ToolchainException
68
69 def newProject():
70     QApplication.instance().project = BProject()
71     page_list = [BIntroPage, BFolderPage, BVersionPage, BBoardPage, BProjectPresets, BRoutePage, BCpuPage, BToolchainPage, BModulePage, BOutputPage, BCreationPage, BFinalPage]
72     wizard = BWizard(page_list)
73     wizard.show()
74     wizard.exec_()
75     project = QApplication.instance().project
76     to_be_opened = project.info("TO_BE_OPENED")
77     command_lines = project.info("COMMAND_LINES")
78     relevant_files = project.info("RELEVANT_FILES")
79     if to_be_opened:
80         for ide in to_be_opened:
81             command_line = command_lines[ide]
82             relevant_file = relevant_files[ide]
83             QProcess.startDetached(command_line, [relevant_file,])
84     sys.exit()
85
86 def editProject(project_file):
87     info_dict = {}
88     while(True):
89         # Empty project is the default fallback.
90         QApplication.instance().project = BProject()
91         try:
92             QApplication.instance().project = BProject(project_file, info_dict)
93         except VersionException:
94             QMessageBox.critical(
95                 None,
96                 QObject().tr("BeRTOS version not found!"),
97                 QObject().tr("The selected BeRTOS version was not found, please select another one...")
98             )
99             dialog = BVersionDialog()
100             if dialog.exec_():
101                 version = dialog.version_page.currentVersion()
102                 info_dict["BERTOS_PATH"] = version
103             continue
104         except ToolchainException, exc:
105             QMessageBox.critical(
106                 None,
107                 QObject().tr("Toolchain not found!"),
108                 QObject().tr("The selected toolchain was not found, please select another one...")
109             )
110             QApplication.instance().project = exc.partial_project
111             dialog = BToolchainDialog()
112             if dialog.exec_():
113                 toolchain = dialog.toolchain_page.currentToolchain()
114                 info_dict["TOOLCHAIN"] = toolchain
115             continue
116         break
117     dialog = BEditingDialog()
118     dialog.exec_()
119
120 def main():
121     app = QApplication(sys.argv)
122     app.settings = QSettings("Develer", "Bertos Configurator")
123     # Development utility lines, to be removed for production
124     datadir = DATA_DIR
125     qrc, rcc = os.path.join(datadir, 'bertos.qrc'), os.path.join(datadir, 'bertos.rcc')
126     if not (hasattr(sys, "frozen") and sys.frozen) and newer(qrc, rcc):
127         os.system("rcc -binary %s -o %s" %(qrc, rcc))
128     QResource.registerResource(rcc)
129     if len(sys.argv) == 3 and sys.argv[1] == "--edit":
130         editProject(os.path.abspath(sys.argv[2]))
131     else:
132         newProject()
133
134
135 if __name__ == '__main__':
136     main()
137