4 # This file is part of BeRTOS.
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.
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.
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
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.
29 # Copyright 2008 Develer S.r.l. (http://www.develer.com/)
33 # Author: Lorenzo Berni <duplo@develer.com>
39 from PyQt4.QtCore import *
40 from PyQt4.QtGui import *
42 from bertos_utils import loadBertosProject, bertosVersion, getToolchainName, createBertosProject
43 from BToolchainPage import BToolchainPage
44 from BVersionPage import BVersionPage
45 import qvariant_converter
48 class BEditingDialog(QDialog):
50 def __init__(self, parent=None):
51 QDialog.__init__(self, parent)
54 self.module_page.reloadData()
57 layout = QVBoxLayout()
58 self.module_page = BModulePage.BModulePage()
59 layout.addWidget(self.module_page)
60 button_layout = QHBoxLayout()
61 self.advanced_button = QToolButton()
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)
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)
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)
88 def changeToolchain(self):
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)
105 toolchain = qvariant_converter.getStringDict(toolchain_page.currentItem().data(Qt.UserRole))
106 toolchain_page.setProjectInfo("TOOLCHAIN", toolchain)
108 def changeBertosVersion(self):
110 layout = QVBoxLayout()
111 version_page = BVersionPage()
112 version_page.reloadData()
113 layout.addWidget(version_page)
114 button_layout = QHBoxLayout()
115 button_layout.addStretch()
116 cancel_button = QPushButton(self.tr("Cancel"))
117 button_layout.addWidget(cancel_button)
118 ok_button = QPushButton(self.tr("Ok"))
119 button_layout.addWidget(ok_button)
120 dialog.connect(cancel_button, SIGNAL("clicked()"), dialog.reject)
121 layout.addLayout(button_layout)
122 dialog.setLayout(layout)
123 dialog.connect(ok_button, SIGNAL("clicked()"), dialog.accept)
124 current_version = version_page.projectInfo("SOURCES_PATH")
126 version = qvariant_converter.getString(version_page.currentItem().data(Qt.UserRole))
127 if version != current_version:
128 if QMessageBox.question(
130 self.tr("BeRTOS version update"),
131 self.tr("Changing the BeRTOS version will destroy all the modification done on the BeRTOS sources"),
132 QMessageBox.Ok | QMessageBox.Cancel
134 version_page.setProjectInfo("SOURCES_PATH", version)
135 version_page.setProjectInfo("OLD_SOURCES_PATH", current_version)
138 createBertosProject(self.module_page.project(), edit=True)
141 def toolchains(self):
142 return self.module_page.toolchains()
144 def currentToolchain(self):
145 return self.module_page.projectInfo("TOOLCHAIN")
147 def setCurrentToolchain(self, toolchain):
148 self.module_page.setProjectInfo("TOOLCHAIN", toolchain)
151 return self.module_page.versions()
153 def currentVersion(self):
154 return self.module_page.projectInfo("SOURCES_PATH")
156 def setCurrentVersion(self, version):
157 self.module_page.setProjectInfo("SOURCES_PATH", version)
162 if len(sys.argv) > 1:
163 project_file = sys.argv[1]
165 print "Invalid usage: use <command> project_file"
167 app = QApplication([])
168 app.project = loadBertosProject(project_file)
169 app.settings = QSettings("Develer", "Bertos Configurator")
170 dialog = BEditingDialog()
172 sys.exit(app.exec_())
174 if __name__ == "__main__":