Skip to content

Commit

Permalink
Create a GeneralTab class
Browse files Browse the repository at this point in the history
  • Loading branch information
MBartkowiakSTFC committed Jan 24, 2024
1 parent 2dddcc7 commit a7d400c
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 1 deletion.
66 changes: 66 additions & 0 deletions MDANSE_GUI/Src/MDANSE_GUI/PyQtGUI/Tabs/GeneralTab.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
from qtpy.QtCore import QObject, Slot, Signal


# **************************************************************************
#
# MDANSE: Molecular Dynamics Analysis for Neutron Scattering Experiments
#
# @file Src/PyQtGUI/RegistryViewer.py
# @brief Shows the MDANSE jobs. Can run standalone.
#
# @homepage https://mdanse.org
# @license GNU General Public License v3 or higher (see LICENSE)
# @copyright Institut Laue Langevin 2013-now
# @copyright ISIS Neutron and Muon Source, STFC, UKRI 2021-now
# @authors Scientific Computing Group at ILL (see AUTHORS)
#
# **************************************************************************

import os

from qtpy.QtCore import QObject, Slot, Signal
from qtpy.QtWidgets import QListView

from MDANSE.Framework.Jobs.IJob import IJob

from MDANSE_GUI.PyQtGUI.Tabs.Layouts.DoublePanel import DoublePanel
from MDANSE_GUI.PyQtGUI.Session.LocalSession import LocalSession
from MDANSE_GUI.PyQtGUI.Tabs.Settings import LocalSettings
from MDANSE_GUI.PyQtGUI.Tabs.Visualisers.TextInfo import TextInfo


class GeneralTab(QObject):
"""This object connects different elements of a GUI tab,
such as the data model, view, visualised, layout,
session, settings and project, all of them relevant
to the MDANSE_GUI design.
The idea of tying the well-defined GUI elements into
a fairly abstract concept of a 'general tab' is intended
to give the programmers enough flexibility to change the
behaviour of GUI sections while keeping the common API
for accessing them from the outside.
"""

def __init__(self, *args, **kwargs):
self._name = kwargs.pop("mdanse_name", "Unnamed GUI part")
self._session = kwargs.pop("session", LocalSession())
self._settings = kwargs.pop("settings", LocalSettings())
self._model = kwargs.pop("model", None)
self._visualiser = kwargs.pop("visualiser", TextInfo())
self._view = kwargs.pop("view", QListView())
layout = kwargs.pop("layout", DoublePanel)
label_text = kwargs.pop("label_text", "An abstract GUI element")
super().__init__(*args, **kwargs)
self._core = layout(
{"data_side": self._view, "visualiser_side": self._visualiser}
)
self._core.set_model(self._model)
self._core.set_label_text(label_text)

@Slot()
def save_state(self):
self._session.save_state(self)

def load_state(self):
self._session.load_state(self)
10 changes: 10 additions & 0 deletions MDANSE_GUI/Src/MDANSE_GUI/PyQtGUI/Tabs/Settings/LocalSettings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class LocalSettings:
def __init__(self, *args, **kwargs):
self._settings = {}

def get(self, key: str):
temp = self._settings.get(key, None)
return temp

def set(self, key: str, value: str):
self._settings[key] = value
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from qtpy.QtWidgets import QPushButton, QTextEdit, QWidget, QFileDialog


class TrajectoryInfo(QTextEdit):
class TextInfo(QTextEdit):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

Expand Down

0 comments on commit a7d400c

Please sign in to comment.