import sys
import numpy as np
from .. import schemes
from ..dicebox import Goal, DiceBox
import pyqtgraph as pg
from pyqtgraph.Qt import QtGui, QtCore, QtWidgets
spaces = ['R', 'aR', 'Rn', 'aRn', 'P', 'GK', 'G', 'aG', 'U', 'aU']
class DumbDiceBoxWidget(QtWidgets.QWidget):
def __init__(self, wt, parent=None):
self.box = wt
super().__init__(parent=parent)
def setup_box(self):
# do the thing
self.box.sample_box = DiceBox(self.box.sample_box)
class GoalWidget(pg.parametertree.ParameterTree):
def __init__(self, wt, parent=None):
self.box = wt
super().__init__(parent=parent, showHeader=False)
self._set_param()
self.setParameters(self.param, showTop=False)
def _set_param(self):
params = list()
tschemes = schemes.get_tn_keys(self.box.nvar)
params.append({'name': 'scheme', 'type': 'list', \
'title': "cubature scheme", \
'values': tschemes, 'value': tschemes[0]})
params.append({'name': 'degree', 'type': 'int', \
'title': "degree",\
'limits': (0, float('inf')), 'value': 5, 'default': 5,\
'tip': "Used only with Grundmann-Möller and Silvester cubaturas"})
params.append({'name': 'tri_space', 'type': 'list', 'value': 'G', \
'title': "triangulation space", 'values': spaces})
params.append({'name': 'tree_space', 'type': 'list', 'value': 'None', \
'title': "tree (potential) space", 'values': spaces+['None'], \
'tip': """Space where distances (and densities) are
calculated. 'None' means triangulation space will be used"""})
params.append({'name': 'kechato_space', 'type': 'list', 'value': 'U', \
'title': "kechato space", 'values': spaces, \
'tip': "Only used with ksee potential"})
params.append({'name': 'potential', 'type': 'list', 'value': 'q_psee', \
'title': "potential", \
'values': ['q_psee', 'psee', 'fee', 'fee2', 'ksee', 'dd']})
q = np.log(self.box.nvar) / self.box.nvar**2
params.append({'name': 'q', 'type': 'float', \
'title': "q", \
'limits': (0, 1), 'value': q, 'default': q,\
'tip': "Only used with q_psee potential"})
params.append({'name': 'p_norm', 'type': 'float', \
'title': "p norm", \
'limits': (1, float('inf')), 'value': 2, 'default': np.inf,
'tip': "Space metric - used for distance calculations"})
params.append({'name': 'shell_budget', 'type': 'int', \
'title': "shell budget", \
'limits': (1, float('inf')), 'value': 1000, 'default': 1000,\
'tip': "Number of annulus candidates"})
params.append({'name': 'outer_budget', 'type': 'int', \
'title': "Outer budget", \
'limits': (1, float('inf')), 'value': 100, 'default': 100,\
'tip': "Number of candidates nodes outside of circumscribed d-ball"})
params.append({'name': 'LHS_correction', \
'title': "LHS-like nodes placement",\
'type': 'bool', 'value': False })
### Create tree of Parameter objects
# I don't know why that signals do not work for me
# Only sigTreeStateChanged works, but I don't want to struggle with it
# May be I'll report the issue
#self.param.sigValueChanged.connect(self.param_changed)
#self.param.sigValueChanging.connect(self.param_changing)
self.param = pg.parametertree.Parameter.create(name='params', type='group', children=params)
#č branima sa rekurzii
#оӵ рекурзилы пезьдэт!
self.param_values = self.param.getValues()
def __getattr__(self, attr):
#č na teoreticky možnou rěkurziju vykašleme
#оӵ рекурзия уз луы
return self.param_values[attr][0]
def setup_box(self):
#č to je důležité! __getatr__ odsaď bere hodnoty
self.param_values = self.param.getValues()
scheme = schemes.get_tn_scheme(self.scheme, self.box.nvar, self.degree)
if self.tree_space == 'None':
tree_space = None
else:
tree_space = self.tree_space
try:
stm_filename = self.box.filename + '_stm'
except AttributeError:
stm_filename = None
# do the thing
self.box.sample_box = Goal(
self.box.sample_box, #č rekurze)
scheme,
tri_space=self.tri_space,
tree_space=tree_space,
kechato_space=self.kechato_space,
potential=self.potential,
q=self.q,
p_norm=self.p_norm,
shell_budget=self.shell_budget,
outer_budget=self.outer_budget,
LHS_correction=self.LHS_correction,
stm_filename=stm_filename,
)
class SetupDiceBoxWidget(pg.LayoutWidget):
def __init__(self, wt, parent=None):
self.box = wt
#č nejdřív vytvořiť apku
self.app = pg.mkQApp("WellMet")
#
super().__init__(parent)
self.setup()
#č zobraziť
self.show()
#č a spustit smyčku
self.app.exec_()
def setup(self):
self.setWindowTitle("Set up sequential algorithm")
self.setup_tabs()
self.addWidget(self.tabs, row=0, col=0, rowspan=1, colspan=2)
self.btn_skip = QtGui.QPushButton('Skip')
self.addWidget(self.btn_skip, row=1, col=0)
self.btn_skip.clicked.connect(self.skip)
self.btn_choose = QtGui.QPushButton('Create')
self.addWidget(self.btn_choose, row=1, col=1)
self.btn_choose.clicked.connect(self.create)
def skip(self):
self.app.quit()
def create(self):
tab_index = self.tabs.currentIndex()
if tab_index == 0:
self.goal.setup_box()
elif tab_index == 1:
self.dice_box.setup_box()
else:
raise
self.app.quit()
def setup_tabs(self):
# Initialize tab screen
self.tabs = QtWidgets.QTabWidget(self)
# Add tabs
self.goal = GoalWidget(self.box, self)
self.tabs.addTab(self.goal, "Goal")
# Add tabs
self.dice_box = DumbDiceBoxWidget(self.box, self)
self.tabs.addTab(self.dice_box, "Dumb DiceBox")
#self.tab_2d = TestCasesListWidget(testcases_2D, self)
#self.tabs.addTab(self.tab_2d,"2D testcases")