An error occurred while loading the file. Please try again.
-
Pierre-Antoine Rouby authoredfa32e429
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# Window.py -- Pamhyr
# Copyright (C) 2023 INRAE
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# -*- coding: utf-8 -*-
from View.Tools.PamhyrWindow import PamhyrDialog
from Solver.Solvers import solver_type_list
from Solver.GenericSolver import GenericSolver
from PyQt5.QtWidgets import (
QPushButton,
)
class ConfigureSolverWindow(PamhyrDialog):
_pamhyr_ui = "ConfigureAddSolverDialog"
_pamhyr_name = "Add/Edit Solver"
def __init__(self, data=None, config=None, parent=None):
if data is not None:
name = f"Edit Solver - {data.name}"
else:
name = "Add a new Solver"
super(ConfigureSolverWindow, self).__init__(
title = name,
config = config,
options = [],
parent=parent
)
# Combo box item
for solver in solver_type_list:
self.combobox_add_item("comboBox_solver", solver)
# Data to return
self.data = data
if self.data is not None:
self.copy_data()
self.setup_connection()
def copy_data(self):
self.set_combobox_text("comboBox_solver", self.data.type)
self.set_line_edit_text("lineEdit_name", self.data.name)
self.set_line_edit_text("lineEdit_description", self.data.description)
self.set_line_edit_text("lineEdit_input", self.data._path_input)
self.set_line_edit_text("lineEdit_input_cmd", self.data._cmd_input)
self.set_line_edit_text("lineEdit_solver", self.data._path_solver)
self.set_line_edit_text("lineEdit_solver_cmd", self.data._cmd_solver)
self.set_line_edit_text("lineEdit_output", self.data._path_output)
self.set_line_edit_text("lineEdit_output_cmd", self.data._cmd_output)
def setup_connection(self):
# File button
buttons = {
"pushButton_input": (lambda: self.file_dialog(
select_file = True,
callback = lambda f: self.set_line_edit_text("lineEdit_input", f[0])
)),
"pushButton_solver": (lambda: self.file_dialog(
select_file = True,
callback = lambda f: self.set_line_edit_text("lineEdit_solver", f[0])
)),
"pushButton_output": (lambda: self.file_dialog(
select_file = True,
callback = lambda f: self.set_line_edit_text("lineEdit_output", f[0])
)),
}
for button in buttons:
self.find(QPushButton, button).clicked.connect(buttons[button])
def accept(self):
if self.get_line_edit_text("lineEdit_name") == "":
self.message_box(
"A solver need a name",
"Please give a name to your solver"
)
else:
# Build new solver from selected type
stype = self.get_combobox_text("comboBox_solver")
self.data = solver_type_list[stype](self.get_line_edit_text("lineEdit_name"))
self.data.description = self.get_line_edit_text("lineEdit_description")
self.data.set_input(
self.get_line_edit_text("lineEdit_input"),
self.get_line_edit_text("lineEdit_input_cmd")
)
self.data.set_solver(
self.get_line_edit_text("lineEdit_solver"),
self.get_line_edit_text("lineEdit_solver_cmd")
)
self.data.set_output(
self.get_line_edit_text("lineEdit_output"),
self.get_line_edit_text("lineEdit_output_cmd")
)
self.done(True)