From e474d10dfbf34969c226728c6e6c7faba46afe42 Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Rouby <pierre-antoine.rouby@inrae.fr> Date: Mon, 26 Jun 2023 14:43:09 +0200 Subject: [PATCH] Config, RunSolver: Add editor command and open solver logs into external editor. --- src/Solver/GenericSolver.py | 3 ++ src/View/Configure/Window.py | 6 ++++ src/View/RunSolver/Log/Window.py | 18 ++++++++++-- src/View/RunSolver/Window.py | 7 +++-- src/View/ui/ConfigureDialog.ui | 50 ++++++++++++++++++++++++++++++++ src/View/ui/SolverLogFile.ui | 3 ++ src/config.py | 4 ++- 7 files changed, 86 insertions(+), 5 deletions(-) diff --git a/src/Solver/GenericSolver.py b/src/Solver/GenericSolver.py index 8f5b0afb..7cf3e332 100644 --- a/src/Solver/GenericSolver.py +++ b/src/Solver/GenericSolver.py @@ -15,3 +15,6 @@ class GenericSolver(AbstractSolver): lst = super(GenericSolver, cls).default_parameters() return lst + + def log_file(self): + return "" diff --git a/src/View/Configure/Window.py b/src/View/Configure/Window.py index c0c1b104..3e51f5c1 100644 --- a/src/View/Configure/Window.py +++ b/src/View/Configure/Window.py @@ -127,6 +127,9 @@ class ConfigureWindow(ASubWindow, ListedSubWindow): table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch) table.setAlternatingRowColors(True) + # Editor + self.set_line_edit_text("lineEdit_editor_cmd", str(self.conf.editor)) + # Language languages = Config.languages() for lang in languages: @@ -190,6 +193,9 @@ class ConfigureWindow(ASubWindow, ListedSubWindow): # Stricklers self.conf.stricklers = deepcopy(self._stricklers) + # Editor + self.conf.editor = self.get_line_edit_text("lineEdit_editor_cmd") + # Language self.conf.lang = Config.languages()[self.get_combobox_text("comboBox_language")] diff --git a/src/View/RunSolver/Log/Window.py b/src/View/RunSolver/Log/Window.py index fb77fe6f..fb7ba631 100644 --- a/src/View/RunSolver/Log/Window.py +++ b/src/View/RunSolver/Log/Window.py @@ -54,7 +54,10 @@ class SolverLogFileWindow(ASubMainWindow, ListedSubWindow): def setup_action(self): self.find(QAction, "action_revert").setEnabled(True) - self.find(QAction, "action_open_in_editor").setEnabled(True) + if self._config.editor != "": + self.find(QAction, "action_open_in_editor").setEnabled(True) + else: + self.find(QAction, "action_open_in_editor").setEnabled(False) def setup_connections(self): self.find(QAction, "action_revert").triggered.connect(self.revert) @@ -71,4 +74,15 @@ class SolverLogFileWindow(ASubMainWindow, ListedSubWindow): self.setup_text() def open_on_editor(self): - print("TODO: open in editor") + p = QProcess(self) + + cmd = self._config.editor + cmd = cmd.replace("@file", self._file_name) + + cmd = cmd.split() + exe = cmd[0] + args = cmd[1:] + + p.start( + exe, args, + ) diff --git a/src/View/RunSolver/Window.py b/src/View/RunSolver/Window.py index 427cea01..1b427b10 100644 --- a/src/View/RunSolver/Window.py +++ b/src/View/RunSolver/Window.py @@ -126,6 +126,7 @@ class SolverLogWindow(ASubMainWindow, ListedSubWindow): self.find(QAction, "action_start").setEnabled(False) self.find(QAction, "action_pause").setEnabled(True) self.find(QAction, "action_stop").setEnabled(True) + self.find(QAction, "action_log_file").setEnabled(False) def setup_alarm(self): self._alarm = QTimer() @@ -159,7 +160,8 @@ class SolverLogWindow(ASubMainWindow, ListedSubWindow): self.find(QAction, "action_start").setEnabled(True) self.find(QAction, "action_pause").setEnabled(False) self.find(QAction, "action_stop").setEnabled(False) - # self.find(QAction, "action_log_file").setEnabled(True) + if self._solver.log_file() != "": + self.find(QAction, "action_log_file").setEnabled(True) while self._output.qsize() != 0: s = self._output.get() @@ -191,7 +193,8 @@ class SolverLogWindow(ASubMainWindow, ListedSubWindow): self.find(QAction, "action_start").setEnabled(True) self.find(QAction, "action_pause").setEnabled(False) self.find(QAction, "action_stop").setEnabled(False) - self.find(QAction, "action_log_file").setEnabled(True) + if self._solver.log_file() != "": + self.find(QAction, "action_log_file").setEnabled(True) def log_file(self): file_name = os.path.join(self._workdir, self._solver.log_file()) diff --git a/src/View/ui/ConfigureDialog.ui b/src/View/ui/ConfigureDialog.ui index 693971a0..8f9a5603 100644 --- a/src/View/ui/ConfigureDialog.ui +++ b/src/View/ui/ConfigureDialog.ui @@ -409,6 +409,56 @@ </item> </layout> </widget> + <widget class="QWidget" name="tab_editor"> + <attribute name="title"> + <string>Editor</string> + </attribute> + <layout class="QGridLayout" name="gridLayout_8"> + <item row="0" column="0"> + <widget class="QLabel" name="label_11"> + <property name="font"> + <font> + <italic>true</italic> + </font> + </property> + <property name="text"> + <string>This value must be used for reading or editing files in speficic case</string> + </property> + </widget> + </item> + <item row="1" column="0"> + <layout class="QHBoxLayout" name="horizontalLayout_8"> + <item> + <widget class="QLabel" name="label"> + <property name="text"> + <string>Editor command</string> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="lineEdit_editor_cmd"> + <property name="inputMask"> + <string/> + </property> + </widget> + </item> + </layout> + </item> + <item row="2" column="0"> + <spacer name="verticalSpacer_5"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>40</height> + </size> + </property> + </spacer> + </item> + </layout> + </widget> <widget class="QWidget" name="tab_language"> <attribute name="title"> <string>Language</string> diff --git a/src/View/ui/SolverLogFile.ui b/src/View/ui/SolverLogFile.ui index dae48914..15922be4 100644 --- a/src/View/ui/SolverLogFile.ui +++ b/src/View/ui/SolverLogFile.ui @@ -13,6 +13,9 @@ <property name="windowTitle"> <string>MainWindow</string> </property> + <property name="locale"> + <locale language="English" country="Europe"/> + </property> <widget class="QWidget" name="centralwidget"> <layout class="QGridLayout" name="gridLayout"> <item row="0" column="0"> diff --git a/src/config.py b/src/config.py index 60550351..f1db3b8c 100644 --- a/src/config.py +++ b/src/config.py @@ -16,7 +16,6 @@ class Config(object): self.set_default_value() def set_default_value(self): - print('toto') # Solvers self._solvers = [] @@ -33,6 +32,9 @@ class Config(object): self.backup_frequence = "00:05:00" self.backup_max = 10 + # Editor + self.editor = "emacs @file" + # Languages self.lang = "" -- GitLab