mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[apps/code] Get imported modules in the variable box
This commit is contained in:
@@ -437,6 +437,18 @@ PythonToolbox::PythonToolbox() :
|
||||
{
|
||||
}
|
||||
|
||||
const ToolboxMessageTree * PythonToolbox::moduleChildren(const char * name, int * numberOfNodes) const {
|
||||
assert(numberOfNodes != nullptr);
|
||||
for (ToolboxMessageTree t : modulesChildren) {
|
||||
if (strcmp(I18n::translate(t.label()), name)) {
|
||||
*numberOfNodes = t.numberOfChildren();
|
||||
assert(*numberOfNodes > 0);
|
||||
return static_cast<const ToolboxMessageTree *>(t.children(0));
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool PythonToolbox::handleEvent(Ion::Events::Event event) {
|
||||
if (Toolbox::handleEvent(event)) {
|
||||
return true;
|
||||
|
||||
@@ -10,7 +10,11 @@ namespace Code {
|
||||
|
||||
class PythonToolbox : public Toolbox {
|
||||
public:
|
||||
// PythonToolbox
|
||||
PythonToolbox();
|
||||
const ToolboxMessageTree * moduleChildren(const char * name, int * numberOfNodes) const;
|
||||
|
||||
// Toolbox
|
||||
bool handleEvent(Ion::Events::Event event) override;
|
||||
protected:
|
||||
KDCoordinate rowHeight(int j) override;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "variable_box_controller.h"
|
||||
#include "python_toolbox.h"
|
||||
#include "script.h"
|
||||
#include "app.h"
|
||||
#include "../shared/toolbox_helpers.h"
|
||||
@@ -130,11 +131,29 @@ void VariableBoxController::addNodesFromImportMaybe(mp_parse_node_struct_t * par
|
||||
}
|
||||
|
||||
if (loadModuleContent) {
|
||||
// We fetch variables and functions imported from a module or a script
|
||||
assert(childNodesCount > 0);
|
||||
mp_parse_node_t moduleName = parseNode->nodes[0];
|
||||
assert(MP_PARSE_NODE_IS_LEAF(moduleName) && MP_PARSE_NODE_LEAF_KIND(moduleName) == MP_PARSE_NODE_ID);
|
||||
|
||||
|
||||
mp_parse_node_t importationSource = parseNode->nodes[0];
|
||||
assert(MP_PARSE_NODE_IS_LEAF(importationSource) && MP_PARSE_NODE_LEAF_KIND(importationSource) == MP_PARSE_NODE_ID);
|
||||
const char * importationSourceName = qstr_str(MP_PARSE_NODE_LEAF_ARG(importationSource));
|
||||
int numberOfChildren = 0;
|
||||
const ToolboxMessageTree * moduleChildren = static_cast<PythonToolbox *>(App::app()->toolboxForInputEventHandler(nullptr))->moduleChildren(importationSourceName, &numberOfChildren);
|
||||
if (moduleChildren != nullptr) {
|
||||
/* If the importation source is a module, get the nodes from the toolbox
|
||||
* We skip the 3 forst nodes, which are "import ...", "from ... import *"
|
||||
* and "....function". */
|
||||
constexpr int numberOfNodesToSkip = 3;
|
||||
assert(numberOfChildren > numberOfNodesToSkip);
|
||||
for (int i = 3; i < numberOfChildren; i++) {
|
||||
// TODO LEA check if not already present
|
||||
const ToolboxMessageTree * currentTree = moduleChildren + i;
|
||||
const char * name = I18n::translate(currentTree->label());
|
||||
addNode(ScriptNode::Type::Variable, NodeOrigin::Importation, name, -1, 1/*TODO LEA*/);
|
||||
}
|
||||
} else if (false) {
|
||||
//TODO LEA
|
||||
// else, try fetching the nodes from a script
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user