File qt_gui/qt_dicebox.py added (mode: 100644) (index 0000000..af6121d) |
|
1 |
|
import sys |
|
2 |
|
import numpy as np |
|
3 |
|
from ..dicebox import Goal |
|
4 |
|
import pyqtgraph as pg |
|
5 |
|
from pyqtgraph.Qt import QtGui, QtCore, QtWidgets |
|
6 |
|
|
|
7 |
|
spaces = ['R', 'aR', 'Rn', 'aRn', 'P', 'GK', 'G', 'aG', 'U', 'aU'] |
|
8 |
|
|
|
9 |
|
class GoalWidget(pg.parametertree.ParameterTree): |
|
10 |
|
def __init__(self, wt, parent=None): |
|
11 |
|
self.box = wt |
|
12 |
|
super().__init__(parent=parent, showHeader=False) |
|
13 |
|
self._set_param() |
|
14 |
|
self.setParameters(self.param, showTop=False) |
|
15 |
|
|
|
16 |
|
def _set_param(self): |
|
17 |
|
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 |
|
|
|
23 |
|
|
|
24 |
|
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'], \ |
|
28 |
|
'tip': """Space where distances (and densities) are |
|
29 |
|
calculated. 'None' means triangulation space will be used"""}) |
|
30 |
|
params.append({'name': 'kechato_space', 'type': 'list', 'value': 'U', \ |
|
31 |
|
'title': "kechato space", 'values': spaces, \ |
|
32 |
|
'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', \ |
|
38 |
|
'title': "q", \ |
|
39 |
|
'limits': (0, 1), 'value': q, 'default': q,\ |
|
40 |
|
'tip': "Only used with q_psee potential"}) |
|
41 |
|
params.append({'name': 'p_norm', 'type': 'float', \ |
|
42 |
|
'title': "p norm", \ |
|
43 |
|
'limits': (0, 1), 'value': q, 'default': q,\ |
|
44 |
|
'tip': "Space metric - used for distance calculations"}) |
|
45 |
|
|
|
46 |
|
params.append({'name': 'shell_budget', 'type': 'int', \ |
|
47 |
|
'title': "shell budget" \ |
|
48 |
|
'limits': (1, float('inf')), 'value': 1000, 'default': 1000,\ |
|
49 |
|
'tip': "Number of annulus candidates"}) |
|
50 |
|
|
|
51 |
|
params.append({'name': 'outer_budget', 'type': 'int', \ |
|
52 |
|
'title': "Outer budget" \ |
|
53 |
|
'limits': (1, float('inf')), 'value': 100, 'default': 100,\ |
|
54 |
|
'tip': "Number of candidates nodes outside of circumscribed d-ball"}) |
|
55 |
|
|
|
56 |
|
params.append({'name': 'LHS_correction', 'title': "LHS-like placement",\ |
|
57 |
|
'type': 'bool', 'value': False }) |
|
58 |
|
|
|
59 |
|
### Create tree of Parameter objects |
|
60 |
|
# I don't know why that signals do not work for me |
|
61 |
|
# Only sigTreeStateChanged works, but I don't want to struggle with it |
|
62 |
|
# May be I'll report the issue |
|
63 |
|
#self.param.sigValueChanged.connect(self.param_changed) |
|
64 |
|
#self.param.sigValueChanging.connect(self.param_changing) |
|
65 |
|
self.param = pg.parametertree.Parameter.create(name='params', type='group', children=params) |
|
66 |
|
|
|
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 |
|
else: |
|
72 |
|
item_str = self.currentItem().text() |
|
73 |
|
return getattr(self.module, item_str)() |
|
74 |
|
|
|
75 |
|
|
|
76 |
|
class SetupDiceBoxWidget(pg.LayoutWidget): |
|
77 |
|
def __init__(self, wt, parent=None): |
|
78 |
|
self.box = wt |
|
79 |
|
#č nejdřív vytvořiť apku |
|
80 |
|
self.app = pg.mkQApp("WellMet") |
|
81 |
|
# |
|
82 |
|
super().__init__(parent) |
|
83 |
|
|
|
84 |
|
self.setup() |
|
85 |
|
|
|
86 |
|
#č zobraziť |
|
87 |
|
self.show() |
|
88 |
|
#č a spustit smyčku |
|
89 |
|
self.app.exec_() |
|
90 |
|
|
|
91 |
|
def setup(self): |
|
92 |
|
self.setWindowTitle("Set up sequential algorithm") |
|
93 |
|
|
|
94 |
|
self.setup_tabs() |
|
95 |
|
self.addWidget(self.tabs, row=0, col=0, rowspan=1, colspan=2) |
|
96 |
|
|
|
97 |
|
self.btn_skip = QtGui.QPushButton('Skip') |
|
98 |
|
self.addWidget(self.btn_skip, row=1, col=0) |
|
99 |
|
self.btn_skip.clicked.connect(self.skip) |
|
100 |
|
|
|
101 |
|
self.btn_choose = QtGui.QPushButton('Create') |
|
102 |
|
self.addWidget(self.btn_choose, row=1, col=1) |
|
103 |
|
self.btn_choose.clicked.connect(self.create) |
|
104 |
|
|
|
105 |
|
def exit(self): |
|
106 |
|
self.app.quit() |
|
107 |
|
sys.exit() |
|
108 |
|
|
|
109 |
|
def create(self): |
|
110 |
|
tab_index = self.tabs.currentIndex() |
|
111 |
|
if tab_index == 0: |
|
112 |
|
self.box = self.tab_2d_papers.extract_selected_item() |
|
113 |
|
elif tab_index == 1: |
|
114 |
|
self.box = self.tab_2d.extract_selected_item() |
|
115 |
|
else: |
|
116 |
|
raise |
|
117 |
|
self.app.quit() |
|
118 |
|
|
|
119 |
|
def setup_tabs(self): |
|
120 |
|
# Initialize tab screen |
|
121 |
|
self.tabs = QtWidgets.QTabWidget(self) |
|
122 |
|
|
|
123 |
|
# Add tabs |
|
124 |
|
self.tab_2d_papers = TestCasesListWidget(testcases_2D_papers, self) |
|
125 |
|
self.tabs.addTab(self.tab_2d_papers,"Well-known 2D testcases") |
|
126 |
|
|
|
127 |
|
self.tab_2d = TestCasesListWidget(testcases_2D, self) |
|
128 |
|
self.tabs.addTab(self.tab_2d,"2D testcases") |
|
129 |
|
|
|
130 |
|
|