From e661e814e95bae616931b522a881176a6b179108 Mon Sep 17 00:00:00 2001 From: Paulocracy <36934614+Paulocracy@users.noreply.github.com> Date: Tue, 30 Apr 2024 15:22:36 +0200 Subject: [PATCH] Add scenario values to clipboard --- cnapy/appdata.py | 1 + cnapy/gui_elements/clipboard_calculator.py | 4 ++++ cnapy/gui_elements/main_window.py | 16 ++++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/cnapy/appdata.py b/cnapy/appdata.py index fe5bcd6b..47d71cbb 100644 --- a/cnapy/appdata.py +++ b/cnapy/appdata.py @@ -67,6 +67,7 @@ def __init__(self): self.scenario_future = [] self.recent_cna_files = [] self.auto_fba = False + self.scenario_in_clipboard = False def scen_values_set(self, reaction: str, values: Tuple[float, float]): if self.project.scen_values.get(reaction, None) != values: # record only real changes diff --git a/cnapy/gui_elements/clipboard_calculator.py b/cnapy/gui_elements/clipboard_calculator.py index 23f7a9a0..11c73f1f 100644 --- a/cnapy/gui_elements/clipboard_calculator.py +++ b/cnapy/gui_elements/clipboard_calculator.py @@ -80,6 +80,10 @@ def compute(self): r_comp = {} if self.l1.isChecked(): l_comp = self.appdata.project.comp_values + + if appdata.scenario_in_clipboard: + for (key, value) in appdata.project.scen_values.items(): + l_comp[key] = value elif self.l2.isChecked(): try: l_comp = self.appdata.clipboard_comp_values diff --git a/cnapy/gui_elements/main_window.py b/cnapy/gui_elements/main_window.py index d0c24709..2aeb002b 100644 --- a/cnapy/gui_elements/main_window.py +++ b/cnapy/gui_elements/main_window.py @@ -230,6 +230,11 @@ def __init__(self, appdata: AppData): self.clipboard_menu.addAction(save_fluxes_as_xlsx_action) save_fluxes_as_xlsx_action.triggered.connect(self.save_fluxes_as_xlsx) + self.scenario_in_clipboard_action = QAction("Include scenario in clipboard", self) + self.scenario_in_clipboard_action.triggered.connect(self.scenario_in_clipboard) + self.scenario_in_clipboard_action.setCheckable(True) + self.clipboard_menu.addAction(self.scenario_in_clipboard_action) + self.map_menu = self.menu.addMenu("Map") self.cnapy_map_actions = QActionGroup(self) separator = QAction(" CNApy map", self) @@ -1566,6 +1571,10 @@ def on_tab_change(self, idx): def copy_to_clipboard(self): self.appdata.clipboard_comp_values = self.appdata.project.comp_values.copy() + if self.appdata.scenario_in_clipboard: + for (key, value) in self.appdata.project.scen_values.items(): + self.appdata.clipboard_comp_values[key] = value + def paste_clipboard(self): try: self.appdata.project.comp_values = self.appdata.clipboard_comp_values.copy() @@ -1578,6 +1587,13 @@ def paste_clipboard(self): return self.centralWidget().update() + + def scenario_in_clipboard(self): + if self.scenario_in_clipboard_action.isChecked(): + self.appdata.scenario_in_clipboard = True + else: + self.appdata.scenario_in_clipboard = False + @Slot() def clipboard_arithmetics(self): dialog = ClipboardCalculator(self.appdata)