Skip to content

Commit

Permalink
Add scenario values to clipboard
Browse files Browse the repository at this point in the history
  • Loading branch information
Paulocracy committed Apr 30, 2024
1 parent 34745a7 commit e661e81
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions cnapy/appdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions cnapy/gui_elements/clipboard_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions cnapy/gui_elements/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand All @@ -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)
Expand Down

0 comments on commit e661e81

Please sign in to comment.