From 4a899f2d9becbd204e6f63dbf4fb7be921a1ce71 Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Fri, 18 Oct 2013 20:15:49 +0300 Subject: [PATCH] Turn user options into for widgets. --- mesongui.py | 32 ++++++++++++++++--- optinterpreter.py | 6 +++- .../common/47 options/meson_options.txt | 2 +- 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/mesongui.py b/mesongui.py index 3a8a8cf73..8c291783c 100755 --- a/mesongui.py +++ b/mesongui.py @@ -15,7 +15,7 @@ # limitations under the License. import sys, os, pickle, time, shutil -import build, coredata, environment +import build, coredata, environment, optinterpreter from PyQt5 import uic from PyQt5.QtWidgets import QApplication, QMainWindow, QHeaderView from PyQt5.QtWidgets import QComboBox, QCheckBox @@ -234,9 +234,11 @@ class CoreModel(QAbstractItemModel): return QModelIndex() class OptionForm: - def __init__(self, cdata, form): - self.coredata = cdata + def __init__(self, build, coredata, form): + self.build = build + self.coredata = coredata self.form = form + form.addRow(PyQt5.QtWidgets.QLabel("Meson options")) combo = QComboBox() combo.addItem('plain') combo.addItem('debug') @@ -256,6 +258,28 @@ class OptionForm: pch.setChecked(self.coredata.use_pch) pch.stateChanged.connect(self.pch_changed) self.form.addRow('Enable pch', pch) + form.addRow(PyQt5.QtWidgets.QLabel("Project options")) + self.set_user_options() + + def set_user_options(self): + options = self.build.user_options + keys = list(options.keys()) + keys.sort() + for key in keys: + opt = options[key] + if isinstance(opt, optinterpreter.UserStringOption): + w = PyQt5.QtWidgets.QLineEdit(opt.value) + elif isinstance(opt, optinterpreter.UserBooleanOption): + w = QCheckBox('') + w.setChecked(opt.value) + elif isinstance(opt, optinterpreter.UserComboOption): + w = QComboBox() + for i in opt.choices: + w.addItem(i) + w.setCurrentText(opt.value) + else: + raise RuntimeError("Unknown option type") + self.form.addRow(opt.description, w) def build_type_changed(self, newtype): self.coredata.buildtype = newtype @@ -338,7 +362,7 @@ class MesonGui(): self.build_dir = self.build.environment.build_dir self.src_dir = self.build.environment.source_dir self.build_models() - self.options = OptionForm(self.coredata, self.ui.option_form) + self.options = OptionForm(self.build, self.coredata, self.ui.option_form) self.ui.show() def build_models(self): diff --git a/optinterpreter.py b/optinterpreter.py index 9d2353646..0b87e04ad 100644 --- a/optinterpreter.py +++ b/optinterpreter.py @@ -23,6 +23,7 @@ class OptionException(coredata.MesonException): class UserOption: def __init__(self, kwargs): super().__init__() + self.description = kwargs.get('description', '') class UserStringOption(UserOption): def __init__(self, kwargs): @@ -127,4 +128,7 @@ class OptionInterpreter: opt_name = posargs[0] if not isinstance(opt_name, str): raise OptionException('Positional argument must be a string.') - self.options[opt_name] = option_types[opt_type](kwargs) + opt = option_types[opt_type](kwargs) + if opt.description == '': + opt.description = opt_name + self.options[opt_name] = opt diff --git a/test cases/common/47 options/meson_options.txt b/test cases/common/47 options/meson_options.txt index fcd3db4b9..653dd75f9 100644 --- a/test cases/common/47 options/meson_options.txt +++ b/test cases/common/47 options/meson_options.txt @@ -1,3 +1,3 @@ -option('testoption', type : 'string', value : 'optval') +option('testoption', type : 'string', value : 'optval', description : 'An option to do something') option('other_one', type : 'boolean', value : false) option('combo_opt', type : 'combo', choices : ['one', 'two', 'combo'], value : 'combo')