Close the Wizard after launching CodeLite.
[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 BProject
44
45 import BStartPage
46 import BWizard
47
48 from BFolderPage import BFolderPage
49 from BOpenPage import BOpenPage
50 from BVersionPage import BVersionPage
51 from BCpuPage import BCpuPage
52 from BToolchainPage import BToolchainPage
53 from BModulePage import BModulePage
54 from BOutputPage import BOutputPage
55 from BCreationPage import BCreationPage
56 from BFinalPage import BFinalPage
57
58 from BEditingDialog import BEditingDialog
59
60 import bertos_utils
61
62 def newProject():
63     page_list = [BFolderPage, BVersionPage, BCpuPage, BToolchainPage, BModulePage, BOutputPage, BCreationPage, BFinalPage]
64     wizard = BWizard.BWizard(page_list)
65     wizard.show()
66     wizard.exec_()
67     project = QApplication.instance().project
68     to_be_opened = project.info("TO_BE_OPENED")
69     command_lines = project.info("COMMAND_LINES")
70     relevant_files = project.info("RELEVANT_FILES")
71     if to_be_opened:
72         for ide in to_be_opened:
73             command_line = command_lines[ide]
74             relevant_file = relevant_files[ide]
75             QProcess.startDetached(command_line, [relevant_file,])
76     sys.exit()
77     
78 def editProject(project_file):
79     QApplication.instance().project = bertos_utils.loadBertosProject(project_file)
80     dialog = BEditingDialog()
81     dialog.exec_()
82
83 def showStartPage():
84     QApplication.instance().dialog = BStartPage.BStartPage()
85     QApplication.instance().connect(QApplication.instance().dialog, SIGNAL("newProject"), newProject)
86     QApplication.instance().connect(QApplication.instance().dialog, SIGNAL("editProject"), editProject)
87     QApplication.instance().dialog.show()
88
89 def main():
90     os.chdir(os.path.dirname(os.path.abspath(sys.argv[0])))
91     app = QApplication(sys.argv)
92     app.settings = QSettings("Develer", "Bertos Configurator")
93     app.project = BProject.BProject()
94     # Development utility lines, to be removed for production
95     if not (hasattr(sys, "frozen") and sys.frozen) and newer("bertos.qrc", "bertos.rcc"):
96         os.system("rcc -binary bertos.qrc -o bertos.rcc")
97     QResource.registerResource("bertos.rcc")
98     if len(sys.argv) == 3 and sys.argv[1] == "--edit":
99         editProject(sys.argv[2])
100     else:
101         newProject()
102  
103
104 if __name__ == '__main__':
105     main()
106