Use the version name instead of the pathw
[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
43 import BModulePage
44
45 class BEditingDialog(QDialog):
46
47     def __init__(self, parent=None):
48         QDialog.__init__(self, parent)
49         self.setupUi()
50         self.module_page.reloadData()
51     
52     def setupUi(self):
53         layout = QVBoxLayout()
54         self.module_page = BModulePage.BModulePage()
55         layout.addWidget(self.module_page)
56         button_layout = QHBoxLayout()
57         self.advanced_button = QToolButton()
58         self.setupMenu()
59         self.advanced_button.setMenu(self.menu)
60         self.advanced_button.setPopupMode(QToolButton.InstantPopup)
61         self.advanced_button.setText(self.tr("Advanced"))
62         button_layout.addWidget(self.advanced_button)
63         button_layout.addStretch()
64         self.cancel_button = QPushButton(self.tr("Cancel"))
65         button_layout.addWidget(self.cancel_button)
66         self.apply_button = QPushButton(self.tr("Apply"))
67         button_layout.addWidget(self.apply_button)
68         layout.addLayout(button_layout)
69         self.setLayout(layout)
70
71     def setupMenu(self):
72         self.menu = QMenu(self.tr("Advanced options"))
73         self.setupToolchainMenu()
74         self.menu.addMenu(self.toolchain_menu)
75         self.setupVersionMenu()
76         self.menu.addMenu(self.version_menu)
77
78     def setupToolchainMenu(self):
79         self.toolchain_menu = QMenu(self.tr("select toolchain"))
80         action_group = QActionGroup(self.toolchain_menu)
81         for toolchain in sorted(self.toolchains()):
82             action = self.toolchain_menu.addAction(toolchain)
83             action_group.addAction(action)
84             action.setCheckable(True)
85             action.setChecked(True if unicode(action.text()) == self.currentToolchain()["path"] else False)
86
87     def setupVersionMenu(self):
88         self.version_menu = QMenu(self.tr("select BeRTOS version"))
89         action_group = QActionGroup(self.version_menu)
90         for version in sorted([bertosVersion(v) for v in self.versions()]):
91             action = self.version_menu.addAction(version)
92             action_group.addAction(action)
93             action.setCheckable(True)
94             action.setChecked(True if unicode(action.text()) == self.currentVersion() else False)
95
96     def toolchains(self):
97         return self.module_page.toolchains()
98     
99     def currentToolchain(self):
100         return self.module_page.projectInfo("TOOLCHAIN")
101     
102     def setCurrentToolchain(self, toolchain):
103         self.module_page.setProjectInfo("TOOLCHAIN", toolchain)
104
105     def versions(self):
106         return self.module_page.versions()
107
108     def currentVersion(self):
109         return self.module_page.projectInfo("SOURCES_PATH")
110     
111     def setCurrentVersion(self, version):
112         self.module_page.setProjectInfo("SOURCES_PATH", version)
113
114
115
116 def main():
117     if len(sys.argv) > 1:
118         project_file = sys.argv[1]
119     else:
120         print "Invalid usage: use <command> project_file"
121         sys.exit()
122     app = QApplication([])
123     app.project = loadBertosProject(project_file)
124     app.settings = QSettings("Develer", "Bertos Configurator")
125     dialog = BEditingDialog()
126     dialog.show()
127     sys.exit(app.exec_())
128
129 if __name__ == "__main__":
130     main()