Skip to content

Commit

Permalink
Rename RApplication to RManager
Browse files Browse the repository at this point in the history
* Python modmesh.view.app is also renamed to modmesh.view.mgr.
  • Loading branch information
yungyuc committed Dec 10, 2022
1 parent 8aa7ab1 commit 2b7945f
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 65 deletions.
4 changes: 2 additions & 2 deletions cpp/modmesh/view/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.16)

set(MODMESH_VIEW_PYMODHEADERS
${CMAKE_CURRENT_SOURCE_DIR}/R3DWidget.hpp
${CMAKE_CURRENT_SOURCE_DIR}/RApplication.hpp
${CMAKE_CURRENT_SOURCE_DIR}/RManager.hpp
${CMAKE_CURRENT_SOURCE_DIR}/RAxisMark.hpp
${CMAKE_CURRENT_SOURCE_DIR}/RPythonConsoleDockWidget.hpp
${CMAKE_CURRENT_SOURCE_DIR}/RStaticMesh.hpp
Expand All @@ -17,7 +17,7 @@ set(MODMESH_VIEW_PYMODHEADERS

set(MODMESH_VIEW_PYMODSOURCES
${CMAKE_CURRENT_SOURCE_DIR}/R3DWidget.cpp
${CMAKE_CURRENT_SOURCE_DIR}/RApplication.cpp
${CMAKE_CURRENT_SOURCE_DIR}/RManager.cpp
${CMAKE_CURRENT_SOURCE_DIR}/RAxisMark.cpp
${CMAKE_CURRENT_SOURCE_DIR}/RPythonConsoleDockWidget.cpp
${CMAKE_CURRENT_SOURCE_DIR}/RStaticMesh.cpp
Expand Down
26 changes: 13 additions & 13 deletions cpp/modmesh/view/RApplication.cpp → cpp/modmesh/view/RManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/

#include <modmesh/view/RApplication.hpp> // Must be the first include.
#include <modmesh/view/RManager.hpp> // Must be the first include.

#include <vector>

Expand All @@ -40,13 +40,13 @@
namespace modmesh
{

RApplication & RApplication::instance()
RManager & RManager::instance()
{
static RApplication ret;
static RManager ret;
return ret;
}

RApplication::RApplication()
RManager::RManager()
: QObject()
{
m_core = QApplication::instance();
Expand All @@ -64,7 +64,7 @@ RApplication::RApplication()
// "exited with code -1073740791". The reason is not yet clarified.
}

RApplication & RApplication::setUp()
RManager & RManager::setUp()
{
if (!m_already_setup)
{
Expand All @@ -77,11 +77,11 @@ RApplication & RApplication::setUp()
return *this;
}

RApplication::~RApplication()
RManager::~RManager()
{
}

R3DWidget * RApplication::add3DWidget()
R3DWidget * RManager::add3DWidget()
{
R3DWidget * viewer = nullptr;
if (m_mdiArea)
Expand All @@ -95,22 +95,22 @@ R3DWidget * RApplication::add3DWidget()
return viewer;
}

void RApplication::setUpConsole()
void RManager::setUpConsole()
{
m_pycon = new RPythonConsoleDockWidget(QString("Console"), m_mainWindow);
m_pycon->setAllowedAreas(Qt::AllDockWidgetAreas);
m_mainWindow->addDockWidget(Qt::BottomDockWidgetArea, m_pycon);
}

void RApplication::setUpCentral()
void RManager::setUpCentral()
{
m_mdiArea = new QMdiArea(m_mainWindow);
m_mdiArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
m_mdiArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
m_mainWindow->setCentralWidget(m_mdiArea);
}

void RApplication::setUpMenu()
void RManager::setUpMenu()
{
m_mainWindow->setMenuBar(new QMenuBar(nullptr));
// NOTE: All menus need to be populated or Windows may crash with
Expand Down Expand Up @@ -140,7 +140,7 @@ void RApplication::setUpMenu()
QString("Exit the application"),
[]()
{
RApplication::instance().quit();
RManager::instance().quit();
});
m_fileMenu->addAction(action);
}
Expand Down Expand Up @@ -187,7 +187,7 @@ void RApplication::setUpMenu()
}
}

void RApplication::clearApplications()
void RManager::clearApplications()
{
for (QAction * a : this->m_appMenu->actions())
{
Expand All @@ -199,7 +199,7 @@ void RApplication::clearApplications()
}
}

void RApplication::addApplication(QString const & name)
void RManager::addApplication(QString const & name)
{
m_appMenu->addAction(new RAppAction(
QString("Load ") + name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,29 +43,31 @@
namespace modmesh
{

class RApplication
class RManager
: public QObject
{
Q_OBJECT

public:

~RApplication() override;
~RManager() override;

RApplication & setUp();
RManager & setUp();

static RApplication & instance();
static RManager & instance();

QCoreApplication * core() { return m_core; }

R3DWidget * add3DWidget();

RPythonConsoleDockWidget * pycon() { return m_pycon; }

QMainWindow * mainWindow() { return m_mainWindow; }

template <typename... Args>
QMdiSubWindow * addSubWindow(Args &&... args);

QMainWindow * mainWindow() { return m_mainWindow; }
void quit() { m_core->quit(); }

public slots:

Expand All @@ -74,7 +76,7 @@ public slots:

private:

RApplication();
RManager();

void setUpConsole();
void setUpCentral();
Expand All @@ -92,10 +94,10 @@ public slots:

RPythonConsoleDockWidget * m_pycon = nullptr;
QMdiArea * m_mdiArea = nullptr;
}; /* end class RApplication */
}; /* end class RManager */

template <typename... Args>
QMdiSubWindow * RApplication::addSubWindow(Args &&... args)
QMdiSubWindow * RManager::addSubWindow(Args &&... args)
{
QMdiSubWindow * subwin = nullptr;
if (m_mdiArea)
Expand Down
2 changes: 1 addition & 1 deletion cpp/modmesh/view/view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include <modmesh/view/common_detail.hpp> // Must be the first include.

#include <modmesh/view/R3DWidget.hpp>
#include <modmesh/view/RApplication.hpp>
#include <modmesh/view/RManager.hpp>
#include <modmesh/view/RPythonConsoleDockWidget.hpp>
#include <modmesh/view/RStaticMesh.hpp>
#include <modmesh/view/RAxisMark.hpp>
Expand Down
32 changes: 16 additions & 16 deletions cpp/modmesh/view/wrap_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,13 +308,13 @@ class MODMESH_PYTHON_WRAPPER_VISIBILITY WrapRPythonConsoleDockWidget

}; /* end class WrapRPythonConsoleDockWidget */

class MODMESH_PYTHON_WRAPPER_VISIBILITY WrapRApplication
: public WrapBase<WrapRApplication, RApplication>
class MODMESH_PYTHON_WRAPPER_VISIBILITY WrapRManager
: public WrapBase<WrapRManager, RManager>
{

friend root_base_type;

WrapRApplication(pybind11::module & mod, char const * pyname, char const * pydoc)
WrapRManager(pybind11::module & mod, char const * pyname, char const * pydoc)
: root_base_type(mod, pyname, pydoc)
{

Expand All @@ -325,15 +325,15 @@ class MODMESH_PYTHON_WRAPPER_VISIBILITY WrapRApplication
"instance",
[](py::object const &) -> wrapped_type &
{
return RApplication::instance();
return RManager::instance();
})
.def_property_readonly_static(
"core",
[](py::object const &) -> QCoreApplication *
{
return RApplication::instance().core();
return RManager::instance().core();
})
.def("setUp", &RApplication::setUp)
.def("setUp", &RManager::setUp)
.def(
"exec",
[](wrapped_type & self)
Expand Down Expand Up @@ -441,19 +441,19 @@ class MODMESH_PYTHON_WRAPPER_VISIBILITY WrapRApplication
return *this;
}

}; /* end class WrapRApplication */
}; /* end class WrapRManager */

struct RApplicationProxy
struct RManagerProxy
{
};

class MODMESH_PYTHON_WRAPPER_VISIBILITY WrapRApplicationProxy
: public WrapBase<WrapRApplicationProxy, RApplicationProxy>
class MODMESH_PYTHON_WRAPPER_VISIBILITY WrapRManagerProxy
: public WrapBase<WrapRManagerProxy, RManagerProxy>
{

friend root_base_type;

WrapRApplicationProxy(pybind11::module & mod, char const * pyname, char const * pydoc)
WrapRManagerProxy(pybind11::module & mod, char const * pyname, char const * pydoc)
: root_base_type(mod, pyname, pydoc)
{
namespace py = pybind11;
Expand All @@ -463,15 +463,15 @@ class MODMESH_PYTHON_WRAPPER_VISIBILITY WrapRApplicationProxy
"__getattr__",
[](wrapped_type &, char const * name)
{
py::object obj = py::cast(RApplication::instance());
py::object obj = py::cast(RManager::instance());
obj = obj.attr(name);
return obj;
})
//
;
}

}; /* end class WrapRApplicationProxy */
}; /* end class WrapRManagerProxy */

void wrap_view(pybind11::module & mod)
{
Expand All @@ -480,10 +480,10 @@ void wrap_view(pybind11::module & mod)
WrapR3DWidget::commit(mod, "R3DWidget", "R3DWidget");
WrapRLine::commit(mod, "RLine", "RLine");
WrapRPythonConsoleDockWidget::commit(mod, "RPythonConsoleDockWidget", "RPythonConsoleDockWidget");
WrapRApplication::commit(mod, "RApplication", "RApplication");
WrapRApplicationProxy::commit(mod, "RApplicationProxy", "RApplicationProxy");
WrapRManager::commit(mod, "RManager", "RManager");
WrapRManagerProxy::commit(mod, "RManagerProxy", "RManagerProxy");

mod.attr("app") = RApplicationProxy();
mod.attr("mgr") = RManagerProxy();
}

struct view_pymod_tag;
Expand Down
2 changes: 1 addition & 1 deletion modmesh/app/bad_euler1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

def load_app():
cmd = "win, svr = mm.app.bad_euler1d.run(animate=True, interval=10)"
view.app.pycon.command = cmd
view.mgr.pycon.command = cmd


class ApplicationWindow(QtWidgets.QMainWindow):
Expand Down
10 changes: 5 additions & 5 deletions modmesh/app/euler1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@


def load_app():
view.app.pycon.writeToHistory("""
view.mgr.pycon.writeToHistory("""
# Use the functions for more examples:
ctrl.start() # Start the movie
ctrl.step() # Stepping the solution
""")
cmd = "ctrl = mm.app.euler1d.run(interval=10, max_steps=50)"
view.app.pycon.command = cmd
view.mgr.pycon.command = cmd


@dataclass
Expand Down Expand Up @@ -120,7 +120,7 @@ def __init__(self, shocktube, max_steps, use_sub=None):
# It is probably because RMainWindow is not recognized by PySide6
# and matplotlib. We may consider to use composite for QMainWindow
# instead of inheritance.
self._subwin = view.app.addSubWindow(self._main)
self._subwin = view.mgr.addSubWindow(self._main)
self._subwin.resize(400, 300)

self.plt = Plot(figsize=(15, 10))
Expand Down Expand Up @@ -171,8 +171,8 @@ def setup_solver(self, interval):
def log(msg):
sys.stdout.write(msg)
sys.stdout.write('\n')
view.app.pycon.writeToHistory(msg)
view.app.pycon.writeToHistory('\n')
view.mgr.pycon.writeToHistory(msg)
view.mgr.pycon.writeToHistory('\n')


def run(interval=10, max_steps=50, **kw):
Expand Down
2 changes: 1 addition & 1 deletion modmesh/app/linear_wave.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

def load_app():
cmd = "win, svr = mm.app.linear_wave.run_linear(animate=True, interval=10)"
view.app.pycon.command = cmd
view.mgr.pycon.command = cmd


class ApplicationWindow(QtWidgets.QMainWindow):
Expand Down
18 changes: 9 additions & 9 deletions modmesh/app/sample_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ def help_tri(set_command=False):
w_tri.showMark()
print("tri nedge:", mh_tri.nedge)
"""
view.app.pycon.writeToHistory(cmd)
view.mgr.pycon.writeToHistory(cmd)
if set_command:
view.app.pycon.command = cmd.strip()
view.mgr.pycon.command = cmd.strip()


def help_tet(set_command=False):
Expand All @@ -57,9 +57,9 @@ def help_tet(set_command=False):
w_tet.showMark()
print("tet nedge:", mh_tet.nedge)
"""
view.app.pycon.writeToHistory(cmd)
view.mgr.pycon.writeToHistory(cmd)
if set_command:
view.app.pycon.command = cmd.strip()
view.mgr.pycon.command = cmd.strip()


def help_other(set_command=False):
Expand All @@ -78,9 +78,9 @@ def help_other(set_command=False):
# line = mm.view.RLine(-1, -1, -1, -2, -2, -2, 0, 128, 128)
# print(line)
"""
view.app.pycon.writeToHistory(cmd)
view.mgr.pycon.writeToHistory(cmd)
if set_command:
view.app.pycon.command = cmd.strip()
view.mgr.pycon.command = cmd.strip()


def make_triangle():
Expand Down Expand Up @@ -113,7 +113,7 @@ def load_app():
'help_other',
'make_triangle',
'make_tetrahedron',
('add3DWidget', view.app.add3DWidget),
('add3DWidget', view.mgr.add3DWidget),
)
for k in symbols:
if isinstance(k, tuple):
Expand All @@ -122,9 +122,9 @@ def load_app():
o = globals().get(k, None)
if o is None:
o = locals().get(k, None)
view.app.pycon.writeToHistory(f"Adding symbol {k}\n")
view.mgr.pycon.writeToHistory(f"Adding symbol {k}\n")
aenv.globals[k] = o
view.app.pycon.writeToHistory("""
view.mgr.pycon.writeToHistory("""
# Use the functions for more examples:
help_tri(set_command=False) # or True
help_tet(set_command=False) # or True
Expand Down
Loading

0 comments on commit 2b7945f

Please sign in to comment.