-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/parameter: Add parameter dialog #246
Merged
Merged
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
fe893f6
add parameter dialog
buganini 13c9a1d
RParameter: support int64/double types
buganini b1aa2cb
RParameter: allow building parameters list at runtime
buganini f61a828
modmesh/params.py: add license
buganini 73c311f
RParameter: clang-format fix
buganini 90d4348
modmesh/params.py: fix flake8 issue
buganini a4df8fd
check PUI version
buganini ad3f4ed
modmesh/params.py: fix test example
buganini File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright (c) 2023, Buganini Chiu <[email protected]> | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* | ||
* - Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* - Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* - Neither the name of the copyright holder nor the names of its contributors | ||
* may be used to endorse or promote products derived from this software | ||
* without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#include <modmesh/view/RParameter.hpp> // Must be the first include. | ||
|
||
namespace modmesh | ||
{ | ||
pybind11::tuple createParameters(void) { | ||
pybind11::module pui_module = pybind11::module::import("PUI"); | ||
return pybind11::make_tuple( | ||
pui_module.attr("StateDict")(), pybind11::list() | ||
); | ||
} | ||
|
||
void openParameterView(pybind11::tuple & params) { | ||
pybind11::module params_module = pybind11::module::import("modmesh.params"); | ||
params_module.attr("openParameterView")(params[1]); | ||
} | ||
|
||
} /* end namespace modmesh */ | ||
|
||
// vim: set ff=unix fenc=utf8 et sw=4 ts=4 sts=4: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#pragma once | ||
|
||
/* | ||
* Copyright (c) 2023, Buganini Chiu <[email protected]> | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* | ||
* - Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* - Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* - Neither the name of the copyright holder nor the names of its contributors | ||
* may be used to endorse or promote products derived from this software | ||
* without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#include <modmesh/view/common_detail.hpp> // Must be the first include. | ||
|
||
namespace modmesh | ||
{ | ||
|
||
pybind11::tuple createParameters(void); | ||
void openParameterView(pybind11::tuple & params); | ||
|
||
template <typename T> | ||
void addParam(pybind11::tuple & params, const char *key, T *ptr) { | ||
params[0][pybind11::str(key)] = *ptr; | ||
auto binding = params[0](key); | ||
binding.attr("bind")( | ||
pybind11::cpp_function([ptr](){ | ||
return *ptr; | ||
}), | ||
pybind11::cpp_function([key, ptr](T value){ | ||
std::cout << "Set " << key << " = " << value << std::endl; | ||
*ptr = value; | ||
}) | ||
); | ||
static_cast<pybind11::list>(params[1]).append(binding); | ||
} | ||
|
||
} /* end namespace modmesh */ | ||
|
||
// vim: set ff=unix fenc=utf8 et sw=4 ts=4 sts=4: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
from PUI.PySide6 import * | ||
|
||
class ParameterView(PuiInQt): | ||
class TableAdapter: | ||
def __init__(self, state, data): | ||
self.state = state | ||
self._data = data | ||
|
||
def data(self, row, col): | ||
param = self._data[row] | ||
return [param.key, param.value][col] | ||
|
||
def setData(self, row, col, value): | ||
if col==1: | ||
self._data[row].value = value | ||
|
||
def editable(self, row, col): | ||
return col > 0 | ||
|
||
def columnHeader(self, col): | ||
return ["Key","Value"][col] | ||
|
||
def rowCount(self): | ||
return len(self._data) | ||
|
||
def columnCount(self): | ||
return 2 | ||
|
||
def __init__(self, container, state): | ||
super().__init__(container) | ||
self.state = state | ||
|
||
def content(self): | ||
data = State() | ||
if not self.state.filter: | ||
data.params = self.state.params | ||
else: | ||
data.params = [it for it in self.state.params if self.state.filter in it.key] | ||
with VBox(): | ||
TextField(self.state("filter")) | ||
Table(self.TableAdapter(self.state, data.params)) | ||
|
||
def openParameterView(params): | ||
state = State() | ||
state.buffer = [f"line {i}" for i in range(50)] | ||
state.cmd_edit = "" | ||
state.config_modal = False | ||
state.filter = "" | ||
state.params = params | ||
pv = ParameterView(Window(size=(640, 480)), state) | ||
pv.redraw() | ||
|
||
if __name__=="__main__": | ||
class Example(): | ||
def __init__(self): | ||
self.app = QtWidgets.QApplication([]) | ||
|
||
def run(self): | ||
openParameterView() | ||
self.app.exec() | ||
|
||
root = Example() | ||
root.run() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add license text.