31e765dc181bcd292a9298f2a75456541989019f
[bertos.git] / wizard / BFinalPage.py
1 #!/usr/bin/env python
2 # encoding: utf-8
3 #
4 # Copyright 2009 Develer S.r.l. (http://www.develer.com/)
5 # All rights reserved.
6 #
7 # $Id$
8 #
9 # Author: Lorenzo Berni <duplo@develer.com>
10 #
11
12 import os
13
14 from PyQt4.QtGui import *
15
16 from BWizardPage import *
17 import bertos_utils
18
19 from const import *
20
21 class BFinalPage(BWizardPage):
22     """
23     Last page of the wizard. It creates the project and show a success message.
24     """
25     
26     def __init__(self):
27         BWizardPage.__init__(self, UI_LOCATION + "/final_page.ui")
28         self.setTitle(self.tr("Project created successfully"))
29     
30     ## Overloaded BWizardPage methods ##
31         
32     def reloadData(self):
33         """
34         Overload of the BWizardPage reloadData method.
35         """
36         QApplication.instance().setOverrideCursor(Qt.WaitCursor)
37         bertos_utils.createBertosProject(self.project())
38         QApplication.instance().restoreOverrideCursor()
39         self._plugin_dict = {}
40         if os.name == "nt":
41             output = self.projectInfo("OUTPUT")
42             import winreg_importer
43             command_lines = winreg_importer.getCommandLines()
44             self.setProjectInfo("COMMAND_LINES", command_lines)
45             layout = QVBoxLayout()
46             for plugin in output:
47                 if plugin in command_lines:
48                     module = bertos_utils.loadPlugin(plugin)
49                     check = QCheckBox(self.tr("Open project in %s" %module.PLUGIN_NAME))
50                     if len(output) == 1:
51                         check.setCheckState(Qt.Checked)
52                     else:
53                         check.setCheckState(Qt.Unchecked)
54                     layout.addWidget(check)
55                     self._plugin_dict[check] = plugin
56             widget = QWidget()
57             widget.setLayout(layout)
58             if len(self._plugin_dict) > 0:
59                 self.pageContent.scrollArea.setVisible(True)
60             self.pageContent.scrollArea.setWidget(widget)
61             for plugin in self._plugin_dict:
62                 self.connect(plugin, SIGNAL("stateChanged(int)"), self.modeChecked)
63         self.modeChecked()
64     
65     def setupUi(self):
66         """
67         Overload of the BWizardPage setupUi method.
68         """
69         self.pageContent.scrollArea.setVisible(False)
70     
71     ####
72
73     ## Slots ##
74
75     def modeChecked(self):
76         to_be_opened = []
77         for check, plugin in self._plugin_dict.items():
78             if check.checkState() == Qt.Checked:
79                 to_be_opened.append(plugin)
80         self.setProjectInfo("TO_BE_OPENED", to_be_opened)
81     
82     ####