Set tooltip instead of changing the entry text.
[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 BTypePage import BTypePage
52 from BBoardPage import BBoardPage
53 from BProjectPresets import BProjectPresets
54 from BRoutePage import BRoutePage
55 from BOpenPage import BOpenPage
56 from BVersionPage import BVersionPage
57 from BCpuPage import BCpuPage
58 from BToolchainPage import BToolchainPage
59 from BModulePage import BModulePage
60 from BOutputPage import BOutputPage
61 from BCreationPage import BCreationPage
62 from BFinalPage import BFinalPage
63
64 from BEditingDialog import BEditingDialog, BVersionDialog, BToolchainDialog
65
66 from const import DATA_DIR
67
68 from LoadException import VersionException, ToolchainException
69
70 def newProject():
71     QApplication.instance().project = BProject()
72     page_list = [BIntroPage, BFolderPage, BVersionPage, BTypePage, BBoardPage, BProjectPresets, BRoutePage, BCpuPage, BToolchainPage, BModulePage, BOutputPage, BCreationPage, BFinalPage]
73     wizard = BWizard(page_list)
74     wizard.show()
75     wizard.exec_()
76     project = QApplication.instance().project
77     to_be_opened = project.info("TO_BE_OPENED")
78     command_lines = project.info("COMMAND_LINES")
79     relevant_files = project.info("RELEVANT_FILES")
80     if to_be_opened:
81         for ide in to_be_opened:
82             command_line = command_lines[ide]
83             relevant_file = relevant_files[ide]
84             QProcess.startDetached(command_line, [relevant_file,])
85     sys.exit()
86
87 def editProject(project_file):
88     info_dict = {}
89     while(True):
90         # Empty project is the default fallback.
91         QApplication.instance().project = BProject()
92         try:
93             QApplication.instance().project = BProject(project_file, info_dict)
94         except VersionException:
95             QMessageBox.critical(
96                 None,
97                 QObject().tr("BeRTOS version not found!"),
98                 QObject().tr("The selected BeRTOS version was not found, please select another one...")
99             )
100             dialog = BVersionDialog()
101             if dialog.exec_():
102                 version = dialog.version_page.currentVersion()
103                 info_dict["BERTOS_PATH"] = version
104             continue
105         except ToolchainException, exc:
106             QMessageBox.critical(
107                 None,
108                 QObject().tr("Toolchain not found!"),
109                 QObject().tr("The selected toolchain was not found, please select another one...")
110             )
111             QApplication.instance().project = exc.partial_project
112             dialog = BToolchainDialog()
113             if dialog.exec_():
114                 toolchain = dialog.toolchain_page.currentToolchain()
115                 info_dict["TOOLCHAIN"] = toolchain
116             continue
117         break
118     dialog = BEditingDialog()
119     dialog.exec_()
120
121 def main():
122     app = QApplication(sys.argv)
123     app.settings = QSettings("Develer", "Bertos Configurator")
124     # Development utility lines, to be removed for production
125     datadir = DATA_DIR
126     qrc, rcc = os.path.join(datadir, 'bertos.qrc'), os.path.join(datadir, 'bertos.rcc')
127     if not (hasattr(sys, "frozen") and sys.frozen) and newer(qrc, rcc):
128         os.system("rcc -binary %s -o %s" %(qrc, rcc))
129     QResource.registerResource(rcc)
130     if len(sys.argv) == 3 and sys.argv[1] == "--edit":
131         editProject(os.path.abspath(sys.argv[2]))
132     else:
133         newProject()
134
135
136 if __name__ == '__main__':
137     main()
138