File qt_gui/qt_dicebox.py changed (mode: 100644) (index af6121d..ddb43bb) |
1 |
1 |
import sys |
import sys |
2 |
2 |
import numpy as np |
import numpy as np |
|
3 |
|
from .. import schemes |
3 |
4 |
from ..dicebox import Goal |
from ..dicebox import Goal |
4 |
5 |
import pyqtgraph as pg |
import pyqtgraph as pg |
5 |
6 |
from pyqtgraph.Qt import QtGui, QtCore, QtWidgets |
from pyqtgraph.Qt import QtGui, QtCore, QtWidgets |
|
... |
... |
from pyqtgraph.Qt import QtGui, QtCore, QtWidgets |
7 |
8 |
spaces = ['R', 'aR', 'Rn', 'aRn', 'P', 'GK', 'G', 'aG', 'U', 'aU'] |
spaces = ['R', 'aR', 'Rn', 'aRn', 'P', 'GK', 'G', 'aG', 'U', 'aU'] |
8 |
9 |
|
|
9 |
10 |
class GoalWidget(pg.parametertree.ParameterTree): |
class GoalWidget(pg.parametertree.ParameterTree): |
10 |
|
def __init__(self, wt, parent=None): |
|
|
11 |
|
def __init__(self, wt, parent=None): |
11 |
12 |
self.box = wt |
self.box = wt |
12 |
13 |
super().__init__(parent=parent, showHeader=False) |
super().__init__(parent=parent, showHeader=False) |
13 |
14 |
self._set_param() |
self._set_param() |
14 |
15 |
self.setParameters(self.param, showTop=False) |
self.setParameters(self.param, showTop=False) |
15 |
|
|
|
|
16 |
|
|
16 |
17 |
def _set_param(self): |
def _set_param(self): |
17 |
18 |
params = list() |
params = list() |
18 |
|
if self.box.nvar < 6: |
|
19 |
|
self.schemes = |
|
20 |
|
params.append({'name': 'scheme', 'type': 'list', \ |
|
21 |
|
'values': schemes, 'value': schemes[0]}) |
|
22 |
|
|
|
|
19 |
|
tschemes = schemes.get_tn_keys(self.box.nvar) |
|
20 |
|
params.append({'name': 'scheme', 'type': 'list', \ |
|
21 |
|
'title': "cubature scheme", \ |
|
22 |
|
'values': tschemes, 'value': tschemes[0]}) |
|
23 |
|
params.append({'name': 'degree', 'type': 'int', \ |
|
24 |
|
'title': "degree",\ |
|
25 |
|
'limits': (1, float('inf')), 'value': 5, 'default': 5,\ |
|
26 |
|
'tip': "Used only with Grundmann-Möller and Silvester cubaturas"}) |
23 |
27 |
|
|
24 |
28 |
params.append({'name': 'tri_space', 'type': 'list', 'value': 'G', \ |
params.append({'name': 'tri_space', 'type': 'list', 'value': 'G', \ |
25 |
|
'title': "triangulation space", 'values': spaces}) |
|
26 |
|
params.append({'name': 'tree_space', 'type': 'list', 'value': 'G', \ |
|
27 |
|
'title': "potential space", 'values': spaces+['None'], \ |
|
|
29 |
|
'title': "triangulation space", 'values': spaces}) |
|
30 |
|
params.append({'name': 'tree_space', 'type': 'list', 'value': 'None', \ |
|
31 |
|
'title': "potential space", 'values': spaces+['None'], \ |
28 |
32 |
'tip': """Space where distances (and densities) are |
'tip': """Space where distances (and densities) are |
29 |
33 |
calculated. 'None' means triangulation space will be used"""}) |
calculated. 'None' means triangulation space will be used"""}) |
30 |
34 |
params.append({'name': 'kechato_space', 'type': 'list', 'value': 'U', \ |
params.append({'name': 'kechato_space', 'type': 'list', 'value': 'U', \ |
31 |
|
'title': "kechato space", 'values': spaces, \ |
|
|
35 |
|
'title': "kechato space", 'values': spaces, \ |
32 |
36 |
'tip': "Only used with ksee potential"}) |
'tip': "Only used with ksee potential"}) |
33 |
|
params.append({'name': 'potential', 'type': 'list', 'value': 'q_psee', \ |
|
34 |
|
'title': "potential", \ |
|
35 |
|
'values': ['q_psee', 'psee', 'fee', 'fee2' 'ksee', 'dd']}) |
|
36 |
|
q = np.log(self.box.nvar) / self.box.nvar**2 |
|
37 |
|
params.append({'name': 'q', 'type': 'float', \ |
|
|
37 |
|
params.append({'name': 'potential', 'type': 'list', 'value': 'q_psee', \ |
|
38 |
|
'title': "potential", \ |
|
39 |
|
'values': ['q_psee', 'psee', 'fee', 'fee2' 'ksee', 'dd']}) |
|
40 |
|
q = np.log(self.box.nvar) / self.box.nvar**2 |
|
41 |
|
params.append({'name': 'q', 'type': 'float', \ |
38 |
42 |
'title': "q", \ |
'title': "q", \ |
39 |
43 |
'limits': (0, 1), 'value': q, 'default': q,\ |
'limits': (0, 1), 'value': q, 'default': q,\ |
40 |
44 |
'tip': "Only used with q_psee potential"}) |
'tip': "Only used with q_psee potential"}) |
41 |
45 |
params.append({'name': 'p_norm', 'type': 'float', \ |
params.append({'name': 'p_norm', 'type': 'float', \ |
42 |
46 |
'title': "p norm", \ |
'title': "p norm", \ |
43 |
|
'limits': (0, 1), 'value': q, 'default': q,\ |
|
|
47 |
|
'limits': (1, float('inf')), 'value': 2, 'default': np.inf, |
44 |
48 |
'tip': "Space metric - used for distance calculations"}) |
'tip': "Space metric - used for distance calculations"}) |
45 |
|
|
|
46 |
49 |
params.append({'name': 'shell_budget', 'type': 'int', \ |
params.append({'name': 'shell_budget', 'type': 'int', \ |
47 |
|
'title': "shell budget" \ |
|
|
50 |
|
'title': "shell budget", \ |
48 |
51 |
'limits': (1, float('inf')), 'value': 1000, 'default': 1000,\ |
'limits': (1, float('inf')), 'value': 1000, 'default': 1000,\ |
49 |
52 |
'tip': "Number of annulus candidates"}) |
'tip': "Number of annulus candidates"}) |
50 |
53 |
|
|
51 |
54 |
params.append({'name': 'outer_budget', 'type': 'int', \ |
params.append({'name': 'outer_budget', 'type': 'int', \ |
52 |
|
'title': "Outer budget" \ |
|
|
55 |
|
'title': "Outer budget", \ |
53 |
56 |
'limits': (1, float('inf')), 'value': 100, 'default': 100,\ |
'limits': (1, float('inf')), 'value': 100, 'default': 100,\ |
54 |
57 |
'tip': "Number of candidates nodes outside of circumscribed d-ball"}) |
'tip': "Number of candidates nodes outside of circumscribed d-ball"}) |
55 |
58 |
|
|
56 |
|
params.append({'name': 'LHS_correction', 'title': "LHS-like placement",\ |
|
57 |
|
'type': 'bool', 'value': False }) |
|
|
59 |
|
params.append({'name': 'LHS_correction', \ |
|
60 |
|
'title': "LHS-like nodes placement",\ |
|
61 |
|
'type': 'bool', 'value': False }) |
58 |
62 |
|
|
59 |
63 |
### Create tree of Parameter objects |
### Create tree of Parameter objects |
60 |
64 |
# I don't know why that signals do not work for me |
# I don't know why that signals do not work for me |
|
... |
... |
class GoalWidget(pg.parametertree.ParameterTree): |
64 |
68 |
#self.param.sigValueChanging.connect(self.param_changing) |
#self.param.sigValueChanging.connect(self.param_changing) |
65 |
69 |
self.param = pg.parametertree.Parameter.create(name='params', type='group', children=params) |
self.param = pg.parametertree.Parameter.create(name='params', type='group', children=params) |
66 |
70 |
|
|
67 |
|
def extract_selected_item(self): |
|
68 |
|
item = self.currentItem() |
|
69 |
|
if item is None: |
|
70 |
|
return getattr(self.module, self.module.__all__[0])() |
|
|
71 |
|
#č branima sa rekurzii |
|
72 |
|
#оӵ рекурзилы пезьдэт! |
|
73 |
|
self.param_values = self.param.getValues() |
|
74 |
|
|
|
75 |
|
def __getattr__(self, attr): |
|
76 |
|
#č na teoreticky možnou rěkurziju vykašleme |
|
77 |
|
#оӵ рекурзия уз луы |
|
78 |
|
return self.param_values[attr][0] |
|
79 |
|
|
|
80 |
|
def setup_box(self): |
|
81 |
|
#č to je důležité! __getatr__ odsaď bere hodnoty |
|
82 |
|
self.param_values = self.param.getValues() |
|
83 |
|
|
|
84 |
|
scheme = schemes.get_tn_scheme(self.scheme, self.box.nvar, self.degree) |
|
85 |
|
|
|
86 |
|
if self.tree_space == 'None': |
|
87 |
|
tree_space = None |
71 |
88 |
else: |
else: |
72 |
|
item_str = self.currentItem().text() |
|
73 |
|
return getattr(self.module, item_str)() |
|
74 |
|
|
|
|
89 |
|
tree_space = self.tree_space |
|
90 |
|
|
|
91 |
|
try: |
|
92 |
|
stm_filename = self.box.filename + '_stm' |
|
93 |
|
except AttributeError: |
|
94 |
|
stm_filename = None |
|
95 |
|
|
|
96 |
|
# do the thing |
|
97 |
|
self.box.sample_box = Goal( |
|
98 |
|
self.box.sample_box, #č rekurze) |
|
99 |
|
scheme, |
|
100 |
|
tri_space=self.tri_space, |
|
101 |
|
tree_space=tree_space, |
|
102 |
|
kechato_space=self.kechato_space, |
|
103 |
|
potential=self.potential, |
|
104 |
|
q=self.q, |
|
105 |
|
p_norm=self.p_norm, |
|
106 |
|
shell_budget=self.shell_budget, |
|
107 |
|
outer_budget=self.outer_budget, |
|
108 |
|
LHS_correction=self.LHS_correction, |
|
109 |
|
stm_filename=stm_filename, |
|
110 |
|
) |
|
111 |
|
|
75 |
112 |
|
|
76 |
113 |
class SetupDiceBoxWidget(pg.LayoutWidget): |
class SetupDiceBoxWidget(pg.LayoutWidget): |
77 |
114 |
def __init__(self, wt, parent=None): |
def __init__(self, wt, parent=None): |
78 |
|
self.box = wt |
|
|
115 |
|
self.box = wt |
79 |
116 |
#č nejdřív vytvořiť apku |
#č nejdřív vytvořiť apku |
80 |
117 |
self.app = pg.mkQApp("WellMet") |
self.app = pg.mkQApp("WellMet") |
81 |
118 |
# |
# |
|
... |
... |
class SetupDiceBoxWidget(pg.LayoutWidget): |
102 |
139 |
self.addWidget(self.btn_choose, row=1, col=1) |
self.addWidget(self.btn_choose, row=1, col=1) |
103 |
140 |
self.btn_choose.clicked.connect(self.create) |
self.btn_choose.clicked.connect(self.create) |
104 |
141 |
|
|
105 |
|
def exit(self): |
|
|
142 |
|
def skip(self): |
106 |
143 |
self.app.quit() |
self.app.quit() |
107 |
|
sys.exit() |
|
108 |
144 |
|
|
109 |
145 |
def create(self): |
def create(self): |
110 |
146 |
tab_index = self.tabs.currentIndex() |
tab_index = self.tabs.currentIndex() |
111 |
147 |
if tab_index == 0: |
if tab_index == 0: |
112 |
|
self.box = self.tab_2d_papers.extract_selected_item() |
|
|
148 |
|
self.goal.setup_box() |
113 |
149 |
elif tab_index == 1: |
elif tab_index == 1: |
114 |
|
self.box = self.tab_2d.extract_selected_item() |
|
|
150 |
|
self.tab_2d.extract_selected_item() |
115 |
151 |
else: |
else: |
116 |
152 |
raise |
raise |
117 |
153 |
self.app.quit() |
self.app.quit() |
|
... |
... |
class SetupDiceBoxWidget(pg.LayoutWidget): |
121 |
157 |
self.tabs = QtWidgets.QTabWidget(self) |
self.tabs = QtWidgets.QTabWidget(self) |
122 |
158 |
|
|
123 |
159 |
# Add tabs |
# Add tabs |
124 |
|
self.tab_2d_papers = TestCasesListWidget(testcases_2D_papers, self) |
|
125 |
|
self.tabs.addTab(self.tab_2d_papers,"Well-known 2D testcases") |
|
|
160 |
|
self.goal = GoalWidget(self.box, self) |
|
161 |
|
self.tabs.addTab(self.goal,"Goal") |
126 |
162 |
|
|
127 |
|
self.tab_2d = TestCasesListWidget(testcases_2D, self) |
|
128 |
|
self.tabs.addTab(self.tab_2d,"2D testcases") |
|
|
163 |
|
#self.tab_2d = TestCasesListWidget(testcases_2D, self) |
|
164 |
|
#self.tabs.addTab(self.tab_2d,"2D testcases") |
129 |
165 |
|
|
130 |
166 |
|
|