forked from npshub/mantid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
context_example_widget.py
52 lines (43 loc) · 1.77 KB
/
context_example_widget.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# Mantid Repository : https://github.com/mantidproject/mantid
#
# Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
# NScD Oak Ridge National Laboratory, European Spallation Source,
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 +
from Muon.GUI.Common.context_example.context_example_view import ContextExampleView
from Muon.GUI.Common.context_example.context_example_presenter import ContextExamplePresenter
from Muon.GUI.Common.context_example.context_example_model import ContextExampleModel
class ContextExampleWidget(object):
"""
An example of how to use the context with a widget class.
The widget class exposes the MVP to the rest of the GUI
"""
def __init__(self, context, parent=None):
model = ContextExampleModel(context)
sub_context = model.getSubContext()
view = ContextExampleView(sub_context, parent)
self._presenter = ContextExamplePresenter(view, model)
@property
def presenter(self):
return self._presenter
@property
def widget(self):
return self._presenter.widget
# interact with context
def setUpdateContext(self, slot):
"""
This function is to set the update
method from the main GUI to the signals
from this GUI
"""
view = self._presenter.widget
view.updateSignal.connect(slot)
def updateContext(self):
self._presenter.updateContext()
def loadFromContext(self):
# extract relevant info from context via model
model = self._presenter.model
sub_context = model.getSubContext()
# update the view with the subcontext
view = self._presenter.widget
view.loadFromContext(sub_context)