Turn user options into for widgets.

pull/15/head
Jussi Pakkanen 11 years ago
parent 75edffd34d
commit 4a899f2d9b
  1. 32
      mesongui.py
  2. 6
      optinterpreter.py
  3. 2
      test cases/common/47 options/meson_options.txt

@ -15,7 +15,7 @@
# limitations under the License. # limitations under the License.
import sys, os, pickle, time, shutil import sys, os, pickle, time, shutil
import build, coredata, environment import build, coredata, environment, optinterpreter
from PyQt5 import uic from PyQt5 import uic
from PyQt5.QtWidgets import QApplication, QMainWindow, QHeaderView from PyQt5.QtWidgets import QApplication, QMainWindow, QHeaderView
from PyQt5.QtWidgets import QComboBox, QCheckBox from PyQt5.QtWidgets import QComboBox, QCheckBox
@ -234,9 +234,11 @@ class CoreModel(QAbstractItemModel):
return QModelIndex() return QModelIndex()
class OptionForm: class OptionForm:
def __init__(self, cdata, form): def __init__(self, build, coredata, form):
self.coredata = cdata self.build = build
self.coredata = coredata
self.form = form self.form = form
form.addRow(PyQt5.QtWidgets.QLabel("Meson options"))
combo = QComboBox() combo = QComboBox()
combo.addItem('plain') combo.addItem('plain')
combo.addItem('debug') combo.addItem('debug')
@ -256,6 +258,28 @@ class OptionForm:
pch.setChecked(self.coredata.use_pch) pch.setChecked(self.coredata.use_pch)
pch.stateChanged.connect(self.pch_changed) pch.stateChanged.connect(self.pch_changed)
self.form.addRow('Enable pch', pch) 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): def build_type_changed(self, newtype):
self.coredata.buildtype = newtype self.coredata.buildtype = newtype
@ -338,7 +362,7 @@ class MesonGui():
self.build_dir = self.build.environment.build_dir self.build_dir = self.build.environment.build_dir
self.src_dir = self.build.environment.source_dir self.src_dir = self.build.environment.source_dir
self.build_models() 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() self.ui.show()
def build_models(self): def build_models(self):

@ -23,6 +23,7 @@ class OptionException(coredata.MesonException):
class UserOption: class UserOption:
def __init__(self, kwargs): def __init__(self, kwargs):
super().__init__() super().__init__()
self.description = kwargs.get('description', '')
class UserStringOption(UserOption): class UserStringOption(UserOption):
def __init__(self, kwargs): def __init__(self, kwargs):
@ -127,4 +128,7 @@ class OptionInterpreter:
opt_name = posargs[0] opt_name = posargs[0]
if not isinstance(opt_name, str): if not isinstance(opt_name, str):
raise OptionException('Positional argument must be a string.') 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

@ -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('other_one', type : 'boolean', value : false)
option('combo_opt', type : 'combo', choices : ['one', 'two', 'combo'], value : 'combo') option('combo_opt', type : 'combo', choices : ['one', 'two', 'combo'], value : 'combo')

Loading…
Cancel
Save