File qt_gui/qt_dicebox.py changed (mode: 100644) (index 9639b40..2db43f3) |
1 |
1 |
import sys |
import sys |
2 |
2 |
import numpy as np |
import numpy as np |
3 |
3 |
from .. import schemes |
from .. import schemes |
4 |
|
from ..dicebox import Goal, DiceBox |
|
|
4 |
|
from ..dicebox import Goal, Razitko, DiceBox |
5 |
5 |
import pyqtgraph as pg |
import pyqtgraph as pg |
6 |
6 |
from pyqtgraph.Qt import QtGui, QtCore, QtWidgets |
from pyqtgraph.Qt import QtGui, QtCore, QtWidgets |
7 |
7 |
|
|
8 |
8 |
spaces = ['R', 'aR', 'Rn', 'aRn', 'P', 'GK', 'G', 'aG', 'U', 'aU'] |
spaces = ['R', 'aR', 'Rn', 'aRn', 'P', 'GK', 'G', 'aG', 'U', 'aU'] |
|
9 |
|
potentials = ['q_psee', 'psee', 'fee', 'fee2', 'ksee', 'chee', 'chee2', 'dd'] |
9 |
10 |
|
|
10 |
11 |
class DumbDiceBoxWidget(QtWidgets.QWidget): |
class DumbDiceBoxWidget(QtWidgets.QWidget): |
11 |
12 |
def __init__(self, wt, parent=None): |
def __init__(self, wt, parent=None): |
|
... |
... |
class DumbDiceBoxWidget(QtWidgets.QWidget): |
16 |
17 |
# do the thing |
# do the thing |
17 |
18 |
self.box.sample_box = DiceBox(self.box.sample_box) |
self.box.sample_box = DiceBox(self.box.sample_box) |
18 |
19 |
|
|
|
20 |
|
|
|
21 |
|
class RazitkoWidget(pg.parametertree.ParameterTree): |
|
22 |
|
def __init__(self, wt, parent=None): |
|
23 |
|
self.box = wt |
|
24 |
|
super().__init__(parent=parent, showHeader=False) |
|
25 |
|
self._set_param() |
|
26 |
|
self.setParameters(self.param, showTop=False) |
|
27 |
|
|
|
28 |
|
def _set_param(self): |
|
29 |
|
params = list() |
|
30 |
|
tschemes = schemes.get_tn_keys(self.box.nvar) |
|
31 |
|
params.append({'name': 'scheme', 'type': 'list', \ |
|
32 |
|
'title': "cubature scheme", \ |
|
33 |
|
'values': tschemes, 'value': tschemes[0]}) |
|
34 |
|
params.append({'name': 'degree', 'type': 'int', \ |
|
35 |
|
'title': "degree",\ |
|
36 |
|
'limits': (0, float('inf')), 'value': 5, 'default': 5,\ |
|
37 |
|
'tip': "Used only with Grundmann-Möller and Silvester cubaturas"}) |
|
38 |
|
|
|
39 |
|
params.append({'name': 'tri_space', 'type': 'list', 'value': 'G', \ |
|
40 |
|
'title': "triangulation space", 'values': spaces}) |
|
41 |
|
params.append({'name': 'tree_space', 'type': 'list', 'value': 'None', \ |
|
42 |
|
'title': "tree (potential) space", 'values': spaces+['None'], \ |
|
43 |
|
'tip': """Space where distances (and densities) are |
|
44 |
|
calculated. 'None' means triangulation space will be used"""}) |
|
45 |
|
params.append({'name': 'sampling_space', 'type': 'list', 'value': 'None', \ |
|
46 |
|
'title': "sampling space", 'values': spaces+['None'], \ |
|
47 |
|
'tip': """Space where convex hull is being integrated. |
|
48 |
|
'None' means triangulation space will be used"""}) |
|
49 |
|
params.append({'name': 'kechato_space', 'type': 'list', 'value': 'U', \ |
|
50 |
|
'title': "kechato space", 'values': spaces, \ |
|
51 |
|
'tip': "Only used with ksee potential"}) |
|
52 |
|
params.append({'name': 'potential', 'type': 'list', 'value': 'q_psee', \ |
|
53 |
|
'title': "potential", \ |
|
54 |
|
'values': potentials}) |
|
55 |
|
q = np.log(self.box.nvar) / self.box.nvar**2 |
|
56 |
|
params.append({'name': 'q', 'type': 'float', \ |
|
57 |
|
'title': "q", \ |
|
58 |
|
'limits': (0, 1), 'value': q, 'default': q,\ |
|
59 |
|
'tip': "Only used with q_psee potential"}) |
|
60 |
|
params.append({'name': 'p_norm', 'type': 'float', \ |
|
61 |
|
'title': "p norm", \ |
|
62 |
|
'limits': (1, float('inf')), 'value': 2, 'default': np.inf, |
|
63 |
|
'tip': "Space metric - used for distance calculations"}) |
|
64 |
|
params.append({'name': 'budget', 'type': 'int', \ |
|
65 |
|
'title': "Shull budget", \ |
|
66 |
|
'limits': (1, float('inf')), 'value': 1000, 'default': 1000,\ |
|
67 |
|
'tip': "Number of nodes for outside integration"}) |
|
68 |
|
params.append({'name': 'LHS_correction', \ |
|
69 |
|
'title': "LHS-like nodes placement",\ |
|
70 |
|
'type': 'bool', 'value': False }) |
|
71 |
|
|
|
72 |
|
### Create tree of Parameter objects |
|
73 |
|
# I don't know why that signals do not work for me |
|
74 |
|
# Only sigTreeStateChanged works, but I don't want to struggle with it |
|
75 |
|
# May be I'll report the issue |
|
76 |
|
#self.param.sigValueChanged.connect(self.param_changed) |
|
77 |
|
#self.param.sigValueChanging.connect(self.param_changing) |
|
78 |
|
self.param = pg.parametertree.Parameter.create(name='params', type='group', children=params) |
|
79 |
|
|
|
80 |
|
#č branima sa rekurzii |
|
81 |
|
#оӵ рекурзилы пезьдэт! |
|
82 |
|
self.param_values = self.param.getValues() |
|
83 |
|
|
|
84 |
|
def __getattr__(self, attr): |
|
85 |
|
#č na teoreticky možnou rěkurziju vykašleme |
|
86 |
|
#оӵ рекурзия уз луы |
|
87 |
|
return self.param_values[attr][0] |
|
88 |
|
|
|
89 |
|
def setup_box(self): |
|
90 |
|
#č to je důležité! __getatr__ odsaď bere hodnoty |
|
91 |
|
self.param_values = self.param.getValues() |
|
92 |
|
|
|
93 |
|
scheme = schemes.get_tn_scheme(self.scheme, self.box.nvar, self.degree) |
|
94 |
|
|
|
95 |
|
if self.tree_space == 'None': |
|
96 |
|
tree_space = None |
|
97 |
|
else: |
|
98 |
|
tree_space = self.tree_space |
|
99 |
|
|
|
100 |
|
if self.sampling_space == 'None': |
|
101 |
|
sampling_space = None |
|
102 |
|
else: |
|
103 |
|
sampling_space = self.sampling_space |
|
104 |
|
|
|
105 |
|
# try: |
|
106 |
|
# stm_filename = self.box.filename + '_stm' |
|
107 |
|
# except AttributeError: |
|
108 |
|
# stm_filename = None |
|
109 |
|
|
|
110 |
|
# do the thing |
|
111 |
|
self.box.sample_box = Razitko( |
|
112 |
|
self.box.sample_box, #č rekurze) |
|
113 |
|
scheme, |
|
114 |
|
tri_space=self.tri_space, |
|
115 |
|
tree_space=tree_space, |
|
116 |
|
sampling_space=sampling_space, |
|
117 |
|
kechato_space=self.kechato_space, |
|
118 |
|
potential=self.potential, |
|
119 |
|
q=self.q, |
|
120 |
|
p_norm=self.p_norm, |
|
121 |
|
budget=self.budget, |
|
122 |
|
LHS_correction=self.LHS_correction, |
|
123 |
|
#stm_filename=stm_filename, |
|
124 |
|
design=None |
|
125 |
|
) |
|
126 |
|
|
|
127 |
|
|
|
128 |
|
|
|
129 |
|
|
19 |
130 |
class GoalWidget(pg.parametertree.ParameterTree): |
class GoalWidget(pg.parametertree.ParameterTree): |
20 |
131 |
def __init__(self, wt, parent=None): |
def __init__(self, wt, parent=None): |
21 |
132 |
self.box = wt |
self.box = wt |
|
... |
... |
class GoalWidget(pg.parametertree.ParameterTree): |
45 |
156 |
'tip': "Only used with ksee potential"}) |
'tip': "Only used with ksee potential"}) |
46 |
157 |
params.append({'name': 'potential', 'type': 'list', 'value': 'q_psee', \ |
params.append({'name': 'potential', 'type': 'list', 'value': 'q_psee', \ |
47 |
158 |
'title': "potential", \ |
'title': "potential", \ |
48 |
|
'values': ['q_psee', 'psee', 'fee', 'fee2', 'ksee', 'chee', 'chee2', 'dd']}) |
|
|
159 |
|
'values': potentials}) |
49 |
160 |
q = np.log(self.box.nvar) / self.box.nvar**2 |
q = np.log(self.box.nvar) / self.box.nvar**2 |
50 |
161 |
params.append({'name': 'q', 'type': 'float', \ |
params.append({'name': 'q', 'type': 'float', \ |
51 |
162 |
'title': "q", \ |
'title': "q", \ |
|
... |
... |
class SetupDiceBoxWidget(pg.LayoutWidget): |
138 |
249 |
self.setWindowTitle("Set up sequential algorithm") |
self.setWindowTitle("Set up sequential algorithm") |
139 |
250 |
|
|
140 |
251 |
self.setup_tabs() |
self.setup_tabs() |
141 |
|
self.addWidget(self.tabs, row=0, col=0, rowspan=1, colspan=2) |
|
|
252 |
|
self.addWidget(self.tab_widget, row=0, col=0, rowspan=1, colspan=2) |
142 |
253 |
|
|
143 |
254 |
self.btn_skip = QtGui.QPushButton('Skip') |
self.btn_skip = QtGui.QPushButton('Skip') |
144 |
255 |
self.addWidget(self.btn_skip, row=1, col=0) |
self.addWidget(self.btn_skip, row=1, col=0) |
|
... |
... |
class SetupDiceBoxWidget(pg.LayoutWidget): |
152 |
263 |
self.app.quit() |
self.app.quit() |
153 |
264 |
|
|
154 |
265 |
def create(self): |
def create(self): |
155 |
|
tab_index = self.tabs.currentIndex() |
|
156 |
|
if tab_index == 0: |
|
157 |
|
self.goal.setup_box() |
|
158 |
|
elif tab_index == 1: |
|
159 |
|
self.dice_box.setup_box() |
|
160 |
|
else: |
|
161 |
|
raise |
|
|
266 |
|
tab_index = self.tab_widget.currentIndex() |
|
267 |
|
self.tabs[tab_index].setup_box() |
162 |
268 |
self.app.quit() |
self.app.quit() |
163 |
269 |
|
|
164 |
270 |
def setup_tabs(self): |
def setup_tabs(self): |
165 |
271 |
# Initialize tab screen |
# Initialize tab screen |
166 |
|
self.tabs = QtWidgets.QTabWidget(self) |
|
|
272 |
|
self.tab_widget = QtWidgets.QTabWidget(self) |
|
273 |
|
#č šlo by to, samozřejmně, i přes Qt |
|
274 |
|
#č ale stejně musíme reference explicitně ukladat |
|
275 |
|
#č aby je nám Python nehodil |
|
276 |
|
self.tabs = [] |
167 |
277 |
|
|
168 |
|
# Add tabs |
|
169 |
|
self.goal = GoalWidget(self.box, self) |
|
170 |
|
self.tabs.addTab(self.goal, "Goal") |
|
|
278 |
|
# Add tab |
|
279 |
|
box_widget = GoalWidget(self.box, self) |
|
280 |
|
self.tab_widget.addTab(box_widget, "Goal") |
|
281 |
|
self.tabs.append(box_widget) |
171 |
282 |
|
|
172 |
|
# Add tabs |
|
173 |
|
self.dice_box = DumbDiceBoxWidget(self.box, self) |
|
174 |
|
self.tabs.addTab(self.dice_box, "Dumb DiceBox") |
|
|
283 |
|
# Add tab |
|
284 |
|
box_widget = RazitkoWidget(self.box, self) |
|
285 |
|
self.tab_widget.addTab(box_widget, "Razitko") |
|
286 |
|
self.tabs.append(box_widget) |
175 |
287 |
|
|
176 |
|
#self.tab_2d = TestCasesListWidget(testcases_2D, self) |
|
177 |
|
#self.tabs.addTab(self.tab_2d,"2D testcases") |
|
|
288 |
|
# Add tab |
|
289 |
|
box_widget = DumbDiceBoxWidget(self.box, self) |
|
290 |
|
self.tab_widget.addTab(box_widget, "Dumb DiceBox") |
|
291 |
|
self.tabs.append(box_widget) |
178 |
292 |
|
|
179 |
293 |
|
|