6ed7e621c3fab625c664c3666fb58e2709a3aae7
[bertos.git] / wizard / BEditingDialog.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 sys
37 import os
38
39 from PyQt4.QtCore import *
40 from PyQt4.QtGui import *
41
42 from bertos_utils import loadBertosProject, bertosVersion, getToolchainName, createBertosProject
43 from BToolchainPage import BToolchainPage
44 from BVersionPage import BVersionPage
45 import qvariant_converter
46 import BModulePage
47
48 class BEditingDialog(QDialog):
49
50     def __init__(self, parent=None):
51         QDialog.__init__(self, parent)
52         self.setupUi()
53         self.connectSignals()
54         self.module_page.reloadData()
55     
56     def setupUi(self):
57         layout = QVBoxLayout()
58         self.module_page = BModulePage.BModulePage()
59         layout.addWidget(self.module_page)
60         button_layout = QHBoxLayout()
61         self.advanced_button = QToolButton()
62         self.setupMenu()
63         self.advanced_button.setMenu(self.menu)
64         self.advanced_button.setPopupMode(QToolButton.InstantPopup)
65         self.advanced_button.setText(self.tr("Advanced"))
66         button_layout.addWidget(self.advanced_button)
67         button_layout.addStretch()
68         self.cancel_button = QPushButton(self.tr("Cancel"))
69         button_layout.addWidget(self.cancel_button)
70         self.apply_button = QPushButton(self.tr("Apply"))
71         button_layout.addWidget(self.apply_button)
72         layout.addLayout(button_layout)
73         self.setLayout(layout)
74
75     def setupMenu(self):
76         self.menu = QMenu(self.tr("Advanced options"))
77         self.change_toolchain = QAction(self.tr("Change toolchain"), self)
78         self.change_bertos_version = QAction(self.tr("Change BeRTOS version"), self)
79         self.menu.addAction(self.change_toolchain)
80         self.menu.addAction(self.change_bertos_version)
81
82     def connectSignals(self):
83         self.connect(self.change_toolchain, SIGNAL("triggered(bool)"), self.changeToolchain)
84         self.connect(self.change_bertos_version, SIGNAL("triggered(bool)"), self.changeBertosVersion)
85         self.connect(self.apply_button, SIGNAL("clicked()"), self.apply)
86         self.connect(self.cancel_button, SIGNAL("clicked()"), self.reject)
87
88     def changeToolchain(self):
89         dialog = QDialog()
90         layout = QVBoxLayout()
91         toolchain_page = BToolchainPage()
92         toolchain_page.reloadData()
93         layout.addWidget(toolchain_page)
94         button_layout = QHBoxLayout()
95         button_layout.addStretch()
96         cancel_button = QPushButton(self.tr("Cancel")) 
97         button_layout.addWidget(cancel_button)
98         ok_button = QPushButton(self.tr("Ok"))
99         button_layout.addWidget(ok_button)
100         dialog.connect(cancel_button, SIGNAL("clicked()"), dialog.reject)
101         layout.addLayout(button_layout)
102         dialog.setLayout(layout)
103         dialog.connect(ok_button, SIGNAL("clicked()"), dialog.accept)
104         dialog.exec_()
105     
106     def changeBertosVersion(self):
107         dialog = QDialog()
108         layout = QVBoxLayout()
109         version_page = BVersionPage()
110         version_page.reloadData()
111         layout.addWidget(version_page)
112         button_layout = QHBoxLayout()
113         button_layout.addStretch()
114         cancel_button = QPushButton(self.tr("Cancel")) 
115         button_layout.addWidget(cancel_button)
116         ok_button = QPushButton(self.tr("Ok"))
117         button_layout.addWidget(ok_button)
118         dialog.connect(cancel_button, SIGNAL("clicked()"), dialog.reject)
119         layout.addLayout(button_layout)
120         dialog.setLayout(layout)
121         dialog.connect(ok_button, SIGNAL("clicked()"), dialog.accept)
122         dialog.exec_()
123
124     def apply(self):
125         createBertosProject(self.module_page.project(), edit=True)
126         self.accept()
127
128     def toolchains(self):
129         return self.module_page.toolchains()
130     
131     def currentToolchain(self):
132         return self.module_page.projectInfo("TOOLCHAIN")
133     
134     def setCurrentToolchain(self, toolchain):
135         self.module_page.setProjectInfo("TOOLCHAIN", toolchain)
136
137     def versions(self):
138         return self.module_page.versions()
139
140     def currentVersion(self):
141         return self.module_page.projectInfo("SOURCES_PATH")
142     
143     def setCurrentVersion(self, version):
144         self.module_page.setProjectInfo("SOURCES_PATH", version)
145
146
147
148 def main():
149     if len(sys.argv) > 1:
150         project_file = sys.argv[1]
151     else:
152         print "Invalid usage: use <command> project_file"
153         sys.exit()
154     app = QApplication([])
155     app.project = loadBertosProject(project_file)
156     app.settings = QSettings("Develer", "Bertos Configurator")
157     dialog = BEditingDialog()
158     dialog.show()
159     sys.exit(app.exec_())
160
161 if __name__ == "__main__":
162     main()